From 5be45ee70f9a854b0f839a59f8f8b261573893c8 Mon Sep 17 00:00:00 2001 From: milek7 Date: Thu, 31 Mar 2022 02:13:29 +0200 Subject: [PATCH] arm64: Map discovered UART into kernel space as device memory. Change-Id: I4af09410c29c5586b85e1e1eba5803c0b30a1b01 Reviewed-on: https://review.haiku-os.org/c/haiku/+/5272 Reviewed-by: Adrien Destugues Tested-by: Commit checker robot --- .../boot/platform/efi/arch/arm64/arch_mmu.cpp | 20 ++++++++++++------- .../arch/arm64/arch_vm_translation_map.cpp | 8 ++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/system/boot/platform/efi/arch/arm64/arch_mmu.cpp b/src/system/boot/platform/efi/arch/arm64/arch_mmu.cpp index 2f80c7fb18..1030e6befb 100644 --- a/src/system/boot/platform/efi/arch/arm64/arch_mmu.cpp +++ b/src/system/boot/platform/efi/arch/arm64/arch_mmu.cpp @@ -489,19 +489,25 @@ arch_mmu_generate_post_efi_page_tables(size_t memory_map_size, | currentMair.MaskOf(MAIR_NORMAL_WB)); } -/* TODO: Not an UART here... inspect dtb? - // identity mapping for the debug uart - map_range(0x09000000, 0x09000000, B_PAGE_SIZE, - ARMv8TranslationTableDescriptor::DefaultPeripheralAttribute - | currentMair.MaskOf(MAIR_DEVICE_nGnRnE)); -*/ - // TODO: We actually can only map physical RAM, mapping everything // could cause unwanted MMIO or bus errors on real hardware. map_range(KERNEL_PMAP_BASE, 0, KERNEL_PMAP_SIZE - 1, ARMv8TranslationTableDescriptor::DefaultCodeAttribute | currentMair.MaskOf(MAIR_NORMAL_WB)); + if (gKernelArgs.arch_args.uart.kind[0] != 0) { + // Map uart because we want to use it during early boot. + uint64 regs_start = gKernelArgs.arch_args.uart.regs.start; + uint64 regs_size = ROUNDUP(gKernelArgs.arch_args.uart.regs.size, B_PAGE_SIZE); + uint64 base = get_next_virtual_address(regs_size); + + map_range(base, regs_start, regs_size, + ARMv8TranslationTableDescriptor::DefaultPeripheralAttribute | + currentMair.MaskOf(MAIR_DEVICE_nGnRnE)); + + gKernelArgs.arch_args.uart.regs.start = base; + } + sort_address_ranges(gKernelArgs.virtual_allocated_range, gKernelArgs.num_virtual_allocated_ranges); diff --git a/src/system/kernel/arch/arm64/arch_vm_translation_map.cpp b/src/system/kernel/arch/arm64/arch_vm_translation_map.cpp index 1cd3b83d24..d310e2281b 100644 --- a/src/system/kernel/arch/arm64/arch_vm_translation_map.cpp +++ b/src/system/kernel/arch/arm64/arch_vm_translation_map.cpp @@ -96,6 +96,14 @@ arch_vm_translation_map_init_post_area(kernel_args* args) area_id area = vm_create_null_area(VMAddressSpace::KernelID(), "physical map area", &address, B_EXACT_ADDRESS, KERNEL_PMAP_SIZE, 0); + if (args->arch_args.uart.kind[0] != 0) { + // debug uart is already mapped by the efi loader + address = (void*)args->arch_args.uart.regs.start; + area_id area = vm_create_null_area(VMAddressSpace::KernelID(), + "debug uart map area", &address, B_EXACT_ADDRESS, + ROUNDUP(args->arch_args.uart.regs.size, B_PAGE_SIZE), 0); + } + return B_OK; }