smp: Remove hacks needed for stivale

This commit is contained in:
mintsuki 2022-09-14 14:54:55 +02:00
parent 08b004600a
commit 5b5f768360
3 changed files with 31 additions and 61 deletions

View File

@ -553,7 +553,7 @@ FEAT_START
EFI_CONFIGURATION_TABLE *cur_table = &gST->ConfigurationTable[i]; EFI_CONFIGURATION_TABLE *cur_table = &gST->ConfigurationTable[i];
if (memcmp(&cur_table->VendorGuid, &dtb_guid, sizeof(EFI_GUID)) == 0) { if (memcmp(&cur_table->VendorGuid, &dtb_guid, sizeof(EFI_GUID)) == 0) {
struct limine_dtb_response *dtb_response = struct limine_dtb_response *dtb_response =
ext_mem_alloc(sizeof(struct limine_dtb_response)); ext_mem_alloc(sizeof(struct limine_dtb_response));
dtb_response->dtb_ptr = reported_addr((void *)cur_table->VendorTable); dtb_response->dtb_ptr = reported_addr((void *)cur_table->VendorTable);
dtb_request->response = reported_addr(dtb_response); dtb_request->response = reported_addr(dtb_response);
@ -878,21 +878,18 @@ FEAT_START
break; // next feature break; // next feature
} }
struct limine_smp_info *smp_array; struct limine_smp_info *smp_info;
struct smp_information *smp_info;
size_t cpu_count; size_t cpu_count;
#if defined (__x86_64__) || defined (__i386__) #if defined (__x86_64__) || defined (__i386__)
uint32_t bsp_lapic_id; uint32_t bsp_lapic_id;
smp_info = init_smp(0, (void **)&smp_array, smp_info = init_smp(&cpu_count, &bsp_lapic_id,
&cpu_count, &bsp_lapic_id,
true, want_5lv, true, want_5lv,
pagemap, smp_request->flags & LIMINE_SMP_X2APIC, nx_available, pagemap, smp_request->flags & LIMINE_SMP_X2APIC, nx_available,
direct_map_offset, true); direct_map_offset, true);
#elif defined (__aarch64__) #elif defined (__aarch64__)
uint64_t bsp_mpidr; uint64_t bsp_mpidr;
smp_info = init_smp(0, (void **)&smp_array, smp_info = init_smp(&cpu_count, &bsp_mpidr,
&cpu_count, &bsp_mpidr,
pagemap, LIMINE_MAIR(fb_attr), LIMINE_TCR(tsz, pa), LIMINE_SCTLR); pagemap, LIMINE_MAIR(fb_attr), LIMINE_TCR(tsz, pa), LIMINE_SCTLR);
#else #else
#error Unknown architecture #error Unknown architecture
@ -904,7 +901,7 @@ FEAT_START
for (size_t i = 0; i < cpu_count; i++) { for (size_t i = 0; i < cpu_count; i++) {
void *cpu_stack = ext_mem_alloc(stack_size) + stack_size; void *cpu_stack = ext_mem_alloc(stack_size) + stack_size;
smp_info[i].stack_addr = reported_addr(cpu_stack + stack_size); smp_info[i].reserved = reported_addr(cpu_stack + stack_size);
} }
struct limine_smp_response *smp_response = struct limine_smp_response *smp_response =
@ -921,7 +918,7 @@ FEAT_START
uint64_t *smp_list = ext_mem_alloc(cpu_count * sizeof(uint64_t)); uint64_t *smp_list = ext_mem_alloc(cpu_count * sizeof(uint64_t));
for (size_t i = 0; i < cpu_count; i++) { for (size_t i = 0; i < cpu_count; i++) {
smp_list[i] = reported_addr(&smp_array[i]); smp_list[i] = reported_addr(&smp_info[i]);
} }
smp_response->cpu_count = cpu_count; smp_response->cpu_count = cpu_count;

View File

@ -11,6 +11,8 @@
#include <sys/gdt.h> #include <sys/gdt.h>
#include <mm/vmm.h> #include <mm/vmm.h>
#include <mm/pmm.h> #include <mm/pmm.h>
#define LIMINE_NO_POINTERS
#include <limine.h>
struct madt { struct madt {
struct sdt header; struct sdt header;
@ -74,7 +76,7 @@ struct trampoline_passed_info {
} __attribute__((packed)); } __attribute__((packed));
static bool smp_start_ap(uint32_t lapic_id, struct gdtr *gdtr, static bool smp_start_ap(uint32_t lapic_id, struct gdtr *gdtr,
struct smp_information *info_struct, struct limine_smp_info *info_struct,
bool longmode, bool lv5, uint32_t pagemap, bool longmode, bool lv5, uint32_t pagemap,
bool x2apic, bool nx, uint64_t hhdm, bool wp) { bool x2apic, bool nx, uint64_t hhdm, bool wp) {
// Prepare the trampoline // Prepare the trampoline
@ -132,9 +134,7 @@ static bool smp_start_ap(uint32_t lapic_id, struct gdtr *gdtr,
return false; return false;
} }
struct smp_information *init_smp(size_t header_hack_size, struct limine_smp_info *init_smp(size_t *cpu_count,
void **header_ptr,
size_t *cpu_count,
uint32_t *_bsp_lapic_id, uint32_t *_bsp_lapic_id,
bool longmode, bool longmode,
bool lv5, bool lv5,
@ -213,9 +213,7 @@ struct smp_information *init_smp(size_t header_hack_size,
} }
} }
*header_ptr = ext_mem_alloc( struct limine_smp_info *ret = ext_mem_alloc(max_cpus * sizeof(struct limine_smp_info));
header_hack_size + max_cpus * sizeof(struct smp_information));
struct smp_information *ret = *header_ptr + header_hack_size;
*cpu_count = 0; *cpu_count = 0;
// Try to start all APs // Try to start all APs
@ -231,10 +229,10 @@ struct smp_information *init_smp(size_t header_hack_size,
if (!((lapic->flags & 1) ^ ((lapic->flags >> 1) & 1))) if (!((lapic->flags & 1) ^ ((lapic->flags >> 1) & 1)))
continue; continue;
struct smp_information *info_struct = &ret[*cpu_count]; struct limine_smp_info *info_struct = &ret[*cpu_count];
info_struct->acpi_processor_uid = lapic->acpi_processor_uid; info_struct->processor_id = lapic->acpi_processor_uid;
info_struct->lapic_id = lapic->lapic_id; info_struct->lapic_id = lapic->lapic_id;
// Do not try to restart the BSP // Do not try to restart the BSP
if (lapic->lapic_id == bsp_lapic_id) { if (lapic->lapic_id == bsp_lapic_id) {
@ -268,10 +266,10 @@ struct smp_information *init_smp(size_t header_hack_size,
if (!((x2lapic->flags & 1) ^ ((x2lapic->flags >> 1) & 1))) if (!((x2lapic->flags & 1) ^ ((x2lapic->flags >> 1) & 1)))
continue; continue;
struct smp_information *info_struct = &ret[*cpu_count]; struct limine_smp_info *info_struct = &ret[*cpu_count];
info_struct->acpi_processor_uid = x2lapic->acpi_processor_uid; info_struct->processor_id = x2lapic->acpi_processor_uid;
info_struct->lapic_id = x2lapic->x2apic_id; info_struct->lapic_id = x2lapic->x2apic_id;
// Do not try to restart the BSP // Do not try to restart the BSP
if (x2lapic->x2apic_id == bsp_x2apic_id) { if (x2lapic->x2apic_id == bsp_x2apic_id) {
@ -325,7 +323,7 @@ enum {
static uint32_t psci_cpu_on = 0xC4000003; static uint32_t psci_cpu_on = 0xC4000003;
static bool try_start_ap(int boot_method, uint64_t method_ptr, static bool try_start_ap(int boot_method, uint64_t method_ptr,
struct smp_information *info_struct, struct limine_smp_info *info_struct,
uint64_t ttbr0, uint64_t ttbr1, uint64_t mair, uint64_t ttbr0, uint64_t ttbr1, uint64_t mair,
uint64_t tcr, uint64_t sctlr) { uint64_t tcr, uint64_t sctlr) {
// Prepare the trampoline // Prepare the trampoline
@ -350,7 +348,7 @@ static bool try_start_ap(int boot_method, uint64_t method_ptr,
passed_info->smp_tpl_tcr = tcr; passed_info->smp_tpl_tcr = tcr;
passed_info->smp_tpl_sctlr = sctlr; passed_info->smp_tpl_sctlr = sctlr;
// Cache coherency between the I-Cache and D-Cache is not guaranteed by the // Cache coherency between the I-Cache and D-Cache is not guaranteed by the
// architecture and as such we must perform I-Cache invalidation. // architecture and as such we must perform I-Cache invalidation.
// Additionally, the newly-booted AP may have caches disabled which implies // Additionally, the newly-booted AP may have caches disabled which implies
// it possibly does not see our cache contents either. // it possibly does not see our cache contents either.
@ -427,9 +425,7 @@ static bool try_start_ap(int boot_method, uint64_t method_ptr,
return false; return false;
} }
static struct smp_information *try_acpi_smp(size_t header_hack_size, static struct limine_smp_info *try_acpi_smp(size_t *cpu_count,
void **header_ptr,
size_t *cpu_count,
uint64_t *_bsp_mpidr, uint64_t *_bsp_mpidr,
pagemap_t pagemap, pagemap_t pagemap,
uint64_t mair, uint64_t mair,
@ -459,7 +455,7 @@ static struct smp_information *try_acpi_smp(size_t header_hack_size,
uint64_t bsp_mpidr; uint64_t bsp_mpidr;
asm volatile ("mrs %0, mpidr_el1" : "=r"(bsp_mpidr)); asm volatile ("mrs %0, mpidr_el1" : "=r"(bsp_mpidr));
// This bit is Res1 in the system reg, but not included in the MPIDR from MADT // This bit is Res1 in the system reg, but not included in the MPIDR from MADT
bsp_mpidr &= ~((uint64_t)1 << 31); bsp_mpidr &= ~((uint64_t)1 << 31);
*_bsp_mpidr = bsp_mpidr; *_bsp_mpidr = bsp_mpidr;
@ -488,9 +484,7 @@ static struct smp_information *try_acpi_smp(size_t header_hack_size,
} }
} }
*header_ptr = ext_mem_alloc( struct limine_smp_info *ret = ext_mem_alloc(max_cpus * sizeof(struct limine_smp_info));
header_hack_size + max_cpus * sizeof(struct smp_information));
struct smp_information *ret = *header_ptr + header_hack_size;
*cpu_count = 0; *cpu_count = 0;
// Try to start all APs // Try to start all APs
@ -506,7 +500,7 @@ static struct smp_information *try_acpi_smp(size_t header_hack_size,
if (!(gicc->flags & 1)) if (!(gicc->flags & 1))
continue; continue;
struct smp_information *info_struct = &ret[*cpu_count]; struct limine_smp_info *info_struct = &ret[*cpu_count];
info_struct->acpi_processor_uid = gicc->acpi_uid; info_struct->acpi_processor_uid = gicc->acpi_uid;
info_struct->gic_iface_no = gicc->iface_no; info_struct->gic_iface_no = gicc->iface_no;
@ -540,22 +534,20 @@ static struct smp_information *try_acpi_smp(size_t header_hack_size,
return ret; return ret;
} }
struct smp_information *init_smp(size_t header_hack_size, struct limine_smp_info *init_smp(size_t *cpu_count,
void **header_ptr,
size_t *cpu_count,
uint64_t *bsp_mpidr, uint64_t *bsp_mpidr,
pagemap_t pagemap, pagemap_t pagemap,
uint64_t mair, uint64_t mair,
uint64_t tcr, uint64_t tcr,
uint64_t sctlr) { uint64_t sctlr) {
struct smp_information *info = NULL; struct limine_smp_info *info = NULL;
//if (dtb_is_present() && (info = try_dtb_smp(header_hack_size, header_ptr, cpu_count, //if (dtb_is_present() && (info = try_dtb_smp(cpu_count,
// _bsp_iface_no, pagemap, mair, tcr, sctlr))) // _bsp_iface_no, pagemap, mair, tcr, sctlr)))
// return info; // return info;
// No RSDP means no ACPI // No RSDP means no ACPI
if (acpi_get_rsdp() && (info = try_acpi_smp(header_hack_size, header_ptr, cpu_count, if (acpi_get_rsdp() && (info = try_acpi_smp(cpu_count,
bsp_mpidr, pagemap, mair, tcr, sctlr))) bsp_mpidr, pagemap, mair, tcr, sctlr)))
return info; return info;

View File

@ -5,20 +5,12 @@
#include <stddef.h> #include <stddef.h>
#include <stdbool.h> #include <stdbool.h>
#include <mm/vmm.h> #include <mm/vmm.h>
#define LIMINE_NO_POINTERS
#include <limine.h>
#if defined (__x86_64__) || defined (__i386__) #if defined (__x86_64__) || defined (__i386__)
struct smp_information { struct limine_smp_info *init_smp(size_t *cpu_count,
uint32_t acpi_processor_uid;
uint32_t lapic_id;
uint64_t stack_addr;
uint64_t goto_address;
uint64_t extra_argument;
} __attribute__((packed));
struct smp_information *init_smp(size_t header_hack_size,
void **header_ptr,
size_t *cpu_count,
uint32_t *_bsp_lapic_id, uint32_t *_bsp_lapic_id,
bool longmode, bool longmode,
bool lv5, bool lv5,
@ -30,18 +22,7 @@ struct smp_information *init_smp(size_t header_hack_size,
#elif defined (__aarch64__) #elif defined (__aarch64__)
struct smp_information { struct limine_smp_info *init_smp(size_t *cpu_count,
uint32_t acpi_processor_uid;
uint32_t gic_iface_no;
uint64_t mpidr;
uint64_t stack_addr;
uint64_t goto_address;
uint64_t extra_argument;
} __attribute__((packed));
struct smp_information *init_smp(size_t header_hack_size,
void **header_ptr,
size_t *cpu_count,
uint64_t *bsp_mpidr, uint64_t *bsp_mpidr,
pagemap_t pagemap, pagemap_t pagemap,
uint64_t mair, uint64_t mair,