Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 1 | #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älkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 9 | #include "e7505.h" |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 10 | |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 11 | #if CONFIG_WRITE_HIGH_TABLES |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 12 | #include <cbmem.h> |
| 13 | #endif |
| 14 | |
| 15 | static 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älkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 39 | tomk = ((unsigned long)pci_read_config8(mc_dev, DRB_ROW_7)) << 16; |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 40 | /* 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älkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 67 | tolm_r = pci_read_config16(mc_dev, TOLM); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 68 | tolm_r = ((tolmk >> 17) << 11) | (tolm_r & 0x7ff); |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 69 | pci_write_config16(mc_dev, TOLM, tolm_r); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 70 | |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 71 | remapbase_r = pci_read_config16(mc_dev, REMAPBASE); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 72 | remapbase_r = (remapbasek >> 16) | (remapbase_r & 0xfc00); |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 73 | pci_write_config16(mc_dev, REMAPBASE, remapbase_r); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 74 | |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 75 | remaplimit_r = pci_read_config16(mc_dev, REMAPLIMIT); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 76 | remaplimit_r = (remaplimitk >> 16) | (remaplimit_r & 0xfc00); |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 77 | pci_write_config16(mc_dev, REMAPLIMIT, remaplimit_r); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 78 | |
| 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 Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 91 | #if CONFIG_WRITE_HIGH_TABLES |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 92 | /* 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älkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 100 | static 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 | |
| 106 | static struct pci_operations intel_pci_ops = { |
| 107 | .set_subsystem = intel_set_subsystem, |
| 108 | }; |
| 109 | |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 110 | static 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älkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 116 | .ops_pci = &intel_pci_ops, |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 117 | .ops_pci_bus = &pci_cf8_conf1, |
| 118 | }; |
| 119 | |
| 120 | static void cpu_bus_init(device_t dev) |
| 121 | { |
| 122 | initialize_cpus(dev->link_list); |
| 123 | } |
| 124 | |
| 125 | static void cpu_bus_noop(device_t dev) |
| 126 | { |
| 127 | } |
| 128 | |
| 129 | static 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 | |
| 137 | static void enable_dev(struct device *dev) |
| 138 | { |
| 139 | /* Set the operations if it is a special bus type */ |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 140 | if (dev->path.type == DEVICE_PATH_DOMAIN) { |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 141 | dev->ops = &pci_domain_ops; |
| 142 | } |
Stefan Reinauer | 0aa37c4 | 2013-02-12 15:20:54 -0800 | [diff] [blame^] | 143 | else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) { |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 144 | dev->ops = &cpu_bus_ops; |
| 145 | } |
| 146 | } |
| 147 | |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 148 | struct chip_operations northbridge_intel_e7505_ops = { |
| 149 | CHIP_NAME("Intel E7505 Northbridge") |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 150 | .enable_dev = enable_dev, |
| 151 | }; |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 152 | |