blob: 3168f47756cd4cc8fbb84c4e53c2fc4163085dd8 [file] [log] [blame]
Angel Pons585495e2020-04-03 01:21:38 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Martin Rothb28f4662018-05-26 17:58:47 -06002
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02003#include <device/pci_ops.h>
Patrick Rudolph1af89232018-11-11 12:50:51 +01004#include <bootblock_common.h>
5#include <southbridge/intel/i82801ix/i82801ix.h>
Patrick Rudolphfbdeb4a2019-02-14 19:47:03 +01006#include <console/console.h>
Kyösti Mälkkib9646a22013-07-03 08:06:32 +03007
8/* Just define these here, there is no gm35.h file to include. */
9#define D0F0_PCIEXBAR_LO 0x60
10#define D0F0_PCIEXBAR_HI 0x64
11
12static void bootblock_northbridge_init(void)
13{
14 uint32_t reg;
15
16 /*
17 * The "io" variant of the config access is explicitly used to
Kyösti Mälkki6f66f412016-12-01 22:08:18 +020018 * setup the PCIEXBAR because CONFIG_MMCONF_SUPPORT is set to
Kyösti Mälkkib9646a22013-07-03 08:06:32 +030019 * to true. That way all subsequent non-explicit config accesses use
20 * MCFG. This code also assumes that bootblock_northbridge_init() is
21 * the first thing called in the non-asm boot block code. The final
22 * assumption is that no assembly code is using the
Kyösti Mälkki6f66f412016-12-01 22:08:18 +020023 * CONFIG_MMCONF_SUPPORT option to do PCI config acceses.
Kyösti Mälkkib9646a22013-07-03 08:06:32 +030024 *
25 * The PCIEXBAR is assumed to live in the memory mapped IO space under
26 * 4GiB.
27 */
28 reg = 0;
29 pci_io_write_config32(PCI_DEV(0,0,0), D0F0_PCIEXBAR_HI, reg);
30 reg = CONFIG_MMCONF_BASE_ADDRESS | 1; /* 256MiB - 0-255 buses. */
31 pci_io_write_config32(PCI_DEV(0,0,0), D0F0_PCIEXBAR_LO, reg);
Patrick Rudolphfbdeb4a2019-02-14 19:47:03 +010032
33 /* MCFG is now active. If it's not qemu was started for machine PC */
34 if (CONFIG(BOOTBLOCK_CONSOLE) &&
35 (pci_read_config32(PCI_DEV(0, 0, 0), D0F0_PCIEXBAR_LO) !=
36 (CONFIG_MMCONF_BASE_ADDRESS | 1)))
37 die("You must run qemu for machine Q35 (-M q35)");
Kyösti Mälkkib9646a22013-07-03 08:06:32 +030038}
39
Patrick Rudolph1af89232018-11-11 12:50:51 +010040static void enable_spi_prefetch(void)
41{
42 u8 reg8;
Elyes HAOUASa4faec32020-04-22 16:49:28 +020043 const pci_devfn_t dev = PCI_DEV(0, 0x1f, 0);
Patrick Rudolph1af89232018-11-11 12:50:51 +010044
45 reg8 = pci_read_config8(dev, 0xdc);
46 reg8 &= ~(3 << 2);
47 reg8 |= (2 << 2); /* Prefetching and Caching Enabled */
48 pci_write_config8(dev, 0xdc, reg8);
49}
50
51static void bootblock_southbridge_init(void)
52{
53 enable_spi_prefetch();
54
55 /* Enable RCBA */
Peter Lemenkov7b428112018-10-23 11:12:46 +020056 pci_write_config32(PCI_DEV(0, 0x1f, 0), RCBA,
Patrick Rudolph1af89232018-11-11 12:50:51 +010057 (uintptr_t)DEFAULT_RCBA | 1);
58}
59
60void bootblock_soc_init(void)
Kyösti Mälkkib9646a22013-07-03 08:06:32 +030061{
62 bootblock_northbridge_init();
63 bootblock_southbridge_init();
64}