| 1 |
|
| 2 |
|
| 3 |
#include <console/console.h> |
| 4 |
#include <device/mmio.h> |
| 5 |
#include <device/device.h> |
| 6 |
#include <device/pci_ops.h> |
| 7 |
#include <device/pci_def.h> |
| 8 |
#include <option.h> |
| 9 |
#include <types.h> |
| 10 |
|
| 11 |
#include "sandybridge.h" |
| 12 |
|
| 13 |
static void systemagent_vtd_init(void) |
| 14 |
{ |
| 15 |
const u32 capid0_a = pci_read_config32(HOST_BRIDGE, CAPID0_A); |
| 16 |
if (capid0_a & (1 << 23)) |
| 17 |
return; |
| 18 |
|
| 19 |
|
| 20 |
mchbar_write32(GFXVTBAR + 4, GFXVT_BASE >> 32); |
| 21 |
mchbar_write32(GFXVTBAR + 0, GFXVT_BASE | 1); |
| 22 |
mchbar_write32(VTVC0BAR + 4, VTVC0_BASE >> 32); |
| 23 |
mchbar_write32(VTVC0BAR + 0, VTVC0_BASE | 1); |
| 24 |
|
| 25 |
|
| 26 |
write32p(GFXVT_BASE + 0xff0, 0x80000000); |
| 27 |
|
| 28 |
const struct device *const azalia = pcidev_on_root(0x1b, 0); |
| 29 |
if (azalia && azalia->enabled) { |
| 30 |
write32p(VTVC0_BASE + 0xff0, 0x20000000); |
| 31 |
write32p(VTVC0_BASE + 0xff0, 0xa0000000); |
| 32 |
} else { |
| 33 |
write32p(VTVC0_BASE + 0xff0, 0x80000000); |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
static void enable_pam_region(void) |
| 38 |
{ |
| 39 |
pci_write_config8(HOST_BRIDGE, PAM0, 0x30); |
| 40 |
pci_write_config8(HOST_BRIDGE, PAM1, 0x33); |
| 41 |
pci_write_config8(HOST_BRIDGE, PAM2, 0x33); |
| 42 |
pci_write_config8(HOST_BRIDGE, PAM3, 0x33); |
| 43 |
pci_write_config8(HOST_BRIDGE, PAM4, 0x33); |
| 44 |
pci_write_config8(HOST_BRIDGE, PAM5, 0x33); |
| 45 |
pci_write_config8(HOST_BRIDGE, PAM6, 0x33); |
| 46 |
} |
| 47 |
|
| 48 |
static void sandybridge_setup_bars(void) |
| 49 |
{ |
| 50 |
printk(BIOS_DEBUG, "Setting up static northbridge registers..."); |
| 51 |
|
| 52 |
pci_write_config32(HOST_BRIDGE, EPBAR, CONFIG_FIXED_EPBAR_MMIO_BASE | 1); |
| 53 |
pci_write_config32(HOST_BRIDGE, EPBAR + 4, 0); |
| 54 |
pci_write_config32(HOST_BRIDGE, MCHBAR, CONFIG_FIXED_MCHBAR_MMIO_BASE | 1); |
| 55 |
pci_write_config32(HOST_BRIDGE, MCHBAR + 4, 0); |
| 56 |
pci_write_config32(HOST_BRIDGE, DMIBAR, CONFIG_FIXED_DMIBAR_MMIO_BASE | 1); |
| 57 |
pci_write_config32(HOST_BRIDGE, DMIBAR + 4, 0); |
| 58 |
|
| 59 |
printk(BIOS_DEBUG, " done\n"); |
| 60 |
} |
| 61 |
|
| 62 |
static void sandybridge_setup_graphics(void) |
| 63 |
{ |
| 64 |
u16 reg16; |
| 65 |
u8 gfxsize; |
| 66 |
|
| 67 |
reg16 = pci_read_config16(PCI_DEV(0, 2, 0), PCI_DEVICE_ID); |
| 68 |
switch (reg16) { |
| 69 |
case 0x0102: |
| 70 |
case 0x0106: |
| 71 |
case 0x010a: |
| 72 |
case 0x0112: |
| 73 |
case 0x0116: |
| 74 |
case 0x0122: |
| 75 |
case 0x0126: |
| 76 |
case 0x0152: |
| 77 |
case 0x0156: |
| 78 |
case 0x0162: |
| 79 |
case 0x0166: |
| 80 |
case 0x016a: |
| 81 |
break; |
| 82 |
default: |
| 83 |
printk(BIOS_DEBUG, "Graphics not supported by this CPU/chipset.\n"); |
| 84 |
return; |
| 85 |
} |
| 86 |
|
| 87 |
printk(BIOS_DEBUG, "Initializing Graphics...\n"); |
| 88 |
|
| 89 |
|
| 90 |
gfxsize = get_uint_option("gfx_uma_size", CONFIG_IGD_DEFAULT_UMA_INDEX); |
| 91 |
|
| 92 |
|
| 93 |
reg16 = pci_read_config16(HOST_BRIDGE, GGC); |
| 94 |
reg16 &= ~0x00f8; |
| 95 |
reg16 |= (gfxsize + 1) << 3; |
| 96 |
|
| 97 |
reg16 &= ~0x0300; |
| 98 |
reg16 |= 2 << 8; |
| 99 |
|
| 100 |
reg16 &= ~0x0002; |
| 101 |
pci_write_config16(HOST_BRIDGE, GGC, reg16); |
| 102 |
|
| 103 |
|
| 104 |
pci_update_config8(PCI_DEV(0, 2, 0), MSAC, ~0x06, 0x02); |
| 105 |
|
| 106 |
|
| 107 |
mchbar_setbits32(SAPMCTL, 1 << 9 | 1 << 10); |
| 108 |
|
| 109 |
|
| 110 |
mchbar_setbits32(SAPMCTL, 1 << 0); |
| 111 |
|
| 112 |
|
| 113 |
mchbar_setbits32(SSKPD_HI, 1 << 31); |
| 114 |
|
| 115 |
|
| 116 |
mchbar_clrbits32(0x6120, 1 << 0); |
| 117 |
|
| 118 |
mchbar_setbits32(INTRDIRCTL, 1 << 4 | 1 << 5); |
| 119 |
} |
| 120 |
|
| 121 |
static void start_peg_link_training(void) |
| 122 |
{ |
| 123 |
u32 deven; |
| 124 |
|
| 125 |
const u16 base_rev = pci_read_config16(HOST_BRIDGE, PCI_DEVICE_ID) & BASE_REV_MASK; |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
if ((base_rev != BASE_REV_IVB) || CONFIG(HAVE_MRC)) |
| 131 |
return; |
| 132 |
|
| 133 |
deven = pci_read_config32(HOST_BRIDGE, DEVEN); |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
if (deven & DEVEN_PEG10) |
| 140 |
pci_update_config32(PCI_DEV(0, 1, 0), AFE_PWRON, ~(1 << 16), 1 << 5); |
| 141 |
|
| 142 |
if (deven & DEVEN_PEG11) |
| 143 |
pci_update_config32(PCI_DEV(0, 1, 1), AFE_PWRON, ~(1 << 16), 1 << 5); |
| 144 |
|
| 145 |
if (deven & DEVEN_PEG12) |
| 146 |
pci_update_config32(PCI_DEV(0, 1, 2), AFE_PWRON, ~(1 << 16), 1 << 5); |
| 147 |
|
| 148 |
if (deven & DEVEN_PEG60) |
| 149 |
pci_update_config32(PCI_DEV(0, 6, 0), AFE_PWRON, ~(1 << 16), 1 << 5); |
| 150 |
} |
| 151 |
|
| 152 |
void systemagent_early_init(void) |
| 153 |
{ |
| 154 |
const size_t is_mobile = get_platform_type() == PLATFORM_MOBILE; |
| 155 |
u32 capid0_a; |
| 156 |
u8 reg8; |
| 157 |
|
| 158 |
|
| 159 |
capid0_a = pci_read_config32(HOST_BRIDGE, CAPID0_A); |
| 160 |
if (capid0_a & (1 << 10)) { |
| 161 |
reg8 = pci_read_config8(HOST_BRIDGE, DIDOR); |
| 162 |
reg8 &= ~7; |
| 163 |
|
| 164 |
if (is_mobile) |
| 165 |
reg8 |= 1; |
| 166 |
|
| 167 |
pci_write_config8(HOST_BRIDGE, DIDOR, reg8); |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
printk(BIOS_INFO, "Detected system type: %s\n", is_mobile ? "mobile" : "desktop"); |
| 172 |
|
| 173 |
|
| 174 |
sandybridge_setup_bars(); |
| 175 |
|
| 176 |
|
| 177 |
enable_pam_region(); |
| 178 |
|
| 179 |
|
| 180 |
systemagent_vtd_init(); |
| 181 |
|
| 182 |
|
| 183 |
pci_or_config32(HOST_BRIDGE, DEVEN, DEVEN_IGD); |
| 184 |
|
| 185 |
sandybridge_setup_graphics(); |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
start_peg_link_training(); |
| 196 |
} |
| 197 |
|
| 198 |
void northbridge_romstage_finalize(void) |
| 199 |
{ |
| 200 |
mchbar_write16(SSKPD_HI, 0xcafe); |
| 201 |
} |