[haiku-commits] BRANCH jessicah-github.efi.master [a8f713d18562] src/system/boot/platform/efi

  • From: jessicah-github.efi.master <community@xxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 18 Sep 2015 05:16:58 +0200 (CEST)

added 1 changeset to branch 'refs/remotes/jessicah-github/efi.master'
old head: ea64a5d823a66754bab409ed99a90eaadffa79cf
new head: a8f713d1856212dedef3c7f2b0e767261e6f2155
overview: https://github.com/jessicah/haiku/compare/ea64a5d823a6...a8f713d18562

----------------------------------------------------------------------------

a8f713d18562: UEFI: working SMP on actual hardware now

On at least one machine, we were trying to copy the SMP
trampoline code over top of ACPI NVS!

Interestingly, Haiku now fails to load all the device
drivers... so not quite getting to the Desktop now :(

[ Jessica Hamilton <jessica.l.hamilton@xxxxxxxxx> ]

----------------------------------------------------------------------------

Commit: a8f713d1856212dedef3c7f2b0e767261e6f2155
Author: Jessica Hamilton <jessica.l.hamilton@xxxxxxxxx>
Date: Fri Sep 18 03:03:42 2015 UTC

----------------------------------------------------------------------------

5 files changed, 25 insertions(+), 10 deletions(-)
src/system/boot/platform/efi/Jamfile | 2 +-
src/system/boot/platform/efi/mmu.cpp | 2 +-
src/system/boot/platform/efi/smp.cpp | 22 ++++++++++++++--------
src/system/boot/platform/efi/smp_trampoline.S | 1 +
src/system/boot/platform/efi/start.cpp | 8 ++++++++

----------------------------------------------------------------------------

diff --git a/src/system/boot/platform/efi/Jamfile
b/src/system/boot/platform/efi/Jamfile
index 4033224..f42af8b 100644
--- a/src/system/boot/platform/efi/Jamfile
+++ b/src/system/boot/platform/efi/Jamfile
@@ -9,7 +9,7 @@ UsePrivateHeaders [ FDirName kernel boot platform efi arch
$(TARGET_ARCH) ] ;
local defines = _BOOT_MODE GNU_EFI_USE_MS_ABI _BOOT_PLATFORM_efi ;
defines = [ FDefines $(defines) ] ;
SubDirCcFlags $(defines) ;
- SubDirC++Flags $(defines) -fno-rtti ;
+ SubDirC++Flags $(defines) -fno-rtti -std=c++11 ;
}

local efi_glue_src =
diff --git a/src/system/boot/platform/efi/mmu.cpp
b/src/system/boot/platform/efi/mmu.cpp
index 3cb2cfa..24d68ae 100644
--- a/src/system/boot/platform/efi/mmu.cpp
+++ b/src/system/boot/platform/efi/mmu.cpp
@@ -342,7 +342,7 @@ mmu_map_physical_memory(addr_t physicalAddress, size_t
size, EFI_MEMORY_TYPE fla
if (physicalAddress + size > (512ull * 1024 * 1024 * 1024))
panic("Can't currently support more than 512GB of RAM!");

- dprintf("mmu_map_physical_memory: AllocatePages @ %lx, %u pages\n",
physicalAddress, aligned_size / B_PAGE_SIZE);
+ dprintf("mmu_map_physical_memory: AllocatePages @ %lx, %" B_PRIuSIZE "
pages\n", physicalAddress, aligned_size / B_PAGE_SIZE);
EFI_STATUS status =
kBootServices->AllocatePages(AllocateAddress,
EfiACPIReclaimMemory, aligned_size / B_PAGE_SIZE, &physicalAddress);
if (status != EFI_SUCCESS) {
diff --git a/src/system/boot/platform/efi/smp.cpp
b/src/system/boot/platform/efi/smp.cpp
index 4cc38f6..2096c6b 100644
--- a/src/system/boot/platform/efi/smp.cpp
+++ b/src/system/boot/platform/efi/smp.cpp
@@ -31,7 +31,7 @@


// See comments at the end of smp_boot_other_cpus()
-#define NO_SMP 1
+#define NO_SMP 0

#define TRACE_SMP
#ifdef TRACE_SMP
@@ -307,13 +307,16 @@ smp_boot_other_cpus(uint32 pml4, uint32 gdtr64, uint64
kernel_entry)
// allocate a stack and a code area for the smp trampoline
// (these have to be < 1M physical, 0xa0000-0xfffff is reserved by the
BIOS,
// and when PXE services are used, the 0x8d000-0x9ffff is also reserved)
-#ifdef _PXE_ENV
- uint64 trampolineCode = 0x8b000;
- uint64 trampolineStack = 0x8c000;
-#else
- uint64 trampolineCode = 0x9f000;
- uint64 trampolineStack = 0x9e000;
-#endif
+
+ // Interestingly, found some of the ranges above used by ACPI and/or
UEFI,
+ // e.g. in one case, we were trying to write to a location mapped as
+ // ACPI Non-Volatile Storage by UEFI!
+
+ // Perhaps we should just iterate over the provided memory map to find a
+ // suitable block of memory to use, since our trampoline code, unlike
the
+ // bios_ia32 version, is actually relocatable...
+ uint64 trampolineCode = 0x9000;
+ uint64 trampolineStack = 0x8000;

// copy the trampoline code over
TRACE(("copying the trampoline code to %p from %p\n",
(char*)trampolineCode, (const void*)&smp_trampoline));
@@ -348,6 +351,7 @@ smp_boot_other_cpus(uint32 pml4, uint32 gdtr64, uint64
kernel_entry)
(uint32 *)(trampolineCode + (uint64)smp_trampoline_args
- (uint64)smp_trampoline);
dprintf("%d: trampoline args value = %x\n", i, *args_ptr);
*args_ptr = (uint32)(uint64)args;
+ dprintf("%d: trampoline args value now = %x\n", i, *args_ptr);

/* clear apic errors */
dprintf("%d: clear apic errors\n", i);
@@ -424,12 +428,14 @@ smp_boot_other_cpus(uint32 pml4, uint32 gdtr64, uint64
kernel_entry)
// Wait for the trampoline code to clear the final stack
location.
// This serves as a notification for us that it has loaded the
address
// and it is safe for us to overwrite it to trampoline the next
CPU.
+ dprintf("%d: wait for trampoline code to finish...\n", i);
while (args->sentinel != 0) {
// On actual hardware, this is failing for some reason.
Perhaps
// we need to use a better location for the trampoline
code?
// Either way, it never succeeds, so defined NO_SMP for
now.
spin(1000);
}
+ dprintf("%d: AP cpu booted!\n", i);
}

TRACE(("done trampolining\n"));
diff --git a/src/system/boot/platform/efi/smp_trampoline.S
b/src/system/boot/platform/efi/smp_trampoline.S
index 48cebf4..cd9906f 100644
--- a/src/system/boot/platform/efi/smp_trampoline.S
+++ b/src/system/boot/platform/efi/smp_trampoline.S
@@ -84,6 +84,7 @@ trampoline_32:
popl %eax
lgdtl (%eax)

+
// Jump into the 64-bit code segment.
pushl $KERNEL_CODE_SELECTOR
leal (.Llmode - smp_trampoline)(%ebx), %eax
diff --git a/src/system/boot/platform/efi/start.cpp
b/src/system/boot/platform/efi/start.cpp
index 8733f22..ccb469a 100644
--- a/src/system/boot/platform/efi/start.cpp
+++ b/src/system/boot/platform/efi/start.cpp
@@ -219,12 +219,16 @@ platform_start_kernel(void)
panic("Unable to allocate memory map.");
}

+ dprintf("malloc'd memory map of %lu bytes\n", actual_memory_map_size);
+
// Read (and print) the memory map.
memory_map_size = actual_memory_map_size;
if (kBootServices->GetMemoryMap(&memory_map_size, memory_map, &map_key,
&descriptor_size, &descriptor_version) != EFI_SUCCESS) {
panic("Unable to fetch system memory map.");
}

+ dprintf("updated memory map size to %lu bytes\n", memory_map_size);
+
addr_t addr = (addr_t)memory_map;
dprintf("System provided memory map:\n");
for (UINTN i = 0; i < memory_map_size / descriptor_size; ++i) {
@@ -257,10 +261,12 @@ platform_start_kernel(void)
break;
}

+ dprintf("current memory map size = %lu bytes, capacity = %lu
bytes\n", memory_map_size, actual_memory_map_size);
memory_map_size = actual_memory_map_size;
if (kBootServices->GetMemoryMap(&memory_map_size, memory_map,
&map_key, &descriptor_size, &descriptor_version) != EFI_SUCCESS) {
panic("Unable to fetch system memory map.");
}
+ dprintf("updated memory map size to %lu bytes\n",
memory_map_size);
}
// We're on our own now...

@@ -268,6 +274,8 @@ platform_start_kernel(void)
stdout = NULL;
stderr = NULL;

+ dprintf("framebuffer @ %p\n",
(void*)gKernelArgs.frame_buffer.physical_buffer.start);
+
// Update EFI, generate final kernel physical memory map, etc.
dprintf("mmu_post_efi_setup...\n");
mmu_post_efi_setup(memory_map_size, memory_map, descriptor_size,
descriptor_version);


Other related posts:

  • » [haiku-commits] BRANCH jessicah-github.efi.master [a8f713d18562] src/system/boot/platform/efi - jessicah-github . efi . master