blob: ae35d90b2c219d386d2b4a85ce1331820967c17a [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 */
Elyes HAOUAScb467282020-04-28 19:55:10 +020030 pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_SPECIAL);
Tobias Diedriche87c38e2010-11-27 09:40:16 +000031
32 /*
Uwe Hermann9da69f82007-11-30 02:08:26 +000033 * The PIIX4 can support the full ISA bus, or the Extended I/O (EIO)
34 * bus, which is a subset of ISA. We select the full ISA bus here.
35 */
36 reg32 = pci_read_config32(dev, GENCFG);
37 reg32 |= ISA; /* Select ISA, not EIO. */
Keith Huice622382020-01-11 03:49:17 -050038
39 /* Some boards use GPO22/23. Select it if configured. */
40 reg32 = ONOFF(sb->gpo22_enable, reg32, GPO2223);
41 pci_write_config32(dev, GENCFG, reg32);
Uwe Hermann9da69f82007-11-30 02:08:26 +000042
43 /* Initialize ISA DMA. */
44 isa_dma_init();
Uwe Hermann77180542010-10-28 08:19:22 +000045
Uwe Hermann77180542010-10-28 08:19:22 +000046 /*
47 * Unlike most other southbridges the 82371EB doesn't have a built-in
48 * IOAPIC. Instead, 82371EB-based boards that support multiple CPUs
49 * have a discrete IOAPIC (Intel 82093AA) soldered onto the board.
50 *
51 * Thus, we can/must only enable the IOAPIC if it actually exists,
52 * i.e. the respective mainboard does "select IOAPIC".
53 */
Keith Hui2f3c37b2020-01-27 18:00:40 -050054 if (CONFIG(IOAPIC)) {
55 u16 reg16;
56 u8 ioapic_id = 2;
57 volatile u32 *ioapic_index = (volatile u32 *)(IO_APIC_ADDR);
58 volatile u32 *ioapic_data = (volatile u32 *)(IO_APIC_ADDR + 0x10);
59
60 /* Enable IOAPIC. */
61 reg16 = pci_read_config16(dev, XBCS);
62 reg16 |= (1 << 8); /* APIC Chip Select */
63 pci_write_config16(dev, XBCS, reg16);
64
65 /* Set the IOAPIC ID. */
66 *ioapic_index = 0;
67 *ioapic_data = ioapic_id << 24;
68
69 /* Read back and verify the IOAPIC ID. */
70 *ioapic_index = 0;
71 reg32 = (*ioapic_data >> 24) & 0x0f;
72 printk(BIOS_DEBUG, "IOAPIC ID = %x\n", reg32);
73 if (reg32 != ioapic_id)
74 die("IOAPIC error!\n");
75 }
Uwe Hermann9da69f82007-11-30 02:08:26 +000076}
77
Myles Watson29cc9ed2009-07-02 18:56:24 +000078static void sb_read_resources(struct device *dev)
79{
80 struct resource *res;
81
82 pci_dev_read_resources(dev);
83
84 res = new_resource(dev, 1);
85 res->base = 0x0UL;
86 res->size = 0x1000UL;
87 res->limit = 0xffffUL;
88 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
89
90 res = new_resource(dev, 2);
91 res->base = 0xff800000UL;
92 res->size = 0x00800000UL; /* 8 MB for flash */
Tobias Diedriche87c38e2010-11-27 09:40:16 +000093 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED |
94 IORESOURCE_RESERVE;
Myles Watson29cc9ed2009-07-02 18:56:24 +000095
Julius Wernercd49cce2019-03-05 16:53:33 -080096#if CONFIG(IOAPIC)
Myles Watson29cc9ed2009-07-02 18:56:24 +000097 res = new_resource(dev, 3); /* IOAPIC */
Uwe Hermann74d1a6e2010-10-12 17:34:08 +000098 res->base = IO_APIC_ADDR;
Myles Watson29cc9ed2009-07-02 18:56:24 +000099 res->size = 0x00001000;
Tobias Diedriche87c38e2010-11-27 09:40:16 +0000100 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED |
101 IORESOURCE_RESERVE;
102#endif
Myles Watson29cc9ed2009-07-02 18:56:24 +0000103}
104
Julius Wernercd49cce2019-03-05 16:53:33 -0800105#if CONFIG(HAVE_ACPI_TABLES)
Furquan Shaikh7536a392020-04-24 21:59:21 -0700106static void southbridge_acpi_fill_ssdt_generator(const struct device *device)
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200107{
108 acpigen_write_mainboard_resources("\\_SB.PCI0.MBRS", "_CRS");
Alexander Couzens5eea4582015-04-12 22:18:55 +0200109 generate_cpu_entries(device);
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200110}
111#endif
112
Uwe Hermann312673c2009-10-27 21:49:33 +0000113static const struct device_operations isa_ops = {
Myles Watson29cc9ed2009-07-02 18:56:24 +0000114 .read_resources = sb_read_resources,
Uwe Hermann9da69f82007-11-30 02:08:26 +0000115 .set_resources = pci_dev_set_resources,
116 .enable_resources = pci_dev_enable_resources,
Julius Wernercd49cce2019-03-05 16:53:33 -0800117#if CONFIG(HAVE_ACPI_TABLES)
Nico Huber68680dd2020-03-31 17:34:52 +0200118 .write_acpi_tables = acpi_write_hpet,
119 .acpi_fill_ssdt = southbridge_acpi_fill_ssdt_generator,
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200120#endif
Uwe Hermann9da69f82007-11-30 02:08:26 +0000121 .init = isa_init,
Nico Huber51b75ae2019-03-14 16:02:05 +0100122 .scan_bus = scan_static_bus,
Uwe Hermann9da69f82007-11-30 02:08:26 +0000123 .ops_pci = 0, /* No subsystem IDs on 82371EB! */
124};
125
126static const struct pci_driver isa_driver __pci_driver = {
127 .ops = &isa_ops,
128 .vendor = PCI_VENDOR_ID_INTEL,
129 .device = PCI_DEVICE_ID_INTEL_82371AB_ISA,
130};
Patrick Georgi17dda3a2020-03-03 17:05:25 +0000131
132static const struct pci_driver isa_SB_driver __pci_driver = {
133 .ops = &isa_ops,
134 .vendor = PCI_VENDOR_ID_INTEL,
135 .device = PCI_DEVICE_ID_INTEL_82371SB_ISA,
136};