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