blob: 00b8f5783b8d707e2e39e61c37df70dde4cff2ef [file] [log] [blame]
Stefan Reinauerb15975b2011-10-21 12:57:59 -07001#include <console/console.h>
2#include <arch/io.h>
3#include <stdint.h>
4#include <device/device.h>
5#include <device/pci.h>
6#include <cpu/cpu.h>
7#include <stdlib.h>
8#include <string.h>
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +02009#include "e7505.h"
Stefan Reinauerb15975b2011-10-21 12:57:59 -070010
Patrick Georgie1667822012-05-05 15:29:32 +020011#if CONFIG_WRITE_HIGH_TABLES
Stefan Reinauerb15975b2011-10-21 12:57:59 -070012#include <cbmem.h>
13#endif
14
15static void pci_domain_set_resources(device_t dev)
16{
17 device_t mc_dev;
18 uint32_t pci_tolm;
19
20 pci_tolm = find_pci_tolm(dev->link_list);
21 mc_dev = dev->link_list->children;
22 if (mc_dev) {
23 /* Figure out which areas are/should be occupied by RAM.
24 * This is all computed in kilobytes and converted to/from
25 * the memory controller right at the edges.
26 * Having different variables in different units is
27 * too confusing to get right. Kilobytes are good up to
28 * 4 Terabytes of RAM...
29 */
30 uint16_t tolm_r, remapbase_r, remaplimit_r;
31 unsigned long tomk, tolmk;
32 unsigned long remapbasek, remaplimitk;
33 int idx;
34
35 /* Get the value of the highest DRB. This tells the end of
36 * the physical memory. The units are ticks of 64MB
37 * i.e. 1 means 64MB.
38 */
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +030039 tomk = ((unsigned long)pci_read_config8(mc_dev, DRB_ROW_7)) << 16;
Stefan Reinauerb15975b2011-10-21 12:57:59 -070040 /* Compute the top of Low memory */
41 tolmk = pci_tolm >> 10;
42 if (tolmk >= tomk) {
43 /* The PCI hole does not overlap memory
44 * we won't use the remap window.
45 */
46 tolmk = tomk;
47 remapbasek = 0x3ff << 16;
48 remaplimitk = 0 << 16;
49 }
50 else {
51 /* The PCI memory hole overlaps memory
52 * setup the remap window.
53 */
54 /* Find the bottom of the remap window
55 * is it above 4G?
56 */
57 remapbasek = 4*1024*1024;
58 if (tomk > remapbasek) {
59 remapbasek = tomk;
60 }
61 /* Find the limit of the remap window */
62 remaplimitk = (remapbasek + (4*1024*1024 - tolmk) - (1 << 16));
63 }
64 /* Write the ram configuration registers,
65 * preserving the reserved bits.
66 */
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +020067 tolm_r = pci_read_config16(mc_dev, TOLM);
Stefan Reinauerb15975b2011-10-21 12:57:59 -070068 tolm_r = ((tolmk >> 17) << 11) | (tolm_r & 0x7ff);
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +020069 pci_write_config16(mc_dev, TOLM, tolm_r);
Stefan Reinauerb15975b2011-10-21 12:57:59 -070070
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +020071 remapbase_r = pci_read_config16(mc_dev, REMAPBASE);
Stefan Reinauerb15975b2011-10-21 12:57:59 -070072 remapbase_r = (remapbasek >> 16) | (remapbase_r & 0xfc00);
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +020073 pci_write_config16(mc_dev, REMAPBASE, remapbase_r);
Stefan Reinauerb15975b2011-10-21 12:57:59 -070074
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +020075 remaplimit_r = pci_read_config16(mc_dev, REMAPLIMIT);
Stefan Reinauerb15975b2011-10-21 12:57:59 -070076 remaplimit_r = (remaplimitk >> 16) | (remaplimit_r & 0xfc00);
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +020077 pci_write_config16(mc_dev, REMAPLIMIT, remaplimit_r);
Stefan Reinauerb15975b2011-10-21 12:57:59 -070078
79 /* Report the memory regions */
80 idx = 10;
81 ram_resource(dev, idx++, 0, 640);
82 ram_resource(dev, idx++, 768, tolmk - 768);
83 if (tomk > 4*1024*1024) {
84 ram_resource(dev, idx++, 4096*1024, tomk - 4*1024*1024);
85 }
86 if (remaplimitk >= remapbasek) {
87 ram_resource(dev, idx++, remapbasek,
88 (remaplimitk + 64*1024) - remapbasek);
89 }
90
Patrick Georgie1667822012-05-05 15:29:32 +020091#if CONFIG_WRITE_HIGH_TABLES
Stefan Reinauerb15975b2011-10-21 12:57:59 -070092 /* Leave some space for ACPI, PIRQ and MP tables */
93 high_tables_base = (tolmk * 1024) - HIGH_MEMORY_SIZE;
94 high_tables_size = HIGH_MEMORY_SIZE;
95#endif
96 }
97 assign_resources(dev->link_list);
98}
99
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +0200100static void intel_set_subsystem(device_t dev, unsigned vendor, unsigned device)
101{
102 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
103 ((device & 0xffff) << 16) | (vendor & 0xffff));
104}
105
106static struct pci_operations intel_pci_ops = {
107 .set_subsystem = intel_set_subsystem,
108};
109
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700110static struct device_operations pci_domain_ops = {
111 .read_resources = pci_domain_read_resources,
112 .set_resources = pci_domain_set_resources,
113 .enable_resources = NULL,
114 .init = NULL,
115 .scan_bus = pci_domain_scan_bus,
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +0200116 .ops_pci = &intel_pci_ops,
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700117 .ops_pci_bus = &pci_cf8_conf1,
118};
119
120static void cpu_bus_init(device_t dev)
121{
122 initialize_cpus(dev->link_list);
123}
124
125static void cpu_bus_noop(device_t dev)
126{
127}
128
129static struct device_operations cpu_bus_ops = {
130 .read_resources = cpu_bus_noop,
131 .set_resources = cpu_bus_noop,
132 .enable_resources = cpu_bus_noop,
133 .init = cpu_bus_init,
134 .scan_bus = 0,
135};
136
137static void enable_dev(struct device *dev)
138{
139 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800140 if (dev->path.type == DEVICE_PATH_DOMAIN) {
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700141 dev->ops = &pci_domain_ops;
142 }
143 else if (dev->path.type == DEVICE_PATH_APIC_CLUSTER) {
144 dev->ops = &cpu_bus_ops;
145 }
146}
147
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +0200148struct chip_operations northbridge_intel_e7505_ops = {
149 CHIP_NAME("Intel E7505 Northbridge")
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700150 .enable_dev = enable_dev,
151};
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +0200152