From 8795b4138edc8b2c3706043276558aa6ee4d939b Mon Sep 17 00:00:00 2001 From: songyanguang <345810377@qq.com> Date: Fri, 22 Nov 2024 14:10:46 +0800 Subject: [PATCH] Modify uart --- .../riscv/rv64gc/preboot_for_jh7110/boot.S | 5 ++++ .../hardkernel/mmu/riscv/rv64gc/bootmmu.c | 28 ++++++------------- .../uart_io_for_jh7110/include/ns16550.h | 2 +- .../riscv/rv64gc/uart_io_for_jh7110/ns16550.c | 28 +++++++------------ 4 files changed, 25 insertions(+), 38 deletions(-) diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/arch/riscv/rv64gc/preboot_for_jh7110/boot.S b/Ubiquitous/XiZi_AIoT/hardkernel/arch/riscv/rv64gc/preboot_for_jh7110/boot.S index 1b0c6b54e..cd19af272 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/arch/riscv/rv64gc/preboot_for_jh7110/boot.S +++ b/Ubiquitous/XiZi_AIoT/hardkernel/arch/riscv/rv64gc/preboot_for_jh7110/boot.S @@ -28,6 +28,10 @@ _boot_start: csrw CSR_IE, zero csrw CSR_IP, zero + j primary_cpu_init + +/* +switch_mode: csrr t0, sstatus srli t0, t0, 8 andi t0, t0, 1 @@ -43,6 +47,7 @@ _boot_start: continue_execution: j primary_cpu_init +*/ primary_cpu_init: la t0, boot_start_addr diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/mmu/riscv/rv64gc/bootmmu.c b/Ubiquitous/XiZi_AIoT/hardkernel/mmu/riscv/rv64gc/bootmmu.c index 3c674498e..db1385a0c 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/mmu/riscv/rv64gc/bootmmu.c +++ b/Ubiquitous/XiZi_AIoT/hardkernel/mmu/riscv/rv64gc/bootmmu.c @@ -59,15 +59,10 @@ extern uint64_t kernel_data_begin[]; #define IDX_MASK (0b111111111) #define L3_PDE_INDEX(idx) ((idx << LEVEL3_PDE_SHIFT) & L3_IDX_MASK) -#define _PAGE_KERNEL (_PAGE_READ \ - | _PAGE_WRITE \ - | _PAGE_PRESENT \ - | _PAGE_ACCESSED \ - | _PAGE_DIRTY \ - | _PAGE_GLOBAL) -#define PAGE_KERNEL (_PAGE_KERNEL) -#define PAGE_KERNEL_READ (_PAGE_KERNEL & ~_PAGE_WRITE) -#define PAGE_KERNEL_EXEC (_PAGE_KERNEL | _PAGE_EXEC) +#define _PAGE_KERNEL (_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC | _PAGE_ACCESSED | _PAGE_GLOBAL | _PAGE_DIRTY) +#define PAGE_KERNEL (_PAGE_KERNEL) +#define PAGE_KERNEL_READ (_PAGE_KERNEL & ~_PAGE_WRITE) +#define PAGE_KERNEL_EXEC (_PAGE_KERNEL | _PAGE_EXEC) // clang-format on uint64_t boot_l2pgdir[NUM_LEVEL2_PDE] __attribute__((aligned(0x1000))) = { 0 }; @@ -125,15 +120,11 @@ static inline void local_flush_tlb_all(void) static void load_boot_pgdir() { - unsigned long satp_val = (unsigned long)(((uintptr_t)boot_l2pgdir >> PAGE_SHIFT) | SATP_MODE); - unsigned long status; + unsigned long satp_val = 0; - status = csr_read(CSR_STATUS); - if( !(status & 0x100) ) { - _debug_uart_printascii("current is not S mode\n"); - } -#if 0 //to debug - csr_write(CSR_SATP, ((uintptr_t)boot_l2pgdir >> PAGE_SHIFT) | SATP_MODE); + satp_val = (unsigned long)(((uintptr_t)boot_l2pgdir >> PAGE_SHIFT) | SATP_MODE); +#if 1 //to debug + csr_write(CSR_SATP, satp_val); #endif } @@ -141,12 +132,11 @@ extern void main(void); static bool _bss_inited = false; void bootmain() { - _debug_uart_init(); + _debug_uart_phymem_init(); _debug_uart_printascii("bootmain start.\n"); build_boot_pgdir(); load_boot_pgdir(); -// _debug_uart_base_map(); _debug_uart_printascii("boot pgdir success\n"); __asm__ __volatile__("addi sp, sp, %0" ::"i"(KERN_OFFSET)); diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/uart/riscv/rv64gc/uart_io_for_jh7110/include/ns16550.h b/Ubiquitous/XiZi_AIoT/hardkernel/uart/riscv/rv64gc/uart_io_for_jh7110/include/ns16550.h index 8f2900357..39788ceb6 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/uart/riscv/rv64gc/uart_io_for_jh7110/include/ns16550.h +++ b/Ubiquitous/XiZi_AIoT/hardkernel/uart/riscv/rv64gc/uart_io_for_jh7110/include/ns16550.h @@ -214,6 +214,6 @@ void _debug_uart_init(void); void _debug_uart_putc(int ch); int _debug_uart_getc(void); void _debug_uart_printascii(const char *str); -void _debug_uart_base_map(void); +void _debug_uart_phymem_init(void); #endif /* __ns16550_h */ diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/uart/riscv/rv64gc/uart_io_for_jh7110/ns16550.c b/Ubiquitous/XiZi_AIoT/hardkernel/uart/riscv/rv64gc/uart_io_for_jh7110/ns16550.c index 85ed50944..9fa44ee17 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/uart/riscv/rv64gc/uart_io_for_jh7110/ns16550.c +++ b/Ubiquitous/XiZi_AIoT/hardkernel/uart/riscv/rv64gc/uart_io_for_jh7110/ns16550.c @@ -9,6 +9,7 @@ struct ns16550 g_ns16550_com_port = {0}; struct ns16550_plat g_ns16550_plat = {0}; +unsigned long g_ns16550_uart_base = {0}; #define CONFIG_SYS_NS16550_UART_BASE 0x10000000 #define CONFIG_BAUDRATE 115200 @@ -80,7 +81,7 @@ static uint32_t ns16550_getfcr(struct ns16550 *port) (unsigned char *)addr - (unsigned char *)com_port) /* Divide positive dividend by positive divisor and round to closest integer. */ -#define DIV_ROUND_CLOSEST(x, divisor) \ +#define DIV_ROUND_CLOSEST(x, divisor) \ (((x) + ((divisor) / 2)) / (divisor)) int ns16550_calc_divisor(struct ns16550 *port, int clock, int baudrate) @@ -134,22 +135,12 @@ int ns16550_tstc(struct ns16550 *com_port) return (serial_in(&com_port->lsr) & UART_LSR_DR) != 0; } - -static int ns16550_serial_assign_base(struct ns16550_plat *plat, unsigned long base) -{ - plat->base = base; - return 0; -} - - static void ns16550_plat_init(void) { struct ns16550_plat *plat = &g_ns16550_plat; - unsigned long addr; - addr = CONFIG_SYS_NS16550_UART_BASE; - ns16550_serial_assign_base(plat, addr); /* refer jh7110 u-boot/arch/riscv/dts/jh7110.dtsi */ + plat->base = g_ns16550_uart_base; plat->reg_offset = 0; plat->reg_shift = 2; plat->reg_width = 4; @@ -181,19 +172,20 @@ void _debug_uart_init(void) { int baudrate = CONFIG_BAUDRATE; + g_ns16550_uart_base = CONFIG_SYS_NS16550_UART_BASE_MAP; ns16550_serial_init(); ns16550_serial_setbrg(baudrate); _debug_uart_printascii("_debug_uart_init success.\n"); } -void _debug_uart_base_map(void) +void _debug_uart_phymem_init(void) { - struct ns16550_plat *plat = &g_ns16550_plat; - unsigned long addr; + int baudrate = CONFIG_BAUDRATE; - addr = CONFIG_SYS_NS16550_UART_BASE_MAP; - ns16550_serial_assign_base(plat, addr); - _debug_uart_printascii("_debug_uart_init_mapped success.\n"); + g_ns16550_uart_base = CONFIG_SYS_NS16550_UART_BASE; + ns16550_serial_init(); + ns16550_serial_setbrg(baudrate); + _debug_uart_printascii("_debug_uart_phymem_init success.\n"); } void _debug_uart_putc(int ch)