blob: 692fd8b7005d87ed80adf3b08113b9c56a657fb5 [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;
Felix Held10942bf2024-02-05 17:24:49 +010056 const u8 ioapic_id = 2;
Keith Hui2f3c37b2020-01-27 18:00:40 -050057
58 /* Enable IOAPIC. */
59 reg16 = pci_read_config16(dev, XBCS);
60 reg16 |= (1 << 8); /* APIC Chip Select */
61 pci_write_config16(dev, XBCS, reg16);
62
Kyösti Mälkki401ec982021-06-06 08:27:15 +030063 /* Set and verify the IOAPIC ID. */
Felix Held0d192892024-02-06 16:55:29 +010064 setup_ioapic(IO_APIC_ADDR, ioapic_id);
65 if (ioapic_id != get_ioapic_id(IO_APIC_ADDR))
Keith Hui2f3c37b2020-01-27 18:00:40 -050066 die("IOAPIC error!\n");
67 }
Uwe Hermann9da69f82007-11-30 02:08:26 +000068}
69
Kyösti Mälkkie742b682023-04-10 17:03:32 +030070#define ACPI_SCI_IRQ 9
71
72void ioapic_get_sci_pin(u8 *gsi, u8 *irq, u8 *flags)
73{
74 *gsi = ACPI_SCI_IRQ;
75 *irq = ACPI_SCI_IRQ;
76 *flags = MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_HIGH;
77}
78
Myles Watson29cc9ed2009-07-02 18:56:24 +000079static void sb_read_resources(struct device *dev)
80{
81 struct resource *res;
82
83 pci_dev_read_resources(dev);
84
85 res = new_resource(dev, 1);
86 res->base = 0x0UL;
87 res->size = 0x1000UL;
88 res->limit = 0xffffUL;
89 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
90
91 res = new_resource(dev, 2);
92 res->base = 0xff800000UL;
93 res->size = 0x00800000UL; /* 8 MB for flash */
Tobias Diedriche87c38e2010-11-27 09:40:16 +000094 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED |
95 IORESOURCE_RESERVE;
Myles Watson29cc9ed2009-07-02 18:56:24 +000096
97 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;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000102}
103
Uwe Hermann312673c2009-10-27 21:49:33 +0000104static const struct device_operations isa_ops = {
Myles Watson29cc9ed2009-07-02 18:56:24 +0000105 .read_resources = sb_read_resources,
Uwe Hermann9da69f82007-11-30 02:08:26 +0000106 .set_resources = pci_dev_set_resources,
107 .enable_resources = pci_dev_enable_resources,
Julius Wernercd49cce2019-03-05 16:53:33 -0800108#if CONFIG(HAVE_ACPI_TABLES)
Nico Huber68680dd2020-03-31 17:34:52 +0200109 .write_acpi_tables = acpi_write_hpet,
Keith Hui562279e2020-05-15 16:14:26 -0400110 .acpi_fill_ssdt = generate_cpu_entries,
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200111#endif
Uwe Hermann9da69f82007-11-30 02:08:26 +0000112 .init = isa_init,
Nico Huber51b75ae2019-03-14 16:02:05 +0100113 .scan_bus = scan_static_bus,
Uwe Hermann9da69f82007-11-30 02:08:26 +0000114 .ops_pci = 0, /* No subsystem IDs on 82371EB! */
115};
116
117static const struct pci_driver isa_driver __pci_driver = {
118 .ops = &isa_ops,
Felix Singer43b7f412022-03-07 04:34:52 +0100119 .vendor = PCI_VID_INTEL,
120 .device = PCI_DID_INTEL_82371AB_ISA,
Uwe Hermann9da69f82007-11-30 02:08:26 +0000121};
Patrick Georgi17dda3a2020-03-03 17:05:25 +0000122
123static const struct pci_driver isa_SB_driver __pci_driver = {
124 .ops = &isa_ops,
Felix Singer43b7f412022-03-07 04:34:52 +0100125 .vendor = PCI_VID_INTEL,
126 .device = PCI_DID_INTEL_82371SB_ISA,
Patrick Georgi17dda3a2020-03-03 17:05:25 +0000127};