blob: 6eb61c72afccb9dbdb868ef68faab2d7cff3c564 [file] [log] [blame]
Lee Leahy77ff0b12015-05-05 15:07:29 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
5 * Copyright (C) 2013 Google Inc.
Lee Leahy32471722015-04-20 15:20:28 -07006 * Copyright (C) 2015 Intel Corp.
Lee Leahy77ff0b12015-05-05 15:07:29 -07007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
Lee Leahy77ff0b12015-05-05 15:07:29 -070016 */
17
Lee Leahy77ff0b12015-05-05 15:07:29 -070018#include <arch/io.h>
19#include <arch/acpi.h>
Lee Leahy2bc9cee2015-06-30 15:25:44 -070020#include <arch/acpigen.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070021#include <bootstate.h>
22#include <cbmem.h>
Lee Leahy32471722015-04-20 15:20:28 -070023#include "chip.h"
Lee Leahy77ff0b12015-05-05 15:07:29 -070024#include <console/console.h>
25#include <cpu/x86/smm.h>
26#include <device/device.h>
27#include <device/pci.h>
28#include <device/pci_ids.h>
29#include <pc80/mc146818rtc.h>
Lee Leahy32471722015-04-20 15:20:28 -070030#include <romstage_handoff.h>
Lee Leahy2bc9cee2015-06-30 15:25:44 -070031#include <soc/acpi.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070032#include <soc/iomap.h>
33#include <soc/irq.h>
34#include <soc/lpc.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070035#include <soc/pci_devs.h>
Lee Leahy32471722015-04-20 15:20:28 -070036#include <soc/pm.h>
Lee Leahy77ff0b12015-05-05 15:07:29 -070037#include <soc/ramstage.h>
38#include <soc/spi.h>
Lee Leahy32471722015-04-20 15:20:28 -070039#include <spi-generic.h>
40#include <stdint.h>
Hannah Williams3fa80a92017-03-22 16:33:36 -070041#include <reg_script.h>
42
43static const struct reg_script ops[] = {
44 REG_MMIO_RMW32(ILB_BASE_ADDRESS + SCNT,
45 ~SCNT_MODE, 0), /* put LPC SERIRQ in Quiet Mode */
46 REG_SCRIPT_END
47};
48
49static void enable_serirq_quiet_mode(void)
50{
51 reg_script_run(ops);
52}
Lee Leahy77ff0b12015-05-05 15:07:29 -070053
54static inline void
55add_mmio_resource(device_t dev, int i, unsigned long addr, unsigned long size)
56{
Lee Leahy32471722015-04-20 15:20:28 -070057 printk(BIOS_SPEW, "%s/%s ( %s, 0x%016lx, 0x%016lx )\n",
58 __FILE__, __func__, dev_name(dev), addr, size);
Lee Leahy77ff0b12015-05-05 15:07:29 -070059 mmio_resource(dev, i, addr >> 10, size >> 10);
60}
61
62static void sc_add_mmio_resources(device_t dev)
63{
Lee Leahy32471722015-04-20 15:20:28 -070064 printk(BIOS_SPEW, "%s/%s ( %s )\n",
65 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -070066 add_mmio_resource(dev, 0xfeb, ABORT_BASE_ADDRESS, ABORT_BASE_SIZE);
67 add_mmio_resource(dev, PBASE, PMC_BASE_ADDRESS, PMC_BASE_SIZE);
68 add_mmio_resource(dev, IOBASE, IO_BASE_ADDRESS, IO_BASE_SIZE);
69 add_mmio_resource(dev, IBASE, ILB_BASE_ADDRESS, ILB_BASE_SIZE);
70 add_mmio_resource(dev, SBASE, SPI_BASE_ADDRESS, SPI_BASE_SIZE);
71 add_mmio_resource(dev, MPBASE, MPHY_BASE_ADDRESS, MPHY_BASE_SIZE);
72 add_mmio_resource(dev, PUBASE, PUNIT_BASE_ADDRESS, PUNIT_BASE_SIZE);
73 add_mmio_resource(dev, RCBA, RCBA_BASE_ADDRESS, RCBA_BASE_SIZE);
74}
75
76/* Default IO range claimed by the LPC device. The upper bound is exclusive. */
77#define LPC_DEFAULT_IO_RANGE_LOWER 0
78#define LPC_DEFAULT_IO_RANGE_UPPER 0x1000
79
80static inline int io_range_in_default(int base, int size)
81{
82 /* Does it start above the range? */
83 if (base >= LPC_DEFAULT_IO_RANGE_UPPER)
84 return 0;
85
86 /* Is it entirely contained? */
87 if (base >= LPC_DEFAULT_IO_RANGE_LOWER &&
88 (base + size) < LPC_DEFAULT_IO_RANGE_UPPER)
89 return 1;
90
91 /* This will return not in range for partial overlaps. */
92 return 0;
93}
94
95/*
96 * Note: this function assumes there is no overlap with the default LPC device's
97 * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER.
98 */
99static void sc_add_io_resource(device_t dev, int base, int size, int index)
100{
101 struct resource *res;
102
Lee Leahy32471722015-04-20 15:20:28 -0700103 printk(BIOS_SPEW, "%s/%s ( %s, 0x%08x, 0x%08x, 0x%08x )\n",
104 __FILE__, __func__, dev_name(dev), base, size, index);
105
Lee Leahy77ff0b12015-05-05 15:07:29 -0700106 if (io_range_in_default(base, size))
107 return;
108
109 res = new_resource(dev, index);
110 res->base = base;
111 res->size = size;
112 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
113}
114
115static void sc_add_io_resources(device_t dev)
116{
117 struct resource *res;
118
Lee Leahy32471722015-04-20 15:20:28 -0700119 printk(BIOS_SPEW, "%s/%s ( %s )\n",
120 __FILE__, __func__, dev_name(dev));
121
Lee Leahy77ff0b12015-05-05 15:07:29 -0700122 /* Add the default claimed IO range for the LPC device. */
123 res = new_resource(dev, 0);
124 res->base = LPC_DEFAULT_IO_RANGE_LOWER;
125 res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER;
126 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
127
128 /* GPIO */
129 sc_add_io_resource(dev, GPIO_BASE_ADDRESS, 256, GBASE);
130
131 /* ACPI */
132 sc_add_io_resource(dev, ACPI_BASE_ADDRESS, 128, ABASE);
133}
134
135static void sc_read_resources(device_t dev)
136{
Lee Leahy32471722015-04-20 15:20:28 -0700137 printk(BIOS_SPEW, "%s/%s ( %s )\n",
138 __FILE__, __func__, dev_name(dev));
139
Lee Leahy77ff0b12015-05-05 15:07:29 -0700140 /* Get the normal PCI resources of this device. */
141 pci_dev_read_resources(dev);
142
143 /* Add non-standard MMIO resources. */
144 sc_add_mmio_resources(dev);
145
146 /* Add IO resources. */
147 sc_add_io_resources(dev);
148}
149
150static void sc_rtc_init(void)
151{
Aaron Durbinb19e33f2017-09-15 14:32:13 -0600152 printk(BIOS_SPEW, "%s/%s\n", __FILE__, __func__);
153 cmos_init(rtc_failure());
Lee Leahy77ff0b12015-05-05 15:07:29 -0700154}
155
Lee Leahy77ff0b12015-05-05 15:07:29 -0700156static void sc_init(device_t dev)
157{
158 int i;
Lee Leahy32471722015-04-20 15:20:28 -0700159 const unsigned long pr_base = ILB_BASE_ADDRESS + 0x08;
160 const unsigned long ir_base = ILB_BASE_ADDRESS + 0x20;
161 void *gen_pmcon1 = (void *)(PMC_BASE_ADDRESS + GEN_PMCON1);
162 void *actl = (void *)(ILB_BASE_ADDRESS + ACTL);
163 const struct soc_irq_route *ir = &global_soc_irq_route;
164 struct soc_intel_braswell_config *config = dev->chip_info;
165
166 printk(BIOS_SPEW, "%s/%s ( %s )\n",
167 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700168
169 /* Set up the PIRQ PIC routing based on static config. */
Lee Leahy32471722015-04-20 15:20:28 -0700170 for (i = 0; i < NUM_PIRQS; i++)
171 write8((void *)(pr_base + i*sizeof(ir->pic[i])),
172 ir->pic[i]);
173
Lee Leahy77ff0b12015-05-05 15:07:29 -0700174 /* Set up the per device PIRQ routing base on static config. */
Lee Leahy32471722015-04-20 15:20:28 -0700175 for (i = 0; i < NUM_IR_DEVS; i++)
176 write16((void *)(ir_base + i*sizeof(ir->pcidev[i])),
177 ir->pcidev[i]);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700178
179 /* Route SCI to IRQ9 */
180 write32(actl, (read32(actl) & ~SCIS_MASK) | SCIS_IRQ9);
181
182 sc_rtc_init();
183
184 if (config->disable_slp_x_stretch_sus_fail) {
185 printk(BIOS_DEBUG, "Disabling slp_x stretching.\n");
186 write32(gen_pmcon1,
187 read32(gen_pmcon1) | DIS_SLP_X_STRCH_SUS_UP);
188 } else {
189 write32(gen_pmcon1,
190 read32(gen_pmcon1) & ~DIS_SLP_X_STRCH_SUS_UP);
191 }
192
Lee Leahy77ff0b12015-05-05 15:07:29 -0700193}
194
195/*
196 * Common code for the south cluster devices.
197 */
198
Lee Leahy32471722015-04-20 15:20:28 -0700199/* Set bit in function disble register to hide this device. */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700200static void sc_disable_devfn(device_t dev)
201{
Lee Leahy32471722015-04-20 15:20:28 -0700202 void *func_dis = (void *)(PMC_BASE_ADDRESS + FUNC_DIS);
203 void *func_dis2 = (void *)(PMC_BASE_ADDRESS + FUNC_DIS2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700204 uint32_t mask = 0;
205 uint32_t mask2 = 0;
206
Lee Leahy32471722015-04-20 15:20:28 -0700207 printk(BIOS_SPEW, "%s/%s ( %s )\n",
208 __FILE__, __func__, dev_name(dev));
209
210#define SET_DIS_MASK(name_) \
211 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \
212 mask |= name_ ## _DIS
213#define SET_DIS_MASK2(name_) \
214 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \
215 mask2 |= name_ ## _DIS
216
Lee Leahy77ff0b12015-05-05 15:07:29 -0700217 switch (dev->path.pci.devfn) {
Lee Leahy32471722015-04-20 15:20:28 -0700218 SET_DIS_MASK(SDIO);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700219 break;
Lee Leahy32471722015-04-20 15:20:28 -0700220 SET_DIS_MASK(SD);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700221 break;
Lee Leahy32471722015-04-20 15:20:28 -0700222 SET_DIS_MASK(SATA);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700223 break;
Lee Leahy32471722015-04-20 15:20:28 -0700224 SET_DIS_MASK(XHCI);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700225 /* Disable super speed PHY when XHCI is not available. */
226 mask2 |= USH_SS_PHY_DIS;
227 break;
Lee Leahy32471722015-04-20 15:20:28 -0700228 SET_DIS_MASK(LPE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700229 break;
Lee Leahy32471722015-04-20 15:20:28 -0700230 SET_DIS_MASK(MMC);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700231 break;
Lee Leahy32471722015-04-20 15:20:28 -0700232 SET_DIS_MASK(SIO_DMA1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700233 break;
Lee Leahy32471722015-04-20 15:20:28 -0700234 SET_DIS_MASK(I2C1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700235 break;
Lee Leahy32471722015-04-20 15:20:28 -0700236 SET_DIS_MASK(I2C2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700237 break;
Lee Leahy32471722015-04-20 15:20:28 -0700238 SET_DIS_MASK(I2C3);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700239 break;
Lee Leahy32471722015-04-20 15:20:28 -0700240 SET_DIS_MASK(I2C4);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700241 break;
Lee Leahy32471722015-04-20 15:20:28 -0700242 SET_DIS_MASK(I2C5);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700243 break;
Lee Leahy32471722015-04-20 15:20:28 -0700244 SET_DIS_MASK(I2C6);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700245 break;
Lee Leahy32471722015-04-20 15:20:28 -0700246 SET_DIS_MASK(I2C7);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700247 break;
Lee Leahy32471722015-04-20 15:20:28 -0700248 SET_DIS_MASK(TXE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700249 break;
Lee Leahy32471722015-04-20 15:20:28 -0700250 SET_DIS_MASK(HDA);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700251 break;
Lee Leahy32471722015-04-20 15:20:28 -0700252 SET_DIS_MASK(PCIE_PORT1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700253 break;
Lee Leahy32471722015-04-20 15:20:28 -0700254 SET_DIS_MASK(PCIE_PORT2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700255 break;
Lee Leahy32471722015-04-20 15:20:28 -0700256 SET_DIS_MASK(PCIE_PORT3);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700257 break;
Lee Leahy32471722015-04-20 15:20:28 -0700258 SET_DIS_MASK(PCIE_PORT4);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700259 break;
Lee Leahy32471722015-04-20 15:20:28 -0700260 SET_DIS_MASK(SIO_DMA2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700261 break;
Lee Leahy32471722015-04-20 15:20:28 -0700262 SET_DIS_MASK(PWM1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700263 break;
Lee Leahy32471722015-04-20 15:20:28 -0700264 SET_DIS_MASK(PWM2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700265 break;
Lee Leahy32471722015-04-20 15:20:28 -0700266 SET_DIS_MASK(HSUART1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700267 break;
Lee Leahy32471722015-04-20 15:20:28 -0700268 SET_DIS_MASK(HSUART2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700269 break;
Lee Leahy32471722015-04-20 15:20:28 -0700270 SET_DIS_MASK(SPI);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700271 break;
Lee Leahy32471722015-04-20 15:20:28 -0700272 SET_DIS_MASK2(SMBUS);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700273 break;
274 }
275
276 if (mask != 0) {
277 write32(func_dis, read32(func_dis) | mask);
278 /* Ensure posted write hits. */
279 read32(func_dis);
280 }
281
282 if (mask2 != 0) {
283 write32(func_dis2, read32(func_dis2) | mask2);
284 /* Ensure posted write hits. */
285 read32(func_dis2);
286 }
287}
288
289static inline void set_d3hot_bits(device_t dev, int offset)
290{
291 uint32_t reg8;
Lee Leahy32471722015-04-20 15:20:28 -0700292
293 printk(BIOS_SPEW, "%s/%s ( %s, 0x%08x )\n",
294 __FILE__, __func__, dev_name(dev), offset);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700295 printk(BIOS_DEBUG, "Power management CAP offset 0x%x.\n", offset);
296 reg8 = pci_read_config8(dev, offset + 4);
297 reg8 |= 0x3;
298 pci_write_config8(dev, offset + 4, reg8);
299}
300
Lee Leahy32471722015-04-20 15:20:28 -0700301/*
302 * Parts of the audio subsystem are powered by the HDA device. Therefore, one
Lee Leahy77ff0b12015-05-05 15:07:29 -0700303 * cannot put HDA into D3Hot. Instead perform this workaround to make some of
Lee Leahy32471722015-04-20 15:20:28 -0700304 * the audio paths work for LPE audio.
305 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700306static void hda_work_around(device_t dev)
307{
Lee Leahy32471722015-04-20 15:20:28 -0700308 void *gctl = (void *)(TEMP_BASE_ADDRESS + 0x8);
309
310 printk(BIOS_SPEW, "%s/%s ( %s )\n",
311 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700312
313 /* Need to set magic register 0x43 to 0xd7 in config space. */
314 pci_write_config8(dev, 0x43, 0xd7);
315
Lee Leahy32471722015-04-20 15:20:28 -0700316 /*
317 * Need to set bit 0 of GCTL to take the device out of reset. However,
318 * that requires setting up the 64-bit BAR.
319 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700320 pci_write_config32(dev, PCI_BASE_ADDRESS_0, TEMP_BASE_ADDRESS);
321 pci_write_config32(dev, PCI_BASE_ADDRESS_1, 0);
322 pci_write_config8(dev, PCI_COMMAND, PCI_COMMAND_MEMORY);
323 write32(gctl, read32(gctl) | 0x1);
324 pci_write_config8(dev, PCI_COMMAND, 0);
325 pci_write_config32(dev, PCI_BASE_ADDRESS_0, 0);
326}
327
328static int place_device_in_d3hot(device_t dev)
329{
Lee Leahy1072e7d2017-03-16 17:35:32 -0700330 unsigned int offset;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700331
Lee Leahy32471722015-04-20 15:20:28 -0700332 printk(BIOS_SPEW, "%s/%s ( %s )\n",
333 __FILE__, __func__, dev_name(dev));
334
335 /*
336 * Parts of the HDA block are used for LPE audio as well.
337 * Therefore assume the HDA will never be put into D3Hot.
338 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700339 if (dev->path.pci.devfn == PCI_DEVFN(HDA_DEV, HDA_FUNC)) {
340 hda_work_around(dev);
341 return 0;
342 }
343
344 offset = pci_find_capability(dev, PCI_CAP_ID_PM);
345
346 if (offset != 0) {
347 set_d3hot_bits(dev, offset);
348 return 0;
349 }
350
Lee Leahy32471722015-04-20 15:20:28 -0700351 /*
352 * For some reason some of the devices don't have the capability
353 * pointer set correctly. Work around this by hard coding the offset.
354 */
355#define DEV_CASE(name_) \
356 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC)
357
Lee Leahy77ff0b12015-05-05 15:07:29 -0700358 switch (dev->path.pci.devfn) {
Lee Leahy32471722015-04-20 15:20:28 -0700359 DEV_CASE(SDIO) :
360 DEV_CASE(SD) :
361 DEV_CASE(MMC) :
362 DEV_CASE(LPE) :
363 DEV_CASE(SIO_DMA1) :
364 DEV_CASE(I2C1) :
365 DEV_CASE(I2C2) :
366 DEV_CASE(I2C3) :
367 DEV_CASE(I2C4) :
368 DEV_CASE(I2C5) :
369 DEV_CASE(I2C6) :
370 DEV_CASE(I2C7) :
371 DEV_CASE(SIO_DMA2) :
372 DEV_CASE(PWM1) :
373 DEV_CASE(PWM2) :
374 DEV_CASE(HSUART1) :
375 DEV_CASE(HSUART2) :
376 DEV_CASE(SPI) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700377 offset = 0x80;
378 break;
Lee Leahy32471722015-04-20 15:20:28 -0700379 DEV_CASE(SATA) :
380 DEV_CASE(XHCI) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700381 offset = 0x70;
382 break;
Lee Leahy32471722015-04-20 15:20:28 -0700383 DEV_CASE(HDA) :
384 DEV_CASE(SMBUS) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700385 offset = 0x50;
386 break;
Lee Leahy32471722015-04-20 15:20:28 -0700387 DEV_CASE(TXE) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700388 /* TXE cannot be placed in D3Hot. */
389 return 0;
Lee Leahy32471722015-04-20 15:20:28 -0700390 DEV_CASE(PCIE_PORT1) :
391 DEV_CASE(PCIE_PORT2) :
392 DEV_CASE(PCIE_PORT3) :
393 DEV_CASE(PCIE_PORT4) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700394 offset = 0xa0;
395 break;
396 }
397
398 if (offset != 0) {
399 set_d3hot_bits(dev, offset);
400 return 0;
401 }
402
403 return -1;
404}
405
406/* Common PCI device function disable. */
407void southcluster_enable_dev(device_t dev)
408{
409 uint32_t reg32;
410
Lee Leahy32471722015-04-20 15:20:28 -0700411 printk(BIOS_SPEW, "%s/%s ( %s )\n",
412 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700413 if (!dev->enabled) {
414 int slot = PCI_SLOT(dev->path.pci.devfn);
415 int func = PCI_FUNC(dev->path.pci.devfn);
416 printk(BIOS_DEBUG, "%s: Disabling device: %02x.%01x\n",
417 dev_path(dev), slot, func);
418
419 /* Ensure memory, io, and bus master are all disabled */
420 reg32 = pci_read_config32(dev, PCI_COMMAND);
421 reg32 &= ~(PCI_COMMAND_MASTER |
422 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
423 pci_write_config32(dev, PCI_COMMAND, reg32);
424
425 /* Place device in D3Hot */
426 if (place_device_in_d3hot(dev) < 0) {
427 printk(BIOS_WARNING,
428 "Could not place %02x.%01x into D3Hot. "
429 "Keeping device visible.\n", slot, func);
430 return;
431 }
432 /* Disable this device if possible */
433 sc_disable_devfn(dev);
434 } else {
435 /* Enable SERR */
436 reg32 = pci_read_config32(dev, PCI_COMMAND);
437 reg32 |= PCI_COMMAND_SERR;
438 pci_write_config32(dev, PCI_COMMAND, reg32);
439 }
440}
441
442static struct device_operations device_ops = {
443 .read_resources = sc_read_resources,
444 .set_resources = pci_dev_set_resources,
445 .enable_resources = NULL,
Lee Leahy2bc9cee2015-06-30 15:25:44 -0700446 .acpi_inject_dsdt_generator = southcluster_inject_dsdt,
447 .write_acpi_tables = southcluster_write_acpi_tables,
Lee Leahy77ff0b12015-05-05 15:07:29 -0700448 .init = sc_init,
449 .enable = southcluster_enable_dev,
Lee Leahy32471722015-04-20 15:20:28 -0700450 .scan_bus = scan_lpc_bus,
Lee Leahy77ff0b12015-05-05 15:07:29 -0700451 .ops_pci = &soc_pci_ops,
452};
453
454static const struct pci_driver southcluster __pci_driver = {
455 .ops = &device_ops,
456 .vendor = PCI_VENDOR_ID_INTEL,
457 .device = LPC_DEVID,
458};
459
460int __attribute__((weak)) mainboard_get_spi_config(struct spi_config *cfg)
461{
Lee Leahy32471722015-04-20 15:20:28 -0700462 printk(BIOS_SPEW, "%s/%s ( 0x%p )\n",
463 __FILE__, __func__, (void *)cfg);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700464 return -1;
465}
466
467static void finalize_chipset(void *unused)
468{
Lee Leahy32471722015-04-20 15:20:28 -0700469 void *bcr = (void *)(SPI_BASE_ADDRESS + BCR);
470 void *gcs = (void *)(RCBA_BASE_ADDRESS + GCS);
471 void *gen_pmcon2 = (void *)(PMC_BASE_ADDRESS + GEN_PMCON2);
472 void *etr = (void *)(PMC_BASE_ADDRESS + ETR);
473 uint8_t *spi = (uint8_t *)SPI_BASE_ADDRESS;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700474 struct spi_config cfg;
475
Lee Leahy32471722015-04-20 15:20:28 -0700476 printk(BIOS_SPEW, "%s/%s ( 0x%p )\n",
477 __FILE__, __func__, unused);
478
Lee Leahy77ff0b12015-05-05 15:07:29 -0700479 /* Set the lock enable on the BIOS control register. */
480 write32(bcr, read32(bcr) | BCR_LE);
481
482 /* Set BIOS lock down bit controlling boot block size and swapping. */
483 write32(gcs, read32(gcs) | BILD);
484
485 /* Lock sleep stretching policy and set SMI lock. */
486 write32(gen_pmcon2, read32(gen_pmcon2) | SLPSX_STR_POL_LOCK | SMI_LOCK);
487
488 /* Set the CF9 lock. */
489 write32(etr, read32(etr) | CF9LOCK);
490
491 if (mainboard_get_spi_config(&cfg) < 0) {
492 printk(BIOS_DEBUG, "No SPI lockdown configuration.\n");
493 } else {
494 write16(spi + PREOP, cfg.preop);
495 write16(spi + OPTYPE, cfg.optype);
496 write32(spi + OPMENU0, cfg.opmenu[0]);
497 write32(spi + OPMENU1, cfg.opmenu[1]);
498 write16(spi + HSFSTS, read16(spi + HSFSTS) | FLOCKDN);
499 write32(spi + UVSCC, cfg.uvscc);
500 write32(spi + LVSCC, cfg.lvscc | VCL);
501 }
Lee Leahy32471722015-04-20 15:20:28 -0700502 spi_init();
Hannah Williams3fa80a92017-03-22 16:33:36 -0700503 enable_serirq_quiet_mode();
Lee Leahy77ff0b12015-05-05 15:07:29 -0700504
505 printk(BIOS_DEBUG, "Finalizing SMM.\n");
506 outb(APM_CNT_FINALIZE, APM_CNT);
507}
508
Hannah Williams2cfdde72015-04-15 19:48:07 -0700509BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_EXIT, finalize_chipset, NULL);