blob: 5af0781422f0b878619334885f96b11bec7848ca [file] [log] [blame]
Mariusz Szafranskia4041332017-08-02 17:28:17 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2014 - 2017 Intel Corporation.
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; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
17#include <console/console.h>
18#include <device/device.h>
19#include <device/pci.h>
20#include <device/pci_ids.h>
21#include <arch/io.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020022#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020023#include <device/pci_ops.h>
Mariusz Szafranskia4041332017-08-02 17:28:17 +020024#include <arch/ioapic.h>
25#include <arch/acpi.h>
Mariusz Szafranskia4041332017-08-02 17:28:17 +020026#include <cpu/x86/smm.h>
27#include <bootstate.h>
28
29#include <soc/lpc.h>
30#include <soc/pci_devs.h>
31#include <soc/ramstage.h>
32#include <soc/iomap.h>
33#include <soc/pcr.h>
34#include <soc/p2sb.h>
35#include <soc/acpi.h>
36
37#include "chip.h"
38
39/* PCH-LP redirection entries */
40#define PCH_LP_REDIR_ETR 120
41
42/**
Jonathan Neuschäfer5268b762018-02-12 12:24:25 +010043 * Set miscellaneous static southbridge features.
Mariusz Szafranskia4041332017-08-02 17:28:17 +020044 *
45 * @param dev PCI device with I/O APIC control registers
46 */
47static void pch_enable_ioapic(struct device *dev)
48{
49 u32 reg32;
50
51 set_ioapic_id((void *)IO_APIC_ADDR, IO_APIC0);
52
53 /* affirm full set of redirection table entries ("write once") */
54 reg32 = io_apic_read((void *)IO_APIC_ADDR, 0x01);
55
56 reg32 &= ~0x00ff0000;
57 reg32 |= (PCH_LP_REDIR_ETR - 1) << 16;
58
59 io_apic_write((void *)IO_APIC_ADDR, 0x01, reg32);
60
61 /*
62 * Select Boot Configuration register (0x03) and
63 * use Processor System Bus (0x01) to deliver interrupts.
64 */
65 io_apic_write((void *)IO_APIC_ADDR, 0x03, 0x01);
66}
67
68/* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control
69 * 0x00 - 0000 = Reserved
70 * 0x01 - 0001 = Reserved
71 * 0x02 - 0010 = Reserved
72 * 0x03 - 0011 = IRQ3
73 * 0x04 - 0100 = IRQ4
74 * 0x05 - 0101 = IRQ5
75 * 0x06 - 0110 = IRQ6
76 * 0x07 - 0111 = IRQ7
77 * 0x08 - 1000 = Reserved
78 * 0x09 - 1001 = IRQ9
79 * 0x0A - 1010 = IRQ10
80 * 0x0B - 1011 = IRQ11
81 * 0x0C - 1100 = IRQ12
82 * 0x0D - 1101 = Reserved
83 * 0x0E - 1110 = IRQ14
84 * 0x0F - 1111 = IRQ15
85 * PIRQ[n]_ROUT[7] - PIRQ Routing Control
86 * 0x80 - The PIRQ is not routed.
87 */
88
Elyes HAOUAS2ec41832018-05-27 17:40:58 +020089static void pch_pirq_init(struct device *dev)
Mariusz Szafranskia4041332017-08-02 17:28:17 +020090{
Elyes HAOUAS2ec41832018-05-27 17:40:58 +020091 struct device *irq_dev;
Mariusz Szafranskia4041332017-08-02 17:28:17 +020092 /* Get the chip configuration */
Kyösti Mälkki8950cfb2019-07-13 22:16:25 +030093 config_t *config = config_of(dev);
Mariusz Szafranskia4041332017-08-02 17:28:17 +020094
95 /* Initialize PIRQ Routings */
96 write8((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIRQA_ROUT),
97 config->pirqa_routing);
98 write8((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIRQB_ROUT),
99 config->pirqb_routing);
100 write8((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIRQC_ROUT),
101 config->pirqc_routing);
102 write8((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIRQD_ROUT),
103 config->pirqd_routing);
104
105 write8((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIRQE_ROUT),
106 config->pirqe_routing);
107 write8((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIRQF_ROUT),
108 config->pirqf_routing);
109 write8((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIRQG_ROUT),
110 config->pirqg_routing);
111 write8((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIRQH_ROUT),
112 config->pirqh_routing);
113
114 /* Initialize device's Interrupt Routings */
115 write16((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIR00),
116 config->ir00_routing);
117 write16((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIR01),
118 config->ir01_routing);
119 write16((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIR02),
120 config->ir02_routing);
121 write16((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIR03),
122 config->ir03_routing);
123 write16((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIR04),
124 config->ir04_routing);
125 write16((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIR05),
126 config->ir05_routing);
127 write16((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIR06),
128 config->ir06_routing);
129 write16((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIR07),
130 config->ir07_routing);
131 write16((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIR08),
132 config->ir08_routing);
133 write16((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIR09),
134 config->ir09_routing);
135 write16((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIR10),
136 config->ir10_routing);
137 write16((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIR11),
138 config->ir11_routing);
139 write16((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIR12),
140 config->ir12_routing);
141
142 /* Initialize device's Interrupt Polarity Control */
143 write32((void *)PCH_PCR_ADDRESS(PID_ITSS, PCH_PCR_ITSS_IPC0),
144 config->ipc0);
145 write32((void *)PCH_PCR_ADDRESS(PID_ITSS, PCH_PCR_ITSS_IPC1),
146 config->ipc1);
147 write32((void *)PCH_PCR_ADDRESS(PID_ITSS, PCH_PCR_ITSS_IPC2),
148 config->ipc2);
149 write32((void *)PCH_PCR_ADDRESS(PID_ITSS, PCH_PCR_ITSS_IPC3),
150 config->ipc3);
151
152 for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) {
153 u8 int_pin = 0, int_line = 0;
154
155 if (!irq_dev->enabled || irq_dev->path.type != DEVICE_PATH_PCI)
156 continue;
157
158 int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
159
160 switch (int_pin) {
161 case 1: /* INTA# */
162 int_line = config->pirqa_routing;
163 break;
164 case 2: /* INTB# */
165 int_line = config->pirqb_routing;
166 break;
167 case 3: /* INTC# */
168 int_line = config->pirqc_routing;
169 break;
170 case 4: /* INTD# */
171 int_line = config->pirqd_routing;
172 break;
173 }
174
175 if (!int_line)
176 continue;
177
178 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line);
179 }
180}
181
Elyes HAOUAS2ec41832018-05-27 17:40:58 +0200182static void pci_p2sb_read_resources(struct device *dev)
Mariusz Szafranskia4041332017-08-02 17:28:17 +0200183{
184 struct resource *res;
185
186 /* Add MMIO resource
187 * Use 0xda as an unused index for PCR BAR.
188 */
189 res = new_resource(dev, 0xda);
190 res->base = DEFAULT_PCR_BASE;
191 res->size = 16 * 1024 * 1024; /* 16MB PCR config space */
192 res->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_STORED |
193 IORESOURCE_ASSIGNED;
194 printk(BIOS_DEBUG,
195 "Adding P2SB PCR config space BAR 0x%08lx-0x%08lx.\n",
196 (unsigned long)(res->base),
197 (unsigned long)(res->base + res->size));
198
199 /* Add MMIO resource
200 * Use 0xdb as an unused index for IOAPIC.
201 */
202 res = new_resource(dev, 0xdb); /* IOAPIC */
203 res->base = IO_APIC_ADDR;
204 res->size = 0x00001000;
205 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
206}
207
208static void pch_enable_serial_irqs(struct device *dev)
209{
210 /* Set packet length and toggle silent mode bit for one frame. */
211 pci_write_config8(dev, SERIRQ_CNTL,
212 (1 << 7) | (1 << 6) | ((21 - 17) << 2) | (0 << 0));
Julius Wernercd49cce2019-03-05 16:53:33 -0800213#if !CONFIG(SERIRQ_CONTINUOUS_MODE)
Mariusz Szafranskia4041332017-08-02 17:28:17 +0200214 pci_write_config8(dev, SERIRQ_CNTL,
215 (1 << 7) | (0 << 6) | ((21 - 17) << 2) | (0 << 0));
216#endif
217}
218
219static void lpc_init(struct device *dev)
220{
221 printk(BIOS_DEBUG, "pch: lpc_init\n");
222
223 /* Get the base address */
224
225 /* Set the value for PCI command register. */
226 pci_write_config16(dev, PCI_COMMAND,
227 PCI_COMMAND_SPECIAL | PCI_COMMAND_MASTER |
228 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
229
230 /* Serial IRQ initialization. */
231 pch_enable_serial_irqs(dev);
232
233 /* IO APIC initialization. */
234 pch_enable_ioapic(dev);
235
236 /* Setup the PIRQ. */
237 pch_pirq_init(dev);
238}
239
Elyes HAOUAS2ec41832018-05-27 17:40:58 +0200240static void pch_lpc_add_mmio_resources(struct device *dev) { /* TODO */ }
Mariusz Szafranskia4041332017-08-02 17:28:17 +0200241
Elyes HAOUAS2ec41832018-05-27 17:40:58 +0200242static void pch_lpc_add_io_resources(struct device *dev)
Mariusz Szafranskia4041332017-08-02 17:28:17 +0200243{
244 struct resource *res;
245 u8 io_index = 0;
246
247 /* Add an extra subtractive resource for both memory and I/O. */
248 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
249 res->base = 0;
250 res->size = 0x1000;
251 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
252 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
253
254 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
255 res->base = 0xff000000;
256 res->size = 0x01000000; /* 16 MB for flash */
257 res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE |
258 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
259}
260
Elyes HAOUAS2ec41832018-05-27 17:40:58 +0200261static void lpc_read_resources(struct device *dev)
Mariusz Szafranskia4041332017-08-02 17:28:17 +0200262{
263 /* Get the normal PCI resources of this device. */
264 pci_dev_read_resources(dev);
265
266 /* Add non-standard MMIO resources. */
267 pch_lpc_add_mmio_resources(dev);
268
269 /* Add IO resources. */
270 pch_lpc_add_io_resources(dev);
271
272 /* Add MMIO resource for IOAPIC. */
273 pci_p2sb_read_resources(dev);
274}
275
276static void pch_decode_init(struct device *dev) { /* TODO */ }
277
Elyes HAOUAS2ec41832018-05-27 17:40:58 +0200278static void lpc_enable_resources(struct device *dev)
Mariusz Szafranskia4041332017-08-02 17:28:17 +0200279{
280 pch_decode_init(dev);
281 pci_dev_enable_resources(dev);
282}
283
284/* Set bit in Function Disable register to hide this device */
285static void pch_hide_devfn(uint32_t devfn) { /* TODO */ }
286
Elyes HAOUAS2ec41832018-05-27 17:40:58 +0200287void southcluster_enable_dev(struct device *dev)
Mariusz Szafranskia4041332017-08-02 17:28:17 +0200288{
289 u32 reg32;
290
291 if (!dev->enabled) {
292 printk(BIOS_DEBUG, "%s: Disabling device\n", dev_path(dev));
293
294 /* Ensure memory, io, and bus master are all disabled */
295 reg32 = pci_read_config32(dev, PCI_COMMAND);
296 reg32 &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY |
297 PCI_COMMAND_IO);
298 pci_write_config32(dev, PCI_COMMAND, reg32);
299
300 /* Hide this device if possible */
301 pch_hide_devfn(dev->path.pci.devfn);
302 } else {
303 /* Enable SERR */
304 reg32 = pci_read_config32(dev, PCI_COMMAND);
305 reg32 |= PCI_COMMAND_SERR;
306 pci_write_config32(dev, PCI_COMMAND, reg32);
307 }
308}
309
310static struct device_operations device_ops = {
311 .read_resources = lpc_read_resources,
312 .set_resources = pci_dev_set_resources,
Julius Wernercd49cce2019-03-05 16:53:33 -0800313#if CONFIG(HAVE_ACPI_TABLES)
Mariusz Szafranskia4041332017-08-02 17:28:17 +0200314 .acpi_inject_dsdt_generator = southcluster_inject_dsdt,
315 .write_acpi_tables = southcluster_write_acpi_tables,
316#endif
317 .enable_resources = lpc_enable_resources,
318 .init = lpc_init,
319 .enable = southcluster_enable_dev,
320 .scan_bus = scan_lpc_bus,
321 .ops_pci = &soc_pci_ops,
322};
323
324static const struct pci_driver lpc_driver __pci_driver = {
325 .ops = &device_ops,
326 .vendor = PCI_VENDOR_ID_INTEL,
327 .device = LPC_DEVID,
328};
329
330static void finalize_chipset(void *unused)
331{
332 printk(BIOS_DEBUG, "Finalizing SMM.\n");
333 outb(APM_CNT_FINALIZE, APM_CNT);
334}
335
336BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, finalize_chipset, NULL);
337BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, finalize_chipset, NULL);