2010-01-16 19:31:34 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the coreboot project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 coresystems GmbH
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <arch/io.h>
|
2003-04-24 08:25:08 +02:00
|
|
|
#include <arch/ioapic.h>
|
2010-01-16 19:31:34 +01:00
|
|
|
#include <console/console.h>
|
|
|
|
#include <cpu/x86/lapic.h>
|
2003-04-24 08:25:08 +02:00
|
|
|
|
2010-01-16 19:31:34 +01:00
|
|
|
static u32 io_apic_read(u32 ioapic_base, u32 reg)
|
|
|
|
{
|
|
|
|
write32(ioapic_base, reg);
|
|
|
|
return read32(ioapic_base + 0x10);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void io_apic_write(u32 ioapic_base, u32 reg, u32 value)
|
|
|
|
{
|
|
|
|
write32(ioapic_base, reg);
|
|
|
|
write32(ioapic_base + 0x10, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear_ioapic(u32 ioapic_base)
|
|
|
|
{
|
|
|
|
u32 low, high;
|
|
|
|
u32 i, ioapic_interrupts;
|
|
|
|
|
2010-04-27 08:56:47 +02:00
|
|
|
printk(BIOS_DEBUG, "IOAPIC: Clearing IOAPIC at 0x%08x\n", ioapic_base);
|
2010-01-16 19:31:34 +01:00
|
|
|
|
2010-10-15 01:40:10 +02:00
|
|
|
/* Read the available number of interrupts. */
|
|
|
|
ioapic_interrupts = (io_apic_read(ioapic_base, 0x01) >> 16) & 0xff;
|
2010-01-16 19:31:34 +01:00
|
|
|
if (!ioapic_interrupts || ioapic_interrupts == 0xff)
|
|
|
|
ioapic_interrupts = 24;
|
2010-04-27 08:56:47 +02:00
|
|
|
printk(BIOS_DEBUG, "IOAPIC: %d interrupts\n", ioapic_interrupts);
|
2010-01-16 19:31:34 +01:00
|
|
|
|
|
|
|
low = DISABLED;
|
|
|
|
high = NONE;
|
|
|
|
|
|
|
|
for (i = 0; i < ioapic_interrupts; i++) {
|
|
|
|
io_apic_write(ioapic_base, i * 2 + 0x10, low);
|
|
|
|
io_apic_write(ioapic_base, i * 2 + 0x11, high);
|
|
|
|
|
2010-10-15 01:40:10 +02:00
|
|
|
printk(BIOS_SPEW, "IOAPIC: reg 0x%08x value 0x%08x 0x%08x\n",
|
|
|
|
i, high, low);
|
2010-01-16 19:31:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (io_apic_read(ioapic_base, 0x10) == 0xffffffff) {
|
2010-10-15 01:40:10 +02:00
|
|
|
printk(BIOS_WARNING, "IOAPIC not responding.\n");
|
2010-01-16 19:31:34 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void setup_ioapic(u32 ioapic_base, u8 ioapic_id)
|
2003-04-24 08:25:08 +02:00
|
|
|
{
|
2010-01-16 19:31:34 +01:00
|
|
|
u32 bsp_lapicid = lapicid();
|
|
|
|
u32 low, high;
|
|
|
|
u32 i, ioapic_interrupts;
|
|
|
|
|
2010-10-15 01:40:10 +02:00
|
|
|
printk(BIOS_DEBUG, "IOAPIC: Initializing IOAPIC at 0x%08x\n",
|
|
|
|
ioapic_base);
|
|
|
|
printk(BIOS_DEBUG, "IOAPIC: Bootstrap Processor Local APIC = 0x%02x\n",
|
|
|
|
bsp_lapicid);
|
2010-01-16 19:31:34 +01:00
|
|
|
|
|
|
|
if (ioapic_id) {
|
2010-04-27 08:56:47 +02:00
|
|
|
printk(BIOS_DEBUG, "IOAPIC: ID = 0x%02x\n", ioapic_id);
|
2010-10-15 01:40:10 +02:00
|
|
|
/* Set IOAPIC ID if it has been specified. */
|
2010-04-27 08:56:47 +02:00
|
|
|
io_apic_write(ioapic_base, 0x00,
|
2011-10-19 06:23:51 +02:00
|
|
|
(io_apic_read(ioapic_base, 0x00) & 0xf0ffffff) |
|
2010-10-15 01:40:10 +02:00
|
|
|
(ioapic_id << 24));
|
2010-01-16 19:31:34 +01:00
|
|
|
}
|
|
|
|
|
2010-10-15 01:40:10 +02:00
|
|
|
/* Read the available number of interrupts. */
|
|
|
|
ioapic_interrupts = (io_apic_read(ioapic_base, 0x01) >> 16) & 0xff;
|
2010-01-16 19:31:34 +01:00
|
|
|
if (!ioapic_interrupts || ioapic_interrupts == 0xff)
|
|
|
|
ioapic_interrupts = 24;
|
2010-04-27 08:56:47 +02:00
|
|
|
printk(BIOS_DEBUG, "IOAPIC: %d interrupts\n", ioapic_interrupts);
|
2010-01-16 19:31:34 +01:00
|
|
|
|
2012-03-16 19:28:15 +01:00
|
|
|
#ifdef CONFIG_IOAPIC_INTERRUPTS_ON_FSB
|
2010-10-15 01:40:10 +02:00
|
|
|
/*
|
|
|
|
* For the Pentium 4 and above APICs deliver their interrupts
|
2003-04-24 08:25:08 +02:00
|
|
|
* on the front side bus, enable that.
|
|
|
|
*/
|
2010-04-27 08:56:47 +02:00
|
|
|
printk(BIOS_DEBUG, "IOAPIC: Enabling interrupts on FSB\n");
|
2010-10-15 01:40:10 +02:00
|
|
|
io_apic_write(ioapic_base, 0x03,
|
|
|
|
io_apic_read(ioapic_base, 0x03) | (1 << 0));
|
2010-01-16 19:31:34 +01:00
|
|
|
#endif
|
2012-03-16 19:28:15 +01:00
|
|
|
#ifdef CONFIG_IOAPIC_INTERRUPTS_ON_APIC_SERIAL_BUS
|
2010-04-27 08:56:47 +02:00
|
|
|
printk(BIOS_DEBUG, "IOAPIC: Enabling interrupts on APIC serial bus\n");
|
2010-01-16 19:31:34 +01:00
|
|
|
io_apic_write(ioapic_base, 0x03, 0);
|
|
|
|
#endif
|
|
|
|
|
2010-10-15 01:40:10 +02:00
|
|
|
/* Enable Virtual Wire Mode. */
|
2010-01-16 19:31:34 +01:00
|
|
|
low = ENABLED | TRIGGER_EDGE | POLARITY_HIGH | PHYSICAL_DEST | ExtINT;
|
|
|
|
high = bsp_lapicid << (56 - 32);
|
|
|
|
|
|
|
|
io_apic_write(ioapic_base, 0x10, low);
|
|
|
|
io_apic_write(ioapic_base, 0x11, high);
|
|
|
|
|
|
|
|
if (io_apic_read(ioapic_base, 0x10) == 0xffffffff) {
|
2010-10-15 01:40:10 +02:00
|
|
|
printk(BIOS_WARNING, "IOAPIC not responding.\n");
|
2010-01-16 19:31:34 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-15 01:40:10 +02:00
|
|
|
printk(BIOS_SPEW, "IOAPIC: reg 0x%08x value 0x%08x 0x%08x\n",
|
|
|
|
0, high, low);
|
2010-01-16 19:31:34 +01:00
|
|
|
|
|
|
|
low = DISABLED;
|
|
|
|
high = NONE;
|
|
|
|
|
|
|
|
for (i = 1; i < ioapic_interrupts; i++) {
|
|
|
|
io_apic_write(ioapic_base, i * 2 + 0x10, low);
|
|
|
|
io_apic_write(ioapic_base, i * 2 + 0x11, high);
|
|
|
|
|
2010-10-15 01:40:10 +02:00
|
|
|
printk(BIOS_SPEW, "IOAPIC: reg 0x%08x value 0x%08x 0x%08x\n",
|
|
|
|
i, high, low);
|
2003-04-24 08:25:08 +02:00
|
|
|
}
|
|
|
|
}
|