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 | #include <cbmem.h> |
Vladimir Serbinenko | c7310d9 | 2014-09-01 09:45:05 +0200 | [diff] [blame] | 11 | #include <arch/acpi.h> |
| 12 | |
| 13 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 14 | { |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 15 | /* Just a dummy */ |
| 16 | return current; |
Vladimir Serbinenko | c7310d9 | 2014-09-01 09:45:05 +0200 | [diff] [blame] | 17 | } |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 18 | |
Elyes HAOUAS | 97e8b75 | 2018-05-09 17:39:47 +0200 | [diff] [blame^] | 19 | static void pci_domain_set_resources(struct device *dev) |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 20 | { |
Elyes HAOUAS | 97e8b75 | 2018-05-09 17:39:47 +0200 | [diff] [blame^] | 21 | struct device *mc_dev; |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 22 | uint32_t pci_tolm; |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 23 | |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 24 | pci_tolm = find_pci_tolm(dev->link_list); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 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älkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 43 | tomk = ((unsigned long)pci_read_config8(mc_dev, DRB_ROW_7)) << 16; |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 44 | /* 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 | } |
Elyes HAOUAS | 15279a9 | 2016-07-28 21:05:26 +0200 | [diff] [blame] | 68 | /* Write the RAM configuration registers, |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 69 | * preserving the reserved bits. |
| 70 | */ |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 71 | tolm_r = pci_read_config16(mc_dev, TOLM); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 72 | tolm_r = ((tolmk >> 17) << 11) | (tolm_r & 0x7ff); |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 73 | pci_write_config16(mc_dev, TOLM, tolm_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 | remapbase_r = pci_read_config16(mc_dev, REMAPBASE); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 76 | remapbase_r = (remapbasek >> 16) | (remapbase_r & 0xfc00); |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 77 | pci_write_config16(mc_dev, REMAPBASE, remapbase_r); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 78 | |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 79 | remaplimit_r = pci_read_config16(mc_dev, REMAPLIMIT); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 80 | remaplimit_r = (remaplimitk >> 16) | (remaplimit_r & 0xfc00); |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 81 | pci_write_config16(mc_dev, REMAPLIMIT, remaplimit_r); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 82 | |
| 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älkki | 70d92b9 | 2017-04-19 19:57:01 +0300 | [diff] [blame] | 95 | set_late_cbmem_top(tolmk * 1024); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 96 | } |
| 97 | assign_resources(dev->link_list); |
| 98 | } |
| 99 | |
Elyes HAOUAS | 97e8b75 | 2018-05-09 17:39:47 +0200 | [diff] [blame^] | 100 | static void intel_set_subsystem(struct device *dev, |
| 101 | unsigned vendor, unsigned device) |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 102 | { |
| 103 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 104 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 105 | } |
| 106 | |
| 107 | static struct pci_operations intel_pci_ops = { |
| 108 | .set_subsystem = intel_set_subsystem, |
| 109 | }; |
| 110 | |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 111 | static struct device_operations pci_domain_ops = { |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 112 | .read_resources = pci_domain_read_resources, |
| 113 | .set_resources = pci_domain_set_resources, |
| 114 | .enable_resources = NULL, |
| 115 | .init = NULL, |
| 116 | .scan_bus = pci_domain_scan_bus, |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 117 | .ops_pci = &intel_pci_ops, |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
Elyes HAOUAS | 97e8b75 | 2018-05-09 17:39:47 +0200 | [diff] [blame^] | 120 | static void cpu_bus_init(struct device *dev) |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 121 | { |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 122 | initialize_cpus(dev->link_list); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 125 | static struct device_operations cpu_bus_ops = { |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 126 | .read_resources = DEVICE_NOOP, |
| 127 | .set_resources = DEVICE_NOOP, |
| 128 | .enable_resources = DEVICE_NOOP, |
| 129 | .init = cpu_bus_init, |
| 130 | .scan_bus = 0, |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | static void enable_dev(struct device *dev) |
| 134 | { |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 135 | /* Set the operations if it is a special bus type */ |
| 136 | if (dev->path.type == DEVICE_PATH_DOMAIN) { |
| 137 | dev->ops = &pci_domain_ops; |
| 138 | } |
| 139 | else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) { |
| 140 | dev->ops = &cpu_bus_ops; |
| 141 | } |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 144 | struct chip_operations northbridge_intel_e7505_ops = { |
| 145 | CHIP_NAME("Intel E7505 Northbridge") |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 146 | .enable_dev = enable_dev, |
| 147 | }; |