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. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
| 20 | * MA 02110-1301 USA |
| 21 | */ |
| 22 | |
| 23 | #include <types.h> |
| 24 | #include <string.h> |
| 25 | #include <console/console.h> |
Stefan Reinauer | e5a0a5d | 2012-09-19 10:51:48 -0700 | [diff] [blame] | 26 | #include <arch/io.h> |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 27 | #include <arch/acpi.h> |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 28 | #include <device/device.h> |
| 29 | #include <device/pci.h> |
| 30 | #include <device/pci_ids.h> |
Stefan Reinauer | e5a0a5d | 2012-09-19 10:51:48 -0700 | [diff] [blame] | 31 | #include <build.h> |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 32 | #include "sandybridge.h" |
| 33 | |
| 34 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 35 | { |
| 36 | device_t dev; |
| 37 | u32 pciexbar = 0; |
| 38 | u32 pciexbar_reg; |
| 39 | int max_buses; |
| 40 | |
Stefan Reinauer | 6097e19 | 2012-06-11 15:38:15 -0700 | [diff] [blame] | 41 | dev = dev_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_SB, 0); |
| 42 | if (!dev) |
| 43 | 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] | 44 | if (!dev) |
| 45 | return current; |
| 46 | |
| 47 | pciexbar_reg=pci_read_config32(dev, PCIEXBAR); |
| 48 | |
| 49 | // MMCFG not supported or not enabled. |
| 50 | if (!(pciexbar_reg & (1 << 0))) |
| 51 | return current; |
| 52 | |
| 53 | switch ((pciexbar_reg >> 1) & 3) { |
| 54 | case 0: // 256MB |
| 55 | pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)); |
| 56 | max_buses = 256; |
| 57 | break; |
| 58 | case 1: // 128M |
| 59 | pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27)); |
| 60 | max_buses = 128; |
| 61 | break; |
| 62 | case 2: // 64M |
| 63 | pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27)|(1 << 26)); |
| 64 | max_buses = 64; |
| 65 | break; |
| 66 | default: // RSVD |
| 67 | return current; |
| 68 | } |
| 69 | |
| 70 | if (!pciexbar) |
| 71 | return current; |
| 72 | |
| 73 | current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *) current, |
| 74 | pciexbar, 0x0, 0x0, max_buses - 1); |
| 75 | |
| 76 | return current; |
| 77 | } |
| 78 | |
Stefan Reinauer | e5a0a5d | 2012-09-19 10:51:48 -0700 | [diff] [blame] | 79 | static void *get_intel_vbios(void) |
| 80 | { |
| 81 | /* This should probably be looking at CBFS or we should always |
| 82 | * deploy the VBIOS on Intel systems, even if we don't run it |
| 83 | * in coreboot (e.g. SeaBIOS only scenarios). |
| 84 | */ |
| 85 | u8 *vbios = (u8 *)0xc0000; |
| 86 | |
| 87 | optionrom_header_t *oprom = (optionrom_header_t *)vbios; |
| 88 | optionrom_pcir_t *pcir = (optionrom_pcir_t *)(vbios + |
| 89 | oprom->pcir_offset); |
| 90 | |
| 91 | |
| 92 | printk(BIOS_DEBUG, "GET_VBIOS: %x %x %x %x %x\n", |
| 93 | oprom->signature, pcir->vendor, pcir->classcode[0], |
| 94 | pcir->classcode[1], pcir->classcode[2]); |
| 95 | |
| 96 | |
| 97 | if ((oprom->signature == OPROM_SIGNATURE) && |
| 98 | (pcir->vendor == PCI_VENDOR_ID_INTEL) && |
| 99 | (pcir->classcode[0] == 0x00) && |
| 100 | (pcir->classcode[1] == 0x00) && |
| 101 | (pcir->classcode[2] == 0x03)) |
| 102 | return (void *)vbios; |
| 103 | |
| 104 | return NULL; |
| 105 | } |
| 106 | |
| 107 | static int init_opregion_vbt(igd_opregion_t *opregion) |
| 108 | { |
| 109 | void *vbios; |
| 110 | vbios = get_intel_vbios(); |
| 111 | if (!vbios) { |
| 112 | printk(BIOS_DEBUG, "VBIOS not found.\n"); |
| 113 | return 1; |
| 114 | } |
| 115 | |
| 116 | printk(BIOS_DEBUG, " ... VBIOS found at %p\n", vbios); |
| 117 | optionrom_header_t *oprom = (optionrom_header_t *)vbios; |
| 118 | optionrom_vbt_t *vbt = (optionrom_vbt_t *)(vbios + |
| 119 | oprom->vbt_offset); |
| 120 | |
| 121 | if (read32((unsigned long)vbt->hdr_signature) != VBT_SIGNATURE) { |
| 122 | printk(BIOS_DEBUG, "VBT not found!\n"); |
| 123 | return 1; |
| 124 | } |
| 125 | |
| 126 | memcpy(opregion->header.vbios_version, vbt->coreblock_biosbuild, 4); |
| 127 | memcpy(opregion->vbt.gvd1, vbt, vbt->hdr_vbt_size < 7168 ? |
| 128 | vbt->hdr_vbt_size : 7168); |
| 129 | |
| 130 | return 0; |
| 131 | } |
| 132 | |
| 133 | |
| 134 | /* Initialize IGD OpRegion, called from ACPI code */ |
| 135 | int init_igd_opregion(igd_opregion_t *opregion) |
| 136 | { |
| 137 | device_t igd; |
| 138 | u16 reg16; |
| 139 | |
| 140 | memset((void *)opregion, 0, sizeof(igd_opregion_t)); |
| 141 | |
| 142 | // FIXME if IGD is disabled, we should exit here. |
| 143 | |
| 144 | memcpy(&opregion->header.signature, IGD_OPREGION_SIGNATURE, |
Edward O'Callaghan | 2b48b65 | 2014-08-03 23:38:17 +1000 | [diff] [blame^] | 145 | sizeof(opregion->header.signature)); |
Stefan Reinauer | e5a0a5d | 2012-09-19 10:51:48 -0700 | [diff] [blame] | 146 | |
| 147 | /* 8kb */ |
| 148 | opregion->header.size = sizeof(igd_opregion_t) / 1024; |
| 149 | opregion->header.version = IGD_OPREGION_VERSION; |
| 150 | |
| 151 | // FIXME We just assume we're mobile for now |
| 152 | opregion->header.mailboxes = MAILBOXES_MOBILE; |
| 153 | |
| 154 | // TODO Initialize Mailbox 1 |
| 155 | |
| 156 | // TODO Initialize Mailbox 3 |
| 157 | opregion->mailbox3.bclp = IGD_BACKLIGHT_BRIGHTNESS; |
| 158 | opregion->mailbox3.pfit = IGD_FIELD_VALID | IGD_PFIT_STRETCH; |
| 159 | opregion->mailbox3.pcft = 0; // should be (IMON << 1) & 0x3e |
| 160 | opregion->mailbox3.cblv = IGD_FIELD_VALID | IGD_INITIAL_BRIGHTNESS; |
| 161 | opregion->mailbox3.bclm[0] = IGD_WORD_FIELD_VALID + 0x0000; |
| 162 | opregion->mailbox3.bclm[1] = IGD_WORD_FIELD_VALID + 0x0a19; |
| 163 | opregion->mailbox3.bclm[2] = IGD_WORD_FIELD_VALID + 0x1433; |
| 164 | opregion->mailbox3.bclm[3] = IGD_WORD_FIELD_VALID + 0x1e4c; |
| 165 | opregion->mailbox3.bclm[4] = IGD_WORD_FIELD_VALID + 0x2866; |
| 166 | opregion->mailbox3.bclm[5] = IGD_WORD_FIELD_VALID + 0x327f; |
| 167 | opregion->mailbox3.bclm[6] = IGD_WORD_FIELD_VALID + 0x3c99; |
| 168 | opregion->mailbox3.bclm[7] = IGD_WORD_FIELD_VALID + 0x46b2; |
| 169 | opregion->mailbox3.bclm[8] = IGD_WORD_FIELD_VALID + 0x50cc; |
| 170 | opregion->mailbox3.bclm[9] = IGD_WORD_FIELD_VALID + 0x5ae5; |
| 171 | opregion->mailbox3.bclm[10] = IGD_WORD_FIELD_VALID + 0x64ff; |
| 172 | |
| 173 | init_opregion_vbt(opregion); |
| 174 | |
| 175 | /* TODO This needs to happen in S3 resume, too. |
| 176 | * Maybe it should move to the finalize handler |
| 177 | */ |
| 178 | igd = dev_find_slot(0, PCI_DEVFN(0x2, 0)); |
| 179 | |
| 180 | pci_write_config32(igd, ASLS, (u32)opregion); |
| 181 | reg16 = pci_read_config16(igd, SWSCI); |
| 182 | reg16 &= ~(1 << 0); |
| 183 | reg16 |= (1 << 15); |
| 184 | pci_write_config16(igd, SWSCI, reg16); |
| 185 | |
| 186 | /* clear dmisci status */ |
| 187 | reg16 = inw(DEFAULT_PMBASE + TCO1_STS); |
| 188 | reg16 |= DMISCI_STS; // reference code does an &= |
| 189 | outw(DEFAULT_PMBASE + TCO1_STS, reg16); |
| 190 | |
| 191 | /* clear acpi tco status */ |
| 192 | outl(DEFAULT_PMBASE + GPE0_STS, TCOSCI_STS); |
| 193 | |
| 194 | /* enable acpi tco scis */ |
| 195 | reg16 = inw(DEFAULT_PMBASE + GPE0_EN); |
| 196 | reg16 |= TCOSCI_EN; |
| 197 | outw(DEFAULT_PMBASE + GPE0_EN, reg16); |
| 198 | |
| 199 | return 0; |
| 200 | } |