Add IOAPIC support for Intel 82371EB and fixup SMP on ASUS P2B-D.
[coreboot.git] / src / southbridge / intel / i82371eb / i82371eb_isa.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007 Uwe Hermann <uwe@hermann-uwe.de>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19  */
20
21 #include <stdint.h>
22 #include <console/console.h>
23 #include <device/device.h>
24 #include <device/pci.h>
25 #include <device/pci_ids.h>
26 #include <pc80/isa-dma.h>
27 #include <pc80/mc146818rtc.h>
28 #include <arch/ioapic.h>
29 #include "i82371eb.h"
30
31 static void enable_intel_82093aa_ioapic(void)
32 {
33         u16 reg16;
34         u32 reg32;
35         u8 ioapic_id = 2;
36         volatile u32 *ioapic_index = (volatile u32 *)(IO_APIC_ADDR);
37         volatile u32 *ioapic_data = (volatile u32 *)(IO_APIC_ADDR + 0x10);
38         device_t dev;
39
40         dev = dev_find_device(PCI_VENDOR_ID_INTEL,
41                               PCI_DEVICE_ID_INTEL_82371AB_ISA, 0);
42
43         /* Enable IOAPIC. */
44         reg16 = pci_read_config16(dev, XBCS);
45         reg16 |= (1 << 8); /* APIC Chip Select */
46         pci_write_config16(dev, XBCS, reg16);
47
48         /* Set the IOAPIC ID. */
49         *ioapic_index = 0;
50         *ioapic_data = ioapic_id << 24;
51
52         /* Read back and verify the IOAPIC ID. */
53         *ioapic_index = 0;
54         reg32 = (*ioapic_data >> 24) & 0x0f;
55         printk(BIOS_DEBUG, "IOAPIC ID = %x\n", reg32);
56         if (reg32 != ioapic_id)
57                 die("IOAPIC error!\n");
58 }
59
60 static void isa_init(struct device *dev)
61 {
62         u32 reg32;
63
64         /* Initialize the real time clock (RTC). */
65         rtc_init(0);
66
67         /*
68          * The PIIX4 can support the full ISA bus, or the Extended I/O (EIO)
69          * bus, which is a subset of ISA. We select the full ISA bus here.
70          */
71         reg32 = pci_read_config32(dev, GENCFG);
72         reg32 |= ISA;   /* Select ISA, not EIO. */
73         pci_write_config16(dev, GENCFG, reg32);
74
75         /* Initialize ISA DMA. */
76         isa_dma_init();
77
78 #if CONFIG_IOAPIC
79         /*
80          * Unlike most other southbridges the 82371EB doesn't have a built-in
81          * IOAPIC. Instead, 82371EB-based boards that support multiple CPUs
82          * have a discrete IOAPIC (Intel 82093AA) soldered onto the board.
83          *
84          * Thus, we can/must only enable the IOAPIC if it actually exists,
85          * i.e. the respective mainboard does "select IOAPIC".
86          */
87         enable_intel_82093aa_ioapic();
88 #endif
89 }
90
91 static void sb_read_resources(struct device *dev)
92 {
93         struct resource *res;
94
95         pci_dev_read_resources(dev);
96
97         res = new_resource(dev, 1);
98         res->base = 0x0UL;
99         res->size = 0x1000UL;
100         res->limit = 0xffffUL;
101         res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
102
103         res = new_resource(dev, 2);
104         res->base = 0xff800000UL;
105         res->size = 0x00800000UL; /* 8 MB for flash */
106         res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
107
108         res = new_resource(dev, 3); /* IOAPIC */
109         res->base = IO_APIC_ADDR;
110         res->size = 0x00001000;
111         res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
112 }
113
114 static const struct device_operations isa_ops = {
115         .read_resources         = sb_read_resources,
116         .set_resources          = pci_dev_set_resources,
117         .enable_resources       = pci_dev_enable_resources,
118         .init                   = isa_init,
119         .scan_bus               = scan_static_bus,      /* TODO: Needed? */
120         .enable                 = 0,
121         .ops_pci                = 0, /* No subsystem IDs on 82371EB! */
122 };
123
124 static const struct pci_driver isa_driver __pci_driver = {
125         .ops    = &isa_ops,
126         .vendor = PCI_VENDOR_ID_INTEL,
127         .device = PCI_DEVICE_ID_INTEL_82371AB_ISA,
128 };
129
130 static const struct pci_driver isa_SB_driver __pci_driver = {
131         .ops    = &isa_ops,
132         .vendor = PCI_VENDOR_ID_INTEL,
133         .device = PCI_DEVICE_ID_INTEL_82371SB_ISA,
134 };