blob: e03312386aee858d59ca63af3b7b3996584d43a0 [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{
152 uint32_t gen_pmcon1;
153 int rtc_fail;
154 struct chipset_power_state *ps = cbmem_find(CBMEM_ID_POWER_STATE);
155
Lee Leahy32471722015-04-20 15:20:28 -0700156 printk(BIOS_SPEW, "%s/%s\n",
157 __FILE__, __func__);
158 if (ps != NULL)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700159 gen_pmcon1 = ps->gen_pmcon1;
Lee Leahy32471722015-04-20 15:20:28 -0700160 else
161 gen_pmcon1 = read32((void *)(PMC_BASE_ADDRESS + GEN_PMCON1));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700162
163 rtc_fail = !!(gen_pmcon1 & RPS);
164
Lee Leahy32471722015-04-20 15:20:28 -0700165 if (rtc_fail)
Lee Leahy77ff0b12015-05-05 15:07:29 -0700166 printk(BIOS_DEBUG, "RTC failure.\n");
Lee Leahy77ff0b12015-05-05 15:07:29 -0700167
168 cmos_init(rtc_fail);
169}
170
Lee Leahy77ff0b12015-05-05 15:07:29 -0700171static void sc_init(device_t dev)
172{
173 int i;
Lee Leahy32471722015-04-20 15:20:28 -0700174 const unsigned long pr_base = ILB_BASE_ADDRESS + 0x08;
175 const unsigned long ir_base = ILB_BASE_ADDRESS + 0x20;
176 void *gen_pmcon1 = (void *)(PMC_BASE_ADDRESS + GEN_PMCON1);
177 void *actl = (void *)(ILB_BASE_ADDRESS + ACTL);
178 const struct soc_irq_route *ir = &global_soc_irq_route;
179 struct soc_intel_braswell_config *config = dev->chip_info;
180
181 printk(BIOS_SPEW, "%s/%s ( %s )\n",
182 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700183
184 /* Set up the PIRQ PIC routing based on static config. */
Lee Leahy32471722015-04-20 15:20:28 -0700185 for (i = 0; i < NUM_PIRQS; i++)
186 write8((void *)(pr_base + i*sizeof(ir->pic[i])),
187 ir->pic[i]);
188
Lee Leahy77ff0b12015-05-05 15:07:29 -0700189 /* Set up the per device PIRQ routing base on static config. */
Lee Leahy32471722015-04-20 15:20:28 -0700190 for (i = 0; i < NUM_IR_DEVS; i++)
191 write16((void *)(ir_base + i*sizeof(ir->pcidev[i])),
192 ir->pcidev[i]);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700193
194 /* Route SCI to IRQ9 */
195 write32(actl, (read32(actl) & ~SCIS_MASK) | SCIS_IRQ9);
196
197 sc_rtc_init();
198
199 if (config->disable_slp_x_stretch_sus_fail) {
200 printk(BIOS_DEBUG, "Disabling slp_x stretching.\n");
201 write32(gen_pmcon1,
202 read32(gen_pmcon1) | DIS_SLP_X_STRCH_SUS_UP);
203 } else {
204 write32(gen_pmcon1,
205 read32(gen_pmcon1) & ~DIS_SLP_X_STRCH_SUS_UP);
206 }
207
Lee Leahy77ff0b12015-05-05 15:07:29 -0700208}
209
210/*
211 * Common code for the south cluster devices.
212 */
213
Lee Leahy32471722015-04-20 15:20:28 -0700214/* Set bit in function disble register to hide this device. */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700215static void sc_disable_devfn(device_t dev)
216{
Lee Leahy32471722015-04-20 15:20:28 -0700217 void *func_dis = (void *)(PMC_BASE_ADDRESS + FUNC_DIS);
218 void *func_dis2 = (void *)(PMC_BASE_ADDRESS + FUNC_DIS2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700219 uint32_t mask = 0;
220 uint32_t mask2 = 0;
221
Lee Leahy32471722015-04-20 15:20:28 -0700222 printk(BIOS_SPEW, "%s/%s ( %s )\n",
223 __FILE__, __func__, dev_name(dev));
224
225#define SET_DIS_MASK(name_) \
226 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \
227 mask |= name_ ## _DIS
228#define SET_DIS_MASK2(name_) \
229 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC): \
230 mask2 |= name_ ## _DIS
231
Lee Leahy77ff0b12015-05-05 15:07:29 -0700232 switch (dev->path.pci.devfn) {
Lee Leahy32471722015-04-20 15:20:28 -0700233 SET_DIS_MASK(SDIO);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700234 break;
Lee Leahy32471722015-04-20 15:20:28 -0700235 SET_DIS_MASK(SD);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700236 break;
Lee Leahy32471722015-04-20 15:20:28 -0700237 SET_DIS_MASK(SATA);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700238 break;
Lee Leahy32471722015-04-20 15:20:28 -0700239 SET_DIS_MASK(XHCI);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700240 /* Disable super speed PHY when XHCI is not available. */
241 mask2 |= USH_SS_PHY_DIS;
242 break;
Lee Leahy32471722015-04-20 15:20:28 -0700243 SET_DIS_MASK(LPE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700244 break;
Lee Leahy32471722015-04-20 15:20:28 -0700245 SET_DIS_MASK(MMC);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700246 break;
Lee Leahy32471722015-04-20 15:20:28 -0700247 SET_DIS_MASK(SIO_DMA1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700248 break;
Lee Leahy32471722015-04-20 15:20:28 -0700249 SET_DIS_MASK(I2C1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700250 break;
Lee Leahy32471722015-04-20 15:20:28 -0700251 SET_DIS_MASK(I2C2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700252 break;
Lee Leahy32471722015-04-20 15:20:28 -0700253 SET_DIS_MASK(I2C3);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700254 break;
Lee Leahy32471722015-04-20 15:20:28 -0700255 SET_DIS_MASK(I2C4);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700256 break;
Lee Leahy32471722015-04-20 15:20:28 -0700257 SET_DIS_MASK(I2C5);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700258 break;
Lee Leahy32471722015-04-20 15:20:28 -0700259 SET_DIS_MASK(I2C6);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700260 break;
Lee Leahy32471722015-04-20 15:20:28 -0700261 SET_DIS_MASK(I2C7);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700262 break;
Lee Leahy32471722015-04-20 15:20:28 -0700263 SET_DIS_MASK(TXE);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700264 break;
Lee Leahy32471722015-04-20 15:20:28 -0700265 SET_DIS_MASK(HDA);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700266 break;
Lee Leahy32471722015-04-20 15:20:28 -0700267 SET_DIS_MASK(PCIE_PORT1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700268 break;
Lee Leahy32471722015-04-20 15:20:28 -0700269 SET_DIS_MASK(PCIE_PORT2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700270 break;
Lee Leahy32471722015-04-20 15:20:28 -0700271 SET_DIS_MASK(PCIE_PORT3);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700272 break;
Lee Leahy32471722015-04-20 15:20:28 -0700273 SET_DIS_MASK(PCIE_PORT4);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700274 break;
Lee Leahy32471722015-04-20 15:20:28 -0700275 SET_DIS_MASK(SIO_DMA2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700276 break;
Lee Leahy32471722015-04-20 15:20:28 -0700277 SET_DIS_MASK(PWM1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700278 break;
Lee Leahy32471722015-04-20 15:20:28 -0700279 SET_DIS_MASK(PWM2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700280 break;
Lee Leahy32471722015-04-20 15:20:28 -0700281 SET_DIS_MASK(HSUART1);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700282 break;
Lee Leahy32471722015-04-20 15:20:28 -0700283 SET_DIS_MASK(HSUART2);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700284 break;
Lee Leahy32471722015-04-20 15:20:28 -0700285 SET_DIS_MASK(SPI);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700286 break;
Lee Leahy32471722015-04-20 15:20:28 -0700287 SET_DIS_MASK2(SMBUS);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700288 break;
289 }
290
291 if (mask != 0) {
292 write32(func_dis, read32(func_dis) | mask);
293 /* Ensure posted write hits. */
294 read32(func_dis);
295 }
296
297 if (mask2 != 0) {
298 write32(func_dis2, read32(func_dis2) | mask2);
299 /* Ensure posted write hits. */
300 read32(func_dis2);
301 }
302}
303
304static inline void set_d3hot_bits(device_t dev, int offset)
305{
306 uint32_t reg8;
Lee Leahy32471722015-04-20 15:20:28 -0700307
308 printk(BIOS_SPEW, "%s/%s ( %s, 0x%08x )\n",
309 __FILE__, __func__, dev_name(dev), offset);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700310 printk(BIOS_DEBUG, "Power management CAP offset 0x%x.\n", offset);
311 reg8 = pci_read_config8(dev, offset + 4);
312 reg8 |= 0x3;
313 pci_write_config8(dev, offset + 4, reg8);
314}
315
Lee Leahy32471722015-04-20 15:20:28 -0700316/*
317 * Parts of the audio subsystem are powered by the HDA device. Therefore, one
Lee Leahy77ff0b12015-05-05 15:07:29 -0700318 * cannot put HDA into D3Hot. Instead perform this workaround to make some of
Lee Leahy32471722015-04-20 15:20:28 -0700319 * the audio paths work for LPE audio.
320 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700321static void hda_work_around(device_t dev)
322{
Lee Leahy32471722015-04-20 15:20:28 -0700323 void *gctl = (void *)(TEMP_BASE_ADDRESS + 0x8);
324
325 printk(BIOS_SPEW, "%s/%s ( %s )\n",
326 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700327
328 /* Need to set magic register 0x43 to 0xd7 in config space. */
329 pci_write_config8(dev, 0x43, 0xd7);
330
Lee Leahy32471722015-04-20 15:20:28 -0700331 /*
332 * Need to set bit 0 of GCTL to take the device out of reset. However,
333 * that requires setting up the 64-bit BAR.
334 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700335 pci_write_config32(dev, PCI_BASE_ADDRESS_0, TEMP_BASE_ADDRESS);
336 pci_write_config32(dev, PCI_BASE_ADDRESS_1, 0);
337 pci_write_config8(dev, PCI_COMMAND, PCI_COMMAND_MEMORY);
338 write32(gctl, read32(gctl) | 0x1);
339 pci_write_config8(dev, PCI_COMMAND, 0);
340 pci_write_config32(dev, PCI_BASE_ADDRESS_0, 0);
341}
342
343static int place_device_in_d3hot(device_t dev)
344{
Lee Leahy1072e7d2017-03-16 17:35:32 -0700345 unsigned int offset;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700346
Lee Leahy32471722015-04-20 15:20:28 -0700347 printk(BIOS_SPEW, "%s/%s ( %s )\n",
348 __FILE__, __func__, dev_name(dev));
349
350 /*
351 * Parts of the HDA block are used for LPE audio as well.
352 * Therefore assume the HDA will never be put into D3Hot.
353 */
Lee Leahy77ff0b12015-05-05 15:07:29 -0700354 if (dev->path.pci.devfn == PCI_DEVFN(HDA_DEV, HDA_FUNC)) {
355 hda_work_around(dev);
356 return 0;
357 }
358
359 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
Lee Leahy32471722015-04-20 15:20:28 -0700366 /*
367 * For some reason some of the devices don't have the capability
368 * pointer set correctly. Work around this by hard coding the offset.
369 */
370#define DEV_CASE(name_) \
371 case PCI_DEVFN(name_ ## _DEV, name_ ## _FUNC)
372
Lee Leahy77ff0b12015-05-05 15:07:29 -0700373 switch (dev->path.pci.devfn) {
Lee Leahy32471722015-04-20 15:20:28 -0700374 DEV_CASE(SDIO) :
375 DEV_CASE(SD) :
376 DEV_CASE(MMC) :
377 DEV_CASE(LPE) :
378 DEV_CASE(SIO_DMA1) :
379 DEV_CASE(I2C1) :
380 DEV_CASE(I2C2) :
381 DEV_CASE(I2C3) :
382 DEV_CASE(I2C4) :
383 DEV_CASE(I2C5) :
384 DEV_CASE(I2C6) :
385 DEV_CASE(I2C7) :
386 DEV_CASE(SIO_DMA2) :
387 DEV_CASE(PWM1) :
388 DEV_CASE(PWM2) :
389 DEV_CASE(HSUART1) :
390 DEV_CASE(HSUART2) :
391 DEV_CASE(SPI) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700392 offset = 0x80;
393 break;
Lee Leahy32471722015-04-20 15:20:28 -0700394 DEV_CASE(SATA) :
395 DEV_CASE(XHCI) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700396 offset = 0x70;
397 break;
Lee Leahy32471722015-04-20 15:20:28 -0700398 DEV_CASE(HDA) :
399 DEV_CASE(SMBUS) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700400 offset = 0x50;
401 break;
Lee Leahy32471722015-04-20 15:20:28 -0700402 DEV_CASE(TXE) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700403 /* TXE cannot be placed in D3Hot. */
404 return 0;
Lee Leahy32471722015-04-20 15:20:28 -0700405 DEV_CASE(PCIE_PORT1) :
406 DEV_CASE(PCIE_PORT2) :
407 DEV_CASE(PCIE_PORT3) :
408 DEV_CASE(PCIE_PORT4) :
Lee Leahy77ff0b12015-05-05 15:07:29 -0700409 offset = 0xa0;
410 break;
411 }
412
413 if (offset != 0) {
414 set_d3hot_bits(dev, offset);
415 return 0;
416 }
417
418 return -1;
419}
420
421/* Common PCI device function disable. */
422void southcluster_enable_dev(device_t dev)
423{
424 uint32_t reg32;
425
Lee Leahy32471722015-04-20 15:20:28 -0700426 printk(BIOS_SPEW, "%s/%s ( %s )\n",
427 __FILE__, __func__, dev_name(dev));
Lee Leahy77ff0b12015-05-05 15:07:29 -0700428 if (!dev->enabled) {
429 int slot = PCI_SLOT(dev->path.pci.devfn);
430 int func = PCI_FUNC(dev->path.pci.devfn);
431 printk(BIOS_DEBUG, "%s: Disabling device: %02x.%01x\n",
432 dev_path(dev), slot, func);
433
434 /* Ensure memory, io, and bus master are all disabled */
435 reg32 = pci_read_config32(dev, PCI_COMMAND);
436 reg32 &= ~(PCI_COMMAND_MASTER |
437 PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
438 pci_write_config32(dev, PCI_COMMAND, reg32);
439
440 /* Place device in D3Hot */
441 if (place_device_in_d3hot(dev) < 0) {
442 printk(BIOS_WARNING,
443 "Could not place %02x.%01x into D3Hot. "
444 "Keeping device visible.\n", slot, func);
445 return;
446 }
447 /* Disable this device if possible */
448 sc_disable_devfn(dev);
449 } else {
450 /* Enable SERR */
451 reg32 = pci_read_config32(dev, PCI_COMMAND);
452 reg32 |= PCI_COMMAND_SERR;
453 pci_write_config32(dev, PCI_COMMAND, reg32);
454 }
455}
456
457static struct device_operations device_ops = {
458 .read_resources = sc_read_resources,
459 .set_resources = pci_dev_set_resources,
460 .enable_resources = NULL,
Lee Leahy2bc9cee2015-06-30 15:25:44 -0700461 .acpi_inject_dsdt_generator = southcluster_inject_dsdt,
462 .write_acpi_tables = southcluster_write_acpi_tables,
Lee Leahy77ff0b12015-05-05 15:07:29 -0700463 .init = sc_init,
464 .enable = southcluster_enable_dev,
Lee Leahy32471722015-04-20 15:20:28 -0700465 .scan_bus = scan_lpc_bus,
Lee Leahy77ff0b12015-05-05 15:07:29 -0700466 .ops_pci = &soc_pci_ops,
467};
468
469static const struct pci_driver southcluster __pci_driver = {
470 .ops = &device_ops,
471 .vendor = PCI_VENDOR_ID_INTEL,
472 .device = LPC_DEVID,
473};
474
475int __attribute__((weak)) mainboard_get_spi_config(struct spi_config *cfg)
476{
Lee Leahy32471722015-04-20 15:20:28 -0700477 printk(BIOS_SPEW, "%s/%s ( 0x%p )\n",
478 __FILE__, __func__, (void *)cfg);
Lee Leahy77ff0b12015-05-05 15:07:29 -0700479 return -1;
480}
481
482static void finalize_chipset(void *unused)
483{
Lee Leahy32471722015-04-20 15:20:28 -0700484 void *bcr = (void *)(SPI_BASE_ADDRESS + BCR);
485 void *gcs = (void *)(RCBA_BASE_ADDRESS + GCS);
486 void *gen_pmcon2 = (void *)(PMC_BASE_ADDRESS + GEN_PMCON2);
487 void *etr = (void *)(PMC_BASE_ADDRESS + ETR);
488 uint8_t *spi = (uint8_t *)SPI_BASE_ADDRESS;
Lee Leahy77ff0b12015-05-05 15:07:29 -0700489 struct spi_config cfg;
490
Lee Leahy32471722015-04-20 15:20:28 -0700491 printk(BIOS_SPEW, "%s/%s ( 0x%p )\n",
492 __FILE__, __func__, unused);
493
Lee Leahy77ff0b12015-05-05 15:07:29 -0700494 /* Set the lock enable on the BIOS control register. */
495 write32(bcr, read32(bcr) | BCR_LE);
496
497 /* Set BIOS lock down bit controlling boot block size and swapping. */
498 write32(gcs, read32(gcs) | BILD);
499
500 /* Lock sleep stretching policy and set SMI lock. */
501 write32(gen_pmcon2, read32(gen_pmcon2) | SLPSX_STR_POL_LOCK | SMI_LOCK);
502
503 /* Set the CF9 lock. */
504 write32(etr, read32(etr) | CF9LOCK);
505
506 if (mainboard_get_spi_config(&cfg) < 0) {
507 printk(BIOS_DEBUG, "No SPI lockdown configuration.\n");
508 } else {
509 write16(spi + PREOP, cfg.preop);
510 write16(spi + OPTYPE, cfg.optype);
511 write32(spi + OPMENU0, cfg.opmenu[0]);
512 write32(spi + OPMENU1, cfg.opmenu[1]);
513 write16(spi + HSFSTS, read16(spi + HSFSTS) | FLOCKDN);
514 write32(spi + UVSCC, cfg.uvscc);
515 write32(spi + LVSCC, cfg.lvscc | VCL);
516 }
Lee Leahy32471722015-04-20 15:20:28 -0700517 spi_init();
Hannah Williams3fa80a92017-03-22 16:33:36 -0700518 enable_serirq_quiet_mode();
Lee Leahy77ff0b12015-05-05 15:07:29 -0700519
520 printk(BIOS_DEBUG, "Finalizing SMM.\n");
521 outb(APM_CNT_FINALIZE, APM_CNT);
522}
523
Hannah Williams2cfdde72015-04-15 19:48:07 -0700524BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_EXIT, finalize_chipset, NULL);