2015-04-11 07:44:37 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1997-1998, 2000-2002, 2004, 2006-2008, 2011-2015 Wind River
|
2015-10-07 00:00:37 +08:00
|
|
|
* Systems, Inc.
|
2015-04-11 07:44:37 +08:00
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2015-04-11 07:44:37 +08:00
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-04-11 07:44:37 +08:00
|
|
|
*
|
2015-10-07 00:00:37 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2015-04-11 07:44:37 +08:00
|
|
|
*/
|
|
|
|
|
2015-08-11 21:22:05 +08:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief Intel IO APIC/xAPIC driver
|
|
|
|
*
|
|
|
|
* This module is a driver for the IO APIC/xAPIC (Advanced Programmable
|
|
|
|
* Interrupt Controller) for P6 (PentiumPro, II, III) family processors
|
|
|
|
* and P7 (Pentium4) family processors. The IO APIC/xAPIC is included
|
|
|
|
* in the Intel's system chip set, such as ICH2. Software intervention
|
|
|
|
* may be required to enable the IO APIC/xAPIC in some chip sets.
|
|
|
|
* The 8259A interrupt controller is intended for use in a uni-processor
|
|
|
|
* system, IO APIC can be used in either a uni-processor or multi-processor
|
|
|
|
* system. The IO APIC handles interrupts very differently than the 8259A.
|
|
|
|
* Briefly, these differences are:
|
|
|
|
* - Method of Interrupt Transmission. The IO APIC transmits interrupts
|
|
|
|
* through a 3-wire bus and interrupts are handled without the need for
|
|
|
|
* the processor to run an interrupt acknowledge cycle.
|
|
|
|
* - Interrupt Priority. The priority of interrupts in the IO APIC is
|
|
|
|
* independent of the interrupt number. For example, interrupt 10 can
|
|
|
|
* be given a higher priority than interrupt 3.
|
|
|
|
* - More Interrupts. The IO APIC supports a total of 24 interrupts.
|
|
|
|
*
|
|
|
|
* The IO APIC unit consists of a set of interrupt input signals, a 24-entry
|
|
|
|
* by 64-bit Interrupt Redirection Table, programmable registers, and a message
|
|
|
|
* unit for sending and receiving APIC messages over the APIC bus or the
|
|
|
|
* Front-Side (system) bus. IO devices inject interrupts into the system by
|
|
|
|
* asserting one of the interrupt lines to the IO APIC. The IO APIC selects the
|
|
|
|
* corresponding entry in the Redirection Table and uses the information in that
|
|
|
|
* entry to format an interrupt request message. Each entry in the Redirection
|
|
|
|
* Table can be individually programmed to indicate edge/level sensitive interrupt
|
|
|
|
* signals, the interrupt vector and priority, the destination processor, and how
|
|
|
|
* the processor is selected (statically and dynamically). The information in
|
|
|
|
* the table is used to transmit a message to other APIC units (via the APIC bus
|
|
|
|
* or the Front-Side (system) bus). IO APIC is used in the Symmetric IO Mode.
|
|
|
|
* The base address of IO APIC is determined in loapic_init() and stored in the
|
|
|
|
* global variable ioApicBase and ioApicData.
|
|
|
|
* The lower 32 bit value of the redirection table entries for IRQ 0
|
|
|
|
* to 15 are edge triggered positive high, and for IRQ 16 to 23 are level
|
|
|
|
* triggered positive low.
|
|
|
|
*
|
|
|
|
* This implementation doesn't support multiple IO APICs.
|
|
|
|
*
|
|
|
|
* INCLUDE FILES: ioapic.h loapic.h
|
|
|
|
*
|
2015-07-02 05:22:39 +08:00
|
|
|
*/
|
2015-04-11 07:44:37 +08:00
|
|
|
|
|
|
|
#include <nanokernel.h>
|
2015-05-29 01:56:47 +08:00
|
|
|
#include <arch/cpu.h>
|
2015-04-11 07:44:37 +08:00
|
|
|
|
|
|
|
#include "board.h"
|
|
|
|
|
|
|
|
#include <toolchain.h>
|
|
|
|
#include <sections.h>
|
|
|
|
|
|
|
|
#include <drivers/ioapic.h> /* public API declarations */
|
|
|
|
#include <drivers/loapic.h> /* public API declarations and registers */
|
|
|
|
|
|
|
|
/* IO APIC direct register offsets */
|
|
|
|
|
|
|
|
#define IOAPIC_IND 0x00 /* Index Register */
|
|
|
|
#define IOAPIC_DATA 0x10 /* IO window (data) - pc.h */
|
|
|
|
#define IOAPIC_IRQPA 0x20 /* IRQ Pin Assertion Register */
|
|
|
|
#define IOAPIC_EOI 0x40 /* EOI Register */
|
|
|
|
|
|
|
|
/* IO APIC indirect register offset */
|
|
|
|
|
|
|
|
#define IOAPIC_ID 0x00 /* IOAPIC ID */
|
|
|
|
#define IOAPIC_VERS 0x01 /* IOAPIC Version */
|
|
|
|
#define IOAPIC_ARB 0x02 /* IOAPIC Arbitration ID */
|
|
|
|
#define IOAPIC_BOOT 0x03 /* IOAPIC Boot Configuration */
|
|
|
|
#define IOAPIC_REDTBL 0x10 /* Redirection Table (24 * 64bit) */
|
|
|
|
|
|
|
|
/* Interrupt delivery type */
|
|
|
|
|
|
|
|
#define IOAPIC_DT_APIC 0x0 /* APIC serial bus */
|
|
|
|
#define IOAPIC_DT_FS 0x1 /* Front side bus message*/
|
|
|
|
|
|
|
|
/* Version register bits */
|
|
|
|
|
|
|
|
#define IOAPIC_MRE_MASK 0x00ff0000 /* Max Red. entry mask */
|
|
|
|
#define IOAPIC_PRQ 0x00008000 /* this has IRQ reg */
|
|
|
|
#define IOAPIC_VERSION 0x000000ff /* version number */
|
|
|
|
|
|
|
|
/* Redirection table entry number */
|
|
|
|
|
|
|
|
#define MAX_REDTABLE_ENTRIES 24
|
|
|
|
|
|
|
|
/* Redirection table entry bits: upper 32 bit */
|
|
|
|
|
|
|
|
#define IOAPIC_DESTINATION 0xff000000
|
|
|
|
|
|
|
|
/* Redirection table entry bits: lower 32 bit */
|
|
|
|
|
|
|
|
#define IOAPIC_VEC_MASK 0x000000ff
|
|
|
|
|
|
|
|
static uint32_t __IoApicGet(int32_t offset);
|
|
|
|
static void __IoApicSet(int32_t offset, uint32_t value);
|
|
|
|
static void ioApicRedSetHi(unsigned int irq, uint32_t upper32);
|
|
|
|
static void ioApicRedSetLo(unsigned int irq, uint32_t lower32);
|
|
|
|
static uint32_t ioApicRedGetLo(unsigned int irq);
|
|
|
|
static void _IoApicRedUpdateLo(unsigned int irq, uint32_t value,
|
|
|
|
uint32_t mask);
|
|
|
|
|
|
|
|
/*
|
2015-07-27 23:02:41 +08:00
|
|
|
* The functions irq_enable() and irq_disable() are implemented in the
|
|
|
|
* interrupt controller driver due to the IRQ virtualization imposed by
|
|
|
|
* the x86 architecture.
|
2015-04-11 07:44:37 +08:00
|
|
|
*/
|
|
|
|
|
2015-07-02 05:22:39 +08:00
|
|
|
/**
|
|
|
|
*
|
2015-07-02 05:51:40 +08:00
|
|
|
* @brief Initialize the IO APIC or xAPIC
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
|
|
|
* This routine initializes the IO APIC or xAPIC.
|
|
|
|
*
|
2015-07-02 05:29:04 +08:00
|
|
|
* @return N/A
|
2015-07-02 05:22:39 +08:00
|
|
|
*/
|
2015-09-16 00:17:38 +08:00
|
|
|
int _ioapic_init(struct device *unused)
|
2015-04-11 07:44:37 +08:00
|
|
|
{
|
2015-09-16 00:17:38 +08:00
|
|
|
ARG_UNUSED(unused);
|
2015-04-11 07:44:37 +08:00
|
|
|
int32_t ix; /* redirection table index */
|
|
|
|
uint32_t rteValue; /* value to copy into redirection table entry */
|
|
|
|
|
|
|
|
/*
|
2015-07-29 02:39:12 +08:00
|
|
|
* The platform must set the Kconfig option IOAPIC_NUM_RTES to indicate
|
|
|
|
* the number of redirection table entries supported by the IOAPIC.
|
2015-04-11 07:44:37 +08:00
|
|
|
*
|
|
|
|
* Note: The number of actual IRQs supported by the IOAPIC can be
|
2015-07-27 23:02:41 +08:00
|
|
|
* determined at runtime by computing:
|
2015-04-11 07:44:37 +08:00
|
|
|
*
|
|
|
|
* ((__IoApicGet(IOAPIC_VERS) & IOAPIC_MRE_MASK) >> 16) + 1
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the redirection table entries with default settings;
|
|
|
|
* actual interrupt vectors are specified during irq_connect().
|
|
|
|
*
|
|
|
|
* A future enhancement should make this initialization "table driven":
|
2015-07-27 23:02:41 +08:00
|
|
|
* use data provided by the platform to specify the initial state
|
2015-04-11 07:44:37 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
rteValue = IOAPIC_EDGE | IOAPIC_HIGH | IOAPIC_FIXED | IOAPIC_INT_MASK |
|
|
|
|
IOAPIC_PHYSICAL | 0 /* dummy vector */;
|
|
|
|
|
2015-07-29 02:39:12 +08:00
|
|
|
for (ix = 0; ix < CONFIG_IOAPIC_NUM_RTES; ix++) {
|
2015-04-11 07:44:37 +08:00
|
|
|
ioApicRedSetHi(ix, 0);
|
|
|
|
ioApicRedSetLo(ix, rteValue);
|
|
|
|
}
|
2015-09-16 00:17:38 +08:00
|
|
|
return 0;
|
2015-04-11 07:44:37 +08:00
|
|
|
}
|
|
|
|
|
2015-07-02 05:22:39 +08:00
|
|
|
/**
|
|
|
|
*
|
2015-07-02 05:51:40 +08:00
|
|
|
* @brief Enable a specified APIC interrupt input line
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
|
|
|
* This routine enables a specified APIC interrupt input line.
|
2015-08-11 21:22:05 +08:00
|
|
|
* @param irq IRQ number to enable
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
2015-07-02 05:29:04 +08:00
|
|
|
* @return N/A
|
2015-07-02 05:22:39 +08:00
|
|
|
*/
|
2015-08-11 21:22:05 +08:00
|
|
|
void _ioapic_irq_enable(unsigned int irq)
|
2015-04-11 07:44:37 +08:00
|
|
|
{
|
|
|
|
_IoApicRedUpdateLo(irq, 0, IOAPIC_INT_MASK);
|
|
|
|
}
|
|
|
|
|
2015-07-02 05:22:39 +08:00
|
|
|
/**
|
|
|
|
*
|
2015-07-02 05:51:40 +08:00
|
|
|
* @brief Disable a specified APIC interrupt input line
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
|
|
|
* This routine disables a specified APIC interrupt input line.
|
2015-08-11 21:22:05 +08:00
|
|
|
* @param irq IRQ number to disable
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
2015-07-02 05:29:04 +08:00
|
|
|
* @return N/A
|
2015-07-02 05:22:39 +08:00
|
|
|
*/
|
2015-08-11 21:22:05 +08:00
|
|
|
void _ioapic_irq_disable(unsigned int irq)
|
2015-04-11 07:44:37 +08:00
|
|
|
{
|
|
|
|
_IoApicRedUpdateLo(irq, IOAPIC_INT_MASK, IOAPIC_INT_MASK);
|
|
|
|
}
|
|
|
|
|
2015-07-02 05:22:39 +08:00
|
|
|
/**
|
|
|
|
*
|
2015-07-02 05:51:40 +08:00
|
|
|
* @brief Programs the interrupt redirection table
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
|
|
|
* This routine sets up the redirection table entry for the specified IRQ
|
2015-08-11 21:22:05 +08:00
|
|
|
* @param irq Virtualized IRQ
|
|
|
|
* @param vector Vector number
|
|
|
|
* @param flags Interrupt flags
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
2015-07-02 05:29:04 +08:00
|
|
|
* @return N/A
|
2015-07-02 05:22:39 +08:00
|
|
|
*/
|
2015-08-11 21:22:05 +08:00
|
|
|
void _ioapic_irq_set(unsigned int irq, unsigned int vector, uint32_t flags)
|
2015-04-11 07:44:37 +08:00
|
|
|
{
|
|
|
|
uint32_t rteValue; /* value to copy into redirection table entry */
|
|
|
|
|
|
|
|
rteValue = IOAPIC_FIXED | IOAPIC_INT_MASK | IOAPIC_PHYSICAL |
|
|
|
|
(vector & IOAPIC_VEC_MASK) | flags;
|
|
|
|
ioApicRedSetHi(irq, 0);
|
|
|
|
ioApicRedSetLo(irq, rteValue);
|
|
|
|
}
|
|
|
|
|
2015-07-02 05:22:39 +08:00
|
|
|
/**
|
|
|
|
*
|
2015-07-02 05:51:40 +08:00
|
|
|
* @brief Program interrupt vector for specified irq
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
|
|
|
* The routine writes the interrupt vector in the Interrupt Redirection
|
|
|
|
* Table for specified irq number
|
|
|
|
*
|
2015-08-11 21:22:05 +08:00
|
|
|
* @param irq Interrupt number
|
|
|
|
* @param vector Vector number
|
2015-07-02 05:29:04 +08:00
|
|
|
* @return N/A
|
2015-07-02 05:22:39 +08:00
|
|
|
*/
|
2015-08-11 21:22:05 +08:00
|
|
|
void _ioapic_int_vec_set(unsigned int irq, unsigned int vector)
|
2015-04-11 07:44:37 +08:00
|
|
|
{
|
|
|
|
_IoApicRedUpdateLo(irq, vector, IOAPIC_VEC_MASK);
|
|
|
|
}
|
|
|
|
|
2015-07-02 05:22:39 +08:00
|
|
|
/**
|
|
|
|
*
|
2015-07-02 05:51:40 +08:00
|
|
|
* @brief Read a 32 bit IO APIC register
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
|
|
|
* This routine reads the specified IO APIC register using indirect addressing.
|
2015-08-11 21:22:05 +08:00
|
|
|
* @param offset Register offset (8 bits)
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
2015-07-02 05:29:04 +08:00
|
|
|
* @return register value
|
2015-07-02 05:22:39 +08:00
|
|
|
*/
|
2015-08-11 21:22:05 +08:00
|
|
|
static uint32_t __IoApicGet(int32_t offset)
|
2015-04-11 07:44:37 +08:00
|
|
|
{
|
|
|
|
uint32_t value; /* value */
|
|
|
|
int key; /* interrupt lock level */
|
|
|
|
|
|
|
|
/* lock interrupts to ensure indirect addressing works "atomically" */
|
|
|
|
|
|
|
|
key = irq_lock();
|
|
|
|
|
2015-07-29 02:39:12 +08:00
|
|
|
*((volatile char *)
|
|
|
|
(CONFIG_IOAPIC_BASE_ADDRESS + IOAPIC_IND)) = (char)offset;
|
|
|
|
value = *((volatile uint32_t *)(CONFIG_IOAPIC_BASE_ADDRESS + IOAPIC_DATA));
|
2015-04-11 07:44:37 +08:00
|
|
|
|
|
|
|
irq_unlock(key);
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2015-07-02 05:22:39 +08:00
|
|
|
/**
|
|
|
|
*
|
2015-07-02 05:51:40 +08:00
|
|
|
* @brief Write a 32 bit IO APIC register
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
|
|
|
* This routine writes the specified IO APIC register using indirect addressing.
|
|
|
|
*
|
2015-08-11 21:22:05 +08:00
|
|
|
* @param offset Register offset (8 bits)
|
|
|
|
* @param value Value to set the register
|
2015-07-02 05:29:04 +08:00
|
|
|
* @return N/A
|
2015-07-02 05:22:39 +08:00
|
|
|
*/
|
2015-08-11 21:22:05 +08:00
|
|
|
static void __IoApicSet(int32_t offset, uint32_t value)
|
2015-04-11 07:44:37 +08:00
|
|
|
{
|
|
|
|
int key; /* interrupt lock level */
|
|
|
|
|
|
|
|
/* lock interrupts to ensure indirect addressing works "atomically" */
|
|
|
|
|
|
|
|
key = irq_lock();
|
|
|
|
|
2015-07-29 02:39:12 +08:00
|
|
|
*(volatile char *)(CONFIG_IOAPIC_BASE_ADDRESS + IOAPIC_IND) = (char)offset;
|
|
|
|
*((volatile uint32_t *)(CONFIG_IOAPIC_BASE_ADDRESS + IOAPIC_DATA)) = value;
|
2015-04-11 07:44:37 +08:00
|
|
|
|
|
|
|
irq_unlock(key);
|
|
|
|
}
|
|
|
|
|
2015-07-02 05:22:39 +08:00
|
|
|
/**
|
|
|
|
*
|
2015-07-02 05:51:40 +08:00
|
|
|
* @brief Get low 32 bits of Redirection Table entry
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
|
|
|
* This routine reads the low-order 32 bits of a Redirection Table entry.
|
|
|
|
*
|
2015-08-11 21:22:05 +08:00
|
|
|
* @param irq INTIN number
|
2015-07-02 05:29:04 +08:00
|
|
|
* @return 32 low-order bits
|
2015-07-02 05:22:39 +08:00
|
|
|
*/
|
2015-08-11 21:22:05 +08:00
|
|
|
static uint32_t ioApicRedGetLo(unsigned int irq)
|
2015-04-11 07:44:37 +08:00
|
|
|
{
|
|
|
|
int32_t offset = IOAPIC_REDTBL + (irq << 1); /* register offset */
|
|
|
|
|
|
|
|
return __IoApicGet(offset);
|
|
|
|
}
|
|
|
|
|
2015-07-02 05:22:39 +08:00
|
|
|
/**
|
|
|
|
*
|
2015-07-02 05:51:40 +08:00
|
|
|
* @brief Set low 32 bits of Redirection Table entry
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
|
|
|
* This routine writes the low-order 32 bits of a Redirection Table entry.
|
|
|
|
*
|
2015-08-11 21:22:05 +08:00
|
|
|
* @param irq INTIN number
|
|
|
|
* @param lower32 Value to be written
|
2015-07-02 05:29:04 +08:00
|
|
|
* @return N/A
|
2015-07-02 05:22:39 +08:00
|
|
|
*/
|
2015-08-11 21:22:05 +08:00
|
|
|
static void ioApicRedSetLo(unsigned int irq, uint32_t lower32)
|
2015-04-11 07:44:37 +08:00
|
|
|
{
|
|
|
|
int32_t offset = IOAPIC_REDTBL + (irq << 1); /* register offset */
|
|
|
|
|
|
|
|
__IoApicSet(offset, lower32);
|
|
|
|
}
|
|
|
|
|
2015-07-02 05:22:39 +08:00
|
|
|
/**
|
|
|
|
*
|
2015-07-02 05:51:40 +08:00
|
|
|
* @brief Set high 32 bits of Redirection Table entry
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
|
|
|
* This routine writes the high-order 32 bits of a Redirection Table entry.
|
|
|
|
*
|
2015-08-11 21:22:05 +08:00
|
|
|
* @param irq INTIN number
|
|
|
|
* @param upper32 Value to be written
|
2015-07-02 05:29:04 +08:00
|
|
|
* @return N/A
|
2015-07-02 05:22:39 +08:00
|
|
|
*/
|
2015-08-11 21:22:05 +08:00
|
|
|
static void ioApicRedSetHi(unsigned int irq, uint32_t upper32)
|
2015-04-11 07:44:37 +08:00
|
|
|
{
|
|
|
|
int32_t offset = IOAPIC_REDTBL + (irq << 1) + 1; /* register offset */
|
|
|
|
|
|
|
|
__IoApicSet(offset, upper32);
|
|
|
|
}
|
|
|
|
|
2015-07-02 05:22:39 +08:00
|
|
|
/**
|
|
|
|
*
|
2015-07-02 05:51:40 +08:00
|
|
|
* @brief Modify low 32 bits of Redirection Table entry
|
2015-07-02 05:22:39 +08:00
|
|
|
*
|
|
|
|
* This routine modifies selected portions of the low-order 32 bits of a
|
|
|
|
* Redirection Table entry, as indicated by the associate bit mask.
|
|
|
|
*
|
2015-08-11 21:22:05 +08:00
|
|
|
* @param irq INTIN number
|
|
|
|
* @param value Value to be written
|
|
|
|
* @param mask Mask of bits to be modified
|
2015-07-02 05:29:04 +08:00
|
|
|
* @return N/A
|
2015-07-02 05:22:39 +08:00
|
|
|
*/
|
2015-08-11 21:22:05 +08:00
|
|
|
static void _IoApicRedUpdateLo(unsigned int irq,
|
|
|
|
uint32_t value,
|
|
|
|
uint32_t mask)
|
2015-04-11 07:44:37 +08:00
|
|
|
{
|
|
|
|
ioApicRedSetLo(irq, (ioApicRedGetLo(irq) & ~mask) | (value & mask));
|
|
|
|
}
|
|
|
|
|