blob: da0107c96206993b74d634118bf30b1e65f6cc6f [file] [log] [blame]
Angel Pons4b429832020-04-02 23:48:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Martin Roth5474eb12018-05-26 19:22:33 -06003
Richard Smithcb8eab42006-07-24 04:25:47 +00004#include <console/console.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 <stdint.h>
7#include <device/device.h>
8#include <device/pci.h>
9#include <device/pci_ids.h>
Corey Osgoode562f722008-12-19 03:36:48 +000010#include <cpu/cpu.h>
Richard Smithcb8eab42006-07-24 04:25:47 +000011#include "northbridge.h"
Uwe Hermann1a9c8922007-04-01 17:24:03 +000012#include "i440bx.h"
Richard Smithcb8eab42006-07-24 04:25:47 +000013
Elyes HAOUAS64d2d102018-02-09 08:43:01 +010014static void northbridge_init(struct device *dev)
Richard Smithcb8eab42006-07-24 04:25:47 +000015{
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000016 printk(BIOS_SPEW, "Northbridge Init\n");
Richard Smithcb8eab42006-07-24 04:25:47 +000017}
18
Richard Smithcb8eab42006-07-24 04:25:47 +000019static struct device_operations northbridge_operations = {
20 .read_resources = pci_dev_read_resources,
21 .set_resources = pci_dev_set_resources,
22 .enable_resources = pci_dev_enable_resources,
23 .init = northbridge_init,
Richard Smithcb8eab42006-07-24 04:25:47 +000024};
25
Stefan Reinauerf1cf1f72007-10-24 09:08:58 +000026static const struct pci_driver northbridge_driver __pci_driver = {
Richard Smithcb8eab42006-07-24 04:25:47 +000027 .ops = &northbridge_operations,
28 .vendor = PCI_VENDOR_ID_INTEL,
Myles Watson032a9652009-05-11 22:24:53 +000029 .device = 0x7190,
Richard Smithcb8eab42006-07-24 04:25:47 +000030};
31
Elyes HAOUAS64d2d102018-02-09 08:43:01 +010032static void i440bx_domain_set_resources(struct device *dev)
Richard Smithcb8eab42006-07-24 04:25:47 +000033{
Elyes HAOUAS322fa322018-05-09 17:49:56 +020034 struct device *mc_dev;
Uwe Hermannf5a6fd22007-05-27 23:31:31 +000035 uint32_t pci_tolm;
Richard Smithcb8eab42006-07-24 04:25:47 +000036
Myles Watson894a3472010-06-09 22:41:35 +000037 pci_tolm = find_pci_tolm(dev->link_list);
38 mc_dev = dev->link_list->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;
Uwe Hermann1a9c8922007-04-01 17:24:03 +000064 ram_resource(dev, idx++, 0, 640);
Uwe Hermannf5a6fd22007-05-27 23:31:31 +000065 ram_resource(dev, idx++, 768, tolmk - 768);
Richard Smithcb8eab42006-07-24 04:25:47 +000066 }
Myles Watson894a3472010-06-09 22:41:35 +000067 assign_resources(dev->link_list);
Richard Smithcb8eab42006-07-24 04:25:47 +000068}
69
Richard Smithcb8eab42006-07-24 04:25:47 +000070static struct device_operations pci_domain_ops = {
Myles Watson032a9652009-05-11 22:24:53 +000071 .read_resources = pci_domain_read_resources,
Myles Watson29cc9ed2009-07-02 18:56:24 +000072 .set_resources = i440bx_domain_set_resources,
Myles Watson032a9652009-05-11 22:24:53 +000073 .scan_bus = pci_domain_scan_bus,
74};
Richard Smithcb8eab42006-07-24 04:25:47 +000075
Elyes HAOUAS64d2d102018-02-09 08:43:01 +010076static void cpu_bus_init(struct device *dev)
Richard Smithcb8eab42006-07-24 04:25:47 +000077{
Myles Watson894a3472010-06-09 22:41:35 +000078 initialize_cpus(dev->link_list);
Richard Smithcb8eab42006-07-24 04:25:47 +000079}
80
Richard Smithcb8eab42006-07-24 04:25:47 +000081static struct device_operations cpu_bus_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +020082 .read_resources = noop_read_resources,
83 .set_resources = noop_set_resources,
Myles Watson032a9652009-05-11 22:24:53 +000084 .init = cpu_bus_init,
Richard Smithcb8eab42006-07-24 04:25:47 +000085};
86
87static void enable_dev(struct device *dev)
88{
Myles Watson032a9652009-05-11 22:24:53 +000089 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -080090 if (dev->path.type == DEVICE_PATH_DOMAIN) {
Myles Watson032a9652009-05-11 22:24:53 +000091 dev->ops = &pci_domain_ops;
Myles Watson032a9652009-05-11 22:24:53 +000092 }
Stefan Reinauer0aa37c42013-02-12 15:20:54 -080093 else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
Myles Watson032a9652009-05-11 22:24:53 +000094 dev->ops = &cpu_bus_ops;
95 }
Richard Smithcb8eab42006-07-24 04:25:47 +000096}
97
98struct chip_operations northbridge_intel_i440bx_ops = {
Uwe Hermannf5a6fd22007-05-27 23:31:31 +000099 CHIP_NAME("Intel 82443BX (440BX) Northbridge")
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000100 .enable_dev = enable_dev,
Richard Smithcb8eab42006-07-24 04:25:47 +0000101};