Angel Pons | 0612b27 | 2020-04-05 15:46:56 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Subrata Banik | 7609c65 | 2017-05-19 14:50:09 +0530 | [diff] [blame] | 2 | |
Kyösti Mälkki | 6046eb4 | 2019-07-14 11:07:39 +0300 | [diff] [blame] | 3 | #define __SIMPLE_DEVICE__ |
| 4 | |
Angel Pons | 9849488 | 2021-01-29 11:35:16 +0100 | [diff] [blame^] | 5 | #include <assert.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 6 | #include <device/mmio.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 7 | #include <device/pci_ops.h> |
Subrata Banik | 7609c65 | 2017-05-19 14:50:09 +0530 | [diff] [blame] | 8 | #include <device/device.h> |
| 9 | #include <device/pci.h> |
| 10 | #include <intelblocks/systemagent.h> |
Angel Pons | ffbb4b2 | 2020-10-15 23:25:58 +0200 | [diff] [blame] | 11 | #include <security/intel/txt/txt_platform.h> |
| 12 | #include <security/intel/txt/txt_register.h> |
Subrata Banik | 7609c65 | 2017-05-19 14:50:09 +0530 | [diff] [blame] | 13 | #include <soc/iomap.h> |
| 14 | #include <soc/pci_devs.h> |
| 15 | #include <soc/systemagent.h> |
Elyes HAOUAS | add76f9 | 2019-03-21 09:55:49 +0100 | [diff] [blame] | 16 | |
Subrata Banik | 7609c65 | 2017-05-19 14:50:09 +0530 | [diff] [blame] | 17 | #include "systemagent_def.h" |
Subrata Banik | 7609c65 | 2017-05-19 14:50:09 +0530 | [diff] [blame] | 18 | |
Subrata Banik | 7609c65 | 2017-05-19 14:50:09 +0530 | [diff] [blame] | 19 | void bootblock_systemagent_early_init(void) |
| 20 | { |
| 21 | uint32_t reg; |
| 22 | uint8_t pciexbar_length; |
| 23 | |
| 24 | /* |
| 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(SA_DEV_ROOT, PCIEXBAR + 4, reg); |
| 30 | |
| 31 | /* Get PCI Express Region Length */ |
Angel Pons | 9849488 | 2021-01-29 11:35:16 +0100 | [diff] [blame^] | 32 | switch (CONFIG_MMCONF_BUS_NUMBER) { |
| 33 | case 256: |
Subrata Banik | 7609c65 | 2017-05-19 14:50:09 +0530 | [diff] [blame] | 34 | pciexbar_length = PCIEXBAR_LENGTH_256MB; |
| 35 | break; |
Angel Pons | 9849488 | 2021-01-29 11:35:16 +0100 | [diff] [blame^] | 36 | case 128: |
Subrata Banik | 7609c65 | 2017-05-19 14:50:09 +0530 | [diff] [blame] | 37 | pciexbar_length = PCIEXBAR_LENGTH_128MB; |
| 38 | break; |
Angel Pons | 9849488 | 2021-01-29 11:35:16 +0100 | [diff] [blame^] | 39 | case 64: |
Subrata Banik | 7609c65 | 2017-05-19 14:50:09 +0530 | [diff] [blame] | 40 | pciexbar_length = PCIEXBAR_LENGTH_64MB; |
| 41 | break; |
| 42 | default: |
Angel Pons | 9849488 | 2021-01-29 11:35:16 +0100 | [diff] [blame^] | 43 | dead_code(); |
Subrata Banik | 7609c65 | 2017-05-19 14:50:09 +0530 | [diff] [blame] | 44 | } |
| 45 | reg = CONFIG_MMCONF_BASE_ADDRESS | (pciexbar_length << 1) |
| 46 | | PCIEXBAR_PCIEXBAREN; |
| 47 | pci_io_write_config32(SA_DEV_ROOT, PCIEXBAR, reg); |
| 48 | |
| 49 | /* |
| 50 | * TSEG defines the base of SMM range. BIOS determines the base |
| 51 | * of TSEG memory which must be at or below Graphics base of GTT |
| 52 | * Stolen memory, hence its better to clear TSEG register early |
| 53 | * to avoid power on default non-zero value (if any). |
| 54 | */ |
| 55 | pci_write_config32(SA_DEV_ROOT, TSEG, 0); |
| 56 | } |
Subrata Banik | 7609c65 | 2017-05-19 14:50:09 +0530 | [diff] [blame] | 57 | |
| 58 | void sa_set_pci_bar(const struct sa_mmio_descriptor *fixed_set_resources, |
| 59 | size_t count) |
| 60 | { |
| 61 | int i; |
| 62 | |
| 63 | for (i = 0; i < count; i++) { |
Subrata Banik | f8d9a13 | 2020-01-21 14:28:26 +0530 | [diff] [blame] | 64 | uint64_t base; |
Subrata Banik | 7609c65 | 2017-05-19 14:50:09 +0530 | [diff] [blame] | 65 | unsigned int index; |
| 66 | |
| 67 | index = fixed_set_resources[i].index; |
| 68 | /* Check if PCI BAR already enabled */ |
| 69 | base = pci_read_config32(SA_DEV_ROOT, index); |
| 70 | |
| 71 | /* If enabled don't program it. */ |
| 72 | if (base & 0x1) |
| 73 | return; |
| 74 | |
| 75 | base = fixed_set_resources[i].base; |
Subrata Banik | f8d9a13 | 2020-01-21 14:28:26 +0530 | [diff] [blame] | 76 | if (base >> 32) |
| 77 | pci_write_config32(SA_DEV_ROOT, index + 4, base >> 32); |
| 78 | pci_write_config32(SA_DEV_ROOT, index, (base & 0xffffffff) | 1); |
Subrata Banik | 7609c65 | 2017-05-19 14:50:09 +0530 | [diff] [blame] | 79 | } |
| 80 | } |
| 81 | |
| 82 | /* |
| 83 | * There are special BARs that actually are programmed in the MCHBAR. These |
| 84 | * Intel special features, but they do consume resources that need to be |
| 85 | * accounted for. |
| 86 | */ |
| 87 | void sa_set_mch_bar(const struct sa_mmio_descriptor *fixed_set_resources, |
| 88 | size_t count) |
| 89 | { |
| 90 | int i; |
| 91 | |
| 92 | for (i = 0; i < count; i++) { |
Subrata Banik | f8d9a13 | 2020-01-21 14:28:26 +0530 | [diff] [blame] | 93 | uint64_t base; |
Subrata Banik | 7609c65 | 2017-05-19 14:50:09 +0530 | [diff] [blame] | 94 | unsigned int index; |
| 95 | |
| 96 | base = fixed_set_resources[i].base; |
| 97 | index = fixed_set_resources[i].index; |
Subrata Banik | f8d9a13 | 2020-01-21 14:28:26 +0530 | [diff] [blame] | 98 | if (base >> 32) |
Patrick Rudolph | 3805354 | 2020-11-30 13:42:24 +0100 | [diff] [blame] | 99 | write32((void *)(uintptr_t)(MCH_BASE_ADDRESS + index + 4), base >> 32); |
| 100 | write32((void *)(uintptr_t)(MCH_BASE_ADDRESS + index), (base & 0xffffffff) | 1); |
Subrata Banik | 7609c65 | 2017-05-19 14:50:09 +0530 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | |
| 104 | void enable_pam_region(void) |
| 105 | { |
| 106 | /* All read and writes in this region are serviced by DRAM */ |
| 107 | pci_write_config8(SA_DEV_ROOT, PAM0, 0x30); |
| 108 | pci_write_config8(SA_DEV_ROOT, PAM1, 0x33); |
| 109 | pci_write_config8(SA_DEV_ROOT, PAM2, 0x33); |
| 110 | pci_write_config8(SA_DEV_ROOT, PAM3, 0x33); |
| 111 | pci_write_config8(SA_DEV_ROOT, PAM4, 0x33); |
| 112 | pci_write_config8(SA_DEV_ROOT, PAM5, 0x33); |
| 113 | pci_write_config8(SA_DEV_ROOT, PAM6, 0x33); |
| 114 | } |
| 115 | |
| 116 | void enable_bios_reset_cpl(void) |
| 117 | { |
| 118 | u8 bios_reset_cpl; |
| 119 | |
| 120 | /* |
| 121 | * Set bits 0+1 of BIOS_RESET_CPL to indicate to the CPU |
| 122 | * that BIOS has initialized memory and power management |
| 123 | */ |
| 124 | bios_reset_cpl = MCHBAR8(BIOS_RESET_CPL); |
| 125 | bios_reset_cpl |= 3; |
| 126 | MCHBAR8(BIOS_RESET_CPL) = bios_reset_cpl; |
| 127 | } |
Subrata Banik | bd6ac22 | 2017-08-21 16:42:15 +0530 | [diff] [blame] | 128 | |
Subrata Banik | 73f448f | 2017-08-29 18:51:14 +0530 | [diff] [blame] | 129 | uintptr_t sa_get_tolud_base(void) |
Subrata Banik | bd6ac22 | 2017-08-21 16:42:15 +0530 | [diff] [blame] | 130 | { |
| 131 | /* All regions concerned for have 1 MiB alignment. */ |
| 132 | return ALIGN_DOWN(pci_read_config32(SA_DEV_ROOT, TOLUD), 1*MiB); |
| 133 | } |
| 134 | |
Matt DeVillier | cbe73ea | 2018-06-25 14:40:53 -0500 | [diff] [blame] | 135 | uintptr_t sa_get_gsm_base(void) |
Subrata Banik | 73f448f | 2017-08-29 18:51:14 +0530 | [diff] [blame] | 136 | { |
| 137 | /* All regions concerned for have 1 MiB alignment. */ |
| 138 | return ALIGN_DOWN(pci_read_config32(SA_DEV_ROOT, BGSM), 1*MiB); |
| 139 | } |
| 140 | |
Subrata Banik | 73f448f | 2017-08-29 18:51:14 +0530 | [diff] [blame] | 141 | uintptr_t sa_get_tseg_base(void) |
| 142 | { |
| 143 | /* All regions concerned for have 1 MiB alignment. */ |
| 144 | return ALIGN_DOWN(pci_read_config32(SA_DEV_ROOT, TSEG), 1*MiB); |
| 145 | } |
| 146 | |
| 147 | size_t sa_get_tseg_size(void) |
| 148 | { |
| 149 | return sa_get_gsm_base() - sa_get_tseg_base(); |
| 150 | } |
Angel Pons | ffbb4b2 | 2020-10-15 23:25:58 +0200 | [diff] [blame] | 151 | |
| 152 | union dpr_register txt_get_chipset_dpr(void) |
| 153 | { |
| 154 | return (union dpr_register) { .raw = pci_read_config32(SA_DEV_ROOT, DPR) }; |
| 155 | } |