aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / native / kernel / dev / pi5_wdt.h
| 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* pi5_wdt.h -- Raspberry Pi 5 (BCM2712) PM watchdog, Pi 5 build only |
| 18 | * (CK_PI5). Armed at kernel start and petted at every boot stage |
| 19 | * (ck_set_stage), so a kernel that stops making progress resets the board |
| 20 | * within CK_PI5_WDT_S seconds; the Pi then starts its normal system (the |
| 21 | * one-shot tryboot flag is already cleared). Never built for the Spark or |
| 22 | * QEMU: the address below is BCM2712-only. |
| 23 | * Registers and sequence: Linux drivers/watchdog/bcm2835_wdt.c |
| 24 | * (bcm2835_wdt_start / _stop); address: bcm2712.dtsi watchdog@7d200000 in |
| 25 | * the soc bus window 0x0 -> 0x10_0000_0000. */ |
| 26 | #ifndef AIENOS_CK_PI5_WDT_H |
| 27 | #define AIENOS_CK_PI5_WDT_H |
| 28 | #include <stdint.h> |
| 29 | |
| 30 | #define CK_PI5_PM_PHYS 0x107d200000ull |
| 31 | #define CK_PI5_PM_RSTC 0x1cu |
| 32 | #define CK_PI5_PM_WDOG 0x24u |
| 33 | #define CK_PI5_PM_PASSWORD 0x5a000000u |
| 34 | #define CK_PI5_PM_WDOG_TIME_SET 0x000fffffu |
| 35 | #define CK_PI5_PM_RSTC_WRCFG_CLR 0xffffffcfu |
| 36 | #define CK_PI5_PM_RSTC_WRCFG_FULL_RESET 0x00000020u |
| 37 | #define CK_PI5_PM_RSTC_RESET 0x00000102u |
| 38 | #ifndef CK_PI5_WDT_S |
| 39 | #define CK_PI5_WDT_S 15u /* the counter holds at most 0xfffff ticks of 1/65536 s: just under 16 s */ |
| 40 | #endif |
| 41 | |
| 42 | /* Register values (pure, host-tested). */ |
| 43 | static inline uint32_t ck_pi5_wdog_value(uint32_t secs) |
| 44 | { |
| 45 | return CK_PI5_PM_PASSWORD | ((secs << 16) & CK_PI5_PM_WDOG_TIME_SET); |
| 46 | } |
| 47 | static inline uint32_t ck_pi5_rstc_arm(uint32_t cur) |
| 48 | { |
| 49 | return CK_PI5_PM_PASSWORD | (cur & CK_PI5_PM_RSTC_WRCFG_CLR) | CK_PI5_PM_RSTC_WRCFG_FULL_RESET; |
| 50 | } |
| 51 | |
| 52 | /* Maps the PM block and arms the watchdog. 0, or -1 if the map failed. */ |
| 53 | int ck_pi5_wdt_arm(void); |
| 54 | /* Restarts the countdown (no-op before arm). */ |
| 55 | void ck_pi5_wdt_pet(void); |
| 56 | /* Stops the watchdog (before an orderly PSCI reset or a long operator hold). */ |
| 57 | void ck_pi5_wdt_stop(void); |
| 58 | #endif |