blob: ae897662c0cff658b33632e00543c1acdb5fe786 [file] [log] [blame]
Martin Roth5474eb12018-05-26 19:22:33 -06001/*
2 * This file is part of the coreboot project.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
Richard Smithcb8eab42006-07-24 04:25:47 +000014#include <console/console.h>
15#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020016#include <device/pci_ops.h>
Richard Smithcb8eab42006-07-24 04:25:47 +000017#include <stdint.h>
18#include <device/device.h>
19#include <device/pci.h>
20#include <device/pci_ids.h>
21#include <stdlib.h>
22#include <string.h>
Corey Osgoode562f722008-12-19 03:36:48 +000023#include <cpu/cpu.h>
Richard Smithcb8eab42006-07-24 04:25:47 +000024#include "northbridge.h"
Uwe Hermann1a9c8922007-04-01 17:24:03 +000025#include "i440bx.h"
Richard Smithcb8eab42006-07-24 04:25:47 +000026
Elyes HAOUAS64d2d102018-02-09 08:43:01 +010027static void northbridge_init(struct device *dev)
Richard Smithcb8eab42006-07-24 04:25:47 +000028{
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000029 printk(BIOS_SPEW, "Northbridge Init\n");
Richard Smithcb8eab42006-07-24 04:25:47 +000030}
31
Richard Smithcb8eab42006-07-24 04:25:47 +000032static struct device_operations northbridge_operations = {
33 .read_resources = pci_dev_read_resources,
34 .set_resources = pci_dev_set_resources,
35 .enable_resources = pci_dev_enable_resources,
36 .init = northbridge_init,
37 .enable = 0,
38 .ops_pci = 0,
39};
40
Stefan Reinauerf1cf1f72007-10-24 09:08:58 +000041static const struct pci_driver northbridge_driver __pci_driver = {
Richard Smithcb8eab42006-07-24 04:25:47 +000042 .ops = &northbridge_operations,
43 .vendor = PCI_VENDOR_ID_INTEL,
Myles Watson032a9652009-05-11 22:24:53 +000044 .device = 0x7190,
Richard Smithcb8eab42006-07-24 04:25:47 +000045};
46
Elyes HAOUAS64d2d102018-02-09 08:43:01 +010047static void i440bx_domain_set_resources(struct device *dev)
Richard Smithcb8eab42006-07-24 04:25:47 +000048{
Elyes HAOUAS322fa322018-05-09 17:49:56 +020049 struct device *mc_dev;
Uwe Hermannf5a6fd22007-05-27 23:31:31 +000050 uint32_t pci_tolm;
Richard Smithcb8eab42006-07-24 04:25:47 +000051
Myles Watson894a3472010-06-09 22:41:35 +000052 pci_tolm = find_pci_tolm(dev->link_list);
53 mc_dev = dev->link_list->children;
Richard Smithcb8eab42006-07-24 04:25:47 +000054 if (mc_dev) {
55 unsigned long tomk, tolmk;
Uwe Hermann1a9c8922007-04-01 17:24:03 +000056 int idx;
Richard Smithcb8eab42006-07-24 04:25:47 +000057
Uwe Hermannf5a6fd22007-05-27 23:31:31 +000058 /* Figure out which areas are/should be occupied by RAM. The
59 * value of the highest DRB denotes the end of the physical
60 * memory (in units of 8MB).
Uwe Hermann1a9c8922007-04-01 17:24:03 +000061 */
Uwe Hermannf5a6fd22007-05-27 23:31:31 +000062 tomk = ((unsigned long)pci_read_config8(mc_dev, DRB7));
Uwe Hermannf03e4e92007-05-10 23:59:20 +000063
Uwe Hermannf5a6fd22007-05-27 23:31:31 +000064 /* Convert to KB. */
65 tomk *= (8 * 1024);
66
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000067 printk(BIOS_DEBUG, "Setting RAM size to %ld MB\n", tomk / 1024);
Uwe Hermannf5a6fd22007-05-27 23:31:31 +000068
69 /* Compute the top of low memory. */
70 tolmk = pci_tolm / 1024;
71
Richard Smithcb8eab42006-07-24 04:25:47 +000072 if (tolmk >= tomk) {
Myles Watson032a9652009-05-11 22:24:53 +000073 /* The PCI hole does not overlap the memory. */
Richard Smithcb8eab42006-07-24 04:25:47 +000074 tolmk = tomk;
75 }
Uwe Hermann1a9c8922007-04-01 17:24:03 +000076
Uwe Hermannf5a6fd22007-05-27 23:31:31 +000077 /* Report the memory regions. */
Richard Smithcb8eab42006-07-24 04:25:47 +000078 idx = 10;
Uwe Hermann1a9c8922007-04-01 17:24:03 +000079 ram_resource(dev, idx++, 0, 640);
Uwe Hermannf5a6fd22007-05-27 23:31:31 +000080 ram_resource(dev, idx++, 768, tolmk - 768);
Richard Smithcb8eab42006-07-24 04:25:47 +000081 }
Myles Watson894a3472010-06-09 22:41:35 +000082 assign_resources(dev->link_list);
Richard Smithcb8eab42006-07-24 04:25:47 +000083}
84
Richard Smithcb8eab42006-07-24 04:25:47 +000085static struct device_operations pci_domain_ops = {
Myles Watson032a9652009-05-11 22:24:53 +000086 .read_resources = pci_domain_read_resources,
Myles Watson29cc9ed2009-07-02 18:56:24 +000087 .set_resources = i440bx_domain_set_resources,
Myles Watson7eac4452010-06-17 16:16:56 +000088 .enable_resources = NULL,
89 .init = NULL,
Myles Watson032a9652009-05-11 22:24:53 +000090 .scan_bus = pci_domain_scan_bus,
91};
Richard Smithcb8eab42006-07-24 04:25:47 +000092
Elyes HAOUAS64d2d102018-02-09 08:43:01 +010093static void cpu_bus_init(struct device *dev)
Richard Smithcb8eab42006-07-24 04:25:47 +000094{
Myles Watson894a3472010-06-09 22:41:35 +000095 initialize_cpus(dev->link_list);
Richard Smithcb8eab42006-07-24 04:25:47 +000096}
97
Richard Smithcb8eab42006-07-24 04:25:47 +000098static struct device_operations cpu_bus_ops = {
Edward O'Callaghan9f744622014-10-31 08:12:34 +110099 .read_resources = DEVICE_NOOP,
100 .set_resources = DEVICE_NOOP,
101 .enable_resources = DEVICE_NOOP,
Myles Watson032a9652009-05-11 22:24:53 +0000102 .init = cpu_bus_init,
103 .scan_bus = 0,
Richard Smithcb8eab42006-07-24 04:25:47 +0000104};
105
106static void enable_dev(struct device *dev)
107{
Myles Watson032a9652009-05-11 22:24:53 +0000108 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800109 if (dev->path.type == DEVICE_PATH_DOMAIN) {
Myles Watson032a9652009-05-11 22:24:53 +0000110 dev->ops = &pci_domain_ops;
Myles Watson032a9652009-05-11 22:24:53 +0000111 }
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800112 else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
Myles Watson032a9652009-05-11 22:24:53 +0000113 dev->ops = &cpu_bus_ops;
114 }
Richard Smithcb8eab42006-07-24 04:25:47 +0000115}
116
117struct chip_operations northbridge_intel_i440bx_ops = {
Uwe Hermannf5a6fd22007-05-27 23:31:31 +0000118 CHIP_NAME("Intel 82443BX (440BX) Northbridge")
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000119 .enable_dev = enable_dev,
Richard Smithcb8eab42006-07-24 04:25:47 +0000120};