blob: 8c851cac5dee1bdfe82f14e0e9fa9efe8554d110 [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älkkide640782019-12-03 07:30:26 +02003#include <arch/bootblock.h>
Angel Pons9debbd62021-01-28 12:42:53 +01004#include <assert.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02005#include <device/pci_ops.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -07006#include <soc/pci_devs.h>
7#include <soc/systemagent.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -07008
Angel Pons9debbd62021-01-28 12:42:53 +01009static uint32_t encode_pciexbar_length(void)
10{
Shelley Chen4e9bb332021-10-20 15:43:45 -070011 switch (CONFIG_ECAM_MMCONF_BUS_NUMBER) {
Angel Pons9debbd62021-01-28 12:42:53 +010012 case 256: return 0 << 1;
13 case 128: return 1 << 1;
14 case 64: return 2 << 1;
15 default: return dead_code_t(uint32_t);
16 }
17}
18
Arthur Heymans5bb15f12018-12-22 16:02:25 +010019void bootblock_early_northbridge_init(void)
Duncan Lauriec88c54c2014-04-30 16:36:13 -070020{
Duncan Lauriec88c54c2014-04-30 16:36:13 -070021 /*
Angel Pons9debbd62021-01-28 12:42:53 +010022 * The "io" variant of the config access is explicitly used to setup the
Shelley Chen4e9bb332021-10-20 15:43:45 -070023 * PCIEXBAR because CONFIG(ECAM_MMCONF_SUPPORT) is set to true. That way, all
Angel Pons9debbd62021-01-28 12:42:53 +010024 * subsequent non-explicit config accesses use MCFG. This code also assumes
25 * that bootblock_northbridge_init() is the first thing called in the non-asm
26 * boot block code. The final assumption is that no assembly code is using the
Shelley Chen4e9bb332021-10-20 15:43:45 -070027 * CONFIG(ECAM_MMCONF_SUPPORT) option to do PCI config accesses.
Duncan Lauriec88c54c2014-04-30 16:36:13 -070028 *
Angel Pons9debbd62021-01-28 12:42:53 +010029 * The PCIEXBAR is assumed to live in the memory mapped IO space under 4GiB.
Duncan Lauriec88c54c2014-04-30 16:36:13 -070030 */
Shelley Chen4e9bb332021-10-20 15:43:45 -070031 const uint32_t reg = CONFIG_ECAM_MMCONF_BASE_ADDRESS | encode_pciexbar_length() | 1;
Angel Pons29924b22021-06-15 13:55:03 +020032 pci_io_write_config32(HOST_BRIDGE, PCIEXBAR + 4, 0);
33 pci_io_write_config32(HOST_BRIDGE, PCIEXBAR, reg);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070034}