blob: 8dd898615edf57ae8550b782ec5e7ac4a5dffe8e [file] [log] [blame]
Aaron Durbine18d68f2013-10-24 00:05:31 -05001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
5 * Copyright (C) 2013 Google Inc.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
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.
Aaron Durbine18d68f2013-10-24 00:05:31 -050015 */
16
17#include <stdint.h>
18#include <arch/io.h>
Kein Yuan35110232014-02-22 12:26:55 -080019#include <arch/acpi.h>
Aaron Durbin4177db52014-02-05 14:55:26 -060020#include <bootstate.h>
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -080021#include <cbmem.h>
Aaron Durbin64031672018-04-21 14:45:32 -060022#include <compiler.h>
Aaron Durbind7bc23a2013-10-29 16:37:10 -050023#include <console/console.h>
Aaron Durbin4177db52014-02-05 14:55:26 -060024#include <cpu/x86/smm.h>
Aaron Durbine18d68f2013-10-24 00:05:31 -050025#include <device/device.h>
26#include <device/pci.h>
27#include <device/pci_ids.h>
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -080028#include <pc80/mc146818rtc.h>
Kein Yuan35110232014-02-22 12:26:55 -080029#include <drivers/uart/uart8250reg.h>
Aaron Durbine18d68f2013-10-24 00:05:31 -050030
Julius Werner18ea2d32014-10-07 16:42:17 -070031#include <soc/iomap.h>
32#include <soc/irq.h>
33#include <soc/lpc.h>
34#include <soc/nvs.h>
35#include <soc/pci_devs.h>
36#include <soc/pmc.h>
37#include <soc/ramstage.h>
38#include <soc/spi.h>
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -080039#include "chip.h"
Vladimir Serbinenko7fb149d2014-10-08 22:56:27 +020040#include <arch/acpi.h>
41#include <arch/acpigen.h>
42#include <cpu/cpu.h>
Aaron Durbine18d68f2013-10-24 00:05:31 -050043
44static inline void
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020045add_mmio_resource(struct device *dev, int i, unsigned long addr,
46 unsigned long size)
Aaron Durbine18d68f2013-10-24 00:05:31 -050047{
48 mmio_resource(dev, i, addr >> 10, size >> 10);
49}
50
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020051static void sc_add_mmio_resources(struct device *dev)
Aaron Durbine18d68f2013-10-24 00:05:31 -050052{
Duncan Laurie7fbe20b2013-11-04 17:00:22 -080053 add_mmio_resource(dev, 0xfeb, ABORT_BASE_ADDRESS, ABORT_BASE_SIZE);
54 add_mmio_resource(dev, PBASE, PMC_BASE_ADDRESS, PMC_BASE_SIZE);
55 add_mmio_resource(dev, IOBASE, IO_BASE_ADDRESS, IO_BASE_SIZE);
56 add_mmio_resource(dev, IBASE, ILB_BASE_ADDRESS, ILB_BASE_SIZE);
57 add_mmio_resource(dev, SBASE, SPI_BASE_ADDRESS, SPI_BASE_SIZE);
58 add_mmio_resource(dev, MPBASE, MPHY_BASE_ADDRESS, MPHY_BASE_SIZE);
59 add_mmio_resource(dev, PUBASE, PUNIT_BASE_ADDRESS, PUNIT_BASE_SIZE);
60 add_mmio_resource(dev, RCBA, RCBA_BASE_ADDRESS, RCBA_BASE_SIZE);
Aaron Durbine18d68f2013-10-24 00:05:31 -050061}
62
63/* Default IO range claimed by the LPC device. The upper bound is exclusive. */
64#define LPC_DEFAULT_IO_RANGE_LOWER 0
65#define LPC_DEFAULT_IO_RANGE_UPPER 0x1000
66
67static inline int io_range_in_default(int base, int size)
68{
69 /* Does it start above the range? */
70 if (base >= LPC_DEFAULT_IO_RANGE_UPPER)
71 return 0;
72
73 /* Is it entirely contained? */
74 if (base >= LPC_DEFAULT_IO_RANGE_LOWER &&
75 (base + size) < LPC_DEFAULT_IO_RANGE_UPPER)
76 return 1;
77
78 /* This will return not in range for partial overlaps. */
79 return 0;
80}
81
82/*
83 * Note: this function assumes there is no overlap with the default LPC device's
84 * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER.
85 */
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +020086static void sc_add_io_resource(struct device *dev, int base, int size,
87 int index)
Aaron Durbine18d68f2013-10-24 00:05:31 -050088{
89 struct resource *res;
90
91 if (io_range_in_default(base, size))
92 return;
93
94 res = new_resource(dev, index);
95 res->base = base;
96 res->size = size;
97 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
98}
99
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200100static void sc_add_io_resources(struct device *dev)
Aaron Durbine18d68f2013-10-24 00:05:31 -0500101{
102 struct resource *res;
103
104 /* Add the default claimed IO range for the LPC device. */
105 res = new_resource(dev, 0);
106 res->base = LPC_DEFAULT_IO_RANGE_LOWER;
107 res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER;
108 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
109
110 /* GPIO */
111 sc_add_io_resource(dev, GPIO_BASE_ADDRESS, 256, GBASE);
112
113 /* ACPI */
114 sc_add_io_resource(dev, ACPI_BASE_ADDRESS, 128, ABASE);
115}
116
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200117static void sc_read_resources(struct device *dev)
Aaron Durbine18d68f2013-10-24 00:05:31 -0500118{
119 /* Get the normal PCI resources of this device. */
120 pci_dev_read_resources(dev);
121
122 /* Add non-standard MMIO resources. */
123 sc_add_mmio_resources(dev);
124
125 /* Add IO resources. */
126 sc_add_io_resources(dev);
127}
128
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -0800129static void sc_rtc_init(void)
130{
Aaron Durbin64b4bdd2017-09-15 14:24:03 -0600131 cmos_init(rtc_failure());
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -0800132}
133
Kein Yuan35110232014-02-22 12:26:55 -0800134/*
135 * The UART hardware loses power while in suspend. Because of this the kernel
136 * can hang because it doesn't re-initialize serial ports it is using for
137 * consoles at resume time. The following function configures the UART
138 * if the hardware is enabled though it may not be the correct baud rate
139 * or configuration. This is definitely a hack, but it helps the kernel
140 * along.
141 */
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200142static void com1_configure_resume(struct device *dev)
Kein Yuan35110232014-02-22 12:26:55 -0800143{
144 const uint16_t port = 0x3f8;
145
Martin Roth99a3bba2014-12-07 14:57:26 -0700146 /* Is the UART I/O port enabled? */
Kein Yuan35110232014-02-22 12:26:55 -0800147 if (!(pci_read_config32(dev, UART_CONT) & 1))
148 return;
149
150 /* Disable interrupts */
151 outb(0x0, port + UART8250_IER);
152
153 /* Enable FIFOs */
154 outb(UART8250_FCR_FIFO_EN, port + UART8250_FCR);
155
156 /* assert DTR and RTS so the other end is happy */
157 outb(UART8250_MCR_DTR | UART8250_MCR_RTS, port + UART8250_MCR);
158
159 /* DLAB on */
160 outb(UART8250_LCR_DLAB | 3, port + UART8250_LCR);
161
162 /* Set Baud Rate Divisor. 1 ==> 115200 Baud */
163 outb(1, port + UART8250_DLL);
164 outb(0, port + UART8250_DLM);
165
166 /* Set to 3 for 8N1 */
167 outb(3, port + UART8250_LCR);
168}
169
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200170static void sc_init(struct device *dev)
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600171{
172 int i;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800173 u8 *pr_base = (u8 *)(ILB_BASE_ADDRESS + 0x08);
Alexander Couzens316170e2015-11-24 09:46:18 +0100174 u16 *ir_base = (u16 *)(ILB_BASE_ADDRESS + 0x20);
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800175 u32 *gen_pmcon1 = (u32 *)(PMC_BASE_ADDRESS + GEN_PMCON1);
176 u32 *actl = (u32 *)(ILB_BASE_ADDRESS + ACTL);
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600177 const struct baytrail_irq_route *ir = &global_baytrail_irq_route;
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -0800178 struct soc_intel_baytrail_config *config = dev->chip_info;
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600179
180 /* Set up the PIRQ PIC routing based on static config. */
181 for (i = 0; i < NUM_PIRQS; i++) {
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800182 write8(pr_base + i, ir->pic[i]);
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600183 }
184 /* Set up the per device PIRQ routing base on static config. */
185 for (i = 0; i < NUM_IR_DEVS; i++) {
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800186 write16(ir_base + i, ir->pcidev[i]);
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600187 }
Aaron Durbin1af36632013-11-07 10:42:16 -0600188
189 /* Route SCI to IRQ9 */
190 write32(actl, (read32(actl) & ~SCIS_MASK) | SCIS_IRQ9);
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -0800191
192 sc_rtc_init();
193
194 if (config->disable_slp_x_stretch_sus_fail) {
195 printk(BIOS_DEBUG, "Disabling slp_x stretching.\n");
196 write32(gen_pmcon1,
197 read32(gen_pmcon1) | DIS_SLP_X_STRCH_SUS_UP);
198 } else {
199 write32(gen_pmcon1,
200 read32(gen_pmcon1) & ~DIS_SLP_X_STRCH_SUS_UP);
201 }
Kein Yuan35110232014-02-22 12:26:55 -0800202
Kyösti Mälkki9e94dbf2015-01-08 20:03:18 +0200203 if (acpi_is_wakeup_s3())
Kein Yuan35110232014-02-22 12:26:55 -0800204 com1_configure_resume(dev);
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600205}
206
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500207/*
208 * Common code for the south cluster devices.
209 */
210
Martin Roth99a3bba2014-12-07 14:57:26 -0700211/* Set bit in function disable register to hide this device. */
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200212static void sc_disable_devfn(struct device *dev)
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500213{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800214 u32 *func_dis = (u32 *)(PMC_BASE_ADDRESS + FUNC_DIS);
215 u32 *func_dis2 = (u32 *)(PMC_BASE_ADDRESS + FUNC_DIS2);
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500216 uint32_t mask = 0;
217 uint32_t mask2 = 0;
218
219 switch (dev->path.pci.devfn) {
220 case PCI_DEVFN(SDIO_DEV, SDIO_FUNC):
221 mask |= SDIO_DIS;
222 break;
223 case PCI_DEVFN(SD_DEV, SD_FUNC):
224 mask |= SD_DIS;
225 break;
226 case PCI_DEVFN(SATA_DEV, SATA_FUNC):
227 mask |= SATA_DIS;
228 break;
229 case PCI_DEVFN(XHCI_DEV, XHCI_FUNC):
230 mask |= XHCI_DIS;
231 /* Disable super speed PHY when XHCI is not available. */
232 mask2 |= USH_SS_PHY_DIS;
233 break;
234 case PCI_DEVFN(LPE_DEV, LPE_FUNC):
235 mask |= LPE_DIS;
236 break;
237 case PCI_DEVFN(MMC_DEV, MMC_FUNC):
238 mask |= MMC_DIS;
239 break;
240 case PCI_DEVFN(SIO_DMA1_DEV, SIO_DMA1_FUNC):
241 mask |= SIO_DMA1_DIS;
242 break;
243 case PCI_DEVFN(I2C1_DEV, I2C1_FUNC):
244 mask |= I2C1_DIS;
245 break;
246 case PCI_DEVFN(I2C2_DEV, I2C2_FUNC):
247 mask |= I2C1_DIS;
248 break;
249 case PCI_DEVFN(I2C3_DEV, I2C3_FUNC):
250 mask |= I2C3_DIS;
251 break;
252 case PCI_DEVFN(I2C4_DEV, I2C4_FUNC):
253 mask |= I2C4_DIS;
254 break;
255 case PCI_DEVFN(I2C5_DEV, I2C5_FUNC):
256 mask |= I2C5_DIS;
257 break;
258 case PCI_DEVFN(I2C6_DEV, I2C6_FUNC):
259 mask |= I2C6_DIS;
260 break;
261 case PCI_DEVFN(I2C7_DEV, I2C7_FUNC):
262 mask |= I2C7_DIS;
263 break;
264 case PCI_DEVFN(TXE_DEV, TXE_FUNC):
265 mask |= TXE_DIS;
266 break;
267 case PCI_DEVFN(HDA_DEV, HDA_FUNC):
268 mask |= HDA_DIS;
269 break;
270 case PCI_DEVFN(PCIE_PORT1_DEV, PCIE_PORT1_FUNC):
271 mask |= PCIE_PORT1_DIS;
272 break;
273 case PCI_DEVFN(PCIE_PORT2_DEV, PCIE_PORT2_FUNC):
274 mask |= PCIE_PORT2_DIS;
275 break;
276 case PCI_DEVFN(PCIE_PORT3_DEV, PCIE_PORT3_FUNC):
277 mask |= PCIE_PORT3_DIS;
278 break;
279 case PCI_DEVFN(PCIE_PORT4_DEV, PCIE_PORT4_FUNC):
280 mask |= PCIE_PORT4_DIS;
281 break;
282 case PCI_DEVFN(EHCI_DEV, EHCI_FUNC):
283 mask |= EHCI_DIS;
284 break;
285 case PCI_DEVFN(SIO_DMA2_DEV, SIO_DMA2_FUNC):
286 mask |= SIO_DMA2_DIS;
287 break;
288 case PCI_DEVFN(PWM1_DEV, PWM1_FUNC):
289 mask |= PWM1_DIS;
290 break;
291 case PCI_DEVFN(PWM2_DEV, PWM2_FUNC):
292 mask |= PWM2_DIS;
293 break;
294 case PCI_DEVFN(HSUART1_DEV, HSUART1_FUNC):
295 mask |= HSUART1_DIS;
296 break;
297 case PCI_DEVFN(HSUART2_DEV, HSUART2_FUNC):
298 mask |= HSUART2_DIS;
299 break;
300 case PCI_DEVFN(SPI_DEV, SPI_FUNC):
301 mask |= SPI_DIS;
302 break;
303 case PCI_DEVFN(SMBUS_DEV, SMBUS_FUNC):
304 mask2 |= SMBUS_DIS;
305 break;
306 }
307
308 if (mask != 0) {
309 write32(func_dis, read32(func_dis) | mask);
310 /* Ensure posted write hits. */
311 read32(func_dis);
312 }
313
314 if (mask2 != 0) {
315 write32(func_dis2, read32(func_dis2) | mask2);
316 /* Ensure posted write hits. */
317 read32(func_dis2);
318 }
319}
320
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200321static inline void set_d3hot_bits(struct device *dev, int offset)
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500322{
323 uint32_t reg8;
324 printk(BIOS_DEBUG, "Power management CAP offset 0x%x.\n", offset);
325 reg8 = pci_read_config8(dev, offset + 4);
326 reg8 |= 0x3;
327 pci_write_config8(dev, offset + 4, reg8);
328}
329
Aaron Durbin46ab8cd2013-10-30 17:07:46 -0500330/* Parts of the audio subsystem are powered by the HDA device. Therefore, one
331 * cannot put HDA into D3Hot. Instead perform this workaround to make some of
332 * the audio paths work for LPE audio. */
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200333static void hda_work_around(struct device *dev)
Aaron Durbin46ab8cd2013-10-30 17:07:46 -0500334{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800335 u32 *gctl = (u32 *)(TEMP_BASE_ADDRESS + 0x8);
Aaron Durbin46ab8cd2013-10-30 17:07:46 -0500336
337 /* Need to set magic register 0x43 to 0xd7 in config space. */
338 pci_write_config8(dev, 0x43, 0xd7);
339
340 /* Need to set bit 0 of GCTL to take the device out of reset. However,
341 * that requires setting up the 64-bit BAR. */
342 pci_write_config32(dev, PCI_BASE_ADDRESS_0, TEMP_BASE_ADDRESS);
343 pci_write_config32(dev, PCI_BASE_ADDRESS_1, 0);
344 pci_write_config8(dev, PCI_COMMAND, PCI_COMMAND_MEMORY);
345 write32(gctl, read32(gctl) | 0x1);
346 pci_write_config8(dev, PCI_COMMAND, 0);
347 pci_write_config32(dev, PCI_BASE_ADDRESS_0, 0);
348}
349
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200350static int place_device_in_d3hot(struct device *dev)
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500351{
352 unsigned offset;
353
Aaron Durbin46ab8cd2013-10-30 17:07:46 -0500354 /* Parts of the HDA block are used for LPE audio as well.
355 * Therefore assume the HDA will never be put into D3Hot. */
356 if (dev->path.pci.devfn == PCI_DEVFN(HDA_DEV, HDA_FUNC)) {
357 hda_work_around(dev);
358 return 0;
359 }
360
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500361 offset = pci_find_capability(dev, PCI_CAP_ID_PM);
362
363 if (offset != 0) {
364 set_d3hot_bits(dev, offset);
365 return 0;
366 }
367
368 /* For some reason some of the devices don't have the capability
369 * pointer set correctly. Work around this by hard coding the offset. */
370 switch (dev->path.pci.devfn) {
371 case PCI_DEVFN(SDIO_DEV, SDIO_FUNC):
372 offset = 0x80;
373 break;
374 case PCI_DEVFN(SD_DEV, SD_FUNC):
375 offset = 0x80;
376 break;
377 case PCI_DEVFN(MMC_DEV, MMC_FUNC):
378 offset = 0x80;
379 break;
380 case PCI_DEVFN(LPE_DEV, LPE_FUNC):
381 offset = 0x80;
382 break;
383 case PCI_DEVFN(SIO_DMA1_DEV, SIO_DMA1_FUNC):
384 offset = 0x80;
385 break;
386 case PCI_DEVFN(I2C1_DEV, I2C1_FUNC):
387 offset = 0x80;
388 break;
389 case PCI_DEVFN(I2C2_DEV, I2C2_FUNC):
390 offset = 0x80;
391 break;
392 case PCI_DEVFN(I2C3_DEV, I2C3_FUNC):
393 offset = 0x80;
394 break;
395 case PCI_DEVFN(I2C4_DEV, I2C4_FUNC):
396 offset = 0x80;
397 break;
398 case PCI_DEVFN(I2C5_DEV, I2C5_FUNC):
399 offset = 0x80;
400 break;
401 case PCI_DEVFN(I2C6_DEV, I2C6_FUNC):
402 offset = 0x80;
403 break;
404 case PCI_DEVFN(I2C7_DEV, I2C7_FUNC):
405 offset = 0x80;
406 break;
407 case PCI_DEVFN(SIO_DMA2_DEV, SIO_DMA2_FUNC):
408 offset = 0x80;
409 break;
410 case PCI_DEVFN(PWM1_DEV, PWM1_FUNC):
411 offset = 0x80;
412 break;
413 case PCI_DEVFN(PWM2_DEV, PWM2_FUNC):
414 offset = 0x80;
415 break;
416 case PCI_DEVFN(HSUART1_DEV, HSUART1_FUNC):
417 offset = 0x80;
418 break;
419 case PCI_DEVFN(HSUART2_DEV, HSUART2_FUNC):
420 offset = 0x80;
421 break;
422 case PCI_DEVFN(SPI_DEV, SPI_FUNC):
423 offset = 0x80;
424 break;
425 case PCI_DEVFN(SATA_DEV, SATA_FUNC):
426 offset = 0x70;
427 break;
428 case PCI_DEVFN(XHCI_DEV, XHCI_FUNC):
429 offset = 0x70;
430 break;
431 case PCI_DEVFN(EHCI_DEV, EHCI_FUNC):
432 offset = 0x70;
433 break;
434 case PCI_DEVFN(HDA_DEV, HDA_FUNC):
435 offset = 0x50;
436 break;
437 case PCI_DEVFN(SMBUS_DEV, SMBUS_FUNC):
438 offset = 0x50;
439 break;
440 case PCI_DEVFN(TXE_DEV, TXE_FUNC):
Aaron Durbin1eae3ee2013-10-30 17:08:59 -0500441 /* TXE cannot be placed in D3Hot. */
442 return 0;
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500443 case PCI_DEVFN(PCIE_PORT1_DEV, PCIE_PORT1_FUNC):
444 offset = 0xa0;
445 break;
446 case PCI_DEVFN(PCIE_PORT2_DEV, PCIE_PORT2_FUNC):
447 offset = 0xa0;
448 break;
449 case PCI_DEVFN(PCIE_PORT3_DEV, PCIE_PORT3_FUNC):
450 offset = 0xa0;
451 break;
452 case PCI_DEVFN(PCIE_PORT4_DEV, PCIE_PORT4_FUNC):
453 offset = 0xa0;
454 break;
455 }
456
457 if (offset != 0) {
458 set_d3hot_bits(dev, offset);
459 return 0;
460 }
461
462 return -1;
463}
464
465/* Common PCI device function disable. */
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200466void southcluster_enable_dev(struct device *dev)
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500467{
468 uint32_t reg32;
469
470 if (!dev->enabled) {
471 int slot = PCI_SLOT(dev->path.pci.devfn);
472 int func = PCI_FUNC(dev->path.pci.devfn);
473 printk(BIOS_DEBUG, "%s: Disabling device: %02x.%01x\n",
474 dev_path(dev), slot, func);
475
476 /* Ensure memory, io, and bus master are all disabled */
477 reg32 = pci_read_config32(dev, PCI_COMMAND);
478 reg32 &= ~(PCI_COMMAND_MASTER |
479 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
480 pci_write_config32(dev, PCI_COMMAND, reg32);
481
482 /* Place device in D3Hot */
483 if (place_device_in_d3hot(dev) < 0) {
484 printk(BIOS_WARNING,
485 "Could not place %02x.%01x into D3Hot. "
486 "Keeping device visible.\n", slot, func);
487 return;
488 }
489 /* Disable this device if possible */
490 sc_disable_devfn(dev);
491 } else {
492 /* Enable SERR */
493 reg32 = pci_read_config32(dev, PCI_COMMAND);
494 reg32 |= PCI_COMMAND_SERR;
495 pci_write_config32(dev, PCI_COMMAND, reg32);
496 }
497}
498
Elyes HAOUAS17a3ceb2018-05-22 10:42:28 +0200499static void southcluster_inject_dsdt(struct device *device)
Vladimir Serbinenko7fb149d2014-10-08 22:56:27 +0200500{
501 global_nvs_t *gnvs;
502
503 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
504 if (!gnvs) {
505 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof (*gnvs));
506 if (gnvs)
507 memset(gnvs, 0, sizeof(*gnvs));
508 }
509
510 if (gnvs) {
511 acpi_create_gnvs(gnvs);
512 acpi_save_gnvs((unsigned long)gnvs);
513 /* And tell SMI about it */
514 smm_setup_structures(gnvs, NULL, NULL);
515
516 /* Add it to DSDT. */
517 acpigen_write_scope("\\");
518 acpigen_write_name_dword("NVSA", (u32) gnvs);
519 acpigen_pop_len();
520 }
521}
522
523
Aaron Durbine18d68f2013-10-24 00:05:31 -0500524static struct device_operations device_ops = {
525 .read_resources = sc_read_resources,
526 .set_resources = pci_dev_set_resources,
Vladimir Serbinenko7fb149d2014-10-08 22:56:27 +0200527 .acpi_inject_dsdt_generator = southcluster_inject_dsdt,
528 .write_acpi_tables = acpi_write_hpet,
Aaron Durbine18d68f2013-10-24 00:05:31 -0500529 .enable_resources = NULL,
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600530 .init = sc_init,
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500531 .enable = southcluster_enable_dev,
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +0200532 .scan_bus = scan_lpc_bus,
Aaron Durbine18d68f2013-10-24 00:05:31 -0500533 .ops_pci = &soc_pci_ops,
534};
535
536static const struct pci_driver southcluster __pci_driver = {
537 .ops = &device_ops,
538 .vendor = PCI_VENDOR_ID_INTEL,
539 .device = LPC_DEVID,
540};
Aaron Durbin4177db52014-02-05 14:55:26 -0600541
Aaron Durbin64031672018-04-21 14:45:32 -0600542int __weak mainboard_get_spi_config(struct spi_config *cfg)
Aaron Durbin4177db52014-02-05 14:55:26 -0600543{
544 return -1;
545}
546
547static void finalize_chipset(void *unused)
548{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800549 u32 *bcr = (u32 *)(SPI_BASE_ADDRESS + BCR);
550 u32 *gcs = (u32 *)(RCBA_BASE_ADDRESS + GCS);
551 u32 *gen_pmcon2 = (u32 *)(PMC_BASE_ADDRESS + GEN_PMCON2);
552 u32 *etr = (u32 *)(PMC_BASE_ADDRESS + ETR);
553 u8 *spi = (u8 *)SPI_BASE_ADDRESS;
Aaron Durbin4177db52014-02-05 14:55:26 -0600554 struct spi_config cfg;
555
556 /* Set the lock enable on the BIOS control register. */
557 write32(bcr, read32(bcr) | BCR_LE);
558
559 /* Set BIOS lock down bit controlling boot block size and swapping. */
560 write32(gcs, read32(gcs) | BILD);
561
562 /* Lock sleep stretching policy and set SMI lock. */
563 write32(gen_pmcon2, read32(gen_pmcon2) | SLPSX_STR_POL_LOCK | SMI_LOCK);
564
565 /* Set the CF9 lock. */
566 write32(etr, read32(etr) | CF9LOCK);
567
568 if (mainboard_get_spi_config(&cfg) < 0) {
569 printk(BIOS_DEBUG, "No SPI lockdown configuration.\n");
570 } else {
571 write16(spi + PREOP, cfg.preop);
572 write16(spi + OPTYPE, cfg.optype);
573 write32(spi + OPMENU0, cfg.opmenu[0]);
574 write32(spi + OPMENU1, cfg.opmenu[1]);
575 write16(spi + HSFSTS, read16(spi + HSFSTS) | FLOCKDN);
576 write32(spi + UVSCC, cfg.uvscc);
577 write32(spi + LVSCC, cfg.lvscc | VCL);
578 }
579
580 printk(BIOS_DEBUG, "Finalizing SMM.\n");
581 outb(APM_CNT_FINALIZE, APM_CNT);
582}
583
Aaron Durbin9ef9d852015-03-16 17:30:09 -0500584BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, finalize_chipset, NULL);
585BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, finalize_chipset, NULL);