From 7068c454852e76e6523b12f9e29adaaa459bcc0e Mon Sep 17 00:00:00 2001 From: Alexander von Gluck IV Date: Sat, 4 Sep 2021 16:47:10 -0500 Subject: [PATCH] system/uart: refactor debug_uart, fix arm uart * Drop ArchUART8260 layer to reduce complexity. It's whole existance in life was to adjust the mmio alignment. * Fold architecture mmio alignment into DebugUart * We could potentially pass a Init(int mmioAlignment) arg in the future if the macros get too messy. * Move Barrier code back a layer into DebugUART * Fixes the arm uart and EFI build Change-Id: I0f127d902993e9f6e6a03cac8c7c37c0363134bf Reviewed-on: https://review.haiku-os.org/c/haiku/+/4422 Reviewed-by: Alex von Gluck IV Reviewed-by: waddlesplash Tested-by: Commit checker robot --- .../private/kernel/arch/generic/debug_uart.h | 9 +- .../kernel/arch/generic/debug_uart_8250.h | 2 - src/system/boot/arch/arm/Jamfile | 3 +- src/system/boot/arch/ppc/Jamfile | 10 ++- src/system/boot/arch/riscv64/Jamfile | 1 + src/system/boot/arch/sparc/Jamfile | 10 ++- src/system/kernel/arch/arm/Jamfile | 2 +- src/system/kernel/arch/arm/arch_uart_8250.cpp | 82 ------------------- src/system/kernel/arch/generic/debug_uart.cpp | 43 ++++++++++ .../kernel/arch/generic/debug_uart_8250.cpp | 12 --- src/system/kernel/arch/ppc/Jamfile | 1 + src/system/kernel/arch/riscv64/Jamfile | 52 ++++++------ 12 files changed, 92 insertions(+), 135 deletions(-) delete mode 100644 src/system/kernel/arch/arm/arch_uart_8250.cpp create mode 100644 src/system/kernel/arch/generic/debug_uart.cpp diff --git a/headers/private/kernel/arch/generic/debug_uart.h b/headers/private/kernel/arch/generic/debug_uart.h index 3d2fae7e35..c6a660e454 100644 --- a/headers/private/kernel/arch/generic/debug_uart.h +++ b/headers/private/kernel/arch/generic/debug_uart.h @@ -40,12 +40,9 @@ public: bool Enabled() const { return fEnabled; } protected: - // default MMIO - virtual void Out8(int reg, uint8 value) - { *((uint8 *)Base() + reg) = value; } - virtual uint8 In8(int reg) - { return *((uint8 *)Base() + reg); } - virtual void Barrier() {} + virtual void Out8(int reg, uint8 value); + virtual uint8 In8(int reg); + virtual void Barrier(); private: addr_t fBase; diff --git a/headers/private/kernel/arch/generic/debug_uart_8250.h b/headers/private/kernel/arch/generic/debug_uart_8250.h index 45a06fd8f9..d04d56b358 100644 --- a/headers/private/kernel/arch/generic/debug_uart_8250.h +++ b/headers/private/kernel/arch/generic/debug_uart_8250.h @@ -34,8 +34,6 @@ public: void FlushTx(); void FlushRx(); - - virtual void Barrier(); }; diff --git a/src/system/boot/arch/arm/Jamfile b/src/system/boot/arch/arm/Jamfile index bc1cc0918b..f8541e5b13 100644 --- a/src/system/boot/arch/arm/Jamfile +++ b/src/system/boot/arch/arm/Jamfile @@ -17,7 +17,7 @@ local kernelLibArchObjects = local kernelArchSources = arch_elf.cpp - arch_uart_8250.cpp + arch_uart_pl011.cpp ; local kernelDebugSources = @@ -28,6 +28,7 @@ local kernelDebugSources = ; local kernelGenericDriverSources = + debug_uart.cpp debug_uart_8250.cpp ; diff --git a/src/system/boot/arch/ppc/Jamfile b/src/system/boot/arch/ppc/Jamfile index b83c57a6e5..44f81cb40b 100644 --- a/src/system/boot/arch/ppc/Jamfile +++ b/src/system/boot/arch/ppc/Jamfile @@ -6,14 +6,18 @@ local kernelLibArchObjects = memset.o ; +local kernelGenericDriverSources = + debug_uart.cpp + debug_uart_8250.cpp +; + local platform ; for platform in [ MultiBootSubDirSetup openfirmware ] { on $(platform) { DEFINES += _BOOT_MODE ; BootMergeObject [ FGristFiles boot_arch_$(TARGET_KERNEL_ARCH).o ] : - debug_uart_8250.cpp - #arch_uart_8250.cpp + $(kernelGenericDriverSources) arch_elf.cpp : # additional flags : @@ -24,7 +28,7 @@ for platform in [ MultiBootSubDirSetup openfirmware ] { SEARCH on [ FGristFiles arch_elf.cpp arch_uart_8250.cpp ] = [ FDirName $(HAIKU_TOP) src system kernel arch $(TARGET_KERNEL_ARCH) ] ; - SEARCH on [ FGristFiles debug_uart_8250.cpp ] + SEARCH on [ FGristFiles $(kernelGenericDriverSources) ] = [ FDirName $(HAIKU_TOP) src system kernel arch generic ] ; } } diff --git a/src/system/boot/arch/riscv64/Jamfile b/src/system/boot/arch/riscv64/Jamfile index ce45eb3870..313ed2b57e 100644 --- a/src/system/boot/arch/riscv64/Jamfile +++ b/src/system/boot/arch/riscv64/Jamfile @@ -22,6 +22,7 @@ local kernelArchDriverSources = ; local kernelGenericDriverSources = + debug_uart.cpp debug_uart_8250.cpp ; diff --git a/src/system/boot/arch/sparc/Jamfile b/src/system/boot/arch/sparc/Jamfile index 5ce2dbe955..c423d14463 100644 --- a/src/system/boot/arch/sparc/Jamfile +++ b/src/system/boot/arch/sparc/Jamfile @@ -5,14 +5,18 @@ local kernelLibArchObjects = memset.o ; +local kernelGenericDriverSources = + debug_uart.cpp + debug_uart_8250.cpp +; + local platform ; for platform in [ MultiBootSubDirSetup openfirmware ] { on $(platform) { DEFINES += _BOOT_MODE ; BootMergeObject [ FGristFiles boot_arch_$(TARGET_KERNEL_ARCH).o ] : - debug_uart_8250.cpp - #arch_uart_8250.cpp + $(kernelGenericDriverSources) arch_elf.cpp : # additional flags : @@ -23,7 +27,7 @@ for platform in [ MultiBootSubDirSetup openfirmware ] { SEARCH on [ FGristFiles arch_elf.cpp arch_uart_8250.cpp ] = [ FDirName $(HAIKU_TOP) src system kernel arch $(TARGET_KERNEL_ARCH) ] ; - SEARCH on [ FGristFiles debug_uart_8250.cpp ] + SEARCH on [ FGristFiles $(kernelGenericDriverSources) ] = [ FDirName $(HAIKU_TOP) src system kernel arch generic ] ; } } diff --git a/src/system/kernel/arch/arm/Jamfile b/src/system/kernel/arch/arm/Jamfile index e7eca39cee..5ca2d39c34 100644 --- a/src/system/kernel/arch/arm/Jamfile +++ b/src/system/kernel/arch/arm/Jamfile @@ -27,8 +27,8 @@ KernelMergeObject kernel_arch_arm.o : arch_asm.S # Serial UART and drivers + debug_uart.cpp debug_uart_8250.cpp - arch_uart_8250.cpp arch_uart_8250_omap.cpp arch_uart_pl011.cpp diff --git a/src/system/kernel/arch/arm/arch_uart_8250.cpp b/src/system/kernel/arch/arm/arch_uart_8250.cpp deleted file mode 100644 index ef3d06d0e7..0000000000 --- a/src/system/kernel/arch/arm/arch_uart_8250.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2011-2012 Haiku, Inc. All rights reserved. - * Distributed under the terms of the MIT License. - * - * Authors: - * François Revol, revol@free.fr - */ - - -#include -#include -#include -#include - - -class ArchUART8250 : public DebugUART8250 { -public: - ArchUART8250(addr_t base, int64 clock); - ~ArchUART8250(); - void InitEarly(); - - // ARM MMIO: on ARM the UART regs are aligned on 32bit - virtual void Out8(int reg, uint8 value); - virtual uint8 In8(int reg); -}; - - -ArchUART8250::ArchUART8250(addr_t base, int64 clock) - : - DebugUART8250(base, clock) -{ -} - - -ArchUART8250::~ArchUART8250() -{ -} - - -void -ArchUART8250::InitEarly() -{ - // Perform special hardware UART configuration -#warning TODO: Detect OMAP3 from fdt! -#if BOARD_CPU_OMAP3 - /* UART1 */ - RMWREG32(CM_FCLKEN1_CORE, 13, 1, 1); - RMWREG32(CM_ICLKEN1_CORE, 13, 1, 1); - - /* UART2 */ - RMWREG32(CM_FCLKEN1_CORE, 14, 1, 1); - RMWREG32(CM_ICLKEN1_CORE, 14, 1, 1); - - /* UART3 */ - RMWREG32(CM_FCLKEN_PER, 11, 1, 1); - RMWREG32(CM_ICLKEN_PER, 11, 1, 1); -#else -#warning INTITIALIZE UART!!!!! -#endif -} - - -void -ArchUART8250::Out8(int reg, uint8 value) -{ - *((uint8 *)Base() + reg * sizeof(uint32)) = value; -} - - -uint8 -ArchUART8250::In8(int reg) -{ - return *((uint8 *)Base() + reg * sizeof(uint32)); -} - - -DebugUART8250 *arch_get_uart_8250(addr_t base, int64 clock) -{ - static char buffer[sizeof(ArchUART8250)]; - ArchUART8250 *uart = new(buffer) ArchUART8250(base, clock); - return uart; -} diff --git a/src/system/kernel/arch/generic/debug_uart.cpp b/src/system/kernel/arch/generic/debug_uart.cpp new file mode 100644 index 0000000000..b6b54d877d --- /dev/null +++ b/src/system/kernel/arch/generic/debug_uart.cpp @@ -0,0 +1,43 @@ +/* + * Copyright 2006-2021, Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ + + +#include + + +void +DebugUART::Out8(int reg, uint8 value) +{ +#ifdef __ARM__ + // 32-bit aligned + *((uint8 *)Base() + reg * sizeof(uint32)) = value; +#else + *((uint8 *)Base() + reg) = value; +#endif +} + + +uint8 +DebugUART::In8(int reg) +{ +#ifdef __ARM__ + // 32-bit aligned + return *((uint8 *)Base() + reg * sizeof(uint32)); +#else + return *((uint8 *)Base() + reg); +#endif +} + + +void +DebugUART::Barrier() +{ + // Simple memory barriers +#if defined(__POWERPC__) + asm volatile("eieio; sync"); +#elif defined(__ARM__) + asm volatile ("" : : : "memory"); +#endif +} diff --git a/src/system/kernel/arch/generic/debug_uart_8250.cpp b/src/system/kernel/arch/generic/debug_uart_8250.cpp index 240c8047e5..7de1ad4703 100644 --- a/src/system/kernel/arch/generic/debug_uart_8250.cpp +++ b/src/system/kernel/arch/generic/debug_uart_8250.cpp @@ -177,18 +177,6 @@ DebugUART8250::FlushRx() } -void -DebugUART8250::Barrier() -{ - // Simple memory barriers -#if defined(__POWERPC__) - asm volatile("eieio; sync"); -#elif defined(__ARM__) - asm volatile ("" : : : "memory"); -#endif -} - - DebugUART8250* arch_get_uart_8250(addr_t base, int64 clock) { diff --git a/src/system/kernel/arch/ppc/Jamfile b/src/system/kernel/arch/ppc/Jamfile index 8af2ede337..490478bdb7 100644 --- a/src/system/kernel/arch/ppc/Jamfile +++ b/src/system/kernel/arch/ppc/Jamfile @@ -56,6 +56,7 @@ KernelMergeObject kernel_arch_ppc.o : arch_asm.S # serial uart + debug_uart.cpp debug_uart_8250.cpp # paging diff --git a/src/system/kernel/arch/riscv64/Jamfile b/src/system/kernel/arch/riscv64/Jamfile index 305bed6e73..af5b6f195f 100644 --- a/src/system/kernel/arch/riscv64/Jamfile +++ b/src/system/kernel/arch/riscv64/Jamfile @@ -6,30 +6,32 @@ UsePrivateKernelHeaders ; SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) generic ] ; KernelMergeObject kernel_arch_riscv64.o : - arch_asm.S - arch_traps.S - arch_commpage.cpp - arch_cpu.cpp - arch_debug.cpp - arch_debug_console.cpp - arch_elf.cpp - arch_int.cpp - arch_platform.cpp - arch_real_time_clock.cpp - arch_smp.cpp - arch_system_info.cpp - arch_timer.cpp - arch_thread.cpp - arch_user_debugger.cpp - arch_vm.cpp - arch_vm_translation_map.cpp - RISCV64VMTranslationMap.cpp - Htif.cpp - sbi_syscalls.S + arch_asm.S + arch_traps.S + arch_commpage.cpp + arch_cpu.cpp + arch_debug.cpp + arch_debug_console.cpp + arch_elf.cpp + arch_int.cpp + arch_platform.cpp + arch_real_time_clock.cpp + arch_smp.cpp + arch_system_info.cpp + arch_timer.cpp + arch_thread.cpp + arch_user_debugger.cpp + arch_vm.cpp + arch_vm_translation_map.cpp + RISCV64VMTranslationMap.cpp + Htif.cpp + sbi_syscalls.S - debug_uart_8250.cpp - arch_uart_sifive.cpp - : - $(TARGET_KERNEL_PIC_CCFLAGS) -Wno-unused - : + # Serial UART drivers + debug_uart.cpp + debug_uart_8250.cpp + arch_uart_sifive.cpp + : + $(TARGET_KERNEL_PIC_CCFLAGS) -Wno-unused + : ;