Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Copyright (C) 2001 Allan Trautman, IBM Corporation |
| 3 | * |
| 4 | * iSeries specific routines for PCI. |
Stephen Rothwell | d387899 | 2005-09-28 02:50:25 +1000 | [diff] [blame] | 5 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * Based on code from pci.c and iSeries_pci.c 32bit |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
Stephen Rothwell | d387899 | 2005-09-28 02:50:25 +1000 | [diff] [blame] | 12 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
Stephen Rothwell | d387899 | 2005-09-28 02:50:25 +1000 | [diff] [blame] | 17 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | */ |
| 22 | #include <linux/kernel.h> |
Stephen Rothwell | d387899 | 2005-09-28 02:50:25 +1000 | [diff] [blame] | 23 | #include <linux/list.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/string.h> |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/pci.h> |
| 28 | |
| 29 | #include <asm/io.h> |
| 30 | #include <asm/irq.h> |
| 31 | #include <asm/prom.h> |
| 32 | #include <asm/machdep.h> |
| 33 | #include <asm/pci-bridge.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <asm/iommu.h> |
Stephen Rothwell | 426c1a1 | 2005-10-14 14:51:42 +1000 | [diff] [blame] | 35 | #include <asm/abs_addr.h> |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 36 | #include <asm/firmware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Kelly Daly | 8021b8a | 2005-11-02 11:41:12 +1100 | [diff] [blame] | 38 | #include <asm/iseries/hv_call_xm.h> |
Kelly Daly | bbc8b62 | 2005-11-02 15:10:38 +1100 | [diff] [blame] | 39 | #include <asm/iseries/mf.h> |
Stephen Rothwell | c7f0e8c | 2006-04-27 17:23:32 +1000 | [diff] [blame] | 40 | #include <asm/iseries/iommu.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Stephen Rothwell | d387899 | 2005-09-28 02:50:25 +1000 | [diff] [blame] | 42 | #include <asm/ppc-pci.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Stephen Rothwell | b08567cb | 2005-09-28 23:37:01 +1000 | [diff] [blame] | 44 | #include "irq.h" |
Stephen Rothwell | 426c1a1 | 2005-10-14 14:51:42 +1000 | [diff] [blame] | 45 | #include "pci.h" |
Stephen Rothwell | c6d2ea9 | 2005-10-14 17:16:17 +1000 | [diff] [blame] | 46 | #include "call_pci.h" |
Stephen Rothwell | b08567cb | 2005-09-28 23:37:01 +1000 | [diff] [blame] | 47 | |
Stephen Rothwell | b9b1812 | 2007-12-07 01:48:14 +1100 | [diff] [blame] | 48 | #define PCI_RETRY_MAX 3 |
| 49 | static int limit_pci_retries = 1; /* Set Retry Error on. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | /* |
| 52 | * Table defines |
| 53 | * Each Entry size is 4 MB * 1024 Entries = 4GB I/O address space. |
| 54 | */ |
| 55 | #define IOMM_TABLE_MAX_ENTRIES 1024 |
| 56 | #define IOMM_TABLE_ENTRY_SIZE 0x0000000000400000UL |
| 57 | #define BASE_IO_MEMORY 0xE000000000000000UL |
| 58 | |
Stephen Rothwell | b58b7f9 | 2006-05-19 16:42:49 +1000 | [diff] [blame] | 59 | static unsigned long max_io_memory = BASE_IO_MEMORY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | static long current_iomm_table_entry; |
| 61 | |
| 62 | /* |
| 63 | * Lookup Tables. |
| 64 | */ |
Stephen Rothwell | b58b7f9 | 2006-05-19 16:42:49 +1000 | [diff] [blame] | 65 | static struct device_node *iomm_table[IOMM_TABLE_MAX_ENTRIES]; |
| 66 | static u8 iobar_table[IOMM_TABLE_MAX_ENTRIES]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Stephen Rothwell | b58b7f9 | 2006-05-19 16:42:49 +1000 | [diff] [blame] | 68 | static const char pci_io_text[] = "iSeries PCI I/O"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | static DEFINE_SPINLOCK(iomm_table_lock); |
| 70 | |
| 71 | /* |
Stephen Rothwell | 2cd1008 | 2007-12-07 01:55:50 +1100 | [diff] [blame^] | 72 | * Generate a Direct Select Address for the Hypervisor |
| 73 | */ |
| 74 | static inline u64 iseries_ds_addr(struct device_node *node) |
| 75 | { |
| 76 | struct pci_dn *pdn = PCI_DN(node); |
| 77 | |
| 78 | return ((u64)pdn->busno << 48) + ((u64)pdn->bussubno << 40) |
| 79 | + ((u64)0x10 << 32); |
| 80 | } |
| 81 | |
| 82 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | * iomm_table_allocate_entry |
| 84 | * |
| 85 | * Adds pci_dev entry in address translation table |
| 86 | * |
| 87 | * - Allocates the number of entries required in table base on BAR |
| 88 | * size. |
| 89 | * - Allocates starting at BASE_IO_MEMORY and increases. |
| 90 | * - The size is round up to be a multiple of entry size. |
| 91 | * - CurrentIndex is incremented to keep track of the last entry. |
| 92 | * - Builds the resource entry for allocated BARs. |
| 93 | */ |
Stephen Rothwell | 1e10590 | 2007-11-19 17:03:59 +1100 | [diff] [blame] | 94 | static void __init iomm_table_allocate_entry(struct pci_dev *dev, int bar_num) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | { |
| 96 | struct resource *bar_res = &dev->resource[bar_num]; |
| 97 | long bar_size = pci_resource_len(dev, bar_num); |
| 98 | |
| 99 | /* |
| 100 | * No space to allocate, quick exit, skip Allocation. |
| 101 | */ |
| 102 | if (bar_size == 0) |
| 103 | return; |
| 104 | /* |
| 105 | * Set Resource values. |
| 106 | */ |
| 107 | spin_lock(&iomm_table_lock); |
| 108 | bar_res->name = pci_io_text; |
Stephen Rothwell | b58b7f9 | 2006-05-19 16:42:49 +1000 | [diff] [blame] | 109 | bar_res->start = BASE_IO_MEMORY + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | IOMM_TABLE_ENTRY_SIZE * current_iomm_table_entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | bar_res->end = bar_res->start + bar_size - 1; |
| 112 | /* |
| 113 | * Allocate the number of table entries needed for BAR. |
| 114 | */ |
| 115 | while (bar_size > 0 ) { |
| 116 | iomm_table[current_iomm_table_entry] = dev->sysdata; |
| 117 | iobar_table[current_iomm_table_entry] = bar_num; |
| 118 | bar_size -= IOMM_TABLE_ENTRY_SIZE; |
| 119 | ++current_iomm_table_entry; |
| 120 | } |
| 121 | max_io_memory = BASE_IO_MEMORY + |
Stephen Rothwell | b58b7f9 | 2006-05-19 16:42:49 +1000 | [diff] [blame] | 122 | IOMM_TABLE_ENTRY_SIZE * current_iomm_table_entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | spin_unlock(&iomm_table_lock); |
| 124 | } |
| 125 | |
| 126 | /* |
| 127 | * allocate_device_bars |
| 128 | * |
| 129 | * - Allocates ALL pci_dev BAR's and updates the resources with the |
| 130 | * BAR value. BARS with zero length will have the resources |
| 131 | * The HvCallPci_getBarParms is used to get the size of the BAR |
| 132 | * space. It calls iomm_table_allocate_entry to allocate |
| 133 | * each entry. |
| 134 | * - Loops through The Bar resources(0 - 5) including the ROM |
| 135 | * is resource(6). |
| 136 | */ |
Stephen Rothwell | 1e10590 | 2007-11-19 17:03:59 +1100 | [diff] [blame] | 137 | static void __init allocate_device_bars(struct pci_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | int bar_num; |
| 140 | |
Stephen Rothwell | b58b7f9 | 2006-05-19 16:42:49 +1000 | [diff] [blame] | 141 | for (bar_num = 0; bar_num <= PCI_ROM_RESOURCE; ++bar_num) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | iomm_table_allocate_entry(dev, bar_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | /* |
| 146 | * Log error information to system console. |
| 147 | * Filter out the device not there errors. |
| 148 | * PCI: EADs Connect Failed 0x18.58.10 Rc: 0x00xx |
| 149 | * PCI: Read Vendor Failed 0x18.58.10 Rc: 0x00xx |
| 150 | * PCI: Connect Bus Unit Failed 0x18.58.10 Rc: 0x00xx |
| 151 | */ |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 152 | static void pci_log_error(char *error, int bus, int subbus, |
| 153 | int agent, int hv_res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 155 | if (hv_res == 0x0302) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | return; |
| 157 | printk(KERN_ERR "PCI: %s Failed: 0x%02X.%02X.%02X Rc: 0x%04X", |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 158 | error, bus, subbus, agent, hv_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | /* |
Stephen Rothwell | 9103eb7 | 2007-12-07 01:46:40 +1100 | [diff] [blame] | 162 | * Look down the chain to find the matching Device Device |
| 163 | */ |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 164 | static struct device_node *find_device_node(int bus, int devfn) |
Stephen Rothwell | 9103eb7 | 2007-12-07 01:46:40 +1100 | [diff] [blame] | 165 | { |
| 166 | struct device_node *node; |
| 167 | |
| 168 | for (node = NULL; (node = of_find_all_nodes(node)); ) { |
| 169 | struct pci_dn *pdn = PCI_DN(node); |
| 170 | |
| 171 | if (pdn && (bus == pdn->busno) && (devfn == pdn->devfn)) |
| 172 | return node; |
| 173 | } |
| 174 | return NULL; |
| 175 | } |
| 176 | |
| 177 | /* |
Stephen Rothwell | d387899 | 2005-09-28 02:50:25 +1000 | [diff] [blame] | 178 | * iSeries_pci_final_fixup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | */ |
| 180 | void __init iSeries_pci_final_fixup(void) |
| 181 | { |
| 182 | struct pci_dev *pdev = NULL; |
Stephen Rothwell | 252e75a | 2005-09-28 14:40:40 +1000 | [diff] [blame] | 183 | struct device_node *node; |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 184 | int num_dev = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | /* Fix up at the device node and pci_dev relationship */ |
| 187 | mf_display_src(0xC9000100); |
| 188 | |
| 189 | printk("pcibios_final_fixup\n"); |
| 190 | for_each_pci_dev(pdev) { |
Stephen Rothwell | 3f17863 | 2007-12-07 01:51:48 +1100 | [diff] [blame] | 191 | struct pci_dn *pdn; |
| 192 | const u32 *agent; |
| 193 | |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 194 | node = find_device_node(pdev->bus->number, pdev->devfn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | printk("pci dev %p (%x.%x), node %p\n", pdev, |
| 196 | pdev->bus->number, pdev->devfn, node); |
Stephen Rothwell | 3f17863 | 2007-12-07 01:51:48 +1100 | [diff] [blame] | 197 | if (!node) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | printk("PCI: Device Tree not found for 0x%016lX\n", |
| 199 | (unsigned long)pdev); |
Stephen Rothwell | 3f17863 | 2007-12-07 01:51:48 +1100 | [diff] [blame] | 200 | continue; |
| 201 | } |
| 202 | |
| 203 | pdn = PCI_DN(node); |
| 204 | agent = of_get_property(node, "linux,agent-id", NULL); |
| 205 | if (pdn && agent) { |
| 206 | u8 irq = iSeries_allocate_IRQ(pdn->busno, 0, |
| 207 | pdn->bussubno); |
| 208 | int err; |
| 209 | |
| 210 | err = HvCallXm_connectBusUnit(pdn->busno, pdn->bussubno, |
| 211 | *agent, irq); |
| 212 | if (err) |
| 213 | pci_log_error("Connect Bus Unit", |
| 214 | pdn->busno, pdn->bussubno, *agent, err); |
| 215 | else { |
| 216 | err = HvCallPci_configStore8(pdn->busno, |
| 217 | pdn->bussubno, *agent, |
| 218 | PCI_INTERRUPT_LINE, irq); |
| 219 | if (err) |
| 220 | pci_log_error("PciCfgStore Irq Failed!", |
| 221 | pdn->busno, pdn->bussubno, |
| 222 | *agent, err); |
| 223 | else |
| 224 | pdev->irq = irq; |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | num_dev++; |
| 229 | pdev->sysdata = node; |
| 230 | PCI_DN(node)->pcidev = pdev; |
| 231 | allocate_device_bars(pdev); |
Stephen Rothwell | 72ece3b | 2007-12-07 01:54:57 +1100 | [diff] [blame] | 232 | iSeries_Device_Information(pdev, num_dev, pdn->busno, |
| 233 | pdn->bussubno); |
Stephen Rothwell | 3f17863 | 2007-12-07 01:51:48 +1100 | [diff] [blame] | 234 | iommu_devnode_init_iSeries(pdev, node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | } |
| 236 | iSeries_activate_IRQs(); |
| 237 | mf_display_src(0xC9000200); |
| 238 | } |
| 239 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | /* |
| 241 | * Config space read and write functions. |
| 242 | * For now at least, we look for the device node for the bus and devfn |
| 243 | * that we are asked to access. It may be possible to translate the devfn |
| 244 | * to a subbus and deviceid more directly. |
| 245 | */ |
| 246 | static u64 hv_cfg_read_func[4] = { |
| 247 | HvCallPciConfigLoad8, HvCallPciConfigLoad16, |
| 248 | HvCallPciConfigLoad32, HvCallPciConfigLoad32 |
| 249 | }; |
| 250 | |
| 251 | static u64 hv_cfg_write_func[4] = { |
| 252 | HvCallPciConfigStore8, HvCallPciConfigStore16, |
| 253 | HvCallPciConfigStore32, HvCallPciConfigStore32 |
| 254 | }; |
| 255 | |
| 256 | /* |
| 257 | * Read PCI config space |
| 258 | */ |
| 259 | static int iSeries_pci_read_config(struct pci_bus *bus, unsigned int devfn, |
| 260 | int offset, int size, u32 *val) |
| 261 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 262 | struct device_node *node = find_device_node(bus->number, devfn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | u64 fn; |
| 264 | struct HvCallPci_LoadReturn ret; |
| 265 | |
| 266 | if (node == NULL) |
| 267 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 268 | if (offset > 255) { |
| 269 | *val = ~0; |
| 270 | return PCIBIOS_BAD_REGISTER_NUMBER; |
| 271 | } |
| 272 | |
| 273 | fn = hv_cfg_read_func[(size - 1) & 3]; |
Stephen Rothwell | 20f48cc | 2005-10-14 16:49:58 +1000 | [diff] [blame] | 274 | HvCall3Ret16(fn, &ret, iseries_ds_addr(node), offset, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | |
| 276 | if (ret.rc != 0) { |
| 277 | *val = ~0; |
| 278 | return PCIBIOS_DEVICE_NOT_FOUND; /* or something */ |
| 279 | } |
| 280 | |
| 281 | *val = ret.value; |
| 282 | return 0; |
| 283 | } |
| 284 | |
| 285 | /* |
| 286 | * Write PCI config space |
| 287 | */ |
| 288 | |
| 289 | static int iSeries_pci_write_config(struct pci_bus *bus, unsigned int devfn, |
| 290 | int offset, int size, u32 val) |
| 291 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 292 | struct device_node *node = find_device_node(bus->number, devfn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | u64 fn; |
| 294 | u64 ret; |
| 295 | |
| 296 | if (node == NULL) |
| 297 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 298 | if (offset > 255) |
| 299 | return PCIBIOS_BAD_REGISTER_NUMBER; |
| 300 | |
| 301 | fn = hv_cfg_write_func[(size - 1) & 3]; |
Stephen Rothwell | 20f48cc | 2005-10-14 16:49:58 +1000 | [diff] [blame] | 302 | ret = HvCall4(fn, iseries_ds_addr(node), offset, val, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
| 304 | if (ret != 0) |
| 305 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 306 | |
| 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | static struct pci_ops iSeries_pci_ops = { |
| 311 | .read = iSeries_pci_read_config, |
| 312 | .write = iSeries_pci_write_config |
| 313 | }; |
| 314 | |
| 315 | /* |
| 316 | * Check Return Code |
| 317 | * -> On Failure, print and log information. |
| 318 | * Increment Retry Count, if exceeds max, panic partition. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | * |
| 320 | * PCI: Device 23.90 ReadL I/O Error( 0): 0x1234 |
| 321 | * PCI: Device 23.90 ReadL Retry( 1) |
| 322 | * PCI: Device 23.90 ReadL Retry Successful(1) |
| 323 | */ |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 324 | static int check_return_code(char *type, struct device_node *dn, |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 325 | int *retry, u64 ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | { |
| 327 | if (ret != 0) { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 328 | struct pci_dn *pdn = PCI_DN(dn); |
Stephen Rothwell | 252e75a | 2005-09-28 14:40:40 +1000 | [diff] [blame] | 329 | |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 330 | (*retry)++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | printk("PCI: %s: Device 0x%04X:%02X I/O Error(%2d): 0x%04X\n", |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 332 | type, pdn->busno, pdn->devfn, |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 333 | *retry, (int)ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | /* |
| 335 | * Bump the retry and check for retry count exceeded. |
| 336 | * If, Exceeded, panic the system. |
| 337 | */ |
Stephen Rothwell | b9b1812 | 2007-12-07 01:48:14 +1100 | [diff] [blame] | 338 | if (((*retry) > PCI_RETRY_MAX) && |
| 339 | (limit_pci_retries > 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | mf_display_src(0xB6000103); |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 341 | panic_timeout = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | panic("PCI: Hardware I/O Error, SRC B6000103, " |
| 343 | "Automatic Reboot Disabled.\n"); |
| 344 | } |
| 345 | return -1; /* Retry Try */ |
| 346 | } |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 347 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | /* |
| 351 | * Translate the I/O Address into a device node, bar, and bar offset. |
| 352 | * Note: Make sure the passed variable end up on the stack to avoid |
| 353 | * the exposure of being device global. |
| 354 | */ |
Stephen Rothwell | 252e75a | 2005-09-28 14:40:40 +1000 | [diff] [blame] | 355 | static inline struct device_node *xlate_iomm_address( |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 356 | const volatile void __iomem *addr, |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 357 | u64 *dsaptr, u64 *bar_offset, const char *func) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 359 | unsigned long orig_addr; |
| 360 | unsigned long base_addr; |
| 361 | unsigned long ind; |
| 362 | struct device_node *dn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 364 | orig_addr = (unsigned long __force)addr; |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 365 | if ((orig_addr < BASE_IO_MEMORY) || (orig_addr >= max_io_memory)) { |
| 366 | static unsigned long last_jiffies; |
| 367 | static int num_printed; |
| 368 | |
| 369 | if ((jiffies - last_jiffies) > 60 * HZ) { |
| 370 | last_jiffies = jiffies; |
| 371 | num_printed = 0; |
| 372 | } |
| 373 | if (num_printed++ < 10) |
| 374 | printk(KERN_ERR |
| 375 | "iSeries_%s: invalid access at IO address %p\n", |
| 376 | func, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | return NULL; |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 378 | } |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 379 | base_addr = orig_addr - BASE_IO_MEMORY; |
| 380 | ind = base_addr / IOMM_TABLE_ENTRY_SIZE; |
| 381 | dn = iomm_table[ind]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 383 | if (dn != NULL) { |
| 384 | int barnum = iobar_table[ind]; |
| 385 | *dsaptr = iseries_ds_addr(dn) | (barnum << 24); |
| 386 | *bar_offset = base_addr % IOMM_TABLE_ENTRY_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | } else |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 388 | panic("PCI: Invalid PCI IO address detected!\n"); |
| 389 | return dn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | /* |
| 393 | * Read MM I/O Instructions for the iSeries |
| 394 | * On MM I/O error, all ones are returned and iSeries_pci_IoError is cal |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 395 | * else, data is returned in Big Endian format. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | */ |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 397 | static u8 iseries_readb(const volatile void __iomem *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 399 | u64 bar_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | u64 dsa; |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 401 | int retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | struct HvCallPci_LoadReturn ret; |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 403 | struct device_node *dn = |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 404 | xlate_iomm_address(addr, &dsa, &bar_offset, "read_byte"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 406 | if (dn == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | return 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | do { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 409 | HvCall3Ret16(HvCallPciBarLoad8, &ret, dsa, bar_offset, 0); |
| 410 | } while (check_return_code("RDB", dn, &retry, ret.rc) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 412 | return ret.value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 415 | static u16 iseries_readw_be(const volatile void __iomem *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 417 | u64 bar_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | u64 dsa; |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 419 | int retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | struct HvCallPci_LoadReturn ret; |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 421 | struct device_node *dn = |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 422 | xlate_iomm_address(addr, &dsa, &bar_offset, "read_word"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 424 | if (dn == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | return 0xffff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | HvCall3Ret16(HvCallPciBarLoad16, &ret, dsa, |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 428 | bar_offset, 0); |
| 429 | } while (check_return_code("RDW", dn, &retry, ret.rc) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 431 | return ret.value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 434 | static u32 iseries_readl_be(const volatile void __iomem *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 436 | u64 bar_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | u64 dsa; |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 438 | int retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | struct HvCallPci_LoadReturn ret; |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 440 | struct device_node *dn = |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 441 | xlate_iomm_address(addr, &dsa, &bar_offset, "read_long"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 443 | if (dn == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | return 0xffffffff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | HvCall3Ret16(HvCallPciBarLoad32, &ret, dsa, |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 447 | bar_offset, 0); |
| 448 | } while (check_return_code("RDL", dn, &retry, ret.rc) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 450 | return ret.value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | |
| 453 | /* |
| 454 | * Write MM I/O Instructions for the iSeries |
| 455 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | */ |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 457 | static void iseries_writeb(u8 data, volatile void __iomem *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 459 | u64 bar_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | u64 dsa; |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 461 | int retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | u64 rc; |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 463 | struct device_node *dn = |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 464 | xlate_iomm_address(addr, &dsa, &bar_offset, "write_byte"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 466 | if (dn == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | do { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 469 | rc = HvCall4(HvCallPciBarStore8, dsa, bar_offset, data, 0); |
| 470 | } while (check_return_code("WWB", dn, &retry, rc) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 473 | static void iseries_writew_be(u16 data, volatile void __iomem *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 475 | u64 bar_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | u64 dsa; |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 477 | int retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | u64 rc; |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 479 | struct device_node *dn = |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 480 | xlate_iomm_address(addr, &dsa, &bar_offset, "write_word"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 482 | if (dn == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | do { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 485 | rc = HvCall4(HvCallPciBarStore16, dsa, bar_offset, data, 0); |
| 486 | } while (check_return_code("WWW", dn, &retry, rc) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 489 | static void iseries_writel_be(u32 data, volatile void __iomem *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 491 | u64 bar_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | u64 dsa; |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 493 | int retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | u64 rc; |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 495 | struct device_node *dn = |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 496 | xlate_iomm_address(addr, &dsa, &bar_offset, "write_long"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 498 | if (dn == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | do { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 501 | rc = HvCall4(HvCallPciBarStore32, dsa, bar_offset, data, 0); |
| 502 | } while (check_return_code("WWL", dn, &retry, rc) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 504 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 505 | static u16 iseries_readw(const volatile void __iomem *addr) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 506 | { |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 507 | return le16_to_cpu(iseries_readw_be(addr)); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 508 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 509 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 510 | static u32 iseries_readl(const volatile void __iomem *addr) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 511 | { |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 512 | return le32_to_cpu(iseries_readl_be(addr)); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 513 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 514 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 515 | static void iseries_writew(u16 data, volatile void __iomem *addr) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 516 | { |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 517 | iseries_writew_be(cpu_to_le16(data), addr); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 518 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 519 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 520 | static void iseries_writel(u32 data, volatile void __iomem *addr) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 521 | { |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 522 | iseries_writel(cpu_to_le32(data), addr); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 523 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 524 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 525 | static void iseries_readsb(const volatile void __iomem *addr, void *buf, |
| 526 | unsigned long count) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 527 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 528 | u8 *dst = buf; |
| 529 | while(count-- > 0) |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 530 | *(dst++) = iseries_readb(addr); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 531 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 532 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 533 | static void iseries_readsw(const volatile void __iomem *addr, void *buf, |
| 534 | unsigned long count) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 535 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 536 | u16 *dst = buf; |
| 537 | while(count-- > 0) |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 538 | *(dst++) = iseries_readw_be(addr); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 539 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 540 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 541 | static void iseries_readsl(const volatile void __iomem *addr, void *buf, |
| 542 | unsigned long count) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 543 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 544 | u32 *dst = buf; |
| 545 | while(count-- > 0) |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 546 | *(dst++) = iseries_readl_be(addr); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 547 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 548 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 549 | static void iseries_writesb(volatile void __iomem *addr, const void *buf, |
| 550 | unsigned long count) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 551 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 552 | const u8 *src = buf; |
| 553 | while(count-- > 0) |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 554 | iseries_writeb(*(src++), addr); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 555 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 556 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 557 | static void iseries_writesw(volatile void __iomem *addr, const void *buf, |
| 558 | unsigned long count) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 559 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 560 | const u16 *src = buf; |
| 561 | while(count-- > 0) |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 562 | iseries_writew_be(*(src++), addr); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 563 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 564 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 565 | static void iseries_writesl(volatile void __iomem *addr, const void *buf, |
| 566 | unsigned long count) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 567 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 568 | const u32 *src = buf; |
| 569 | while(count-- > 0) |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 570 | iseries_writel_be(*(src++), addr); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 571 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 572 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 573 | static void iseries_memset_io(volatile void __iomem *addr, int c, |
| 574 | unsigned long n) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 575 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 576 | volatile char __iomem *d = addr; |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 577 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 578 | while (n-- > 0) |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 579 | iseries_writeb(c, d++); |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | static void iseries_memcpy_fromio(void *dest, const volatile void __iomem *src, |
| 583 | unsigned long n) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 584 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 585 | char *d = dest; |
| 586 | const volatile char __iomem *s = src; |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 587 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 588 | while (n-- > 0) |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 589 | *d++ = iseries_readb(s++); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 590 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 591 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 592 | static void iseries_memcpy_toio(volatile void __iomem *dest, const void *src, |
| 593 | unsigned long n) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 594 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 595 | const char *s = src; |
| 596 | volatile char __iomem *d = dest; |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 597 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 598 | while (n-- > 0) |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 599 | iseries_writeb(*s++, d++); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 600 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 601 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 602 | /* We only set MMIO ops. The default PIO ops will be default |
| 603 | * to the MMIO ops + pci_io_base which is 0 on iSeries as |
| 604 | * expected so both should work. |
| 605 | * |
| 606 | * Note that we don't implement the readq/writeq versions as |
| 607 | * I don't know of an HV call for doing so. Thus, the default |
| 608 | * operation will be used instead, which will fault a the value |
| 609 | * return by iSeries for MMIO addresses always hits a non mapped |
| 610 | * area. This is as good as the BUG() we used to have there. |
| 611 | */ |
| 612 | static struct ppc_pci_io __initdata iseries_pci_io = { |
| 613 | .readb = iseries_readb, |
| 614 | .readw = iseries_readw, |
| 615 | .readl = iseries_readl, |
| 616 | .readw_be = iseries_readw_be, |
| 617 | .readl_be = iseries_readl_be, |
| 618 | .writeb = iseries_writeb, |
| 619 | .writew = iseries_writew, |
| 620 | .writel = iseries_writel, |
| 621 | .writew_be = iseries_writew_be, |
| 622 | .writel_be = iseries_writel_be, |
| 623 | .readsb = iseries_readsb, |
| 624 | .readsw = iseries_readsw, |
| 625 | .readsl = iseries_readsl, |
| 626 | .writesb = iseries_writesb, |
| 627 | .writesw = iseries_writesw, |
| 628 | .writesl = iseries_writesl, |
| 629 | .memset_io = iseries_memset_io, |
| 630 | .memcpy_fromio = iseries_memcpy_fromio, |
| 631 | .memcpy_toio = iseries_memcpy_toio, |
| 632 | }; |
| 633 | |
| 634 | /* |
| 635 | * iSeries_pcibios_init |
| 636 | * |
| 637 | * Description: |
| 638 | * This function checks for all possible system PCI host bridges that connect |
| 639 | * PCI buses. The system hypervisor is queried as to the guest partition |
| 640 | * ownership status. A pci_controller is built for any bus which is partially |
| 641 | * owned or fully owned by this guest partition. |
| 642 | */ |
| 643 | void __init iSeries_pcibios_init(void) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 644 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 645 | struct pci_controller *phb; |
| 646 | struct device_node *root = of_find_node_by_path("/"); |
| 647 | struct device_node *node = NULL; |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 648 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 649 | /* Install IO hooks */ |
| 650 | ppc_pci_io = iseries_pci_io; |
| 651 | |
Benjamin Herrenschmidt | 3d5134e | 2007-06-04 15:15:36 +1000 | [diff] [blame] | 652 | /* iSeries has no IO space in the common sense, it needs to set |
| 653 | * the IO base to 0 |
| 654 | */ |
| 655 | pci_io_base = 0; |
| 656 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 657 | if (root == NULL) { |
| 658 | printk(KERN_CRIT "iSeries_pcibios_init: can't find root " |
| 659 | "of device tree\n"); |
| 660 | return; |
| 661 | } |
| 662 | while ((node = of_get_next_child(root, node)) != NULL) { |
| 663 | HvBusNumber bus; |
| 664 | const u32 *busp; |
| 665 | |
| 666 | if ((node->type == NULL) || (strcmp(node->type, "pci") != 0)) |
| 667 | continue; |
| 668 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 669 | busp = of_get_property(node, "bus-range", NULL); |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 670 | if (busp == NULL) |
| 671 | continue; |
| 672 | bus = *busp; |
| 673 | printk("bus %d appears to exist\n", bus); |
| 674 | phb = pcibios_alloc_controller(node); |
| 675 | if (phb == NULL) |
| 676 | continue; |
| 677 | |
Kumar Gala | bf440b7 | 2007-06-27 00:19:08 -0500 | [diff] [blame] | 678 | phb->pci_mem_offset = bus; |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 679 | phb->first_busno = bus; |
| 680 | phb->last_busno = bus; |
| 681 | phb->ops = &iSeries_pci_ops; |
| 682 | } |
| 683 | |
| 684 | of_node_put(root); |
| 685 | |
| 686 | pci_devs_phb_init(); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 687 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 688 | |