blob: 54c700bfb9b89e4c601b3f476e5d5456b0c3c451 [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#include <cbmem.h>
Vladimir Serbinenkoc7310d92014-09-01 09:45:05 +020011#include <arch/acpi.h>
12
13unsigned long acpi_fill_mcfg(unsigned long current)
14{
15 /* Just a dummy */
16 return current;
17}
Stefan Reinauerb15975b2011-10-21 12:57:59 -070018
19static void pci_domain_set_resources(device_t dev)
20{
21 device_t mc_dev;
22 uint32_t pci_tolm;
23
24 pci_tolm = find_pci_tolm(dev->link_list);
25 mc_dev = dev->link_list->children;
26 if (mc_dev) {
27 /* Figure out which areas are/should be occupied by RAM.
28 * This is all computed in kilobytes and converted to/from
29 * the memory controller right at the edges.
30 * Having different variables in different units is
31 * too confusing to get right. Kilobytes are good up to
32 * 4 Terabytes of RAM...
33 */
34 uint16_t tolm_r, remapbase_r, remaplimit_r;
35 unsigned long tomk, tolmk;
36 unsigned long remapbasek, remaplimitk;
37 int idx;
38
39 /* Get the value of the highest DRB. This tells the end of
40 * the physical memory. The units are ticks of 64MB
41 * i.e. 1 means 64MB.
42 */
Kyösti Mälkki5bd271b2012-04-10 16:11:53 +030043 tomk = ((unsigned long)pci_read_config8(mc_dev, DRB_ROW_7)) << 16;
Stefan Reinauerb15975b2011-10-21 12:57:59 -070044 /* Compute the top of Low memory */
45 tolmk = pci_tolm >> 10;
46 if (tolmk >= tomk) {
47 /* The PCI hole does not overlap memory
48 * we won't use the remap window.
49 */
50 tolmk = tomk;
51 remapbasek = 0x3ff << 16;
52 remaplimitk = 0 << 16;
53 }
54 else {
55 /* The PCI memory hole overlaps memory
56 * setup the remap window.
57 */
58 /* Find the bottom of the remap window
59 * is it above 4G?
60 */
61 remapbasek = 4*1024*1024;
62 if (tomk > remapbasek) {
63 remapbasek = tomk;
64 }
65 /* Find the limit of the remap window */
66 remaplimitk = (remapbasek + (4*1024*1024 - tolmk) - (1 << 16));
67 }
68 /* Write the ram configuration registers,
69 * preserving the reserved bits.
70 */
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +020071 tolm_r = pci_read_config16(mc_dev, TOLM);
Stefan Reinauerb15975b2011-10-21 12:57:59 -070072 tolm_r = ((tolmk >> 17) << 11) | (tolm_r & 0x7ff);
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +020073 pci_write_config16(mc_dev, TOLM, tolm_r);
Stefan Reinauerb15975b2011-10-21 12:57:59 -070074
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +020075 remapbase_r = pci_read_config16(mc_dev, REMAPBASE);
Stefan Reinauerb15975b2011-10-21 12:57:59 -070076 remapbase_r = (remapbasek >> 16) | (remapbase_r & 0xfc00);
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +020077 pci_write_config16(mc_dev, REMAPBASE, remapbase_r);
Stefan Reinauerb15975b2011-10-21 12:57:59 -070078
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +020079 remaplimit_r = pci_read_config16(mc_dev, REMAPLIMIT);
Stefan Reinauerb15975b2011-10-21 12:57:59 -070080 remaplimit_r = (remaplimitk >> 16) | (remaplimit_r & 0xfc00);
Kyösti Mälkki0a0d5e82011-10-31 14:18:33 +020081 pci_write_config16(mc_dev, REMAPLIMIT, remaplimit_r);
Stefan Reinauerb15975b2011-10-21 12:57:59 -070082
83 /* Report the memory regions */
84 idx = 10;
85 ram_resource(dev, idx++, 0, 640);
86 ram_resource(dev, idx++, 768, tolmk - 768);
87 if (tomk > 4*1024*1024) {
88 ram_resource(dev, idx++, 4096*1024, tomk - 4*1024*1024);
89 }
90 if (remaplimitk >= remapbasek) {
91 ram_resource(dev, idx++, remapbasek,
92 (remaplimitk + 64*1024) - remapbasek);
93 }
94
Kyösti Mälkki42f46512013-06-27 08:20:09 +030095 set_top_of_ram(tolmk * 1024);
Stefan Reinauerb15975b2011-10-21 12:57:59 -070096 }
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,
Kyösti Mälkki33e5df32013-07-03 10:51:34 +0300117 .ops_pci_bus = pci_bus_default_ops,
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700118};
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 }
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800143 else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
Stefan Reinauerb15975b2011-10-21 12:57:59 -0700144 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};