blob: 3d1970c0eef765876524370e3265b9d7f7e0f987 [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>
Julius Wernercd49cce2019-03-05 16:53:33 -080026#if CONFIG(HAVE_ACPI_TABLES)
Vladimir Serbinenko41877d82014-09-01 22:18:01 +020027#include <arch/acpi.h>
28#include <arch/acpigen.h>
29#endif
Uwe Hermann9da69f82007-11-30 02:08:26 +000030#include "i82371eb.h"
Keith Huice622382020-01-11 03:49:17 -050031#include "chip.h"
Uwe Hermann9da69f82007-11-30 02:08:26 +000032
33static void isa_init(struct device *dev)
34{
Uwe Hermann9da69f82007-11-30 02:08:26 +000035 u32 reg32;
Keith Huice622382020-01-11 03:49:17 -050036 struct southbridge_intel_i82371eb_config *sb = dev->chip_info;
Uwe Hermann9da69f82007-11-30 02:08:26 +000037
38 /* Initialize the real time clock (RTC). */
Gabe Blackb3f08c62014-04-30 17:12:25 -070039 cmos_init(0);
Uwe Hermann9da69f82007-11-30 02:08:26 +000040
Uwe Hermann9da69f82007-11-30 02:08:26 +000041 /*
Tobias Diedriche87c38e2010-11-27 09:40:16 +000042 * Enable special cycles, needed for soft poweroff.
43 */
44 reg32 = pci_read_config16(dev, PCI_COMMAND);
45 reg32 |= PCI_COMMAND_SPECIAL;
46 pci_write_config16(dev, PCI_COMMAND, reg32);
47
48 /*
Uwe Hermann9da69f82007-11-30 02:08:26 +000049 * The PIIX4 can support the full ISA bus, or the Extended I/O (EIO)
50 * bus, which is a subset of ISA. We select the full ISA bus here.
51 */
52 reg32 = pci_read_config32(dev, GENCFG);
53 reg32 |= ISA; /* Select ISA, not EIO. */
Keith Huice622382020-01-11 03:49:17 -050054
55 /* Some boards use GPO22/23. Select it if configured. */
56 reg32 = ONOFF(sb->gpo22_enable, reg32, GPO2223);
57 pci_write_config32(dev, GENCFG, reg32);
Uwe Hermann9da69f82007-11-30 02:08:26 +000058
59 /* Initialize ISA DMA. */
60 isa_dma_init();
Uwe Hermann77180542010-10-28 08:19:22 +000061
Uwe Hermann77180542010-10-28 08:19:22 +000062 /*
63 * Unlike most other southbridges the 82371EB doesn't have a built-in
64 * IOAPIC. Instead, 82371EB-based boards that support multiple CPUs
65 * have a discrete IOAPIC (Intel 82093AA) soldered onto the board.
66 *
67 * Thus, we can/must only enable the IOAPIC if it actually exists,
68 * i.e. the respective mainboard does "select IOAPIC".
69 */
Keith Hui2f3c37b2020-01-27 18:00:40 -050070 if (CONFIG(IOAPIC)) {
71 u16 reg16;
72 u8 ioapic_id = 2;
73 volatile u32 *ioapic_index = (volatile u32 *)(IO_APIC_ADDR);
74 volatile u32 *ioapic_data = (volatile u32 *)(IO_APIC_ADDR + 0x10);
75
76 /* Enable IOAPIC. */
77 reg16 = pci_read_config16(dev, XBCS);
78 reg16 |= (1 << 8); /* APIC Chip Select */
79 pci_write_config16(dev, XBCS, reg16);
80
81 /* Set the IOAPIC ID. */
82 *ioapic_index = 0;
83 *ioapic_data = ioapic_id << 24;
84
85 /* Read back and verify the IOAPIC ID. */
86 *ioapic_index = 0;
87 reg32 = (*ioapic_data >> 24) & 0x0f;
88 printk(BIOS_DEBUG, "IOAPIC ID = %x\n", reg32);
89 if (reg32 != ioapic_id)
90 die("IOAPIC error!\n");
91 }
Uwe Hermann9da69f82007-11-30 02:08:26 +000092}
93
Myles Watson29cc9ed2009-07-02 18:56:24 +000094static void sb_read_resources(struct device *dev)
95{
96 struct resource *res;
97
98 pci_dev_read_resources(dev);
99
100 res = new_resource(dev, 1);
101 res->base = 0x0UL;
102 res->size = 0x1000UL;
103 res->limit = 0xffffUL;
104 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
105
106 res = new_resource(dev, 2);
107 res->base = 0xff800000UL;
108 res->size = 0x00800000UL; /* 8 MB for flash */
Tobias Diedriche87c38e2010-11-27 09:40:16 +0000109 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED |
110 IORESOURCE_RESERVE;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000111
Julius Wernercd49cce2019-03-05 16:53:33 -0800112#if CONFIG(IOAPIC)
Myles Watson29cc9ed2009-07-02 18:56:24 +0000113 res = new_resource(dev, 3); /* IOAPIC */
Uwe Hermann74d1a6e2010-10-12 17:34:08 +0000114 res->base = IO_APIC_ADDR;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000115 res->size = 0x00001000;
Tobias Diedriche87c38e2010-11-27 09:40:16 +0000116 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED |
117 IORESOURCE_RESERVE;
118#endif
Myles Watson29cc9ed2009-07-02 18:56:24 +0000119}
120
Julius Wernercd49cce2019-03-05 16:53:33 -0800121#if CONFIG(HAVE_ACPI_TABLES)
Elyes HAOUAS07e77f12018-05-13 13:25:13 +0200122static void southbridge_acpi_fill_ssdt_generator(struct device *device)
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200123{
124 acpigen_write_mainboard_resources("\\_SB.PCI0.MBRS", "_CRS");
Alexander Couzens5eea4582015-04-12 22:18:55 +0200125 generate_cpu_entries(device);
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200126}
127#endif
128
Uwe Hermann312673c2009-10-27 21:49:33 +0000129static const struct device_operations isa_ops = {
Myles Watson29cc9ed2009-07-02 18:56:24 +0000130 .read_resources = sb_read_resources,
Uwe Hermann9da69f82007-11-30 02:08:26 +0000131 .set_resources = pci_dev_set_resources,
132 .enable_resources = pci_dev_enable_resources,
Julius Wernercd49cce2019-03-05 16:53:33 -0800133#if CONFIG(HAVE_ACPI_TABLES)
Vladimir Serbinenko41877d82014-09-01 22:18:01 +0200134 .write_acpi_tables = acpi_write_hpet,
135 .acpi_fill_ssdt_generator = southbridge_acpi_fill_ssdt_generator,
136#endif
Uwe Hermann9da69f82007-11-30 02:08:26 +0000137 .init = isa_init,
Nico Huber51b75ae2019-03-14 16:02:05 +0100138 .scan_bus = scan_static_bus,
Uwe Hermann9da69f82007-11-30 02:08:26 +0000139 .enable = 0,
140 .ops_pci = 0, /* No subsystem IDs on 82371EB! */
141};
142
143static const struct pci_driver isa_driver __pci_driver = {
144 .ops = &isa_ops,
145 .vendor = PCI_VENDOR_ID_INTEL,
146 .device = PCI_DEVICE_ID_INTEL_82371AB_ISA,
147};
Patrick Georgi17dda3a2020-03-03 17:05:25 +0000148
149static const struct pci_driver isa_SB_driver __pci_driver = {
150 .ops = &isa_ops,
151 .vendor = PCI_VENDOR_ID_INTEL,
152 .device = PCI_DEVICE_ID_INTEL_82371SB_ISA,
153};