blob: 79e9ee53b832aa52bd3101d6f87f1536903a2c1b [file] [log] [blame]
Angel Pons4b429832020-04-02 23:48:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauer278534d2008-10-29 04:51:07 +00002
Arthur Heymans17ad4592018-08-06 15:35:28 +02003#include <cbmem.h>
Angel Ponscff4d162020-08-03 16:11:53 +02004#include <commonlib/helpers.h>
Stefan Reinauer278534d2008-10-29 04:51:07 +00005#include <console/console.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02006#include <device/pci_ops.h>
Stefan Reinauer278534d2008-10-29 04:51:07 +00007#include <stdint.h>
8#include <device/device.h>
9#include <device/pci.h>
10#include <device/pci_ids.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -070011#include <acpi/acpi.h>
Kyösti Mälkkif091f4d2019-08-14 03:49:21 +030012#include <cpu/intel/smm_reloc.h>
Arthur Heymans98c92572022-11-07 11:39:58 +010013#include <cpu/intel/speedstep.h>
Arthur Heymans85549542023-07-05 09:42:09 +020014#include <cpu/x86/smm.h>
Stefan Reinauer278534d2008-10-29 04:51:07 +000015#include "i945.h"
16
Arthur Heymans794f56b2018-06-15 19:37:23 +020017static void mch_domain_read_resources(struct device *dev)
Stefan Reinauer278534d2008-10-29 04:51:07 +000018{
Arthur Heymans85549542023-07-05 09:42:09 +020019 uint32_t pci_tolm;
20 uintptr_t tolud;
Nico Huber4e008c62019-01-12 15:28:43 +010021 struct device *const d0f0 = pcidev_on_root(0, 0);
Kyösti Mälkkic1d4d0b2021-06-26 19:09:05 +030022 int idx = 3;
Stefan Reinauer278534d2008-10-29 04:51:07 +000023
Arthur Heymans794f56b2018-06-15 19:37:23 +020024 pci_domain_read_resources(dev);
25
Stefan Reinauer71a3d962009-07-21 21:44:24 +000026 /* Can we find out how much memory we can use at most
27 * this way?
28 */
Arthur Heymans7fcd4d52023-08-24 15:12:19 +020029 pci_tolm = find_pci_tolm(dev->downstream);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000030 printk(BIOS_DEBUG, "pci_tolm: 0x%x\n", pci_tolm);
Stefan Reinauer278534d2008-10-29 04:51:07 +000031
Arthur Heymans85549542023-07-05 09:42:09 +020032 tolud = pci_read_config8(d0f0, TOLUD) << 24;
33 printk(BIOS_SPEW, "Top of Low Used DRAM: 0x%08lx\n", tolud);
Stefan Reinauer278534d2008-10-29 04:51:07 +000034
35 /* Report the memory regions */
Arthur Heymans85549542023-07-05 09:42:09 +020036 ram_range(dev, idx++, 0, 0xa0000);
37 ram_from_to(dev, idx++, 1 * MiB, (uintptr_t)cbmem_top());
38
39 /* TSEG */
40 uintptr_t tseg_base;
41 size_t tseg_size;
42 smm_region(&tseg_base, &tseg_size);
43 mmio_range(dev, idx++, tseg_base, tseg_size);
44
45 /* cbmem_top can be shifted downwards due to alignment.
46 Mark the region between cbmem_top and tseg_base as unusable */
47 if ((uintptr_t)cbmem_top() < tseg_base) {
48 printk(BIOS_DEBUG, "Unused RAM between cbmem_top and TOM: 0x%lx\n",
49 tseg_base - (uintptr_t)cbmem_top());
50 mmio_from_to(dev, idx++, (uintptr_t)cbmem_top(), tseg_base);
51 }
52 if (tseg_base + tseg_size < tolud)
53 mmio_from_to(dev, idx++, tseg_base + tseg_size, tolud);
54
Furquan Shaikh7cf96ae2020-05-16 23:55:02 -070055 /* legacy VGA memory */
Arthur Heymans85549542023-07-05 09:42:09 +020056 mmio_from_to(dev, idx++, 0xa0000, 0xc0000);
Arthur Heymans15ef9b62021-01-18 00:48:27 +010057 /* RAM to be used for option roms and BIOS */
Arthur Heymans85549542023-07-05 09:42:09 +020058 reserved_ram_from_to(dev, idx++, 0xc0000, 1 * MiB);
Arthur Heymans794f56b2018-06-15 19:37:23 +020059}
60
61static void mch_domain_set_resources(struct device *dev)
62{
63 struct resource *res;
64
65 for (res = dev->resource_list; res; res = res->next)
66 report_resource_stored(dev, res, "");
Kyösti Mälkki6ff1d362012-07-27 08:42:20 +030067
Arthur Heymans7fcd4d52023-08-24 15:12:19 +020068 assign_resources(dev->downstream);
Stefan Reinauer278534d2008-10-29 04:51:07 +000069}
70
Arthur Heymansa8a9f342017-12-24 08:11:13 +010071static const char *northbridge_acpi_name(const struct device *dev)
72{
73 if (dev->path.type == DEVICE_PATH_DOMAIN)
74 return "PCI0";
75
Fabio Aiuto61ed4ef2022-09-30 14:55:53 +020076 if (!is_pci_dev_on_bus(dev, 0))
Arthur Heymansa8a9f342017-12-24 08:11:13 +010077 return NULL;
78
79 switch (dev->path.pci.devfn) {
80 case PCI_DEVFN(0, 0):
81 return "MCHC";
82 }
83
84 return NULL;
85}
86
Arthur Heymanscf3076e2018-04-10 12:57:42 +020087void northbridge_write_smram(u8 smram)
88{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030089 struct device *dev = pcidev_on_root(0, 0);
Arthur Heymanscf3076e2018-04-10 12:57:42 +020090
Elyes Haouas5e6b0f02022-09-13 09:55:49 +020091 if (!dev)
Arthur Heymanscf3076e2018-04-10 12:57:42 +020092 die("could not find pci 00:00.0!\n");
93
94 pci_write_config8(dev, SMRAM, smram);
95}
96
Arthur Heymans22d6ee82022-11-07 10:03:40 +010097struct device_operations i945_pci_domain_ops = {
Arthur Heymans794f56b2018-06-15 19:37:23 +020098 .read_resources = mch_domain_read_resources,
99 .set_resources = mch_domain_set_resources,
Arthur Heymans0b0113f2023-08-31 17:09:28 +0200100 .scan_bus = pci_host_bridge_scan_bus,
Arthur Heymansa8a9f342017-12-24 08:11:13 +0100101 .acpi_name = northbridge_acpi_name,
Stefan Reinauer278534d2008-10-29 04:51:07 +0000102};
103
Elyes HAOUAS658a9342018-02-08 14:46:22 +0100104static void mc_read_resources(struct device *dev)
Stefan Reinauer278534d2008-10-29 04:51:07 +0000105{
Stefan Reinauer278534d2008-10-29 04:51:07 +0000106 pci_dev_read_resources(dev);
107
Angel Ponsa6b09222021-01-20 13:00:02 +0100108 mmconf_resource(dev, PCIEXBAR);
Stefan Reinauer278534d2008-10-29 04:51:07 +0000109}
110
Stefan Reinauer278534d2008-10-29 04:51:07 +0000111static struct device_operations mc_ops = {
112 .read_resources = mc_read_resources,
Kyösti Mälkki27198ac2016-12-02 14:38:13 +0200113 .set_resources = pci_dev_set_resources,
Stefan Reinauer278534d2008-10-29 04:51:07 +0000114 .enable_resources = pci_dev_enable_resources,
Nico Huber68680dd2020-03-31 17:34:52 +0200115 .acpi_fill_ssdt = generate_cpu_entries,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200116 .ops_pci = &pci_dev_ops_pci,
Stefan Reinauer278534d2008-10-29 04:51:07 +0000117};
118
Nico Huber04be6b52016-10-22 20:01:34 +0200119static const unsigned short pci_device_ids[] = {
120 0x2770, /* desktop */
121 0x27a0, 0x27ac, /* mobile */
122 0 };
Vladimir Serbinenkob67eaee2014-11-16 23:08:05 +0100123
Stefan Reinauer278534d2008-10-29 04:51:07 +0000124static const struct pci_driver mc_driver __pci_driver = {
125 .ops = &mc_ops,
Felix Singer43b7f412022-03-07 04:34:52 +0100126 .vendor = PCI_VID_INTEL,
Vladimir Serbinenkob67eaee2014-11-16 23:08:05 +0100127 .devices = pci_device_ids,
Stefan Reinauer278534d2008-10-29 04:51:07 +0000128};
129
Arthur Heymans22d6ee82022-11-07 10:03:40 +0100130struct device_operations i945_cpu_bus_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +0200131 .read_resources = noop_read_resources,
132 .set_resources = noop_set_resources,
Kyösti Mälkkib3267e02019-08-13 16:44:04 +0300133 .init = mp_cpu_bus_init,
Stefan Reinauer278534d2008-10-29 04:51:07 +0000134};
135
Stefan Reinauer278534d2008-10-29 04:51:07 +0000136struct chip_operations northbridge_intel_i945_ops = {
Nicholas Sudsgaardbfb11be2024-01-30 09:53:46 +0900137 .name = "Intel i945 Northbridge",
Stefan Reinauer278534d2008-10-29 04:51:07 +0000138};
Arthur Heymans98c92572022-11-07 11:39:58 +0100139
140bool northbridge_support_slfm(void)
141{
142 return false;
143}