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