2015-04-11 01:44:37 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1984-2008, 2011-2015 Wind River Systems, Inc.
|
2017-01-19 02:01:01 +01:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2015-04-11 01:44:37 +02:00
|
|
|
*/
|
|
|
|
|
2023-07-06 22:27:04 +02:00
|
|
|
|
|
|
|
#define DT_DRV_COMPAT intel_loapic
|
|
|
|
|
2019-06-06 23:36:44 +02:00
|
|
|
/*
|
|
|
|
* driver for x86 CPU local APIC (as an interrupt controller)
|
2015-07-01 23:22:39 +02:00
|
|
|
*/
|
2015-04-11 01:44:37 +02:00
|
|
|
|
2022-05-06 10:25:46 +02:00
|
|
|
#include <zephyr/kernel.h>
|
|
|
|
#include <zephyr/kernel_structs.h>
|
|
|
|
#include <zephyr/arch/cpu.h>
|
|
|
|
#include <zephyr/pm/device.h>
|
Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t. This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.
We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.
We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.
Jira: ZEP-2051
Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-19 17:32:08 +02:00
|
|
|
#include <zephyr/types.h>
|
2016-05-07 06:55:51 +02:00
|
|
|
#include <string.h>
|
2022-05-06 10:25:46 +02:00
|
|
|
#include <zephyr/sys/__assert.h>
|
|
|
|
#include <zephyr/arch/x86/msr.h>
|
2015-04-11 01:44:37 +02:00
|
|
|
|
2022-05-06 10:25:46 +02:00
|
|
|
#include <zephyr/toolchain.h>
|
|
|
|
#include <zephyr/linker/sections.h>
|
|
|
|
#include <zephyr/drivers/interrupt_controller/loapic.h> /* public API declarations */
|
|
|
|
#include <zephyr/device.h>
|
|
|
|
#include <zephyr/drivers/interrupt_controller/sysapic.h>
|
|
|
|
#include <zephyr/drivers/interrupt_controller/ioapic.h>
|
2015-04-11 01:44:37 +02:00
|
|
|
|
|
|
|
/* Local APIC Version Register Bits */
|
|
|
|
|
|
|
|
#define LOAPIC_VERSION_MASK 0x000000ff /* LO APIC Version mask */
|
|
|
|
#define LOAPIC_MAXLVT_MASK 0x00ff0000 /* LO APIC Max LVT mask */
|
|
|
|
#define LOAPIC_PENTIUM4 0x00000014 /* LO APIC in Pentium4 */
|
|
|
|
#define LOAPIC_LVT_PENTIUM4 5 /* LO APIC LVT - Pentium4 */
|
|
|
|
#define LOAPIC_LVT_P6 4 /* LO APIC LVT - P6 */
|
|
|
|
#define LOAPIC_LVT_P5 3 /* LO APIC LVT - P5 */
|
|
|
|
|
|
|
|
/* Local APIC Vector Table Bits */
|
|
|
|
|
|
|
|
#define LOAPIC_VECTOR 0x000000ff /* vectorNo */
|
|
|
|
#define LOAPIC_MODE 0x00000700 /* delivery mode */
|
|
|
|
#define LOAPIC_FIXED 0x00000000 /* delivery mode: FIXED */
|
|
|
|
#define LOAPIC_SMI 0x00000200 /* delivery mode: SMI */
|
|
|
|
#define LOAPIC_NMI 0x00000400 /* delivery mode: NMI */
|
|
|
|
#define LOAPIC_EXT 0x00000700 /* delivery mode: ExtINT */
|
|
|
|
#define LOAPIC_IDLE 0x00000000 /* delivery status: Idle */
|
|
|
|
#define LOAPIC_PEND 0x00001000 /* delivery status: Pend */
|
|
|
|
#define LOAPIC_HIGH 0x00000000 /* polarity: High */
|
|
|
|
#define LOAPIC_LOW 0x00002000 /* polarity: Low */
|
|
|
|
#define LOAPIC_REMOTE 0x00004000 /* remote IRR */
|
|
|
|
#define LOAPIC_EDGE 0x00000000 /* trigger mode: Edge */
|
|
|
|
#define LOAPIC_LEVEL 0x00008000 /* trigger mode: Level */
|
|
|
|
|
|
|
|
/* Local APIC Spurious-Interrupt Register Bits */
|
|
|
|
|
|
|
|
#define LOAPIC_ENABLE 0x100 /* APIC Enabled */
|
|
|
|
#define LOAPIC_FOCUS_DISABLE 0x200 /* Focus Processor Checking */
|
|
|
|
|
2015-12-09 23:53:41 +01:00
|
|
|
#if CONFIG_LOAPIC_SPURIOUS_VECTOR_ID == -1
|
|
|
|
#define LOAPIC_SPURIOUS_VECTOR_ID (CONFIG_IDT_NUM_VECTORS - 1)
|
|
|
|
#else
|
|
|
|
#define LOAPIC_SPURIOUS_VECTOR_ID CONFIG_LOAPIC_SPURIOUS_VECTOR_ID
|
|
|
|
#endif
|
2015-04-11 01:44:37 +02:00
|
|
|
|
2023-07-06 22:27:04 +02:00
|
|
|
#define LOAPIC_SSPND_BITS_PER_IRQ 1 /* Just the one for enable disable*/
|
|
|
|
#define LOAPIC_SUSPEND_BITS_REQD (ROUND_UP((LOAPIC_IRQ_COUNT * LOAPIC_SSPND_BITS_PER_IRQ), 32))
|
2020-09-02 00:31:40 +02:00
|
|
|
#ifdef CONFIG_PM_DEVICE
|
2021-03-17 21:47:56 +01:00
|
|
|
__pinned_bss
|
2023-07-06 22:27:04 +02:00
|
|
|
uint32_t loapic_suspend_buf[LOAPIC_SUSPEND_BITS_REQD / 32] = {0};
|
2016-05-07 06:55:51 +02:00
|
|
|
#endif
|
|
|
|
|
2023-07-06 22:27:04 +02:00
|
|
|
DEVICE_MMIO_TOPLEVEL(LOAPIC_REGS_STR, DT_DRV_INST(0));
|
2020-06-26 21:09:01 +02:00
|
|
|
|
2021-03-17 21:47:56 +01:00
|
|
|
__pinned_func
|
2020-06-26 21:09:01 +02:00
|
|
|
void send_eoi(void)
|
|
|
|
{
|
|
|
|
x86_write_xapic(LOAPIC_EOI, 0);
|
|
|
|
}
|
|
|
|
|
2015-07-01 23:22:39 +02:00
|
|
|
/**
|
2019-09-28 22:58:22 +02:00
|
|
|
* @brief Enable and initialize the local APIC.
|
2015-07-01 23:22:39 +02:00
|
|
|
*
|
2019-09-28 22:58:22 +02:00
|
|
|
* Called from early assembly layer (e.g., crt0.S).
|
2015-07-01 23:22:39 +02:00
|
|
|
*/
|
2021-03-17 21:47:56 +01:00
|
|
|
__pinned_func
|
2020-02-10 23:09:05 +01:00
|
|
|
void z_loapic_enable(unsigned char cpu_number)
|
2015-04-11 01:44:37 +02:00
|
|
|
{
|
2020-05-27 18:26:57 +02:00
|
|
|
int32_t loApicMaxLvt; /* local APIC Max LVT */
|
2023-07-06 22:27:04 +02:00
|
|
|
DEVICE_MMIO_TOPLEVEL_MAP(LOAPIC_REGS_STR, K_MEM_CACHE_NONE);
|
2015-04-11 01:44:37 +02:00
|
|
|
|
2020-02-10 23:09:05 +01:00
|
|
|
#ifndef CONFIG_X2APIC
|
|
|
|
/*
|
|
|
|
* in xAPIC and flat model, bits 24-31 in LDR (Logical APIC ID) are
|
|
|
|
* bitmap of target logical APIC ID and it supports maximum 8 local
|
|
|
|
* APICs.
|
|
|
|
*
|
|
|
|
* The logical APIC ID could be arbitrarily selected by system software
|
|
|
|
* and is different from local APIC ID in local APIC ID register.
|
|
|
|
*
|
|
|
|
* We choose 0 for BSP, and the index to x86_cpuboot[] for secondary
|
|
|
|
* CPUs.
|
|
|
|
*
|
|
|
|
* in X2APIC, LDR is read-only.
|
|
|
|
*/
|
|
|
|
x86_write_xapic(LOAPIC_LDR, 1 << (cpu_number + 24));
|
|
|
|
#endif
|
|
|
|
|
2019-06-08 01:26:44 +02:00
|
|
|
/*
|
|
|
|
* enable the local APIC. note that we use xAPIC mode here, since
|
|
|
|
* x2APIC access is not enabled until the next step (if at all).
|
|
|
|
*/
|
|
|
|
|
|
|
|
x86_write_xapic(LOAPIC_SVR,
|
|
|
|
x86_read_xapic(LOAPIC_SVR) | LOAPIC_ENABLE);
|
|
|
|
|
|
|
|
#ifdef CONFIG_X2APIC
|
|
|
|
/*
|
|
|
|
* turn on x2APIC mode. we trust the config option, so
|
|
|
|
* we don't check CPUID to see if x2APIC is supported.
|
|
|
|
*/
|
|
|
|
|
2020-05-27 18:26:57 +02:00
|
|
|
uint64_t msr = z_x86_msr_read(X86_APIC_BASE_MSR);
|
2019-06-08 01:26:44 +02:00
|
|
|
msr |= X86_APIC_BASE_MSR_X2APIC;
|
|
|
|
z_x86_msr_write(X86_APIC_BASE_MSR, msr);
|
|
|
|
#endif
|
|
|
|
|
2019-06-06 23:36:44 +02:00
|
|
|
loApicMaxLvt = (x86_read_loapic(LOAPIC_VER) & LOAPIC_MAXLVT_MASK) >> 16;
|
2015-04-11 01:44:37 +02:00
|
|
|
|
|
|
|
/* reset the DFR, TPR, TIMER_CONFIG, and TIMER_ICR */
|
|
|
|
|
2019-06-05 19:28:38 +02:00
|
|
|
#ifndef CONFIG_X2APIC
|
2020-02-10 23:09:05 +01:00
|
|
|
/* Flat model */
|
2019-06-06 23:36:44 +02:00
|
|
|
x86_write_loapic(LOAPIC_DFR, 0xffffffff); /* no DFR in x2APIC mode */
|
jailhouse: add support for x2APIC mode for all LOAPIC accesses
Besides the fact that we did not have that for the current supported
boards, that makes sense for this new, virtualized mode, that is meant
to be run on top of full-fledged x86 64 CPUs.
By having xAPIC mode access only, Jailhouse has to intercept those MMIO
reads and writes, in order to examine what they do and arbitrate if it's
safe or not (e.g. not all values are accepted to ICR register). This
means that we can't run away from having a VM-exit event for each and
every access to APIC memory region and this impacts the latency the
guest OS observes over bare metal a lot.
When in x2APIC mode, Jailhouse does not require VM-exits for MSR
accesses other that writes to the ICR register, so the latency the guest
observes is reduced to almost zero.
Here are some outputs of the the command line
$ sudo ./tools/jailhouse cell stats tiny-demo
on a Jailhouse's root cell console, for one of the Zephyr demos using
LOAPIC timers, left for a couple of seconds:
Statistics for tiny-demo cell (x2APIC root, x2APIC inmate)
COUNTER SUM PER SEC
vmexits_total 7 0
vmexits_management 3 0
vmexits_cr 2 0
vmexits_cpuid 1 0
vmexits_msr 1 0
vmexits_exception 0 0
vmexits_hypercall 0 0
vmexits_mmio 0 0
vmexits_pio 0 0
vmexits_xapic 0 0
vmexits_xsetbv 0 0
Statistics for tiny-demo cell (xAPIC root, xAPIC inmate)
COUNTER SUM PER SEC
vmexits_total 4087 40
vmexits_xapic 4080 40
vmexits_management 3 0
vmexits_cr 2 0
vmexits_cpuid 1 0
vmexits_msr 1 0
vmexits_exception 0 0
vmexits_hypercall 0 0
vmexits_mmio 0 0
vmexits_pio 0 0
vmexits_xsetbv 0 0
Statistics for tiny-demo cell (xAPIC root, x2APIC inmate)
COUNTER SUM PER SEC
vmexits_total 4087 40
vmexits_msr 4080 40
vmexits_management 3 0
vmexits_cr 2 0
vmexits_cpuid 1 0
vmexits_exception 0 0
vmexits_hypercall 0 0
vmexits_mmio 0 0
vmexits_pio 0 0
vmexits_xapic 0 0
vmexits_xsetbv 0 0
See that under x2APIC mode on both Jailhouse/root-cell and guest, the
interruptions from the hypervisor are minimal. That is not the case when
Jailhouse is on xAPIC mode, though. Note also that, as a plus, x2APIC
accesses on the guest will map to xAPIC MMIO on the hypervisor just
fine.
Signed-off-by: Gustavo Lima Chaves <gustavo.lima.chaves@intel.com>
2017-10-11 23:17:12 +02:00
|
|
|
#endif
|
2017-10-11 23:08:17 +02:00
|
|
|
|
2019-06-06 23:36:44 +02:00
|
|
|
x86_write_loapic(LOAPIC_TPR, 0x0);
|
|
|
|
x86_write_loapic(LOAPIC_TIMER_CONFIG, 0x0);
|
|
|
|
x86_write_loapic(LOAPIC_TIMER_ICR, 0x0);
|
2015-04-11 01:44:37 +02:00
|
|
|
|
|
|
|
/* program Local Vector Table for the Virtual Wire Mode */
|
|
|
|
|
|
|
|
/* set LINT0: extInt, high-polarity, edge-trigger, not-masked */
|
|
|
|
|
2019-06-06 23:36:44 +02:00
|
|
|
x86_write_loapic(LOAPIC_LINT0, (x86_read_loapic(LOAPIC_LINT0) &
|
2017-10-11 23:08:17 +02:00
|
|
|
~(LOAPIC_MODE | LOAPIC_LOW |
|
|
|
|
LOAPIC_LEVEL | LOAPIC_LVT_MASKED)) |
|
|
|
|
(LOAPIC_EXT | LOAPIC_HIGH | LOAPIC_EDGE));
|
2015-04-11 01:44:37 +02:00
|
|
|
|
|
|
|
/* set LINT1: NMI, high-polarity, edge-trigger, not-masked */
|
|
|
|
|
2019-06-06 23:36:44 +02:00
|
|
|
x86_write_loapic(LOAPIC_LINT1, (x86_read_loapic(LOAPIC_LINT1) &
|
2017-10-11 23:08:17 +02:00
|
|
|
~(LOAPIC_MODE | LOAPIC_LOW |
|
|
|
|
LOAPIC_LEVEL | LOAPIC_LVT_MASKED)) |
|
|
|
|
(LOAPIC_NMI | LOAPIC_HIGH | LOAPIC_EDGE));
|
2015-04-11 01:44:37 +02:00
|
|
|
|
|
|
|
/* lock the Local APIC interrupts */
|
|
|
|
|
2019-06-06 23:36:44 +02:00
|
|
|
x86_write_loapic(LOAPIC_TIMER, LOAPIC_LVT_MASKED);
|
|
|
|
x86_write_loapic(LOAPIC_ERROR, LOAPIC_LVT_MASKED);
|
2015-04-11 01:44:37 +02:00
|
|
|
|
2019-06-04 16:52:23 +02:00
|
|
|
if (loApicMaxLvt >= LOAPIC_LVT_P6) {
|
2019-06-06 23:36:44 +02:00
|
|
|
x86_write_loapic(LOAPIC_PMC, LOAPIC_LVT_MASKED);
|
2019-06-04 16:52:23 +02:00
|
|
|
}
|
2015-04-11 01:44:37 +02:00
|
|
|
|
2019-06-04 16:52:23 +02:00
|
|
|
if (loApicMaxLvt >= LOAPIC_LVT_PENTIUM4) {
|
2019-06-06 23:36:44 +02:00
|
|
|
x86_write_loapic(LOAPIC_THERMAL, LOAPIC_LVT_MASKED);
|
2019-06-04 16:52:23 +02:00
|
|
|
}
|
2015-04-11 01:44:37 +02:00
|
|
|
|
2015-12-09 23:53:41 +01:00
|
|
|
#if CONFIG_LOAPIC_SPURIOUS_VECTOR
|
2019-06-06 23:36:44 +02:00
|
|
|
x86_write_loapic(LOAPIC_SVR, (x86_read_loapic(LOAPIC_SVR) & 0xFFFFFF00) |
|
2017-10-11 23:08:17 +02:00
|
|
|
(LOAPIC_SPURIOUS_VECTOR_ID & 0xFF));
|
2015-12-09 23:53:41 +01:00
|
|
|
#endif
|
|
|
|
|
2015-04-11 01:44:37 +02:00
|
|
|
/* discard a pending interrupt if any */
|
2019-06-06 23:36:44 +02:00
|
|
|
x86_write_loapic(LOAPIC_EOI, 0);
|
2019-09-28 22:58:22 +02:00
|
|
|
}
|
2015-04-11 01:44:37 +02:00
|
|
|
|
2019-09-28 22:58:22 +02:00
|
|
|
/**
|
|
|
|
* @brief Dummy initialization function.
|
|
|
|
*
|
|
|
|
* The local APIC is initialized via z_loapic_enable() long before the
|
|
|
|
* kernel runs through its device initializations, so this is unneeded.
|
|
|
|
*/
|
2021-03-17 21:47:56 +01:00
|
|
|
__boot_func
|
2020-04-30 20:33:38 +02:00
|
|
|
static int loapic_init(const struct device *unused)
|
2019-09-28 22:58:22 +02:00
|
|
|
{
|
|
|
|
ARG_UNUSED(unused);
|
2016-08-02 21:05:08 +02:00
|
|
|
return 0;
|
2015-04-11 01:44:37 +02:00
|
|
|
}
|
|
|
|
|
2021-03-09 19:54:42 +01:00
|
|
|
|
2021-03-17 21:47:56 +01:00
|
|
|
__pinned_func
|
2021-03-09 19:54:42 +01:00
|
|
|
uint32_t z_loapic_irq_base(void)
|
|
|
|
{
|
|
|
|
return z_ioapic_num_rtes();
|
|
|
|
}
|
|
|
|
|
2015-07-01 23:22:39 +02:00
|
|
|
/**
|
2015-07-01 23:51:40 +02:00
|
|
|
* @brief Set the vector field in the specified RTE
|
2015-07-01 23:22:39 +02:00
|
|
|
*
|
2016-09-22 20:20:26 +02:00
|
|
|
* This associates an IRQ with the desired vector in the IDT.
|
2015-07-01 23:22:39 +02:00
|
|
|
*/
|
2021-03-17 21:47:56 +01:00
|
|
|
__boot_func
|
2019-03-08 22:19:05 +01:00
|
|
|
void z_loapic_int_vec_set(unsigned int irq, /* IRQ number of the interrupt */
|
2015-07-27 17:02:41 +02:00
|
|
|
unsigned int vector /* vector to copy into the LVT */
|
2015-04-11 01:44:37 +02:00
|
|
|
)
|
|
|
|
{
|
2018-08-15 02:57:08 +02:00
|
|
|
unsigned int oldLevel; /* previous interrupt lock level */
|
2015-04-11 01:44:37 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The following mappings are used:
|
|
|
|
*
|
|
|
|
* IRQ0 -> LOAPIC_TIMER
|
|
|
|
* IRQ1 -> LOAPIC_THERMAL
|
|
|
|
* IRQ2 -> LOAPIC_PMC
|
|
|
|
* IRQ3 -> LOAPIC_LINT0
|
|
|
|
* IRQ4 -> LOAPIC_LINT1
|
|
|
|
* IRQ5 -> LOAPIC_ERROR
|
|
|
|
*
|
|
|
|
* It's assumed that LVTs are spaced by 0x10 bytes
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* update the 'vector' bits in the LVT */
|
|
|
|
|
|
|
|
oldLevel = irq_lock();
|
2019-06-06 23:36:44 +02:00
|
|
|
x86_write_loapic(LOAPIC_TIMER + (irq * 0x10),
|
|
|
|
(x86_read_loapic(LOAPIC_TIMER + (irq * 0x10)) &
|
2017-10-11 23:08:17 +02:00
|
|
|
~LOAPIC_VECTOR) | vector);
|
2015-04-11 01:44:37 +02:00
|
|
|
irq_unlock(oldLevel);
|
|
|
|
}
|
|
|
|
|
2015-07-01 23:22:39 +02:00
|
|
|
/**
|
2015-07-01 23:51:40 +02:00
|
|
|
* @brief Enable an individual LOAPIC interrupt (IRQ)
|
2015-07-01 23:22:39 +02:00
|
|
|
*
|
2015-10-20 18:42:33 +02:00
|
|
|
* @param irq the IRQ number of the interrupt
|
|
|
|
*
|
2015-07-01 23:22:39 +02:00
|
|
|
* This routine clears the interrupt mask bit in the LVT for the specified IRQ
|
|
|
|
*/
|
2021-03-17 21:47:56 +01:00
|
|
|
__pinned_func
|
2019-03-08 22:19:05 +01:00
|
|
|
void z_loapic_irq_enable(unsigned int irq)
|
2015-04-11 01:44:37 +02:00
|
|
|
{
|
2018-08-15 02:57:08 +02:00
|
|
|
unsigned int oldLevel; /* previous interrupt lock level */
|
2015-04-11 01:44:37 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* See the comments in _LoApicLvtVecSet() regarding IRQ to LVT mappings
|
|
|
|
* and ths assumption concerning LVT spacing.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* clear the mask bit in the LVT */
|
|
|
|
|
|
|
|
oldLevel = irq_lock();
|
2019-06-06 23:36:44 +02:00
|
|
|
x86_write_loapic(LOAPIC_TIMER + (irq * 0x10),
|
|
|
|
x86_read_loapic(LOAPIC_TIMER + (irq * 0x10)) &
|
2017-10-11 23:08:17 +02:00
|
|
|
~LOAPIC_LVT_MASKED);
|
2015-04-11 01:44:37 +02:00
|
|
|
irq_unlock(oldLevel);
|
|
|
|
}
|
|
|
|
|
2015-07-01 23:22:39 +02:00
|
|
|
/**
|
2015-07-01 23:51:40 +02:00
|
|
|
* @brief Disable an individual LOAPIC interrupt (IRQ)
|
2015-07-01 23:22:39 +02:00
|
|
|
*
|
2015-10-20 18:42:33 +02:00
|
|
|
* @param irq the IRQ number of the interrupt
|
|
|
|
*
|
2015-07-01 23:22:39 +02:00
|
|
|
* This routine clears the interrupt mask bit in the LVT for the specified IRQ
|
|
|
|
*/
|
2021-03-17 21:47:56 +01:00
|
|
|
__pinned_func
|
2019-03-08 22:19:05 +01:00
|
|
|
void z_loapic_irq_disable(unsigned int irq)
|
2015-04-11 01:44:37 +02:00
|
|
|
{
|
2018-08-15 02:57:08 +02:00
|
|
|
unsigned int oldLevel; /* previous interrupt lock level */
|
2015-04-11 01:44:37 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* See the comments in _LoApicLvtVecSet() regarding IRQ to LVT mappings
|
|
|
|
* and ths assumption concerning LVT spacing.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* set the mask bit in the LVT */
|
|
|
|
|
|
|
|
oldLevel = irq_lock();
|
2019-06-06 23:36:44 +02:00
|
|
|
x86_write_loapic(LOAPIC_TIMER + (irq * 0x10),
|
|
|
|
x86_read_loapic(LOAPIC_TIMER + (irq * 0x10)) |
|
2017-10-11 23:08:17 +02:00
|
|
|
LOAPIC_LVT_MASKED);
|
2015-04-11 01:44:37 +02:00
|
|
|
irq_unlock(oldLevel);
|
|
|
|
}
|
2015-08-22 02:10:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Find the currently executing interrupt vector, if any
|
|
|
|
*
|
|
|
|
* This routine finds the vector of the interrupt that is being processed.
|
|
|
|
* The ISR (In-Service Register) register contain the vectors of the interrupts
|
2017-04-19 19:45:34 +02:00
|
|
|
* in service. And the higher vector is the identification of the interrupt
|
2015-08-22 02:10:32 +02:00
|
|
|
* being currently processed.
|
|
|
|
*
|
2016-07-12 20:42:18 +02:00
|
|
|
* This function must be called with interrupts locked in interrupt context.
|
|
|
|
*
|
2015-08-22 02:10:32 +02:00
|
|
|
* ISR registers' offsets:
|
|
|
|
* --------------------
|
|
|
|
* | Offset | bits |
|
|
|
|
* --------------------
|
|
|
|
* | 0100H | 0:31 |
|
|
|
|
* | 0110H | 32:63 |
|
|
|
|
* | 0120H | 64:95 |
|
|
|
|
* | 0130H | 96:127 |
|
|
|
|
* | 0140H | 128:159 |
|
|
|
|
* | 0150H | 160:191 |
|
|
|
|
* | 0160H | 192:223 |
|
|
|
|
* | 0170H | 224:255 |
|
|
|
|
* --------------------
|
|
|
|
*
|
2016-09-08 20:01:23 +02:00
|
|
|
* @return The vector of the interrupt that is currently being processed, or -1
|
|
|
|
* if no IRQ is being serviced.
|
2015-08-22 02:10:32 +02:00
|
|
|
*/
|
2021-03-17 21:47:56 +01:00
|
|
|
__pinned_func
|
2019-06-28 22:06:37 +02:00
|
|
|
int z_irq_controller_isr_vector_get(void)
|
2015-08-22 02:10:32 +02:00
|
|
|
{
|
2016-07-12 20:42:18 +02:00
|
|
|
int pReg, block;
|
|
|
|
|
2016-09-08 20:01:23 +02:00
|
|
|
/* Block 0 bits never lit up as these are all exception or reserved
|
|
|
|
* vectors
|
|
|
|
*/
|
|
|
|
for (block = 7; likely(block > 0); block--) {
|
2019-06-06 23:36:44 +02:00
|
|
|
pReg = x86_read_loapic(LOAPIC_ISR + (block * 0x10));
|
2022-07-20 08:37:40 +02:00
|
|
|
if (pReg != 0) {
|
2016-07-12 20:42:18 +02:00
|
|
|
return (block * 32) + (find_msb_set(pReg) - 1);
|
2015-08-22 02:10:32 +02:00
|
|
|
}
|
|
|
|
|
2016-07-12 20:42:18 +02:00
|
|
|
}
|
2016-09-08 20:01:23 +02:00
|
|
|
return -1;
|
2015-08-22 02:10:32 +02:00
|
|
|
}
|
2015-12-08 20:17:56 +01:00
|
|
|
|
2020-09-02 00:31:40 +02:00
|
|
|
#ifdef CONFIG_PM_DEVICE
|
2021-03-17 21:47:56 +01:00
|
|
|
__pinned_func
|
2020-04-30 20:33:38 +02:00
|
|
|
static int loapic_suspend(const struct device *port)
|
2016-05-07 06:55:51 +02:00
|
|
|
{
|
2020-05-27 18:26:57 +02:00
|
|
|
volatile uint32_t lvt; /* local vector table entry value */
|
2016-05-07 06:55:51 +02:00
|
|
|
int loapic_irq;
|
|
|
|
|
|
|
|
ARG_UNUSED(port);
|
|
|
|
|
2023-07-06 22:27:04 +02:00
|
|
|
(void)memset(loapic_suspend_buf, 0, (LOAPIC_SUSPEND_BITS_REQD >> 3));
|
2016-05-07 06:55:51 +02:00
|
|
|
|
|
|
|
for (loapic_irq = 0; loapic_irq < LOAPIC_IRQ_COUNT; loapic_irq++) {
|
|
|
|
|
2021-03-09 19:54:42 +01:00
|
|
|
if (_irq_to_interrupt_vector[z_loapic_irq_base() + loapic_irq]) {
|
2016-05-07 06:55:51 +02:00
|
|
|
|
|
|
|
/* Since vector numbers are already present in RAM/ROM,
|
|
|
|
* We save only the mask bits here.
|
|
|
|
*/
|
2019-06-06 23:36:44 +02:00
|
|
|
lvt = x86_read_loapic(LOAPIC_TIMER + (loapic_irq * 0x10));
|
2016-05-07 06:55:51 +02:00
|
|
|
|
2019-03-27 02:57:45 +01:00
|
|
|
if ((lvt & LOAPIC_LVT_MASKED) == 0U) {
|
2016-05-07 06:55:51 +02:00
|
|
|
sys_bitfield_set_bit((mem_addr_t)loapic_suspend_buf,
|
|
|
|
loapic_irq);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-06-04 17:41:39 +02:00
|
|
|
|
2016-05-07 06:55:51 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-03-17 21:47:56 +01:00
|
|
|
__pinned_func
|
2020-04-30 20:33:38 +02:00
|
|
|
int loapic_resume(const struct device *port)
|
2016-05-07 06:55:51 +02:00
|
|
|
{
|
|
|
|
int loapic_irq;
|
|
|
|
|
|
|
|
ARG_UNUSED(port);
|
|
|
|
|
|
|
|
/* Assuming all loapic device registers lose their state, the call to
|
2019-03-12 22:15:42 +01:00
|
|
|
* z_loapic_init(), should bring all the registers to a sane state.
|
2016-05-07 06:55:51 +02:00
|
|
|
*/
|
2019-03-12 22:15:42 +01:00
|
|
|
loapic_init(NULL);
|
2016-05-07 06:55:51 +02:00
|
|
|
|
|
|
|
for (loapic_irq = 0; loapic_irq < LOAPIC_IRQ_COUNT; loapic_irq++) {
|
|
|
|
|
2021-03-09 19:54:42 +01:00
|
|
|
if (_irq_to_interrupt_vector[z_loapic_irq_base() + loapic_irq]) {
|
2016-05-07 06:55:51 +02:00
|
|
|
/* Configure vector and enable the required ones*/
|
2019-03-08 22:19:05 +01:00
|
|
|
z_loapic_int_vec_set(loapic_irq,
|
2021-03-09 19:54:42 +01:00
|
|
|
_irq_to_interrupt_vector[z_loapic_irq_base() +
|
|
|
|
loapic_irq]);
|
2016-05-07 06:55:51 +02:00
|
|
|
|
|
|
|
if (sys_bitfield_test_bit((mem_addr_t) loapic_suspend_buf,
|
|
|
|
loapic_irq)) {
|
2019-03-08 22:19:05 +01:00
|
|
|
z_loapic_irq_enable(loapic_irq);
|
2016-05-07 06:55:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-11 18:17:19 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Implements the driver control management functionality
|
|
|
|
* the *context may include IN data or/and OUT data
|
|
|
|
*/
|
2021-03-17 21:47:56 +01:00
|
|
|
__pinned_func
|
2021-11-02 16:19:41 +01:00
|
|
|
static int loapic_pm_action(const struct device *dev,
|
|
|
|
enum pm_device_action action)
|
2016-09-11 18:17:19 +02:00
|
|
|
{
|
2019-02-14 05:05:42 +01:00
|
|
|
int ret = 0;
|
|
|
|
|
2021-07-05 15:13:40 +02:00
|
|
|
switch (action) {
|
|
|
|
case PM_DEVICE_ACTION_SUSPEND:
|
2021-07-05 10:35:15 +02:00
|
|
|
ret = loapic_suspend(dev);
|
|
|
|
break;
|
2021-07-05 15:13:40 +02:00
|
|
|
case PM_DEVICE_ACTION_RESUME:
|
2021-07-05 10:35:15 +02:00
|
|
|
ret = loapic_resume(dev);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -ENOTSUP;
|
2016-09-11 18:17:19 +02:00
|
|
|
}
|
2016-05-07 06:55:51 +02:00
|
|
|
|
2019-02-14 05:05:42 +01:00
|
|
|
return ret;
|
2016-05-07 06:55:51 +02:00
|
|
|
}
|
2021-11-16 16:36:01 +01:00
|
|
|
#endif /* CONFIG_PM_DEVICE */
|
2016-05-07 06:55:51 +02:00
|
|
|
|
2023-09-15 22:46:42 +02:00
|
|
|
PM_DEVICE_DT_INST_DEFINE(0, loapic_pm_action);
|
2021-10-13 12:25:06 +02:00
|
|
|
|
2023-09-15 22:46:42 +02:00
|
|
|
DEVICE_DT_INST_DEFINE(0, loapic_init, PM_DEVICE_DT_INST_GET(0), NULL, NULL,
|
|
|
|
PRE_KERNEL_1, CONFIG_INTC_INIT_PRIORITY, NULL);
|
2015-12-09 23:53:41 +01:00
|
|
|
|
|
|
|
#if CONFIG_LOAPIC_SPURIOUS_VECTOR
|
2019-03-12 22:15:42 +01:00
|
|
|
extern void z_loapic_spurious_handler(void);
|
2015-12-09 23:53:41 +01:00
|
|
|
|
2019-03-12 22:15:42 +01:00
|
|
|
NANO_CPU_INT_REGISTER(z_loapic_spurious_handler, NANO_SOFT_IRQ,
|
2015-12-09 23:53:41 +01:00
|
|
|
LOAPIC_SPURIOUS_VECTOR_ID >> 4,
|
|
|
|
LOAPIC_SPURIOUS_VECTOR_ID, 0);
|
|
|
|
#endif
|