diff options
Diffstat (limited to 'sys/dev/dev_init.c')
-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; } |