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 | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 180 | node = find_device_node(pdev->bus->number, pdev->devfn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | printk("pci dev %p (%x.%x), node %p\n", pdev, |
| 182 | pdev->bus->number, pdev->devfn, node); |
| 183 | |
| 184 | if (node != NULL) { |
Stephen Rothwell | b025279 | 2006-05-19 16:50:39 +1000 | [diff] [blame] | 185 | struct pci_dn *pdn = PCI_DN(node); |
Jeremy Kerr | c4c7cba | 2006-07-12 15:39:42 +1000 | [diff] [blame] | 186 | const u32 *agent; |
Stephen Rothwell | b025279 | 2006-05-19 16:50:39 +1000 | [diff] [blame] | 187 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 188 | agent = of_get_property(node, "linux,agent-id", NULL); |
Stephen Rothwell | b025279 | 2006-05-19 16:50:39 +1000 | [diff] [blame] | 189 | if ((pdn != NULL) && (agent != NULL)) { |
| 190 | u8 irq = iSeries_allocate_IRQ(pdn->busno, 0, |
| 191 | pdn->bussubno); |
| 192 | int err; |
| 193 | |
| 194 | err = HvCallXm_connectBusUnit(pdn->busno, pdn->bussubno, |
| 195 | *agent, irq); |
| 196 | if (err) |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 197 | pci_log_error("Connect Bus Unit", |
Stephen Rothwell | b025279 | 2006-05-19 16:50:39 +1000 | [diff] [blame] | 198 | pdn->busno, pdn->bussubno, *agent, err); |
| 199 | else { |
| 200 | err = HvCallPci_configStore8(pdn->busno, pdn->bussubno, |
| 201 | *agent, |
| 202 | PCI_INTERRUPT_LINE, |
| 203 | irq); |
| 204 | if (err) |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 205 | pci_log_error("PciCfgStore Irq Failed!", |
Stephen Rothwell | b025279 | 2006-05-19 16:50:39 +1000 | [diff] [blame] | 206 | pdn->busno, pdn->bussubno, *agent, err); |
| 207 | } |
| 208 | if (!err) |
| 209 | pdev->irq = irq; |
| 210 | } |
| 211 | |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 212 | ++num_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | pdev->sysdata = (void *)node; |
Stephen Rothwell | 252e75a | 2005-09-28 14:40:40 +1000 | [diff] [blame] | 214 | PCI_DN(node)->pcidev = pdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | allocate_device_bars(pdev); |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 216 | iSeries_Device_Information(pdev, num_dev); |
Benjamin Herrenschmidt | 12d04ee | 2006-11-11 17:25:02 +1100 | [diff] [blame] | 217 | iommu_devnode_init_iSeries(pdev, node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | } else |
| 219 | printk("PCI: Device Tree not found for 0x%016lX\n", |
| 220 | (unsigned long)pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | } |
| 222 | iSeries_activate_IRQs(); |
| 223 | mf_display_src(0xC9000200); |
| 224 | } |
| 225 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | #if 0 |
| 227 | /* |
| 228 | * Returns the device node for the passed pci_dev |
| 229 | * Sanity Check Node PciDev to passed pci_dev |
| 230 | * If none is found, returns a NULL which the client must handle. |
| 231 | */ |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 232 | static struct device_node *get_device_node(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | { |
Stephen Rothwell | 252e75a | 2005-09-28 14:40:40 +1000 | [diff] [blame] | 234 | struct device_node *node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | |
| 236 | node = pdev->sysdata; |
Stephen Rothwell | 252e75a | 2005-09-28 14:40:40 +1000 | [diff] [blame] | 237 | if (node == NULL || PCI_DN(node)->pcidev != pdev) |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 238 | node = find_device_node(pdev->bus->number, pdev->devfn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | return node; |
| 240 | } |
| 241 | #endif |
| 242 | |
| 243 | /* |
| 244 | * Config space read and write functions. |
| 245 | * For now at least, we look for the device node for the bus and devfn |
| 246 | * that we are asked to access. It may be possible to translate the devfn |
| 247 | * to a subbus and deviceid more directly. |
| 248 | */ |
| 249 | static u64 hv_cfg_read_func[4] = { |
| 250 | HvCallPciConfigLoad8, HvCallPciConfigLoad16, |
| 251 | HvCallPciConfigLoad32, HvCallPciConfigLoad32 |
| 252 | }; |
| 253 | |
| 254 | static u64 hv_cfg_write_func[4] = { |
| 255 | HvCallPciConfigStore8, HvCallPciConfigStore16, |
| 256 | HvCallPciConfigStore32, HvCallPciConfigStore32 |
| 257 | }; |
| 258 | |
| 259 | /* |
| 260 | * Read PCI config space |
| 261 | */ |
| 262 | static int iSeries_pci_read_config(struct pci_bus *bus, unsigned int devfn, |
| 263 | int offset, int size, u32 *val) |
| 264 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 265 | struct device_node *node = find_device_node(bus->number, devfn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | u64 fn; |
| 267 | struct HvCallPci_LoadReturn ret; |
| 268 | |
| 269 | if (node == NULL) |
| 270 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 271 | if (offset > 255) { |
| 272 | *val = ~0; |
| 273 | return PCIBIOS_BAD_REGISTER_NUMBER; |
| 274 | } |
| 275 | |
| 276 | fn = hv_cfg_read_func[(size - 1) & 3]; |
Stephen Rothwell | 20f48cc | 2005-10-14 16:49:58 +1000 | [diff] [blame] | 277 | HvCall3Ret16(fn, &ret, iseries_ds_addr(node), offset, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
| 279 | if (ret.rc != 0) { |
| 280 | *val = ~0; |
| 281 | return PCIBIOS_DEVICE_NOT_FOUND; /* or something */ |
| 282 | } |
| 283 | |
| 284 | *val = ret.value; |
| 285 | return 0; |
| 286 | } |
| 287 | |
| 288 | /* |
| 289 | * Write PCI config space |
| 290 | */ |
| 291 | |
| 292 | static int iSeries_pci_write_config(struct pci_bus *bus, unsigned int devfn, |
| 293 | int offset, int size, u32 val) |
| 294 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 295 | struct device_node *node = find_device_node(bus->number, devfn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | u64 fn; |
| 297 | u64 ret; |
| 298 | |
| 299 | if (node == NULL) |
| 300 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 301 | if (offset > 255) |
| 302 | return PCIBIOS_BAD_REGISTER_NUMBER; |
| 303 | |
| 304 | fn = hv_cfg_write_func[(size - 1) & 3]; |
Stephen Rothwell | 20f48cc | 2005-10-14 16:49:58 +1000 | [diff] [blame] | 305 | ret = HvCall4(fn, iseries_ds_addr(node), offset, val, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
| 307 | if (ret != 0) |
| 308 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 309 | |
| 310 | return 0; |
| 311 | } |
| 312 | |
| 313 | static struct pci_ops iSeries_pci_ops = { |
| 314 | .read = iSeries_pci_read_config, |
| 315 | .write = iSeries_pci_write_config |
| 316 | }; |
| 317 | |
| 318 | /* |
| 319 | * Check Return Code |
| 320 | * -> On Failure, print and log information. |
| 321 | * Increment Retry Count, if exceeds max, panic partition. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | * |
| 323 | * PCI: Device 23.90 ReadL I/O Error( 0): 0x1234 |
| 324 | * PCI: Device 23.90 ReadL Retry( 1) |
| 325 | * PCI: Device 23.90 ReadL Retry Successful(1) |
| 326 | */ |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 327 | static int check_return_code(char *type, struct device_node *dn, |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 328 | int *retry, u64 ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | { |
| 330 | if (ret != 0) { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 331 | struct pci_dn *pdn = PCI_DN(dn); |
Stephen Rothwell | 252e75a | 2005-09-28 14:40:40 +1000 | [diff] [blame] | 332 | |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 333 | (*retry)++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | 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^] | 335 | type, pdn->busno, pdn->devfn, |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 336 | *retry, (int)ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | /* |
| 338 | * Bump the retry and check for retry count exceeded. |
| 339 | * If, Exceeded, panic the system. |
| 340 | */ |
Stephen Rothwell | b9b1812 | 2007-12-07 01:48:14 +1100 | [diff] [blame] | 341 | if (((*retry) > PCI_RETRY_MAX) && |
| 342 | (limit_pci_retries > 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | mf_display_src(0xB6000103); |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 344 | panic_timeout = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | panic("PCI: Hardware I/O Error, SRC B6000103, " |
| 346 | "Automatic Reboot Disabled.\n"); |
| 347 | } |
| 348 | return -1; /* Retry Try */ |
| 349 | } |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 350 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | /* |
| 354 | * Translate the I/O Address into a device node, bar, and bar offset. |
| 355 | * Note: Make sure the passed variable end up on the stack to avoid |
| 356 | * the exposure of being device global. |
| 357 | */ |
Stephen Rothwell | 252e75a | 2005-09-28 14:40:40 +1000 | [diff] [blame] | 358 | static inline struct device_node *xlate_iomm_address( |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 359 | const volatile void __iomem *addr, |
| 360 | u64 *dsaptr, u64 *bar_offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 362 | unsigned long orig_addr; |
| 363 | unsigned long base_addr; |
| 364 | unsigned long ind; |
| 365 | struct device_node *dn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 367 | orig_addr = (unsigned long __force)addr; |
| 368 | if ((orig_addr < BASE_IO_MEMORY) || (orig_addr >= max_io_memory)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | return NULL; |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 370 | base_addr = orig_addr - BASE_IO_MEMORY; |
| 371 | ind = base_addr / IOMM_TABLE_ENTRY_SIZE; |
| 372 | dn = iomm_table[ind]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 374 | if (dn != NULL) { |
| 375 | int barnum = iobar_table[ind]; |
| 376 | *dsaptr = iseries_ds_addr(dn) | (barnum << 24); |
| 377 | *bar_offset = base_addr % IOMM_TABLE_ENTRY_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | } else |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 379 | panic("PCI: Invalid PCI IO address detected!\n"); |
| 380 | return dn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | /* |
| 384 | * Read MM I/O Instructions for the iSeries |
| 385 | * 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] | 386 | * else, data is returned in Big Endian format. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | */ |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 388 | static u8 iSeries_read_byte(const volatile void __iomem *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 390 | u64 bar_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | u64 dsa; |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 392 | int retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | struct HvCallPci_LoadReturn ret; |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 394 | struct device_node *dn = |
| 395 | xlate_iomm_address(addr, &dsa, &bar_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 397 | if (dn == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | static unsigned long last_jiffies; |
| 399 | static int num_printed; |
| 400 | |
| 401 | if ((jiffies - last_jiffies) > 60 * HZ) { |
| 402 | last_jiffies = jiffies; |
| 403 | num_printed = 0; |
| 404 | } |
| 405 | if (num_printed++ < 10) |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 406 | printk(KERN_ERR "iSeries_read_byte: invalid access at IO address %p\n", |
| 407 | addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | return 0xff; |
| 409 | } |
| 410 | do { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 411 | HvCall3Ret16(HvCallPciBarLoad8, &ret, dsa, bar_offset, 0); |
| 412 | } while (check_return_code("RDB", dn, &retry, ret.rc) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 414 | return ret.value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | } |
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 | static u16 iSeries_read_word(const volatile void __iomem *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 419 | u64 bar_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | u64 dsa; |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 421 | int retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | struct HvCallPci_LoadReturn ret; |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 423 | struct device_node *dn = |
| 424 | xlate_iomm_address(addr, &dsa, &bar_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 426 | if (dn == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | static unsigned long last_jiffies; |
| 428 | static int num_printed; |
| 429 | |
| 430 | if ((jiffies - last_jiffies) > 60 * HZ) { |
| 431 | last_jiffies = jiffies; |
| 432 | num_printed = 0; |
| 433 | } |
| 434 | if (num_printed++ < 10) |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 435 | printk(KERN_ERR "iSeries_read_word: invalid access at IO address %p\n", |
| 436 | addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | return 0xffff; |
| 438 | } |
| 439 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | HvCall3Ret16(HvCallPciBarLoad16, &ret, dsa, |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 441 | bar_offset, 0); |
| 442 | } while (check_return_code("RDW", dn, &retry, ret.rc) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 444 | return ret.value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | } |
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 | static u32 iSeries_read_long(const volatile void __iomem *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 449 | u64 bar_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | u64 dsa; |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 451 | int retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | struct HvCallPci_LoadReturn ret; |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 453 | struct device_node *dn = |
| 454 | xlate_iomm_address(addr, &dsa, &bar_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 456 | if (dn == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | static unsigned long last_jiffies; |
| 458 | static int num_printed; |
| 459 | |
| 460 | if ((jiffies - last_jiffies) > 60 * HZ) { |
| 461 | last_jiffies = jiffies; |
| 462 | num_printed = 0; |
| 463 | } |
| 464 | if (num_printed++ < 10) |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 465 | printk(KERN_ERR "iSeries_read_long: invalid access at IO address %p\n", |
| 466 | addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | return 0xffffffff; |
| 468 | } |
| 469 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | HvCall3Ret16(HvCallPciBarLoad32, &ret, dsa, |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 471 | bar_offset, 0); |
| 472 | } while (check_return_code("RDL", dn, &retry, ret.rc) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 474 | return ret.value; |
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 | |
| 477 | /* |
| 478 | * Write MM I/O Instructions for the iSeries |
| 479 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | */ |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 481 | static void iSeries_write_byte(u8 data, volatile void __iomem *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 483 | u64 bar_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | u64 dsa; |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 485 | int retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | u64 rc; |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 487 | struct device_node *dn = |
| 488 | xlate_iomm_address(addr, &dsa, &bar_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 490 | if (dn == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | static unsigned long last_jiffies; |
| 492 | static int num_printed; |
| 493 | |
| 494 | if ((jiffies - last_jiffies) > 60 * HZ) { |
| 495 | last_jiffies = jiffies; |
| 496 | num_printed = 0; |
| 497 | } |
| 498 | if (num_printed++ < 10) |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 499 | printk(KERN_ERR "iSeries_write_byte: invalid access at IO address %p\n", addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | return; |
| 501 | } |
| 502 | do { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 503 | rc = HvCall4(HvCallPciBarStore8, dsa, bar_offset, data, 0); |
| 504 | } while (check_return_code("WWB", dn, &retry, rc) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 507 | static void iSeries_write_word(u16 data, volatile void __iomem *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 509 | u64 bar_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | u64 dsa; |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 511 | int retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | u64 rc; |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 513 | struct device_node *dn = |
| 514 | xlate_iomm_address(addr, &dsa, &bar_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 516 | if (dn == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | static unsigned long last_jiffies; |
| 518 | static int num_printed; |
| 519 | |
| 520 | if ((jiffies - last_jiffies) > 60 * HZ) { |
| 521 | last_jiffies = jiffies; |
| 522 | num_printed = 0; |
| 523 | } |
| 524 | if (num_printed++ < 10) |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 525 | printk(KERN_ERR "iSeries_write_word: invalid access at IO address %p\n", |
| 526 | addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | return; |
| 528 | } |
| 529 | do { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 530 | rc = HvCall4(HvCallPciBarStore16, dsa, bar_offset, data, 0); |
| 531 | } while (check_return_code("WWW", dn, &retry, rc) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 534 | static void iSeries_write_long(u32 data, volatile void __iomem *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 536 | u64 bar_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | u64 dsa; |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 538 | int retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | u64 rc; |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 540 | struct device_node *dn = |
| 541 | xlate_iomm_address(addr, &dsa, &bar_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 543 | if (dn == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | static unsigned long last_jiffies; |
| 545 | static int num_printed; |
| 546 | |
| 547 | if ((jiffies - last_jiffies) > 60 * HZ) { |
| 548 | last_jiffies = jiffies; |
| 549 | num_printed = 0; |
| 550 | } |
| 551 | if (num_printed++ < 10) |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 552 | printk(KERN_ERR "iSeries_write_long: invalid access at IO address %p\n", |
| 553 | addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | return; |
| 555 | } |
| 556 | do { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 557 | rc = HvCall4(HvCallPciBarStore32, dsa, bar_offset, data, 0); |
| 558 | } while (check_return_code("WWL", dn, &retry, rc) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 560 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 561 | static u8 iseries_readb(const volatile void __iomem *addr) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 562 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 563 | return iSeries_read_byte(addr); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 564 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 565 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 566 | static u16 iseries_readw(const volatile void __iomem *addr) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 567 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 568 | return le16_to_cpu(iSeries_read_word(addr)); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 569 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 570 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 571 | static u32 iseries_readl(const volatile void __iomem *addr) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 572 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 573 | return le32_to_cpu(iSeries_read_long(addr)); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 574 | } |
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 | static u16 iseries_readw_be(const volatile void __iomem *addr) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 577 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 578 | return iSeries_read_word(addr); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 579 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 580 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 581 | static u32 iseries_readl_be(const volatile void __iomem *addr) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 582 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 583 | return iSeries_read_long(addr); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 584 | } |
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 | static void iseries_writeb(u8 data, volatile void __iomem *addr) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 587 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 588 | iSeries_write_byte(data, 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_writew(u16 data, volatile void __iomem *addr) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 592 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 593 | iSeries_write_word(cpu_to_le16(data), addr); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 594 | } |
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 | static void iseries_writel(u32 data, volatile void __iomem *addr) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 597 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 598 | iSeries_write_long(cpu_to_le32(data), addr); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 599 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 600 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 601 | static void iseries_writew_be(u16 data, volatile void __iomem *addr) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 602 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 603 | iSeries_write_word(data, addr); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 604 | } |
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 | static void iseries_writel_be(u32 data, volatile void __iomem *addr) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 607 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 608 | iSeries_write_long(data, addr); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 609 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 610 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 611 | static void iseries_readsb(const volatile void __iomem *addr, void *buf, |
| 612 | unsigned long count) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 613 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 614 | u8 *dst = buf; |
| 615 | while(count-- > 0) |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 616 | *(dst++) = iSeries_read_byte(addr); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 617 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 618 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 619 | static void iseries_readsw(const volatile void __iomem *addr, void *buf, |
| 620 | unsigned long count) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 621 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 622 | u16 *dst = buf; |
| 623 | while(count-- > 0) |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 624 | *(dst++) = iSeries_read_word(addr); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 625 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 626 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 627 | static void iseries_readsl(const volatile void __iomem *addr, void *buf, |
| 628 | unsigned long count) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 629 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 630 | u32 *dst = buf; |
| 631 | while(count-- > 0) |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 632 | *(dst++) = iSeries_read_long(addr); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 633 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 634 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 635 | static void iseries_writesb(volatile void __iomem *addr, const void *buf, |
| 636 | unsigned long count) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 637 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 638 | const u8 *src = buf; |
| 639 | while(count-- > 0) |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 640 | iSeries_write_byte(*(src++), addr); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 641 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 642 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 643 | static void iseries_writesw(volatile void __iomem *addr, const void *buf, |
| 644 | unsigned long count) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 645 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 646 | const u16 *src = buf; |
| 647 | while(count-- > 0) |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 648 | iSeries_write_word(*(src++), addr); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 649 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 650 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 651 | static void iseries_writesl(volatile void __iomem *addr, const void *buf, |
| 652 | unsigned long count) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 653 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 654 | const u32 *src = buf; |
| 655 | while(count-- > 0) |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 656 | iSeries_write_long(*(src++), addr); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 657 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 658 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 659 | static void iseries_memset_io(volatile void __iomem *addr, int c, |
| 660 | unsigned long n) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 661 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 662 | volatile char __iomem *d = addr; |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 663 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 664 | while (n-- > 0) |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 665 | iSeries_write_byte(c, d++); |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | static void iseries_memcpy_fromio(void *dest, const volatile void __iomem *src, |
| 669 | unsigned long n) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 670 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 671 | char *d = dest; |
| 672 | const volatile char __iomem *s = src; |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 673 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 674 | while (n-- > 0) |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 675 | *d++ = iSeries_read_byte(s++); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 676 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 677 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 678 | static void iseries_memcpy_toio(volatile void __iomem *dest, const void *src, |
| 679 | unsigned long n) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 680 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 681 | const char *s = src; |
| 682 | volatile char __iomem *d = dest; |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 683 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 684 | while (n-- > 0) |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame^] | 685 | iSeries_write_byte(*s++, d++); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 686 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 687 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 688 | /* We only set MMIO ops. The default PIO ops will be default |
| 689 | * to the MMIO ops + pci_io_base which is 0 on iSeries as |
| 690 | * expected so both should work. |
| 691 | * |
| 692 | * Note that we don't implement the readq/writeq versions as |
| 693 | * I don't know of an HV call for doing so. Thus, the default |
| 694 | * operation will be used instead, which will fault a the value |
| 695 | * return by iSeries for MMIO addresses always hits a non mapped |
| 696 | * area. This is as good as the BUG() we used to have there. |
| 697 | */ |
| 698 | static struct ppc_pci_io __initdata iseries_pci_io = { |
| 699 | .readb = iseries_readb, |
| 700 | .readw = iseries_readw, |
| 701 | .readl = iseries_readl, |
| 702 | .readw_be = iseries_readw_be, |
| 703 | .readl_be = iseries_readl_be, |
| 704 | .writeb = iseries_writeb, |
| 705 | .writew = iseries_writew, |
| 706 | .writel = iseries_writel, |
| 707 | .writew_be = iseries_writew_be, |
| 708 | .writel_be = iseries_writel_be, |
| 709 | .readsb = iseries_readsb, |
| 710 | .readsw = iseries_readsw, |
| 711 | .readsl = iseries_readsl, |
| 712 | .writesb = iseries_writesb, |
| 713 | .writesw = iseries_writesw, |
| 714 | .writesl = iseries_writesl, |
| 715 | .memset_io = iseries_memset_io, |
| 716 | .memcpy_fromio = iseries_memcpy_fromio, |
| 717 | .memcpy_toio = iseries_memcpy_toio, |
| 718 | }; |
| 719 | |
| 720 | /* |
| 721 | * iSeries_pcibios_init |
| 722 | * |
| 723 | * Description: |
| 724 | * This function checks for all possible system PCI host bridges that connect |
| 725 | * PCI buses. The system hypervisor is queried as to the guest partition |
| 726 | * ownership status. A pci_controller is built for any bus which is partially |
| 727 | * owned or fully owned by this guest partition. |
| 728 | */ |
| 729 | void __init iSeries_pcibios_init(void) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 730 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 731 | struct pci_controller *phb; |
| 732 | struct device_node *root = of_find_node_by_path("/"); |
| 733 | struct device_node *node = NULL; |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 734 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 735 | /* Install IO hooks */ |
| 736 | ppc_pci_io = iseries_pci_io; |
| 737 | |
Benjamin Herrenschmidt | 3d5134e | 2007-06-04 15:15:36 +1000 | [diff] [blame] | 738 | /* iSeries has no IO space in the common sense, it needs to set |
| 739 | * the IO base to 0 |
| 740 | */ |
| 741 | pci_io_base = 0; |
| 742 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 743 | if (root == NULL) { |
| 744 | printk(KERN_CRIT "iSeries_pcibios_init: can't find root " |
| 745 | "of device tree\n"); |
| 746 | return; |
| 747 | } |
| 748 | while ((node = of_get_next_child(root, node)) != NULL) { |
| 749 | HvBusNumber bus; |
| 750 | const u32 *busp; |
| 751 | |
| 752 | if ((node->type == NULL) || (strcmp(node->type, "pci") != 0)) |
| 753 | continue; |
| 754 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 755 | busp = of_get_property(node, "bus-range", NULL); |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 756 | if (busp == NULL) |
| 757 | continue; |
| 758 | bus = *busp; |
| 759 | printk("bus %d appears to exist\n", bus); |
| 760 | phb = pcibios_alloc_controller(node); |
| 761 | if (phb == NULL) |
| 762 | continue; |
| 763 | |
Kumar Gala | bf440b7 | 2007-06-27 00:19:08 -0500 | [diff] [blame] | 764 | phb->pci_mem_offset = bus; |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 765 | phb->first_busno = bus; |
| 766 | phb->last_busno = bus; |
| 767 | phb->ops = &iSeries_pci_ops; |
| 768 | } |
| 769 | |
| 770 | of_node_put(root); |
| 771 | |
| 772 | pci_devs_phb_init(); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 773 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 774 | |