blob: c5329f43134640b08e37abd2aab89ee430fcd4fa [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;
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. */
Kyösti Mälkki682613f2021-06-08 11:31:19 +030064 setup_ioapic(VIO_APIC_VADDR, ioapic_id);
Kyösti Mälkki401ec982021-06-06 08:27:15 +030065 if (ioapic_id != get_ioapic_id(VIO_APIC_VADDR))
Keith Hui2f3c37b2020-01-27 18:00:40 -050066 die("IOAPIC error!\n");
67 }
Uwe Hermann9da69f82007-11-30 02:08:26 +000068}
69
Myles Watson29cc9ed2009-07-02 18:56:24 +000070static void sb_read_resources(struct device *dev)
71{
72 struct resource *res;
73
74 pci_dev_read_resources(dev);
75
76 res = new_resource(dev, 1);
77 res->base = 0x0UL;
78 res->size = 0x1000UL;
79 res->limit = 0xffffUL;
80 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
81
82 res = new_resource(dev, 2);
83 res->base = 0xff800000UL;
84 res->size = 0x00800000UL; /* 8 MB for flash */
Tobias Diedriche87c38e2010-11-27 09:40:16 +000085 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED |
86 IORESOURCE_RESERVE;
Myles Watson29cc9ed2009-07-02 18:56:24 +000087
88 res = new_resource(dev, 3); /* IOAPIC */
Uwe Hermann74d1a6e2010-10-12 17:34:08 +000089 res->base = IO_APIC_ADDR;
Myles Watson29cc9ed2009-07-02 18:56:24 +000090 res->size = 0x00001000;
Tobias Diedriche87c38e2010-11-27 09:40:16 +000091 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED |
92 IORESOURCE_RESERVE;
Myles Watson29cc9ed2009-07-02 18:56:24 +000093}
94
Uwe Hermann312673c2009-10-27 21:49:33 +000095static const struct device_operations isa_ops = {
Myles Watson29cc9ed2009-07-02 18:56:24 +000096 .read_resources = sb_read_resources,
Uwe Hermann9da69f82007-11-30 02:08:26 +000097 .set_resources = pci_dev_set_resources,
98 .enable_resources = pci_dev_enable_resources,
Julius Wernercd49cce2019-03-05 16:53:33 -080099#if CONFIG(HAVE_ACPI_TABLES)
Nico Huber68680dd2020-03-31 17:34:52 +0200100 .write_acpi_tables = acpi_write_hpet,
Keith Hui562279e2020-05-15 16:14:26 -0400101 .acpi_fill_ssdt = generate_cpu_entries,
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200102#endif
Uwe Hermann9da69f82007-11-30 02:08:26 +0000103 .init = isa_init,
Nico Huber51b75ae2019-03-14 16:02:05 +0100104 .scan_bus = scan_static_bus,
Uwe Hermann9da69f82007-11-30 02:08:26 +0000105 .ops_pci = 0, /* No subsystem IDs on 82371EB! */
106};
107
108static const struct pci_driver isa_driver __pci_driver = {
109 .ops = &isa_ops,
Felix Singer43b7f412022-03-07 04:34:52 +0100110 .vendor = PCI_VID_INTEL,
111 .device = PCI_DID_INTEL_82371AB_ISA,
Uwe Hermann9da69f82007-11-30 02:08:26 +0000112};
Patrick Georgi17dda3a2020-03-03 17:05:25 +0000113
114static const struct pci_driver isa_SB_driver __pci_driver = {
115 .ops = &isa_ops,
Felix Singer43b7f412022-03-07 04:34:52 +0100116 .vendor = PCI_VID_INTEL,
117 .device = PCI_DID_INTEL_82371SB_ISA,
Patrick Georgi17dda3a2020-03-03 17:05:25 +0000118};