blob: 8b9028baff80d932b88195da6215fc8dd3aa821e [file] [log] [blame]
Angel Ponsf94ac9a2020-04-05 15:46:48 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Duncan Lauriec88c54c2014-04-30 16:36:13 -07002
Kyösti Mälkki13f66502019-03-03 08:01:05 +02003#include <device/mmio.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02004#include <device/pci_ops.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -07005#include <device/pci_def.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -07006#include <soc/iomap.h>
7#include <soc/pci_devs.h>
8#include <soc/romstage.h>
9#include <soc/systemagent.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070010
Angel Pons6f448742020-10-13 14:05:18 +020011static void broadwell_setup_bars(void)
12{
13 /* Set up all hardcoded northbridge BARs */
Angel Pons29924b22021-06-15 13:55:03 +020014 pci_write_config32(HOST_BRIDGE, MCHBAR, CONFIG_FIXED_MCHBAR_MMIO_BASE | 1);
15 pci_write_config32(HOST_BRIDGE, DMIBAR, CONFIG_FIXED_DMIBAR_MMIO_BASE | 1);
16 pci_write_config32(HOST_BRIDGE, EPBAR, CONFIG_FIXED_EPBAR_MMIO_BASE | 1);
Angel Pons6f448742020-10-13 14:05:18 +020017
Angel Ponsa8753e92021-04-17 14:34:37 +020018 mchbar_write32(EDRAMBAR, EDRAM_BASE_ADDRESS | 1);
19 mchbar_write32(GDXCBAR, GDXC_BASE_ADDRESS | 1);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070020
21 /* Set C0000-FFFFF to access RAM on both reads and writes */
Angel Pons29924b22021-06-15 13:55:03 +020022 pci_write_config8(HOST_BRIDGE, PAM0, 0x30);
23 pci_write_config8(HOST_BRIDGE, PAM1, 0x33);
24 pci_write_config8(HOST_BRIDGE, PAM2, 0x33);
25 pci_write_config8(HOST_BRIDGE, PAM3, 0x33);
26 pci_write_config8(HOST_BRIDGE, PAM4, 0x33);
27 pci_write_config8(HOST_BRIDGE, PAM5, 0x33);
28 pci_write_config8(HOST_BRIDGE, PAM6, 0x33);
Angel Pons6f448742020-10-13 14:05:18 +020029}
Duncan Lauriec88c54c2014-04-30 16:36:13 -070030
31void systemagent_early_init(void)
32{
Matt DeVillier81a6f102018-02-19 17:33:48 -060033 const bool vtd_capable =
Angel Pons29924b22021-06-15 13:55:03 +020034 !(pci_read_config32(HOST_BRIDGE, CAPID0_A) & VTD_DISABLE);
Matt DeVillier81a6f102018-02-19 17:33:48 -060035
Angel Pons6f448742020-10-13 14:05:18 +020036 broadwell_setup_bars();
37
38 /* Device enable: IGD and Mini-HD */
Angel Pons29924b22021-06-15 13:55:03 +020039 pci_write_config32(HOST_BRIDGE, DEVEN, DEVEN_D0EN | DEVEN_D2EN | DEVEN_D3EN);
Matt DeVillier81a6f102018-02-19 17:33:48 -060040
41 if (vtd_capable) {
42 /* setup BARs: zeroize top 32 bits; set enable bit */
Angel Ponsa8753e92021-04-17 14:34:37 +020043 mchbar_write32(GFXVTBAR + 4, GFXVT_BASE_ADDRESS >> 32);
44 mchbar_write32(GFXVTBAR + 0, GFXVT_BASE_ADDRESS | 1);
45 mchbar_write32(VTVC0BAR + 4, VTVC0_BASE_ADDRESS >> 32);
46 mchbar_write32(VTVC0BAR + 0, VTVC0_BASE_ADDRESS | 1);
Matt DeVillier81a6f102018-02-19 17:33:48 -060047
48 /* set PRSCAPDIS, lock GFXVTBAR policy cfg registers */
49 u32 reg32;
Elyes Haouas878a99f2022-12-11 10:35:46 +010050 reg32 = read32p(GFXVT_BASE_ADDRESS + ARCHDIS);
51 write32p(GFXVT_BASE_ADDRESS + ARCHDIS,
Matt DeVillier81a6f102018-02-19 17:33:48 -060052 reg32 | DMAR_LCKDN | PRSCAPDIS);
53 /* lock VTVC0BAR policy cfg registers */
Elyes Haouas878a99f2022-12-11 10:35:46 +010054 reg32 = read32p(VTVC0_BASE_ADDRESS + ARCHDIS);
55 write32p(VTVC0_BASE_ADDRESS + ARCHDIS,
Matt DeVillier81a6f102018-02-19 17:33:48 -060056 reg32 | DMAR_LCKDN);
57 }
Duncan Lauriec88c54c2014-04-30 16:36:13 -070058}