Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2007-2009 coresystems GmbH |
Stefan Reinauer | e5a0a5d | 2012-09-19 10:51:48 -0700 | [diff] [blame] | 5 | * Copyright (C) 2012 The Chromium OS Authors |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 6 | * |
| 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 Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include <types.h> |
| 19 | #include <string.h> |
| 20 | #include <console/console.h> |
Stefan Reinauer | e5a0a5d | 2012-09-19 10:51:48 -0700 | [diff] [blame] | 21 | #include <arch/io.h> |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 22 | #include <arch/acpi.h> |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 23 | #include <device/device.h> |
| 24 | #include <device/pci.h> |
| 25 | #include <device/pci_ids.h> |
Vladimir Serbinenko | 35c0f43 | 2014-09-02 22:25:36 +0200 | [diff] [blame] | 26 | #include <drivers/intel/gma/i915.h> |
| 27 | #include <arch/acpigen.h> |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 28 | #include "sandybridge.h" |
Vladimir Serbinenko | 35c0f43 | 2014-09-02 22:25:36 +0200 | [diff] [blame] | 29 | #include <cbmem.h> |
Vladimir Serbinenko | a71bdc3 | 2014-08-30 00:35:39 +0200 | [diff] [blame] | 30 | #include <drivers/intel/gma/intel_bios.h> |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame^] | 31 | #include <southbridge/intel/bd82x6x/pch.h> |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 32 | |
| 33 | unsigned 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 Reinauer | 6097e19 | 2012-06-11 15:38:15 -0700 | [diff] [blame] | 40 | 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 Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 43 | 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 Reinauer | e5a0a5d | 2012-09-19 10:51:48 -0700 | [diff] [blame] | 78 | static 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 | |
| 106 | static 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 Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 120 | if (read32(vbt->hdr_signature) != VBT_SIGNATURE) { |
Stefan Reinauer | e5a0a5d | 2012-09-19 10:51:48 -0700 | [diff] [blame] | 121 | 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 */ |
| 134 | int 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'Callaghan | 2b48b65 | 2014-08-03 23:38:17 +1000 | [diff] [blame] | 144 | sizeof(opregion->header.signature)); |
Stefan Reinauer | e5a0a5d | 2012-09-19 10:51:48 -0700 | [diff] [blame] | 145 | |
| 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 Serbinenko | 35c0f43 | 2014-09-02 22:25:36 +0200 | [diff] [blame] | 200 | |
| 201 | void *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 Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame^] | 211 | |
| 212 | static 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 | |
| 238 | #define ALIGN_CURRENT current = (ALIGN(current, 16)) |
| 239 | unsigned long northbridge_write_acpi_tables(struct device *const dev, |
| 240 | unsigned long current, |
| 241 | struct acpi_rsdp *const rsdp) |
| 242 | { |
| 243 | const u32 capid0_a = pci_read_config32(dev, 0xe4); |
| 244 | if (capid0_a & (1 << 23)) |
| 245 | return current; |
| 246 | |
| 247 | printk(BIOS_DEBUG, "ACPI: * DMAR\n"); |
| 248 | acpi_dmar_t *const dmar = (acpi_dmar_t *)current; |
| 249 | acpi_create_dmar(dmar, DMAR_INTR_REMAP, acpi_fill_dmar); |
| 250 | current += dmar->header.length; |
| 251 | ALIGN_CURRENT; |
| 252 | acpi_add_table(rsdp, dmar); |
| 253 | |
| 254 | ALIGN_CURRENT; |
| 255 | |
| 256 | printk(BIOS_DEBUG, "current = %lx\n", current); |
| 257 | |
| 258 | return current; |
| 259 | } |