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