blob: 69c817f212fe5f84c7703bdd44c2abe8a3eba497 [file] [log] [blame]
Angel Pons4b429832020-04-02 23:48:50 +02001/* 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 Pons1ac6f8b2021-01-20 13:13:26 +01004#include <assert.h>
Angel Pons37cae542021-02-02 16:28:07 +01005#include <device/pci_ops.h>
Angel Pons1ac6f8b2021-01-20 13:13:26 +01006#include <types.h>
Kyösti Mälkki35a72492013-07-01 11:21:53 +03007
Jacob Garber4a216472019-12-27 14:18:32 -07008#include "gm45.h"
Kyösti Mälkki35a72492013-07-01 11:21:53 +03009
Angel Pons1ac6f8b2021-01-20 13:13:26 +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 Pons1ac6f8b2021-01-20 13:13:26 +010017 }
18}
19
Arthur Heymansbe9533a2019-10-12 14:35:25 +020020void bootblock_early_northbridge_init(void)
Kyösti Mälkki35a72492013-07-01 11:21:53 +030021{
Kyösti Mälkki35a72492013-07-01 11:21:53 +030022 /*
23 * The "io" variant of the config access is explicitly used to
Shelley Chen4e9bb332021-10-20 15:43:45 -070024 * setup the PCIEXBAR because CONFIG(ECAM_MMCONF_SUPPORT) is set to
Elyes HAOUAS45373322021-01-16 15:01:43 +010025 * true. That way all subsequent non-explicit config accesses use
Kyösti Mälkki35a72492013-07-01 11:21:53 +030026 * MCFG. This code also assumes that bootblock_northbridge_init() is
27 * the first thing called in the non-asm boot block code. The final
28 * assumption is that no assembly code is using the
Shelley Chen4e9bb332021-10-20 15:43:45 -070029 * CONFIG(ECAM_MMCONF_SUPPORT) option to do PCI config accesses.
Kyösti Mälkki35a72492013-07-01 11:21:53 +030030 *
31 * The PCIEXBAR is assumed to live in the memory mapped IO space under
32 * 4GiB.
33 */
Shelley Chen4e9bb332021-10-20 15:43:45 -070034 const uint32_t reg32 = CONFIG_ECAM_MMCONF_BASE_ADDRESS | encode_pciexbar_length() | 1;
Angel Pons1ac6f8b2021-01-20 13:13:26 +010035 pci_io_write_config32(PCI_DEV(0, 0, 0), D0F0_PCIEXBAR_HI, 0);
Elyes HAOUASc4d1b472021-01-31 08:26:01 +010036 pci_io_write_config32(PCI_DEV(0, 0, 0), D0F0_PCIEXBAR_LO, reg32);
Kyösti Mälkki35a72492013-07-01 11:21:53 +030037}