From a3c174ee4c08d1d5e7a89ce187f52e3c0807a7eb Mon Sep 17 00:00:00 2001 From: stefan Date: Sun, 23 Apr 2023 17:00:14 -0400 Subject: memory detection --- sys/dev/dev_init.c | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) (limited to 'sys/dev/dev_init.c') 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 #include -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; } -- cgit v1.2.3