OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Dec 06, 2019 6:03 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Multiple CPUs on UEFI
PostPosted: Mon Dec 02, 2019 11:15 am 
Offline

Joined: Sat May 11, 2019 2:39 pm
Posts: 1
This ancient post is the first and the only thing that Google pulls out on this topic. I'm not really surprised - utilizing multiple CPUs is an extremely rare feature in hobby OSes.

Anyway, that thread left two of my questions unanswered.
    1. With UEFI, the bootloader starts off in protected mode with A20 enabled and 4 KB identity paging, as well as a system table pointer bundle that includes ACPI which can be used to discover other cores/CPUs. When I wake up a core myself, does the firmware boot it in protected mode with A20 open, or do I have to do GRUB's work myself for the rest of the cores?
    2. How do I place the entry point and the GPT in the first 1 MiB of memory without trespassing into UEFI land?

Any suggestions or example code of how to find and wake up other cores from EFI_Main()?


Top
 Profile  
 
 Post subject: Re: Multiple CPUs on UEFI
PostPosted: Mon Dec 02, 2019 12:21 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 1697
You're not finding any results because UEFI doesn't really change how you initialize multiple CPUs. You'll want to read the Multiprocessor Specification version 1.4 if you haven't already.


Top
 Profile  
 
 Post subject: Re: Multiple CPUs on UEFI
PostPosted: Mon Dec 02, 2019 1:43 pm 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 289
To expand upon Octo's answer: If you have access to UEFI, then you have access to the System Table. And with that, access to ACPI. And with that, access to the MADT, which tells you the APIC IDs of all enabled CPUs. And how to proceed from here is something you can read in the Intel SDM, volume 3A, chapter 8.4. Or else in the AMD APM volume 2 somewhere. In all brevity, you are expected to send an INIT IPI to the target processor, wait for 10 ms, send a SIPI to it, wait for 200 ┬Ás, check to see if the CPU started, if so, assume success, else send a second SIPI and wait up to 100 ms. If the processor still is not up, it's not coming. (I would send it another INIT IPI on failure, just in case the processor is somehow up and running something I didn't ask it to. INIT IPI should stop it from executing any instructions)

Initial state of the AP will be 16-bit mode, with most registers initialized to 0, including IP. CS will be xx00, where xx is the vector of the SIPI. From there you execute the usual trampoline to end up in your OS.

Since there is only one A20 gate in the system, it will be necessarily enabled already. However, MSRs are processor specific, and thus must be reloaded with their values as needed. This includes MTRRs, if you reprogram those. I have no idea what you want with the GPT in the first MB of memory. I have a normal and a debug trampoline, and even the debug trampoline is less than 3000 bytes. Since the initialization code takes at least one page, anyway, this is all you'll need.


Top
 Profile  
 
 Post subject: Re: Multiple CPUs on UEFI
PostPosted: Tue Dec 03, 2019 2:14 am 
Offline
Member
Member
User avatar

Joined: Mon Sep 03, 2018 2:25 am
Posts: 53
There is another way, UEFI also provides a service to boot up the APs. The MpService

I don't know if its widely supported, and if it doesn't exist you have to fallback to parsing the MADT or MP tables i guess


Top
 Profile  
 
 Post subject: Re: Multiple CPUs on UEFI
PostPosted: Tue Dec 03, 2019 7:22 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 1697
I don't think you can use that service as a substitute for the ACPI MADT, it doesn't give a whole lot of information about the APs.

You certainly can't use it to boot the APs:
UEFI Platform Initialization Specification wrote:
The Protocol is available only during boot time.
...
Modules that use this protocol must guarantee that all non-blocking mode requests on all APs have been completed before the UEFI event EFI_EVENT_LEGACY_BOOT_GUID or EFI_EVENT_GROUP_EXIT_BOOT_SERVICES is signaled.


Top
 Profile  
 
 Post subject: Re: Multiple CPUs on UEFI
PostPosted: Fri Dec 06, 2019 6:24 am 
Offline
Member
Member
User avatar

Joined: Sun Oct 18, 2009 5:47 pm
Posts: 192
Location: Alexandria, Egypt | Ottawa, Canada
Octocontrabass wrote:
I don't think you can use that service as a substitute for the ACPI MADT, it doesn't give a whole lot of information about the APs.

You certainly can't use it to boot the APs:
UEFI Platform Initialization Specification wrote:
The Protocol is available only during boot time.
...
Modules that use this protocol must guarantee that all non-blocking mode requests on all APs have been completed before the UEFI event EFI_EVENT_LEGACY_BOOT_GUID or EFI_EVENT_GROUP_EXIT_BOOT_SERVICES is signaled.

I think you still can use it at boot time in order to bring the APs to a known state (protected mode with your code running on the AP and waiting for an OS-specific IPI).

If I understand correctly, I would expect the boot-loader to use MpServices in order to execute a 'dispatching user-provided function' as explained in the header file. The user function could be a simple 32-bit or 64-bit piece of code that sends EFI_EVENT to the BSP then waits for an IPI that is specific to the OS.

The BSP (running the UEFI boot-loader) waits for the event to make sure that the AP is initialized. the bootloder then exits boot services and boots into the OS, which communicates the IPIs to the APs, executes the scheduler on them, then the APs have fun together.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot], MSN [Bot] and 20 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group