Skip to content

Commit ee3c50b

Browse files
Andrew Boiecarlescufi
Andrew Boie
authored andcommitted
x86: apic: use device MMIO APIs
A hack was required for the loapic code due to the address range not being in DTS. A bug was filed. Signed-off-by: Andrew Boie <[email protected]>
1 parent d15a531 commit ee3c50b

File tree

5 files changed

+51
-5
lines changed

5 files changed

+51
-5
lines changed

arch/x86/core/ia32/intstub.S

+6-1
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,13 @@ alreadyOnIntStack:
209209
movl $(X86_X2APIC_BASE_MSR + (LOAPIC_EOI >> 4)), %ecx
210210
wrmsr
211211
#else /* xAPIC */
212+
#ifdef DEVICE_MMIO_IS_IN_RAM
213+
movl z_loapic_regs, %edx
214+
movl %eax, LOAPIC_EOI(%edx)
215+
#else
212216
movl %eax, (CONFIG_LOAPIC_BASE_ADDRESS + LOAPIC_EOI)
213-
#endif
217+
#endif /* DEVICE_MMIO_IS_IN_RAM */
218+
#endif /* CONFIG_X2APIC */
214219

215220
/* determine whether exiting from a nested interrupt */
216221
movl $_kernel, %ecx

arch/x86/core/intel64/locore.S

+6-1
Original file line numberDiff line numberDiff line change
@@ -698,8 +698,13 @@ irq_dispatch:
698698
movl $(X86_X2APIC_BASE_MSR + (LOAPIC_EOI >> 4)), %ecx
699699
wrmsr
700700
#else /* xAPIC */
701+
#ifdef DEVICE_MMIO_IS_IN_RAM
702+
movl z_loapic_regs, %edx
703+
movl %eax, LOAPIC_EOI(%edx)
704+
#else
701705
movl %eax, (CONFIG_LOAPIC_BASE_ADDRESS + LOAPIC_EOI)
702-
#endif
706+
#endif /* DEVICE_MMIO_IS_IN_RAM */
707+
#endif /* CONFIG_X2APIC */
703708

704709
movq %gs:__x86_tss64_t_cpu_OFFSET, %rsi
705710

drivers/interrupt_controller/intc_ioapic.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@
6464
#include <drivers/interrupt_controller/loapic.h> /* public API declarations and registers */
6565
#include "intc_ioapic_priv.h"
6666

67-
#define IOAPIC_REG DT_INST_REG_ADDR(0)
67+
DEVICE_MMIO_TOPLEVEL_STATIC(ioapic_regs, 0);
68+
69+
#define IOAPIC_REG DEVICE_MMIO_TOPLEVEL_GET(ioapic_regs)
6870
#define BITS_PER_IRQ 4
6971
#define IOAPIC_BITFIELD_HI_LO 0
7072
#define IOAPIC_BITFIELD_LVL_EDGE 1
@@ -121,6 +123,9 @@ static void IoApicRedUpdateLo(unsigned int irq, uint32_t value,
121123
int ioapic_init(struct device *unused)
122124
{
123125
ARG_UNUSED(unused);
126+
127+
DEVICE_MMIO_TOPLEVEL_MAP(ioapic_regs, K_MEM_CACHE_NONE);
128+
124129
#ifdef CONFIG_IOAPIC_MASK_RTE
125130
int32_t ix; /* redirection table index */
126131
uint32_t rteValue; /* value to copy into redirection table entry */

drivers/interrupt_controller/intc_loapic.c

+13
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ uint32_t loapic_suspend_buf[LOPIC_SUSPEND_BITS_REQD / 32] = {0};
6565
static uint32_t loapic_device_power_state = DEVICE_PM_ACTIVE_STATE;
6666
#endif
6767

68+
#ifdef DEVICE_MMIO_IS_IN_RAM
69+
mm_reg_t z_loapic_regs;
70+
#endif
71+
72+
void send_eoi(void)
73+
{
74+
x86_write_xapic(LOAPIC_EOI, 0);
75+
}
76+
6877
/**
6978
* @brief Enable and initialize the local APIC.
7079
*
@@ -75,6 +84,10 @@ void z_loapic_enable(unsigned char cpu_number)
7584
{
7685
int32_t loApicMaxLvt; /* local APIC Max LVT */
7786

87+
#ifdef DEVICE_MMIO_IS_IN_RAM
88+
device_map(&z_loapic_regs, CONFIG_LOAPIC_BASE_ADDRESS, 0x1000,
89+
K_MEM_CACHE_NONE);
90+
#endif /* DEVICE_MMIO_IS_IN_RAM */
7891
#ifndef CONFIG_X2APIC
7992
/*
8093
* in xAPIC and flat model, bits 24-31 in LDR (Logical APIC ID) are

include/drivers/interrupt_controller/loapic.h

+20-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <arch/cpu.h>
1313
#include <arch/x86/msr.h>
14+
#include <sys/device_mmio.h>
1415

1516
/* Local APIC Register Offset */
1617

@@ -70,14 +71,25 @@ static inline uint64_t x86_read_x2apic(unsigned int reg)
7071
return z_x86_msr_read(X86_X2APIC_BASE_MSR + reg);
7172
}
7273

74+
/* Defined in intc_loapic.c */
75+
#ifdef DEVICE_MMIO_IS_IN_RAM
76+
extern mm_reg_t z_loapic_regs;
77+
#endif
78+
7379
/**
7480
* @brief Read 32-bit value from the local APIC in xAPIC (MMIO) mode.
7581
*
7682
* @param reg the LOAPIC register number to read (LOAPIC_*)
7783
*/
7884
static inline uint32_t x86_read_xapic(unsigned int reg)
7985
{
80-
return sys_read32(CONFIG_LOAPIC_BASE_ADDRESS + reg);
86+
mm_reg_t base;
87+
#ifdef DEVICE_MMIO_IS_IN_RAM
88+
base = z_loapic_regs;
89+
#else
90+
base = CONFIG_LOAPIC_BASE_ADDRESS;
91+
#endif
92+
return sys_read32(base + reg);
8193
}
8294

8395
/**
@@ -119,7 +131,13 @@ static inline void x86_write_x2apic(unsigned int reg, uint64_t val)
119131
*/
120132
static inline void x86_write_xapic(unsigned int reg, uint32_t val)
121133
{
122-
sys_write32(val, CONFIG_LOAPIC_BASE_ADDRESS + reg);
134+
mm_reg_t base;
135+
#ifdef DEVICE_MMIO_IS_IN_RAM
136+
base = z_loapic_regs;
137+
#else
138+
base = CONFIG_LOAPIC_BASE_ADDRESS;
139+
#endif
140+
sys_write32(val, base + reg);
123141
}
124142

125143
/**

0 commit comments

Comments
 (0)