Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 1 | /* |
Stefan Reinauer | 7e61e45 | 2008-01-18 10:35:56 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2007 Uwe Hermann <uwe@hermann-uwe.de> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <stdint.h> |
| 18 | #include <console/console.h> |
| 19 | #include <device/device.h> |
| 20 | #include <device/pci.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 21 | #include <device/pci_ops.h> |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 22 | #include <device/pci_ids.h> |
| 23 | #include <pc80/isa-dma.h> |
| 24 | #include <pc80/mc146818rtc.h> |
Uwe Hermann | 74d1a6e | 2010-10-12 17:34:08 +0000 | [diff] [blame] | 25 | #include <arch/ioapic.h> |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 26 | #if CONFIG(HAVE_ACPI_TABLES) |
Vladimir Serbinenko | 41877d8 | 2014-09-01 22:18:01 +0200 | [diff] [blame] | 27 | #include <arch/acpi.h> |
| 28 | #include <arch/acpigen.h> |
| 29 | #endif |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 30 | #include "i82371eb.h" |
Keith Hui | ce62238 | 2020-01-11 03:49:17 -0500 | [diff] [blame] | 31 | #include "chip.h" |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 32 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 33 | #if CONFIG(IOAPIC) |
Uwe Hermann | 7718054 | 2010-10-28 08:19:22 +0000 | [diff] [blame] | 34 | static void enable_intel_82093aa_ioapic(void) |
| 35 | { |
| 36 | u16 reg16; |
| 37 | u32 reg32; |
| 38 | u8 ioapic_id = 2; |
| 39 | volatile u32 *ioapic_index = (volatile u32 *)(IO_APIC_ADDR); |
| 40 | volatile u32 *ioapic_data = (volatile u32 *)(IO_APIC_ADDR + 0x10); |
Elyes HAOUAS | 07e77f1 | 2018-05-13 13:25:13 +0200 | [diff] [blame] | 41 | struct device *dev; |
Uwe Hermann | 7718054 | 2010-10-28 08:19:22 +0000 | [diff] [blame] | 42 | |
| 43 | dev = dev_find_device(PCI_VENDOR_ID_INTEL, |
| 44 | PCI_DEVICE_ID_INTEL_82371AB_ISA, 0); |
| 45 | |
| 46 | /* Enable IOAPIC. */ |
| 47 | reg16 = pci_read_config16(dev, XBCS); |
| 48 | reg16 |= (1 << 8); /* APIC Chip Select */ |
| 49 | pci_write_config16(dev, XBCS, reg16); |
| 50 | |
| 51 | /* Set the IOAPIC ID. */ |
| 52 | *ioapic_index = 0; |
| 53 | *ioapic_data = ioapic_id << 24; |
| 54 | |
| 55 | /* Read back and verify the IOAPIC ID. */ |
| 56 | *ioapic_index = 0; |
| 57 | reg32 = (*ioapic_data >> 24) & 0x0f; |
| 58 | printk(BIOS_DEBUG, "IOAPIC ID = %x\n", reg32); |
| 59 | if (reg32 != ioapic_id) |
| 60 | die("IOAPIC error!\n"); |
| 61 | } |
Uwe Hermann | b34ff66 | 2010-10-28 14:22:20 +0000 | [diff] [blame] | 62 | #endif |
Uwe Hermann | 7718054 | 2010-10-28 08:19:22 +0000 | [diff] [blame] | 63 | |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 64 | static void isa_init(struct device *dev) |
| 65 | { |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 66 | u32 reg32; |
Keith Hui | ce62238 | 2020-01-11 03:49:17 -0500 | [diff] [blame] | 67 | struct southbridge_intel_i82371eb_config *sb = dev->chip_info; |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 68 | |
| 69 | /* Initialize the real time clock (RTC). */ |
Gabe Black | b3f08c6 | 2014-04-30 17:12:25 -0700 | [diff] [blame] | 70 | cmos_init(0); |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 71 | |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 72 | /* |
Tobias Diedrich | e87c38e | 2010-11-27 09:40:16 +0000 | [diff] [blame] | 73 | * Enable special cycles, needed for soft poweroff. |
| 74 | */ |
| 75 | reg32 = pci_read_config16(dev, PCI_COMMAND); |
| 76 | reg32 |= PCI_COMMAND_SPECIAL; |
| 77 | pci_write_config16(dev, PCI_COMMAND, reg32); |
| 78 | |
| 79 | /* |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 80 | * The PIIX4 can support the full ISA bus, or the Extended I/O (EIO) |
| 81 | * bus, which is a subset of ISA. We select the full ISA bus here. |
| 82 | */ |
| 83 | reg32 = pci_read_config32(dev, GENCFG); |
| 84 | reg32 |= ISA; /* Select ISA, not EIO. */ |
Keith Hui | ce62238 | 2020-01-11 03:49:17 -0500 | [diff] [blame] | 85 | |
| 86 | /* Some boards use GPO22/23. Select it if configured. */ |
| 87 | reg32 = ONOFF(sb->gpo22_enable, reg32, GPO2223); |
| 88 | pci_write_config32(dev, GENCFG, reg32); |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 89 | |
| 90 | /* Initialize ISA DMA. */ |
| 91 | isa_dma_init(); |
Uwe Hermann | 7718054 | 2010-10-28 08:19:22 +0000 | [diff] [blame] | 92 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 93 | #if CONFIG(IOAPIC) |
Uwe Hermann | 7718054 | 2010-10-28 08:19:22 +0000 | [diff] [blame] | 94 | /* |
| 95 | * Unlike most other southbridges the 82371EB doesn't have a built-in |
| 96 | * IOAPIC. Instead, 82371EB-based boards that support multiple CPUs |
| 97 | * have a discrete IOAPIC (Intel 82093AA) soldered onto the board. |
| 98 | * |
| 99 | * Thus, we can/must only enable the IOAPIC if it actually exists, |
| 100 | * i.e. the respective mainboard does "select IOAPIC". |
| 101 | */ |
| 102 | enable_intel_82093aa_ioapic(); |
| 103 | #endif |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 106 | static void sb_read_resources(struct device *dev) |
| 107 | { |
| 108 | struct resource *res; |
| 109 | |
| 110 | pci_dev_read_resources(dev); |
| 111 | |
| 112 | res = new_resource(dev, 1); |
| 113 | res->base = 0x0UL; |
| 114 | res->size = 0x1000UL; |
| 115 | res->limit = 0xffffUL; |
| 116 | res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 117 | |
| 118 | res = new_resource(dev, 2); |
| 119 | res->base = 0xff800000UL; |
| 120 | res->size = 0x00800000UL; /* 8 MB for flash */ |
Tobias Diedrich | e87c38e | 2010-11-27 09:40:16 +0000 | [diff] [blame] | 121 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED | |
| 122 | IORESOURCE_RESERVE; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 123 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 124 | #if CONFIG(IOAPIC) |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 125 | res = new_resource(dev, 3); /* IOAPIC */ |
Uwe Hermann | 74d1a6e | 2010-10-12 17:34:08 +0000 | [diff] [blame] | 126 | res->base = IO_APIC_ADDR; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 127 | res->size = 0x00001000; |
Tobias Diedrich | e87c38e | 2010-11-27 09:40:16 +0000 | [diff] [blame] | 128 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED | |
| 129 | IORESOURCE_RESERVE; |
| 130 | #endif |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 133 | #if CONFIG(HAVE_ACPI_TABLES) |
Elyes HAOUAS | 07e77f1 | 2018-05-13 13:25:13 +0200 | [diff] [blame] | 134 | static void southbridge_acpi_fill_ssdt_generator(struct device *device) |
Vladimir Serbinenko | 41877d8 | 2014-09-01 22:18:01 +0200 | [diff] [blame] | 135 | { |
| 136 | acpigen_write_mainboard_resources("\\_SB.PCI0.MBRS", "_CRS"); |
Alexander Couzens | 5eea458 | 2015-04-12 22:18:55 +0200 | [diff] [blame] | 137 | generate_cpu_entries(device); |
Vladimir Serbinenko | 41877d8 | 2014-09-01 22:18:01 +0200 | [diff] [blame] | 138 | } |
| 139 | #endif |
| 140 | |
Uwe Hermann | 312673c | 2009-10-27 21:49:33 +0000 | [diff] [blame] | 141 | static const struct device_operations isa_ops = { |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 142 | .read_resources = sb_read_resources, |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 143 | .set_resources = pci_dev_set_resources, |
| 144 | .enable_resources = pci_dev_enable_resources, |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 145 | #if CONFIG(HAVE_ACPI_TABLES) |
Vladimir Serbinenko | 41877d8 | 2014-09-01 22:18:01 +0200 | [diff] [blame] | 146 | .write_acpi_tables = acpi_write_hpet, |
| 147 | .acpi_fill_ssdt_generator = southbridge_acpi_fill_ssdt_generator, |
| 148 | #endif |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 149 | .init = isa_init, |
Nico Huber | 51b75ae | 2019-03-14 16:02:05 +0100 | [diff] [blame] | 150 | .scan_bus = scan_static_bus, |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 151 | .enable = 0, |
| 152 | .ops_pci = 0, /* No subsystem IDs on 82371EB! */ |
| 153 | }; |
| 154 | |
| 155 | static const struct pci_driver isa_driver __pci_driver = { |
| 156 | .ops = &isa_ops, |
| 157 | .vendor = PCI_VENDOR_ID_INTEL, |
| 158 | .device = PCI_DEVICE_ID_INTEL_82371AB_ISA, |
| 159 | }; |