Martin Roth | 5474eb1 | 2018-05-26 19:22:33 -0600 | [diff] [blame] | 1 | /* |
| 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 | |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 14 | #include <console/console.h> |
| 15 | #include <arch/io.h> |
| 16 | #include <stdint.h> |
| 17 | #include <device/device.h> |
| 18 | #include <device/pci.h> |
| 19 | #include <cpu/cpu.h> |
| 20 | #include <stdlib.h> |
| 21 | #include <string.h> |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 22 | #include "e7505.h" |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 23 | #include <cbmem.h> |
Vladimir Serbinenko | c7310d9 | 2014-09-01 09:45:05 +0200 | [diff] [blame] | 24 | #include <arch/acpi.h> |
| 25 | |
| 26 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 27 | { |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 28 | /* Just a dummy */ |
| 29 | return current; |
Vladimir Serbinenko | c7310d9 | 2014-09-01 09:45:05 +0200 | [diff] [blame] | 30 | } |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 31 | |
Kyösti Mälkki | 9e69c87 | 2018-06-02 15:35:27 +0300 | [diff] [blame^] | 32 | static void mch_domain_read_resources(struct device *dev) |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 33 | { |
Elyes HAOUAS | 97e8b75 | 2018-05-09 17:39:47 +0200 | [diff] [blame] | 34 | struct device *mc_dev; |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 35 | uint32_t pci_tolm; |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 36 | |
Kyösti Mälkki | 9e69c87 | 2018-06-02 15:35:27 +0300 | [diff] [blame^] | 37 | pci_domain_read_resources(dev); |
| 38 | |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 39 | pci_tolm = find_pci_tolm(dev->link_list); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 40 | mc_dev = dev->link_list->children; |
| 41 | if (mc_dev) { |
| 42 | /* Figure out which areas are/should be occupied by RAM. |
| 43 | * This is all computed in kilobytes and converted to/from |
| 44 | * the memory controller right at the edges. |
| 45 | * Having different variables in different units is |
| 46 | * too confusing to get right. Kilobytes are good up to |
| 47 | * 4 Terabytes of RAM... |
| 48 | */ |
| 49 | uint16_t tolm_r, remapbase_r, remaplimit_r; |
| 50 | unsigned long tomk, tolmk; |
| 51 | unsigned long remapbasek, remaplimitk; |
| 52 | int idx; |
| 53 | |
| 54 | /* Get the value of the highest DRB. This tells the end of |
| 55 | * the physical memory. The units are ticks of 64MB |
| 56 | * i.e. 1 means 64MB. |
| 57 | */ |
Kyösti Mälkki | 5bd271b | 2012-04-10 16:11:53 +0300 | [diff] [blame] | 58 | tomk = ((unsigned long)pci_read_config8(mc_dev, DRB_ROW_7)) << 16; |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 59 | /* Compute the top of Low memory */ |
| 60 | tolmk = pci_tolm >> 10; |
| 61 | if (tolmk >= tomk) { |
| 62 | /* The PCI hole does not overlap memory |
| 63 | * we won't use the remap window. |
| 64 | */ |
| 65 | tolmk = tomk; |
| 66 | remapbasek = 0x3ff << 16; |
| 67 | remaplimitk = 0 << 16; |
| 68 | } |
| 69 | else { |
| 70 | /* The PCI memory hole overlaps memory |
| 71 | * setup the remap window. |
| 72 | */ |
| 73 | /* Find the bottom of the remap window |
| 74 | * is it above 4G? |
| 75 | */ |
| 76 | remapbasek = 4*1024*1024; |
| 77 | if (tomk > remapbasek) { |
| 78 | remapbasek = tomk; |
| 79 | } |
| 80 | /* Find the limit of the remap window */ |
| 81 | remaplimitk = (remapbasek + (4*1024*1024 - tolmk) - (1 << 16)); |
| 82 | } |
Elyes HAOUAS | 15279a9 | 2016-07-28 21:05:26 +0200 | [diff] [blame] | 83 | /* Write the RAM configuration registers, |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 84 | * preserving the reserved bits. |
| 85 | */ |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 86 | tolm_r = pci_read_config16(mc_dev, TOLM); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 87 | tolm_r = ((tolmk >> 17) << 11) | (tolm_r & 0x7ff); |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 88 | pci_write_config16(mc_dev, TOLM, tolm_r); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 89 | |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 90 | remapbase_r = pci_read_config16(mc_dev, REMAPBASE); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 91 | remapbase_r = (remapbasek >> 16) | (remapbase_r & 0xfc00); |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 92 | pci_write_config16(mc_dev, REMAPBASE, remapbase_r); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 93 | |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 94 | remaplimit_r = pci_read_config16(mc_dev, REMAPLIMIT); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 95 | remaplimit_r = (remaplimitk >> 16) | (remaplimit_r & 0xfc00); |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 96 | pci_write_config16(mc_dev, REMAPLIMIT, remaplimit_r); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 97 | |
| 98 | /* Report the memory regions */ |
| 99 | idx = 10; |
| 100 | ram_resource(dev, idx++, 0, 640); |
| 101 | ram_resource(dev, idx++, 768, tolmk - 768); |
| 102 | if (tomk > 4*1024*1024) { |
| 103 | ram_resource(dev, idx++, 4096*1024, tomk - 4*1024*1024); |
| 104 | } |
| 105 | if (remaplimitk >= remapbasek) { |
| 106 | ram_resource(dev, idx++, remapbasek, |
| 107 | (remaplimitk + 64*1024) - remapbasek); |
| 108 | } |
| 109 | |
Kyösti Mälkki | 70d92b9 | 2017-04-19 19:57:01 +0300 | [diff] [blame] | 110 | set_late_cbmem_top(tolmk * 1024); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 111 | } |
Kyösti Mälkki | 9e69c87 | 2018-06-02 15:35:27 +0300 | [diff] [blame^] | 112 | } |
| 113 | |
| 114 | static void mch_domain_set_resources(struct device *dev) |
| 115 | { |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 116 | assign_resources(dev->link_list); |
| 117 | } |
| 118 | |
Elyes HAOUAS | 97e8b75 | 2018-05-09 17:39:47 +0200 | [diff] [blame] | 119 | static void intel_set_subsystem(struct device *dev, |
| 120 | unsigned vendor, unsigned device) |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 121 | { |
| 122 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 123 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 124 | } |
| 125 | |
| 126 | static struct pci_operations intel_pci_ops = { |
| 127 | .set_subsystem = intel_set_subsystem, |
| 128 | }; |
| 129 | |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 130 | static struct device_operations pci_domain_ops = { |
Kyösti Mälkki | 9e69c87 | 2018-06-02 15:35:27 +0300 | [diff] [blame^] | 131 | .read_resources = mch_domain_read_resources, |
| 132 | .set_resources = mch_domain_set_resources, |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 133 | .enable_resources = NULL, |
| 134 | .init = NULL, |
| 135 | .scan_bus = pci_domain_scan_bus, |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 136 | .ops_pci = &intel_pci_ops, |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 137 | }; |
| 138 | |
Elyes HAOUAS | 97e8b75 | 2018-05-09 17:39:47 +0200 | [diff] [blame] | 139 | static void cpu_bus_init(struct device *dev) |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 140 | { |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 141 | initialize_cpus(dev->link_list); |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 144 | static struct device_operations cpu_bus_ops = { |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 145 | .read_resources = DEVICE_NOOP, |
| 146 | .set_resources = DEVICE_NOOP, |
| 147 | .enable_resources = DEVICE_NOOP, |
| 148 | .init = cpu_bus_init, |
| 149 | .scan_bus = 0, |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 150 | }; |
| 151 | |
| 152 | static void enable_dev(struct device *dev) |
| 153 | { |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 154 | /* Set the operations if it is a special bus type */ |
| 155 | if (dev->path.type == DEVICE_PATH_DOMAIN) { |
| 156 | dev->ops = &pci_domain_ops; |
| 157 | } |
| 158 | else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) { |
| 159 | dev->ops = &cpu_bus_ops; |
| 160 | } |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Kyösti Mälkki | 0a0d5e8 | 2011-10-31 14:18:33 +0200 | [diff] [blame] | 163 | struct chip_operations northbridge_intel_e7505_ops = { |
| 164 | CHIP_NAME("Intel E7505 Northbridge") |
Stefan Reinauer | b15975b | 2011-10-21 12:57:59 -0700 | [diff] [blame] | 165 | .enable_dev = enable_dev, |
| 166 | }; |