blob: f695d6123fb0adf7dcc83c0af6940d536aad3cb9 [file] [log] [blame]
Mariusz Szafranskia4041332017-08-02 17:28:17 +02001/*
2 * This file is part of the coreboot project.
3 *
Mariusz Szafranskia4041332017-08-02 17:28:17 +02004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 */
15
16#include <console/console.h>
17#include <device/device.h>
18#include <device/pci.h>
19#include <device/pci_ids.h>
20#include <arch/io.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020021#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020022#include <device/pci_ops.h>
Mariusz Szafranskia4041332017-08-02 17:28:17 +020023#include <arch/ioapic.h>
24#include <arch/acpi.h>
Mariusz Szafranskia4041332017-08-02 17:28:17 +020025#include <cpu/x86/smm.h>
26#include <bootstate.h>
27
28#include <soc/lpc.h>
29#include <soc/pci_devs.h>
30#include <soc/ramstage.h>
31#include <soc/iomap.h>
32#include <soc/pcr.h>
33#include <soc/p2sb.h>
34#include <soc/acpi.h>
35
36#include "chip.h"
37
38/* PCH-LP redirection entries */
39#define PCH_LP_REDIR_ETR 120
40
41/**
Jonathan Neuschäfer5268b762018-02-12 12:24:25 +010042 * Set miscellaneous static southbridge features.
Mariusz Szafranskia4041332017-08-02 17:28:17 +020043 *
44 * @param dev PCI device with I/O APIC control registers
45 */
46static void pch_enable_ioapic(struct device *dev)
47{
48 u32 reg32;
49
50 set_ioapic_id((void *)IO_APIC_ADDR, IO_APIC0);
51
52 /* affirm full set of redirection table entries ("write once") */
53 reg32 = io_apic_read((void *)IO_APIC_ADDR, 0x01);
54
55 reg32 &= ~0x00ff0000;
56 reg32 |= (PCH_LP_REDIR_ETR - 1) << 16;
57
58 io_apic_write((void *)IO_APIC_ADDR, 0x01, reg32);
59
60 /*
61 * Select Boot Configuration register (0x03) and
62 * use Processor System Bus (0x01) to deliver interrupts.
63 */
64 io_apic_write((void *)IO_APIC_ADDR, 0x03, 0x01);
65}
66
Stephen Douthit56a74bc2019-08-05 12:49:08 -040067/* interrupt router lookup for internal devices */
68struct dnv_ir_lut {
69 /* (dev << 3) | fn */
70 u8 devfn;
71 u8 ir;
72};
73
74#define DEVFN(dev, fn) ((dev << 3) | (fn))
75
76static const struct dnv_ir_lut dnv_ir_lut[] = {
77 {.devfn = DEVFN(0x05, 0), .ir = 3}, /* RCEC */
78 {.devfn = DEVFN(0x06, 0), .ir = 4}, /* Virtual RP to QAT */
79 {.devfn = DEVFN(0x09, 0), .ir = 7}, /* PCIe RP0 */
80 {.devfn = DEVFN(0x0a, 0), .ir = 7}, /* PCIe RP1 */
81 {.devfn = DEVFN(0x0b, 0), .ir = 7}, /* PCIe RP2 */
82 {.devfn = DEVFN(0x0c, 0), .ir = 7}, /* PCIe RP3 */
83 {.devfn = DEVFN(0x0e, 0), .ir = 8}, /* PCIe RP4 */
84 {.devfn = DEVFN(0x0f, 0), .ir = 8}, /* PCIe RP5 */
85 {.devfn = DEVFN(0x10, 0), .ir = 8}, /* PCIe RP6 */
86 {.devfn = DEVFN(0x11, 0), .ir = 8}, /* PCIe RP7 */
87 {.devfn = DEVFN(0x12, 0), .ir = 10}, /* SMBus - Host */
88 {.devfn = DEVFN(0x13, 0), .ir = 6}, /* AHCI0 */
89 {.devfn = DEVFN(0x14, 0), .ir = 11}, /* AHCI1 */
90 {.devfn = DEVFN(0x15, 0), .ir = 9}, /* USB */
91 {.devfn = DEVFN(0x16, 0), .ir = 1}, /* Virtual RP to LAN0 */
92 {.devfn = DEVFN(0x17, 0), .ir = 2}, /* Virtual RP to LAN1 */
93 {.devfn = DEVFN(0x18, 0), .ir = 5}, /* ME HECI1 */
94 {.devfn = DEVFN(0x18, 1), .ir = 5}, /* ME HECI1 */
95 {.devfn = DEVFN(0x18, 2), .ir = 5}, /* ME PTIO-IDER */
96 {.devfn = DEVFN(0x18, 3), .ir = 5}, /* ME PTIO-KT */
97 {.devfn = DEVFN(0x18, 4), .ir = 5}, /* ME HECI3 */
98 {.devfn = DEVFN(0x1a, 0), .ir = 10}, /* HSUART0 */
99 {.devfn = DEVFN(0x1a, 1), .ir = 10}, /* HSUART1 */
100 {.devfn = DEVFN(0x1a, 2), .ir = 10}, /* HSUART2 */
101 {.devfn = DEVFN(0x1b, 0), .ir = 12}, /* IE HECI1 */
102 {.devfn = DEVFN(0x1b, 1), .ir = 12}, /* IE HECI1 */
103 {.devfn = DEVFN(0x1b, 2), .ir = 12}, /* IE PTIO-IDER */
104 {.devfn = DEVFN(0x1b, 3), .ir = 12}, /* IE PTIO-KT */
105 {.devfn = DEVFN(0x1b, 4), .ir = 12}, /* IE HECI3 */
106 {.devfn = DEVFN(0x1c, 0), .ir = 12}, /* SDHCI */
107 {.devfn = DEVFN(0x1f, 0), .ir = 0}, /* LPC */
108 {.devfn = DEVFN(0x1f, 1), .ir = 0}, /* PS2B */
109 {.devfn = DEVFN(0x1f, 4), .ir = 0}, /* SMBus - Legacy */
110 {.devfn = DEVFN(0x1f, 7), .ir = 0}, /* Trace Hub */
111};
112
113/*
114 * Only 6 of the 8 root ports have swizzling, return '1' if this bdf is one of
115 * them, '0' otherwise
116 */
117static int is_dnv_swizzled_rp(uint16_t bdf)
118{
119 switch (bdf) {
120 case DEVFN(10, 0):
121 case DEVFN(11, 0):
122 case DEVFN(12, 0):
123 case DEVFN(15, 0):
124 case DEVFN(16, 0):
125 case DEVFN(17, 0):
126 return 1;
127 }
128
129 return 0;
130}
131
132/*
133 * Figure out which upstream interrupt pin a downstream device gets swizzled to
134 *
135 * config - pointer to chip_info containing routing info
136 * devfn - device/function of root port to check swizzling for
137 * pin - interrupt pin 1-4 = A-D
138 *
139 * Return new pin mapping, 0 if invalid pin
140 */
141static int dnv_get_swizzled_pin(config_t *config, u8 devfn, u8 pin)
142{
143 if (pin < 1 || pin > 4)
144 return 0;
145
146 devfn >>= 3;
147 if (devfn < 13)
148 devfn -= 9;
149 else
150 devfn -= 14;
151
152 return ((pin - 1 + devfn) % 4) + 1;
153}
154
155/*
156 * Figure out which upstream interrupt pin a downstream device gets swizzled to
157 *
158 * config - pointer to chip_info containing routing info
159 * devfn - device/function of root port to check swizzling for
160 * pin - interrupt pin 1-4 = A-D
161 *
162 * Return new pin mapping, 0 if invalid pin
163 */
164static int dnv_get_ir(config_t *config, u8 devfn, u8 pin)
165{
166 int i = 0;
167 int line = 0xff;
168 u16 ir = 0xffff;
169
170 /* The only valid pin values are 1-4 for A-D */
171 if (pin < 1 || pin > 4) {
172 printk(BIOS_WARNING, "%s: pin %d is invalid\n", __func__, pin);
173 goto dnv_get_ir_done;
174 }
175
176 for (i = 0; i < ARRAY_SIZE(dnv_ir_lut); i++) {
177 if (dnv_ir_lut[i].devfn == devfn)
178 break;
179 }
180
181 if (i == ARRAY_SIZE(dnv_ir_lut)) {
182 printk(BIOS_WARNING, "%s: no entry\n", __func__);
183 goto dnv_get_ir_done;
184 }
185
186 switch (dnv_ir_lut[i].ir) {
187 case 0:
188 ir = config->ir00_routing;
189 break;
190 case 1:
191 ir = config->ir01_routing;
192 break;
193 case 2:
194 ir = config->ir02_routing;
195 break;
196 case 3:
197 ir = config->ir03_routing;
198 break;
199 case 4:
200 ir = config->ir04_routing;
201 break;
202 case 5:
203 ir = config->ir05_routing;
204 break;
205 case 6:
206 ir = config->ir06_routing;
207 break;
208 case 7:
209 ir = config->ir07_routing;
210 break;
211 case 8:
212 ir = config->ir08_routing;
213 break;
214 case 9:
215 ir = config->ir09_routing;
216 break;
217 case 10:
218 ir = config->ir10_routing;
219 break;
220 case 11:
221 ir = config->ir11_routing;
222 break;
223 case 12:
224 ir = config->ir12_routing;
225 break;
226 default:
227 printk(BIOS_ERR, "%s: invalid ir %d for entry %d\n", __func__, dnv_ir_lut[i].ir,
228 i);
229 goto dnv_get_ir_done;
230 }
231
232 ir >>= (pin - 1) * 4;
233 ir &= 0xf;
234 switch (ir) {
235 case 0:
236 line = config->pirqa_routing;
237 break;
238 case 1:
239 line = config->pirqb_routing;
240 break;
241 case 2:
242 line = config->pirqc_routing;
243 break;
244 case 3:
245 line = config->pirqd_routing;
246 break;
247 case 4:
248 line = config->pirqe_routing;
249 break;
250 case 5:
251 line = config->pirqf_routing;
252 break;
253 case 6:
254 line = config->pirqg_routing;
255 break;
256 case 7:
257 line = config->pirqh_routing;
258 break;
259 default:
260 printk(BIOS_ERR, "%s: invalid ir pirq %d for entry %d\n", __func__, ir, i);
261 break;
262 }
263
264dnv_get_ir_done:
265 return line;
266}
267
268/*
269 * PCI devices have the INT_LINE (0x3C) and INT_PIN (0x3D) registers which
270 * report interrupt routing information to operating systems and drivers. The
271 * INT_PIN register is generally read only and reports which interrupt pin
272 * A - D it uses. The INT_LINE register is configurable and reports which IRQ
273 * (generally the PIC IRQs 1 - 15) it will use. This needs to take interrupt
274 * pin swizzling on devices that are downstream on a PCI bridge into account.
275 */
276static u8 dnv_get_int_line(struct device *irq_dev)
277{
278 config_t *config;
279 struct device *targ_dev = NULL;
280 uint16_t parent_bdf = 0;
281 int8_t original_int_pin = 0, new_int_pin = 0, swiz_int_pin = 0;
282 uint8_t int_line = 0xff;
283
284 if (irq_dev->path.type != DEVICE_PATH_PCI || !irq_dev->enabled) {
285 printk(BIOS_ERR, "%s for non pci device?\n", __func__);
286 goto dnv_get_int_line_done;
287 }
288
289 /*
290 * Get the INT_PIN swizzled up to the root port if necessary
291 * using the existing coreboot pci_device code
292 */
293 original_int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
294 new_int_pin = get_pci_irq_pins(irq_dev, &targ_dev);
295 if (targ_dev == NULL || new_int_pin < 1)
296 goto dnv_get_int_line_done;
297
298 printk(BIOS_DEBUG, "%s: irq_dev %s, targ_dev %s:\n", __func__, dev_path(irq_dev),
299 dev_path(targ_dev));
300 printk(BIOS_DEBUG, "%s: std swizzle %s from %c to %c\n", __func__, dev_path(targ_dev),
301 '@' + original_int_pin, '@' + new_int_pin);
302
303 /* Swizzle this device if needed */
304 config = targ_dev->chip_info;
305 parent_bdf = targ_dev->path.pci.devfn | targ_dev->bus->secondary << 8;
306 if (is_dnv_swizzled_rp(parent_bdf) && irq_dev != targ_dev) {
307 swiz_int_pin = dnv_get_swizzled_pin(config, parent_bdf, new_int_pin);
308 printk(BIOS_DEBUG, "%s: dnv swizzle %s from %c to %c\n", __func__,
309 dev_path(targ_dev), '@' + new_int_pin, '@' + swiz_int_pin);
310 } else {
311 swiz_int_pin = new_int_pin;
312 }
313
314 /* Look up the routing for the pin */
315 int_line = dnv_get_ir(config, parent_bdf, swiz_int_pin);
316
317dnv_get_int_line_done:
318 printk(BIOS_DEBUG, "\tINT_LINE\t\t: %d\n", int_line);
319 return int_line;
320}
321
Mariusz Szafranskia4041332017-08-02 17:28:17 +0200322/* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control
323 * 0x00 - 0000 = Reserved
324 * 0x01 - 0001 = Reserved
325 * 0x02 - 0010 = Reserved
326 * 0x03 - 0011 = IRQ3
327 * 0x04 - 0100 = IRQ4
328 * 0x05 - 0101 = IRQ5
329 * 0x06 - 0110 = IRQ6
330 * 0x07 - 0111 = IRQ7
331 * 0x08 - 1000 = Reserved
332 * 0x09 - 1001 = IRQ9
333 * 0x0A - 1010 = IRQ10
334 * 0x0B - 1011 = IRQ11
335 * 0x0C - 1100 = IRQ12
336 * 0x0D - 1101 = Reserved
337 * 0x0E - 1110 = IRQ14
338 * 0x0F - 1111 = IRQ15
339 * PIRQ[n]_ROUT[7] - PIRQ Routing Control
340 * 0x80 - The PIRQ is not routed.
341 */
342
Elyes HAOUAS2ec41832018-05-27 17:40:58 +0200343static void pch_pirq_init(struct device *dev)
Mariusz Szafranskia4041332017-08-02 17:28:17 +0200344{
Elyes HAOUAS2ec41832018-05-27 17:40:58 +0200345 struct device *irq_dev;
Mariusz Szafranskia4041332017-08-02 17:28:17 +0200346 /* Get the chip configuration */
Kyösti Mälkki8950cfb2019-07-13 22:16:25 +0300347 config_t *config = config_of(dev);
Mariusz Szafranskia4041332017-08-02 17:28:17 +0200348
349 /* Initialize PIRQ Routings */
350 write8((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIRQA_ROUT),
351 config->pirqa_routing);
352 write8((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIRQB_ROUT),
353 config->pirqb_routing);
354 write8((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIRQC_ROUT),
355 config->pirqc_routing);
356 write8((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIRQD_ROUT),
357 config->pirqd_routing);
358
359 write8((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIRQE_ROUT),
360 config->pirqe_routing);
361 write8((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIRQF_ROUT),
362 config->pirqf_routing);
363 write8((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIRQG_ROUT),
364 config->pirqg_routing);
365 write8((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIRQH_ROUT),
366 config->pirqh_routing);
367
368 /* Initialize device's Interrupt Routings */
369 write16((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIR00),
370 config->ir00_routing);
371 write16((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIR01),
372 config->ir01_routing);
373 write16((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIR02),
374 config->ir02_routing);
375 write16((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIR03),
376 config->ir03_routing);
377 write16((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIR04),
378 config->ir04_routing);
379 write16((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIR05),
380 config->ir05_routing);
381 write16((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIR06),
382 config->ir06_routing);
383 write16((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIR07),
384 config->ir07_routing);
385 write16((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIR08),
386 config->ir08_routing);
387 write16((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIR09),
388 config->ir09_routing);
389 write16((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIR10),
390 config->ir10_routing);
391 write16((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIR11),
392 config->ir11_routing);
393 write16((void *)PCH_PCR_ADDRESS(PID_ITSS, PCR_ITSS_PIR12),
394 config->ir12_routing);
395
396 /* Initialize device's Interrupt Polarity Control */
397 write32((void *)PCH_PCR_ADDRESS(PID_ITSS, PCH_PCR_ITSS_IPC0),
398 config->ipc0);
399 write32((void *)PCH_PCR_ADDRESS(PID_ITSS, PCH_PCR_ITSS_IPC1),
400 config->ipc1);
401 write32((void *)PCH_PCR_ADDRESS(PID_ITSS, PCH_PCR_ITSS_IPC2),
402 config->ipc2);
403 write32((void *)PCH_PCR_ADDRESS(PID_ITSS, PCH_PCR_ITSS_IPC3),
404 config->ipc3);
405
406 for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) {
Stephen Douthit56a74bc2019-08-05 12:49:08 -0400407 int devfn = irq_dev->path.pci.devfn;
Mariusz Szafranskia4041332017-08-02 17:28:17 +0200408 u8 int_pin = 0, int_line = 0;
409
410 if (!irq_dev->enabled || irq_dev->path.type != DEVICE_PATH_PCI)
411 continue;
412
413 int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
414
Stephen Douthit56a74bc2019-08-05 12:49:08 -0400415 int_line = dnv_get_int_line(irq_dev);
416 printk(BIOS_DEBUG, "%s: %02x:%02x.%d pin %d int line %d\n", __func__,
417 irq_dev->bus->secondary, devfn >> 3, devfn & 0x7, int_pin, int_line);
Mariusz Szafranskia4041332017-08-02 17:28:17 +0200418
419 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line);
420 }
421}
422
Elyes HAOUAS2ec41832018-05-27 17:40:58 +0200423static void pci_p2sb_read_resources(struct device *dev)
Mariusz Szafranskia4041332017-08-02 17:28:17 +0200424{
425 struct resource *res;
426
427 /* Add MMIO resource
428 * Use 0xda as an unused index for PCR BAR.
429 */
430 res = new_resource(dev, 0xda);
431 res->base = DEFAULT_PCR_BASE;
432 res->size = 16 * 1024 * 1024; /* 16MB PCR config space */
433 res->flags = IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_STORED |
434 IORESOURCE_ASSIGNED;
435 printk(BIOS_DEBUG,
436 "Adding P2SB PCR config space BAR 0x%08lx-0x%08lx.\n",
437 (unsigned long)(res->base),
438 (unsigned long)(res->base + res->size));
439
440 /* Add MMIO resource
441 * Use 0xdb as an unused index for IOAPIC.
442 */
443 res = new_resource(dev, 0xdb); /* IOAPIC */
444 res->base = IO_APIC_ADDR;
445 res->size = 0x00001000;
446 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
447}
448
449static void pch_enable_serial_irqs(struct device *dev)
450{
451 /* Set packet length and toggle silent mode bit for one frame. */
452 pci_write_config8(dev, SERIRQ_CNTL,
453 (1 << 7) | (1 << 6) | ((21 - 17) << 2) | (0 << 0));
Julius Wernercd49cce2019-03-05 16:53:33 -0800454#if !CONFIG(SERIRQ_CONTINUOUS_MODE)
Mariusz Szafranskia4041332017-08-02 17:28:17 +0200455 pci_write_config8(dev, SERIRQ_CNTL,
456 (1 << 7) | (0 << 6) | ((21 - 17) << 2) | (0 << 0));
457#endif
458}
459
460static void lpc_init(struct device *dev)
461{
462 printk(BIOS_DEBUG, "pch: lpc_init\n");
463
464 /* Get the base address */
465
466 /* Set the value for PCI command register. */
467 pci_write_config16(dev, PCI_COMMAND,
468 PCI_COMMAND_SPECIAL | PCI_COMMAND_MASTER |
469 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
470
471 /* Serial IRQ initialization. */
472 pch_enable_serial_irqs(dev);
473
474 /* IO APIC initialization. */
475 pch_enable_ioapic(dev);
476
477 /* Setup the PIRQ. */
478 pch_pirq_init(dev);
479}
480
Elyes HAOUAS2ec41832018-05-27 17:40:58 +0200481static void pch_lpc_add_mmio_resources(struct device *dev) { /* TODO */ }
Mariusz Szafranskia4041332017-08-02 17:28:17 +0200482
Elyes HAOUAS2ec41832018-05-27 17:40:58 +0200483static void pch_lpc_add_io_resources(struct device *dev)
Mariusz Szafranskia4041332017-08-02 17:28:17 +0200484{
485 struct resource *res;
486 u8 io_index = 0;
487
488 /* Add an extra subtractive resource for both memory and I/O. */
489 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
490 res->base = 0;
491 res->size = 0x1000;
492 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
493 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
494
495 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
496 res->base = 0xff000000;
497 res->size = 0x01000000; /* 16 MB for flash */
498 res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE |
499 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
500}
501
Elyes HAOUAS2ec41832018-05-27 17:40:58 +0200502static void lpc_read_resources(struct device *dev)
Mariusz Szafranskia4041332017-08-02 17:28:17 +0200503{
504 /* Get the normal PCI resources of this device. */
505 pci_dev_read_resources(dev);
506
507 /* Add non-standard MMIO resources. */
508 pch_lpc_add_mmio_resources(dev);
509
510 /* Add IO resources. */
511 pch_lpc_add_io_resources(dev);
512
513 /* Add MMIO resource for IOAPIC. */
514 pci_p2sb_read_resources(dev);
515}
516
517static void pch_decode_init(struct device *dev) { /* TODO */ }
518
Elyes HAOUAS2ec41832018-05-27 17:40:58 +0200519static void lpc_enable_resources(struct device *dev)
Mariusz Szafranskia4041332017-08-02 17:28:17 +0200520{
521 pch_decode_init(dev);
522 pci_dev_enable_resources(dev);
523}
524
525/* Set bit in Function Disable register to hide this device */
526static void pch_hide_devfn(uint32_t devfn) { /* TODO */ }
527
Elyes HAOUAS2ec41832018-05-27 17:40:58 +0200528void southcluster_enable_dev(struct device *dev)
Mariusz Szafranskia4041332017-08-02 17:28:17 +0200529{
530 u32 reg32;
531
532 if (!dev->enabled) {
533 printk(BIOS_DEBUG, "%s: Disabling device\n", dev_path(dev));
534
535 /* Ensure memory, io, and bus master are all disabled */
536 reg32 = pci_read_config32(dev, PCI_COMMAND);
537 reg32 &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY |
538 PCI_COMMAND_IO);
539 pci_write_config32(dev, PCI_COMMAND, reg32);
540
541 /* Hide this device if possible */
542 pch_hide_devfn(dev->path.pci.devfn);
543 } else {
544 /* Enable SERR */
545 reg32 = pci_read_config32(dev, PCI_COMMAND);
546 reg32 |= PCI_COMMAND_SERR;
547 pci_write_config32(dev, PCI_COMMAND, reg32);
548 }
549}
550
551static struct device_operations device_ops = {
552 .read_resources = lpc_read_resources,
553 .set_resources = pci_dev_set_resources,
Julius Wernercd49cce2019-03-05 16:53:33 -0800554#if CONFIG(HAVE_ACPI_TABLES)
Nico Huber68680dd2020-03-31 17:34:52 +0200555 .acpi_inject_dsdt = southcluster_inject_dsdt,
Mariusz Szafranskia4041332017-08-02 17:28:17 +0200556 .write_acpi_tables = southcluster_write_acpi_tables,
557#endif
558 .enable_resources = lpc_enable_resources,
559 .init = lpc_init,
560 .enable = southcluster_enable_dev,
Nico Huber51b75ae2019-03-14 16:02:05 +0100561 .scan_bus = scan_static_bus,
Mariusz Szafranskia4041332017-08-02 17:28:17 +0200562 .ops_pci = &soc_pci_ops,
563};
564
565static const struct pci_driver lpc_driver __pci_driver = {
566 .ops = &device_ops,
567 .vendor = PCI_VENDOR_ID_INTEL,
Felix Singerdbc90df2019-11-22 00:10:20 +0100568 .device = PCI_DEVICE_ID_INTEL_DENVERTON_LPC,
Mariusz Szafranskia4041332017-08-02 17:28:17 +0200569};
570
571static void finalize_chipset(void *unused)
572{
573 printk(BIOS_DEBUG, "Finalizing SMM.\n");
574 outb(APM_CNT_FINALIZE, APM_CNT);
575}
576
577BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, finalize_chipset, NULL);
578BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, finalize_chipset, NULL);