nixos-riscv/patches/opensbi-timer-debug.patch

230 lines
7.3 KiB
Diff
Raw Permalink Normal View History

2024-07-12 13:19:10 +02:00
diff --git a/lib/sbi/sbi_timer.c b/lib/sbi/sbi_timer.c
index 7b618de..65e42b0 100644
--- a/lib/sbi/sbi_timer.c
+++ b/lib/sbi/sbi_timer.c
@@ -183,13 +183,17 @@ int sbi_timer_init(struct sbi_scratch *scratch, bool cold_boot)
u64 *time_delta;
const struct sbi_platform *plat = sbi_platform_ptr(scratch);
+ sbi_printf("sbi_timer_init: begins\n");
+
if (cold_boot) {
time_delta_off = sbi_scratch_alloc_offset(sizeof(*time_delta));
if (!time_delta_off)
return SBI_ENOMEM;
- if (sbi_hart_has_extension(scratch, SBI_HART_EXT_ZICNTR))
+ if (sbi_hart_has_extension(scratch, SBI_HART_EXT_ZICNTR)) {
+ sbi_printf("sbi_timer_init: got Zicntr extension\n");
get_time_val = get_ticks;
+ }
} else {
if (!time_delta_off)
return SBI_ENOMEM;
@@ -198,7 +202,10 @@ int sbi_timer_init(struct sbi_scratch *scratch, bool cold_boot)
time_delta = sbi_scratch_offset_ptr(scratch, time_delta_off);
*time_delta = 0;
- return sbi_platform_timer_init(plat, cold_boot);
+ int rc = sbi_platform_timer_init(plat, cold_boot);
+ if (rc)
+ sbi_printf("sbi_platform_timer: sbi_platform_timer_init failed (%d)\n", rc);
+ return rc;
}
void sbi_timer_exit(struct sbi_scratch *scratch)
2024-07-12 16:09:36 +02:00
diff --git a/lib/sbi/sbi_trap.c b/lib/sbi/sbi_trap.c
2024-07-12 17:45:57 +02:00
index b4f3a17..cde2073 100644
2024-07-12 16:09:36 +02:00
--- a/lib/sbi/sbi_trap.c
+++ b/lib/sbi/sbi_trap.c
2024-07-12 16:32:55 +02:00
@@ -283,6 +283,7 @@ static int sbi_trap_aia_irq(void)
*/
struct sbi_trap_context *sbi_trap_handler(struct sbi_trap_context *tcntx)
{
2024-07-12 17:45:57 +02:00
+ sbi_printf("<");
2024-07-12 16:32:55 +02:00
int rc = SBI_ENOTSUPP;
const char *msg = "trap handler failed";
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
@@ -295,6 +296,7 @@ struct sbi_trap_context *sbi_trap_handler(struct sbi_trap_context *tcntx)
sbi_trap_set_context(scratch, tcntx);
if (mcause & MCAUSE_IRQ_MASK) {
2024-08-30 14:29:23 +02:00
+ sbi_printf("i(%lu)", mcause & ~MCAUSE_IRQ_MASK);
2024-07-12 16:32:55 +02:00
if (sbi_hart_has_extension(sbi_scratch_thishart_ptr(),
SBI_HART_EXT_SMAIA))
rc = sbi_trap_aia_irq();
2024-07-12 17:45:57 +02:00
@@ -306,35 +308,42 @@ struct sbi_trap_context *sbi_trap_handler(struct sbi_trap_context *tcntx)
2024-07-12 16:09:36 +02:00
switch (mcause) {
case CAUSE_ILLEGAL_INSTRUCTION:
2024-07-12 17:45:57 +02:00
+ sbi_printf("I");
2024-07-12 16:09:36 +02:00
rc = sbi_illegal_insn_handler(tcntx);
msg = "illegal instruction handler failed";
break;
case CAUSE_MISALIGNED_LOAD:
2024-07-12 17:45:57 +02:00
+ sbi_printf("L");
2024-07-12 16:09:36 +02:00
sbi_pmu_ctr_incr_fw(SBI_PMU_FW_MISALIGNED_LOAD);
rc = sbi_misaligned_load_handler(tcntx);
msg = "misaligned load handler failed";
break;
case CAUSE_MISALIGNED_STORE:
2024-07-12 17:45:57 +02:00
+ sbi_printf("S");
2024-07-12 16:09:36 +02:00
sbi_pmu_ctr_incr_fw(SBI_PMU_FW_MISALIGNED_STORE);
rc = sbi_misaligned_store_handler(tcntx);
msg = "misaligned store handler failed";
2024-07-12 17:45:57 +02:00
break;
case CAUSE_SUPERVISOR_ECALL:
case CAUSE_MACHINE_ECALL:
+ sbi_printf("E");
rc = sbi_ecall_handler(tcntx);
msg = "ecall handler failed";
break;
case CAUSE_LOAD_ACCESS:
+ sbi_printf("l");
sbi_pmu_ctr_incr_fw(SBI_PMU_FW_ACCESS_LOAD);
rc = sbi_load_access_handler(tcntx);
msg = "load fault handler failed";
break;
case CAUSE_STORE_ACCESS:
+ sbi_printf("s");
sbi_pmu_ctr_incr_fw(SBI_PMU_FW_ACCESS_STORE);
rc = sbi_store_access_handler(tcntx);
msg = "store fault handler failed";
break;
default:
+ sbi_printf("R");
/* If the trap came from S or U mode, redirect it there */
msg = "trap redirect failed";
rc = sbi_trap_redirect(regs, trap);
@@ -344,6 +353,8 @@ struct sbi_trap_context *sbi_trap_handler(struct sbi_trap_context *tcntx)
2024-07-12 16:09:36 +02:00
trap_done:
if (rc)
sbi_trap_error(msg, rc, tcntx);
+ else
2024-07-12 17:45:57 +02:00
+ sbi_printf(">");
2024-07-12 16:09:36 +02:00
if (((regs->mstatus & MSTATUS_MPP) >> MSTATUS_MPP_SHIFT) != PRV_M)
sbi_sse_process_pending_events(regs);
2024-07-12 13:19:10 +02:00
diff --git a/lib/utils/timer/fdt_timer.c b/lib/utils/timer/fdt_timer.c
index f468730..db20526 100644
--- a/lib/utils/timer/fdt_timer.c
+++ b/lib/utils/timer/fdt_timer.c
@@ -7,6 +7,7 @@
* Anup Patel <anup.patel@wdc.com>
*/
+#include <sbi/sbi_console.h>
#include <sbi/sbi_error.h>
#include <sbi/sbi_scratch.h>
#include <sbi_utils/fdt/fdt_helper.h>
@@ -39,19 +40,26 @@ static int fdt_timer_cold_init(void)
void *fdt = fdt_get_address();
for (pos = 0; pos < fdt_timer_drivers_size; pos++) {
+ sbi_printf("fdt_timer_cold_init: pos = %d\n", pos);
drv = fdt_timer_drivers[pos];
noff = -1;
while ((noff = fdt_find_match(fdt, noff,
drv->match_table, &match)) >= 0) {
+
+ sbi_printf("fdt_timer_cold_init: got match, name = %s\n", match->compatible);
if (!fdt_node_is_enabled(fdt, noff))
continue;
+ sbi_printf("fdt_timer_cold_init: enabled\n");
+
/* drv->cold_init must not be NULL */
if (drv->cold_init == NULL)
return SBI_EFAIL;
rc = drv->cold_init(fdt, noff, match);
+ sbi_printf("fdt_timer_cold_init: drc->cold_init = %d\n", rc);
+
if (rc == SBI_ENODEV)
continue;
if (rc)
@@ -69,6 +77,7 @@ static int fdt_timer_cold_init(void)
* We can't fail here since systems with Sstc might not provide
* mtimer/clint DT node in the device tree.
*/
+ sbi_printf("fdt_timer_cold_init: returns 0\n");
return 0;
}
@@ -78,9 +87,15 @@ int fdt_timer_init(bool cold_boot)
if (cold_boot) {
rc = fdt_timer_cold_init();
- if (rc)
+ if (rc) {
+ sbi_printf("fdt_timer_init: fdt_timer_cold_init failed (%d)\n", rc);
return rc;
+ }
}
- return fdt_timer_warm_init();
+ rc = fdt_timer_warm_init();
+ if (rc)
+ sbi_printf("fdt_timer_init: fdt_timer_warm_init failed (%d)\n", rc);
+
+ return rc;
}
diff --git a/lib/utils/timer/fdt_timer_mtimer.c b/lib/utils/timer/fdt_timer_mtimer.c
2024-07-12 13:55:08 +02:00
index 9e27e3a..cef2ee6 100644
--- a/lib/utils/timer/fdt_timer_mtimer.c
+++ b/lib/utils/timer/fdt_timer_mtimer.c
@@ -8,6 +8,7 @@
*/
#include <libfdt.h>
+#include <sbi/sbi_console.h>
#include <sbi/sbi_error.h>
#include <sbi/sbi_heap.h>
#include <sbi/sbi_list.h>
@@ -33,6 +34,7 @@ static struct aclint_mtimer_data *mt_reference = NULL;
static int timer_mtimer_cold_init(void *fdt, int nodeoff,
const struct fdt_match *match)
{
+
int rc;
unsigned long addr[2], size[2];
struct timer_mtimer_node *mtn, *n;
@@ -40,6 +42,8 @@ static int timer_mtimer_cold_init(void *fdt, int nodeoff,
const struct timer_mtimer_quirks *quirks = match->data;
bool is_clint = quirks && quirks->is_clint;
+ sbi_printf("timer_mtimer_cold_init: begins, is_clint = %d\n", (int) is_clint);
+
mtn = sbi_zalloc(sizeof(*mtn));
if (!mtn)
return SBI_ENOMEM;
@@ -49,6 +53,7 @@ static int timer_mtimer_cold_init(void *fdt, int nodeoff,
&addr[0], &size[0], &addr[1], &size[1],
&mt->first_hartid, &mt->hart_count);
if (rc) {
+ sbi_printf("timer_mtimer_cold_init: fdt_parse_aclint_node failed (%d)\n", rc);
sbi_free(mtn);
return rc;
}
@@ -57,6 +62,7 @@ static int timer_mtimer_cold_init(void *fdt, int nodeoff,
rc = fdt_parse_timebase_frequency(fdt, &mt->mtime_freq);
if (rc) {
+ sbi_printf("timer_mtimer_cold_init: fdt_parse_timebase_frequency failed (%d)\n", rc);
sbi_free(mtn);
return rc;
}
@@ -83,6 +89,11 @@ static int timer_mtimer_cold_init(void *fdt, int nodeoff,
mt->mtimecmp_size = size[1];
}
+ sbi_printf("timer_mtimer_cold_init: mtime_addr = 0x%08lx\n", mt->mtime_addr);
+ sbi_printf("timer_mtimer_cold_init: mtime_size = 0x%08lx\n", mt->mtime_size);
2024-07-12 13:55:08 +02:00
+ sbi_printf("timer_mtimer_cold_init: mtimecmp_addr = 0x%08lx\n", mt->mtimecmp_addr);
+ sbi_printf("timer_mtimer_cold_init: mtimecmp_size = 0x%08lx\n", mt->mtimecmp_size);
+
/* Apply additional quirks */
if (quirks) {
mt->has_64bit_mmio = quirks->has_64bit_mmio;