blob: 4953144349ee41859addc48318a14e1806232b94 [file] [log] [blame]
Stefan Reinauer00636b02012-04-04 00:08:51 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2007-2009 coresystems GmbH
Stefan Reinauere5a0a5d2012-09-19 10:51:48 -07005 * Copyright (C) 2012 The Chromium OS Authors
Stefan Reinauer00636b02012-04-04 00:08:51 +02006 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; version 2 of
10 * 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.
Stefan Reinauer00636b02012-04-04 00:08:51 +020016 */
17
18#include <types.h>
19#include <string.h>
20#include <console/console.h>
Stefan Reinauere5a0a5d2012-09-19 10:51:48 -070021#include <arch/io.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020022#include <arch/acpi.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020023#include <device/device.h>
24#include <device/pci.h>
25#include <device/pci_ids.h>
Vladimir Serbinenko35c0f432014-09-02 22:25:36 +020026#include <drivers/intel/gma/i915.h>
27#include <arch/acpigen.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020028#include "sandybridge.h"
Vladimir Serbinenko35c0f432014-09-02 22:25:36 +020029#include <cbmem.h>
Vladimir Serbinenkoa71bdc32014-08-30 00:35:39 +020030#include <drivers/intel/gma/intel_bios.h>
Nico Huber9d9ce0d2015-10-26 12:59:49 +010031#include <southbridge/intel/bd82x6x/pch.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020032
33unsigned long acpi_fill_mcfg(unsigned long current)
34{
35 device_t dev;
36 u32 pciexbar = 0;
37 u32 pciexbar_reg;
38 int max_buses;
39
Stefan Reinauer6097e192012-06-11 15:38:15 -070040 dev = dev_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_SB, 0);
41 if (!dev)
42 dev = dev_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_IB, 0);
Stefan Reinauer00636b02012-04-04 00:08:51 +020043 if (!dev)
44 return current;
45
46 pciexbar_reg=pci_read_config32(dev, PCIEXBAR);
47
48 // MMCFG not supported or not enabled.
49 if (!(pciexbar_reg & (1 << 0)))
50 return current;
51
52 switch ((pciexbar_reg >> 1) & 3) {
53 case 0: // 256MB
54 pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28));
55 max_buses = 256;
56 break;
57 case 1: // 128M
58 pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
59 max_buses = 128;
60 break;
61 case 2: // 64M
62 pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27)|(1 << 26));
63 max_buses = 64;
64 break;
65 default: // RSVD
66 return current;
67 }
68
69 if (!pciexbar)
70 return current;
71
72 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *) current,
73 pciexbar, 0x0, 0x0, max_buses - 1);
74
75 return current;
76}
77
Stefan Reinauere5a0a5d2012-09-19 10:51:48 -070078static void *get_intel_vbios(void)
79{
80 /* This should probably be looking at CBFS or we should always
81 * deploy the VBIOS on Intel systems, even if we don't run it
82 * in coreboot (e.g. SeaBIOS only scenarios).
83 */
84 u8 *vbios = (u8 *)0xc0000;
85
86 optionrom_header_t *oprom = (optionrom_header_t *)vbios;
87 optionrom_pcir_t *pcir = (optionrom_pcir_t *)(vbios +
88 oprom->pcir_offset);
89
90
91 printk(BIOS_DEBUG, "GET_VBIOS: %x %x %x %x %x\n",
92 oprom->signature, pcir->vendor, pcir->classcode[0],
93 pcir->classcode[1], pcir->classcode[2]);
94
95
96 if ((oprom->signature == OPROM_SIGNATURE) &&
97 (pcir->vendor == PCI_VENDOR_ID_INTEL) &&
98 (pcir->classcode[0] == 0x00) &&
99 (pcir->classcode[1] == 0x00) &&
100 (pcir->classcode[2] == 0x03))
101 return (void *)vbios;
102
103 return NULL;
104}
105
106static int init_opregion_vbt(igd_opregion_t *opregion)
107{
108 void *vbios;
109 vbios = get_intel_vbios();
110 if (!vbios) {
111 printk(BIOS_DEBUG, "VBIOS not found.\n");
112 return 1;
113 }
114
115 printk(BIOS_DEBUG, " ... VBIOS found at %p\n", vbios);
116 optionrom_header_t *oprom = (optionrom_header_t *)vbios;
117 optionrom_vbt_t *vbt = (optionrom_vbt_t *)(vbios +
118 oprom->vbt_offset);
119
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800120 if (read32(vbt->hdr_signature) != VBT_SIGNATURE) {
Stefan Reinauere5a0a5d2012-09-19 10:51:48 -0700121 printk(BIOS_DEBUG, "VBT not found!\n");
122 return 1;
123 }
124
125 memcpy(opregion->header.vbios_version, vbt->coreblock_biosbuild, 4);
126 memcpy(opregion->vbt.gvd1, vbt, vbt->hdr_vbt_size < 7168 ?
127 vbt->hdr_vbt_size : 7168);
128
129 return 0;
130}
131
132
133/* Initialize IGD OpRegion, called from ACPI code */
134int init_igd_opregion(igd_opregion_t *opregion)
135{
136 device_t igd;
137 u16 reg16;
138
139 memset((void *)opregion, 0, sizeof(igd_opregion_t));
140
141 // FIXME if IGD is disabled, we should exit here.
142
143 memcpy(&opregion->header.signature, IGD_OPREGION_SIGNATURE,
Edward O'Callaghan2b48b652014-08-03 23:38:17 +1000144 sizeof(opregion->header.signature));
Stefan Reinauere5a0a5d2012-09-19 10:51:48 -0700145
146 /* 8kb */
147 opregion->header.size = sizeof(igd_opregion_t) / 1024;
148 opregion->header.version = IGD_OPREGION_VERSION;
149
150 // FIXME We just assume we're mobile for now
151 opregion->header.mailboxes = MAILBOXES_MOBILE;
152
153 // TODO Initialize Mailbox 1
154
155 // TODO Initialize Mailbox 3
156 opregion->mailbox3.bclp = IGD_BACKLIGHT_BRIGHTNESS;
157 opregion->mailbox3.pfit = IGD_FIELD_VALID | IGD_PFIT_STRETCH;
158 opregion->mailbox3.pcft = 0; // should be (IMON << 1) & 0x3e
159 opregion->mailbox3.cblv = IGD_FIELD_VALID | IGD_INITIAL_BRIGHTNESS;
160 opregion->mailbox3.bclm[0] = IGD_WORD_FIELD_VALID + 0x0000;
161 opregion->mailbox3.bclm[1] = IGD_WORD_FIELD_VALID + 0x0a19;
162 opregion->mailbox3.bclm[2] = IGD_WORD_FIELD_VALID + 0x1433;
163 opregion->mailbox3.bclm[3] = IGD_WORD_FIELD_VALID + 0x1e4c;
164 opregion->mailbox3.bclm[4] = IGD_WORD_FIELD_VALID + 0x2866;
165 opregion->mailbox3.bclm[5] = IGD_WORD_FIELD_VALID + 0x327f;
166 opregion->mailbox3.bclm[6] = IGD_WORD_FIELD_VALID + 0x3c99;
167 opregion->mailbox3.bclm[7] = IGD_WORD_FIELD_VALID + 0x46b2;
168 opregion->mailbox3.bclm[8] = IGD_WORD_FIELD_VALID + 0x50cc;
169 opregion->mailbox3.bclm[9] = IGD_WORD_FIELD_VALID + 0x5ae5;
170 opregion->mailbox3.bclm[10] = IGD_WORD_FIELD_VALID + 0x64ff;
171
172 init_opregion_vbt(opregion);
173
174 /* TODO This needs to happen in S3 resume, too.
175 * Maybe it should move to the finalize handler
176 */
177 igd = dev_find_slot(0, PCI_DEVFN(0x2, 0));
178
179 pci_write_config32(igd, ASLS, (u32)opregion);
180 reg16 = pci_read_config16(igd, SWSCI);
181 reg16 &= ~(1 << 0);
182 reg16 |= (1 << 15);
183 pci_write_config16(igd, SWSCI, reg16);
184
185 /* clear dmisci status */
186 reg16 = inw(DEFAULT_PMBASE + TCO1_STS);
187 reg16 |= DMISCI_STS; // reference code does an &=
188 outw(DEFAULT_PMBASE + TCO1_STS, reg16);
189
190 /* clear acpi tco status */
191 outl(DEFAULT_PMBASE + GPE0_STS, TCOSCI_STS);
192
193 /* enable acpi tco scis */
194 reg16 = inw(DEFAULT_PMBASE + GPE0_EN);
195 reg16 |= TCOSCI_EN;
196 outw(DEFAULT_PMBASE + GPE0_EN, reg16);
197
198 return 0;
199}
Vladimir Serbinenko35c0f432014-09-02 22:25:36 +0200200
201void *igd_make_opregion(void)
202{
203 igd_opregion_t *opregion;
204
205 printk(BIOS_DEBUG, "ACPI: * IGD OpRegion\n");
206 opregion = cbmem_add(CBMEM_ID_IGD_OPREGION, sizeof (*opregion));
207 if (opregion)
208 init_igd_opregion(opregion);
209 return opregion;
210}
Nico Huber9d9ce0d2015-10-26 12:59:49 +0100211
212static unsigned long acpi_fill_dmar(unsigned long current)
213{
214 const struct device *const igfx = dev_find_slot(0, PCI_DEVFN(2, 0));
215
216 if (igfx && igfx->enabled) {
217 const unsigned long tmp = current;
218 current += acpi_create_dmar_drhd(current, 0, 0, IOMMU_BASE1);
219 current += acpi_create_dmar_drhd_ds_pci(current, 0, 2, 0);
220 current += acpi_create_dmar_drhd_ds_pci(current, 0, 2, 1);
221 acpi_dmar_drhd_fixup(tmp, current);
222 }
223
224 const unsigned long tmp = current;
225 current += acpi_create_dmar_drhd(current,
226 DRHD_INCLUDE_PCI_ALL, 0, IOMMU_BASE2);
227 current += acpi_create_dmar_drhd_ds_ioapic(current,
228 2, PCH_IOAPIC_PCI_BUS, PCH_IOAPIC_PCI_SLOT, 0);
229 size_t i;
230 for (i = 0; i < 8; ++i)
231 current += acpi_create_dmar_drhd_ds_msi_hpet(current,
232 0, PCH_HPET_PCI_BUS, PCH_HPET_PCI_SLOT, i);
233 acpi_dmar_drhd_fixup(tmp, current);
234
235 return current;
236}
237
Nico Huber9d9ce0d2015-10-26 12:59:49 +0100238unsigned long northbridge_write_acpi_tables(struct device *const dev,
239 unsigned long current,
240 struct acpi_rsdp *const rsdp)
241{
242 const u32 capid0_a = pci_read_config32(dev, 0xe4);
243 if (capid0_a & (1 << 23))
244 return current;
245
246 printk(BIOS_DEBUG, "ACPI: * DMAR\n");
247 acpi_dmar_t *const dmar = (acpi_dmar_t *)current;
248 acpi_create_dmar(dmar, DMAR_INTR_REMAP, acpi_fill_dmar);
249 current += dmar->header.length;
Aaron Durbin07a1b282015-12-10 17:07:38 -0600250 current = acpi_align_current(current);
Nico Huber9d9ce0d2015-10-26 12:59:49 +0100251 acpi_add_table(rsdp, dmar);
252
Aaron Durbin07a1b282015-12-10 17:07:38 -0600253 current = acpi_align_current(current);
Nico Huber9d9ce0d2015-10-26 12:59:49 +0100254
255 printk(BIOS_DEBUG, "current = %lx\n", current);
256
257 return current;
258}