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