blob: 84ae0ee0d3d3cb5c1a8057521333c85317ae36c9 [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
45add_mmio_resource(device_t dev, int i, unsigned long addr, unsigned long size)
46{
47 mmio_resource(dev, i, addr >> 10, size >> 10);
48}
49
50static void sc_add_mmio_resources(device_t dev)
51{
Duncan Laurie7fbe20b2013-11-04 17:00:22 -080052 add_mmio_resource(dev, 0xfeb, ABORT_BASE_ADDRESS, ABORT_BASE_SIZE);
53 add_mmio_resource(dev, PBASE, PMC_BASE_ADDRESS, PMC_BASE_SIZE);
54 add_mmio_resource(dev, IOBASE, IO_BASE_ADDRESS, IO_BASE_SIZE);
55 add_mmio_resource(dev, IBASE, ILB_BASE_ADDRESS, ILB_BASE_SIZE);
56 add_mmio_resource(dev, SBASE, SPI_BASE_ADDRESS, SPI_BASE_SIZE);
57 add_mmio_resource(dev, MPBASE, MPHY_BASE_ADDRESS, MPHY_BASE_SIZE);
58 add_mmio_resource(dev, PUBASE, PUNIT_BASE_ADDRESS, PUNIT_BASE_SIZE);
59 add_mmio_resource(dev, RCBA, RCBA_BASE_ADDRESS, RCBA_BASE_SIZE);
Aaron Durbine18d68f2013-10-24 00:05:31 -050060}
61
62/* Default IO range claimed by the LPC device. The upper bound is exclusive. */
63#define LPC_DEFAULT_IO_RANGE_LOWER 0
64#define LPC_DEFAULT_IO_RANGE_UPPER 0x1000
65
66static inline int io_range_in_default(int base, int size)
67{
68 /* Does it start above the range? */
69 if (base >= LPC_DEFAULT_IO_RANGE_UPPER)
70 return 0;
71
72 /* Is it entirely contained? */
73 if (base >= LPC_DEFAULT_IO_RANGE_LOWER &&
74 (base + size) < LPC_DEFAULT_IO_RANGE_UPPER)
75 return 1;
76
77 /* This will return not in range for partial overlaps. */
78 return 0;
79}
80
81/*
82 * Note: this function assumes there is no overlap with the default LPC device's
83 * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER.
84 */
85static void sc_add_io_resource(device_t dev, int base, int size, int index)
86{
87 struct resource *res;
88
89 if (io_range_in_default(base, size))
90 return;
91
92 res = new_resource(dev, index);
93 res->base = base;
94 res->size = size;
95 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
96}
97
98static void sc_add_io_resources(device_t dev)
99{
100 struct resource *res;
101
102 /* Add the default claimed IO range for the LPC device. */
103 res = new_resource(dev, 0);
104 res->base = LPC_DEFAULT_IO_RANGE_LOWER;
105 res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER;
106 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
107
108 /* GPIO */
109 sc_add_io_resource(dev, GPIO_BASE_ADDRESS, 256, GBASE);
110
111 /* ACPI */
112 sc_add_io_resource(dev, ACPI_BASE_ADDRESS, 128, ABASE);
113}
114
115static void sc_read_resources(device_t dev)
116{
117 /* Get the normal PCI resources of this device. */
118 pci_dev_read_resources(dev);
119
120 /* Add non-standard MMIO resources. */
121 sc_add_mmio_resources(dev);
122
123 /* Add IO resources. */
124 sc_add_io_resources(dev);
125}
126
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -0800127static void sc_rtc_init(void)
128{
Aaron Durbin64b4bdd2017-09-15 14:24:03 -0600129 cmos_init(rtc_failure());
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -0800130}
131
Kein Yuan35110232014-02-22 12:26:55 -0800132/*
133 * The UART hardware loses power while in suspend. Because of this the kernel
134 * can hang because it doesn't re-initialize serial ports it is using for
135 * consoles at resume time. The following function configures the UART
136 * if the hardware is enabled though it may not be the correct baud rate
137 * or configuration. This is definitely a hack, but it helps the kernel
138 * along.
139 */
140static void com1_configure_resume(device_t dev)
141{
142 const uint16_t port = 0x3f8;
143
Martin Roth99a3bba2014-12-07 14:57:26 -0700144 /* Is the UART I/O port enabled? */
Kein Yuan35110232014-02-22 12:26:55 -0800145 if (!(pci_read_config32(dev, UART_CONT) & 1))
146 return;
147
148 /* Disable interrupts */
149 outb(0x0, port + UART8250_IER);
150
151 /* Enable FIFOs */
152 outb(UART8250_FCR_FIFO_EN, port + UART8250_FCR);
153
154 /* assert DTR and RTS so the other end is happy */
155 outb(UART8250_MCR_DTR | UART8250_MCR_RTS, port + UART8250_MCR);
156
157 /* DLAB on */
158 outb(UART8250_LCR_DLAB | 3, port + UART8250_LCR);
159
160 /* Set Baud Rate Divisor. 1 ==> 115200 Baud */
161 outb(1, port + UART8250_DLL);
162 outb(0, port + UART8250_DLM);
163
164 /* Set to 3 for 8N1 */
165 outb(3, port + UART8250_LCR);
166}
167
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600168static void sc_init(device_t dev)
169{
170 int i;
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800171 u8 *pr_base = (u8 *)(ILB_BASE_ADDRESS + 0x08);
Alexander Couzens316170e2015-11-24 09:46:18 +0100172 u16 *ir_base = (u16 *)(ILB_BASE_ADDRESS + 0x20);
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800173 u32 *gen_pmcon1 = (u32 *)(PMC_BASE_ADDRESS + GEN_PMCON1);
174 u32 *actl = (u32 *)(ILB_BASE_ADDRESS + ACTL);
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600175 const struct baytrail_irq_route *ir = &global_baytrail_irq_route;
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -0800176 struct soc_intel_baytrail_config *config = dev->chip_info;
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600177
178 /* Set up the PIRQ PIC routing based on static config. */
179 for (i = 0; i < NUM_PIRQS; i++) {
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800180 write8(pr_base + i, ir->pic[i]);
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600181 }
182 /* Set up the per device PIRQ routing base on static config. */
183 for (i = 0; i < NUM_IR_DEVS; i++) {
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800184 write16(ir_base + i, ir->pcidev[i]);
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600185 }
Aaron Durbin1af36632013-11-07 10:42:16 -0600186
187 /* Route SCI to IRQ9 */
188 write32(actl, (read32(actl) & ~SCIS_MASK) | SCIS_IRQ9);
Shawn Nematbakhsh51d787a2014-01-16 17:52:21 -0800189
190 sc_rtc_init();
191
192 if (config->disable_slp_x_stretch_sus_fail) {
193 printk(BIOS_DEBUG, "Disabling slp_x stretching.\n");
194 write32(gen_pmcon1,
195 read32(gen_pmcon1) | DIS_SLP_X_STRCH_SUS_UP);
196 } else {
197 write32(gen_pmcon1,
198 read32(gen_pmcon1) & ~DIS_SLP_X_STRCH_SUS_UP);
199 }
Kein Yuan35110232014-02-22 12:26:55 -0800200
Kyösti Mälkki9e94dbf2015-01-08 20:03:18 +0200201 if (acpi_is_wakeup_s3())
Kein Yuan35110232014-02-22 12:26:55 -0800202 com1_configure_resume(dev);
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600203}
204
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500205/*
206 * Common code for the south cluster devices.
207 */
208
Martin Roth99a3bba2014-12-07 14:57:26 -0700209/* Set bit in function disable register to hide this device. */
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500210static void sc_disable_devfn(device_t dev)
211{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800212 u32 *func_dis = (u32 *)(PMC_BASE_ADDRESS + FUNC_DIS);
213 u32 *func_dis2 = (u32 *)(PMC_BASE_ADDRESS + FUNC_DIS2);
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500214 uint32_t mask = 0;
215 uint32_t mask2 = 0;
216
217 switch (dev->path.pci.devfn) {
218 case PCI_DEVFN(SDIO_DEV, SDIO_FUNC):
219 mask |= SDIO_DIS;
220 break;
221 case PCI_DEVFN(SD_DEV, SD_FUNC):
222 mask |= SD_DIS;
223 break;
224 case PCI_DEVFN(SATA_DEV, SATA_FUNC):
225 mask |= SATA_DIS;
226 break;
227 case PCI_DEVFN(XHCI_DEV, XHCI_FUNC):
228 mask |= XHCI_DIS;
229 /* Disable super speed PHY when XHCI is not available. */
230 mask2 |= USH_SS_PHY_DIS;
231 break;
232 case PCI_DEVFN(LPE_DEV, LPE_FUNC):
233 mask |= LPE_DIS;
234 break;
235 case PCI_DEVFN(MMC_DEV, MMC_FUNC):
236 mask |= MMC_DIS;
237 break;
238 case PCI_DEVFN(SIO_DMA1_DEV, SIO_DMA1_FUNC):
239 mask |= SIO_DMA1_DIS;
240 break;
241 case PCI_DEVFN(I2C1_DEV, I2C1_FUNC):
242 mask |= I2C1_DIS;
243 break;
244 case PCI_DEVFN(I2C2_DEV, I2C2_FUNC):
245 mask |= I2C1_DIS;
246 break;
247 case PCI_DEVFN(I2C3_DEV, I2C3_FUNC):
248 mask |= I2C3_DIS;
249 break;
250 case PCI_DEVFN(I2C4_DEV, I2C4_FUNC):
251 mask |= I2C4_DIS;
252 break;
253 case PCI_DEVFN(I2C5_DEV, I2C5_FUNC):
254 mask |= I2C5_DIS;
255 break;
256 case PCI_DEVFN(I2C6_DEV, I2C6_FUNC):
257 mask |= I2C6_DIS;
258 break;
259 case PCI_DEVFN(I2C7_DEV, I2C7_FUNC):
260 mask |= I2C7_DIS;
261 break;
262 case PCI_DEVFN(TXE_DEV, TXE_FUNC):
263 mask |= TXE_DIS;
264 break;
265 case PCI_DEVFN(HDA_DEV, HDA_FUNC):
266 mask |= HDA_DIS;
267 break;
268 case PCI_DEVFN(PCIE_PORT1_DEV, PCIE_PORT1_FUNC):
269 mask |= PCIE_PORT1_DIS;
270 break;
271 case PCI_DEVFN(PCIE_PORT2_DEV, PCIE_PORT2_FUNC):
272 mask |= PCIE_PORT2_DIS;
273 break;
274 case PCI_DEVFN(PCIE_PORT3_DEV, PCIE_PORT3_FUNC):
275 mask |= PCIE_PORT3_DIS;
276 break;
277 case PCI_DEVFN(PCIE_PORT4_DEV, PCIE_PORT4_FUNC):
278 mask |= PCIE_PORT4_DIS;
279 break;
280 case PCI_DEVFN(EHCI_DEV, EHCI_FUNC):
281 mask |= EHCI_DIS;
282 break;
283 case PCI_DEVFN(SIO_DMA2_DEV, SIO_DMA2_FUNC):
284 mask |= SIO_DMA2_DIS;
285 break;
286 case PCI_DEVFN(PWM1_DEV, PWM1_FUNC):
287 mask |= PWM1_DIS;
288 break;
289 case PCI_DEVFN(PWM2_DEV, PWM2_FUNC):
290 mask |= PWM2_DIS;
291 break;
292 case PCI_DEVFN(HSUART1_DEV, HSUART1_FUNC):
293 mask |= HSUART1_DIS;
294 break;
295 case PCI_DEVFN(HSUART2_DEV, HSUART2_FUNC):
296 mask |= HSUART2_DIS;
297 break;
298 case PCI_DEVFN(SPI_DEV, SPI_FUNC):
299 mask |= SPI_DIS;
300 break;
301 case PCI_DEVFN(SMBUS_DEV, SMBUS_FUNC):
302 mask2 |= SMBUS_DIS;
303 break;
304 }
305
306 if (mask != 0) {
307 write32(func_dis, read32(func_dis) | mask);
308 /* Ensure posted write hits. */
309 read32(func_dis);
310 }
311
312 if (mask2 != 0) {
313 write32(func_dis2, read32(func_dis2) | mask2);
314 /* Ensure posted write hits. */
315 read32(func_dis2);
316 }
317}
318
319static inline void set_d3hot_bits(device_t dev, int offset)
320{
321 uint32_t reg8;
322 printk(BIOS_DEBUG, "Power management CAP offset 0x%x.\n", offset);
323 reg8 = pci_read_config8(dev, offset + 4);
324 reg8 |= 0x3;
325 pci_write_config8(dev, offset + 4, reg8);
326}
327
Aaron Durbin46ab8cd2013-10-30 17:07:46 -0500328/* Parts of the audio subsystem are powered by the HDA device. Therefore, one
329 * cannot put HDA into D3Hot. Instead perform this workaround to make some of
330 * the audio paths work for LPE audio. */
331static void hda_work_around(device_t dev)
332{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800333 u32 *gctl = (u32 *)(TEMP_BASE_ADDRESS + 0x8);
Aaron Durbin46ab8cd2013-10-30 17:07:46 -0500334
335 /* Need to set magic register 0x43 to 0xd7 in config space. */
336 pci_write_config8(dev, 0x43, 0xd7);
337
338 /* Need to set bit 0 of GCTL to take the device out of reset. However,
339 * that requires setting up the 64-bit BAR. */
340 pci_write_config32(dev, PCI_BASE_ADDRESS_0, TEMP_BASE_ADDRESS);
341 pci_write_config32(dev, PCI_BASE_ADDRESS_1, 0);
342 pci_write_config8(dev, PCI_COMMAND, PCI_COMMAND_MEMORY);
343 write32(gctl, read32(gctl) | 0x1);
344 pci_write_config8(dev, PCI_COMMAND, 0);
345 pci_write_config32(dev, PCI_BASE_ADDRESS_0, 0);
346}
347
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500348static int place_device_in_d3hot(device_t dev)
349{
350 unsigned offset;
351
Aaron Durbin46ab8cd2013-10-30 17:07:46 -0500352 /* Parts of the HDA block are used for LPE audio as well.
353 * Therefore assume the HDA will never be put into D3Hot. */
354 if (dev->path.pci.devfn == PCI_DEVFN(HDA_DEV, HDA_FUNC)) {
355 hda_work_around(dev);
356 return 0;
357 }
358
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500359 offset = pci_find_capability(dev, PCI_CAP_ID_PM);
360
361 if (offset != 0) {
362 set_d3hot_bits(dev, offset);
363 return 0;
364 }
365
366 /* For some reason some of the devices don't have the capability
367 * pointer set correctly. Work around this by hard coding the offset. */
368 switch (dev->path.pci.devfn) {
369 case PCI_DEVFN(SDIO_DEV, SDIO_FUNC):
370 offset = 0x80;
371 break;
372 case PCI_DEVFN(SD_DEV, SD_FUNC):
373 offset = 0x80;
374 break;
375 case PCI_DEVFN(MMC_DEV, MMC_FUNC):
376 offset = 0x80;
377 break;
378 case PCI_DEVFN(LPE_DEV, LPE_FUNC):
379 offset = 0x80;
380 break;
381 case PCI_DEVFN(SIO_DMA1_DEV, SIO_DMA1_FUNC):
382 offset = 0x80;
383 break;
384 case PCI_DEVFN(I2C1_DEV, I2C1_FUNC):
385 offset = 0x80;
386 break;
387 case PCI_DEVFN(I2C2_DEV, I2C2_FUNC):
388 offset = 0x80;
389 break;
390 case PCI_DEVFN(I2C3_DEV, I2C3_FUNC):
391 offset = 0x80;
392 break;
393 case PCI_DEVFN(I2C4_DEV, I2C4_FUNC):
394 offset = 0x80;
395 break;
396 case PCI_DEVFN(I2C5_DEV, I2C5_FUNC):
397 offset = 0x80;
398 break;
399 case PCI_DEVFN(I2C6_DEV, I2C6_FUNC):
400 offset = 0x80;
401 break;
402 case PCI_DEVFN(I2C7_DEV, I2C7_FUNC):
403 offset = 0x80;
404 break;
405 case PCI_DEVFN(SIO_DMA2_DEV, SIO_DMA2_FUNC):
406 offset = 0x80;
407 break;
408 case PCI_DEVFN(PWM1_DEV, PWM1_FUNC):
409 offset = 0x80;
410 break;
411 case PCI_DEVFN(PWM2_DEV, PWM2_FUNC):
412 offset = 0x80;
413 break;
414 case PCI_DEVFN(HSUART1_DEV, HSUART1_FUNC):
415 offset = 0x80;
416 break;
417 case PCI_DEVFN(HSUART2_DEV, HSUART2_FUNC):
418 offset = 0x80;
419 break;
420 case PCI_DEVFN(SPI_DEV, SPI_FUNC):
421 offset = 0x80;
422 break;
423 case PCI_DEVFN(SATA_DEV, SATA_FUNC):
424 offset = 0x70;
425 break;
426 case PCI_DEVFN(XHCI_DEV, XHCI_FUNC):
427 offset = 0x70;
428 break;
429 case PCI_DEVFN(EHCI_DEV, EHCI_FUNC):
430 offset = 0x70;
431 break;
432 case PCI_DEVFN(HDA_DEV, HDA_FUNC):
433 offset = 0x50;
434 break;
435 case PCI_DEVFN(SMBUS_DEV, SMBUS_FUNC):
436 offset = 0x50;
437 break;
438 case PCI_DEVFN(TXE_DEV, TXE_FUNC):
Aaron Durbin1eae3ee2013-10-30 17:08:59 -0500439 /* TXE cannot be placed in D3Hot. */
440 return 0;
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500441 case PCI_DEVFN(PCIE_PORT1_DEV, PCIE_PORT1_FUNC):
442 offset = 0xa0;
443 break;
444 case PCI_DEVFN(PCIE_PORT2_DEV, PCIE_PORT2_FUNC):
445 offset = 0xa0;
446 break;
447 case PCI_DEVFN(PCIE_PORT3_DEV, PCIE_PORT3_FUNC):
448 offset = 0xa0;
449 break;
450 case PCI_DEVFN(PCIE_PORT4_DEV, PCIE_PORT4_FUNC):
451 offset = 0xa0;
452 break;
453 }
454
455 if (offset != 0) {
456 set_d3hot_bits(dev, offset);
457 return 0;
458 }
459
460 return -1;
461}
462
463/* Common PCI device function disable. */
464void southcluster_enable_dev(device_t dev)
465{
466 uint32_t reg32;
467
468 if (!dev->enabled) {
469 int slot = PCI_SLOT(dev->path.pci.devfn);
470 int func = PCI_FUNC(dev->path.pci.devfn);
471 printk(BIOS_DEBUG, "%s: Disabling device: %02x.%01x\n",
472 dev_path(dev), slot, func);
473
474 /* Ensure memory, io, and bus master are all disabled */
475 reg32 = pci_read_config32(dev, PCI_COMMAND);
476 reg32 &= ~(PCI_COMMAND_MASTER |
477 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
478 pci_write_config32(dev, PCI_COMMAND, reg32);
479
480 /* Place device in D3Hot */
481 if (place_device_in_d3hot(dev) < 0) {
482 printk(BIOS_WARNING,
483 "Could not place %02x.%01x into D3Hot. "
484 "Keeping device visible.\n", slot, func);
485 return;
486 }
487 /* Disable this device if possible */
488 sc_disable_devfn(dev);
489 } else {
490 /* Enable SERR */
491 reg32 = pci_read_config32(dev, PCI_COMMAND);
492 reg32 |= PCI_COMMAND_SERR;
493 pci_write_config32(dev, PCI_COMMAND, reg32);
494 }
495}
496
Alexander Couzensa90dad12015-04-12 21:49:46 +0200497static void southcluster_inject_dsdt(device_t device)
Vladimir Serbinenko7fb149d2014-10-08 22:56:27 +0200498{
499 global_nvs_t *gnvs;
500
501 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
502 if (!gnvs) {
503 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof (*gnvs));
504 if (gnvs)
505 memset(gnvs, 0, sizeof(*gnvs));
506 }
507
508 if (gnvs) {
509 acpi_create_gnvs(gnvs);
510 acpi_save_gnvs((unsigned long)gnvs);
511 /* And tell SMI about it */
512 smm_setup_structures(gnvs, NULL, NULL);
513
514 /* Add it to DSDT. */
515 acpigen_write_scope("\\");
516 acpigen_write_name_dword("NVSA", (u32) gnvs);
517 acpigen_pop_len();
518 }
519}
520
521
Aaron Durbine18d68f2013-10-24 00:05:31 -0500522static struct device_operations device_ops = {
523 .read_resources = sc_read_resources,
524 .set_resources = pci_dev_set_resources,
Vladimir Serbinenko7fb149d2014-10-08 22:56:27 +0200525 .acpi_inject_dsdt_generator = southcluster_inject_dsdt,
526 .write_acpi_tables = acpi_write_hpet,
Aaron Durbine18d68f2013-10-24 00:05:31 -0500527 .enable_resources = NULL,
Aaron Durbin3bde3d72013-11-04 21:45:52 -0600528 .init = sc_init,
Aaron Durbind7bc23a2013-10-29 16:37:10 -0500529 .enable = southcluster_enable_dev,
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +0200530 .scan_bus = scan_lpc_bus,
Aaron Durbine18d68f2013-10-24 00:05:31 -0500531 .ops_pci = &soc_pci_ops,
532};
533
534static const struct pci_driver southcluster __pci_driver = {
535 .ops = &device_ops,
536 .vendor = PCI_VENDOR_ID_INTEL,
537 .device = LPC_DEVID,
538};
Aaron Durbin4177db52014-02-05 14:55:26 -0600539
Aaron Durbin64031672018-04-21 14:45:32 -0600540int __weak mainboard_get_spi_config(struct spi_config *cfg)
Aaron Durbin4177db52014-02-05 14:55:26 -0600541{
542 return -1;
543}
544
545static void finalize_chipset(void *unused)
546{
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800547 u32 *bcr = (u32 *)(SPI_BASE_ADDRESS + BCR);
548 u32 *gcs = (u32 *)(RCBA_BASE_ADDRESS + GCS);
549 u32 *gen_pmcon2 = (u32 *)(PMC_BASE_ADDRESS + GEN_PMCON2);
550 u32 *etr = (u32 *)(PMC_BASE_ADDRESS + ETR);
551 u8 *spi = (u8 *)SPI_BASE_ADDRESS;
Aaron Durbin4177db52014-02-05 14:55:26 -0600552 struct spi_config cfg;
553
554 /* Set the lock enable on the BIOS control register. */
555 write32(bcr, read32(bcr) | BCR_LE);
556
557 /* Set BIOS lock down bit controlling boot block size and swapping. */
558 write32(gcs, read32(gcs) | BILD);
559
560 /* Lock sleep stretching policy and set SMI lock. */
561 write32(gen_pmcon2, read32(gen_pmcon2) | SLPSX_STR_POL_LOCK | SMI_LOCK);
562
563 /* Set the CF9 lock. */
564 write32(etr, read32(etr) | CF9LOCK);
565
566 if (mainboard_get_spi_config(&cfg) < 0) {
567 printk(BIOS_DEBUG, "No SPI lockdown configuration.\n");
568 } else {
569 write16(spi + PREOP, cfg.preop);
570 write16(spi + OPTYPE, cfg.optype);
571 write32(spi + OPMENU0, cfg.opmenu[0]);
572 write32(spi + OPMENU1, cfg.opmenu[1]);
573 write16(spi + HSFSTS, read16(spi + HSFSTS) | FLOCKDN);
574 write32(spi + UVSCC, cfg.uvscc);
575 write32(spi + LVSCC, cfg.lvscc | VCL);
576 }
577
578 printk(BIOS_DEBUG, "Finalizing SMM.\n");
579 outb(APM_CNT_FINALIZE, APM_CNT);
580}
581
Aaron Durbin9ef9d852015-03-16 17:30:09 -0500582BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, finalize_chipset, NULL);
583BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, finalize_chipset, NULL);