Patrick Georgi | ac95903 | 2020-05-05 22:49:26 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 2 | |
| 3 | #include <stdint.h> |
| 4 | #include <console/console.h> |
| 5 | #include <device/device.h> |
| 6 | #include <device/pci.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 7 | #include <device/pci_ops.h> |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 8 | #include <device/pci_ids.h> |
| 9 | #include <pc80/isa-dma.h> |
| 10 | #include <pc80/mc146818rtc.h> |
Uwe Hermann | 74d1a6e | 2010-10-12 17:34:08 +0000 | [diff] [blame] | 11 | #include <arch/ioapic.h> |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 12 | #if CONFIG(HAVE_ACPI_TABLES) |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 13 | #include <acpi/acpi.h> |
| 14 | #include <acpi/acpigen.h> |
Vladimir Serbinenko | 41877d8 | 2014-09-01 22:18:01 +0200 | [diff] [blame] | 15 | #endif |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 16 | #include "i82371eb.h" |
Keith Hui | ce62238 | 2020-01-11 03:49:17 -0500 | [diff] [blame] | 17 | #include "chip.h" |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 18 | |
| 19 | static void isa_init(struct device *dev) |
| 20 | { |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 21 | u32 reg32; |
Keith Hui | ce62238 | 2020-01-11 03:49:17 -0500 | [diff] [blame] | 22 | struct southbridge_intel_i82371eb_config *sb = dev->chip_info; |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 23 | |
| 24 | /* Initialize the real time clock (RTC). */ |
Gabe Black | b3f08c6 | 2014-04-30 17:12:25 -0700 | [diff] [blame] | 25 | cmos_init(0); |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 26 | |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 27 | /* |
Tobias Diedrich | e87c38e | 2010-11-27 09:40:16 +0000 | [diff] [blame] | 28 | * Enable special cycles, needed for soft poweroff. |
| 29 | */ |
Elyes HAOUAS | cb46728 | 2020-04-28 19:55:10 +0200 | [diff] [blame] | 30 | pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_SPECIAL); |
Tobias Diedrich | e87c38e | 2010-11-27 09:40:16 +0000 | [diff] [blame] | 31 | |
| 32 | /* |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 33 | * 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 Hui | ce62238 | 2020-01-11 03:49:17 -0500 | [diff] [blame] | 38 | |
| 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 Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 42 | |
| 43 | /* Initialize ISA DMA. */ |
| 44 | isa_dma_init(); |
Uwe Hermann | 7718054 | 2010-10-28 08:19:22 +0000 | [diff] [blame] | 45 | |
Uwe Hermann | 7718054 | 2010-10-28 08:19:22 +0000 | [diff] [blame] | 46 | /* |
| 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 Hui | 2f3c37b | 2020-01-27 18:00:40 -0500 | [diff] [blame] | 54 | if (CONFIG(IOAPIC)) { |
| 55 | u16 reg16; |
Felix Held | 10942bf | 2024-02-05 17:24:49 +0100 | [diff] [blame] | 56 | const u8 ioapic_id = 2; |
Keith Hui | 2f3c37b | 2020-01-27 18:00:40 -0500 | [diff] [blame] | 57 | |
| 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älkki | 401ec98 | 2021-06-06 08:27:15 +0300 | [diff] [blame] | 63 | /* Set and verify the IOAPIC ID. */ |
Kyösti Mälkki | 682613f | 2021-06-08 11:31:19 +0300 | [diff] [blame] | 64 | setup_ioapic(VIO_APIC_VADDR, ioapic_id); |
Kyösti Mälkki | 401ec98 | 2021-06-06 08:27:15 +0300 | [diff] [blame] | 65 | if (ioapic_id != get_ioapic_id(VIO_APIC_VADDR)) |
Keith Hui | 2f3c37b | 2020-01-27 18:00:40 -0500 | [diff] [blame] | 66 | die("IOAPIC error!\n"); |
| 67 | } |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Kyösti Mälkki | e742b68 | 2023-04-10 17:03:32 +0300 | [diff] [blame] | 70 | #define ACPI_SCI_IRQ 9 |
| 71 | |
| 72 | void 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 Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 79 | static 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 Diedrich | e87c38e | 2010-11-27 09:40:16 +0000 | [diff] [blame] | 94 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED | |
| 95 | IORESOURCE_RESERVE; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 96 | |
| 97 | res = new_resource(dev, 3); /* IOAPIC */ |
Uwe Hermann | 74d1a6e | 2010-10-12 17:34:08 +0000 | [diff] [blame] | 98 | res->base = IO_APIC_ADDR; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 99 | res->size = 0x00001000; |
Tobias Diedrich | e87c38e | 2010-11-27 09:40:16 +0000 | [diff] [blame] | 100 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED | |
| 101 | IORESOURCE_RESERVE; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Uwe Hermann | 312673c | 2009-10-27 21:49:33 +0000 | [diff] [blame] | 104 | static const struct device_operations isa_ops = { |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 105 | .read_resources = sb_read_resources, |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 106 | .set_resources = pci_dev_set_resources, |
| 107 | .enable_resources = pci_dev_enable_resources, |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 108 | #if CONFIG(HAVE_ACPI_TABLES) |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 109 | .write_acpi_tables = acpi_write_hpet, |
Keith Hui | 562279e | 2020-05-15 16:14:26 -0400 | [diff] [blame] | 110 | .acpi_fill_ssdt = generate_cpu_entries, |
Vladimir Serbinenko | 41877d8 | 2014-09-01 22:18:01 +0200 | [diff] [blame] | 111 | #endif |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 112 | .init = isa_init, |
Nico Huber | 51b75ae | 2019-03-14 16:02:05 +0100 | [diff] [blame] | 113 | .scan_bus = scan_static_bus, |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 114 | .ops_pci = 0, /* No subsystem IDs on 82371EB! */ |
| 115 | }; |
| 116 | |
| 117 | static const struct pci_driver isa_driver __pci_driver = { |
| 118 | .ops = &isa_ops, |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 119 | .vendor = PCI_VID_INTEL, |
| 120 | .device = PCI_DID_INTEL_82371AB_ISA, |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 121 | }; |
Patrick Georgi | 17dda3a | 2020-03-03 17:05:25 +0000 | [diff] [blame] | 122 | |
| 123 | static const struct pci_driver isa_SB_driver __pci_driver = { |
| 124 | .ops = &isa_ops, |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 125 | .vendor = PCI_VID_INTEL, |
| 126 | .device = PCI_DID_INTEL_82371SB_ISA, |
Patrick Georgi | 17dda3a | 2020-03-03 17:05:25 +0000 | [diff] [blame] | 127 | }; |