blob: 1deddf6f75e73f74ba8e507ba174d068af02addb [file] [log] [blame]
Uwe Hermann9da69f82007-11-30 02:08:26 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Uwe Hermann9da69f82007-11-30 02:08:26 +00003 *
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
Paul Menzela46a7122013-02-23 18:37:27 +010018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Uwe Hermann9da69f82007-11-30 02:08:26 +000019 */
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>
Uwe Hermann74d1a6e2010-10-12 17:34:08 +000028#include <arch/ioapic.h>
Vladimir Serbinenko41877d82014-09-01 22:18:01 +020029#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
30#include <arch/acpi.h>
31#include <arch/acpigen.h>
32#endif
Uwe Hermann9da69f82007-11-30 02:08:26 +000033#include "i82371eb.h"
34
Uwe Hermannb34ff662010-10-28 14:22:20 +000035#if CONFIG_IOAPIC
Uwe Hermann77180542010-10-28 08:19:22 +000036static void enable_intel_82093aa_ioapic(void)
37{
38 u16 reg16;
39 u32 reg32;
40 u8 ioapic_id = 2;
41 volatile u32 *ioapic_index = (volatile u32 *)(IO_APIC_ADDR);
42 volatile u32 *ioapic_data = (volatile u32 *)(IO_APIC_ADDR + 0x10);
43 device_t dev;
44
45 dev = dev_find_device(PCI_VENDOR_ID_INTEL,
46 PCI_DEVICE_ID_INTEL_82371AB_ISA, 0);
47
48 /* Enable IOAPIC. */
49 reg16 = pci_read_config16(dev, XBCS);
50 reg16 |= (1 << 8); /* APIC Chip Select */
51 pci_write_config16(dev, XBCS, reg16);
52
53 /* Set the IOAPIC ID. */
54 *ioapic_index = 0;
55 *ioapic_data = ioapic_id << 24;
56
57 /* Read back and verify the IOAPIC ID. */
58 *ioapic_index = 0;
59 reg32 = (*ioapic_data >> 24) & 0x0f;
60 printk(BIOS_DEBUG, "IOAPIC ID = %x\n", reg32);
61 if (reg32 != ioapic_id)
62 die("IOAPIC error!\n");
63}
Uwe Hermannb34ff662010-10-28 14:22:20 +000064#endif
Uwe Hermann77180542010-10-28 08:19:22 +000065
Uwe Hermann9da69f82007-11-30 02:08:26 +000066static void isa_init(struct device *dev)
67{
Uwe Hermann9da69f82007-11-30 02:08:26 +000068 u32 reg32;
69
70 /* Initialize the real time clock (RTC). */
Gabe Blackb3f08c62014-04-30 17:12:25 -070071 cmos_init(0);
Uwe Hermann9da69f82007-11-30 02:08:26 +000072
Uwe Hermann9da69f82007-11-30 02:08:26 +000073 /*
Tobias Diedriche87c38e2010-11-27 09:40:16 +000074 * Enable special cycles, needed for soft poweroff.
75 */
76 reg32 = pci_read_config16(dev, PCI_COMMAND);
77 reg32 |= PCI_COMMAND_SPECIAL;
78 pci_write_config16(dev, PCI_COMMAND, reg32);
79
80 /*
Uwe Hermann9da69f82007-11-30 02:08:26 +000081 * The PIIX4 can support the full ISA bus, or the Extended I/O (EIO)
82 * bus, which is a subset of ISA. We select the full ISA bus here.
83 */
84 reg32 = pci_read_config32(dev, GENCFG);
85 reg32 |= ISA; /* Select ISA, not EIO. */
86 pci_write_config16(dev, GENCFG, reg32);
87
88 /* Initialize ISA DMA. */
89 isa_dma_init();
Uwe Hermann77180542010-10-28 08:19:22 +000090
91#if CONFIG_IOAPIC
92 /*
93 * Unlike most other southbridges the 82371EB doesn't have a built-in
94 * IOAPIC. Instead, 82371EB-based boards that support multiple CPUs
95 * have a discrete IOAPIC (Intel 82093AA) soldered onto the board.
96 *
97 * Thus, we can/must only enable the IOAPIC if it actually exists,
98 * i.e. the respective mainboard does "select IOAPIC".
99 */
100 enable_intel_82093aa_ioapic();
101#endif
Uwe Hermann9da69f82007-11-30 02:08:26 +0000102}
103
Myles Watson29cc9ed2009-07-02 18:56:24 +0000104static void sb_read_resources(struct device *dev)
105{
106 struct resource *res;
107
108 pci_dev_read_resources(dev);
109
110 res = new_resource(dev, 1);
111 res->base = 0x0UL;
112 res->size = 0x1000UL;
113 res->limit = 0xffffUL;
114 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
115
116 res = new_resource(dev, 2);
117 res->base = 0xff800000UL;
118 res->size = 0x00800000UL; /* 8 MB for flash */
Tobias Diedriche87c38e2010-11-27 09:40:16 +0000119 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED |
120 IORESOURCE_RESERVE;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000121
Tobias Diedriche87c38e2010-11-27 09:40:16 +0000122#if CONFIG_IOAPIC
Myles Watson29cc9ed2009-07-02 18:56:24 +0000123 res = new_resource(dev, 3); /* IOAPIC */
Uwe Hermann74d1a6e2010-10-12 17:34:08 +0000124 res->base = IO_APIC_ADDR;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000125 res->size = 0x00001000;
Tobias Diedriche87c38e2010-11-27 09:40:16 +0000126 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED |
127 IORESOURCE_RESERVE;
128#endif
Myles Watson29cc9ed2009-07-02 18:56:24 +0000129}
130
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200131#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
132static void southbridge_acpi_fill_ssdt_generator(void)
133{
134 acpigen_write_mainboard_resources("\\_SB.PCI0.MBRS", "_CRS");
135 generate_cpu_entries();
136}
137#endif
138
Uwe Hermann312673c2009-10-27 21:49:33 +0000139static const struct device_operations isa_ops = {
Myles Watson29cc9ed2009-07-02 18:56:24 +0000140 .read_resources = sb_read_resources,
Uwe Hermann9da69f82007-11-30 02:08:26 +0000141 .set_resources = pci_dev_set_resources,
142 .enable_resources = pci_dev_enable_resources,
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200143#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
144 .write_acpi_tables = acpi_write_hpet,
145 .acpi_fill_ssdt_generator = southbridge_acpi_fill_ssdt_generator,
146#endif
Uwe Hermann9da69f82007-11-30 02:08:26 +0000147 .init = isa_init,
148 .scan_bus = scan_static_bus, /* TODO: Needed? */
149 .enable = 0,
150 .ops_pci = 0, /* No subsystem IDs on 82371EB! */
151};
152
153static const struct pci_driver isa_driver __pci_driver = {
154 .ops = &isa_ops,
155 .vendor = PCI_VENDOR_ID_INTEL,
156 .device = PCI_DEVICE_ID_INTEL_82371AB_ISA,
157};
Myles Watson0520d552009-05-11 22:44:14 +0000158
159static const struct pci_driver isa_SB_driver __pci_driver = {
160 .ops = &isa_ops,
161 .vendor = PCI_VENDOR_ID_INTEL,
162 .device = PCI_DEVICE_ID_INTEL_82371SB_ISA,
163};