From e16f5f81dfb2e97a554ec19b941ec05a7942fd2d Mon Sep 17 00:00:00 2001 From: Kimplul Date: Fri, 4 Aug 2023 20:50:41 +0300 Subject: add initial smp bringup --- common/debug.c | 9 +++++---- common/fdt.c | 15 --------------- common/main.c | 7 ++++--- common/pmem.c | 8 +++++--- common/proc.c | 6 ++++++ 5 files changed, 20 insertions(+), 25 deletions(-) (limited to 'common') diff --git a/common/debug.c b/common/debug.c index ff9dc18..526bfdc 100644 --- a/common/debug.c +++ b/common/debug.c @@ -199,14 +199,15 @@ static struct dbg_info __dbg_from_fdt(const void *fdt) enum serial_dev dev = __serial_dev_enum(dev_name); /* get serial device address */ - struct cell_info ci = get_reginfo(fdt, stdout); - void *reg_ptr = (void *)fdt_getprop(fdt, stdout_offset, "reg", NULL); + const void *reg_ptr = fdt_getprop(fdt, stdout_offset, "reg", NULL); + struct cell_info ci = get_cellinfo(fdt, stdout_offset); pm_t dbg_ptr = (pm_t)fdt_load_reg_addr(ci, reg_ptr, 0); /* get serial device offset if present */ size_t shift = 0; - void *shift_ptr = (void *)fdt_getprop(fdt, stdout_offset, "reg-shift", - NULL); + const void *shift_ptr = fdt_getprop(fdt, stdout_offset, "reg-shift", + NULL); + if (shift_ptr) shift = (size_t)fdt_load_int32_ptr(shift_ptr); diff --git a/common/fdt.c b/common/fdt.c index 3f20d72..677be7b 100644 --- a/common/fdt.c +++ b/common/fdt.c @@ -13,18 +13,3 @@ struct cell_info get_cellinfo(const void *fdt, const int offset) return (struct cell_info){ fdt_size_cells(fdt, offset), fdt_address_cells(fdt, offset) }; } - -/* how "reg" is interpreted depends on the parent node */ -struct cell_info get_reginfo(const void *fdt, const char *path) -{ - const char *i = strrchr(path, '/'); - if (!i) - return (struct cell_info){ 0, 0 }; - - size_t baselen = i - path; - if (baselen == 0) - /* root node */ - baselen = 1; - - return get_cellinfo(fdt, fdt_path_offset_namelen(fdt, path, baselen)); -} diff --git a/common/main.c b/common/main.c index 30d9ed5..7291387 100644 --- a/common/main.c +++ b/common/main.c @@ -15,6 +15,7 @@ #include #include #include +#include #include /** @@ -51,9 +52,9 @@ void __main main(void *fdt, uintptr_t ram_base) init_irq(fdt); init_timer(fdt); init_proc(fdt); - /* free temporary virtual memory now that we're in the init process - * space */ - destroy_vmem(b); + + /* try to bring up other cores on system */ + smp_bringup(b, fdt); /* start running init program */ run_init(cur_tcb(), fdt); diff --git a/common/pmem.c b/common/pmem.c index 02c5146..ed79e4a 100644 --- a/common/pmem.c +++ b/common/pmem.c @@ -550,7 +550,7 @@ static void __mark_area_used(pm_t base, pm_t top) static void __mark_reserved_mem(void *fdt) { int rmem_offset = fdt_path_offset(fdt, "/reserved-memory"); - struct cell_info ci = get_reginfo(fdt, "/reserved-memory"); + struct cell_info ci = get_cellinfo(fdt, rmem_offset); int node = 0; fdt_for_each_subnode(node, fdt, rmem_offset) { @@ -576,10 +576,12 @@ static void __mark_reserved_mem(void *fdt) */ static pm_t __get_ramtop(void *fdt) { - struct cell_info ci = get_reginfo(fdt, "/memory"); int mem_offset = fdt_path_offset(fdt, "/memory"); - uint8_t *mem_reg = (uint8_t *)fdt_getprop(fdt, mem_offset, "reg", NULL); + const void *mem_reg = fdt_getprop(fdt, mem_offset, "reg", NULL); + /* here we actually want the root offset because /memory itself doesn't + * have children, I guess? */ + struct cell_info ci = get_cellinfo(fdt, fdt_path_offset(fdt, "/")); pm_t base = (pm_t)fdt_load_reg_addr(ci, mem_reg, 0); return (pm_t)fdt_load_reg_size(ci, mem_reg, 0) + base; } diff --git a/common/proc.c b/common/proc.c index 0f0c7f8..e6c2769 100644 --- a/common/proc.c +++ b/common/proc.c @@ -36,6 +36,12 @@ stat_t init_proc(void *fdt) if (!t) return ERR_OOMEM; + /* we're the first cpu, so we always have ID 0 */ + t->cpu_id = 0; + + /* force tcb for core */ + tcb_assign(t); + /* set current tcb */ use_tcb(t); -- cgit v1.3