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. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
Patrick Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 18 | * Foundation, Inc. |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include <stdint.h> |
| 22 | #include <console/console.h> |
| 23 | #include <device/device.h> |
| 24 | #include <device/pci.h> |
| 25 | #include <device/pci_ids.h> |
| 26 | #include <pc80/isa-dma.h> |
| 27 | #include <pc80/mc146818rtc.h> |
Uwe Hermann | 74d1a6e | 2010-10-12 17:34:08 +0000 | [diff] [blame] | 28 | #include <arch/ioapic.h> |
Vladimir Serbinenko | 41877d8 | 2014-09-01 22:18:01 +0200 | [diff] [blame] | 29 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
| 30 | #include <arch/acpi.h> |
| 31 | #include <arch/acpigen.h> |
| 32 | #endif |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 33 | #include "i82371eb.h" |
| 34 | |
Uwe Hermann | b34ff66 | 2010-10-28 14:22:20 +0000 | [diff] [blame] | 35 | #if CONFIG_IOAPIC |
Uwe Hermann | 7718054 | 2010-10-28 08:19:22 +0000 | [diff] [blame] | 36 | static void enable_intel_82093aa_ioapic(void) |
| 37 | { |
| 38 | u16 reg16; |
| 39 | u32 reg32; |
| 40 | u8 ioapic_id = 2; |
| 41 | volatile u32 *ioapic_index = (volatile u32 *)(IO_APIC_ADDR); |
| 42 | volatile u32 *ioapic_data = (volatile u32 *)(IO_APIC_ADDR + 0x10); |
| 43 | device_t dev; |
| 44 | |
| 45 | dev = dev_find_device(PCI_VENDOR_ID_INTEL, |
| 46 | PCI_DEVICE_ID_INTEL_82371AB_ISA, 0); |
| 47 | |
| 48 | /* Enable IOAPIC. */ |
| 49 | reg16 = pci_read_config16(dev, XBCS); |
| 50 | reg16 |= (1 << 8); /* APIC Chip Select */ |
| 51 | pci_write_config16(dev, XBCS, reg16); |
| 52 | |
| 53 | /* Set the IOAPIC ID. */ |
| 54 | *ioapic_index = 0; |
| 55 | *ioapic_data = ioapic_id << 24; |
| 56 | |
| 57 | /* Read back and verify the IOAPIC ID. */ |
| 58 | *ioapic_index = 0; |
| 59 | reg32 = (*ioapic_data >> 24) & 0x0f; |
| 60 | printk(BIOS_DEBUG, "IOAPIC ID = %x\n", reg32); |
| 61 | if (reg32 != ioapic_id) |
| 62 | die("IOAPIC error!\n"); |
| 63 | } |
Uwe Hermann | b34ff66 | 2010-10-28 14:22:20 +0000 | [diff] [blame] | 64 | #endif |
Uwe Hermann | 7718054 | 2010-10-28 08:19:22 +0000 | [diff] [blame] | 65 | |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 66 | static void isa_init(struct device *dev) |
| 67 | { |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 68 | u32 reg32; |
| 69 | |
| 70 | /* Initialize the real time clock (RTC). */ |
Gabe Black | b3f08c6 | 2014-04-30 17:12:25 -0700 | [diff] [blame] | 71 | cmos_init(0); |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 72 | |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 73 | /* |
Tobias Diedrich | e87c38e | 2010-11-27 09:40:16 +0000 | [diff] [blame] | 74 | * Enable special cycles, needed for soft poweroff. |
| 75 | */ |
| 76 | reg32 = pci_read_config16(dev, PCI_COMMAND); |
| 77 | reg32 |= PCI_COMMAND_SPECIAL; |
| 78 | pci_write_config16(dev, PCI_COMMAND, reg32); |
| 79 | |
| 80 | /* |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 81 | * The PIIX4 can support the full ISA bus, or the Extended I/O (EIO) |
| 82 | * bus, which is a subset of ISA. We select the full ISA bus here. |
| 83 | */ |
| 84 | reg32 = pci_read_config32(dev, GENCFG); |
| 85 | reg32 |= ISA; /* Select ISA, not EIO. */ |
| 86 | pci_write_config16(dev, GENCFG, reg32); |
| 87 | |
| 88 | /* Initialize ISA DMA. */ |
| 89 | isa_dma_init(); |
Uwe Hermann | 7718054 | 2010-10-28 08:19:22 +0000 | [diff] [blame] | 90 | |
| 91 | #if CONFIG_IOAPIC |
| 92 | /* |
| 93 | * Unlike most other southbridges the 82371EB doesn't have a built-in |
| 94 | * IOAPIC. Instead, 82371EB-based boards that support multiple CPUs |
| 95 | * have a discrete IOAPIC (Intel 82093AA) soldered onto the board. |
| 96 | * |
| 97 | * Thus, we can/must only enable the IOAPIC if it actually exists, |
| 98 | * i.e. the respective mainboard does "select IOAPIC". |
| 99 | */ |
| 100 | enable_intel_82093aa_ioapic(); |
| 101 | #endif |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 104 | static void sb_read_resources(struct device *dev) |
| 105 | { |
| 106 | struct resource *res; |
| 107 | |
| 108 | pci_dev_read_resources(dev); |
| 109 | |
| 110 | res = new_resource(dev, 1); |
| 111 | res->base = 0x0UL; |
| 112 | res->size = 0x1000UL; |
| 113 | res->limit = 0xffffUL; |
| 114 | res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 115 | |
| 116 | res = new_resource(dev, 2); |
| 117 | res->base = 0xff800000UL; |
| 118 | res->size = 0x00800000UL; /* 8 MB for flash */ |
Tobias Diedrich | e87c38e | 2010-11-27 09:40:16 +0000 | [diff] [blame] | 119 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED | |
| 120 | IORESOURCE_RESERVE; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 121 | |
Tobias Diedrich | e87c38e | 2010-11-27 09:40:16 +0000 | [diff] [blame] | 122 | #if CONFIG_IOAPIC |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 123 | res = new_resource(dev, 3); /* IOAPIC */ |
Uwe Hermann | 74d1a6e | 2010-10-12 17:34:08 +0000 | [diff] [blame] | 124 | res->base = IO_APIC_ADDR; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 125 | res->size = 0x00001000; |
Tobias Diedrich | e87c38e | 2010-11-27 09:40:16 +0000 | [diff] [blame] | 126 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED | |
| 127 | IORESOURCE_RESERVE; |
| 128 | #endif |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Vladimir Serbinenko | 41877d8 | 2014-09-01 22:18:01 +0200 | [diff] [blame] | 131 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
Alexander Couzens | 5eea458 | 2015-04-12 22:18:55 +0200 | [diff] [blame^] | 132 | static void southbridge_acpi_fill_ssdt_generator(device_t device) |
Vladimir Serbinenko | 41877d8 | 2014-09-01 22:18:01 +0200 | [diff] [blame] | 133 | { |
| 134 | acpigen_write_mainboard_resources("\\_SB.PCI0.MBRS", "_CRS"); |
Alexander Couzens | 5eea458 | 2015-04-12 22:18:55 +0200 | [diff] [blame^] | 135 | generate_cpu_entries(device); |
Vladimir Serbinenko | 41877d8 | 2014-09-01 22:18:01 +0200 | [diff] [blame] | 136 | } |
| 137 | #endif |
| 138 | |
Uwe Hermann | 312673c | 2009-10-27 21:49:33 +0000 | [diff] [blame] | 139 | static const struct device_operations isa_ops = { |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 140 | .read_resources = sb_read_resources, |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 141 | .set_resources = pci_dev_set_resources, |
| 142 | .enable_resources = pci_dev_enable_resources, |
Vladimir Serbinenko | 41877d8 | 2014-09-01 22:18:01 +0200 | [diff] [blame] | 143 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
| 144 | .write_acpi_tables = acpi_write_hpet, |
| 145 | .acpi_fill_ssdt_generator = southbridge_acpi_fill_ssdt_generator, |
| 146 | #endif |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 147 | .init = isa_init, |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 148 | .scan_bus = scan_lpc_bus, /* TODO: Needed? */ |
Uwe Hermann | 9da69f8 | 2007-11-30 02:08:26 +0000 | [diff] [blame] | 149 | .enable = 0, |
| 150 | .ops_pci = 0, /* No subsystem IDs on 82371EB! */ |
| 151 | }; |
| 152 | |
| 153 | static const struct pci_driver isa_driver __pci_driver = { |
| 154 | .ops = &isa_ops, |
| 155 | .vendor = PCI_VENDOR_ID_INTEL, |
| 156 | .device = PCI_DEVICE_ID_INTEL_82371AB_ISA, |
| 157 | }; |
Myles Watson | 0520d55 | 2009-05-11 22:44:14 +0000 | [diff] [blame] | 158 | |
| 159 | static const struct pci_driver isa_SB_driver __pci_driver = { |
| 160 | .ops = &isa_ops, |
| 161 | .vendor = PCI_VENDOR_ID_INTEL, |
| 162 | .device = PCI_DEVICE_ID_INTEL_82371SB_ISA, |
| 163 | }; |