blob: efbfb22470cc65527894b65a78a6df13f149eba3 [file] [log] [blame]
Patrick Georgiac959032020-05-05 22:49:26 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Uwe Hermann9da69f82007-11-30 02:08:26 +00002
3#include <stdint.h>
4#include <console/console.h>
5#include <device/device.h>
6#include <device/pci.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02007#include <device/pci_ops.h>
Uwe Hermann9da69f82007-11-30 02:08:26 +00008#include <device/pci_ids.h>
9#include <pc80/isa-dma.h>
10#include <pc80/mc146818rtc.h>
Uwe Hermann74d1a6e2010-10-12 17:34:08 +000011#include <arch/ioapic.h>
Julius Wernercd49cce2019-03-05 16:53:33 -080012#if CONFIG(HAVE_ACPI_TABLES)
Furquan Shaikh76cedd22020-05-02 10:24:23 -070013#include <acpi/acpi.h>
14#include <acpi/acpigen.h>
Vladimir Serbinenko41877d82014-09-01 22:18:01 +020015#endif
Uwe Hermann9da69f82007-11-30 02:08:26 +000016#include "i82371eb.h"
Keith Huice622382020-01-11 03:49:17 -050017#include "chip.h"
Uwe Hermann9da69f82007-11-30 02:08:26 +000018
19static void isa_init(struct device *dev)
20{
Uwe Hermann9da69f82007-11-30 02:08:26 +000021 u32 reg32;
Keith Huice622382020-01-11 03:49:17 -050022 struct southbridge_intel_i82371eb_config *sb = dev->chip_info;
Uwe Hermann9da69f82007-11-30 02:08:26 +000023
24 /* Initialize the real time clock (RTC). */
Gabe Blackb3f08c62014-04-30 17:12:25 -070025 cmos_init(0);
Uwe Hermann9da69f82007-11-30 02:08:26 +000026
Uwe Hermann9da69f82007-11-30 02:08:26 +000027 /*
Tobias Diedriche87c38e2010-11-27 09:40:16 +000028 * Enable special cycles, needed for soft poweroff.
29 */
30 reg32 = pci_read_config16(dev, PCI_COMMAND);
31 reg32 |= PCI_COMMAND_SPECIAL;
32 pci_write_config16(dev, PCI_COMMAND, reg32);
33
34 /*
Uwe Hermann9da69f82007-11-30 02:08:26 +000035 * The PIIX4 can support the full ISA bus, or the Extended I/O (EIO)
36 * bus, which is a subset of ISA. We select the full ISA bus here.
37 */
38 reg32 = pci_read_config32(dev, GENCFG);
39 reg32 |= ISA; /* Select ISA, not EIO. */
Keith Huice622382020-01-11 03:49:17 -050040
41 /* Some boards use GPO22/23. Select it if configured. */
42 reg32 = ONOFF(sb->gpo22_enable, reg32, GPO2223);
43 pci_write_config32(dev, GENCFG, reg32);
Uwe Hermann9da69f82007-11-30 02:08:26 +000044
45 /* Initialize ISA DMA. */
46 isa_dma_init();
Uwe Hermann77180542010-10-28 08:19:22 +000047
Uwe Hermann77180542010-10-28 08:19:22 +000048 /*
49 * Unlike most other southbridges the 82371EB doesn't have a built-in
50 * IOAPIC. Instead, 82371EB-based boards that support multiple CPUs
51 * have a discrete IOAPIC (Intel 82093AA) soldered onto the board.
52 *
53 * Thus, we can/must only enable the IOAPIC if it actually exists,
54 * i.e. the respective mainboard does "select IOAPIC".
55 */
Keith Hui2f3c37b2020-01-27 18:00:40 -050056 if (CONFIG(IOAPIC)) {
57 u16 reg16;
58 u8 ioapic_id = 2;
59 volatile u32 *ioapic_index = (volatile u32 *)(IO_APIC_ADDR);
60 volatile u32 *ioapic_data = (volatile u32 *)(IO_APIC_ADDR + 0x10);
61
62 /* Enable IOAPIC. */
63 reg16 = pci_read_config16(dev, XBCS);
64 reg16 |= (1 << 8); /* APIC Chip Select */
65 pci_write_config16(dev, XBCS, reg16);
66
67 /* Set the IOAPIC ID. */
68 *ioapic_index = 0;
69 *ioapic_data = ioapic_id << 24;
70
71 /* Read back and verify the IOAPIC ID. */
72 *ioapic_index = 0;
73 reg32 = (*ioapic_data >> 24) & 0x0f;
74 printk(BIOS_DEBUG, "IOAPIC ID = %x\n", reg32);
75 if (reg32 != ioapic_id)
76 die("IOAPIC error!\n");
77 }
Uwe Hermann9da69f82007-11-30 02:08:26 +000078}
79
Myles Watson29cc9ed2009-07-02 18:56:24 +000080static void sb_read_resources(struct device *dev)
81{
82 struct resource *res;
83
84 pci_dev_read_resources(dev);
85
86 res = new_resource(dev, 1);
87 res->base = 0x0UL;
88 res->size = 0x1000UL;
89 res->limit = 0xffffUL;
90 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
91
92 res = new_resource(dev, 2);
93 res->base = 0xff800000UL;
94 res->size = 0x00800000UL; /* 8 MB for flash */
Tobias Diedriche87c38e2010-11-27 09:40:16 +000095 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED |
96 IORESOURCE_RESERVE;
Myles Watson29cc9ed2009-07-02 18:56:24 +000097
Julius Wernercd49cce2019-03-05 16:53:33 -080098#if CONFIG(IOAPIC)
Myles Watson29cc9ed2009-07-02 18:56:24 +000099 res = new_resource(dev, 3); /* IOAPIC */
Uwe Hermann74d1a6e2010-10-12 17:34:08 +0000100 res->base = IO_APIC_ADDR;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000101 res->size = 0x00001000;
Tobias Diedriche87c38e2010-11-27 09:40:16 +0000102 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED |
103 IORESOURCE_RESERVE;
104#endif
Myles Watson29cc9ed2009-07-02 18:56:24 +0000105}
106
Julius Wernercd49cce2019-03-05 16:53:33 -0800107#if CONFIG(HAVE_ACPI_TABLES)
Furquan Shaikh7536a392020-04-24 21:59:21 -0700108static void southbridge_acpi_fill_ssdt_generator(const struct device *device)
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200109{
110 acpigen_write_mainboard_resources("\\_SB.PCI0.MBRS", "_CRS");
Alexander Couzens5eea4582015-04-12 22:18:55 +0200111 generate_cpu_entries(device);
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200112}
113#endif
114
Uwe Hermann312673c2009-10-27 21:49:33 +0000115static const struct device_operations isa_ops = {
Myles Watson29cc9ed2009-07-02 18:56:24 +0000116 .read_resources = sb_read_resources,
Uwe Hermann9da69f82007-11-30 02:08:26 +0000117 .set_resources = pci_dev_set_resources,
118 .enable_resources = pci_dev_enable_resources,
Julius Wernercd49cce2019-03-05 16:53:33 -0800119#if CONFIG(HAVE_ACPI_TABLES)
Nico Huber68680dd2020-03-31 17:34:52 +0200120 .write_acpi_tables = acpi_write_hpet,
121 .acpi_fill_ssdt = southbridge_acpi_fill_ssdt_generator,
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200122#endif
Uwe Hermann9da69f82007-11-30 02:08:26 +0000123 .init = isa_init,
Nico Huber51b75ae2019-03-14 16:02:05 +0100124 .scan_bus = scan_static_bus,
Uwe Hermann9da69f82007-11-30 02:08:26 +0000125 .ops_pci = 0, /* No subsystem IDs on 82371EB! */
126};
127
128static const struct pci_driver isa_driver __pci_driver = {
129 .ops = &isa_ops,
130 .vendor = PCI_VENDOR_ID_INTEL,
131 .device = PCI_DEVICE_ID_INTEL_82371AB_ISA,
132};
Patrick Georgi17dda3a2020-03-03 17:05:25 +0000133
134static const struct pci_driver isa_SB_driver __pci_driver = {
135 .ops = &isa_ops,
136 .vendor = PCI_VENDOR_ID_INTEL,
137 .device = PCI_DEVICE_ID_INTEL_82371SB_ISA,
138};