blob: 4e4d157714b7187eada418b18768834afe04e0e7 [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>
Lee Leahy77ff0b12015-05-05 15:07:29 -070041
42static inline void
43add_mmio_resource(device_t dev, int i, unsigned long addr, unsigned long size)
44{
Lee Leahy32471722015-04-20 15:20:28 -070045 printk(BIOS_SPEW, "%s/%s ( %s, 0x%016lx, 0x%016lx )\n",
46 __FILE__, __func__, dev_name(dev), addr, size);
Lee Leahy77ff0b12015-05-05 15:07:29 -070047 mmio_resource(dev, i, addr >> 10, size >> 10);
48}
49
50static void sc_add_mmio_resources(device_t dev)
51{
Lee Leahy32471722015-04-20 15:20:28 -070052 printk(BIOS_SPEW, "%s/%s ( %s )\n",
53 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -070054 add_mmio_resource(dev, 0xfeb, ABORT_BASE_ADDRESS, ABORT_BASE_SIZE);
55 add_mmio_resource(dev, PBASE, PMC_BASE_ADDRESS, PMC_BASE_SIZE);
56 add_mmio_resource(dev, IOBASE, IO_BASE_ADDRESS, IO_BASE_SIZE);
57 add_mmio_resource(dev, IBASE, ILB_BASE_ADDRESS, ILB_BASE_SIZE);
58 add_mmio_resource(dev, SBASE, SPI_BASE_ADDRESS, SPI_BASE_SIZE);
59 add_mmio_resource(dev, MPBASE, MPHY_BASE_ADDRESS, MPHY_BASE_SIZE);
60 add_mmio_resource(dev, PUBASE, PUNIT_BASE_ADDRESS, PUNIT_BASE_SIZE);
61 add_mmio_resource(dev, RCBA, RCBA_BASE_ADDRESS, RCBA_BASE_SIZE);
62}
63
64/* Default IO range claimed by the LPC device. The upper bound is exclusive. */
65#define LPC_DEFAULT_IO_RANGE_LOWER 0
66#define LPC_DEFAULT_IO_RANGE_UPPER 0x1000
67
68static inline int io_range_in_default(int base, int size)
69{
70 /* Does it start above the range? */
71 if (base >= LPC_DEFAULT_IO_RANGE_UPPER)
72 return 0;
73
74 /* Is it entirely contained? */
75 if (base >= LPC_DEFAULT_IO_RANGE_LOWER &&
76 (base + size) < LPC_DEFAULT_IO_RANGE_UPPER)
77 return 1;
78
79 /* This will return not in range for partial overlaps. */
80 return 0;
81}
82
83/*
84 * Note: this function assumes there is no overlap with the default LPC device's
85 * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER.
86 */
87static void sc_add_io_resource(device_t dev, int base, int size, int index)
88{
89 struct resource *res;
90
Lee Leahy32471722015-04-20 15:20:28 -070091 printk(BIOS_SPEW, "%s/%s ( %s, 0x%08x, 0x%08x, 0x%08x )\n",
92 __FILE__, __func__, dev_name(dev), base, size, index);
93
Lee Leahy77ff0b12015-05-05 15:07:29 -070094 if (io_range_in_default(base, size))
95 return;
96
97 res = new_resource(dev, index);
98 res->base = base;
99 res->size = size;
100 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
101}
102
103static void sc_add_io_resources(device_t dev)
104{
105 struct resource *res;
106
Lee Leahy32471722015-04-20 15:20:28 -0700107 printk(BIOS_SPEW, "%s/%s ( %s )\n",
108 __FILE__, __func__, dev_name(dev));
109
Lee Leahy77ff0b12015-05-05 15:07:29 -0700110 /* Add the default claimed IO range for the LPC device. */
111 res = new_resource(dev, 0);
112 res->base = LPC_DEFAULT_IO_RANGE_LOWER;
113 res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER;
114 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
115
116 /* GPIO */
117 sc_add_io_resource(dev, GPIO_BASE_ADDRESS, 256, GBASE);
118
119 /* ACPI */
120 sc_add_io_resource(dev, ACPI_BASE_ADDRESS, 128, ABASE);
121}
122
123static void sc_read_resources(device_t dev)
124{
Lee Leahy32471722015-04-20 15:20:28 -0700125 printk(BIOS_SPEW, "%s/%s ( %s )\n",
126 __FILE__, __func__, dev_name(dev));
127
Lee Leahy77ff0b12015-05-05 15:07:29 -0700128 /* Get the normal PCI resources of this device. */
129 pci_dev_read_resources(dev);
130
131 /* Add non-standard MMIO resources. */
132 sc_add_mmio_resources(dev);
133
134 /* Add IO resources. */
135 sc_add_io_resources(dev);
136}
137
138static void sc_rtc_init(void)
139{
140 uint32_t gen_pmcon1;
141 int rtc_fail;
142 struct chipset_power_state *ps = cbmem_find(CBMEM_ID_POWER_STATE);
143
Lee Leahy32471722015-04-20 15:20:28 -0700144 printk(BIOS_SPEW, "%s/%s\n",
145 __FILE__, __func__);
146 if (ps != NULL)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700147 gen_pmcon1 = ps->gen_pmcon1;
Lee Leahy32471722015-04-20 15:20:28 -0700148 else
149 gen_pmcon1 = read32((void *)(PMC_BASE_ADDRESS + GEN_PMCON1));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700150
151 rtc_fail = !!(gen_pmcon1 & RPS);
152
Lee Leahy32471722015-04-20 15:20:28 -0700153 if (rtc_fail)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700154 printk(BIOS_DEBUG, "RTC failure.\n");
Lee Leahy77ff0b12015-05-05 15:07:29 -0700155
156 cmos_init(rtc_fail);
157}
158
Lee Leahy77ff0b12015-05-05 15:07:29 -0700159static void sc_init(device_t dev)
160{
161 int i;
Lee Leahy32471722015-04-20 15:20:28 -0700162 const unsigned long pr_base = ILB_BASE_ADDRESS + 0x08;
163 const unsigned long ir_base = ILB_BASE_ADDRESS + 0x20;
164 void *gen_pmcon1 = (void *)(PMC_BASE_ADDRESS + GEN_PMCON1);
165 void *actl = (void *)(ILB_BASE_ADDRESS + ACTL);
166 const struct soc_irq_route *ir = &global_soc_irq_route;
167 struct soc_intel_braswell_config *config = dev->chip_info;
168
169 printk(BIOS_SPEW, "%s/%s ( %s )\n",
170 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700171
172 /* Set up the PIRQ PIC routing based on static config. */
Lee Leahy32471722015-04-20 15:20:28 -0700173 for (i = 0; i < NUM_PIRQS; i++)
174 write8((void *)(pr_base + i*sizeof(ir->pic[i])),
175 ir->pic[i]);
176
Lee Leahy77ff0b12015-05-05 15:07:29 -0700177 /* Set up the per device PIRQ routing base on static config. */
Lee Leahy32471722015-04-20 15:20:28 -0700178 for (i = 0; i < NUM_IR_DEVS; i++)
179 write16((void *)(ir_base + i*sizeof(ir->pcidev[i])),
180 ir->pcidev[i]);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700181
182 /* Route SCI to IRQ9 */
183 write32(actl, (read32(actl) & ~SCIS_MASK) | SCIS_IRQ9);
184
185 sc_rtc_init();
186
187 if (config->disable_slp_x_stretch_sus_fail) {
188 printk(BIOS_DEBUG, "Disabling slp_x stretching.\n");
189 write32(gen_pmcon1,
190 read32(gen_pmcon1) | DIS_SLP_X_STRCH_SUS_UP);
191 } else {
192 write32(gen_pmcon1,
193 read32(gen_pmcon1) & ~DIS_SLP_X_STRCH_SUS_UP);
194 }
195
Lee Leahy77ff0b12015-05-05 15:07:29 -0700196}
197
198/*
199 * Common code for the south cluster devices.
200 */
201
Lee Leahy32471722015-04-20 15:20:28 -0700202/* Set bit in function disble register to hide this device. */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700203static void sc_disable_devfn(device_t dev)
204{
Lee Leahy32471722015-04-20 15:20:28 -0700205 void *func_dis = (void *)(PMC_BASE_ADDRESS + FUNC_DIS);
206 void *func_dis2 = (void *)(PMC_BASE_ADDRESS + FUNC_DIS2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700207 uint32_t mask = 0;
208 uint32_t mask2 = 0;
209
Lee Leahy32471722015-04-20 15:20:28 -0700210 printk(BIOS_SPEW, "%s/%s ( %s )\n",
211 __FILE__, __func__, dev_name(dev));
212
213#define SET_DIS_MASK(name_) \
214 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \
215 mask |= name_ ## _DIS
216#define SET_DIS_MASK2(name_) \
217 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \
218 mask2 |= name_ ## _DIS
219
Lee Leahy77ff0b12015-05-05 15:07:29 -0700220 switch (dev->path.pci.devfn) {
Lee Leahy32471722015-04-20 15:20:28 -0700221 SET_DIS_MASK(SDIO);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700222 break;
Lee Leahy32471722015-04-20 15:20:28 -0700223 SET_DIS_MASK(SD);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700224 break;
Lee Leahy32471722015-04-20 15:20:28 -0700225 SET_DIS_MASK(SATA);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700226 break;
Lee Leahy32471722015-04-20 15:20:28 -0700227 SET_DIS_MASK(XHCI);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700228 /* Disable super speed PHY when XHCI is not available. */
229 mask2 |= USH_SS_PHY_DIS;
230 break;
Lee Leahy32471722015-04-20 15:20:28 -0700231 SET_DIS_MASK(LPE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700232 break;
Lee Leahy32471722015-04-20 15:20:28 -0700233 SET_DIS_MASK(MMC);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700234 break;
Lee Leahy32471722015-04-20 15:20:28 -0700235 SET_DIS_MASK(SIO_DMA1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700236 break;
Lee Leahy32471722015-04-20 15:20:28 -0700237 SET_DIS_MASK(I2C1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700238 break;
Lee Leahy32471722015-04-20 15:20:28 -0700239 SET_DIS_MASK(I2C2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700240 break;
Lee Leahy32471722015-04-20 15:20:28 -0700241 SET_DIS_MASK(I2C3);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700242 break;
Lee Leahy32471722015-04-20 15:20:28 -0700243 SET_DIS_MASK(I2C4);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700244 break;
Lee Leahy32471722015-04-20 15:20:28 -0700245 SET_DIS_MASK(I2C5);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700246 break;
Lee Leahy32471722015-04-20 15:20:28 -0700247 SET_DIS_MASK(I2C6);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700248 break;
Lee Leahy32471722015-04-20 15:20:28 -0700249 SET_DIS_MASK(I2C7);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700250 break;
Lee Leahy32471722015-04-20 15:20:28 -0700251 SET_DIS_MASK(TXE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700252 break;
Lee Leahy32471722015-04-20 15:20:28 -0700253 SET_DIS_MASK(HDA);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700254 break;
Lee Leahy32471722015-04-20 15:20:28 -0700255 SET_DIS_MASK(PCIE_PORT1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700256 break;
Lee Leahy32471722015-04-20 15:20:28 -0700257 SET_DIS_MASK(PCIE_PORT2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700258 break;
Lee Leahy32471722015-04-20 15:20:28 -0700259 SET_DIS_MASK(PCIE_PORT3);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700260 break;
Lee Leahy32471722015-04-20 15:20:28 -0700261 SET_DIS_MASK(PCIE_PORT4);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700262 break;
Lee Leahy32471722015-04-20 15:20:28 -0700263 SET_DIS_MASK(SIO_DMA2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700264 break;
Lee Leahy32471722015-04-20 15:20:28 -0700265 SET_DIS_MASK(PWM1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700266 break;
Lee Leahy32471722015-04-20 15:20:28 -0700267 SET_DIS_MASK(PWM2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700268 break;
Lee Leahy32471722015-04-20 15:20:28 -0700269 SET_DIS_MASK(HSUART1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700270 break;
Lee Leahy32471722015-04-20 15:20:28 -0700271 SET_DIS_MASK(HSUART2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700272 break;
Lee Leahy32471722015-04-20 15:20:28 -0700273 SET_DIS_MASK(SPI);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700274 break;
Lee Leahy32471722015-04-20 15:20:28 -0700275 SET_DIS_MASK2(SMBUS);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700276 break;
277 }
278
279 if (mask != 0) {
280 write32(func_dis, read32(func_dis) | mask);
281 /* Ensure posted write hits. */
282 read32(func_dis);
283 }
284
285 if (mask2 != 0) {
286 write32(func_dis2, read32(func_dis2) | mask2);
287 /* Ensure posted write hits. */
288 read32(func_dis2);
289 }
290}
291
292static inline void set_d3hot_bits(device_t dev, int offset)
293{
294 uint32_t reg8;
Lee Leahy32471722015-04-20 15:20:28 -0700295
296 printk(BIOS_SPEW, "%s/%s ( %s, 0x%08x )\n",
297 __FILE__, __func__, dev_name(dev), offset);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700298 printk(BIOS_DEBUG, "Power management CAP offset 0x%x.\n", offset);
299 reg8 = pci_read_config8(dev, offset + 4);
300 reg8 |= 0x3;
301 pci_write_config8(dev, offset + 4, reg8);
302}
303
Lee Leahy32471722015-04-20 15:20:28 -0700304/*
305 * Parts of the audio subsystem are powered by the HDA device. Therefore, one
Lee Leahy77ff0b12015-05-05 15:07:29 -0700306 * cannot put HDA into D3Hot. Instead perform this workaround to make some of
Lee Leahy32471722015-04-20 15:20:28 -0700307 * the audio paths work for LPE audio.
308 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700309static void hda_work_around(device_t dev)
310{
Lee Leahy32471722015-04-20 15:20:28 -0700311 void *gctl = (void *)(TEMP_BASE_ADDRESS + 0x8);
312
313 printk(BIOS_SPEW, "%s/%s ( %s )\n",
314 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700315
316 /* Need to set magic register 0x43 to 0xd7 in config space. */
317 pci_write_config8(dev, 0x43, 0xd7);
318
Lee Leahy32471722015-04-20 15:20:28 -0700319 /*
320 * Need to set bit 0 of GCTL to take the device out of reset. However,
321 * that requires setting up the 64-bit BAR.
322 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700323 pci_write_config32(dev, PCI_BASE_ADDRESS_0, TEMP_BASE_ADDRESS);
324 pci_write_config32(dev, PCI_BASE_ADDRESS_1, 0);
325 pci_write_config8(dev, PCI_COMMAND, PCI_COMMAND_MEMORY);
326 write32(gctl, read32(gctl) | 0x1);
327 pci_write_config8(dev, PCI_COMMAND, 0);
328 pci_write_config32(dev, PCI_BASE_ADDRESS_0, 0);
329}
330
331static int place_device_in_d3hot(device_t dev)
332{
Lee Leahy1072e7d2017-03-16 17:35:32 -0700333 unsigned int offset;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700334
Lee Leahy32471722015-04-20 15:20:28 -0700335 printk(BIOS_SPEW, "%s/%s ( %s )\n",
336 __FILE__, __func__, dev_name(dev));
337
338 /*
339 * Parts of the HDA block are used for LPE audio as well.
340 * Therefore assume the HDA will never be put into D3Hot.
341 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700342 if (dev->path.pci.devfn == PCI_DEVFN(HDA_DEV, HDA_FUNC)) {
343 hda_work_around(dev);
344 return 0;
345 }
346
347 offset = pci_find_capability(dev, PCI_CAP_ID_PM);
348
349 if (offset != 0) {
350 set_d3hot_bits(dev, offset);
351 return 0;
352 }
353
Lee Leahy32471722015-04-20 15:20:28 -0700354 /*
355 * For some reason some of the devices don't have the capability
356 * pointer set correctly. Work around this by hard coding the offset.
357 */
358#define DEV_CASE(name_) \
359 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC)
360
Lee Leahy77ff0b12015-05-05 15:07:29 -0700361 switch (dev->path.pci.devfn) {
Lee Leahy32471722015-04-20 15:20:28 -0700362 DEV_CASE(SDIO) :
363 DEV_CASE(SD) :
364 DEV_CASE(MMC) :
365 DEV_CASE(LPE) :
366 DEV_CASE(SIO_DMA1) :
367 DEV_CASE(I2C1) :
368 DEV_CASE(I2C2) :
369 DEV_CASE(I2C3) :
370 DEV_CASE(I2C4) :
371 DEV_CASE(I2C5) :
372 DEV_CASE(I2C6) :
373 DEV_CASE(I2C7) :
374 DEV_CASE(SIO_DMA2) :
375 DEV_CASE(PWM1) :
376 DEV_CASE(PWM2) :
377 DEV_CASE(HSUART1) :
378 DEV_CASE(HSUART2) :
379 DEV_CASE(SPI) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700380 offset = 0x80;
381 break;
Lee Leahy32471722015-04-20 15:20:28 -0700382 DEV_CASE(SATA) :
383 DEV_CASE(XHCI) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700384 offset = 0x70;
385 break;
Lee Leahy32471722015-04-20 15:20:28 -0700386 DEV_CASE(HDA) :
387 DEV_CASE(SMBUS) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700388 offset = 0x50;
389 break;
Lee Leahy32471722015-04-20 15:20:28 -0700390 DEV_CASE(TXE) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700391 /* TXE cannot be placed in D3Hot. */
392 return 0;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700393 break;
Lee Leahy32471722015-04-20 15:20:28 -0700394 DEV_CASE(PCIE_PORT1) :
395 DEV_CASE(PCIE_PORT2) :
396 DEV_CASE(PCIE_PORT3) :
397 DEV_CASE(PCIE_PORT4) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700398 offset = 0xa0;
399 break;
400 }
401
402 if (offset != 0) {
403 set_d3hot_bits(dev, offset);
404 return 0;
405 }
406
407 return -1;
408}
409
410/* Common PCI device function disable. */
411void southcluster_enable_dev(device_t dev)
412{
413 uint32_t reg32;
414
Lee Leahy32471722015-04-20 15:20:28 -0700415 printk(BIOS_SPEW, "%s/%s ( %s )\n",
416 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700417 if (!dev->enabled) {
418 int slot = PCI_SLOT(dev->path.pci.devfn);
419 int func = PCI_FUNC(dev->path.pci.devfn);
420 printk(BIOS_DEBUG, "%s: Disabling device: %02x.%01x\n",
421 dev_path(dev), slot, func);
422
423 /* Ensure memory, io, and bus master are all disabled */
424 reg32 = pci_read_config32(dev, PCI_COMMAND);
425 reg32 &= ~(PCI_COMMAND_MASTER |
426 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
427 pci_write_config32(dev, PCI_COMMAND, reg32);
428
429 /* Place device in D3Hot */
430 if (place_device_in_d3hot(dev) < 0) {
431 printk(BIOS_WARNING,
432 "Could not place %02x.%01x into D3Hot. "
433 "Keeping device visible.\n", slot, func);
434 return;
435 }
436 /* Disable this device if possible */
437 sc_disable_devfn(dev);
438 } else {
439 /* Enable SERR */
440 reg32 = pci_read_config32(dev, PCI_COMMAND);
441 reg32 |= PCI_COMMAND_SERR;
442 pci_write_config32(dev, PCI_COMMAND, reg32);
443 }
444}
445
446static struct device_operations device_ops = {
447 .read_resources = sc_read_resources,
448 .set_resources = pci_dev_set_resources,
449 .enable_resources = NULL,
Lee Leahy2bc9cee2015-06-30 15:25:44 -0700450 .acpi_inject_dsdt_generator = southcluster_inject_dsdt,
451 .write_acpi_tables = southcluster_write_acpi_tables,
Lee Leahy77ff0b12015-05-05 15:07:29 -0700452 .init = sc_init,
453 .enable = southcluster_enable_dev,
Lee Leahy32471722015-04-20 15:20:28 -0700454 .scan_bus = scan_lpc_bus,
Lee Leahy77ff0b12015-05-05 15:07:29 -0700455 .ops_pci = &soc_pci_ops,
456};
457
458static const struct pci_driver southcluster __pci_driver = {
459 .ops = &device_ops,
460 .vendor = PCI_VENDOR_ID_INTEL,
461 .device = LPC_DEVID,
462};
463
464int __attribute__((weak)) mainboard_get_spi_config(struct spi_config *cfg)
465{
Lee Leahy32471722015-04-20 15:20:28 -0700466 printk(BIOS_SPEW, "%s/%s ( 0x%p )\n",
467 __FILE__, __func__, (void *)cfg);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700468 return -1;
469}
470
471static void finalize_chipset(void *unused)
472{
Lee Leahy32471722015-04-20 15:20:28 -0700473 void *bcr = (void *)(SPI_BASE_ADDRESS + BCR);
474 void *gcs = (void *)(RCBA_BASE_ADDRESS + GCS);
475 void *gen_pmcon2 = (void *)(PMC_BASE_ADDRESS + GEN_PMCON2);
476 void *etr = (void *)(PMC_BASE_ADDRESS + ETR);
477 uint8_t *spi = (uint8_t *)SPI_BASE_ADDRESS;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700478 struct spi_config cfg;
479
Lee Leahy32471722015-04-20 15:20:28 -0700480 printk(BIOS_SPEW, "%s/%s ( 0x%p )\n",
481 __FILE__, __func__, unused);
482
Lee Leahy77ff0b12015-05-05 15:07:29 -0700483 /* Set the lock enable on the BIOS control register. */
484 write32(bcr, read32(bcr) | BCR_LE);
485
486 /* Set BIOS lock down bit controlling boot block size and swapping. */
487 write32(gcs, read32(gcs) | BILD);
488
489 /* Lock sleep stretching policy and set SMI lock. */
490 write32(gen_pmcon2, read32(gen_pmcon2) | SLPSX_STR_POL_LOCK | SMI_LOCK);
491
492 /* Set the CF9 lock. */
493 write32(etr, read32(etr) | CF9LOCK);
494
495 if (mainboard_get_spi_config(&cfg) < 0) {
496 printk(BIOS_DEBUG, "No SPI lockdown configuration.\n");
497 } else {
498 write16(spi + PREOP, cfg.preop);
499 write16(spi + OPTYPE, cfg.optype);
500 write32(spi + OPMENU0, cfg.opmenu[0]);
501 write32(spi + OPMENU1, cfg.opmenu[1]);
502 write16(spi + HSFSTS, read16(spi + HSFSTS) | FLOCKDN);
503 write32(spi + UVSCC, cfg.uvscc);
504 write32(spi + LVSCC, cfg.lvscc | VCL);
505 }
Lee Leahy32471722015-04-20 15:20:28 -0700506 spi_init();
Lee Leahy77ff0b12015-05-05 15:07:29 -0700507
508 printk(BIOS_DEBUG, "Finalizing SMM.\n");
509 outb(APM_CNT_FINALIZE, APM_CNT);
510}
511
512BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, finalize_chipset, NULL);
513BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, finalize_chipset, NULL);