From 7870d56b155c2be73cdacfba94eeb893cd55628e Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Tue, 26 Nov 2024 13:59:54 +0100 Subject: dt: Fetch the CPU frequency as well MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the 'timebase-frequency' property is available under the 'cpus' node from the DTB blob, it makes sense to try to fetch this value from there instead of hardcoding it. For other use-cases, where this information is not available through DT (e.g. ACPI on the VisionFive2 board), we will have to hardcode it with a default value even if it's not the proper one. Signed-off-by: Miquel Sabaté Solà --- include/fbos/dt.h | 20 ++++++++++++++------ include/fbos/init.h | 7 +++++++ 2 files changed, 21 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/fbos/dt.h b/include/fbos/dt.h index fd77c35..bbeb7cd 100644 --- a/include/fbos/dt.h +++ b/include/fbos/dt.h @@ -3,13 +3,21 @@ #include -// Pair of addresses where the initrd is located in memory. -struct initrd_addr { - uintptr_t start; - uintptr_t end; +// Default value for the 'dt_info.cpu_freq' property if none could be retrieved. +#define DEFAULT_CPU_FREQ 10000000 + +// Holds all the information that we gather from the initial DeviceTree blob. +struct dt_info { + // Ticks per second. If `get_dt_info` fails at setting this value, then + // `DEFAULT_CPU_FREQ` is used. + uint64_t cpu_freq; + + // Start and end addresses of the initramfs blob as stored in memory. + uintptr_t initrd_start; + uintptr_t initrd_end; }; -// Returns the `initrd` addresses as parsed from the given DTB blob. -struct initrd_addr find_dt_initrd_addr(uint32_t *dtb); +// Set 'info' by parsing the given 'dtb' blob. +void get_dt_info(uint32_t *dtb, struct dt_info *info); #endif // __FBOS_DT_H_ diff --git a/include/fbos/init.h b/include/fbos/init.h index f0f1dce..9e0049e 100644 --- a/include/fbos/init.h +++ b/include/fbos/init.h @@ -2,6 +2,7 @@ #define __FBOS_INIT_H #include +#include #include // Tracks the amount of seconds that have elapsed since activating timer @@ -10,6 +11,12 @@ // Instantiated in kernel/trap.c, initialized in main.c. extern uint64_t seconds_elapsed; +// General information from the DTB blob. This will be properly initialized at +// the very beginning of kernel initialization. +// +// Instantiated and initialized in kernel/main.c. +extern struct dt_info info; + // Extract the executables from the initrd that is located at `base_addr` and // has the given `size`. void extract_initrd(const unsigned char *const base_addr, uint64_t size, -- cgit v1.2.3