blob: 421c561109280455b1fd76fa821b1dcb0308f31f [file] [log] [blame]
Angel Pons6e5aabd2020-03-23 23:44:42 +01001/* SPDX-License-Identifier: GPL-2.0-only */
Martin Roth5474eb12018-05-26 19:22:33 -06002
Kyösti Mälkkide640782019-12-03 07:30:26 +02003#include <arch/bootblock.h>
Angel Pons10f9b832021-01-20 14:58:32 +01004#include <assert.h>
Angel Pons37cae542021-02-02 16:28:07 +01005#include <device/pci_ops.h>
Angel Pons10f9b832021-01-20 14:58:32 +01006#include <types.h>
Elyes HAOUAS9cbf26d2021-01-31 08:31:20 +01007
Arthur Heymans360d9472019-11-12 18:11:03 +01008#include "sandybridge.h"
Kyösti Mälkkifbdb0852013-07-01 11:21:53 +03009
Angel Pons10f9b832021-01-20 14:58:32 +010010static uint32_t encode_pciexbar_length(void)
11{
Shelley Chen4e9bb332021-10-20 15:43:45 -070012 switch (CONFIG_ECAM_MMCONF_BUS_NUMBER) {
Felix Singer893d77e2023-12-08 11:00:26 +010013 case 256: return 0 << 1;
14 case 128: return 1 << 1;
15 case 64: return 2 << 1;
16 default: return dead_code_t(uint32_t);
Angel Pons10f9b832021-01-20 14:58:32 +010017 }
18}
19
Arthur Heymans360d9472019-11-12 18:11:03 +010020void bootblock_early_northbridge_init(void)
Kyösti Mälkkifbdb0852013-07-01 11:21:53 +030021{
Kyösti Mälkkifbdb0852013-07-01 11:21:53 +030022 /*
Angel Pons7c49cb82020-03-16 23:17:32 +010023 * The "io" variant of the config access is explicitly used to setup the
Shelley Chen4e9bb332021-10-20 15:43:45 -070024 * PCIEXBAR because CONFIG(ECAM_MMCONF_SUPPORT) is set to true. That way, all
Angel Pons7c49cb82020-03-16 23:17:32 +010025 * subsequent non-explicit config accesses use MCFG. This code also assumes
26 * that bootblock_northbridge_init() is the first thing called in the non-asm
27 * boot block code. The final assumption is that no assembly code is using the
Shelley Chen4e9bb332021-10-20 15:43:45 -070028 * CONFIG(ECAM_MMCONF_SUPPORT) option to do PCI config accesses.
Kyösti Mälkkifbdb0852013-07-01 11:21:53 +030029 *
Angel Pons7c49cb82020-03-16 23:17:32 +010030 * The PCIEXBAR is assumed to live in the memory mapped IO space under 4GiB.
Kyösti Mälkkifbdb0852013-07-01 11:21:53 +030031 */
Shelley Chen4e9bb332021-10-20 15:43:45 -070032 const uint32_t reg32 = CONFIG_ECAM_MMCONF_BASE_ADDRESS | encode_pciexbar_length() | 1;
Angel Pons10f9b832021-01-20 14:58:32 +010033 pci_io_write_config32(HOST_BRIDGE, PCIEXBAR + 4, 0);
Elyes HAOUAS9cbf26d2021-01-31 08:31:20 +010034 pci_io_write_config32(HOST_BRIDGE, PCIEXBAR, reg32);
Kyösti Mälkkifbdb0852013-07-01 11:21:53 +030035}