blob: b4041ef9e0355542b54557c852a40ee972fd223a [file] [log] [blame]
Uwe Hermann9da69f82007-11-30 02:08:26 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Uwe Hermann9da69f82007-11-30 02:08:26 +00003 *
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 Hermann9da69f82007-11-30 02:08:26 +000015 */
16
17#include <stdint.h>
18#include <console/console.h>
19#include <device/device.h>
20#include <device/pci.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020021#include <device/pci_ops.h>
Uwe Hermann9da69f82007-11-30 02:08:26 +000022#include <device/pci_ids.h>
23#include <pc80/isa-dma.h>
24#include <pc80/mc146818rtc.h>
Uwe Hermann74d1a6e2010-10-12 17:34:08 +000025#include <arch/ioapic.h>
Vladimir Serbinenko41877d82014-09-01 22:18:01 +020026#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
27#include <arch/acpi.h>
28#include <arch/acpigen.h>
29#endif
Uwe Hermann9da69f82007-11-30 02:08:26 +000030#include "i82371eb.h"
31
Martin Roth7a1a3ad2017-06-24 21:29:38 -060032#if IS_ENABLED(CONFIG_IOAPIC)
Uwe Hermann77180542010-10-28 08:19:22 +000033static void enable_intel_82093aa_ioapic(void)
34{
35 u16 reg16;
36 u32 reg32;
37 u8 ioapic_id = 2;
38 volatile u32 *ioapic_index = (volatile u32 *)(IO_APIC_ADDR);
39 volatile u32 *ioapic_data = (volatile u32 *)(IO_APIC_ADDR + 0x10);
Elyes HAOUAS07e77f12018-05-13 13:25:13 +020040 struct device *dev;
Uwe Hermann77180542010-10-28 08:19:22 +000041
42 dev = dev_find_device(PCI_VENDOR_ID_INTEL,
43 PCI_DEVICE_ID_INTEL_82371AB_ISA, 0);
44
45 /* Enable IOAPIC. */
46 reg16 = pci_read_config16(dev, XBCS);
47 reg16 |= (1 << 8); /* APIC Chip Select */
48 pci_write_config16(dev, XBCS, reg16);
49
50 /* Set the IOAPIC ID. */
51 *ioapic_index = 0;
52 *ioapic_data = ioapic_id << 24;
53
54 /* Read back and verify the IOAPIC ID. */
55 *ioapic_index = 0;
56 reg32 = (*ioapic_data >> 24) & 0x0f;
57 printk(BIOS_DEBUG, "IOAPIC ID = %x\n", reg32);
58 if (reg32 != ioapic_id)
59 die("IOAPIC error!\n");
60}
Uwe Hermannb34ff662010-10-28 14:22:20 +000061#endif
Uwe Hermann77180542010-10-28 08:19:22 +000062
Uwe Hermann9da69f82007-11-30 02:08:26 +000063static void isa_init(struct device *dev)
64{
Uwe Hermann9da69f82007-11-30 02:08:26 +000065 u32 reg32;
66
67 /* Initialize the real time clock (RTC). */
Gabe Blackb3f08c62014-04-30 17:12:25 -070068 cmos_init(0);
Uwe Hermann9da69f82007-11-30 02:08:26 +000069
Uwe Hermann9da69f82007-11-30 02:08:26 +000070 /*
Tobias Diedriche87c38e2010-11-27 09:40:16 +000071 * Enable special cycles, needed for soft poweroff.
72 */
73 reg32 = pci_read_config16(dev, PCI_COMMAND);
74 reg32 |= PCI_COMMAND_SPECIAL;
75 pci_write_config16(dev, PCI_COMMAND, reg32);
76
77 /*
Uwe Hermann9da69f82007-11-30 02:08:26 +000078 * The PIIX4 can support the full ISA bus, or the Extended I/O (EIO)
79 * bus, which is a subset of ISA. We select the full ISA bus here.
80 */
81 reg32 = pci_read_config32(dev, GENCFG);
82 reg32 |= ISA; /* Select ISA, not EIO. */
83 pci_write_config16(dev, GENCFG, reg32);
84
85 /* Initialize ISA DMA. */
86 isa_dma_init();
Uwe Hermann77180542010-10-28 08:19:22 +000087
Martin Roth7a1a3ad2017-06-24 21:29:38 -060088#if IS_ENABLED(CONFIG_IOAPIC)
Uwe Hermann77180542010-10-28 08:19:22 +000089 /*
90 * Unlike most other southbridges the 82371EB doesn't have a built-in
91 * IOAPIC. Instead, 82371EB-based boards that support multiple CPUs
92 * have a discrete IOAPIC (Intel 82093AA) soldered onto the board.
93 *
94 * Thus, we can/must only enable the IOAPIC if it actually exists,
95 * i.e. the respective mainboard does "select IOAPIC".
96 */
97 enable_intel_82093aa_ioapic();
98#endif
Uwe Hermann9da69f82007-11-30 02:08:26 +000099}
100
Myles Watson29cc9ed2009-07-02 18:56:24 +0000101static void sb_read_resources(struct device *dev)
102{
103 struct resource *res;
104
105 pci_dev_read_resources(dev);
106
107 res = new_resource(dev, 1);
108 res->base = 0x0UL;
109 res->size = 0x1000UL;
110 res->limit = 0xffffUL;
111 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
112
113 res = new_resource(dev, 2);
114 res->base = 0xff800000UL;
115 res->size = 0x00800000UL; /* 8 MB for flash */
Tobias Diedriche87c38e2010-11-27 09:40:16 +0000116 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED |
117 IORESOURCE_RESERVE;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000118
Martin Roth7a1a3ad2017-06-24 21:29:38 -0600119#if IS_ENABLED(CONFIG_IOAPIC)
Myles Watson29cc9ed2009-07-02 18:56:24 +0000120 res = new_resource(dev, 3); /* IOAPIC */
Uwe Hermann74d1a6e2010-10-12 17:34:08 +0000121 res->base = IO_APIC_ADDR;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000122 res->size = 0x00001000;
Tobias Diedriche87c38e2010-11-27 09:40:16 +0000123 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED |
124 IORESOURCE_RESERVE;
125#endif
Myles Watson29cc9ed2009-07-02 18:56:24 +0000126}
127
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200128#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
Elyes HAOUAS07e77f12018-05-13 13:25:13 +0200129static void southbridge_acpi_fill_ssdt_generator(struct device *device)
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200130{
131 acpigen_write_mainboard_resources("\\_SB.PCI0.MBRS", "_CRS");
Alexander Couzens5eea4582015-04-12 22:18:55 +0200132 generate_cpu_entries(device);
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200133}
134#endif
135
Uwe Hermann312673c2009-10-27 21:49:33 +0000136static const struct device_operations isa_ops = {
Myles Watson29cc9ed2009-07-02 18:56:24 +0000137 .read_resources = sb_read_resources,
Uwe Hermann9da69f82007-11-30 02:08:26 +0000138 .set_resources = pci_dev_set_resources,
139 .enable_resources = pci_dev_enable_resources,
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200140#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
141 .write_acpi_tables = acpi_write_hpet,
142 .acpi_fill_ssdt_generator = southbridge_acpi_fill_ssdt_generator,
143#endif
Uwe Hermann9da69f82007-11-30 02:08:26 +0000144 .init = isa_init,
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +0200145 .scan_bus = scan_lpc_bus, /* TODO: Needed? */
Uwe Hermann9da69f82007-11-30 02:08:26 +0000146 .enable = 0,
147 .ops_pci = 0, /* No subsystem IDs on 82371EB! */
148};
149
150static const struct pci_driver isa_driver __pci_driver = {
151 .ops = &isa_ops,
152 .vendor = PCI_VENDOR_ID_INTEL,
153 .device = PCI_DEVICE_ID_INTEL_82371AB_ISA,
154};
Myles Watson0520d552009-05-11 22:44:14 +0000155
156static const struct pci_driver isa_SB_driver __pci_driver = {
157 .ops = &isa_ops,
158 .vendor = PCI_VENDOR_ID_INTEL,
159 .device = PCI_DEVICE_ID_INTEL_82371SB_ISA,
160};