blob: 0a72cb7d6099aa4f89c3735d6ff466fbab3cc7e5 [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
Richard Smithcb8eab42006-07-24 04:25:47 +00003#include <console/console.h>
Arthur Heymans46e93f92021-11-26 14:53:13 +01004#include <cpu/x86/mp.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02005#include <device/pci_ops.h>
Richard Smithcb8eab42006-07-24 04:25:47 +00006#include <device/device.h>
7#include <device/pci.h>
8#include <device/pci_ids.h>
Arthur Heymans46e93f92021-11-26 14:53:13 +01009#include <stdint.h>
Uwe Hermann1a9c8922007-04-01 17:24:03 +000010#include "i440bx.h"
Richard Smithcb8eab42006-07-24 04:25:47 +000011
Elyes HAOUAS64d2d102018-02-09 08:43:01 +010012static void northbridge_init(struct device *dev)
Richard Smithcb8eab42006-07-24 04:25:47 +000013{
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000014 printk(BIOS_SPEW, "Northbridge Init\n");
Richard Smithcb8eab42006-07-24 04:25:47 +000015}
16
Richard Smithcb8eab42006-07-24 04:25:47 +000017static struct device_operations northbridge_operations = {
18 .read_resources = pci_dev_read_resources,
19 .set_resources = pci_dev_set_resources,
20 .enable_resources = pci_dev_enable_resources,
21 .init = northbridge_init,
Richard Smithcb8eab42006-07-24 04:25:47 +000022};
23
Stefan Reinauerf1cf1f72007-10-24 09:08:58 +000024static const struct pci_driver northbridge_driver __pci_driver = {
Richard Smithcb8eab42006-07-24 04:25:47 +000025 .ops = &northbridge_operations,
Felix Singer43b7f412022-03-07 04:34:52 +010026 .vendor = PCI_VID_INTEL,
Myles Watson032a9652009-05-11 22:24:53 +000027 .device = 0x7190,
Richard Smithcb8eab42006-07-24 04:25:47 +000028};
29
Furquan Shaikhffa5e8d2020-05-13 13:00:49 -070030static void i440bx_domain_read_resources(struct device *dev)
Richard Smithcb8eab42006-07-24 04:25:47 +000031{
Elyes HAOUAS322fa322018-05-09 17:49:56 +020032 struct device *mc_dev;
Uwe Hermannf5a6fd22007-05-27 23:31:31 +000033 uint32_t pci_tolm;
Richard Smithcb8eab42006-07-24 04:25:47 +000034
Furquan Shaikhffa5e8d2020-05-13 13:00:49 -070035 pci_domain_read_resources(dev);
36
Arthur Heymans7fcd4d52023-08-24 15:12:19 +020037 pci_tolm = find_pci_tolm(dev->downstream);
38 mc_dev = dev->downstream->children;
Richard Smithcb8eab42006-07-24 04:25:47 +000039 if (mc_dev) {
40 unsigned long tomk, tolmk;
Uwe Hermann1a9c8922007-04-01 17:24:03 +000041 int idx;
Richard Smithcb8eab42006-07-24 04:25:47 +000042
Uwe Hermannf5a6fd22007-05-27 23:31:31 +000043 /* Figure out which areas are/should be occupied by RAM. The
44 * value of the highest DRB denotes the end of the physical
45 * memory (in units of 8MB).
Uwe Hermann1a9c8922007-04-01 17:24:03 +000046 */
Uwe Hermannf5a6fd22007-05-27 23:31:31 +000047 tomk = ((unsigned long)pci_read_config8(mc_dev, DRB7));
Uwe Hermannf03e4e92007-05-10 23:59:20 +000048
Uwe Hermannf5a6fd22007-05-27 23:31:31 +000049 /* Convert to KB. */
50 tomk *= (8 * 1024);
51
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000052 printk(BIOS_DEBUG, "Setting RAM size to %ld MB\n", tomk / 1024);
Uwe Hermannf5a6fd22007-05-27 23:31:31 +000053
54 /* Compute the top of low memory. */
55 tolmk = pci_tolm / 1024;
56
Richard Smithcb8eab42006-07-24 04:25:47 +000057 if (tolmk >= tomk) {
Myles Watson032a9652009-05-11 22:24:53 +000058 /* The PCI hole does not overlap the memory. */
Richard Smithcb8eab42006-07-24 04:25:47 +000059 tolmk = tomk;
60 }
Uwe Hermann1a9c8922007-04-01 17:24:03 +000061
Uwe Hermannf5a6fd22007-05-27 23:31:31 +000062 /* Report the memory regions. */
Richard Smithcb8eab42006-07-24 04:25:47 +000063 idx = 10;
Arthur Heymansa4b391b2023-07-05 09:25:38 +020064 ram_range(dev, idx++, 0, 0xa0000);
65 ram_from_to(dev, idx++, 0xc0000, tolmk * KiB);
Richard Smithcb8eab42006-07-24 04:25:47 +000066 }
Richard Smithcb8eab42006-07-24 04:25:47 +000067}
68
Richard Smithcb8eab42006-07-24 04:25:47 +000069static struct device_operations pci_domain_ops = {
Furquan Shaikhffa5e8d2020-05-13 13:00:49 -070070 .read_resources = i440bx_domain_read_resources,
71 .set_resources = pci_domain_set_resources,
Arthur Heymans0b0113f2023-08-31 17:09:28 +020072 .scan_bus = pci_host_bridge_scan_bus,
Myles Watson032a9652009-05-11 22:24:53 +000073};
Richard Smithcb8eab42006-07-24 04:25:47 +000074
Arthur Heymans46e93f92021-11-26 14:53:13 +010075static int get_cpu_count(void)
Richard Smithcb8eab42006-07-24 04:25:47 +000076{
Arthur Heymans46e93f92021-11-26 14:53:13 +010077 return CONFIG_MAX_CPUS;
78}
79
80static const struct mp_ops mp_ops = {
81 .get_cpu_count = get_cpu_count,
82};
83
84void mp_init_cpus(struct bus *cpu_bus)
85{
86 /* TODO: Handle mp_init_with_smm failure? */
87 mp_init_with_smm(cpu_bus, &mp_ops);
Richard Smithcb8eab42006-07-24 04:25:47 +000088}
89
Richard Smithcb8eab42006-07-24 04:25:47 +000090static struct device_operations cpu_bus_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +020091 .read_resources = noop_read_resources,
92 .set_resources = noop_set_resources,
Arthur Heymans46e93f92021-11-26 14:53:13 +010093 .init = mp_cpu_bus_init,
Richard Smithcb8eab42006-07-24 04:25:47 +000094};
95
96static void enable_dev(struct device *dev)
97{
Myles Watson032a9652009-05-11 22:24:53 +000098 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -080099 if (dev->path.type == DEVICE_PATH_DOMAIN) {
Myles Watson032a9652009-05-11 22:24:53 +0000100 dev->ops = &pci_domain_ops;
Myles Watson032a9652009-05-11 22:24:53 +0000101 }
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800102 else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
Myles Watson032a9652009-05-11 22:24:53 +0000103 dev->ops = &cpu_bus_ops;
104 }
Richard Smithcb8eab42006-07-24 04:25:47 +0000105}
106
107struct chip_operations northbridge_intel_i440bx_ops = {
Nicholas Sudsgaardbfb11be2024-01-30 09:53:46 +0900108 .name = "Intel 82443BX (440BX) Northbridge",
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000109 .enable_dev = enable_dev,
Richard Smithcb8eab42006-07-24 04:25:47 +0000110};