Angel Pons | 4b42983 | 2020-04-02 23:48:50 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 2 | |
Arthur Heymans | 17ad459 | 2018-08-06 15:35:28 +0200 | [diff] [blame] | 3 | #include <cbmem.h> |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 4 | #include <console/console.h> |
Elyes HAOUAS | 748caed | 2019-12-19 17:02:08 +0100 | [diff] [blame] | 5 | #include <device/pci_def.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 6 | #include <device/pci_ops.h> |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 7 | #include <stdint.h> |
| 8 | #include <device/device.h> |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 9 | #include <boot/tables.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 10 | #include <acpi/acpi.h> |
Angel Pons | 2a8ceef | 2020-09-15 12:23:45 +0200 | [diff] [blame] | 11 | #include <northbridge/intel/x4x/memmap.h> |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 12 | #include <northbridge/intel/x4x/chip.h> |
| 13 | #include <northbridge/intel/x4x/x4x.h> |
Kyösti Mälkki | f091f4d | 2019-08-14 03:49:21 +0300 | [diff] [blame] | 14 | #include <cpu/intel/smm_reloc.h> |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 15 | |
Elyes HAOUAS | fea02e1 | 2018-02-08 14:59:03 +0100 | [diff] [blame] | 16 | static void mch_domain_read_resources(struct device *dev) |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 17 | { |
Arthur Heymans | 4c65bfc | 2018-04-10 13:34:24 +0200 | [diff] [blame] | 18 | u8 index; |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 19 | u64 tom, touud; |
Arthur Heymans | 4c65bfc | 2018-04-10 13:34:24 +0200 | [diff] [blame] | 20 | u32 tomk, tolud, delta_cbmem; |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 21 | u32 uma_sizek = 0; |
| 22 | |
Damien Zammit | 9fb08f5 | 2016-01-22 18:56:23 +1100 | [diff] [blame] | 23 | const u32 top32memk = 4 * (GiB / KiB); |
| 24 | index = 3; |
| 25 | |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 26 | pci_domain_read_resources(dev); |
| 27 | |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 28 | struct device *mch = pcidev_on_root(0, 0); |
Arthur Heymans | c6e13b6 | 2018-06-26 21:06:38 +0200 | [diff] [blame] | 29 | |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 30 | /* Top of Upper Usable DRAM, including remap */ |
Arthur Heymans | c6e13b6 | 2018-06-26 21:06:38 +0200 | [diff] [blame] | 31 | touud = pci_read_config16(mch, D0F0_TOUUD); |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 32 | touud <<= 20; |
| 33 | |
| 34 | /* Top of Lower Usable DRAM */ |
Arthur Heymans | c6e13b6 | 2018-06-26 21:06:38 +0200 | [diff] [blame] | 35 | tolud = pci_read_config16(mch, D0F0_TOLUD) & 0xfff0; |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 36 | tolud <<= 16; |
| 37 | |
| 38 | /* Top of Memory - does not account for any UMA */ |
Arthur Heymans | c6e13b6 | 2018-06-26 21:06:38 +0200 | [diff] [blame] | 39 | tom = pci_read_config16(mch, D0F0_TOM) & 0x01ff; |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 40 | tom <<= 26; |
| 41 | |
Angel Pons | dd7ce4e | 2021-03-26 23:21:02 +0100 | [diff] [blame] | 42 | printk(BIOS_DEBUG, "TOUUD 0x%llx TOLUD 0x%08x TOM 0x%llx\n", touud, tolud, tom); |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 43 | |
| 44 | tomk = tolud >> 10; |
| 45 | |
| 46 | /* Graphics memory comes next */ |
Arthur Heymans | 4c4f56a | 2017-02-27 13:46:11 +0100 | [diff] [blame] | 47 | |
Arthur Heymans | c6e13b6 | 2018-06-26 21:06:38 +0200 | [diff] [blame] | 48 | const u16 ggc = pci_read_config16(mch, D0F0_GGC); |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 49 | printk(BIOS_DEBUG, "IGD decoded, subtracting "); |
| 50 | |
| 51 | /* Graphics memory */ |
| 52 | const u32 gms_sizek = decode_igd_memory_size((ggc >> 4) & 0xf); |
| 53 | printk(BIOS_DEBUG, "%uM UMA", gms_sizek >> 10); |
Arthur Heymans | 4c4f56a | 2017-02-27 13:46:11 +0100 | [diff] [blame] | 54 | tomk -= gms_sizek; |
| 55 | uma_sizek += gms_sizek; |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 56 | |
| 57 | /* GTT Graphics Stolen Memory Size (GGMS) */ |
| 58 | const u32 gsm_sizek = decode_igd_gtt_size((ggc >> 8) & 0xf); |
| 59 | printk(BIOS_DEBUG, " and %uM GTT\n", gsm_sizek >> 10); |
Arthur Heymans | 4c4f56a | 2017-02-27 13:46:11 +0100 | [diff] [blame] | 60 | tomk -= gsm_sizek; |
| 61 | uma_sizek += gsm_sizek; |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 62 | |
Arthur Heymans | 4c4f56a | 2017-02-27 13:46:11 +0100 | [diff] [blame] | 63 | printk(BIOS_DEBUG, "TSEG decoded, subtracting "); |
Arthur Heymans | 4c65bfc | 2018-04-10 13:34:24 +0200 | [diff] [blame] | 64 | const u32 tseg_sizek = decode_tseg_size( |
| 65 | pci_read_config8(dev, D0F0_ESMRAMC)) >> 10; |
Arthur Heymans | 4c4f56a | 2017-02-27 13:46:11 +0100 | [diff] [blame] | 66 | uma_sizek += tseg_sizek; |
| 67 | tomk -= tseg_sizek; |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 68 | |
Arthur Heymans | 4c4f56a | 2017-02-27 13:46:11 +0100 | [diff] [blame] | 69 | printk(BIOS_DEBUG, "%dM\n", tseg_sizek >> 10); |
| 70 | |
Arthur Heymans | 17ad459 | 2018-08-06 15:35:28 +0200 | [diff] [blame] | 71 | /* cbmem_top can be shifted downwards due to alignment. |
| 72 | Mark the region between cbmem_top and tomk as unusable */ |
Kyösti Mälkki | 4e4edf7 | 2022-05-26 19:03:55 +0300 | [diff] [blame] | 73 | delta_cbmem = tomk - ((uintptr_t)cbmem_top() >> 10); |
Arthur Heymans | 17ad459 | 2018-08-06 15:35:28 +0200 | [diff] [blame] | 74 | tomk -= delta_cbmem; |
| 75 | uma_sizek += delta_cbmem; |
| 76 | |
Angel Pons | dd7ce4e | 2021-03-26 23:21:02 +0100 | [diff] [blame] | 77 | printk(BIOS_DEBUG, "Unused RAM between cbmem_top and TOM: 0x%xK\n", delta_cbmem); |
Arthur Heymans | 17ad459 | 2018-08-06 15:35:28 +0200 | [diff] [blame] | 78 | |
Arthur Heymans | 4c4f56a | 2017-02-27 13:46:11 +0100 | [diff] [blame] | 79 | printk(BIOS_INFO, "Available memory below 4GB: %uM\n", tomk >> 10); |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 80 | |
| 81 | /* Report the memory regions */ |
Kyösti Mälkki | 8ee11b3 | 2021-06-27 21:08:32 +0300 | [diff] [blame] | 82 | ram_from_to(dev, index++, 0, 0xa0000); |
| 83 | mmio_from_to(dev, index++, 0xa0000, 0xc0000); |
| 84 | reserved_ram_from_to(dev, index++, 0xc0000, 1 * MiB); |
Kyösti Mälkki | 27d6299 | 2022-05-24 20:25:58 +0300 | [diff] [blame] | 85 | ram_resource_kb(dev, index++, 0x100000 >> 10, (tomk - (0x100000 >> 10))); |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 86 | |
| 87 | /* |
| 88 | * If >= 4GB installed then memory from TOLUD to 4GB |
| 89 | * is remapped above TOM, TOUUD will account for both |
| 90 | */ |
Kyösti Mälkki | 0a18d64 | 2021-06-28 21:43:31 +0300 | [diff] [blame] | 91 | upper_ram_end(dev, index++, touud); |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 92 | |
Angel Pons | dd7ce4e | 2021-03-26 23:21:02 +0100 | [diff] [blame] | 93 | printk(BIOS_DEBUG, "Adding UMA memory area base=0x%08x size=0x%08x\n", |
| 94 | tomk << 10, uma_sizek << 10); |
Kyösti Mälkki | 27d6299 | 2022-05-24 20:25:58 +0300 | [diff] [blame] | 95 | uma_resource_kb(dev, index++, tomk, uma_sizek); |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 96 | |
Damien Zammit | 9fb08f5 | 2016-01-22 18:56:23 +1100 | [diff] [blame] | 97 | /* Reserve high memory where the NB BARs are up to 4GiB */ |
Kyösti Mälkki | 27d6299 | 2022-05-24 20:25:58 +0300 | [diff] [blame] | 98 | fixed_mem_resource_kb(dev, index++, DEFAULT_HECIBAR >> 10, |
Damien Zammit | 9fb08f5 | 2016-01-22 18:56:23 +1100 | [diff] [blame] | 99 | top32memk - (DEFAULT_HECIBAR >> 10), |
| 100 | IORESOURCE_RESERVE); |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 101 | |
Angel Pons | bbc80f4 | 2021-01-20 13:23:18 +0100 | [diff] [blame] | 102 | mmconf_resource(dev, index++); |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 103 | } |
| 104 | |
Elyes HAOUAS | fea02e1 | 2018-02-08 14:59:03 +0100 | [diff] [blame] | 105 | static void mch_domain_set_resources(struct device *dev) |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 106 | { |
Damien Zammit | 9fb08f5 | 2016-01-22 18:56:23 +1100 | [diff] [blame] | 107 | struct resource *res; |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 108 | |
Damien Zammit | 9fb08f5 | 2016-01-22 18:56:23 +1100 | [diff] [blame] | 109 | for (res = dev->resource_list; res; res = res->next) |
| 110 | report_resource_stored(dev, res, ""); |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 111 | |
| 112 | assign_resources(dev->link_list); |
| 113 | } |
| 114 | |
Elyes HAOUAS | fea02e1 | 2018-02-08 14:59:03 +0100 | [diff] [blame] | 115 | static void mch_domain_init(struct device *dev) |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 116 | { |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 117 | /* Enable SERR */ |
Elyes HAOUAS | 5ac723e | 2020-04-29 09:09:12 +0200 | [diff] [blame] | 118 | pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_SERR); |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 119 | } |
| 120 | |
Arthur Heymans | a8a9f34 | 2017-12-24 08:11:13 +0100 | [diff] [blame] | 121 | static const char *northbridge_acpi_name(const struct device *dev) |
| 122 | { |
| 123 | if (dev->path.type == DEVICE_PATH_DOMAIN) |
| 124 | return "PCI0"; |
| 125 | |
| 126 | if (dev->path.type != DEVICE_PATH_PCI || dev->bus->secondary != 0) |
| 127 | return NULL; |
| 128 | |
| 129 | switch (dev->path.pci.devfn) { |
| 130 | case PCI_DEVFN(0, 0): |
| 131 | return "MCHC"; |
| 132 | } |
| 133 | |
| 134 | return NULL; |
| 135 | } |
| 136 | |
Arthur Heymans | 4c65bfc | 2018-04-10 13:34:24 +0200 | [diff] [blame] | 137 | void northbridge_write_smram(u8 smram) |
| 138 | { |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 139 | struct device *dev = pcidev_on_root(0, 0); |
Arthur Heymans | 4c65bfc | 2018-04-10 13:34:24 +0200 | [diff] [blame] | 140 | |
| 141 | if (dev == NULL) |
| 142 | die("could not find pci 00:00.0!\n"); |
| 143 | |
| 144 | pci_write_config8(dev, D0F0_SMRAM, smram); |
| 145 | } |
| 146 | |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 147 | static struct device_operations pci_domain_ops = { |
| 148 | .read_resources = mch_domain_read_resources, |
| 149 | .set_resources = mch_domain_set_resources, |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 150 | .init = mch_domain_init, |
| 151 | .scan_bus = pci_domain_scan_bus, |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 152 | .write_acpi_tables = northbridge_write_acpi_tables, |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 153 | .acpi_fill_ssdt = generate_cpu_entries, |
Arthur Heymans | a8a9f34 | 2017-12-24 08:11:13 +0100 | [diff] [blame] | 154 | .acpi_name = northbridge_acpi_name, |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 155 | }; |
| 156 | |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 157 | static struct device_operations cpu_bus_ops = { |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame] | 158 | .read_resources = noop_read_resources, |
| 159 | .set_resources = noop_set_resources, |
Kyösti Mälkki | b3267e0 | 2019-08-13 16:44:04 +0300 | [diff] [blame] | 160 | .init = mp_cpu_bus_init, |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 161 | }; |
| 162 | |
Elyes HAOUAS | fea02e1 | 2018-02-08 14:59:03 +0100 | [diff] [blame] | 163 | static void enable_dev(struct device *dev) |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 164 | { |
| 165 | /* Set the operations if it is a special bus type */ |
Arthur Heymans | 70a1dda | 2017-03-09 01:58:24 +0100 | [diff] [blame] | 166 | if (dev->path.type == DEVICE_PATH_DOMAIN) |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 167 | dev->ops = &pci_domain_ops; |
Arthur Heymans | 70a1dda | 2017-03-09 01:58:24 +0100 | [diff] [blame] | 168 | else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 169 | dev->ops = &cpu_bus_ops; |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 170 | } |
| 171 | |
Arthur Heymans | a854c9d | 2019-11-27 21:53:01 +0100 | [diff] [blame] | 172 | static void hide_pci_fn(const int dev_bit_base, const struct device *dev) |
| 173 | { |
| 174 | if (!dev || dev->enabled) |
| 175 | return; |
| 176 | const unsigned int fn = PCI_FUNC(dev->path.pci.devfn); |
| 177 | const struct device *const d0f0 = pcidev_on_root(0, 0); |
| 178 | pci_update_config32(d0f0, D0F0_DEVEN, ~(1 << (dev_bit_base + fn)), 0); |
| 179 | } |
| 180 | |
| 181 | static void hide_pci_dev(const int dev, int functions, const int dev_bit_base) |
| 182 | { |
| 183 | for (; functions >= 0; functions--) |
| 184 | hide_pci_fn(dev_bit_base, pcidev_on_root(dev, functions)); |
| 185 | } |
| 186 | |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 187 | static void x4x_init(void *const chip_info) |
| 188 | { |
Kyösti Mälkki | 98a9174 | 2018-05-21 21:29:16 +0300 | [diff] [blame] | 189 | struct device *const d0f0 = pcidev_on_root(0x0, 0); |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 190 | |
| 191 | /* Hide internal functions based on devicetree info. */ |
Arthur Heymans | a854c9d | 2019-11-27 21:53:01 +0100 | [diff] [blame] | 192 | hide_pci_dev(6, 0, 13); /* PEG1: only on P45 */ |
| 193 | hide_pci_dev(3, 3, 6); /* ME */ |
| 194 | hide_pci_dev(2, 1, 3); /* IGD */ |
| 195 | hide_pci_dev(1, 0, 1); /* PEG0 */ |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 196 | |
| 197 | const u32 deven = pci_read_config32(d0f0, D0F0_DEVEN); |
| 198 | if (!(deven & (0xf << 6))) |
| 199 | pci_write_config32(d0f0, D0F0_DEVEN, deven & ~(1 << 14)); |
| 200 | } |
| 201 | |
| 202 | struct chip_operations northbridge_intel_x4x_ops = { |
| 203 | CHIP_NAME("Intel 4-Series Northbridge") |
| 204 | .enable_dev = enable_dev, |
| 205 | .init = x4x_init, |
| 206 | }; |