Angel Pons | 4b42983 | 2020-04-02 23:48:50 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 2 | |
Felix Held | 928a9c8 | 2022-02-24 00:51:11 +0100 | [diff] [blame] | 3 | #include <arch/hpet.h> |
Arthur Heymans | 17ad459 | 2018-08-06 15:35:28 +0200 | [diff] [blame] | 4 | #include <cbmem.h> |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 5 | #include <console/console.h> |
Arthur Heymans | 95a1142 | 2021-01-18 00:41:35 +0100 | [diff] [blame] | 6 | #include <commonlib/bsd/helpers.h> |
Elyes HAOUAS | 748caed | 2019-12-19 17:02:08 +0100 | [diff] [blame] | 7 | #include <device/pci_def.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 8 | #include <device/pci_ops.h> |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 9 | #include <stdint.h> |
| 10 | #include <device/device.h> |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 11 | #include <boot/tables.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 12 | #include <acpi/acpi.h> |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 13 | #include <northbridge/intel/pineview/pineview.h> |
Kyösti Mälkki | f091f4d | 2019-08-14 03:49:21 +0300 | [diff] [blame] | 14 | #include <cpu/intel/smm_reloc.h> |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 15 | |
Angel Pons | 39ff703 | 2020-03-09 21:39:44 +0100 | [diff] [blame] | 16 | /* |
| 17 | * Reserve everything between A segment and 1MB: |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 18 | * |
| 19 | * 0xa0000 - 0xbffff: legacy VGA |
Damien Zammit | 51fdb92 | 2016-01-18 18:34:52 +1100 | [diff] [blame] | 20 | * 0xc0000 - 0xcffff: VGA OPROM (needed by kernel) |
| 21 | * 0xe0000 - 0xfffff: SeaBIOS, if used, otherwise DMI |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 22 | */ |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 23 | |
Elyes HAOUAS | 6275360 | 2018-02-09 08:46:25 +0100 | [diff] [blame] | 24 | static void add_fixed_resources(struct device *dev, int index) |
Damien Zammit | 51fdb92 | 2016-01-18 18:34:52 +1100 | [diff] [blame] | 25 | { |
| 26 | struct resource *resource; |
| 27 | |
| 28 | resource = new_resource(dev, index++); |
Felix Held | 928a9c8 | 2022-02-24 00:51:11 +0100 | [diff] [blame] | 29 | resource->base = (resource_t) HPET_BASE_ADDRESS; |
Damien Zammit | 51fdb92 | 2016-01-18 18:34:52 +1100 | [diff] [blame] | 30 | resource->size = (resource_t) 0x00100000; |
Angel Pons | 39ff703 | 2020-03-09 21:39:44 +0100 | [diff] [blame] | 31 | resource->flags = IORESOURCE_MEM |
| 32 | | IORESOURCE_RESERVE |
| 33 | | IORESOURCE_FIXED |
| 34 | | IORESOURCE_STORED |
| 35 | | IORESOURCE_ASSIGNED; |
Damien Zammit | 51fdb92 | 2016-01-18 18:34:52 +1100 | [diff] [blame] | 36 | |
Kyösti Mälkki | 8ee11b3 | 2021-06-27 21:08:32 +0300 | [diff] [blame] | 37 | mmio_from_to(dev, index++, 0xa0000, 0xc0000); |
| 38 | reserved_ram_from_to(dev, index++, 0xc0000, 1 * MiB); |
Damien Zammit | 51fdb92 | 2016-01-18 18:34:52 +1100 | [diff] [blame] | 39 | } |
| 40 | |
Elyes HAOUAS | 6275360 | 2018-02-09 08:46:25 +0100 | [diff] [blame] | 41 | static void mch_domain_read_resources(struct device *dev) |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 42 | { |
| 43 | u64 tom, touud; |
Damien Zammit | 51fdb92 | 2016-01-18 18:34:52 +1100 | [diff] [blame] | 44 | u32 tomk, tolud, tseg_sizek; |
Angel Pons | 1318ab4 | 2021-01-20 13:31:09 +0100 | [diff] [blame] | 45 | u32 cbmem_topk, delta_cbmem; |
Damien Zammit | 51fdb92 | 2016-01-18 18:34:52 +1100 | [diff] [blame] | 46 | u16 index; |
Damien Zammit | 51fdb92 | 2016-01-18 18:34:52 +1100 | [diff] [blame] | 47 | |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 48 | struct device *mch = pcidev_on_root(0, 0); |
Arthur Heymans | 15e1b39 | 2018-06-26 21:06:13 +0200 | [diff] [blame] | 49 | |
Damien Zammit | 51fdb92 | 2016-01-18 18:34:52 +1100 | [diff] [blame] | 50 | index = 3; |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 51 | |
| 52 | pci_domain_read_resources(dev); |
| 53 | |
| 54 | /* Top of Upper Usable DRAM, including remap */ |
Arthur Heymans | 15e1b39 | 2018-06-26 21:06:13 +0200 | [diff] [blame] | 55 | touud = pci_read_config16(mch, TOUUD); |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 56 | touud <<= 20; |
| 57 | |
| 58 | /* Top of Lower Usable DRAM */ |
Arthur Heymans | 15e1b39 | 2018-06-26 21:06:13 +0200 | [diff] [blame] | 59 | tolud = pci_read_config16(mch, TOLUD) & 0xfff0; |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 60 | tolud <<= 16; |
| 61 | |
| 62 | /* Top of Memory - does not account for any UMA */ |
Angel Pons | 39ff703 | 2020-03-09 21:39:44 +0100 | [diff] [blame] | 63 | tom = pci_read_config16(mch, TOM) & 0x01ff; |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 64 | tom <<= 27; |
| 65 | |
Angel Pons | 39ff703 | 2020-03-09 21:39:44 +0100 | [diff] [blame] | 66 | printk(BIOS_DEBUG, "TOUUD 0x%llx TOLUD 0x%08x TOM 0x%llx ", touud, tolud, tom); |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 67 | |
Arthur Heymans | 95a1142 | 2021-01-18 00:41:35 +0100 | [diff] [blame] | 68 | tomk = tolud / KiB; |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 69 | |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 70 | /* Graphics memory */ |
Arthur Heymans | 15e1b39 | 2018-06-26 21:06:13 +0200 | [diff] [blame] | 71 | const u16 ggc = pci_read_config16(mch, GGC); |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 72 | const u32 gms_sizek = decode_igd_memory_size((ggc >> 4) & 0xf); |
Arthur Heymans | 95a1142 | 2021-01-18 00:41:35 +0100 | [diff] [blame] | 73 | printk(BIOS_DEBUG, "%uM UMA", gms_sizek / KiB); |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 74 | tomk -= gms_sizek; |
| 75 | |
| 76 | /* GTT Graphics Stolen Memory Size (GGMS) */ |
| 77 | const u32 gsm_sizek = decode_igd_gtt_size((ggc >> 8) & 0xf); |
Arthur Heymans | 95a1142 | 2021-01-18 00:41:35 +0100 | [diff] [blame] | 78 | printk(BIOS_DEBUG, " and %uM GTT\n", gsm_sizek / KiB); |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 79 | tomk -= gsm_sizek; |
| 80 | |
Arthur Heymans | 95a1142 | 2021-01-18 00:41:35 +0100 | [diff] [blame] | 81 | const u32 tseg_basek = pci_read_config32(mch, TSEG) / KiB; |
| 82 | const u32 igd_basek = pci_read_config32(mch, GBSM) / KiB; |
| 83 | const u32 gtt_basek = pci_read_config32(mch, BGSM) / KiB; |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 84 | |
Damien Zammit | 51fdb92 | 2016-01-18 18:34:52 +1100 | [diff] [blame] | 85 | /* Subtract TSEG size */ |
| 86 | tseg_sizek = gtt_basek - tseg_basek; |
| 87 | tomk -= tseg_sizek; |
Arthur Heymans | 95a1142 | 2021-01-18 00:41:35 +0100 | [diff] [blame] | 88 | printk(BIOS_DEBUG, "TSEG decoded, subtracting %dM\n", tseg_sizek / KiB); |
Arthur Heymans | 17ad459 | 2018-08-06 15:35:28 +0200 | [diff] [blame] | 89 | |
| 90 | /* cbmem_top can be shifted downwards due to alignment. |
| 91 | Mark the region between cbmem_top and tomk as unusable */ |
Arthur Heymans | 95a1142 | 2021-01-18 00:41:35 +0100 | [diff] [blame] | 92 | cbmem_topk = (uint32_t)cbmem_top() / KiB; |
Arthur Heymans | 17ad459 | 2018-08-06 15:35:28 +0200 | [diff] [blame] | 93 | delta_cbmem = tomk - cbmem_topk; |
| 94 | tomk -= delta_cbmem; |
| 95 | |
Angel Pons | 39ff703 | 2020-03-09 21:39:44 +0100 | [diff] [blame] | 96 | printk(BIOS_DEBUG, "Unused RAM between cbmem_top and TOMK: 0x%xK\n", delta_cbmem); |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 97 | |
| 98 | /* Report the memory regions */ |
Kyösti Mälkki | 27d6299 | 2022-05-24 20:25:58 +0300 | [diff] [blame] | 99 | ram_resource_kb(dev, index++, 0, 0xa0000 / KiB); |
| 100 | ram_resource_kb(dev, index++, 1 * MiB / KiB, tomk - 1 * MiB / KiB); |
| 101 | mmio_resource_kb(dev, index++, tseg_basek, tseg_sizek); |
| 102 | mmio_resource_kb(dev, index++, gtt_basek, gsm_sizek); |
| 103 | mmio_resource_kb(dev, index++, igd_basek, gms_sizek); |
| 104 | reserved_ram_resource_kb(dev, index++, cbmem_topk, delta_cbmem); |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 105 | |
| 106 | /* |
Damien Zammit | 51fdb92 | 2016-01-18 18:34:52 +1100 | [diff] [blame] | 107 | * If > 4GB installed then memory from TOLUD to 4GB |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 108 | * is remapped above TOM, TOUUD will account for both |
| 109 | */ |
Kyösti Mälkki | 0a18d64 | 2021-06-28 21:43:31 +0300 | [diff] [blame] | 110 | upper_ram_end(dev, index++, touud); |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 111 | |
Angel Pons | 1318ab4 | 2021-01-20 13:31:09 +0100 | [diff] [blame] | 112 | mmconf_resource(dev, index++); |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 113 | |
Damien Zammit | 51fdb92 | 2016-01-18 18:34:52 +1100 | [diff] [blame] | 114 | add_fixed_resources(dev, index); |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 115 | } |
| 116 | |
Arthur Heymans | de6bda6 | 2018-04-10 13:40:39 +0200 | [diff] [blame] | 117 | void northbridge_write_smram(u8 smram) |
| 118 | { |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 119 | struct device *dev = pcidev_on_root(0, 0); |
Arthur Heymans | de6bda6 | 2018-04-10 13:40:39 +0200 | [diff] [blame] | 120 | |
| 121 | if (dev == NULL) |
| 122 | die("could not find pci 00:00.0!\n"); |
| 123 | |
| 124 | pci_write_config8(dev, SMRAM, smram); |
| 125 | } |
| 126 | |
Elyes HAOUAS | 6275360 | 2018-02-09 08:46:25 +0100 | [diff] [blame] | 127 | static void mch_domain_set_resources(struct device *dev) |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 128 | { |
Damien Zammit | 51fdb92 | 2016-01-18 18:34:52 +1100 | [diff] [blame] | 129 | struct resource *res; |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 130 | |
Damien Zammit | 51fdb92 | 2016-01-18 18:34:52 +1100 | [diff] [blame] | 131 | for (res = dev->resource_list; res; res = res->next) |
| 132 | report_resource_stored(dev, res, ""); |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 133 | |
| 134 | assign_resources(dev->link_list); |
| 135 | } |
| 136 | |
Elyes HAOUAS | 6275360 | 2018-02-09 08:46:25 +0100 | [diff] [blame] | 137 | static void mch_domain_init(struct device *dev) |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 138 | { |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 139 | /* Enable SERR */ |
Elyes HAOUAS | 5ac723e | 2020-04-29 09:09:12 +0200 | [diff] [blame] | 140 | pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_SERR); |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 141 | } |
| 142 | |
Arthur Heymans | a8a9f34 | 2017-12-24 08:11:13 +0100 | [diff] [blame] | 143 | static const char *northbridge_acpi_name(const struct device *dev) |
| 144 | { |
| 145 | if (dev->path.type == DEVICE_PATH_DOMAIN) |
| 146 | return "PCI0"; |
| 147 | |
| 148 | if (dev->path.type != DEVICE_PATH_PCI || dev->bus->secondary != 0) |
| 149 | return NULL; |
| 150 | |
| 151 | switch (dev->path.pci.devfn) { |
| 152 | case PCI_DEVFN(0, 0): |
| 153 | return "MCHC"; |
| 154 | } |
| 155 | |
| 156 | return NULL; |
| 157 | } |
| 158 | |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 159 | static struct device_operations pci_domain_ops = { |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 160 | .read_resources = mch_domain_read_resources, |
| 161 | .set_resources = mch_domain_set_resources, |
| 162 | .init = mch_domain_init, |
| 163 | .scan_bus = pci_domain_scan_bus, |
| 164 | .acpi_fill_ssdt = generate_cpu_entries, |
| 165 | .acpi_name = northbridge_acpi_name, |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 166 | }; |
| 167 | |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 168 | static struct device_operations cpu_bus_ops = { |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame] | 169 | .read_resources = noop_read_resources, |
| 170 | .set_resources = noop_set_resources, |
Kyösti Mälkki | b3267e0 | 2019-08-13 16:44:04 +0300 | [diff] [blame] | 171 | .init = mp_cpu_bus_init, |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 172 | }; |
| 173 | |
Elyes HAOUAS | 6275360 | 2018-02-09 08:46:25 +0100 | [diff] [blame] | 174 | static void enable_dev(struct device *dev) |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 175 | { |
| 176 | /* Set the operations if it is a special bus type */ |
| 177 | if (dev->path.type == DEVICE_PATH_DOMAIN) { |
| 178 | dev->ops = &pci_domain_ops; |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 179 | } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) { |
| 180 | dev->ops = &cpu_bus_ops; |
| 181 | } |
| 182 | } |
| 183 | |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 184 | struct chip_operations northbridge_intel_pineview_ops = { |
| 185 | CHIP_NAME("Intel Pineview Northbridge") |
| 186 | .enable_dev = enable_dev, |
Damien Zammit | f7060f1 | 2015-11-14 00:59:21 +1100 | [diff] [blame] | 187 | }; |