blob: d502e956e3f845d4aec00395729063616bd90905 [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>
Duncan Laurie35dc00f2015-01-18 14:06:42 -080047
Duncan Lauriec88c54c2014-04-30 16:36:13 -070048static void pch_enable_ioapic(struct device *dev)
49{
50 u32 reg32;
51
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080052 set_ioapic_id(VIO_APIC_VADDR, 0x02);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070053
54 /* affirm full set of redirection table entries ("write once") */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080055 reg32 = io_apic_read(VIO_APIC_VADDR, 0x01);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070056
57 /* PCH-LP has 39 redirection entries */
58 reg32 &= ~0x00ff0000;
59 reg32 |= 0x00270000;
60
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080061 io_apic_write(VIO_APIC_VADDR, 0x01, reg32);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070062
63 /*
64 * Select Boot Configuration register (0x03) and
65 * use Processor System Bus (0x01) to deliver interrupts.
66 */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080067 io_apic_write(VIO_APIC_VADDR, 0x03, 0x01);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070068}
69
70/* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control
71 * 0x00 - 0000 = Reserved
72 * 0x01 - 0001 = Reserved
73 * 0x02 - 0010 = Reserved
74 * 0x03 - 0011 = IRQ3
75 * 0x04 - 0100 = IRQ4
76 * 0x05 - 0101 = IRQ5
77 * 0x06 - 0110 = IRQ6
78 * 0x07 - 0111 = IRQ7
79 * 0x08 - 1000 = Reserved
80 * 0x09 - 1001 = IRQ9
81 * 0x0A - 1010 = IRQ10
82 * 0x0B - 1011 = IRQ11
83 * 0x0C - 1100 = IRQ12
84 * 0x0D - 1101 = Reserved
85 * 0x0E - 1110 = IRQ14
86 * 0x0F - 1111 = IRQ15
87 * PIRQ[n]_ROUT[7] - PIRQ Routing Control
88 * 0x80 - The PIRQ is not routed.
89 */
90
91static void pch_pirq_init(device_t dev)
92{
93 device_t irq_dev;
94 config_t *config = dev->chip_info;
95
96 pci_write_config8(dev, PIRQA_ROUT, config->pirqa_routing);
97 pci_write_config8(dev, PIRQB_ROUT, config->pirqb_routing);
98 pci_write_config8(dev, PIRQC_ROUT, config->pirqc_routing);
99 pci_write_config8(dev, PIRQD_ROUT, config->pirqd_routing);
100
101 pci_write_config8(dev, PIRQE_ROUT, config->pirqe_routing);
102 pci_write_config8(dev, PIRQF_ROUT, config->pirqf_routing);
103 pci_write_config8(dev, PIRQG_ROUT, config->pirqg_routing);
104 pci_write_config8(dev, PIRQH_ROUT, config->pirqh_routing);
105
Elyes HAOUAS4a83f1c2016-08-25 21:07:59 +0200106 for (irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) {
Lee Leahy26b7cd02017-03-16 18:47:55 -0700107 u8 int_pin = 0, int_line = 0;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700108
109 if (!irq_dev->enabled || irq_dev->path.type != DEVICE_PATH_PCI)
110 continue;
111
112 int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
113
114 switch (int_pin) {
Lee Leahy8a9c7dc2017-03-17 10:43:25 -0700115 case 1: /* INTA# */
116 int_line = config->pirqa_routing;
117 break;
118 case 2: /* INTB# */
119 int_line = config->pirqb_routing;
120 break;
121 case 3: /* INTC# */
122 int_line = config->pirqc_routing;
123 break;
124 case 4: /* INTD# */
125 int_line = config->pirqd_routing;
126 break;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700127 }
128
129 if (!int_line)
130 continue;
131
132 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line);
133 }
134}
135
136static void pch_power_options(device_t dev)
137{
138 u16 reg16;
139 const char *state;
140 /* Get the chip configuration */
141 config_t *config = dev->chip_info;
Lee Leahy26b7cd02017-03-16 18:47:55 -0700142 int pwr_on = CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700143
144 /* Which state do we want to goto after g3 (power restored)?
145 * 0 == S0 Full On
146 * 1 == S5 Soft Off
147 *
148 * If the option is not existent (Laptops), use Kconfig setting.
149 */
150 get_option(&pwr_on, "power_on_after_fail");
151
152 reg16 = pci_read_config16(dev, GEN_PMCON_3);
153 reg16 &= 0xfffe;
154 switch (pwr_on) {
155 case MAINBOARD_POWER_OFF:
156 reg16 |= 1;
157 state = "off";
158 break;
159 case MAINBOARD_POWER_ON:
160 reg16 &= ~1;
161 state = "on";
162 break;
163 case MAINBOARD_POWER_KEEP:
164 reg16 &= ~1;
165 state = "state keep";
166 break;
167 default:
168 state = "undefined";
169 }
170 pci_write_config16(dev, GEN_PMCON_3, reg16);
171 printk(BIOS_INFO, "Set power %s after power failure.\n", state);
172
173 /* GPE setup based on device tree configuration */
174 enable_all_gpe(config->gpe0_en_1, config->gpe0_en_2,
175 config->gpe0_en_3, config->gpe0_en_4);
176
177 /* SMI setup based on device tree configuration */
178 enable_alt_smi(config->alt_gp_smi_en);
179}
180
181static void pch_rtc_init(struct device *dev)
182{
Aaron Durbinb9d9b792017-09-15 11:51:58 -0600183 cmos_init(rtc_failure());
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700184}
185
186static const struct reg_script pch_misc_init_script[] = {
187 /* Setup SLP signal assertion, SLP_S4=4s, SLP_S3=50ms */
188 REG_PCI_RMW16(GEN_PMCON_3, ~((3 << 4)|(1 << 10)),
189 (1 << 3)|(1 << 11)|(1 << 12)),
190 /* Prepare sleep mode */
191 REG_IO_RMW32(ACPI_BASE_ADDRESS + PM1_CNT, ~SLP_TYP, SCI_EN),
192 /* Setup NMI on errors, disable SERR */
193 REG_IO_RMW8(0x61, ~0xf0, (1 << 2)),
194 /* Disable NMI sources */
195 REG_IO_OR8(0x70, (1 << 7)),
196 /* Indicate DRAM init done for MRC */
197 REG_PCI_OR8(GEN_PMCON_2, (1 << 7)),
198 /* Enable BIOS updates outside of SMM */
199 REG_PCI_RMW8(0xdc, ~(1 << 5), 0),
200 /* Clear status bits to prevent unexpected wake */
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700201 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x3310, 0x0000002f),
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700202 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x3f02, ~0x0000000f, 0),
Kenji Chen074a0282014-09-20 01:39:20 +0800203 /* Enable PCIe Releaxed Order */
204 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2314, (1 << 31) | (1 << 7)),
205 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x1114, (1 << 15) | (1 << 14)),
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700206 /* Setup SERIRQ, enable continuous mode */
207 REG_PCI_OR8(SERIRQ_CNTL, (1 << 7) | (1 << 6)),
Martin Rothe6ff1592017-06-24 21:34:29 -0600208#if !IS_ENABLED(CONFIG_SERIRQ_CONTINUOUS_MODE)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700209 REG_PCI_RMW8(SERIRQ_CNTL, ~(1 << 6), 0),
210#endif
211 REG_SCRIPT_END
212};
213
214/* Magic register settings for power management */
215static const struct reg_script pch_pm_init_script[] = {
216 REG_PCI_WRITE8(0xa9, 0x46),
217 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x232c, ~1, 0),
218 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x1100, 0x0000c13f),
219 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x2320, ~0x60, 0x10),
220 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3314, 0x00012fff),
221 REG_MMIO_RMW32(RCBA_BASE_ADDRESS + 0x3318, ~0x000f0330, 0x0dcf0400),
222 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3324, 0x04000000),
223 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3368, 0x00041400),
224 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3388, 0x3f8ddbff),
225 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33ac, 0x00007001),
226 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33b0, 0x00181900),
227 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33c0, 0x00060A00),
228 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33d0, 0x06200840),
229 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a28, 0x01010101),
230 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a2c, 0x040c0404),
231 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a9c, 0x9000000a),
232 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b1c, 0x03808033),
233 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b34, 0x80000009),
234 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3348, 0x022ddfff),
235 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x334c, 0x00000001),
236 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3358, 0x0001c000),
237 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3380, 0x3f8ddbff),
238 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3384, 0x0001c7e1),
239 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x338c, 0x0001c7e1),
240 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3398, 0x0001c000),
241 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33a8, 0x00181900),
242 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33dc, 0x00080000),
243 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33e0, 0x00000001),
244 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a20, 0x0000040c),
245 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a24, 0x01010101),
246 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a30, 0x01010101),
247 REG_PCI_RMW32(0xac, ~0x00200000, 0),
248 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x0410, 0x00000003),
249 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2618, 0x08000000),
250 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2300, 0x00000002),
251 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x2600, 0x00000008),
252 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x33b4, 0x00007001),
253 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3350, 0x022ddfff),
254 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3354, 0x00000001),
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700255 /* Power Optimizer */
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700256 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33d4, 0x08000000),
Matt DeVillierc97e0422017-02-16 11:36:16 -0600257 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33c8, 0x00000080),
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700258 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b10, 0x0000883c),
259 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b14, 0x1e0a4616),
260 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b24, 0x40000005),
261 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x2b20, 0x0005db01),
262 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a80, 0x05145005),
263 REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + 0x3a84, 0x00001005),
264 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33d4, 0x2fff2fb1),
265 REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x33c8, 0x00008000),
266 REG_SCRIPT_END
267};
268
269static void pch_enable_mphy(void)
270{
271 u32 gpio71_native = gpio_is_native(71);
272 u32 data_and = 0xffffffff;
273 u32 data_or = (1 << 14) | (1 << 13) | (1 << 12);
274
275 if (gpio71_native) {
276 data_or |= (1 << 0);
277 if (pch_is_wpt()) {
278 data_and &= ~((1 << 7) | (1 << 6) | (1 << 3));
279 data_or |= (1 << 5) | (1 << 4);
280
281 if (pch_is_wpt_ulx()) {
282 /* Check if SATA and USB3 MPHY are enabled */
283 u32 strap19 = pch_read_soft_strap(19);
284 strap19 &= ((1 << 31) | (1 << 30));
285 strap19 >>= 30;
286 if (strap19 == 3) {
287 data_or |= (1 << 3);
288 printk(BIOS_DEBUG, "Enable ULX MPHY PG "
289 "control in single domain\n");
290 } else if (strap19 == 0) {
291 printk(BIOS_DEBUG, "Enable ULX MPHY PG "
292 "control in split domains\n");
293 } else {
294 printk(BIOS_DEBUG, "Invalid PCH Soft "
295 "Strap 19 configuration\n");
296 }
297 } else {
298 data_or |= (1 << 3);
299 }
300 }
301 }
302
303 pch_iobp_update(0xCF000000, data_and, data_or);
304}
305
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700306static void pch_init_deep_sx(struct device *dev)
307{
308 config_t *config = dev->chip_info;
309
310 if (config->deep_sx_enable_ac) {
311 RCBA32_OR(DEEP_S3_POL, DEEP_S3_EN_AC);
312 RCBA32_OR(DEEP_S5_POL, DEEP_S5_EN_AC);
313 }
314
315 if (config->deep_sx_enable_dc) {
316 RCBA32_OR(DEEP_S3_POL, DEEP_S3_EN_DC);
317 RCBA32_OR(DEEP_S5_POL, DEEP_S5_EN_DC);
318 }
319
320 if (config->deep_sx_enable_ac || config->deep_sx_enable_dc)
321 RCBA32_OR(DEEP_SX_CONFIG,
322 DEEP_SX_WAKE_PIN_EN | DEEP_SX_GP27_PIN_EN);
323}
324
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700325/* Power Management init */
326static void pch_pm_init(struct device *dev)
327{
328 printk(BIOS_DEBUG, "PCH PM init\n");
329
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700330 pch_init_deep_sx(dev);
331
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700332 pch_enable_mphy();
333
334 reg_script_run_on_dev(dev, pch_pm_init_script);
335
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700336 if (pch_is_wpt()) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700337 RCBA32_OR(0x33e0, (1 << 4) | (1 << 1));
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700338 RCBA32_OR(0x2b1c, (1 << 22) | (1 << 14) | (1 << 13));
339 RCBA32(0x33e4) = 0x16bf0002;
340 RCBA32_OR(0x33e4, 0x1);
341 }
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700342
343 pch_iobp_update(0xCA000000, ~0UL, 0x00000009);
344
345 /* Set RCBA 0x2b1c[29]=1 if DSP disabled */
346 if (RCBA32(FD) & PCH_DISABLE_ADSPD)
347 RCBA32_OR(0x2b1c, (1 << 29));
348
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700349}
350
351static void pch_cg_init(device_t dev)
352{
353 u32 reg32;
354 u16 reg16;
355
356 /* DMI */
357 RCBA32_OR(0x2234, 0xf);
358
359 reg16 = pci_read_config16(dev, GEN_PMCON_1);
360 reg16 &= ~(1 << 10); /* Disable BIOS_PCI_EXP_EN for native PME */
361 if (pch_is_wpt())
362 reg16 &= ~(1 << 11);
363 else
364 reg16 |= (1 << 11);
365 reg16 |= (1 << 5) | (1 << 6) | (1 << 7) | (1 << 12);
366 reg16 |= (1 << 2); // PCI CLKRUN# Enable
367 pci_write_config16(dev, GEN_PMCON_1, reg16);
368
369 /*
370 * RCBA + 0x2614[27:25,14:13,10,8] = 101,11,1,1
371 * RCBA + 0x2614[23:16] = 0x20
372 * RCBA + 0x2614[30:28] = 0x0
373 * RCBA + 0x2614[26] = 1 (IF 0:2.0@0x08 >= 0x0b)
374 */
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700375 RCBA32_AND_OR(0x2614, ~0x64ff0000, 0x0a206500);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700376
377 /* Check for 0:2.0@0x08 >= 0x0b */
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700378 if (pch_is_wpt() || pci_read_config8(SA_DEV_IGD, 0x8) >= 0x0b)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700379 RCBA32_OR(0x2614, (1 << 26));
380
381 RCBA32_OR(0x900, 0x0000031f);
382
383 reg32 = RCBA32(CG);
384 if (RCBA32(0x3454) & (1 << 4))
385 reg32 &= ~(1 << 29); // LPC Dynamic
386 else
387 reg32 |= (1 << 29); // LPC Dynamic
388 reg32 |= (1 << 31); // LP LPC
389 reg32 |= (1 << 30); // LP BLA
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700390 if (RCBA32(0x3454) & (1 << 4))
391 reg32 &= ~(1 << 29);
392 else
393 reg32 |= (1 << 29);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700394 reg32 |= (1 << 28); // GPIO Dynamic
395 reg32 |= (1 << 27); // HPET Dynamic
396 reg32 |= (1 << 26); // Generic Platform Event Clock
397 if (RCBA32(BUC) & PCH_DISABLE_GBE)
398 reg32 |= (1 << 23); // GbE Static
Duncan Laurie446fb8e2014-08-08 09:59:43 -0700399 if (RCBA32(FD) & PCH_DISABLE_HD_AUDIO)
400 reg32 |= (1 << 21); // HDA Static
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700401 reg32 |= (1 << 22); // HDA Dynamic
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700402 RCBA32(CG) = reg32;
403
404 /* PCH-LP LPC */
405 if (pch_is_wpt())
406 RCBA32_AND_OR(0x3434, ~0x1f, 0x17);
407 else
408 RCBA32_OR(0x3434, 0x7);
409
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700410 /* SPI */
411 RCBA32_OR(0x38c0, 0x3c07);
412
413 pch_iobp_update(0xCE00C000, ~1UL, 0x00000000);
414}
415
416static void pch_set_acpi_mode(void)
417{
Martin Rothe6ff1592017-06-24 21:34:29 -0600418#if IS_ENABLED(CONFIG_HAVE_SMI_HANDLER)
Kyösti Mälkki9e94dbf2015-01-08 20:03:18 +0200419 if (!acpi_is_wakeup_s3()) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700420 printk(BIOS_DEBUG, "Disabling ACPI via APMC:\n");
421 outb(APM_CNT_ACPI_DISABLE, APM_CNT);
422 printk(BIOS_DEBUG, "done.\n");
423 }
424#endif /* CONFIG_HAVE_SMI_HANDLER */
425}
426
427static void lpc_init(struct device *dev)
428{
429 /* Legacy initialization */
430 isa_dma_init();
431 pch_rtc_init(dev);
432 reg_script_run_on_dev(dev, pch_misc_init_script);
433
434 /* Interrupt configuration */
435 pch_enable_ioapic(dev);
436 pch_pirq_init(dev);
437 setup_i8259();
438 i8259_configure_irq_trigger(9, 1);
439
440 /* Initialize power management */
441 pch_power_options(dev);
442 pch_pm_init(dev);
443 pch_cg_init(dev);
444
445 pch_set_acpi_mode();
446}
447
448static void pch_lpc_add_mmio_resources(device_t dev)
449{
450 u32 reg;
451 struct resource *res;
452 const u32 default_decode_base = IO_APIC_ADDR;
453
454 /*
455 * Just report all resources from IO-APIC base to 4GiB. Don't mark
456 * them reserved as that may upset the OS if this range is marked
457 * as reserved in the e820.
458 */
459 res = new_resource(dev, OIC);
460 res->base = default_decode_base;
461 res->size = 0 - default_decode_base;
462 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
463
464 /* RCBA */
Lee Leahy6ef51922017-03-17 10:56:08 -0700465 if (default_decode_base > RCBA_BASE_ADDRESS) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700466 res = new_resource(dev, RCBA);
467 res->base = RCBA_BASE_ADDRESS;
468 res->size = 16 * 1024;
469 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED |
Lee Leahy26b7cd02017-03-16 18:47:55 -0700470 IORESOURCE_FIXED | IORESOURCE_RESERVE;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700471 }
472
473 /* Check LPC Memory Decode register. */
474 reg = pci_read_config32(dev, LGMR);
475 if (reg & 1) {
476 reg &= ~0xffff;
477 if (reg < default_decode_base) {
478 res = new_resource(dev, LGMR);
479 res->base = reg;
480 res->size = 16 * 1024;
481 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED |
Lee Leahy26b7cd02017-03-16 18:47:55 -0700482 IORESOURCE_FIXED | IORESOURCE_RESERVE;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700483 }
484 }
485}
486
487/* Default IO range claimed by the LPC device. The upper bound is exclusive. */
488#define LPC_DEFAULT_IO_RANGE_LOWER 0
489#define LPC_DEFAULT_IO_RANGE_UPPER 0x1000
490
491static inline int pch_io_range_in_default(u16 base, u16 size)
492{
493 /* Does it start above the range? */
494 if (base >= LPC_DEFAULT_IO_RANGE_UPPER)
495 return 0;
496
497 /* Is it entirely contained? */
498 if (base >= LPC_DEFAULT_IO_RANGE_LOWER &&
499 (base + size) < LPC_DEFAULT_IO_RANGE_UPPER)
500 return 1;
501
502 /* This will return not in range for partial overlaps. */
503 return 0;
504}
505
506/*
507 * Note: this function assumes there is no overlap with the default LPC device's
508 * claimed range: LPC_DEFAULT_IO_RANGE_LOWER -> LPC_DEFAULT_IO_RANGE_UPPER.
509 */
510static void pch_lpc_add_io_resource(device_t dev, u16 base, u16 size, int index)
511{
512 struct resource *res;
513
514 if (pch_io_range_in_default(base, size))
515 return;
516
517 res = new_resource(dev, index);
518 res->base = base;
519 res->size = size;
520 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
521}
522
523static void pch_lpc_add_gen_io_resources(device_t dev, int reg_value, int index)
524{
525 /*
526 * Check if the register is enabled. If so and the base exceeds the
Martin Rothde7ed6f2014-12-07 14:58:18 -0700527 * device's default claim range add the resource.
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700528 */
529 if (reg_value & 1) {
530 u16 base = reg_value & 0xfffc;
531 u16 size = (0x3 | ((reg_value >> 16) & 0xfc)) + 1;
532 pch_lpc_add_io_resource(dev, base, size, index);
533 }
534}
535
536static void pch_lpc_add_io_resources(device_t dev)
537{
538 struct resource *res;
539 config_t *config = dev->chip_info;
540
541 /* Add the default claimed IO range for the LPC device. */
542 res = new_resource(dev, 0);
543 res->base = LPC_DEFAULT_IO_RANGE_LOWER;
544 res->size = LPC_DEFAULT_IO_RANGE_UPPER - LPC_DEFAULT_IO_RANGE_LOWER;
545 res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
546
547 /* GPIOBASE */
548 pch_lpc_add_io_resource(dev, GPIO_BASE_ADDRESS,
549 GPIO_BASE_SIZE, GPIO_BASE);
550
551 /* PMBASE */
552 pch_lpc_add_io_resource(dev, ACPI_BASE_ADDRESS, ACPI_BASE_SIZE, PMBASE);
553
554 /* LPC Generic IO Decode range. */
555 pch_lpc_add_gen_io_resources(dev, config->gen1_dec, LPC_GEN1_DEC);
556 pch_lpc_add_gen_io_resources(dev, config->gen2_dec, LPC_GEN2_DEC);
557 pch_lpc_add_gen_io_resources(dev, config->gen3_dec, LPC_GEN3_DEC);
558 pch_lpc_add_gen_io_resources(dev, config->gen4_dec, LPC_GEN4_DEC);
559}
560
561static void pch_lpc_read_resources(device_t dev)
562{
563 global_nvs_t *gnvs;
564
565 /* Get the normal PCI resources of this device. */
566 pci_dev_read_resources(dev);
567
568 /* Add non-standard MMIO resources. */
569 pch_lpc_add_mmio_resources(dev);
570
571 /* Add IO resources. */
572 pch_lpc_add_io_resources(dev);
573
574 /* Allocate ACPI NVS in CBMEM */
575 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(global_nvs_t));
Kyösti Mälkki9e94dbf2015-01-08 20:03:18 +0200576 if (!acpi_is_wakeup_s3() && gnvs)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700577 memset(gnvs, 0, sizeof(global_nvs_t));
578}
579
Alexander Couzensa90dad12015-04-12 21:49:46 +0200580static void southcluster_inject_dsdt(device_t device)
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100581{
582 global_nvs_t *gnvs;
583
584 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
585 if (!gnvs) {
Lee Leahy26b7cd02017-03-16 18:47:55 -0700586 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(*gnvs));
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100587 if (gnvs)
588 memset(gnvs, 0, sizeof(*gnvs));
589 }
590
591 if (gnvs) {
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100592 acpi_create_gnvs(gnvs);
593 acpi_save_gnvs((unsigned long)gnvs);
594 /* And tell SMI about it */
595 smm_setup_structures(gnvs, NULL, NULL);
596
597 /* Add it to DSDT. */
598 acpigen_write_scope("\\");
599 acpigen_write_name_dword("NVSA", (u32) gnvs);
600 acpigen_pop_len();
601 }
602}
603
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700604static struct device_operations device_ops = {
605 .read_resources = &pch_lpc_read_resources,
606 .set_resources = &pci_dev_set_resources,
607 .enable_resources = &pci_dev_enable_resources,
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100608 .acpi_inject_dsdt_generator = southcluster_inject_dsdt,
609 .write_acpi_tables = acpi_write_hpet,
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700610 .init = &lpc_init,
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +0200611 .scan_bus = &scan_lpc_bus,
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700612 .ops_pci = &broadwell_pci_ops,
613};
614
615static const unsigned short pci_device_ids[] = {
616 PCH_LPT_LP_SAMPLE,
617 PCH_LPT_LP_PREMIUM,
618 PCH_LPT_LP_MAINSTREAM,
619 PCH_LPT_LP_VALUE,
620 PCH_WPT_HSW_U_SAMPLE,
621 PCH_WPT_BDW_U_SAMPLE,
622 PCH_WPT_BDW_U_PREMIUM,
623 PCH_WPT_BDW_U_BASE,
624 PCH_WPT_BDW_Y_SAMPLE,
625 PCH_WPT_BDW_Y_PREMIUM,
626 PCH_WPT_BDW_Y_BASE,
627 PCH_WPT_BDW_H,
628 0
629};
630
631static const struct pci_driver pch_lpc __pci_driver = {
632 .ops = &device_ops,
633 .vendor = PCI_VENDOR_ID_INTEL,
634 .devices = pci_device_ids,
635};