Skip to content

Commit

Permalink
clint: move hart wakeup till after all FDT parsing
Browse files Browse the repository at this point in the history
The clint was wiping out information discovered by the plic.
Initialize hart stacks as they are discovered.
Then fill in clint+plic info
Then wake the harts.
  • Loading branch information
terpstra committed Apr 1, 2017
1 parent 078ea39 commit 733fae9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
10 changes: 6 additions & 4 deletions machine/fdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ void query_mem(uintptr_t fdt)
///////////////////////////////////////////// HART SCAN //////////////////////////////////////////

static uint32_t hart_phandles[MAX_HARTS];
uint64_t hart_mask;

struct hart_scan {
const struct fdt_scan_node *cpu;
Expand Down Expand Up @@ -221,7 +222,9 @@ static void hart_done(const struct fdt_scan_node *node, void *extra)

if (scan->hart < MAX_HARTS) {
hart_phandles[scan->hart] = scan->phandle;
hart_mask |= 1 << scan->hart;
if (scan->hart >= num_harts) num_harts = scan->hart + 1;
hls_init(scan->hart);
}
}
}
Expand Down Expand Up @@ -304,10 +307,9 @@ static void clint_done(const struct fdt_scan_node *node, void *extra)
if (hart_phandles[hart] == phandle)
break;
if (hart < MAX_HARTS) {
hls_t *hls = hls_init(hart);
hls_t *hls = OTHER_HLS(hart);
hls->ipi = (void*)(scan->reg + index * 4);
hls->timecmp = (void*)(scan->reg + 0x4000 + (index * 8));
*hls->ipi = 1; // wakeup the hart
}
value += 4;
}
Expand Down Expand Up @@ -407,10 +409,10 @@ static void plic_done(const struct fdt_scan_node *node, void *extra)
value += 2;
}
#if 0
printm("PLIC: prio %x devs %d\n", (uint32_t)(uintptr_t)plic_priorities, plic_ndevs);
printm("PLIC: prio %x devs %d\r\n", (uint32_t)(uintptr_t)plic_priorities, plic_ndevs);
for (int i = 0; i < MAX_HARTS; ++i) {
hls_t *hls = OTHER_HLS(i);
printm("CPU %d: %x %x %x %x\n", i, (uint32_t)(uintptr_t)hls->plic_m_ie, (uint32_t)(uintptr_t)hls->plic_m_thresh, (uint32_t)(uintptr_t)hls->plic_s_ie, (uint32_t)(uintptr_t)hls->plic_s_thresh);
printm("CPU %d: %x %x %x %x\r\n", i, (uint32_t)(uintptr_t)hls->plic_m_ie, (uint32_t)(uintptr_t)hls->plic_m_thresh, (uint32_t)(uintptr_t)hls->plic_s_ie, (uint32_t)(uintptr_t)hls->plic_s_thresh);
}
#endif
}
Expand Down
3 changes: 3 additions & 0 deletions machine/fdt.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,7 @@ void query_harts(uintptr_t fdt);
void query_plic(uintptr_t fdt);
void query_clint(uintptr_t fdt);

// The hartids of available harts
extern uint64_t hart_mask;

#endif
13 changes: 11 additions & 2 deletions machine/minit.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,28 @@ static void hart_plic_init()
*HLS()->plic_s_thresh = 0;
}

static void wake_harts()
{
for (int hart = 0; hart < MAX_HARTS; ++hart)
if (((hart_mask >> hart) & 1))
*OTHER_HLS(hart)->ipi = 1; // wakeup the hart
}

void init_first_hart(uintptr_t hartid, uintptr_t dtb)
{
hart_init();
hls_init(0); // this might get called again from parse_config_string

// Confirm console as early as possible
query_uart(dtb);
printm("SBI console now online\n");
printm("SBI console now online\r\n");

query_mem(dtb);
query_harts(dtb);
query_plic(dtb);
query_clint(dtb);
query_plic(dtb);

wake_harts();

plic_init();
hart_plic_init();
Expand Down

0 comments on commit 733fae9

Please sign in to comment.