From: Benjamin Herrenschmidt Date: Thu, 18 Jun 2020 01:06:33 +0000 (+1000) Subject: console: Cleanup console API X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e3941109af1d8203dddc2aa12e33170d6dca5c4b;p=microwatt.git console: Cleanup console API Use a more generic console_init() instead of potato_uart_init(), and do the same for interrupt control. There should be no change in behaviour. Signed-off-by: Benjamin Herrenschmidt --- diff --git a/hello_world/hello_world.bin b/hello_world/hello_world.bin index ae4c4a8..dda2b66 100755 Binary files a/hello_world/hello_world.bin and b/hello_world/hello_world.bin differ diff --git a/hello_world/hello_world.c b/hello_world/hello_world.c index 6575667..b5d1ef2 100644 --- a/hello_world/hello_world.c +++ b/hello_world/hello_world.c @@ -7,7 +7,7 @@ int main(void) { - potato_uart_init(); + console_init(); puts(HELLO_WORLD); diff --git a/hello_world/hello_world.elf b/hello_world/hello_world.elf index e658438..d89e408 100755 Binary files a/hello_world/hello_world.elf and b/hello_world/hello_world.elf differ diff --git a/hello_world/hello_world.hex b/hello_world/hello_world.hex index 6098247..f799a45 100644 --- a/hello_world/hello_world.hex +++ b/hello_world/hello_world.hex @@ -514,67 +514,68 @@ e8010010ebc1fff0 7c0803a6ebe1fff8 3c4000014e800020 7c0802a63842a000 -3fe2fffffbe1fff8 -f80100103bff7240 -48000051f821ffd1 -7fe3fb7860000000 -60000000480001d5 -7fe3fb787c641b78 -600000004800017d -60000000480000ed -480001295463063e +f821ffe1f8010010 +6000000048000229 +386372783c62ffff +600000004800018d +60000000480000f9 +480001355463063e 4bffffec60000000 0100000000000000 -3c40000100000180 +3c40000100000080 3d20c0003842a000 6129200060000000 f922800079290020 612900203d20c000 7c0004ac79290020 3d40001c7d204eea -7d295392614a2000 -394a0018e9428000 -7c0004ac3929ffff +614a200079290600 +e94280007d295392 +3929ffff394a0018 +7d2057ea7c0004ac +000000004e800020 +0000000000000000 +3842a0003c400001 +419e00082fa40000 +6000000060630002 +39290020e9228000 +7c604fea7c0004ac +000000004e800020 +0000000000000000 +3842a0003c400001 +e922800060000000 +3929002039400000 +7d404fea7c0004ac +000000004e800020 +0000000000000000 +3842a0003c400001 +e922800060000000 +7c0004ac39290010 +712900017d204eea +e86280004082ffe8 +7c0004ac38630008 +5463063e7c601eea +000000004e800020 +0000000000000000 +3842a0003c400001 +e922800060000000 +7c0004ac39290010 +712900087d204eea +5469063e4082ffe8 +7c0004ace9428000 4e8000207d2057ea 0000000000000000 3c40000100000000 -600000003842a000 -394000ffe9228000 -7c0004ac39290020 -4e8000207d404fea -0000000000000000 -3c40000100000000 -600000003842a000 -39400000e9228000 -7c0004ac39290020 -4e8000207d404fea -0000000000000000 -3c40000100000000 -600000003842a000 -39290010e9228000 -7d204eea7c0004ac -4082ffe871290001 -38630008e8628000 -7c601eea7c0004ac -4e8000205463063e -0000000000000000 -3c40000100000000 -600000003842a000 -39290010e9228000 -7d204eea7c0004ac -4082ffe871290008 -7c0004ace9228000 -4e8000207c604fea -0000000000000000 -3c40000100000000 7c0802a63842a000 fbe1fff8fbc1fff0 -7c7f1b787fc32214 -f821ffd1f8010010 -409e000c7fbff040 -4bfffe0c38210030 -3bff0001887f0000 -4bffffe44bffff8d +f80100103bc3ffff +8ffe0001f821ffd1 +409e00102fbf0000 +3860000038210030 +2b9f000a4bfffe10 +3860000d409e000c +7fe3fb784bffff81 +4bffffd04bffff79 0100000000000000 3920000000000280 2f8a00007d4348ae @@ -582,5 +583,11 @@ f821ffd1f8010010 392900014e800020 000000004bffffe8 0000000000000000 +3842a0003c400001 +000000004bfffe1c +0000000000000000 +3842a0003c400001 +000000004bfffe68 +0000000000000000 6f57206f6c6c6548 -0000000a0d646c72 +000000000a646c72 diff --git a/include/console.h b/include/console.h index e871c67..78d0a86 100644 --- a/include/console.h +++ b/include/console.h @@ -1,8 +1,7 @@ #include -void potato_uart_init(void); -void potato_uart_irq_en(void); -void potato_uart_irq_dis(void); +void console_init(void); +void console_set_irq_en(bool rx_irq, bool tx_irq); int getchar(void); int putchar(int c); int puts(const char *str); diff --git a/include/microwatt_soc.h b/include/microwatt_soc.h index 77d5a58..8b69889 100644 --- a/include/microwatt_soc.h +++ b/include/microwatt_soc.h @@ -69,6 +69,8 @@ #define POTATO_CONSOLE_STATUS_TX_FULL 0x08 #define POTATO_CONSOLE_CLOCK_DIV 0x18 #define POTATO_CONSOLE_IRQ_EN 0x20 +#define POTATO_CONSOLE_IRQ_RX 0x01 +#define POTATO_CONSOLE_IRQ_TX 0x02 /* * Register definitionss for our standard (16550 style) UART diff --git a/lib/console.c b/lib/console.c index bce220e..892c76f 100644 --- a/lib/console.c +++ b/lib/console.c @@ -80,9 +80,15 @@ void potato_uart_init(void) potato_uart_reg_write(POTATO_CONSOLE_CLOCK_DIV, potato_uart_divisor(proc_freq, UART_FREQ)); } -void potato_uart_irq_en(void) +void potato_uart_set_irq_en(bool rx_irq, bool tx_irq) { - potato_uart_reg_write(POTATO_CONSOLE_IRQ_EN, 0xff); + uint64_t en = 0; + + if (rx_irq) + en |= POTATO_CONSOLE_IRQ_RX; + if (tx_irq) + en |= POTATO_CONSOLE_IRQ_TX; + potato_uart_reg_write(POTATO_CONSOLE_IRQ_EN, en); } void potato_uart_irq_dis(void) @@ -131,3 +137,13 @@ size_t strlen(const char *s) return len; } #endif + +void console_init(void) +{ + potato_uart_init(); +} + +void console_set_irq_en(bool rx_irq, bool tx_irq) +{ + potato_uart_set_irq_en(rx_irq, tx_irq); +} diff --git a/litedram/gen-src/sdram_init/main.c b/litedram/gen-src/sdram_init/main.c index dd3b507..19cc2ad 100644 --- a/litedram/gen-src/sdram_init/main.c +++ b/litedram/gen-src/sdram_init/main.c @@ -241,7 +241,7 @@ uint64_t main(void) bool try_flash = false; /* Init the UART */ - potato_uart_init(); + console_init(); printf("\n\nWelcome to Microwatt !\n\n"); diff --git a/rust_lib_demo/hello_world.c b/rust_lib_demo/hello_world.c index c8797fd..6c44be9 100644 --- a/rust_lib_demo/hello_world.c +++ b/rust_lib_demo/hello_world.c @@ -25,7 +25,7 @@ void init_bss() int main(void) { init_bss(); - potato_uart_init(); + console_init(); puts(HELLO_WORLD); diff --git a/tests/decrementer/decrementer.c b/tests/decrementer/decrementer.c index e6cff2c..7b1c345 100644 --- a/tests/decrementer/decrementer.c +++ b/tests/decrementer/decrementer.c @@ -25,7 +25,7 @@ int main(void) { int fail = 0; - potato_uart_init(); + console_init(); print_test_number(1); if (dec_test_1() != 0) { diff --git a/tests/illegal/illegal.c b/tests/illegal/illegal.c index af0c04b..fbd9634 100644 --- a/tests/illegal/illegal.c +++ b/tests/illegal/illegal.c @@ -23,7 +23,7 @@ int main(void) { int fail = 0; - potato_uart_init(); + console_init(); print_test_number(1); if (ill_test_1() != 0) { diff --git a/tests/misc/misc.c b/tests/misc/misc.c index 0b9079c..f96203e 100644 --- a/tests/misc/misc.c +++ b/tests/misc/misc.c @@ -24,7 +24,7 @@ int main(void) { int fail = 0; - potato_uart_init(); + console_init(); print_test_number(1); if (test_addpcis_1() != 0) { diff --git a/tests/mmu/mmu.c b/tests/mmu/mmu.c index a5d086b..b91a852 100644 --- a/tests/mmu/mmu.c +++ b/tests/mmu/mmu.c @@ -661,7 +661,7 @@ void do_test(int num, int (*test)(void)) int main(void) { - potato_uart_init(); + console_init(); init_mmu(); do_test(1, mmu_test_1); diff --git a/tests/privileged/privileged.c b/tests/privileged/privileged.c index 98c037c..154e9b4 100644 --- a/tests/privileged/privileged.c +++ b/tests/privileged/privileged.c @@ -228,7 +228,7 @@ void do_test(int num, int (*fn)(unsigned long)) int main(void) { - potato_uart_init(); + console_init(); init_mmu(); map(0x2000, 0x2000, REF | CHG | PERM_RD | PERM_EX); /* map code page */ map(0x7000, 0x7000, REF | CHG | PERM_RD | PERM_WR); /* map stack page */ diff --git a/tests/sc/sc.c b/tests/sc/sc.c index a705d19..94e17fa 100644 --- a/tests/sc/sc.c +++ b/tests/sc/sc.c @@ -23,7 +23,7 @@ int main(void) { int fail = 0; - potato_uart_init(); + console_init(); print_test_number(1); if (sc_test_1() != 0) { diff --git a/tests/xics/xics.c b/tests/xics/xics.c index a867744..97b6539 100644 --- a/tests/xics/xics.c +++ b/tests/xics/xics.c @@ -83,7 +83,7 @@ void ipi_isr(void) { void uart_isr(void) { debug_puts(UART); - potato_uart_irq_dis(); // disable interrupt to ack it + console_set_irq_en(false, false); isrs_run |= ISR_UART; } @@ -202,7 +202,7 @@ int xics_test_1(void) icp_write8(XICS_XIRR, 0x00); // mask all interrupts // trigger two interrupts - potato_uart_irq_en(); // cause serial interrupt + console_set_irq_en(true,true);// cause serial interrupt ics_write_xive(0x6, 0); // set source to prio 6 icp_write8(XICS_MFRR, 0x04); // cause ipi interrupt at prio 5 @@ -222,7 +222,7 @@ int xics_test_1(void) // cleanup icp_write8(XICS_XIRR, 0x00); // mask all interrupts - potato_uart_irq_dis(); + console_set_irq_en(false, false); ics_write_xive(0, 0xff); isrs_run = 0; @@ -242,7 +242,7 @@ int xics_test_2(void) assert(isrs_run == 0); // trigger both - potato_uart_irq_en(); // cause 0x500 interrupt + console_set_irq_en(true, true); icp_write8(XICS_MFRR, 0x05); // cause 0x500 interrupt delay(); @@ -250,7 +250,7 @@ int xics_test_2(void) // cleanup icp_write8(XICS_XIRR, 0x00); // mask all interrupts - potato_uart_irq_dis(); + console_set_irq_en(false, false); isrs_run = 0; return 0; @@ -307,7 +307,7 @@ int main(void) int i = 0; int (*t)(void); - potato_uart_init(); + console_init(); ipi_running = false; /* run the tests */