blob: dadbaffcafe77ccd2bea4cd71f74cdebb57f4625 [file] [log] [blame]
Duncan Lauriec88c54c2014-04-30 16:36:13 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
5 * Copyright (C) 2014 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.
Duncan Lauriec88c54c2014-04-30 16:36:13 -070015 */
16
17#include <console/console.h>
18#include <delay.h>
19#include <device/device.h>
20#include <device/pci.h>
21#include <device/pci_ids.h>
22#include <pc80/mc146818rtc.h>
23#include <pc80/isa-dma.h>
24#include <pc80/i8259.h>
25#include <arch/io.h>
26#include <arch/ioapic.h>
27#include <arch/acpi.h>
28#include <cpu/cpu.h>
29#include <cpu/x86/smm.h>
30#include <cbmem.h>
31#include <reg_script.h>
32#include <string.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070033#include <soc/gpio.h>
34#include <soc/iobp.h>
35#include <soc/iomap.h>
36#include <soc/lpc.h>
37#include <soc/nvs.h>
38#include <soc/pch.h>
39#include <soc/pci_devs.h>
40#include <soc/pm.h>
41#include <soc/ramstage.h>
42#include <soc/rcba.h>
43#include <soc/intel/broadwell/chip.h>
Vladimir Serbinenkob219da82014-11-09 03:29:30 +010044#include <arch/acpi.h>
45#include <arch/acpigen.h>
46#include <cpu/cpu.h>
Furquan Shaikh2a12e2e2016-07-25 11:48:03 -070047#include <vboot/vbnv.h>
48#include <vboot/vbnv_layout.h>
Duncan Laurie35dc00f2015-01-18 14:06:42 -080049
Duncan Lauriec88c54c2014-04-30 16:36:13 -070050static void pch_enable_ioapic(struct device *dev)
51{
52 u32 reg32;
53
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080054 set_ioapic_id(VIO_APIC_VADDR, 0x02);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070055
56 /* affirm full set of redirection table entries ("write once") */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080057 reg32 = io_apic_read(VIO_APIC_VADDR, 0x01);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070058
59 /* PCH-LP has 39 redirection entries */
60 reg32 &= ~0x00ff0000;
61 reg32 |= 0x00270000;
62
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080063 io_apic_write(VIO_APIC_VADDR, 0x01, reg32);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070064
65 /*
66 * Select Boot Configuration register (0x03) and
67 * use Processor System Bus (0x01) to deliver interrupts.
68 */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080069 io_apic_write(VIO_APIC_VADDR, 0x03, 0x01);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070070}
71
72/* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control
73 * 0x00 - 0000 = Reserved
74 * 0x01 - 0001 = Reserved
75 * 0x02 - 0010 = Reserved
76 * 0x03 - 0011 = IRQ3
77 * 0x04 - 0100 = IRQ4
78 * 0x05 - 0101 = IRQ5
79 * 0x06 - 0110 = IRQ6
80 * 0x07 - 0111 = IRQ7
81 * 0x08 - 1000 = Reserved
82 * 0x09 - 1001 = IRQ9
83 * 0x0A - 1010 = IRQ10
84 * 0x0B - 1011 = IRQ11
85 * 0x0C - 1100 = IRQ12
86 * 0x0D - 1101 = Reserved
87 * 0x0E - 1110 = IRQ14
88 * 0x0F - 1111 = IRQ15
89 * PIRQ[n]_ROUT[7] - PIRQ Routing Control
90 * 0x80 - The PIRQ is not routed.
91 */
92
93static void pch_pirq_init(device_t dev)
94{
95 device_t irq_dev;
96 config_t *config = dev->chip_info;
97
98 pci_write_config8(dev, PIRQA_ROUT, config->pirqa_routing);
99 pci_write_config8(dev, PIRQB_ROUT, config->pirqb_routing);
100 pci_write_config8(dev, PIRQC_ROUT, config->pirqc_routing);
101 pci_write_config8(dev, PIRQD_ROUT, config->pirqd_routing);
102
103 pci_write_config8(dev, PIRQE_ROUT, config->pirqe_routing);
104 pci_write_config8(dev, PIRQF_ROUT, config->pirqf_routing);
105 pci_write_config8(dev, PIRQG_ROUT, config->pirqg_routing);
106 pci_write_config8(dev, PIRQH_ROUT, config->pirqh_routing);
107
Elyes HAOUAS4a83f1c2016-08-25 21:07:59 +0200108 for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) {
Lee Leahy26b7cd02017-03-16 18:47:55 -0700109 u8 int_pin = 0, int_line = 0;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700110
111 if (!irq_dev->enabled || irq_dev->path.type != DEVICE_PATH_PCI)
112 continue;
113
114 int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
115
116 switch (int_pin) {
Lee Leahy8a9c7dc2017-03-17 10:43:25 -0700117 case 1: /* INTA# */
118 int_line = config->pirqa_routing;
119 break;
120 case 2: /* INTB# */
121 int_line = config->pirqb_routing;
122 break;
123 case 3: /* INTC# */
124 int_line = config->pirqc_routing;
125 break;
126 case 4: /* INTD# */
127 int_line = config->pirqd_routing;
128 break;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700129 }
130
131 if (!int_line)
132 continue;
133
134 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line);
135 }
136}
137
138static void pch_power_options(device_t dev)
139{
140 u16 reg16;
141 const char *state;
142 /* Get the chip configuration */
143 config_t *config = dev->chip_info;
Lee Leahy26b7cd02017-03-16 18:47:55 -0700144 int pwr_on = CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700145
146 /* Which state do we want to goto after g3 (power restored)?
147 * 0 == S0 Full On
148 * 1 == S5 Soft Off
149 *
150 * If the option is not existent (Laptops), use Kconfig setting.
151 */
152 get_option(&pwr_on, "power_on_after_fail");
153
154 reg16 = pci_read_config16(dev, GEN_PMCON_3);
155 reg16 &= 0xfffe;
156 switch (pwr_on) {
157 case MAINBOARD_POWER_OFF:
158 reg16 |= 1;
159 state = "off";
160 break;
161 case MAINBOARD_POWER_ON:
162 reg16 &= ~1;
163 state = "on";
164 break;
165 case MAINBOARD_POWER_KEEP:
166 reg16 &= ~1;
167 state = "state keep";
168 break;
169 default:
170 state = "undefined";
171 }
172 pci_write_config16(dev, GEN_PMCON_3, reg16);
173 printk(BIOS_INFO, "Set power %s after power failure.\n", state);
174
175 /* GPE setup based on device tree configuration */
176 enable_all_gpe(config->gpe0_en_1, config->gpe0_en_2,
177 config->gpe0_en_3, config->gpe0_en_4);
178
179 /* SMI setup based on device tree configuration */
180 enable_alt_smi(config->alt_gp_smi_en);
181}
182
183static void pch_rtc_init(struct device *dev)
184{
185 u8 reg8;
186 int rtc_failed;
187
188 reg8 = pci_read_config8(dev, GEN_PMCON_3);
189 rtc_failed = reg8 & RTC_BATTERY_DEAD;
190 if (rtc_failed) {
191 reg8 &= ~RTC_BATTERY_DEAD;
192 pci_write_config8(dev, GEN_PMCON_3, reg8);
193 printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed);
194 }
195
Furquan Shaikh0faf4012016-07-27 14:31:16 -0700196 if (IS_ENABLED(CONFIG_VBOOT_VBNV_CMOS))
197 init_vbnv_cmos(rtc_failed);
198 else
199 cmos_init(rtc_failed);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700200}
201
202static const struct reg_script pch_misc_init_script[] = {
203 /* Setup SLP signal assertion, SLP_S4=4s, SLP_S3=50ms */
204 REG_PCI_RMW16(GEN_PMCON_3, ~((3 << 4)|(1 << 10)),
205 (1 << 3)|(1 << 11)|(1 << 12)),
206 /* Prepare sleep mode */
207 REG_IO_RMW32(ACPI_BASE_ADDRESS + PM1_CNT, ~SLP_TYP, SCI_EN),
208 /* Setup NMI on errors, disable SERR */
209 REG_IO_RMW8(0x61, ~0xf0, (1 << 2)),
210 /* Disable NMI sources */
211 REG_IO_OR8(0x70, (1 << 7)),
212 /* Indicate DRAM init done for MRC */
213 REG_PCI_OR8(GEN_PMCON_2, (1 << 7)),
214 /* Enable BIOS updates outside of SMM */
215 REG_PCI_RMW8(0xdc, ~(1 << 5), 0),
216 /* Clear status bits to prevent unexpected wake */
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700217 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x3310, 0x0000002f),
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700218 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x3f02, ~0x0000000f, 0),
Kenji Chen074a0282014-09-20 01:39:20 +0800219 /* Enable PCIe Releaxed Order */
220 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2314, (1 << 31) | (1 << 7)),
221 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x1114, (1 << 15) | (1 << 14)),
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700222 /* Setup SERIRQ, enable continuous mode */
223 REG_PCI_OR8(SERIRQ_CNTL, (1 << 7) | (1 << 6)),
224#if !CONFIG_SERIRQ_CONTINUOUS_MODE
225 REG_PCI_RMW8(SERIRQ_CNTL, ~(1 << 6), 0),
226#endif
227 REG_SCRIPT_END
228};
229
230/* Magic register settings for power management */
231static const struct reg_script pch_pm_init_script[] = {
232 REG_PCI_WRITE8(0xa9, 0x46),
233 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x232c, ~1, 0),
234 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x1100, 0x0000c13f),
235 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x2320, ~0x60, 0x10),
236 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3314, 0x00012fff),
237 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x3318, ~0x000f0330, 0x0dcf0400),
238 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3324, 0x04000000),
239 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3368, 0x00041400),
240 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3388, 0x3f8ddbff),
241 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33ac, 0x00007001),
242 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33b0, 0x00181900),
243 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33c0, 0x00060A00),
244 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33d0, 0x06200840),
245 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a28, 0x01010101),
246 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a2c, 0x040c0404),
247 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a9c, 0x9000000a),
248 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b1c, 0x03808033),
249 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b34, 0x80000009),
250 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3348, 0x022ddfff),
251 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x334c, 0x00000001),
252 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3358, 0x0001c000),
253 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3380, 0x3f8ddbff),
254 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3384, 0x0001c7e1),
255 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x338c, 0x0001c7e1),
256 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3398, 0x0001c000),
257 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33a8, 0x00181900),
258 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33dc, 0x00080000),
259 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33e0, 0x00000001),
260 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a20, 0x0000040c),
261 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a24, 0x01010101),
262 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a30, 0x01010101),
263 REG_PCI_RMW32(0xac, ~0x00200000, 0),
264 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x0410, 0x00000003),
265 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2618, 0x08000000),
266 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2300, 0x00000002),
267 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2600, 0x00000008),
268 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33b4, 0x00007001),
269 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3350, 0x022ddfff),
270 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3354, 0x00000001),
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700271 /* Power Optimizer */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700272 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33d4, 0x08000000),
Matt DeVillierc97e0422017-02-16 11:36:16 -0600273 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33c8, 0x00000080),
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700274 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b10, 0x0000883c),
275 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b14, 0x1e0a4616),
276 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b24, 0x40000005),
277 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b20, 0x0005db01),
278 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a80, 0x05145005),
279 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a84, 0x00001005),
280 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33d4, 0x2fff2fb1),
281 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33c8, 0x00008000),
282 REG_SCRIPT_END
283};
284
285static void pch_enable_mphy(void)
286{
287 u32 gpio71_native = gpio_is_native(71);
288 u32 data_and = 0xffffffff;
289 u32 data_or = (1 << 14) | (1 << 13) | (1 << 12);
290
291 if (gpio71_native) {
292 data_or |= (1 << 0);
293 if (pch_is_wpt()) {
294 data_and &= ~((1 << 7) | (1 << 6) | (1 << 3));
295 data_or |= (1 << 5) | (1 << 4);
296
297 if (pch_is_wpt_ulx()) {
298 /* Check if SATA and USB3 MPHY are enabled */
299 u32 strap19 = pch_read_soft_strap(19);
300 strap19 &= ((1 << 31) | (1 << 30));
301 strap19 >>= 30;
302 if (strap19 == 3) {
303 data_or |= (1 << 3);
304 printk(BIOS_DEBUG, "Enable ULX MPHY PG "
305 "control in single domain\n");
306 } else if (strap19 == 0) {
307 printk(BIOS_DEBUG, "Enable ULX MPHY PG "
308 "control in split domains\n");
309 } else {
310 printk(BIOS_DEBUG, "Invalid PCH Soft "
311 "Strap 19 configuration\n");
312 }
313 } else {
314 data_or |= (1 << 3);
315 }
316 }
317 }
318
319 pch_iobp_update(0xCF000000, data_and, data_or);
320}
321
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700322static void pch_init_deep_sx(struct device *dev)
323{
324 config_t *config = dev->chip_info;
325
326 if (config->deep_sx_enable_ac) {
327 RCBA32_OR(DEEP_S3_POL, DEEP_S3_EN_AC);
328 RCBA32_OR(DEEP_S5_POL, DEEP_S5_EN_AC);
329 }
330
331 if (config->deep_sx_enable_dc) {
332 RCBA32_OR(DEEP_S3_POL, DEEP_S3_EN_DC);
333 RCBA32_OR(DEEP_S5_POL, DEEP_S5_EN_DC);
334 }
335
336 if (config->deep_sx_enable_ac || config->deep_sx_enable_dc)
337 RCBA32_OR(DEEP_SX_CONFIG,
338 DEEP_SX_WAKE_PIN_EN | DEEP_SX_GP27_PIN_EN);
339}
340
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700341/* Power Management init */
342static void pch_pm_init(struct device *dev)
343{
344 printk(BIOS_DEBUG, "PCH PM init\n");
345
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700346 pch_init_deep_sx(dev);
347
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700348 pch_enable_mphy();
349
350 reg_script_run_on_dev(dev, pch_pm_init_script);
351
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700352 if (pch_is_wpt()) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700353 RCBA32_OR(0x33e0, (1 << 4) | (1 << 1));
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700354 RCBA32_OR(0x2b1c, (1 << 22) | (1 << 14) | (1 << 13));
355 RCBA32(0x33e4) = 0x16bf0002;
356 RCBA32_OR(0x33e4, 0x1);
357 }
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700358
359 pch_iobp_update(0xCA000000, ~0UL, 0x00000009);
360
361 /* Set RCBA 0x2b1c[29]=1 if DSP disabled */
362 if (RCBA32(FD) & PCH_DISABLE_ADSPD)
363 RCBA32_OR(0x2b1c, (1 << 29));
364
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700365}
366
367static void pch_cg_init(device_t dev)
368{
369 u32 reg32;
370 u16 reg16;
371
372 /* DMI */
373 RCBA32_OR(0x2234, 0xf);
374
375 reg16 = pci_read_config16(dev, GEN_PMCON_1);
376 reg16 &= ~(1 << 10); /* Disable BIOS_PCI_EXP_EN for native PME */
377 if (pch_is_wpt())
378 reg16 &= ~(1 << 11);
379 else
380 reg16 |= (1 << 11);
381 reg16 |= (1 << 5) | (1 << 6) | (1 << 7) | (1 << 12);
382 reg16 |= (1 << 2); // PCI CLKRUN# Enable
383 pci_write_config16(dev, GEN_PMCON_1, reg16);
384
385 /*
386 * RCBA + 0x2614[27:25,14:13,10,8] = 101,11,1,1
387 * RCBA + 0x2614[23:16] = 0x20
388 * RCBA + 0x2614[30:28] = 0x0
389 * RCBA + 0x2614[26] = 1 (IF 0:2.0@0x08 >= 0x0b)
390 */
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700391 RCBA32_AND_OR(0x2614, ~0x64ff0000, 0x0a206500);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700392
393 /* Check for 0:2.0@0x08 >= 0x0b */
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700394 if (pch_is_wpt() || pci_read_config8(SA_DEV_IGD, 0x8) >= 0x0b)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700395 RCBA32_OR(0x2614, (1 << 26));
396
397 RCBA32_OR(0x900, 0x0000031f);
398
399 reg32 = RCBA32(CG);
400 if (RCBA32(0x3454) & (1 << 4))
401 reg32 &= ~(1 << 29); // LPC Dynamic
402 else
403 reg32 |= (1 << 29); // LPC Dynamic
404 reg32 |= (1 << 31); // LP LPC
405 reg32 |= (1 << 30); // LP BLA
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700406 if (RCBA32(0x3454) & (1 << 4))
407 reg32 &= ~(1 << 29);
408 else
409 reg32 |= (1 << 29);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700410 reg32 |= (1 << 28); // GPIO Dynamic
411 reg32 |= (1 << 27); // HPET Dynamic
412 reg32 |= (1 << 26); // Generic Platform Event Clock
413 if (RCBA32(BUC) & PCH_DISABLE_GBE)
414 reg32 |= (1 << 23); // GbE Static
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700415 if (RCBA32(FD) & PCH_DISABLE_HD_AUDIO)
416 reg32 |= (1 << 21); // HDA Static
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700417 reg32 |= (1 << 22); // HDA Dynamic
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700418 RCBA32(CG) = reg32;
419
420 /* PCH-LP LPC */
421 if (pch_is_wpt())
422 RCBA32_AND_OR(0x3434, ~0x1f, 0x17);
423 else
424 RCBA32_OR(0x3434, 0x7);
425
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700426 /* SPI */
427 RCBA32_OR(0x38c0, 0x3c07);
428
429 pch_iobp_update(0xCE00C000, ~1UL, 0x00000000);
430}
431
432static void pch_set_acpi_mode(void)
433{
434#if CONFIG_HAVE_SMI_HANDLER
Kyösti Mälkki9e94dbf2015-01-08 20:03:18 +0200435 if (!acpi_is_wakeup_s3()) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700436 printk(BIOS_DEBUG, "Disabling ACPI via APMC:\n");
437 outb(APM_CNT_ACPI_DISABLE, APM_CNT);
438 printk(BIOS_DEBUG, "done.\n");
439 }
440#endif /* CONFIG_HAVE_SMI_HANDLER */
441}
442
443static void lpc_init(struct device *dev)
444{
445 /* Legacy initialization */
446 isa_dma_init();
447 pch_rtc_init(dev);
448 reg_script_run_on_dev(dev, pch_misc_init_script);
449
450 /* Interrupt configuration */
451 pch_enable_ioapic(dev);
452 pch_pirq_init(dev);
453 setup_i8259();
454 i8259_configure_irq_trigger(9, 1);
455
456 /* Initialize power management */
457 pch_power_options(dev);
458 pch_pm_init(dev);
459 pch_cg_init(dev);
460
461 pch_set_acpi_mode();
462}
463
464static void pch_lpc_add_mmio_resources(device_t dev)
465{
466 u32 reg;
467 struct resource *res;
468 const u32 default_decode_base = IO_APIC_ADDR;
469
470 /*
471 * Just report all resources from IO-APIC base to 4GiB. Don't mark
472 * them reserved as that may upset the OS if this range is marked
473 * as reserved in the e820.
474 */
475 res = new_resource(dev, OIC);
476 res->base = default_decode_base;
477 res->size = 0 - default_decode_base;
478 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
479
480 /* RCBA */
481 if (RCBA_BASE_ADDRESS < default_decode_base) {
482 res = new_resource(dev, RCBA);
483 res->base = RCBA_BASE_ADDRESS;
484 res->size = 16 * 1024;
485 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED |
Lee Leahy26b7cd02017-03-16 18:47:55 -0700486 IORESOURCE_FIXED | IORESOURCE_RESERVE;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700487 }
488
489 /* Check LPC Memory Decode register. */
490 reg = pci_read_config32(dev, LGMR);
491 if (reg & 1) {
492 reg &= ~0xffff;
493 if (reg < default_decode_base) {
494 res = new_resource(dev, LGMR);
495 res->base = reg;
496 res->size = 16 * 1024;
497 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED |
Lee Leahy26b7cd02017-03-16 18:47:55 -0700498 IORESOURCE_FIXED | IORESOURCE_RESERVE;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700499 }
500 }
501}
502
503/* Default IO range claimed by the LPC device. The upper bound is exclusive. */
504#define LPC_DEFAULT_IO_RANGE_LOWER 0
505#define LPC_DEFAULT_IO_RANGE_UPPER 0x1000
506
507static inline int pch_io_range_in_default(u16 base, u16 size)
508{
509 /* Does it start above the range? */
510 if (base >= LPC_DEFAULT_IO_RANGE_UPPER)
511 return 0;
512
513 /* Is it entirely contained? */
514 if (base >= LPC_DEFAULT_IO_RANGE_LOWER &&
515 (base + size) < LPC_DEFAULT_IO_RANGE_UPPER)
516 return 1;
517
518 /* This will return not in range for partial overlaps. */
519 return 0;
520}
521
522/*
523 * Note: this function assumes there is no overlap with the default LPC device's
524 * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER.
525 */
526static void pch_lpc_add_io_resource(device_t dev, u16 base, u16 size, int index)
527{
528 struct resource *res;
529
530 if (pch_io_range_in_default(base, size))
531 return;
532
533 res = new_resource(dev, index);
534 res->base = base;
535 res->size = size;
536 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
537}
538
539static void pch_lpc_add_gen_io_resources(device_t dev, int reg_value, int index)
540{
541 /*
542 * Check if the register is enabled. If so and the base exceeds the
Martin Rothde7ed6f2014-12-07 14:58:18 -0700543 * device's default claim range add the resource.
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700544 */
545 if (reg_value & 1) {
546 u16 base = reg_value & 0xfffc;
547 u16 size = (0x3 | ((reg_value >> 16) & 0xfc)) + 1;
548 pch_lpc_add_io_resource(dev, base, size, index);
549 }
550}
551
552static void pch_lpc_add_io_resources(device_t dev)
553{
554 struct resource *res;
555 config_t *config = dev->chip_info;
556
557 /* Add the default claimed IO range for the LPC device. */
558 res = new_resource(dev, 0);
559 res->base = LPC_DEFAULT_IO_RANGE_LOWER;
560 res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER;
561 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
562
563 /* GPIOBASE */
564 pch_lpc_add_io_resource(dev, GPIO_BASE_ADDRESS,
565 GPIO_BASE_SIZE, GPIO_BASE);
566
567 /* PMBASE */
568 pch_lpc_add_io_resource(dev, ACPI_BASE_ADDRESS, ACPI_BASE_SIZE, PMBASE);
569
570 /* LPC Generic IO Decode range. */
571 pch_lpc_add_gen_io_resources(dev, config->gen1_dec, LPC_GEN1_DEC);
572 pch_lpc_add_gen_io_resources(dev, config->gen2_dec, LPC_GEN2_DEC);
573 pch_lpc_add_gen_io_resources(dev, config->gen3_dec, LPC_GEN3_DEC);
574 pch_lpc_add_gen_io_resources(dev, config->gen4_dec, LPC_GEN4_DEC);
575}
576
577static void pch_lpc_read_resources(device_t dev)
578{
579 global_nvs_t *gnvs;
580
581 /* Get the normal PCI resources of this device. */
582 pci_dev_read_resources(dev);
583
584 /* Add non-standard MMIO resources. */
585 pch_lpc_add_mmio_resources(dev);
586
587 /* Add IO resources. */
588 pch_lpc_add_io_resources(dev);
589
590 /* Allocate ACPI NVS in CBMEM */
591 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(global_nvs_t));
Kyösti Mälkki9e94dbf2015-01-08 20:03:18 +0200592 if (!acpi_is_wakeup_s3() && gnvs)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700593 memset(gnvs, 0, sizeof(global_nvs_t));
594}
595
Alexander Couzensa90dad12015-04-12 21:49:46 +0200596static void southcluster_inject_dsdt(device_t device)
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100597{
598 global_nvs_t *gnvs;
599
600 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
601 if (!gnvs) {
Lee Leahy26b7cd02017-03-16 18:47:55 -0700602 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(*gnvs));
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100603 if (gnvs)
604 memset(gnvs, 0, sizeof(*gnvs));
605 }
606
607 if (gnvs) {
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100608 acpi_create_gnvs(gnvs);
609 acpi_save_gnvs((unsigned long)gnvs);
610 /* And tell SMI about it */
611 smm_setup_structures(gnvs, NULL, NULL);
612
613 /* Add it to DSDT. */
614 acpigen_write_scope("\\");
615 acpigen_write_name_dword("NVSA", (u32) gnvs);
616 acpigen_pop_len();
617 }
618}
619
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700620static struct device_operations device_ops = {
621 .read_resources = &pch_lpc_read_resources,
622 .set_resources = &pci_dev_set_resources,
623 .enable_resources = &pci_dev_enable_resources,
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100624 .acpi_inject_dsdt_generator = southcluster_inject_dsdt,
625 .write_acpi_tables = acpi_write_hpet,
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700626 .init = &lpc_init,
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +0200627 .scan_bus = &scan_lpc_bus,
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700628 .ops_pci = &broadwell_pci_ops,
629};
630
631static const unsigned short pci_device_ids[] = {
632 PCH_LPT_LP_SAMPLE,
633 PCH_LPT_LP_PREMIUM,
634 PCH_LPT_LP_MAINSTREAM,
635 PCH_LPT_LP_VALUE,
636 PCH_WPT_HSW_U_SAMPLE,
637 PCH_WPT_BDW_U_SAMPLE,
638 PCH_WPT_BDW_U_PREMIUM,
639 PCH_WPT_BDW_U_BASE,
640 PCH_WPT_BDW_Y_SAMPLE,
641 PCH_WPT_BDW_Y_PREMIUM,
642 PCH_WPT_BDW_Y_BASE,
643 PCH_WPT_BDW_H,
644 0
645};
646
647static const struct pci_driver pch_lpc __pci_driver = {
648 .ops = &device_ops,
649 .vendor = PCI_VENDOR_ID_INTEL,
650 .devices = pci_device_ids,
651};