blob: 91405459a3beb3e158234a46d3d9c500b209f144 [file] [log] [blame]
Patrick Georgi02363b52020-05-05 20:48:50 +02001/* This file is part of the coreboot project. */
Patrick Georgiac959032020-05-05 22:49:26 +02002/* SPDX-License-Identifier: GPL-2.0-or-later */
Uwe Hermann9da69f82007-11-30 02:08:26 +00003
4#include <stdint.h>
5#include <console/console.h>
6#include <device/device.h>
7#include <device/pci.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02008#include <device/pci_ops.h>
Uwe Hermann9da69f82007-11-30 02:08:26 +00009#include <device/pci_ids.h>
10#include <pc80/isa-dma.h>
11#include <pc80/mc146818rtc.h>
Uwe Hermann74d1a6e2010-10-12 17:34:08 +000012#include <arch/ioapic.h>
Julius Wernercd49cce2019-03-05 16:53:33 -080013#if CONFIG(HAVE_ACPI_TABLES)
Furquan Shaikh76cedd22020-05-02 10:24:23 -070014#include <acpi/acpi.h>
15#include <acpi/acpigen.h>
Vladimir Serbinenko41877d82014-09-01 22:18:01 +020016#endif
Uwe Hermann9da69f82007-11-30 02:08:26 +000017#include "i82371eb.h"
Keith Huice622382020-01-11 03:49:17 -050018#include "chip.h"
Uwe Hermann9da69f82007-11-30 02:08:26 +000019
20static void isa_init(struct device *dev)
21{
Uwe Hermann9da69f82007-11-30 02:08:26 +000022 u32 reg32;
Keith Huice622382020-01-11 03:49:17 -050023 struct southbridge_intel_i82371eb_config *sb = dev->chip_info;
Uwe Hermann9da69f82007-11-30 02:08:26 +000024
25 /* Initialize the real time clock (RTC). */
Gabe Blackb3f08c62014-04-30 17:12:25 -070026 cmos_init(0);
Uwe Hermann9da69f82007-11-30 02:08:26 +000027
Uwe Hermann9da69f82007-11-30 02:08:26 +000028 /*
Tobias Diedriche87c38e2010-11-27 09:40:16 +000029 * Enable special cycles, needed for soft poweroff.
30 */
31 reg32 = pci_read_config16(dev, PCI_COMMAND);
32 reg32 |= PCI_COMMAND_SPECIAL;
33 pci_write_config16(dev, PCI_COMMAND, reg32);
34
35 /*
Uwe Hermann9da69f82007-11-30 02:08:26 +000036 * The PIIX4 can support the full ISA bus, or the Extended I/O (EIO)
37 * bus, which is a subset of ISA. We select the full ISA bus here.
38 */
39 reg32 = pci_read_config32(dev, GENCFG);
40 reg32 |= ISA; /* Select ISA, not EIO. */
Keith Huice622382020-01-11 03:49:17 -050041
42 /* Some boards use GPO22/23. Select it if configured. */
43 reg32 = ONOFF(sb->gpo22_enable, reg32, GPO2223);
44 pci_write_config32(dev, GENCFG, reg32);
Uwe Hermann9da69f82007-11-30 02:08:26 +000045
46 /* Initialize ISA DMA. */
47 isa_dma_init();
Uwe Hermann77180542010-10-28 08:19:22 +000048
Uwe Hermann77180542010-10-28 08:19:22 +000049 /*
50 * Unlike most other southbridges the 82371EB doesn't have a built-in
51 * IOAPIC. Instead, 82371EB-based boards that support multiple CPUs
52 * have a discrete IOAPIC (Intel 82093AA) soldered onto the board.
53 *
54 * Thus, we can/must only enable the IOAPIC if it actually exists,
55 * i.e. the respective mainboard does "select IOAPIC".
56 */
Keith Hui2f3c37b2020-01-27 18:00:40 -050057 if (CONFIG(IOAPIC)) {
58 u16 reg16;
59 u8 ioapic_id = 2;
60 volatile u32 *ioapic_index = (volatile u32 *)(IO_APIC_ADDR);
61 volatile u32 *ioapic_data = (volatile u32 *)(IO_APIC_ADDR + 0x10);
62
63 /* Enable IOAPIC. */
64 reg16 = pci_read_config16(dev, XBCS);
65 reg16 |= (1 << 8); /* APIC Chip Select */
66 pci_write_config16(dev, XBCS, reg16);
67
68 /* Set the IOAPIC ID. */
69 *ioapic_index = 0;
70 *ioapic_data = ioapic_id << 24;
71
72 /* Read back and verify the IOAPIC ID. */
73 *ioapic_index = 0;
74 reg32 = (*ioapic_data >> 24) & 0x0f;
75 printk(BIOS_DEBUG, "IOAPIC ID = %x\n", reg32);
76 if (reg32 != ioapic_id)
77 die("IOAPIC error!\n");
78 }
Uwe Hermann9da69f82007-11-30 02:08:26 +000079}
80
Myles Watson29cc9ed2009-07-02 18:56:24 +000081static void sb_read_resources(struct device *dev)
82{
83 struct resource *res;
84
85 pci_dev_read_resources(dev);
86
87 res = new_resource(dev, 1);
88 res->base = 0x0UL;
89 res->size = 0x1000UL;
90 res->limit = 0xffffUL;
91 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
92
93 res = new_resource(dev, 2);
94 res->base = 0xff800000UL;
95 res->size = 0x00800000UL; /* 8 MB for flash */
Tobias Diedriche87c38e2010-11-27 09:40:16 +000096 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED |
97 IORESOURCE_RESERVE;
Myles Watson29cc9ed2009-07-02 18:56:24 +000098
Julius Wernercd49cce2019-03-05 16:53:33 -080099#if CONFIG(IOAPIC)
Myles Watson29cc9ed2009-07-02 18:56:24 +0000100 res = new_resource(dev, 3); /* IOAPIC */
Uwe Hermann74d1a6e2010-10-12 17:34:08 +0000101 res->base = IO_APIC_ADDR;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000102 res->size = 0x00001000;
Tobias Diedriche87c38e2010-11-27 09:40:16 +0000103 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED |
104 IORESOURCE_RESERVE;
105#endif
Myles Watson29cc9ed2009-07-02 18:56:24 +0000106}
107
Julius Wernercd49cce2019-03-05 16:53:33 -0800108#if CONFIG(HAVE_ACPI_TABLES)
Furquan Shaikh7536a392020-04-24 21:59:21 -0700109static void southbridge_acpi_fill_ssdt_generator(const struct device *device)
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200110{
111 acpigen_write_mainboard_resources("\\_SB.PCI0.MBRS", "_CRS");
Alexander Couzens5eea4582015-04-12 22:18:55 +0200112 generate_cpu_entries(device);
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200113}
114#endif
115
Uwe Hermann312673c2009-10-27 21:49:33 +0000116static const struct device_operations isa_ops = {
Myles Watson29cc9ed2009-07-02 18:56:24 +0000117 .read_resources = sb_read_resources,
Uwe Hermann9da69f82007-11-30 02:08:26 +0000118 .set_resources = pci_dev_set_resources,
119 .enable_resources = pci_dev_enable_resources,
Julius Wernercd49cce2019-03-05 16:53:33 -0800120#if CONFIG(HAVE_ACPI_TABLES)
Nico Huber68680dd2020-03-31 17:34:52 +0200121 .write_acpi_tables = acpi_write_hpet,
122 .acpi_fill_ssdt = southbridge_acpi_fill_ssdt_generator,
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200123#endif
Uwe Hermann9da69f82007-11-30 02:08:26 +0000124 .init = isa_init,
Nico Huber51b75ae2019-03-14 16:02:05 +0100125 .scan_bus = scan_static_bus,
Uwe Hermann9da69f82007-11-30 02:08:26 +0000126 .ops_pci = 0, /* No subsystem IDs on 82371EB! */
127};
128
129static const struct pci_driver isa_driver __pci_driver = {
130 .ops = &isa_ops,
131 .vendor = PCI_VENDOR_ID_INTEL,
132 .device = PCI_DEVICE_ID_INTEL_82371AB_ISA,
133};
Patrick Georgi17dda3a2020-03-03 17:05:25 +0000134
135static const struct pci_driver isa_SB_driver __pci_driver = {
136 .ops = &isa_ops,
137 .vendor = PCI_VENDOR_ID_INTEL,
138 .device = PCI_DEVICE_ID_INTEL_82371SB_ISA,
139};