mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-11-16 19:04:53 +08:00
bsps/i386: Standardize APIC definitions across x86 BSPs
Move common APIC register definitions to a shared bsps/include/bsp/apic.h header and keep architecture specific definitions in respective BSP headers, aviudubg cross BSP dependencies. Standardize LAPIC register access in pc386 to use array indexing and LAPIC_REGISTER_* definitions. Rename architecture-specific symbols to BSP-neutral names and standardize APIC base access. Fixes #5516
This commit is contained in:
1 parent
97cf8529cb
commit
b758d1ad73
13 files changed
+256
-168
No files matched your search
@@ -52,6 +52,7 @@
|
||||
#ifndef _APIC_H
|
||||
#define _APIC_H
|
||||
|
||||
#include <bsp/apic.h>
|
||||
#include <rtems/score/basedefs.h>
|
||||
|
||||
/*
|
||||
@@ -82,67 +83,9 @@
|
||||
|
||||
#define IOAPIC_REGSEL 0
|
||||
#define IOAPIC_RW 0x10
|
||||
#define IOAPIC_ID 0
|
||||
#define IOAPIC_VER 1
|
||||
#define IOAPIC_REDIR 0x10
|
||||
|
||||
#define LAPIC_ID 0x20
|
||||
#define LAPIC_VER 0x30
|
||||
#define LAPIC_TPR 0x80
|
||||
#define LAPIC_APR 0x90
|
||||
#define LAPIC_PPR 0xA0
|
||||
#define LAPIC_EOI 0xB0
|
||||
#define LAPIC_LDR 0xD0
|
||||
#define LAPIC_DFR 0xE0
|
||||
#define LAPIC_SPIV 0xF0
|
||||
#define LAPIC_SPIV_ENABLE_APIC 0x100
|
||||
#define LAPIC_ISR 0x100
|
||||
#define LAPIC_TMR 0x180
|
||||
#define LAPIC_IRR 0x200
|
||||
#define LAPIC_ESR 0x280
|
||||
#define LAPIC_ICR_LOW 0x300
|
||||
#define LAPIC_ICR_HIGH 0x310
|
||||
#define LAPIC_ICR_DS_SELF 0x40000
|
||||
#define LAPIC_ICR_DS_ALLINC 0x80000
|
||||
#define LAPIC_ICR_DS_ALLEX 0xC0000
|
||||
#define LAPIC_ICR_TM_LEVEL 0x8000
|
||||
#define LAPIC_ICR_LEVELASSERT 0x4000
|
||||
#define LAPIC_ICR_STATUS_PEND 0x1000
|
||||
#define LAPIC_ICR_DM_LOGICAL 0x800
|
||||
#define LAPIC_ICR_DM_LOWPRI 0x100
|
||||
#define LAPIC_ICR_DM_SMI 0x200
|
||||
#define LAPIC_ICR_DM_NMI 0x400
|
||||
#define LAPIC_ICR_DM_INIT 0x500
|
||||
#define LAPIC_ICR_DM_SIPI 0x600
|
||||
#define LAPIC_LVTT 0x320
|
||||
#define LAPIC_LVTPC 0x340
|
||||
#define LAPIC_LVT0 0x350
|
||||
#define LAPIC_LVT1 0x360
|
||||
#define LAPIC_LVTE 0x370
|
||||
#define LAPIC_TICR 0x380
|
||||
#define LAPIC_TCCR 0x390
|
||||
#define LAPIC_TDCR 0x3E0
|
||||
|
||||
/* The address of the MSR pointing to the APIC base physical address */
|
||||
#define APIC_BASE_MSR 0x1B
|
||||
/* Value to hardware-enable the APIC through the APIC_BASE_MSR */
|
||||
#define APIC_BASE_MSR_ENABLE 0x800
|
||||
|
||||
/*
|
||||
* Since the LAPIC registers are contained in an array of 32-bit elements
|
||||
* these byte-offsets need to be divided by 4 to index the array.
|
||||
*/
|
||||
#define LAPIC_OFFSET(val) (val >> 2)
|
||||
|
||||
#define LAPIC_REGISTER_ID LAPIC_OFFSET(LAPIC_ID)
|
||||
#define LAPIC_REGISTER_EOI LAPIC_OFFSET(LAPIC_EOI)
|
||||
#define LAPIC_REGISTER_SPURIOUS LAPIC_OFFSET(LAPIC_SPIV)
|
||||
#define LAPIC_REGISTER_ESR LAPIC_OFFSET(LAPIC_ESR)
|
||||
#define LAPIC_REGISTER_ICR_LOW LAPIC_OFFSET(LAPIC_ICR_LOW)
|
||||
#define LAPIC_REGISTER_ICR_HIGH LAPIC_OFFSET(LAPIC_ICR_HIGH)
|
||||
|
||||
#define LAPIC_EOI_ACK 0
|
||||
#define LAPIC_SPURIOUS_ENABLE 0x100
|
||||
#define IOAPIC_ID 0
|
||||
#define IOAPIC_VER 1
|
||||
#define IOAPIC_REDIR 0x10
|
||||
|
||||
/**
|
||||
* @brief Initializes the Local APIC by hardware and software enabling it.
|
||||
+12
-14
@@ -84,26 +84,24 @@ GDB can be support using:
|
||||
|
||||
The GDB stub details and in shared/comm/GDB.HOWTO.
|
||||
|
||||
## SMP
|
||||
|
||||
SMP
|
||||
---
|
||||
The following files were developed by Erich Boleyn <erich@uruk.org>.
|
||||
The following files were developed by Erich Boleyn <erich@uruk.org>.
|
||||
The original files were copied from http://www.uruk.org/mps/ and committed
|
||||
into cvs as is. These files will be modified for RTEMS smp support,
|
||||
into cvs as is. These files will be modified for RTEMS smp support,
|
||||
but the original files are being committed in order to track any file
|
||||
changes that occur. We are attempting to keep these changes as minimal
|
||||
and conainted as possible.
|
||||
changes that occur. We are attempting to keep these changes as minimal
|
||||
and contained as possible.
|
||||
|
||||
* start/smp-imps.c
|
||||
* ../include/bsp/smp-imps.h
|
||||
* ../include/bsp/apic.h
|
||||
- start/smp-imps.c
|
||||
- ../include/bsp/smp-imps.h
|
||||
- ../../include/bsp/apic.h
|
||||
|
||||
## Status
|
||||
|
||||
Status
|
||||
------
|
||||
There are a wide range of PC configurations. This BSP has been tested
|
||||
on only a handful. There are configurations which do not yet work. The
|
||||
failure is suspected to be video card related. Here is a list of
|
||||
There are a wide range of PC configurations. This BSP has been tested
|
||||
on only a handful. There are configurations which do not yet work. The
|
||||
failure is suspected to be video card related. Here is a list of
|
||||
successes and failures.
|
||||
|
||||
```
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
#include <rtems/score/smpimpl.h>
|
||||
|
||||
#include <bsp/apic.h>
|
||||
#include <bsp/i386-apic.h>
|
||||
#include <bsp/smp-imps.h>
|
||||
#include <bsp.h>
|
||||
#include <rtems.h>
|
||||
@@ -47,7 +47,9 @@ bool _CPU_SMP_Start_processor( uint32_t cpu_index )
|
||||
|
||||
uint32_t _CPU_SMP_Get_current_processor( void )
|
||||
{
|
||||
return lapic_get_cpu_index( lapic_get_id() );
|
||||
return imps_apic_cpu_map[
|
||||
bsp_lapic_base[LAPIC_REGISTER_ID] >> 24
|
||||
];
|
||||
}
|
||||
|
||||
uint32_t _CPU_SMP_Initialize( void )
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
#endif
|
||||
|
||||
#include <bsp.h>
|
||||
#include <bsp/apic.h>
|
||||
#include <bsp/i386-apic.h>
|
||||
#include <bsp/smp-imps.h>
|
||||
#include <bsp/irq.h>
|
||||
#include <bsp/tblsizes.h>
|
||||
@@ -86,6 +86,10 @@
|
||||
|
||||
extern uint8_t gdtdesc[GDT_SIZE];
|
||||
|
||||
static int lapic_dummy = 0;
|
||||
unsigned imps_lapic_addr =
|
||||
((unsigned)(&lapic_dummy)) - (LAPIC_REGISTER_ID << 2);
|
||||
|
||||
/* #define KERNEL_PRINT(_format) printk(_format) */
|
||||
|
||||
static void CMOS_WRITE_BYTE(
|
||||
@@ -212,6 +216,29 @@ get_checksum(unsigned start, int length)
|
||||
return (sum&0xFF);
|
||||
}
|
||||
|
||||
/*
|
||||
* APIC ICR write and status check function.
|
||||
*/
|
||||
int
|
||||
send_ipi(unsigned int dst, unsigned int v)
|
||||
{
|
||||
int to, send_status, apicid;
|
||||
|
||||
apicid = imps_cpu_apic_map[dst];
|
||||
|
||||
bsp_lapic_base[LAPIC_REGISTER_ICR_HIGH] = (apicid << 24);
|
||||
bsp_lapic_base[LAPIC_REGISTER_ICR_LOW] = v;
|
||||
|
||||
/* Wait for send to finish */
|
||||
to = 0;
|
||||
do {
|
||||
UDELAY(100);
|
||||
send_status = bsp_lapic_base[LAPIC_REGISTER_ICR_LOW] & LAPIC_ICR_DELIV_STAT_PEND;
|
||||
} while (send_status && (to++ < 1000));
|
||||
|
||||
return (to < 1000);
|
||||
}
|
||||
|
||||
/*
|
||||
* Primary function for booting individual CPUs.
|
||||
*
|
||||
@@ -266,7 +293,20 @@ boot_cpu(imps_processor *proc)
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
/* clear the APIC error register */
|
||||
lapic_clear_errors();
|
||||
bsp_lapic_base[LAPIC_REGISTER_ESR] = 0;
|
||||
(void) bsp_lapic_base[LAPIC_REGISTER_ESR];
|
||||
|
||||
/* assert INIT IPI */
|
||||
send_ipi(
|
||||
cpuid,
|
||||
LAPIC_ICR_TM_LEVEL | LAPIC_ICR_LEVELASSERT | LAPIC_ICR_DM_INIT
|
||||
);
|
||||
UDELAY(10000);
|
||||
|
||||
/* de-assert INIT IPI */
|
||||
send_ipi(cpuid, LAPIC_ICR_TM_LEVEL | LAPIC_ICR_DM_INIT);
|
||||
|
||||
UDELAY(10000);
|
||||
|
||||
/*
|
||||
* Send Startup IPIs if not an old pre-integrated APIC.
|
||||
@@ -289,7 +329,8 @@ boot_cpu(imps_processor *proc)
|
||||
*/
|
||||
|
||||
/* clear the APIC error register */
|
||||
lapic_clear_errors();
|
||||
bsp_lapic_base[LAPIC_REGISTER_ESR] = 0;
|
||||
(void) bsp_lapic_base[LAPIC_REGISTER_ESR];
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Warray-bounds"
|
||||
@@ -493,12 +534,17 @@ imps_read_bios(imps_fps *fps_ptr)
|
||||
if (lapic_paddr != (READ_MSR_LO(APIC_BASE_MSR) & 0xFFFFF000)) {
|
||||
return;
|
||||
}
|
||||
imps_lapic_addr = PHYS_TO_VIRTUAL(imps_lapic_addr);
|
||||
|
||||
/* Initialize the Local APIC */
|
||||
if (!lapic_initialize(PHYS_TO_VIRTUAL(lapic_paddr))) {
|
||||
printk("Failed to initialize Local APIC\n");
|
||||
return;
|
||||
}
|
||||
/*
|
||||
* Setup primary CPU.
|
||||
*/
|
||||
apicid = bsp_lapic_base[LAPIC_REGISTER_SPURIOUS];
|
||||
bsp_lapic_base[LAPIC_REGISTER_SPURIOUS] = apicid | LAPIC_SPURIOUS_ENABLE;
|
||||
|
||||
apicid = bsp_lapic_base[LAPIC_REGISTER_ID] >> 24;
|
||||
imps_cpu_apic_map[0] = apicid;
|
||||
imps_apic_cpu_map[apicid] = 0;
|
||||
|
||||
if (fps_ptr->cth_ptr) {
|
||||
char str1[16], str2[16];
|
||||
@@ -604,11 +650,19 @@ imps_force(int ncpus)
|
||||
|
||||
printk("Intel MultiProcessor \"Force\" Support\n");
|
||||
|
||||
lapic_paddr = (READ_MSR_LO(APIC_BASE_MSR) & 0xFFFFF000);
|
||||
if (!lapic_initialize(PHYS_TO_VIRTUAL(lapic_paddr))) {
|
||||
printk("Failed to initialize Local APIC\n");
|
||||
return 0;
|
||||
}
|
||||
imps_lapic_addr = (READ_MSR_LO(0x1b) & 0xFFFFF000);
|
||||
imps_lapic_addr = PHYS_TO_VIRTUAL(imps_lapic_addr);
|
||||
|
||||
/*
|
||||
* Setup primary CPU.
|
||||
*/
|
||||
apicid = bsp_lapic_base[LAPIC_REGISTER_SPURIOUS];
|
||||
bsp_lapic_base[LAPIC_REGISTER_SPURIOUS] =
|
||||
apicid | LAPIC_SPURIOUS_ENABLE;
|
||||
|
||||
apicid = bsp_lapic_base[LAPIC_REGISTER_ID] >> 24;
|
||||
imps_cpu_apic_map[0] = apicid;
|
||||
imps_apic_cpu_map[apicid] = 0;
|
||||
|
||||
p.type = 0;
|
||||
p.apic_ver = 0x10;
|
||||
@@ -716,7 +770,8 @@ imps_probe(void)
|
||||
*/
|
||||
static void smp_apic_ack(void)
|
||||
{
|
||||
lapic_send_eoi();
|
||||
(void) bsp_lapic_base[LAPIC_REGISTER_SPURIOUS];
|
||||
bsp_lapic_base[LAPIC_REGISTER_EOI] = LAPIC_EOI_ACK;
|
||||
}
|
||||
|
||||
static void bsp_inter_processor_interrupt(void *arg)
|
||||
@@ -762,7 +817,9 @@ static void secondary_cpu_initialize(void)
|
||||
{
|
||||
asm volatile( "lidt IDT_Descriptor" );
|
||||
|
||||
lapic_enable();
|
||||
apicid = bsp_lapic_base[LAPIC_REGISTER_SPURIOUS];
|
||||
bsp_lapic_base[LAPIC_REGISTER_SPURIOUS] =
|
||||
apicid | LAPIC_SPURIOUS_ENABLE;
|
||||
|
||||
#ifdef __SSE__
|
||||
enable_sse();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <bsp/apic.h>
|
||||
#include <bsp/i386-apic.h>
|
||||
#include <bsp.h>
|
||||
|
||||
volatile uint32_t *i386_lapic_base; /* Utilized in assembly */
|
||||
@@ -45,11 +45,6 @@ void lapic_enable(void)
|
||||
i386_lapic_base[LAPIC_REGISTER_SPURIOUS] = value;
|
||||
}
|
||||
|
||||
uint8_t lapic_get_id(void)
|
||||
{
|
||||
return i386_lapic_base[LAPIC_REGISTER_ID] >> 24;
|
||||
}
|
||||
|
||||
void lapic_send_eoi(void)
|
||||
{
|
||||
i386_lapic_base[LAPIC_REGISTER_EOI] = LAPIC_EOI_ACK;
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
*/
|
||||
|
||||
#include <bsp.h>
|
||||
#include <bsp/apic.h>
|
||||
#include <bsp/i386-apic.h>
|
||||
#include <bsp/irq.h>
|
||||
#include <bsp/irq-generic.h>
|
||||
#include <libcpu/cpuModel.h>
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
/* SPDX-License-Identifier: BSD-2-Clause */
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup RTEMSBSPsSharedAPIC
|
||||
*
|
||||
* @brief APIC definitions
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2024 Matheus Pecoraro
|
||||
* Copyright (c) 2018 Amaan Cheval <amaan.cheval@gmail.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _BSP_APIC_H
|
||||
#define _BSP_APIC_H
|
||||
|
||||
#include <rtems/score/basedefs.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* The address of the MSR pointing to the APIC base physical address */
|
||||
#define APIC_BASE_MSR 0x1B
|
||||
/* Value to hardware-enable the APIC through the APIC_BASE_MSR */
|
||||
#define APIC_BASE_MSR_ENABLE 0x800
|
||||
|
||||
#define xAPIC_MAX_APIC_ID 0xFE
|
||||
|
||||
/*
|
||||
* APIC register definitions.
|
||||
*/
|
||||
|
||||
#define LAPIC_ID 0x20
|
||||
#define LAPIC_VER 0x30
|
||||
#define LAPIC_TPR 0x80
|
||||
#define LAPIC_APR 0x90
|
||||
#define LAPIC_PPR 0xA0
|
||||
#define LAPIC_EOI 0xB0
|
||||
#define LAPIC_LDR 0xD0
|
||||
#define LAPIC_DFR 0xE0
|
||||
#define LAPIC_SPIV 0xF0
|
||||
#define LAPIC_SPIV_ENABLE_APIC 0x100
|
||||
#define LAPIC_ISR 0x100
|
||||
#define LAPIC_TMR 0x180
|
||||
#define LAPIC_IRR 0x200
|
||||
#define LAPIC_ESR 0x280
|
||||
#define LAPIC_ICR_LOW 0x300
|
||||
#define LAPIC_ICR_HIGH 0x310
|
||||
|
||||
#define LAPIC_ICR_DS_SELF 0x40000
|
||||
#define LAPIC_ICR_DS_ALLINC 0x80000
|
||||
#define LAPIC_ICR_DS_ALLEX 0xC0000
|
||||
#define LAPIC_ICR_TM_LEVEL 0x8000
|
||||
#define LAPIC_ICR_LEVELASSERT 0x4000
|
||||
#define LAPIC_ICR_STATUS_PEND 0x1000
|
||||
#define LAPIC_ICR_DM_LOGICAL 0x800
|
||||
#define LAPIC_ICR_DM_LOWPRI 0x100
|
||||
#define LAPIC_ICR_DM_SMI 0x200
|
||||
#define LAPIC_ICR_DM_NMI 0x400
|
||||
#define LAPIC_ICR_DM_INIT 0x500
|
||||
#define LAPIC_ICR_DM_SIPI 0x600
|
||||
|
||||
#define LAPIC_LVTT 0x320
|
||||
#define LAPIC_LVTPC 0x340
|
||||
#define LAPIC_LVT0 0x350
|
||||
#define LAPIC_LVT1 0x360
|
||||
#define LAPIC_LVTE 0x370
|
||||
#define LAPIC_TICR 0x380
|
||||
#define LAPIC_TCCR 0x390
|
||||
#define LAPIC_TDCR 0x3E0
|
||||
|
||||
/*
|
||||
* Since the LAPIC registers are contained in an array of 32-bit elements
|
||||
* these byte-offsets need to be divided by 4 to index the array.
|
||||
*/
|
||||
#define LAPIC_OFFSET(val) ((val) >> 2)
|
||||
|
||||
#define LAPIC_REGISTER_ID LAPIC_OFFSET(LAPIC_ID)
|
||||
#define LAPIC_REGISTER_EOI LAPIC_OFFSET(LAPIC_EOI)
|
||||
#define LAPIC_REGISTER_SPURIOUS LAPIC_OFFSET(LAPIC_SPIV)
|
||||
#define LAPIC_REGISTER_ESR LAPIC_OFFSET(LAPIC_ESR)
|
||||
#define LAPIC_REGISTER_ICR_LOW LAPIC_OFFSET(LAPIC_ICR_LOW)
|
||||
#define LAPIC_REGISTER_ICR_HIGH LAPIC_OFFSET(LAPIC_ICR_HIGH)
|
||||
|
||||
#define LAPIC_EOI_ACK 0
|
||||
#define LAPIC_SPURIOUS_ENABLE 0x100
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _BSP_APIC_H */
|
||||
@@ -37,36 +37,15 @@
|
||||
#ifndef _AMD64_APIC_H
|
||||
#define _AMD64_APIC_H
|
||||
|
||||
#include <bsp/apic.h>
|
||||
#include <rtems/score/basedefs.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* The address of the MSR pointing to the APIC base physical address */
|
||||
#define APIC_BASE_MSR 0x1B
|
||||
/* Value to hardware-enable the APIC through the APIC_BASE_MSR */
|
||||
#define APIC_BASE_MSR_ENABLE 0x800
|
||||
|
||||
#define xAPIC_MAX_APIC_ID 0xFE
|
||||
|
||||
/*
|
||||
* Since the LAPIC registers are contained in an array of 32-bit elements
|
||||
* these byte-offsets need to be divided by 4 to index the array.
|
||||
*/
|
||||
#define LAPIC_OFFSET(val) (val >> 2)
|
||||
|
||||
#define LAPIC_REGISTER_ID LAPIC_OFFSET(0x20)
|
||||
#define LAPIC_REGISTER_EOI LAPIC_OFFSET(0x0B0)
|
||||
#define LAPIC_REGISTER_SPURIOUS LAPIC_OFFSET(0x0F0)
|
||||
/*
|
||||
* The interrupt request register is a bit field of 256 bits. It is split into
|
||||
* eight 32-bit registers which are 16 bytes apart.
|
||||
*/
|
||||
#define LAPIC_REGISTER_IRR_BASE LAPIC_OFFSET(0x200)
|
||||
#define LAPIC_REGISTER_IRR_STRIDE LAPIC_OFFSET(0x010)
|
||||
#define LAPIC_REGISTER_ICR_LOW LAPIC_OFFSET(0x300)
|
||||
#define LAPIC_REGISTER_ICR_HIGH LAPIC_OFFSET(0x310)
|
||||
#define LAPIC_REGISTER_LVT_TIMER LAPIC_OFFSET(0x320)
|
||||
#define LAPIC_REGISTER_TIMER_INITCNT LAPIC_OFFSET(0x380)
|
||||
#define LAPIC_REGISTER_TIMER_CURRCNT LAPIC_OFFSET(0x390)
|
||||
@@ -83,9 +62,10 @@ extern "C" {
|
||||
#define LAPIC_ICR_TRIG_LEVEL 0x8000
|
||||
#define LAPIC_ICR_DEST_SELF 0x40000
|
||||
|
||||
#define LAPIC_EOI_ACK 0
|
||||
#define LAPIC_SELECT_TMR_PERIODIC 0x20000
|
||||
#define LAPIC_SPURIOUS_ENABLE 0x100
|
||||
|
||||
extern volatile uint32_t *bsp_lapic_base;
|
||||
extern uint8_t bsp_lapic_to_cpu_map[xAPIC_MAX_APIC_ID + 1];
|
||||
|
||||
/* Number of times to calibrate the LAPIC timer to average it out */
|
||||
#define LAPIC_TIMER_NUM_CALIBRATIONS 5
|
||||
@@ -175,14 +155,11 @@ RTEMS_STATIC_ASSERT(
|
||||
} \
|
||||
} while(0); \
|
||||
|
||||
extern volatile uint32_t* amd64_lapic_base;
|
||||
extern uint8_t amd64_lapic_to_cpu_map[xAPIC_MAX_APIC_ID + 1];
|
||||
|
||||
/**
|
||||
* @brief Initializes the Local APIC by hardware and software enabling it.
|
||||
*
|
||||
* Initializes the Local APIC by hardware and software enabling it, and sets
|
||||
* up the amd64_lapic_base pointer that can be used as a 32-bit addressable array to
|
||||
* up the bsp_lapic_base pointer that can be used as a 32-bit addressable array to
|
||||
* access Local APIC registers.
|
||||
*
|
||||
* @return true if successful.
|
||||
@@ -271,7 +248,7 @@ void lapic_start_ap(uint32_t cpu_index, uint8_t page_vector);
|
||||
inline uint8_t lapic_get_id(void)
|
||||
{
|
||||
/* ID stored in highest 8 bits */
|
||||
return amd64_lapic_base[LAPIC_REGISTER_ID]>>24;
|
||||
return bsp_lapic_base[LAPIC_REGISTER_ID]>>24;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -279,7 +256,7 @@ inline uint8_t lapic_get_id(void)
|
||||
*/
|
||||
inline void lapic_eoi(void)
|
||||
{
|
||||
amd64_lapic_base[LAPIC_REGISTER_EOI] = LAPIC_EOI_ACK;
|
||||
bsp_lapic_base[LAPIC_REGISTER_EOI] = LAPIC_EOI_ACK;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -43,11 +43,11 @@
|
||||
|
||||
extern void apic_spurious_handler(void);
|
||||
|
||||
volatile uint32_t* amd64_lapic_base;
|
||||
volatile uint32_t* bsp_lapic_base;
|
||||
|
||||
#ifdef RTEMS_SMP
|
||||
/* Maps the processor index to the Local APIC ID */
|
||||
uint8_t amd64_lapic_to_cpu_map[xAPIC_MAX_APIC_ID + 1];
|
||||
uint8_t bsp_lapic_to_cpu_map[xAPIC_MAX_APIC_ID + 1];
|
||||
static uint8_t cpu_to_lapic_map[xAPIC_MAX_APIC_ID + 1];
|
||||
static uint32_t lapic_count = 0;
|
||||
#endif
|
||||
@@ -85,14 +85,14 @@ static void madt_subtables_handler(ACPI_SUBTABLE_HEADER* entry)
|
||||
break;
|
||||
}
|
||||
|
||||
amd64_lapic_to_cpu_map[lapic_entry->Id] = (uint8_t) lapic_count;
|
||||
bsp_lapic_to_cpu_map[lapic_entry->Id] = (uint8_t) lapic_count;
|
||||
cpu_to_lapic_map[lapic_count++] = lapic_entry->Id;
|
||||
break;
|
||||
#endif
|
||||
case ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE:
|
||||
ACPI_MADT_LOCAL_APIC_OVERRIDE* lapic_override =
|
||||
(ACPI_MADT_LOCAL_APIC_OVERRIDE*) entry;
|
||||
amd64_lapic_base = (uint32_t*) lapic_override->Address;
|
||||
bsp_lapic_base = (uint32_t*) lapic_override->Address;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -117,11 +117,11 @@ static bool parse_madt(void)
|
||||
#ifdef RTEMS_SMP
|
||||
/* Ensure the boot processor is cpu index 0 */
|
||||
uint8_t lapic_id = lapic_get_id();
|
||||
amd64_lapic_to_cpu_map[lapic_id] = (uint8_t) lapic_count;
|
||||
bsp_lapic_to_cpu_map[lapic_id] = (uint8_t) lapic_count;
|
||||
cpu_to_lapic_map[lapic_count++] = lapic_id;
|
||||
#endif
|
||||
|
||||
amd64_lapic_base = (uint32_t*) ((uintptr_t) madt->Address);
|
||||
bsp_lapic_base = (uint32_t*) ((uintptr_t) madt->Address);
|
||||
acpi_walk_subtables(
|
||||
(ACPI_TABLE_HEADER*) madt,
|
||||
sizeof(ACPI_TABLE_MADT),
|
||||
@@ -142,8 +142,8 @@ static bool parse_madt(void)
|
||||
static uint32_t lapic_timer_calc_ticks_per_sec(void)
|
||||
{
|
||||
/* Configure LAPIC timer in one-shot mode to prepare for calibration */
|
||||
amd64_lapic_base[LAPIC_REGISTER_LVT_TIMER] = BSP_VECTOR_APIC_TIMER;
|
||||
amd64_lapic_base[LAPIC_REGISTER_TIMER_DIV] = LAPIC_TIMER_SELECT_DIVIDER;
|
||||
bsp_lapic_base[LAPIC_REGISTER_LVT_TIMER] = BSP_VECTOR_APIC_TIMER;
|
||||
bsp_lapic_base[LAPIC_REGISTER_TIMER_DIV] = LAPIC_TIMER_SELECT_DIVIDER;
|
||||
|
||||
uint8_t chan2_value;
|
||||
PIT_CHAN2_ENABLE(chan2_value);
|
||||
@@ -166,15 +166,15 @@ static uint32_t lapic_timer_calc_ticks_per_sec(void)
|
||||
const uint32_t lapic_calibrate_init_count = 0xffffffff;
|
||||
|
||||
PIT_CHAN2_START_DELAY(chan2_value);
|
||||
amd64_lapic_base[LAPIC_REGISTER_TIMER_INITCNT] = lapic_calibrate_init_count;
|
||||
bsp_lapic_base[LAPIC_REGISTER_TIMER_INITCNT] = lapic_calibrate_init_count;
|
||||
|
||||
PIT_CHAN2_WAIT_DELAY(pit_ticks);
|
||||
uint32_t lapic_currcnt = amd64_lapic_base[LAPIC_REGISTER_TIMER_CURRCNT];
|
||||
uint32_t lapic_currcnt = bsp_lapic_base[LAPIC_REGISTER_TIMER_CURRCNT];
|
||||
|
||||
DBG_PRINTF("PIT stopped at 0x%" PRIx32 "\n", pit_ticks);
|
||||
|
||||
/* Stop APIC timer to calculate ticks to time ratio */
|
||||
amd64_lapic_base[LAPIC_REGISTER_LVT_TIMER] = LAPIC_LVT_MASK;
|
||||
bsp_lapic_base[LAPIC_REGISTER_LVT_TIMER] = LAPIC_LVT_MASK;
|
||||
|
||||
/* Get counts passed since we started counting */
|
||||
uint32_t lapic_ticks_per_sec = lapic_calibrate_init_count - lapic_currcnt;
|
||||
@@ -214,16 +214,16 @@ static uint32_t lapic_timer_calc_ticks_per_sec(void)
|
||||
*/
|
||||
static void send_ipi(uint8_t dest_id, uint32_t icr_low)
|
||||
{
|
||||
amd64_lapic_base[LAPIC_REGISTER_ICR_HIGH] =
|
||||
(amd64_lapic_base[LAPIC_REGISTER_ICR_HIGH] & LAPIC_ICR_HIGH_MASK) | (dest_id << 24);
|
||||
bsp_lapic_base[LAPIC_REGISTER_ICR_HIGH] =
|
||||
(bsp_lapic_base[LAPIC_REGISTER_ICR_HIGH] & LAPIC_ICR_HIGH_MASK) | (dest_id << 24);
|
||||
|
||||
amd64_lapic_base[LAPIC_REGISTER_ICR_LOW] =
|
||||
(amd64_lapic_base[LAPIC_REGISTER_ICR_LOW] & LAPIC_ICR_LOW_MASK) | icr_low;
|
||||
bsp_lapic_base[LAPIC_REGISTER_ICR_LOW] =
|
||||
(bsp_lapic_base[LAPIC_REGISTER_ICR_LOW] & LAPIC_ICR_LOW_MASK) | icr_low;
|
||||
}
|
||||
|
||||
static void wait_ipi(void)
|
||||
{
|
||||
while (amd64_lapic_base[LAPIC_REGISTER_ICR_LOW] & LAPIC_ICR_DELIV_STAT_PEND) {
|
||||
while (bsp_lapic_base[LAPIC_REGISTER_ICR_LOW] & LAPIC_ICR_DELIV_STAT_PEND) {
|
||||
amd64_spinwait();
|
||||
}
|
||||
}
|
||||
@@ -243,17 +243,17 @@ bool lapic_initialize(void)
|
||||
apic_base_msr >> 32
|
||||
);
|
||||
|
||||
DBG_PRINTF("APIC is at 0x%" PRIxPTR "\n", (uintptr_t) amd64_lapic_base);
|
||||
DBG_PRINTF("APIC is at 0x%" PRIxPTR "\n", (uintptr_t) bsp_lapic_base);
|
||||
DBG_PRINTF(
|
||||
"APIC ID at *0x%" PRIxPTR "=0x%" PRIx32 "\n",
|
||||
(uintptr_t) &amd64_lapic_base[LAPIC_REGISTER_ID],
|
||||
amd64_lapic_base[LAPIC_REGISTER_ID]
|
||||
(uintptr_t) &bsp_lapic_base[LAPIC_REGISTER_ID],
|
||||
bsp_lapic_base[LAPIC_REGISTER_ID]
|
||||
);
|
||||
|
||||
DBG_PRINTF(
|
||||
"APIC spurious vector register *0x%" PRIxPTR "=0x%" PRIx32 "\n",
|
||||
(uintptr_t) &amd64_lapic_base[LAPIC_REGISTER_SPURIOUS],
|
||||
amd64_lapic_base[LAPIC_REGISTER_SPURIOUS]
|
||||
(uintptr_t) &bsp_lapic_base[LAPIC_REGISTER_SPURIOUS],
|
||||
bsp_lapic_base[LAPIC_REGISTER_SPURIOUS]
|
||||
);
|
||||
|
||||
/*
|
||||
@@ -265,13 +265,13 @@ bool lapic_initialize(void)
|
||||
(uintptr_t) apic_spurious_handler,
|
||||
&old
|
||||
);
|
||||
amd64_lapic_base[LAPIC_REGISTER_SPURIOUS] =
|
||||
bsp_lapic_base[LAPIC_REGISTER_SPURIOUS] =
|
||||
LAPIC_SPURIOUS_ENABLE | BSP_VECTOR_SPURIOUS;
|
||||
|
||||
DBG_PRINTF(
|
||||
"APIC spurious vector register *0x%" PRIxPTR "=0x%" PRIx32 "\n",
|
||||
(uintptr_t) &amd64_lapic_base[LAPIC_REGISTER_SPURIOUS],
|
||||
amd64_lapic_base[LAPIC_REGISTER_SPURIOUS]
|
||||
(uintptr_t) &bsp_lapic_base[LAPIC_REGISTER_SPURIOUS],
|
||||
bsp_lapic_base[LAPIC_REGISTER_SPURIOUS]
|
||||
);
|
||||
|
||||
/*
|
||||
@@ -308,14 +308,14 @@ uint32_t lapic_timer_calc_ticks(uint64_t desired_freq_hz)
|
||||
|
||||
void lapic_timer_enable(uint32_t reload_value)
|
||||
{
|
||||
amd64_lapic_base[LAPIC_REGISTER_LVT_TIMER] = BSP_VECTOR_APIC_TIMER | LAPIC_SELECT_TMR_PERIODIC;
|
||||
amd64_lapic_base[LAPIC_REGISTER_TIMER_DIV] = LAPIC_TIMER_SELECT_DIVIDER;
|
||||
amd64_lapic_base[LAPIC_REGISTER_TIMER_INITCNT] = reload_value;
|
||||
bsp_lapic_base[LAPIC_REGISTER_LVT_TIMER] = BSP_VECTOR_APIC_TIMER | LAPIC_SELECT_TMR_PERIODIC;
|
||||
bsp_lapic_base[LAPIC_REGISTER_TIMER_DIV] = LAPIC_TIMER_SELECT_DIVIDER;
|
||||
bsp_lapic_base[LAPIC_REGISTER_TIMER_INITCNT] = reload_value;
|
||||
}
|
||||
|
||||
void lapic_timer_set_masked(bool masked)
|
||||
{
|
||||
uint32_t lvt = amd64_lapic_base[LAPIC_REGISTER_LVT_TIMER];
|
||||
uint32_t lvt = bsp_lapic_base[LAPIC_REGISTER_LVT_TIMER];
|
||||
|
||||
if (masked) {
|
||||
lvt |= LAPIC_LVT_MASK;
|
||||
@@ -323,21 +323,21 @@ void lapic_timer_set_masked(bool masked)
|
||||
lvt &= ~LAPIC_LVT_MASK;
|
||||
}
|
||||
|
||||
amd64_lapic_base[LAPIC_REGISTER_LVT_TIMER] = lvt;
|
||||
bsp_lapic_base[LAPIC_REGISTER_LVT_TIMER] = lvt;
|
||||
}
|
||||
|
||||
bool lapic_timer_is_masked(void)
|
||||
{
|
||||
return (amd64_lapic_base[LAPIC_REGISTER_LVT_TIMER] & LAPIC_LVT_MASK) != 0;
|
||||
return (bsp_lapic_base[LAPIC_REGISTER_LVT_TIMER] & LAPIC_LVT_MASK) != 0;
|
||||
}
|
||||
|
||||
void lapic_raise_self(uint32_t vector)
|
||||
{
|
||||
amd64_lapic_base[LAPIC_REGISTER_ICR_LOW] =
|
||||
(amd64_lapic_base[LAPIC_REGISTER_ICR_LOW] & LAPIC_ICR_LOW_MASK) |
|
||||
bsp_lapic_base[LAPIC_REGISTER_ICR_LOW] =
|
||||
(bsp_lapic_base[LAPIC_REGISTER_ICR_LOW] & LAPIC_ICR_LOW_MASK) |
|
||||
LAPIC_ICR_DEST_SELF | LAPIC_ICR_ASSERT | vector;
|
||||
|
||||
while (amd64_lapic_base[LAPIC_REGISTER_ICR_LOW] & LAPIC_ICR_DELIV_STAT_PEND) {
|
||||
while (bsp_lapic_base[LAPIC_REGISTER_ICR_LOW] & LAPIC_ICR_DELIV_STAT_PEND) {
|
||||
amd64_spinwait();
|
||||
}
|
||||
}
|
||||
@@ -347,7 +347,7 @@ bool lapic_is_pending(uint32_t vector)
|
||||
uint32_t reg = LAPIC_REGISTER_IRR_BASE +
|
||||
(vector / 32) * LAPIC_REGISTER_IRR_STRIDE;
|
||||
|
||||
return (amd64_lapic_base[reg] & (UINT32_C(1) << (vector % 32))) != 0;
|
||||
return (bsp_lapic_base[reg] & (UINT32_C(1) << (vector % 32))) != 0;
|
||||
}
|
||||
|
||||
#ifdef RTEMS_SMP
|
||||
|
||||
@@ -108,7 +108,7 @@ bool _CPU_SMP_Start_processor(uint32_t cpu_index)
|
||||
uint32_t _CPU_SMP_Get_current_processor(void)
|
||||
{
|
||||
uint8_t lapic_id = lapic_get_id();
|
||||
return amd64_lapic_to_cpu_map[lapic_id];
|
||||
return bsp_lapic_to_cpu_map[lapic_id];
|
||||
}
|
||||
|
||||
uint32_t _CPU_SMP_Initialize(void)
|
||||
@@ -143,7 +143,7 @@ void smp_init_ap(void)
|
||||
Context_Control_fp* null_fp_context_p = &_CPU_Null_fp_context;
|
||||
_CPU_Context_restore_fp(&null_fp_context_p);
|
||||
|
||||
amd64_lapic_base[LAPIC_REGISTER_SPURIOUS] =
|
||||
bsp_lapic_base[LAPIC_REGISTER_SPURIOUS] =
|
||||
LAPIC_SPURIOUS_ENABLE | BSP_VECTOR_SPURIOUS;
|
||||
|
||||
lidt(&amd64_idtr);
|
||||
|
||||
@@ -161,10 +161,10 @@
|
||||
.macro GET_CPU_INDEX REG REG32
|
||||
.set LAPIC_ID, 0x20
|
||||
.set LAPIC_ID_SHIFT, 24
|
||||
movq amd64_lapic_base, \REG
|
||||
movq bsp_lapic_base, \REG
|
||||
movl LAPIC_ID(\REG), \REG32
|
||||
shrq $LAPIC_ID_SHIFT, \REG /* LAPIC_ID in REG */
|
||||
movzbq amd64_lapic_to_cpu_map(\REG), \REG /* CPU ID in REG */
|
||||
movzbq bsp_lapic_to_cpu_map(\REG), \REG /* CPU ID in REG */
|
||||
.endm
|
||||
|
||||
/* REG32 must be the lower 32 bits of REG */
|
||||
|
||||
@@ -14,7 +14,6 @@ install:
|
||||
- bsps/i386/include/uart.h
|
||||
- destination: ${BSP_INCLUDEDIR}/bsp
|
||||
source:
|
||||
- bsps/i386/include/bsp/apic.h
|
||||
- bsps/i386/include/bsp/irq_asm.h
|
||||
- bsps/i386/include/bsp/realmode_int.h
|
||||
- bsps/i386/include/bsp/smp-imps.h
|
||||
|
||||
@@ -10,6 +10,7 @@ includes: []
|
||||
install:
|
||||
- destination: ${BSP_INCLUDEDIR}/bsp
|
||||
source:
|
||||
- bsps/include/bsp/apic.h
|
||||
- bsps/include/bsp/bootcard.h
|
||||
- bsps/include/bsp/console-polled.h
|
||||
- bsps/include/bsp/console-termios.h
|
||||
|
||||
Reference in new issue
Block a user