aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2024-11-26 13:59:54 +0100
committerMiquel Sabaté Solà <mikisabate@gmail.com>2024-11-26 13:59:54 +0100
commit7870d56b155c2be73cdacfba94eeb893cd55628e (patch)
treef95699d91e19635c7aa0e99dbf114da2a06e80a2 /include
parent30d6ab8c6b40b2897fa3f49cce0302cc6c3a66e6 (diff)
downloadfbos-7870d56b155c2be73cdacfba94eeb893cd55628e.tar.gz
fbos-7870d56b155c2be73cdacfba94eeb893cd55628e.zip
dt: Fetch the CPU frequency as well
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à <mikisabate@gmail.com>
Diffstat (limited to 'include')
-rw-r--r--include/fbos/dt.h20
-rw-r--r--include/fbos/init.h7
2 files changed, 21 insertions, 6 deletions
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 <fbos/compiler.h>
-// 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 <fbos/compiler.h>
+#include <fbos/dt.h>
#include <fbos/sched.h>
// 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,