blob: 6a89291455296fbf7622c21c92f85944df7e527c [file] [log] [blame]
Stefan Reinauerdebb11f2008-10-29 04:46:52 +00001/*
2 * This file is part of the coreboot project.
3 *
Stefan Reinauer54309d62009-01-20 22:53:10 +00004 * Copyright (C) 2008-2009 coresystems GmbH
Stefan Reinauerdebb11f2008-10-29 04:46:52 +00005 *
Stefan Reinauera8e11682009-03-11 14:54:18 +00006 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * the License.
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000010 *
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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
Patrick Georgib890a122015-03-26 15:17:45 +010018 * Foundation, Inc.
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000019 */
20
21#include <console/console.h>
22#include <device/device.h>
23#include <device/pci.h>
24#include <device/pci_ids.h>
25#include <pc80/mc146818rtc.h>
26#include <pc80/isa-dma.h>
Stefan Reinauer54309d62009-01-20 22:53:10 +000027#include <pc80/i8259.h>
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000028#include <arch/io.h>
Uwe Hermann74d1a6e2010-10-12 17:34:08 +000029#include <arch/ioapic.h>
Stefan Reinauerab872542011-10-14 15:18:29 -070030#include <arch/acpi.h>
Stefan Reinauercadc5452010-12-18 23:29:37 +000031#include <cpu/cpu.h>
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000032#include "i82801gx.h"
Sven Schnellef4dc1a72011-06-05 11:33:41 +020033#include <cpu/x86/smm.h>
Vladimir Serbinenko0e646172014-08-31 00:27:05 +020034#include <arch/acpigen.h>
35#include <cbmem.h>
36#include <string.h>
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +010037#include <drivers/intel/gma/i915.h>
Vladimir Serbinenko0e646172014-08-31 00:27:05 +020038#include "nvs.h"
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000039
Stefan Reinauer573f7d42009-07-21 21:50:34 +000040#define NMI_OFF 0
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000041
Stefan Reinauer573f7d42009-07-21 21:50:34 +000042#define ENABLE_ACPI_MODE_IN_COREBOOT 0
43#define TEST_SMM_FLASH_LOCKDOWN 0
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000044
Stefan Reinauer54309d62009-01-20 22:53:10 +000045typedef struct southbridge_intel_i82801gx_config config_t;
46
Paul Menzelddddf152013-04-23 14:40:23 +020047/**
48 * Set miscellanous static southbridge features.
49 *
50 * @param dev PCI device with I/O APIC control registers
51 */
52static void i82801gx_enable_ioapic(struct device *dev)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000053{
Paul Menzelddddf152013-04-23 14:40:23 +020054 /* Enable ACPI I/O range decode */
Kyösti Mälkki1cca3402013-02-26 19:21:39 +020055 pci_write_config8(dev, ACPI_CNTL, ACPI_EN);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000056
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080057 set_ioapic_id(VIO_APIC_VADDR, 0x02);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000058
Paul Menzelddddf152013-04-23 14:40:23 +020059 /*
60 * Select Boot Configuration register (0x03) and
61 * use Processor System Bus (0x01) to deliver interrupts.
62 */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080063 io_apic_write(VIO_APIC_VADDR, 0x03, 0x01);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000064}
65
66static void i82801gx_enable_serial_irqs(struct device *dev)
67{
68 /* Set packet length and toggle silent mode bit for one frame. */
69 pci_write_config8(dev, SERIRQ_CNTL,
70 (1 << 7) | (1 << 6) | ((21 - 17) << 2) | (0 << 0));
71}
72
Stefan Reinauer573f7d42009-07-21 21:50:34 +000073/* PIRQ[n]_ROUT[3:0] - PIRQ Routing Control
74 * 0x00 - 0000 = Reserved
75 * 0x01 - 0001 = Reserved
76 * 0x02 - 0010 = Reserved
77 * 0x03 - 0011 = IRQ3
78 * 0x04 - 0100 = IRQ4
79 * 0x05 - 0101 = IRQ5
80 * 0x06 - 0110 = IRQ6
81 * 0x07 - 0111 = IRQ7
82 * 0x08 - 1000 = Reserved
83 * 0x09 - 1001 = IRQ9
84 * 0x0A - 1010 = IRQ10
85 * 0x0B - 1011 = IRQ11
86 * 0x0C - 1100 = IRQ12
87 * 0x0D - 1101 = Reserved
88 * 0x0E - 1110 = IRQ14
89 * 0x0F - 1111 = IRQ15
90 * PIRQ[n]_ROUT[7] - PIRQ Routing Control
91 * 0x80 - The PIRQ is not routed.
92 */
93
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000094static void i82801gx_pirq_init(device_t dev)
95{
Stefan Reinauer54309d62009-01-20 22:53:10 +000096 device_t irq_dev;
97 /* Get the chip configuration */
98 config_t *config = dev->chip_info;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000099
Stefan Reinauer54309d62009-01-20 22:53:10 +0000100 pci_write_config8(dev, PIRQA_ROUT, config->pirqa_routing);
101 pci_write_config8(dev, PIRQB_ROUT, config->pirqb_routing);
102 pci_write_config8(dev, PIRQC_ROUT, config->pirqc_routing);
103 pci_write_config8(dev, PIRQD_ROUT, config->pirqd_routing);
104
105 pci_write_config8(dev, PIRQE_ROUT, config->pirqe_routing);
106 pci_write_config8(dev, PIRQF_ROUT, config->pirqf_routing);
107 pci_write_config8(dev, PIRQG_ROUT, config->pirqg_routing);
108 pci_write_config8(dev, PIRQH_ROUT, config->pirqh_routing);
109
110 /* Eric Biederman once said we should let the OS do this.
111 * I am not so sure anymore he was right.
112 */
113
114 for(irq_dev = all_devices; irq_dev; irq_dev = irq_dev->next) {
115 u8 int_pin=0, int_line=0;
116
117 if (!irq_dev->enabled || irq_dev->path.type != DEVICE_PATH_PCI)
118 continue;
119
120 int_pin = pci_read_config8(irq_dev, PCI_INTERRUPT_PIN);
121
122 switch (int_pin) {
123 case 1: /* INTA# */ int_line = config->pirqa_routing; break;
124 case 2: /* INTB# */ int_line = config->pirqb_routing; break;
125 case 3: /* INTC# */ int_line = config->pirqc_routing; break;
126 case 4: /* INTD# */ int_line = config->pirqd_routing; break;
127 }
128
129 if (!int_line)
130 continue;
131
132 pci_write_config8(irq_dev, PCI_INTERRUPT_LINE, int_line);
133 }
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000134}
135
Stefan Reinauera8e11682009-03-11 14:54:18 +0000136static void i82801gx_gpi_routing(device_t dev)
137{
138 /* Get the chip configuration */
139 config_t *config = dev->chip_info;
140 u32 reg32 = 0;
141
142 /* An array would be much nicer here, or some
143 * other method of doing this.
144 */
145 reg32 |= (config->gpi0_routing & 0x03) << 0;
146 reg32 |= (config->gpi1_routing & 0x03) << 2;
147 reg32 |= (config->gpi2_routing & 0x03) << 4;
148 reg32 |= (config->gpi3_routing & 0x03) << 6;
149 reg32 |= (config->gpi4_routing & 0x03) << 8;
150 reg32 |= (config->gpi5_routing & 0x03) << 10;
151 reg32 |= (config->gpi6_routing & 0x03) << 12;
152 reg32 |= (config->gpi7_routing & 0x03) << 14;
153 reg32 |= (config->gpi8_routing & 0x03) << 16;
154 reg32 |= (config->gpi9_routing & 0x03) << 18;
155 reg32 |= (config->gpi10_routing & 0x03) << 20;
156 reg32 |= (config->gpi11_routing & 0x03) << 22;
157 reg32 |= (config->gpi12_routing & 0x03) << 24;
158 reg32 |= (config->gpi13_routing & 0x03) << 26;
159 reg32 |= (config->gpi14_routing & 0x03) << 28;
160 reg32 |= (config->gpi15_routing & 0x03) << 30;
161
Kyösti Mälkkib85a87b2014-12-29 11:32:27 +0200162 pci_write_config32(dev, GPIO_ROUT, reg32);
Stefan Reinauera8e11682009-03-11 14:54:18 +0000163}
164
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000165static void i82801gx_power_options(device_t dev)
166{
167 u8 reg8;
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000168 u16 reg16, pmbase;
169 u32 reg32;
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000170 const char *state;
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000171 /* Get the chip configuration */
172 config_t *config = dev->chip_info;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000173
Stefan Reinauer08670622009-06-30 15:17:49 +0000174 int pwr_on=CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL;
Luc Verhaegena9c5ea02009-06-03 14:19:33 +0000175 int nmi_option;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000176
177 /* Which state do we want to goto after g3 (power restored)?
178 * 0 == S0 Full On
179 * 1 == S5 Soft Off
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000180 *
181 * If the option is not existent (Laptops), use MAINBOARD_POWER_ON.
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000182 */
Varad Gautam06ef0462015-03-11 09:54:41 +0530183 pwr_on = MAINBOARD_POWER_ON;
184 get_option(&pwr_on, "power_on_after_fail");
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000185
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000186 reg8 = pci_read_config8(dev, GEN_PMCON_3);
187 reg8 &= 0xfe;
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000188 switch (pwr_on) {
189 case MAINBOARD_POWER_OFF:
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000190 reg8 |= 1;
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000191 state = "off";
192 break;
193 case MAINBOARD_POWER_ON:
194 reg8 &= ~1;
195 state = "on";
196 break;
197 case MAINBOARD_POWER_KEEP:
198 reg8 &= ~1;
199 state = "state keep";
200 break;
201 default:
202 state = "undefined";
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000203 }
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000204
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000205 reg8 |= (3 << 4); /* avoid #S4 assertions */
Stefan Reinauera8e11682009-03-11 14:54:18 +0000206 reg8 &= ~(1 << 3); /* minimum asssertion is 1 to 2 RTCCLK */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000207
208 pci_write_config8(dev, GEN_PMCON_3, reg8);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000209 printk(BIOS_INFO, "Set power %s after power failure.\n", state);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000210
211 /* Set up NMI on errors. */
212 reg8 = inb(0x61);
213 reg8 &= 0x0f; /* Higher Nibble must be 0 */
214 reg8 &= ~(1 << 3); /* IOCHK# NMI Enable */
215 // reg8 &= ~(1 << 2); /* PCI SERR# Enable */
216 reg8 |= (1 << 2); /* PCI SERR# Disable for now */
217 outb(reg8, 0x61);
218
219 reg8 = inb(0x70);
220 nmi_option = NMI_OFF;
Luc Verhaegena9c5ea02009-06-03 14:19:33 +0000221 get_option(&nmi_option, "nmi");
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000222 if (nmi_option) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000223 printk(BIOS_INFO, "NMI sources enabled.\n");
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000224 reg8 &= ~(1 << 7); /* Set NMI. */
225 } else {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000226 printk(BIOS_INFO, "NMI sources disabled.\n");
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000227 reg8 |= ( 1 << 7); /* Can't mask NMI from PCI-E and NMI_NOW */
228 }
229 outb(reg8, 0x70);
230
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000231 /* Enable CPU_SLP# and Intel Speedstep, set SMI# rate down */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000232 reg16 = pci_read_config16(dev, GEN_PMCON_1);
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000233 reg16 &= ~(3 << 0); // SMI# rate 1 minute
234 reg16 |= (1 << 2); // CLKRUN_EN - Mobile/Ultra only
235 reg16 |= (1 << 3); // Speedstep Enable - Mobile/Ultra only
236 reg16 |= (1 << 5); // CPUSLP_EN Desktop only
Sven Schnelle906f9ae2011-10-23 16:35:01 +0200237
238 if (config->c4onc3_enable)
239 reg16 |= (1 << 7);
240
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000241 // another laptop wants this?
242 // reg16 &= ~(1 << 10); // BIOS_PCI_EXP_EN - Desktop/Mobile only
243 reg16 |= (1 << 10); // BIOS_PCI_EXP_EN - Desktop/Mobile only
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000244#if DEBUG_PERIODIC_SMIS
245 /* Set DEBUG_PERIODIC_SMIS in i82801gx.h to debug using
246 * periodic SMIs.
247 */
248 reg16 |= (3 << 0); // Periodic SMI every 8s
249#endif
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000250 pci_write_config16(dev, GEN_PMCON_1, reg16);
251
Stefan Reinauera8e11682009-03-11 14:54:18 +0000252 // Set the board's GPI routing.
253 i82801gx_gpi_routing(dev);
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000254
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000255 pmbase = pci_read_config16(dev, 0x40) & 0xfffe;
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000256
257 outl(config->gpe0_en, pmbase + GPE0_EN);
258 outw(config->alt_gp_smi_en, pmbase + ALT_GP_SMI_EN);
259
260 /* Set up power management block and determine sleep mode */
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000261 reg32 = inl(pmbase + 0x04); // PM1_CNT
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000262
263 reg32 &= ~(7 << 10); // SLP_TYP
264 reg32 |= (1 << 1); // enable C3->C0 transition on bus master
265 reg32 |= (1 << 0); // SCI_EN
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000266 outl(reg32, pmbase + 0x04);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000267}
268
Stefan Reinauera8e11682009-03-11 14:54:18 +0000269static void i82801gx_configure_cstates(device_t dev)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000270{
271 u8 reg8;
Stefan Reinauer109ab312009-08-12 16:08:05 +0000272
Stefan Reinauera8e11682009-03-11 14:54:18 +0000273 reg8 = pci_read_config8(dev, 0xa9); // Cx state configuration
274 reg8 |= (1 << 4) | (1 << 3) | (1 << 2); // Enable Popup & Popdown
275 pci_write_config8(dev, 0xa9, reg8);
276
277 // Set Deeper Sleep configuration to recommended values
278 reg8 = pci_read_config8(dev, 0xaa);
279 reg8 &= 0xf0;
280 reg8 |= (2 << 2); // Deeper Sleep to Stop CPU: 34-40us
281 reg8 |= (2 << 0); // Deeper Sleep to Sleep: 15us
282 pci_write_config8(dev, 0xaa, reg8);
283}
284
285static void i82801gx_rtc_init(struct device *dev)
286{
287 u8 reg8;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000288 int rtc_failed;
289
290 reg8 = pci_read_config8(dev, GEN_PMCON_3);
291 rtc_failed = reg8 & RTC_BATTERY_DEAD;
292 if (rtc_failed) {
293 reg8 &= ~RTC_BATTERY_DEAD;
294 pci_write_config8(dev, GEN_PMCON_3, reg8);
295 }
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000296 printk(BIOS_DEBUG, "rtc_failed = 0x%x\n", rtc_failed);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000297
Gabe Blackb3f08c62014-04-30 17:12:25 -0700298 cmos_init(rtc_failed);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000299}
300
Stefan Reinauera8e11682009-03-11 14:54:18 +0000301static void enable_hpet(void)
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000302{
Stefan Reinauera8e11682009-03-11 14:54:18 +0000303 u32 reg32;
Stefan Reinauer109ab312009-08-12 16:08:05 +0000304
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000305 /* Move HPET to default address 0xfed00000 and enable it */
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000306 reg32 = RCBA32(HPTC);
Stefan Reinauera8e11682009-03-11 14:54:18 +0000307 reg32 |= (1 << 7); // HPET Address Enable
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000308 reg32 &= ~(3 << 0);
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000309 RCBA32(HPTC) = reg32;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000310}
311
Stefan Reinauera8e11682009-03-11 14:54:18 +0000312static void enable_clock_gating(void)
313{
314 u32 reg32;
Stefan Reinauer109ab312009-08-12 16:08:05 +0000315
Stefan Reinauera8e11682009-03-11 14:54:18 +0000316 /* Enable Clock Gating for most devices */
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000317 reg32 = RCBA32(CG);
Stefan Reinauera8e11682009-03-11 14:54:18 +0000318 reg32 |= (1 << 31); // LPC clock gating
319 reg32 |= (1 << 30); // PATA clock gating
320 // SATA clock gating
321 reg32 |= (1 << 27) | (1 << 26) | (1 << 25) | (1 << 24);
322 reg32 |= (1 << 23); // AC97 clock gating
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000323 reg32 |= (1 << 19); // USB EHCI clock gating
Stefan Reinauera8e11682009-03-11 14:54:18 +0000324 reg32 |= (1 << 3) | (1 << 1); // DMI clock gating
325 reg32 |= (1 << 2); // PCIe clock gating;
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000326 reg32 &= ~(1 << 20); // No static clock gating for USB
327 reg32 &= ~( (1 << 29) | (1 << 28) ); // Disable UHCI clock gating
328 RCBA32(CG) = reg32;
Stefan Reinauera8e11682009-03-11 14:54:18 +0000329}
Stefan Reinauer269563a2009-01-19 21:20:22 +0000330
Stefan Reinauer08670622009-06-30 15:17:49 +0000331#if CONFIG_HAVE_SMI_HANDLER
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000332static void i82801gx_lock_smm(struct device *dev)
333{
Stefan Reinauera8e11682009-03-11 14:54:18 +0000334#if TEST_SMM_FLASH_LOCKDOWN
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000335 u8 reg8;
Stefan Reinauera8e11682009-03-11 14:54:18 +0000336#endif
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000337
Kyösti Mälkkic3ed8862014-06-19 19:50:51 +0300338 if (!acpi_is_wakeup_s3()) {
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000339#if ENABLE_ACPI_MODE_IN_COREBOOT
Sven Schnellef4dc1a72011-06-05 11:33:41 +0200340 printk(BIOS_DEBUG, "Enabling ACPI via APMC:\n");
341 outb(APM_CNT_ACPI_ENABLE, APM_CNT); // Enable ACPI mode
342 printk(BIOS_DEBUG, "done.\n");
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000343#else
Sven Schnellef4dc1a72011-06-05 11:33:41 +0200344 printk(BIOS_DEBUG, "Disabling ACPI via APMC:\n");
345 outb(APM_CNT_ACPI_DISABLE, APM_CNT); // Disable ACPI mode
346 printk(BIOS_DEBUG, "done.\n");
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000347#endif
Sven Schnellee2618072011-06-05 11:39:12 +0200348 } else {
349 printk(BIOS_DEBUG, "S3 wakeup, enabling ACPI via APMC\n");
350 outb(APM_CNT_ACPI_ENABLE, APM_CNT);
351 }
Stefan Reinauer109ab312009-08-12 16:08:05 +0000352 /* Don't allow evil boot loaders, kernels, or
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000353 * userspace applications to deceive us:
354 */
355 smm_lock();
356
357#if TEST_SMM_FLASH_LOCKDOWN
358 /* Now try this: */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000359 printk(BIOS_DEBUG, "Locking BIOS to RO... ");
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000360 reg8 = pci_read_config8(dev, 0xdc); /* BIOS_CNTL */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000361 printk(BIOS_DEBUG, " BLE: %s; BWE: %s\n", (reg8&2)?"on":"off",
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000362 (reg8&1)?"rw":"ro");
363 reg8 &= ~(1 << 0); /* clear BIOSWE */
364 pci_write_config8(dev, 0xdc, reg8);
365 reg8 |= (1 << 1); /* set BLE */
366 pci_write_config8(dev, 0xdc, reg8);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000367 printk(BIOS_DEBUG, "ok.\n");
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000368 reg8 = pci_read_config8(dev, 0xdc); /* BIOS_CNTL */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000369 printk(BIOS_DEBUG, " BLE: %s; BWE: %s\n", (reg8&2)?"on":"off",
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000370 (reg8&1)?"rw":"ro");
371
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000372 printk(BIOS_DEBUG, "Writing:\n");
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000373 *(volatile u8 *)0xfff00000 = 0x00;
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000374 printk(BIOS_DEBUG, "Testing:\n");
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000375 reg8 |= (1 << 0); /* set BIOSWE */
376 pci_write_config8(dev, 0xdc, reg8);
377
378 reg8 = pci_read_config8(dev, 0xdc); /* BIOS_CNTL */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000379 printk(BIOS_DEBUG, " BLE: %s; BWE: %s\n", (reg8&2)?"on":"off",
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000380 (reg8&1)?"rw":"ro");
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000381 printk(BIOS_DEBUG, "Done.\n");
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000382#endif
383}
Stefan Reinauer269563a2009-01-19 21:20:22 +0000384#endif
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000385
Stefan Reinauera8e11682009-03-11 14:54:18 +0000386#define SPIBASE 0x3020
387static void i82801gx_spi_init(void)
388{
389 u16 spicontrol;
390
391 spicontrol = RCBA16(SPIBASE + 2);
392 spicontrol &= ~(1 << 0); // SPI Access Request
393 RCBA16(SPIBASE + 2) = spicontrol;
394}
395
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000396static void i82801gx_fixups(struct device *dev)
Stefan Reinauera8e11682009-03-11 14:54:18 +0000397{
398 /* This needs to happen after PCI enumeration */
399 RCBA32(0x1d40) |= 1;
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000400
401 /* USB Transient Disconnect Detect:
402 * Prevent a SE0 condition on the USB ports from being
403 * interpreted by the UHCI controller as a disconnect
404 */
405 pci_write_config8(dev, 0xad, 0x3);
Stefan Reinauera8e11682009-03-11 14:54:18 +0000406}
407
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000408static void lpc_init(struct device *dev)
409{
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000410 printk(BIOS_DEBUG, "i82801gx: lpc_init\n");
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000411
412 /* Set the value for PCI command register. */
413 pci_write_config16(dev, PCI_COMMAND, 0x000f);
414
415 /* IO APIC initialization. */
Paul Menzelddddf152013-04-23 14:40:23 +0200416 i82801gx_enable_ioapic(dev);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000417
418 i82801gx_enable_serial_irqs(dev);
419
420 /* Setup the PIRQ. */
421 i82801gx_pirq_init(dev);
422
423 /* Setup power options. */
424 i82801gx_power_options(dev);
425
Stefan Reinauera8e11682009-03-11 14:54:18 +0000426 /* Configure Cx state registers */
427 i82801gx_configure_cstates(dev);
428
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000429 /* Set the state of the GPIO lines. */
430 //gpio_init(dev);
431
432 /* Initialize the real time clock. */
433 i82801gx_rtc_init(dev);
434
435 /* Initialize ISA DMA. */
436 isa_dma_init();
437
438 /* Initialize the High Precision Event Timers, if present. */
Stefan Reinauera8e11682009-03-11 14:54:18 +0000439 enable_hpet();
440
441 /* Initialize Clock Gating */
442 enable_clock_gating();
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000443
444 setup_i8259();
445
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000446 /* The OS should do this? */
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000447 /* Interrupt 9 should be level triggered (SCI) */
448 i8259_configure_irq_trigger(9, 1);
Stefan Reinaueraca6ec62009-10-26 17:12:21 +0000449
Stefan Reinauer08670622009-06-30 15:17:49 +0000450#if CONFIG_HAVE_SMI_HANDLER
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000451 i82801gx_lock_smm(dev);
Stefan Reinauer269563a2009-01-19 21:20:22 +0000452#endif
Stefan Reinauera8e11682009-03-11 14:54:18 +0000453
454 i82801gx_spi_init();
455
Stefan Reinauer7a3d0952010-01-17 13:49:07 +0000456 i82801gx_fixups(dev);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000457}
458
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200459void acpi_fill_fadt(acpi_fadt_t * fadt)
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200460{
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200461 device_t dev = dev_find_slot(0, PCI_DEVFN(0x1f,0));
462 config_t *chip = dev->chip_info;
463 u16 pmbase = pci_read_config16(dev, 0x40) & 0xfffe;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200464
465 fadt->pm1a_evt_blk = pmbase;
466 fadt->pm1b_evt_blk = 0x0;
467 fadt->pm1a_cnt_blk = pmbase + 0x4;
468 fadt->pm1b_cnt_blk = 0x0;
469 fadt->pm2_cnt_blk = pmbase + 0x20;
470 fadt->pm_tmr_blk = pmbase + 0x8;
471 fadt->gpe0_blk = pmbase + 0x28;
472 fadt->gpe1_blk = 0;
473
474 fadt->pm1_evt_len = 4;
475 fadt->pm1_cnt_len = 2;
476 fadt->pm2_cnt_len = 1;
477 fadt->pm_tmr_len = 4;
478 fadt->gpe0_blk_len = 8;
479 fadt->gpe1_blk_len = 0;
480 fadt->gpe1_base = 0;
481
482 fadt->reset_reg.space_id = 1;
483 fadt->reset_reg.bit_width = 8;
484 fadt->reset_reg.bit_offset = 0;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200485 fadt->reset_reg.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200486 fadt->reset_reg.addrl = 0xcf9;
487 fadt->reset_reg.addrh = 0;
488
489 fadt->reset_value = 6;
490
491 fadt->x_pm1a_evt_blk.space_id = 1;
492 fadt->x_pm1a_evt_blk.bit_width = 32;
493 fadt->x_pm1a_evt_blk.bit_offset = 0;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200494 fadt->x_pm1a_evt_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200495 fadt->x_pm1a_evt_blk.addrl = pmbase;
496 fadt->x_pm1a_evt_blk.addrh = 0x0;
497
498 fadt->x_pm1b_evt_blk.space_id = 0;
499 fadt->x_pm1b_evt_blk.bit_width = 0;
500 fadt->x_pm1b_evt_blk.bit_offset = 0;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200501 fadt->x_pm1b_evt_blk.access_size = 0;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200502 fadt->x_pm1b_evt_blk.addrl = 0x0;
503 fadt->x_pm1b_evt_blk.addrh = 0x0;
504
505 fadt->x_pm1a_cnt_blk.space_id = 1;
506 fadt->x_pm1a_cnt_blk.bit_width = 16;
507 fadt->x_pm1a_cnt_blk.bit_offset = 0;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200508 fadt->x_pm1a_cnt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200509 fadt->x_pm1a_cnt_blk.addrl = pmbase + 0x4;
510 fadt->x_pm1a_cnt_blk.addrh = 0x0;
511
512 fadt->x_pm1b_cnt_blk.space_id = 0;
513 fadt->x_pm1b_cnt_blk.bit_width = 0;
514 fadt->x_pm1b_cnt_blk.bit_offset = 0;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200515 fadt->x_pm1b_cnt_blk.access_size = 0;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200516 fadt->x_pm1b_cnt_blk.addrl = 0x0;
517 fadt->x_pm1b_cnt_blk.addrh = 0x0;
518
519 fadt->x_pm2_cnt_blk.space_id = 1;
520 fadt->x_pm2_cnt_blk.bit_width = 8;
521 fadt->x_pm2_cnt_blk.bit_offset = 0;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200522 fadt->x_pm2_cnt_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200523 fadt->x_pm2_cnt_blk.addrl = pmbase + 0x20;
524 fadt->x_pm2_cnt_blk.addrh = 0x0;
525
526 fadt->x_pm_tmr_blk.space_id = 1;
527 fadt->x_pm_tmr_blk.bit_width = 32;
528 fadt->x_pm_tmr_blk.bit_offset = 0;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200529 fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200530 fadt->x_pm_tmr_blk.addrl = pmbase + 0x8;
531 fadt->x_pm_tmr_blk.addrh = 0x0;
532
533 fadt->x_gpe0_blk.space_id = 1;
534 fadt->x_gpe0_blk.bit_width = 64;
535 fadt->x_gpe0_blk.bit_offset = 0;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200536 fadt->x_gpe0_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200537 fadt->x_gpe0_blk.addrl = pmbase + 0x28;
538 fadt->x_gpe0_blk.addrh = 0x0;
539
540 fadt->x_gpe1_blk.space_id = 0;
541 fadt->x_gpe1_blk.bit_width = 0;
542 fadt->x_gpe1_blk.bit_offset = 0;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200543 fadt->x_gpe1_blk.access_size = 0;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200544 fadt->x_gpe1_blk.addrl = 0x0;
545 fadt->x_gpe1_blk.addrh = 0x0;
546 fadt->day_alrm = 0xd;
547 fadt->mon_alrm = 0x00;
548 fadt->century = 0x32;
549
550 fadt->model = 1;
551 fadt->sci_int = 0x9;
552 fadt->smi_cmd = APM_CNT;
553 fadt->acpi_enable = APM_CNT_ACPI_ENABLE;
554 fadt->acpi_disable = APM_CNT_ACPI_DISABLE;
555 fadt->s4bios_req = 0x0;
556 fadt->pstate_cnt = APM_CNT_PST_CONTROL;
557
558 fadt->cst_cnt = APM_CNT_CST_CONTROL;
559 fadt->p_lvl2_lat = 1;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200560 fadt->p_lvl3_lat = chip->c3_latency;
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200561 fadt->flush_size = 0;
562 fadt->flush_stride = 0;
563 fadt->duty_offset = 1;
Vladimir Serbinenkoab83ef02014-10-25 15:18:25 +0200564 if (chip->p_cnt_throttling_supported) {
565 fadt->duty_width = 3;
566 } else {
567 fadt->duty_width = 0;
568 }
569 fadt->iapc_boot_arch = 0x03;
570 fadt->flags = (ACPI_FADT_WBINVD | ACPI_FADT_C1_SUPPORTED
571 | ACPI_FADT_SLEEP_BUTTON | ACPI_FADT_S4_RTC_WAKE
572 | ACPI_FADT_PLATFORM_CLOCK | ACPI_FADT_RESET_REGISTER
573 | ACPI_FADT_C2_MP_SUPPORTED);
574 if (chip->docking_supported) {
575 fadt->flags |= ACPI_FADT_DOCKING_SUPPORTED;
576 }
Vladimir Serbinenkoc21e0732014-10-16 12:48:19 +0200577}
578
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000579static void i82801gx_lpc_read_resources(device_t dev)
580{
581 struct resource *res;
Vladimir Serbinenkof119f082014-11-24 21:05:56 +0100582 u8 io_index = 0;
583 int i;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000584
585 /* Get the normal PCI resources of this device. */
586 pci_dev_read_resources(dev);
587
588 /* Add an extra subtractive resource for both memory and I/O. */
Vladimir Serbinenkof119f082014-11-24 21:05:56 +0100589 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
Myles Watson29cc9ed2009-07-02 18:56:24 +0000590 res->base = 0;
591 res->size = 0x1000;
592 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
593 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000594
Vladimir Serbinenkof119f082014-11-24 21:05:56 +0100595 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
Myles Watson29cc9ed2009-07-02 18:56:24 +0000596 res->base = 0xff800000;
597 res->size = 0x00800000; /* 8 MB for flash */
598 res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE |
599 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
600
601 res = new_resource(dev, 3); /* IOAPIC */
Uwe Hermann74d1a6e2010-10-12 17:34:08 +0000602 res->base = IO_APIC_ADDR;
Myles Watson29cc9ed2009-07-02 18:56:24 +0000603 res->size = 0x00001000;
604 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
Vladimir Serbinenkof119f082014-11-24 21:05:56 +0100605
606 /* Set IO decode ranges if required.*/
607 for (i = 0; i < 4; i++) {
608 u32 gen_dec;
609 gen_dec = pci_read_config32(dev, 0x84 + 4 * i);
610
611 if ((gen_dec & 0xFFFC) > 0x1000) {
612 res = new_resource(dev, IOINDEX_SUBTRACTIVE(io_index++, 0));
613 res->base = gen_dec & 0xFFFC;
614 res->size = (gen_dec >> 16) & 0xFC;
615 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
616 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
617 }
618 }
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000619}
620
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000621static void set_subsystem(device_t dev, unsigned vendor, unsigned device)
622{
Stefan Reinauera8e11682009-03-11 14:54:18 +0000623 if (!vendor || !device) {
624 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
625 pci_read_config32(dev, PCI_VENDOR_ID));
626 } else {
627 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
628 ((device & 0xffff) << 16) | (vendor & 0xffff));
629 }
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000630}
631
Alexander Couzensa90dad12015-04-12 21:49:46 +0200632static void southbridge_inject_dsdt(device_t dev)
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200633{
634 global_nvs_t *gnvs = cbmem_add (CBMEM_ID_ACPI_GNVS, sizeof (*gnvs));
635
636 if (gnvs) {
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100637 const struct i915_gpu_controller_info *gfx = intel_gma_get_controller_info();
638
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200639 memset(gnvs, 0, sizeof(*gnvs));
Vladimir Serbinenko385743a2014-10-18 02:26:21 +0200640
641 gnvs->apic = 1;
642 gnvs->mpen = 1; /* Enable Multi Processing */
643
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200644 acpi_create_gnvs(gnvs);
Vladimir Serbinenkodd2bc3f2014-10-31 09:16:31 +0100645
646 gnvs->ndid = gfx->ndid;
647 memcpy(gnvs->did, gfx->did, sizeof(gnvs->did));
648
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200649 /* And tell SMI about it */
650 smm_setup_structures(gnvs, NULL, NULL);
651
652 /* Add it to SSDT. */
Vladimir Serbinenko1bad88e2014-11-04 21:20:56 +0100653 acpigen_write_scope("\\");
654 acpigen_write_name_dword("NVSA", (u32) gnvs);
655 acpigen_pop_len();
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200656 }
657}
658
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000659static struct pci_operations pci_ops = {
660 .set_subsystem = set_subsystem,
661};
662
663static struct device_operations device_ops = {
664 .read_resources = i82801gx_lpc_read_resources,
665 .set_resources = pci_dev_set_resources,
Myles Watson7eac4452010-06-17 16:16:56 +0000666 .enable_resources = pci_dev_enable_resources,
Vladimir Serbinenko0e646172014-08-31 00:27:05 +0200667 .acpi_inject_dsdt_generator = southbridge_inject_dsdt,
668 .write_acpi_tables = acpi_write_hpet,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000669 .init = lpc_init,
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +0200670 .scan_bus = scan_lpc_bus,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000671 .enable = i82801gx_enable,
672 .ops_pci = &pci_ops,
673};
674
Stefan Reinauer573f7d42009-07-21 21:50:34 +0000675/* 82801GH (ICH7 DH) */
676static const struct pci_driver ich7_dh_lpc __pci_driver = {
677 .ops = &device_ops,
678 .vendor = PCI_VENDOR_ID_INTEL,
679 .device = 0x27b0,
680};
681
Stefan Reinauer54309d62009-01-20 22:53:10 +0000682/* 82801GB/GR (ICH7/ICH7R) */
683static const struct pci_driver ich7_ich7r_lpc __pci_driver = {
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000684 .ops = &device_ops,
685 .vendor = PCI_VENDOR_ID_INTEL,
Uwe Hermann5d7a1c82008-10-31 18:41:09 +0000686 .device = 0x27b8,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000687};
688
Uwe Hermannbddc6932008-10-29 13:51:31 +0000689/* 82801GBM/GU (ICH7-M/ICH7-U) */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000690static const struct pci_driver ich7m_ich7u_lpc __pci_driver = {
691 .ops = &device_ops,
692 .vendor = PCI_VENDOR_ID_INTEL,
Uwe Hermann5d7a1c82008-10-31 18:41:09 +0000693 .device = 0x27b9,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000694};
695
Uwe Hermannbddc6932008-10-29 13:51:31 +0000696/* 82801GHM (ICH7-M DH) */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000697static const struct pci_driver ich7m_dh_lpc __pci_driver = {
698 .ops = &device_ops,
699 .vendor = PCI_VENDOR_ID_INTEL,
Uwe Hermann5d7a1c82008-10-31 18:41:09 +0000700 .device = 0x27bd,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000701};