kernel: implement cpu IDs and per-cpu variables
This commit is contained in:
@@ -3,10 +3,5 @@
|
||||
|
||||
kern_status_t acpi_init(void)
|
||||
{
|
||||
kern_status_t status = acpi_smp_init();
|
||||
if (status != KERN_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
return KERN_OK;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <arch/acpi.h>
|
||||
#include <socks/printk.h>
|
||||
#include <socks/vm.h>
|
||||
#include <socks/cpu.h>
|
||||
|
||||
#define AP_TRAMPOLINE_PADDR 0x8000
|
||||
#define LAPIC_IPI_STATUS_REG 0x0280
|
||||
@@ -26,7 +27,7 @@ struct lapic_override_record {
|
||||
extern uint8_t acpi_bsp_lapic_id(void);
|
||||
extern char ap_trampoline[];
|
||||
|
||||
static int send_ipi(void *lapic, unsigned int target_id, uint32_t payload)
|
||||
static int __used send_ipi(void *lapic, unsigned int target_id, uint32_t payload)
|
||||
{
|
||||
uintptr_t lapic_ptr = (uintptr_t)lapic;
|
||||
|
||||
@@ -38,7 +39,7 @@ static int send_ipi(void *lapic, unsigned int target_id, uint32_t payload)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int init_ap(struct acpi_madt_record *rec, void *bsp_lapic, uint8_t bsp_id)
|
||||
static int __used init_ap(struct acpi_madt_record *rec, void *bsp_lapic, uint8_t bsp_id)
|
||||
{
|
||||
struct lapic_record *lapic = (struct lapic_record *)(rec + 1);
|
||||
if (!(lapic->l_flags & 0x1) && !(lapic->l_flags & 0x2)) {
|
||||
@@ -60,7 +61,7 @@ static int init_ap(struct acpi_madt_record *rec, void *bsp_lapic, uint8_t bsp_id
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void *find_lapic(struct acpi_madt *madt)
|
||||
static void *__used find_lapic(struct acpi_madt *madt)
|
||||
{
|
||||
phys_addr_t local_apic = madt->m_lapic_ptr;
|
||||
|
||||
@@ -85,6 +86,7 @@ static void *find_lapic(struct acpi_madt *madt)
|
||||
return vm_phys_to_virt(local_apic);
|
||||
}
|
||||
|
||||
/*
|
||||
kern_status_t acpi_smp_init(void)
|
||||
{
|
||||
struct acpi_madt *madt = (struct acpi_madt *)acpi_find_sdt(ACPI_SIG_MADT);
|
||||
@@ -118,6 +120,54 @@ kern_status_t acpi_smp_init(void)
|
||||
p += rec->r_length;
|
||||
}
|
||||
|
||||
printk("acpi: initialised %u processors", nr_processors);
|
||||
printk("acpi: found %u logical cores", nr_processors);
|
||||
return KERN_OK;
|
||||
}
|
||||
*/
|
||||
|
||||
kern_status_t acpi_scan_cpu_topology(void)
|
||||
{
|
||||
struct acpi_madt *madt = (struct acpi_madt *)acpi_find_sdt(ACPI_SIG_MADT);
|
||||
if (!madt) {
|
||||
return KERN_UNSUPPORTED;
|
||||
}
|
||||
|
||||
uint8_t bsp_id = acpi_bsp_lapic_id();
|
||||
|
||||
//void *bsp_lapic = find_lapic(madt);
|
||||
|
||||
unsigned char *p = (unsigned char *)madt + sizeof *madt;
|
||||
unsigned char *madt_end = (unsigned char *)madt + madt->m_base.s_length;
|
||||
|
||||
unsigned int nr_processors = 0;
|
||||
|
||||
while (p < madt_end) {
|
||||
struct acpi_madt_record *rec = (struct acpi_madt_record *)p;
|
||||
|
||||
if (rec->r_type != ACPI_MADT_LAPIC) {
|
||||
p += rec->r_length;
|
||||
continue;
|
||||
}
|
||||
|
||||
struct lapic_record *lapic = (struct lapic_record *)(rec + 1);
|
||||
|
||||
if (!(lapic->l_flags & 0x1) && !(lapic->l_flags & 0x2)) {
|
||||
/* processor cannot be used */
|
||||
continue;
|
||||
}
|
||||
|
||||
cpu_set_available(lapic->l_apic_id);
|
||||
nr_processors++;
|
||||
|
||||
p += rec->r_length;
|
||||
}
|
||||
|
||||
cpu_set_online(bsp_id);
|
||||
|
||||
/* store the BSP ID in the current cpu block */
|
||||
ml_cpu_block *self = ml_this_cpu();
|
||||
self->c_cpu_id = bsp_id;
|
||||
|
||||
printk("acpi: found %u logical cores", nr_processors);
|
||||
return KERN_OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user