diff options
author | stefan <stefan@s00.xyz> | 2023-04-23 17:00:14 -0400 |
---|---|---|
committer | stefan <stefan@s00.xyz> | 2023-04-23 17:00:14 -0400 |
commit | a3c174ee4c08d1d5e7a89ce187f52e3c0807a7eb (patch) | |
tree | bad1c1d9026e7de550a1e69863acdf9a8213b2b7 /sys/dev | |
parent | 386ad4f82955d389ae347bc50f7efca5edb9d9a8 (diff) | |
download | sv-a3c174ee4c08d1d5e7a89ce187f52e3c0807a7eb.tar.gz |
memory detection
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/dev_init.c | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/sys/dev/dev_init.c b/sys/dev/dev_init.c index fc70853..9933c2a 100644 --- a/sys/dev/dev_init.c +++ b/sys/dev/dev_init.c @@ -5,18 +5,46 @@ #include <string.h> #include <stdint.h> -void -dev_init(struct fdt_header *fdt) + +static void +mem_init(struct fdt_header *fdt, struct devicetree *dt) { + + int memory = fdt_path_offset(fdt, "/memory"); + if (memory < 0) + printf("[dev_init] failed to find memory node\n"); + + int len; + + struct _reg *val = fdt_getprop(fdt, memory, "reg", &len); + /* bad idea */ + dt->memory.origin = fdt64_to_cpu(val->address); + dt->memory.size = fdt64_to_cpu(val->size); + printf("[mem_init] found %dMB of memory at %p\n", dt->memory.size >> 20, dt->memory.origin); + + int n = fdt_num_mem_rsv(fdt); + printf("[mem_init] found %d memory reserve map entries\n", n); +} + + +struct devicetree +dev_init(struct fdt_header *fdt) +{ + struct devicetree dt = {0}; + if (fdt_check_header(fdt) == 0) printf("[dev_init] valid fdt at %p\n", fdt); else printf("[dev_init] error: fdt_check_header()\n"); - int offset = fdt_next_node(fdt, offset, 0); - do { - printf("[dev_init] found %s\n", fdt_get_name(fdt, offset, NULL)); - offset = fdt_next_node(fdt, offset, 0); - } while (offset != -FDT_ERR_NOTFOUND); + printf("[dev_init] detecting memory...\n"); + mem_init(fdt, &dt); + +// int offset = fdt_next_node(fdt, offset, 0); +// do { +// printf("[dev_init] found %s\n", fdt_get_name(fdt, offset, 0)); +// offset = fdt_next_node(fdt, offset, 0); +// } while (offset != -FDT_ERR_NOTFOUND); + return dt; } |