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 |
Stephen Rothwell | 1dee202 | 2007-12-07 16:10:22 +1100 | [diff] [blame] | 3 | * Copyright (C) 2005,2007 Stephen Rothwell, IBM Corp |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | * iSeries specific routines for PCI. |
Stephen Rothwell | d387899 | 2005-09-28 02:50:25 +1000 | [diff] [blame] | 6 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * Based on code from pci.c and iSeries_pci.c 32bit |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
Stephen Rothwell | d387899 | 2005-09-28 02:50:25 +1000 | [diff] [blame] | 13 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
Stephen Rothwell | d387899 | 2005-09-28 02:50:25 +1000 | [diff] [blame] | 18 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | */ |
Benjamin Herrenschmidt | 50c9bc2 | 2007-12-20 14:54:55 +1100 | [diff] [blame] | 23 | |
| 24 | #undef DEBUG |
| 25 | |
S.Çağlar Onur | 59861bc | 2008-03-17 20:36:26 +1100 | [diff] [blame] | 26 | #include <linux/jiffies.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/kernel.h> |
Stephen Rothwell | d387899 | 2005-09-28 02:50:25 +1000 | [diff] [blame] | 28 | #include <linux/list.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <linux/string.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 30 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/init.h> |
| 32 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/pci.h> |
Stephen Rothwell | 885b86e | 2007-12-21 15:50:09 +1100 | [diff] [blame] | 34 | #include <linux/of.h> |
Akinobu Mita | 8260cf6 | 2010-02-28 00:58:16 +0000 | [diff] [blame] | 35 | #include <linux/ratelimit.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Stephen Rothwell | 1dee202 | 2007-12-07 16:10:22 +1100 | [diff] [blame] | 37 | #include <asm/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <asm/io.h> |
| 39 | #include <asm/irq.h> |
| 40 | #include <asm/prom.h> |
| 41 | #include <asm/machdep.h> |
| 42 | #include <asm/pci-bridge.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <asm/iommu.h> |
Stephen Rothwell | 426c1a1 | 2005-10-14 14:51:42 +1000 | [diff] [blame] | 44 | #include <asm/abs_addr.h> |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 45 | #include <asm/firmware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Stephen Rothwell | 1dee202 | 2007-12-07 16:10:22 +1100 | [diff] [blame] | 47 | #include <asm/iseries/hv_types.h> |
Kelly Daly | 8021b8a | 2005-11-02 11:41:12 +1100 | [diff] [blame] | 48 | #include <asm/iseries/hv_call_xm.h> |
Kelly Daly | bbc8b62 | 2005-11-02 15:10:38 +1100 | [diff] [blame] | 49 | #include <asm/iseries/mf.h> |
Stephen Rothwell | c7f0e8c | 2006-04-27 17:23:32 +1000 | [diff] [blame] | 50 | #include <asm/iseries/iommu.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Stephen Rothwell | d387899 | 2005-09-28 02:50:25 +1000 | [diff] [blame] | 52 | #include <asm/ppc-pci.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Stephen Rothwell | b08567cb | 2005-09-28 23:37:01 +1000 | [diff] [blame] | 54 | #include "irq.h" |
Stephen Rothwell | 426c1a1 | 2005-10-14 14:51:42 +1000 | [diff] [blame] | 55 | #include "pci.h" |
Stephen Rothwell | c6d2ea9 | 2005-10-14 17:16:17 +1000 | [diff] [blame] | 56 | #include "call_pci.h" |
Stephen Rothwell | b08567cb | 2005-09-28 23:37:01 +1000 | [diff] [blame] | 57 | |
Stephen Rothwell | b9b1812 | 2007-12-07 01:48:14 +1100 | [diff] [blame] | 58 | #define PCI_RETRY_MAX 3 |
| 59 | static int limit_pci_retries = 1; /* Set Retry Error on. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | /* |
| 62 | * Table defines |
| 63 | * Each Entry size is 4 MB * 1024 Entries = 4GB I/O address space. |
| 64 | */ |
| 65 | #define IOMM_TABLE_MAX_ENTRIES 1024 |
| 66 | #define IOMM_TABLE_ENTRY_SIZE 0x0000000000400000UL |
| 67 | #define BASE_IO_MEMORY 0xE000000000000000UL |
Benjamin Herrenschmidt | 50c9bc2 | 2007-12-20 14:54:55 +1100 | [diff] [blame] | 68 | #define END_IO_MEMORY 0xEFFFFFFFFFFFFFFFUL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Stephen Rothwell | b58b7f9 | 2006-05-19 16:42:49 +1000 | [diff] [blame] | 70 | static unsigned long max_io_memory = BASE_IO_MEMORY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | static long current_iomm_table_entry; |
| 72 | |
| 73 | /* |
| 74 | * Lookup Tables. |
| 75 | */ |
Stephen Rothwell | b58b7f9 | 2006-05-19 16:42:49 +1000 | [diff] [blame] | 76 | static struct device_node *iomm_table[IOMM_TABLE_MAX_ENTRIES]; |
Stephen Rothwell | 885b86e | 2007-12-21 15:50:09 +1100 | [diff] [blame] | 77 | static u64 ds_addr_table[IOMM_TABLE_MAX_ENTRIES]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | static DEFINE_SPINLOCK(iomm_table_lock); |
| 80 | |
| 81 | /* |
Stephen Rothwell | 2cd1008 | 2007-12-07 01:55:50 +1100 | [diff] [blame] | 82 | * Generate a Direct Select Address for the Hypervisor |
| 83 | */ |
| 84 | static inline u64 iseries_ds_addr(struct device_node *node) |
| 85 | { |
| 86 | struct pci_dn *pdn = PCI_DN(node); |
Stephen Rothwell | 885b86e | 2007-12-21 15:50:09 +1100 | [diff] [blame] | 87 | const u32 *sbp = of_get_property(node, "linux,subbus", NULL); |
Stephen Rothwell | 2cd1008 | 2007-12-07 01:55:50 +1100 | [diff] [blame] | 88 | |
Stephen Rothwell | 885b86e | 2007-12-21 15:50:09 +1100 | [diff] [blame] | 89 | return ((u64)pdn->busno << 48) + ((u64)(sbp ? *sbp : 0) << 40) |
Stephen Rothwell | 2cd1008 | 2007-12-07 01:55:50 +1100 | [diff] [blame] | 90 | + ((u64)0x10 << 32); |
| 91 | } |
| 92 | |
| 93 | /* |
Stephen Rothwell | 1dee202 | 2007-12-07 16:10:22 +1100 | [diff] [blame] | 94 | * Size of Bus VPD data |
| 95 | */ |
| 96 | #define BUS_VPDSIZE 1024 |
| 97 | |
| 98 | /* |
| 99 | * Bus Vpd Tags |
| 100 | */ |
| 101 | #define VPD_END_OF_AREA 0x79 |
| 102 | #define VPD_ID_STRING 0x82 |
| 103 | #define VPD_VENDOR_AREA 0x84 |
| 104 | |
| 105 | /* |
| 106 | * Mfg Area Tags |
| 107 | */ |
| 108 | #define VPD_FRU_FRAME_ID 0x4649 /* "FI" */ |
| 109 | #define VPD_SLOT_MAP_FORMAT 0x4D46 /* "MF" */ |
| 110 | #define VPD_SLOT_MAP 0x534D /* "SM" */ |
| 111 | |
| 112 | /* |
| 113 | * Structures of the areas |
| 114 | */ |
| 115 | struct mfg_vpd_area { |
| 116 | u16 tag; |
| 117 | u8 length; |
| 118 | u8 data1; |
| 119 | u8 data2; |
| 120 | }; |
| 121 | #define MFG_ENTRY_SIZE 3 |
| 122 | |
| 123 | struct slot_map { |
| 124 | u8 agent; |
| 125 | u8 secondary_agent; |
| 126 | u8 phb; |
| 127 | char card_location[3]; |
| 128 | char parms[8]; |
| 129 | char reserved[2]; |
| 130 | }; |
| 131 | #define SLOT_ENTRY_SIZE 16 |
| 132 | |
| 133 | /* |
| 134 | * Parse the Slot Area |
| 135 | */ |
| 136 | static void __init iseries_parse_slot_area(struct slot_map *map, int len, |
| 137 | HvAgentId agent, u8 *phb, char card[4]) |
| 138 | { |
| 139 | /* |
| 140 | * Parse Slot label until we find the one requested |
| 141 | */ |
| 142 | while (len > 0) { |
| 143 | if (map->agent == agent) { |
| 144 | /* |
| 145 | * If Phb wasn't found, grab the entry first one found. |
| 146 | */ |
| 147 | if (*phb == 0xff) |
| 148 | *phb = map->phb; |
| 149 | /* Found it, extract the data. */ |
| 150 | if (map->phb == *phb) { |
| 151 | memcpy(card, &map->card_location, 3); |
| 152 | card[3] = 0; |
| 153 | break; |
| 154 | } |
| 155 | } |
| 156 | /* Point to the next Slot */ |
| 157 | map = (struct slot_map *)((char *)map + SLOT_ENTRY_SIZE); |
| 158 | len -= SLOT_ENTRY_SIZE; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | /* |
| 163 | * Parse the Mfg Area |
| 164 | */ |
| 165 | static void __init iseries_parse_mfg_area(struct mfg_vpd_area *area, int len, |
| 166 | HvAgentId agent, u8 *phb, u8 *frame, char card[4]) |
| 167 | { |
| 168 | u16 slot_map_fmt = 0; |
| 169 | |
| 170 | /* Parse Mfg Data */ |
| 171 | while (len > 0) { |
| 172 | int mfg_tag_len = area->length; |
| 173 | /* Frame ID (FI 4649020310 ) */ |
| 174 | if (area->tag == VPD_FRU_FRAME_ID) |
| 175 | *frame = area->data1; |
| 176 | /* Slot Map Format (MF 4D46020004 ) */ |
| 177 | else if (area->tag == VPD_SLOT_MAP_FORMAT) |
| 178 | slot_map_fmt = (area->data1 * 256) |
| 179 | + area->data2; |
| 180 | /* Slot Map (SM 534D90 */ |
| 181 | else if (area->tag == VPD_SLOT_MAP) { |
| 182 | struct slot_map *slot_map; |
| 183 | |
| 184 | if (slot_map_fmt == 0x1004) |
| 185 | slot_map = (struct slot_map *)((char *)area |
| 186 | + MFG_ENTRY_SIZE + 1); |
| 187 | else |
| 188 | slot_map = (struct slot_map *)((char *)area |
| 189 | + MFG_ENTRY_SIZE); |
| 190 | iseries_parse_slot_area(slot_map, mfg_tag_len, |
| 191 | agent, phb, card); |
| 192 | } |
| 193 | /* |
| 194 | * Point to the next Mfg Area |
| 195 | * Use defined size, sizeof give wrong answer |
| 196 | */ |
| 197 | area = (struct mfg_vpd_area *)((char *)area + mfg_tag_len |
| 198 | + MFG_ENTRY_SIZE); |
| 199 | len -= (mfg_tag_len + MFG_ENTRY_SIZE); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | /* |
| 204 | * Look for "BUS".. Data is not Null terminated. |
| 205 | * PHBID of 0xFF indicates PHB was not found in VPD Data. |
| 206 | */ |
| 207 | static u8 __init iseries_parse_phbid(u8 *area, int len) |
| 208 | { |
| 209 | while (len > 0) { |
| 210 | if ((*area == 'B') && (*(area + 1) == 'U') |
| 211 | && (*(area + 2) == 'S')) { |
| 212 | area += 3; |
| 213 | while (*area == ' ') |
| 214 | area++; |
| 215 | return *area & 0x0F; |
| 216 | } |
| 217 | area++; |
| 218 | len--; |
| 219 | } |
| 220 | return 0xff; |
| 221 | } |
| 222 | |
| 223 | /* |
| 224 | * Parse out the VPD Areas |
| 225 | */ |
| 226 | static void __init iseries_parse_vpd(u8 *data, int data_len, |
| 227 | HvAgentId agent, u8 *frame, char card[4]) |
| 228 | { |
| 229 | u8 phb = 0xff; |
| 230 | |
| 231 | while (data_len > 0) { |
| 232 | int len; |
| 233 | u8 tag = *data; |
| 234 | |
| 235 | if (tag == VPD_END_OF_AREA) |
| 236 | break; |
| 237 | len = *(data + 1) + (*(data + 2) * 256); |
| 238 | data += 3; |
| 239 | data_len -= 3; |
| 240 | if (tag == VPD_ID_STRING) |
| 241 | phb = iseries_parse_phbid(data, len); |
| 242 | else if (tag == VPD_VENDOR_AREA) |
| 243 | iseries_parse_mfg_area((struct mfg_vpd_area *)data, len, |
| 244 | agent, &phb, frame, card); |
| 245 | /* Point to next Area. */ |
| 246 | data += len; |
| 247 | data_len -= len; |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | static int __init iseries_get_location_code(u16 bus, HvAgentId agent, |
| 252 | u8 *frame, char card[4]) |
| 253 | { |
| 254 | int status = 0; |
| 255 | int bus_vpd_len = 0; |
| 256 | u8 *bus_vpd = kmalloc(BUS_VPDSIZE, GFP_KERNEL); |
| 257 | |
| 258 | if (bus_vpd == NULL) { |
| 259 | printk("PCI: Bus VPD Buffer allocation failure.\n"); |
| 260 | return 0; |
| 261 | } |
| 262 | bus_vpd_len = HvCallPci_getBusVpd(bus, iseries_hv_addr(bus_vpd), |
| 263 | BUS_VPDSIZE); |
| 264 | if (bus_vpd_len == 0) { |
| 265 | printk("PCI: Bus VPD Buffer zero length.\n"); |
| 266 | goto out_free; |
| 267 | } |
| 268 | /* printk("PCI: bus_vpd: %p, %d\n",bus_vpd, bus_vpd_len); */ |
| 269 | /* Make sure this is what I think it is */ |
| 270 | if (*bus_vpd != VPD_ID_STRING) { |
| 271 | printk("PCI: Bus VPD Buffer missing starting tag.\n"); |
| 272 | goto out_free; |
| 273 | } |
| 274 | iseries_parse_vpd(bus_vpd, bus_vpd_len, agent, frame, card); |
| 275 | status = 1; |
| 276 | out_free: |
| 277 | kfree(bus_vpd); |
| 278 | return status; |
| 279 | } |
| 280 | |
| 281 | /* |
| 282 | * Prints the device information. |
| 283 | * - Pass in pci_dev* pointer to the device. |
| 284 | * - Pass in the device count |
| 285 | * |
| 286 | * Format: |
| 287 | * PCI: Bus 0, Device 26, Vendor 0x12AE Frame 1, Card C10 Ethernet |
| 288 | * controller |
| 289 | */ |
Benjamin Herrenschmidt | 50c9bc2 | 2007-12-20 14:54:55 +1100 | [diff] [blame] | 290 | static void __init iseries_device_information(struct pci_dev *pdev, |
| 291 | u16 bus, HvSubBusNumber subbus) |
Stephen Rothwell | 1dee202 | 2007-12-07 16:10:22 +1100 | [diff] [blame] | 292 | { |
| 293 | u8 frame = 0; |
| 294 | char card[4]; |
| 295 | HvAgentId agent; |
| 296 | |
| 297 | agent = ISERIES_PCI_AGENTID(ISERIES_GET_DEVICE_FROM_SUBBUS(subbus), |
| 298 | ISERIES_GET_FUNCTION_FROM_SUBBUS(subbus)); |
| 299 | |
| 300 | if (iseries_get_location_code(bus, agent, &frame, card)) { |
Benjamin Herrenschmidt | 50c9bc2 | 2007-12-20 14:54:55 +1100 | [diff] [blame] | 301 | printk(KERN_INFO "PCI: %s, Vendor %04X Frame%3d, " |
| 302 | "Card %4s 0x%04X\n", pci_name(pdev), pdev->vendor, |
| 303 | frame, card, (int)(pdev->class >> 8)); |
Stephen Rothwell | 1dee202 | 2007-12-07 16:10:22 +1100 | [diff] [blame] | 304 | } |
| 305 | } |
| 306 | |
| 307 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | * iomm_table_allocate_entry |
| 309 | * |
| 310 | * Adds pci_dev entry in address translation table |
| 311 | * |
| 312 | * - Allocates the number of entries required in table base on BAR |
| 313 | * size. |
| 314 | * - Allocates starting at BASE_IO_MEMORY and increases. |
| 315 | * - The size is round up to be a multiple of entry size. |
| 316 | * - CurrentIndex is incremented to keep track of the last entry. |
| 317 | * - Builds the resource entry for allocated BARs. |
| 318 | */ |
Stephen Rothwell | 1e10590 | 2007-11-19 17:03:59 +1100 | [diff] [blame] | 319 | 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] | 320 | { |
| 321 | struct resource *bar_res = &dev->resource[bar_num]; |
| 322 | long bar_size = pci_resource_len(dev, bar_num); |
Kumar Gala | d7b41b1 | 2009-05-18 02:56:27 +0000 | [diff] [blame] | 323 | struct device_node *dn = pci_device_to_OF_node(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
| 325 | /* |
| 326 | * No space to allocate, quick exit, skip Allocation. |
| 327 | */ |
| 328 | if (bar_size == 0) |
| 329 | return; |
| 330 | /* |
| 331 | * Set Resource values. |
| 332 | */ |
| 333 | spin_lock(&iomm_table_lock); |
Stephen Rothwell | b58b7f9 | 2006-05-19 16:42:49 +1000 | [diff] [blame] | 334 | bar_res->start = BASE_IO_MEMORY + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | IOMM_TABLE_ENTRY_SIZE * current_iomm_table_entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | bar_res->end = bar_res->start + bar_size - 1; |
| 337 | /* |
| 338 | * Allocate the number of table entries needed for BAR. |
| 339 | */ |
| 340 | while (bar_size > 0 ) { |
Kumar Gala | d7b41b1 | 2009-05-18 02:56:27 +0000 | [diff] [blame] | 341 | iomm_table[current_iomm_table_entry] = dn; |
Stephen Rothwell | 885b86e | 2007-12-21 15:50:09 +1100 | [diff] [blame] | 342 | ds_addr_table[current_iomm_table_entry] = |
Kumar Gala | d7b41b1 | 2009-05-18 02:56:27 +0000 | [diff] [blame] | 343 | iseries_ds_addr(dn) | (bar_num << 24); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | bar_size -= IOMM_TABLE_ENTRY_SIZE; |
| 345 | ++current_iomm_table_entry; |
| 346 | } |
| 347 | max_io_memory = BASE_IO_MEMORY + |
Stephen Rothwell | b58b7f9 | 2006-05-19 16:42:49 +1000 | [diff] [blame] | 348 | IOMM_TABLE_ENTRY_SIZE * current_iomm_table_entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | spin_unlock(&iomm_table_lock); |
| 350 | } |
| 351 | |
| 352 | /* |
| 353 | * allocate_device_bars |
| 354 | * |
| 355 | * - Allocates ALL pci_dev BAR's and updates the resources with the |
| 356 | * BAR value. BARS with zero length will have the resources |
| 357 | * The HvCallPci_getBarParms is used to get the size of the BAR |
| 358 | * space. It calls iomm_table_allocate_entry to allocate |
| 359 | * each entry. |
| 360 | * - Loops through The Bar resources(0 - 5) including the ROM |
| 361 | * is resource(6). |
| 362 | */ |
Stephen Rothwell | 1e10590 | 2007-11-19 17:03:59 +1100 | [diff] [blame] | 363 | static void __init allocate_device_bars(struct pci_dev *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | int bar_num; |
| 366 | |
Stephen Rothwell | b58b7f9 | 2006-05-19 16:42:49 +1000 | [diff] [blame] | 367 | for (bar_num = 0; bar_num <= PCI_ROM_RESOURCE; ++bar_num) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | iomm_table_allocate_entry(dev, bar_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | /* |
| 372 | * Log error information to system console. |
| 373 | * Filter out the device not there errors. |
| 374 | * PCI: EADs Connect Failed 0x18.58.10 Rc: 0x00xx |
| 375 | * PCI: Read Vendor Failed 0x18.58.10 Rc: 0x00xx |
| 376 | * PCI: Connect Bus Unit Failed 0x18.58.10 Rc: 0x00xx |
| 377 | */ |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 378 | static void pci_log_error(char *error, int bus, int subbus, |
| 379 | int agent, int hv_res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 381 | if (hv_res == 0x0302) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | return; |
| 383 | 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] | 384 | error, bus, subbus, agent, hv_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | /* |
Stephen Rothwell | 9103eb7 | 2007-12-07 01:46:40 +1100 | [diff] [blame] | 388 | * Look down the chain to find the matching Device Device |
| 389 | */ |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 390 | static struct device_node *find_device_node(int bus, int devfn) |
Stephen Rothwell | 9103eb7 | 2007-12-07 01:46:40 +1100 | [diff] [blame] | 391 | { |
| 392 | struct device_node *node; |
| 393 | |
| 394 | for (node = NULL; (node = of_find_all_nodes(node)); ) { |
| 395 | struct pci_dn *pdn = PCI_DN(node); |
| 396 | |
| 397 | if (pdn && (bus == pdn->busno) && (devfn == pdn->devfn)) |
| 398 | return node; |
| 399 | } |
| 400 | return NULL; |
| 401 | } |
| 402 | |
| 403 | /* |
Benjamin Herrenschmidt | 50c9bc2 | 2007-12-20 14:54:55 +1100 | [diff] [blame] | 404 | * iSeries_pcibios_fixup_resources |
| 405 | * |
| 406 | * Fixes up all resources for devices |
| 407 | */ |
| 408 | void __init iSeries_pcibios_fixup_resources(struct pci_dev *pdev) |
| 409 | { |
| 410 | const u32 *agent; |
| 411 | const u32 *sub_bus; |
| 412 | unsigned char bus = pdev->bus->number; |
| 413 | struct device_node *node; |
| 414 | int i; |
| 415 | |
Kumar Gala | d7b41b1 | 2009-05-18 02:56:27 +0000 | [diff] [blame] | 416 | node = pci_device_to_OF_node(pdev); |
Benjamin Herrenschmidt | 50c9bc2 | 2007-12-20 14:54:55 +1100 | [diff] [blame] | 417 | pr_debug("PCI: iSeries %s, pdev %p, node %p\n", |
| 418 | pci_name(pdev), pdev, node); |
| 419 | if (!node) { |
| 420 | printk("PCI: %s disabled, device tree entry not found !\n", |
| 421 | pci_name(pdev)); |
| 422 | for (i = 0; i <= PCI_ROM_RESOURCE; i++) |
| 423 | pdev->resource[i].flags = 0; |
| 424 | return; |
| 425 | } |
| 426 | sub_bus = of_get_property(node, "linux,subbus", NULL); |
| 427 | agent = of_get_property(node, "linux,agent-id", NULL); |
| 428 | if (agent && sub_bus) { |
| 429 | u8 irq = iSeries_allocate_IRQ(bus, 0, *sub_bus); |
| 430 | int err; |
| 431 | |
| 432 | err = HvCallXm_connectBusUnit(bus, *sub_bus, *agent, irq); |
| 433 | if (err) |
| 434 | pci_log_error("Connect Bus Unit", |
| 435 | bus, *sub_bus, *agent, err); |
| 436 | else { |
| 437 | err = HvCallPci_configStore8(bus, *sub_bus, |
| 438 | *agent, PCI_INTERRUPT_LINE, irq); |
| 439 | if (err) |
| 440 | pci_log_error("PciCfgStore Irq Failed!", |
| 441 | bus, *sub_bus, *agent, err); |
| 442 | else |
| 443 | pdev->irq = irq; |
| 444 | } |
| 445 | } |
| 446 | |
Benjamin Herrenschmidt | 50c9bc2 | 2007-12-20 14:54:55 +1100 | [diff] [blame] | 447 | allocate_device_bars(pdev); |
Denis Kirjanov | d3005fb | 2010-06-16 05:16:59 +0000 | [diff] [blame] | 448 | if (likely(sub_bus)) |
| 449 | iseries_device_information(pdev, bus, *sub_bus); |
| 450 | else |
| 451 | printk(KERN_ERR "PCI: Device node %s has missing or invalid " |
| 452 | "linux,subbus property\n", node->full_name); |
Benjamin Herrenschmidt | 50c9bc2 | 2007-12-20 14:54:55 +1100 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | /* |
Stephen Rothwell | d387899 | 2005-09-28 02:50:25 +1000 | [diff] [blame] | 456 | * iSeries_pci_final_fixup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | */ |
| 458 | void __init iSeries_pci_final_fixup(void) |
| 459 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | /* Fix up at the device node and pci_dev relationship */ |
| 461 | mf_display_src(0xC9000100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | iSeries_activate_IRQs(); |
| 463 | mf_display_src(0xC9000200); |
| 464 | } |
| 465 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | /* |
| 467 | * Config space read and write functions. |
| 468 | * For now at least, we look for the device node for the bus and devfn |
| 469 | * that we are asked to access. It may be possible to translate the devfn |
| 470 | * to a subbus and deviceid more directly. |
| 471 | */ |
| 472 | static u64 hv_cfg_read_func[4] = { |
| 473 | HvCallPciConfigLoad8, HvCallPciConfigLoad16, |
| 474 | HvCallPciConfigLoad32, HvCallPciConfigLoad32 |
| 475 | }; |
| 476 | |
| 477 | static u64 hv_cfg_write_func[4] = { |
| 478 | HvCallPciConfigStore8, HvCallPciConfigStore16, |
| 479 | HvCallPciConfigStore32, HvCallPciConfigStore32 |
| 480 | }; |
| 481 | |
| 482 | /* |
| 483 | * Read PCI config space |
| 484 | */ |
| 485 | static int iSeries_pci_read_config(struct pci_bus *bus, unsigned int devfn, |
| 486 | int offset, int size, u32 *val) |
| 487 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 488 | struct device_node *node = find_device_node(bus->number, devfn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | u64 fn; |
| 490 | struct HvCallPci_LoadReturn ret; |
| 491 | |
| 492 | if (node == NULL) |
| 493 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 494 | if (offset > 255) { |
| 495 | *val = ~0; |
| 496 | return PCIBIOS_BAD_REGISTER_NUMBER; |
| 497 | } |
| 498 | |
| 499 | fn = hv_cfg_read_func[(size - 1) & 3]; |
Stephen Rothwell | 20f48cc | 2005-10-14 16:49:58 +1000 | [diff] [blame] | 500 | HvCall3Ret16(fn, &ret, iseries_ds_addr(node), offset, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | |
| 502 | if (ret.rc != 0) { |
| 503 | *val = ~0; |
| 504 | return PCIBIOS_DEVICE_NOT_FOUND; /* or something */ |
| 505 | } |
| 506 | |
| 507 | *val = ret.value; |
| 508 | return 0; |
| 509 | } |
| 510 | |
| 511 | /* |
| 512 | * Write PCI config space |
| 513 | */ |
| 514 | |
| 515 | static int iSeries_pci_write_config(struct pci_bus *bus, unsigned int devfn, |
| 516 | int offset, int size, u32 val) |
| 517 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 518 | struct device_node *node = find_device_node(bus->number, devfn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | u64 fn; |
| 520 | u64 ret; |
| 521 | |
| 522 | if (node == NULL) |
| 523 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 524 | if (offset > 255) |
| 525 | return PCIBIOS_BAD_REGISTER_NUMBER; |
| 526 | |
| 527 | fn = hv_cfg_write_func[(size - 1) & 3]; |
Stephen Rothwell | 20f48cc | 2005-10-14 16:49:58 +1000 | [diff] [blame] | 528 | ret = HvCall4(fn, iseries_ds_addr(node), offset, val, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | |
| 530 | if (ret != 0) |
| 531 | return PCIBIOS_DEVICE_NOT_FOUND; |
| 532 | |
| 533 | return 0; |
| 534 | } |
| 535 | |
| 536 | static struct pci_ops iSeries_pci_ops = { |
| 537 | .read = iSeries_pci_read_config, |
| 538 | .write = iSeries_pci_write_config |
| 539 | }; |
| 540 | |
| 541 | /* |
| 542 | * Check Return Code |
| 543 | * -> On Failure, print and log information. |
| 544 | * Increment Retry Count, if exceeds max, panic partition. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | * |
| 546 | * PCI: Device 23.90 ReadL I/O Error( 0): 0x1234 |
| 547 | * PCI: Device 23.90 ReadL Retry( 1) |
| 548 | * PCI: Device 23.90 ReadL Retry Successful(1) |
| 549 | */ |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 550 | static int check_return_code(char *type, struct device_node *dn, |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 551 | int *retry, u64 ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | { |
| 553 | if (ret != 0) { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 554 | struct pci_dn *pdn = PCI_DN(dn); |
Stephen Rothwell | 252e75a | 2005-09-28 14:40:40 +1000 | [diff] [blame] | 555 | |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 556 | (*retry)++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | 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] | 558 | type, pdn->busno, pdn->devfn, |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 559 | *retry, (int)ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | /* |
| 561 | * Bump the retry and check for retry count exceeded. |
| 562 | * If, Exceeded, panic the system. |
| 563 | */ |
Stephen Rothwell | b9b1812 | 2007-12-07 01:48:14 +1100 | [diff] [blame] | 564 | if (((*retry) > PCI_RETRY_MAX) && |
| 565 | (limit_pci_retries > 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | mf_display_src(0xB6000103); |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 567 | panic_timeout = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | panic("PCI: Hardware I/O Error, SRC B6000103, " |
| 569 | "Automatic Reboot Disabled.\n"); |
| 570 | } |
| 571 | return -1; /* Retry Try */ |
| 572 | } |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 573 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | /* |
| 577 | * Translate the I/O Address into a device node, bar, and bar offset. |
| 578 | * Note: Make sure the passed variable end up on the stack to avoid |
| 579 | * the exposure of being device global. |
| 580 | */ |
Stephen Rothwell | 252e75a | 2005-09-28 14:40:40 +1000 | [diff] [blame] | 581 | static inline struct device_node *xlate_iomm_address( |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 582 | const volatile void __iomem *addr, |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 583 | u64 *dsaptr, u64 *bar_offset, const char *func) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 585 | unsigned long orig_addr; |
| 586 | unsigned long base_addr; |
| 587 | unsigned long ind; |
| 588 | struct device_node *dn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 590 | orig_addr = (unsigned long __force)addr; |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 591 | if ((orig_addr < BASE_IO_MEMORY) || (orig_addr >= max_io_memory)) { |
Akinobu Mita | 8260cf6 | 2010-02-28 00:58:16 +0000 | [diff] [blame] | 592 | static DEFINE_RATELIMIT_STATE(ratelimit, 60 * HZ, 10); |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 593 | |
Akinobu Mita | 8260cf6 | 2010-02-28 00:58:16 +0000 | [diff] [blame] | 594 | if (__ratelimit(&ratelimit)) |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 595 | printk(KERN_ERR |
| 596 | "iSeries_%s: invalid access at IO address %p\n", |
| 597 | func, addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | return NULL; |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 599 | } |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 600 | base_addr = orig_addr - BASE_IO_MEMORY; |
| 601 | ind = base_addr / IOMM_TABLE_ENTRY_SIZE; |
| 602 | dn = iomm_table[ind]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 604 | if (dn != NULL) { |
Stephen Rothwell | 885b86e | 2007-12-21 15:50:09 +1100 | [diff] [blame] | 605 | *dsaptr = ds_addr_table[ind]; |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 606 | *bar_offset = base_addr % IOMM_TABLE_ENTRY_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | } else |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 608 | panic("PCI: Invalid PCI IO address detected!\n"); |
| 609 | return dn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | /* |
| 613 | * Read MM I/O Instructions for the iSeries |
| 614 | * 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] | 615 | * else, data is returned in Big Endian format. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | */ |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 617 | static u8 iseries_readb(const volatile void __iomem *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 619 | u64 bar_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | u64 dsa; |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 621 | int retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | struct HvCallPci_LoadReturn ret; |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 623 | struct device_node *dn = |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 624 | xlate_iomm_address(addr, &dsa, &bar_offset, "read_byte"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 626 | if (dn == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | return 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | do { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 629 | HvCall3Ret16(HvCallPciBarLoad8, &ret, dsa, bar_offset, 0); |
| 630 | } while (check_return_code("RDB", dn, &retry, ret.rc) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 632 | return ret.value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 635 | static u16 iseries_readw_be(const volatile void __iomem *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 637 | u64 bar_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | u64 dsa; |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 639 | int retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | struct HvCallPci_LoadReturn ret; |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 641 | struct device_node *dn = |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 642 | xlate_iomm_address(addr, &dsa, &bar_offset, "read_word"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 644 | if (dn == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | return 0xffff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | HvCall3Ret16(HvCallPciBarLoad16, &ret, dsa, |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 648 | bar_offset, 0); |
| 649 | } while (check_return_code("RDW", dn, &retry, ret.rc) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 651 | return ret.value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 654 | static u32 iseries_readl_be(const volatile void __iomem *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 656 | u64 bar_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | u64 dsa; |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 658 | int retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | struct HvCallPci_LoadReturn ret; |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 660 | struct device_node *dn = |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 661 | xlate_iomm_address(addr, &dsa, &bar_offset, "read_long"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 663 | if (dn == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | return 0xffffffff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | HvCall3Ret16(HvCallPciBarLoad32, &ret, dsa, |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 667 | bar_offset, 0); |
| 668 | } while (check_return_code("RDL", dn, &retry, ret.rc) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 670 | return ret.value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | |
| 673 | /* |
| 674 | * Write MM I/O Instructions for the iSeries |
| 675 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | */ |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 677 | static void iseries_writeb(u8 data, volatile void __iomem *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 679 | u64 bar_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | u64 dsa; |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 681 | int retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | u64 rc; |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 683 | struct device_node *dn = |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 684 | xlate_iomm_address(addr, &dsa, &bar_offset, "write_byte"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 686 | if (dn == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | do { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 689 | rc = HvCall4(HvCallPciBarStore8, dsa, bar_offset, data, 0); |
| 690 | } while (check_return_code("WWB", dn, &retry, rc) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 693 | static void iseries_writew_be(u16 data, volatile void __iomem *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 695 | u64 bar_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | u64 dsa; |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 697 | int retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | u64 rc; |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 699 | struct device_node *dn = |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 700 | xlate_iomm_address(addr, &dsa, &bar_offset, "write_word"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 702 | if (dn == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | do { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 705 | rc = HvCall4(HvCallPciBarStore16, dsa, bar_offset, data, 0); |
| 706 | } while (check_return_code("WWW", dn, &retry, rc) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 709 | static void iseries_writel_be(u32 data, volatile void __iomem *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 711 | u64 bar_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | u64 dsa; |
Stephen Rothwell | a2ebaf2 | 2005-06-21 17:15:47 -0700 | [diff] [blame] | 713 | int retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | u64 rc; |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 715 | struct device_node *dn = |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 716 | xlate_iomm_address(addr, &dsa, &bar_offset, "write_long"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | |
Stephen Rothwell | 0d416f2 | 2007-12-07 01:52:45 +1100 | [diff] [blame] | 718 | if (dn == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | do { |
Stephen Rothwell | 7a73bd7 | 2007-12-07 01:49:27 +1100 | [diff] [blame] | 721 | rc = HvCall4(HvCallPciBarStore32, dsa, bar_offset, data, 0); |
| 722 | } while (check_return_code("WWL", dn, &retry, rc) != 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 724 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 725 | static u16 iseries_readw(const volatile void __iomem *addr) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 726 | { |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 727 | return le16_to_cpu(iseries_readw_be(addr)); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 728 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 729 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 730 | static u32 iseries_readl(const volatile void __iomem *addr) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 731 | { |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 732 | return le32_to_cpu(iseries_readl_be(addr)); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 733 | } |
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 | static void iseries_writew(u16 data, volatile void __iomem *addr) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 736 | { |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 737 | iseries_writew_be(cpu_to_le16(data), addr); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 738 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 739 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 740 | static void iseries_writel(u32 data, volatile void __iomem *addr) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 741 | { |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 742 | iseries_writel(cpu_to_le32(data), addr); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 743 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 744 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 745 | static void iseries_readsb(const volatile void __iomem *addr, void *buf, |
| 746 | unsigned long count) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 747 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 748 | u8 *dst = buf; |
| 749 | while(count-- > 0) |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 750 | *(dst++) = iseries_readb(addr); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 751 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 752 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 753 | static void iseries_readsw(const volatile void __iomem *addr, void *buf, |
| 754 | unsigned long count) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 755 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 756 | u16 *dst = buf; |
| 757 | while(count-- > 0) |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 758 | *(dst++) = iseries_readw_be(addr); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 759 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 760 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 761 | static void iseries_readsl(const volatile void __iomem *addr, void *buf, |
| 762 | unsigned long count) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 763 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 764 | u32 *dst = buf; |
| 765 | while(count-- > 0) |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 766 | *(dst++) = iseries_readl_be(addr); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 767 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 768 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 769 | static void iseries_writesb(volatile void __iomem *addr, const void *buf, |
| 770 | unsigned long count) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 771 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 772 | const u8 *src = buf; |
| 773 | while(count-- > 0) |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 774 | iseries_writeb(*(src++), addr); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 775 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 776 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 777 | static void iseries_writesw(volatile void __iomem *addr, const void *buf, |
| 778 | unsigned long count) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 779 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 780 | const u16 *src = buf; |
| 781 | while(count-- > 0) |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 782 | iseries_writew_be(*(src++), addr); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 783 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 784 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 785 | static void iseries_writesl(volatile void __iomem *addr, const void *buf, |
| 786 | unsigned long count) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 787 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 788 | const u32 *src = buf; |
| 789 | while(count-- > 0) |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 790 | iseries_writel_be(*(src++), addr); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 791 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 792 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 793 | static void iseries_memset_io(volatile void __iomem *addr, int c, |
| 794 | unsigned long n) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 795 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 796 | volatile char __iomem *d = addr; |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 797 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 798 | while (n-- > 0) |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 799 | iseries_writeb(c, d++); |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | static void iseries_memcpy_fromio(void *dest, const volatile void __iomem *src, |
| 803 | unsigned long n) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 804 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 805 | char *d = dest; |
| 806 | const volatile char __iomem *s = src; |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 807 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 808 | while (n-- > 0) |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 809 | *d++ = iseries_readb(s++); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 810 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 811 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 812 | static void iseries_memcpy_toio(volatile void __iomem *dest, const void *src, |
| 813 | unsigned long n) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 814 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 815 | const char *s = src; |
| 816 | volatile char __iomem *d = dest; |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 817 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 818 | while (n-- > 0) |
Stephen Rothwell | 3448938 | 2007-12-07 01:53:44 +1100 | [diff] [blame] | 819 | iseries_writeb(*s++, d++); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 820 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 821 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 822 | /* We only set MMIO ops. The default PIO ops will be default |
| 823 | * to the MMIO ops + pci_io_base which is 0 on iSeries as |
| 824 | * expected so both should work. |
| 825 | * |
| 826 | * Note that we don't implement the readq/writeq versions as |
| 827 | * I don't know of an HV call for doing so. Thus, the default |
| 828 | * operation will be used instead, which will fault a the value |
| 829 | * return by iSeries for MMIO addresses always hits a non mapped |
| 830 | * area. This is as good as the BUG() we used to have there. |
| 831 | */ |
| 832 | static struct ppc_pci_io __initdata iseries_pci_io = { |
| 833 | .readb = iseries_readb, |
| 834 | .readw = iseries_readw, |
| 835 | .readl = iseries_readl, |
| 836 | .readw_be = iseries_readw_be, |
| 837 | .readl_be = iseries_readl_be, |
| 838 | .writeb = iseries_writeb, |
| 839 | .writew = iseries_writew, |
| 840 | .writel = iseries_writel, |
| 841 | .writew_be = iseries_writew_be, |
| 842 | .writel_be = iseries_writel_be, |
| 843 | .readsb = iseries_readsb, |
| 844 | .readsw = iseries_readsw, |
| 845 | .readsl = iseries_readsl, |
| 846 | .writesb = iseries_writesb, |
| 847 | .writesw = iseries_writesw, |
| 848 | .writesl = iseries_writesl, |
| 849 | .memset_io = iseries_memset_io, |
| 850 | .memcpy_fromio = iseries_memcpy_fromio, |
| 851 | .memcpy_toio = iseries_memcpy_toio, |
| 852 | }; |
| 853 | |
| 854 | /* |
| 855 | * iSeries_pcibios_init |
| 856 | * |
| 857 | * Description: |
| 858 | * This function checks for all possible system PCI host bridges that connect |
| 859 | * PCI buses. The system hypervisor is queried as to the guest partition |
| 860 | * ownership status. A pci_controller is built for any bus which is partially |
| 861 | * owned or fully owned by this guest partition. |
| 862 | */ |
| 863 | void __init iSeries_pcibios_init(void) |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 864 | { |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 865 | struct pci_controller *phb; |
| 866 | struct device_node *root = of_find_node_by_path("/"); |
| 867 | struct device_node *node = NULL; |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 868 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 869 | /* Install IO hooks */ |
| 870 | ppc_pci_io = iseries_pci_io; |
| 871 | |
Stephen Rothwell | 9ccc4fd | 2007-12-07 02:03:23 +1100 | [diff] [blame] | 872 | pci_probe_only = 1; |
| 873 | |
Benjamin Herrenschmidt | 3d5134e | 2007-06-04 15:15:36 +1000 | [diff] [blame] | 874 | /* iSeries has no IO space in the common sense, it needs to set |
| 875 | * the IO base to 0 |
| 876 | */ |
| 877 | pci_io_base = 0; |
| 878 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 879 | if (root == NULL) { |
| 880 | printk(KERN_CRIT "iSeries_pcibios_init: can't find root " |
| 881 | "of device tree\n"); |
| 882 | return; |
| 883 | } |
| 884 | while ((node = of_get_next_child(root, node)) != NULL) { |
| 885 | HvBusNumber bus; |
| 886 | const u32 *busp; |
| 887 | |
| 888 | if ((node->type == NULL) || (strcmp(node->type, "pci") != 0)) |
| 889 | continue; |
| 890 | |
Stephen Rothwell | e2eb639 | 2007-04-03 22:26:41 +1000 | [diff] [blame] | 891 | busp = of_get_property(node, "bus-range", NULL); |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 892 | if (busp == NULL) |
| 893 | continue; |
| 894 | bus = *busp; |
| 895 | printk("bus %d appears to exist\n", bus); |
| 896 | phb = pcibios_alloc_controller(node); |
| 897 | if (phb == NULL) |
| 898 | continue; |
Stephen Rothwell | 6207e81 | 2007-12-07 02:04:33 +1100 | [diff] [blame] | 899 | /* All legacy iSeries PHBs are in domain zero */ |
| 900 | phb->global_number = 0; |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 901 | |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 902 | phb->first_busno = bus; |
| 903 | phb->last_busno = bus; |
| 904 | phb->ops = &iSeries_pci_ops; |
Benjamin Herrenschmidt | 50c9bc2 | 2007-12-20 14:54:55 +1100 | [diff] [blame] | 905 | phb->io_base_virt = (void __iomem *)_IO_BASE; |
| 906 | phb->io_resource.flags = IORESOURCE_IO; |
| 907 | phb->io_resource.start = BASE_IO_MEMORY; |
| 908 | phb->io_resource.end = END_IO_MEMORY; |
| 909 | phb->io_resource.name = "iSeries PCI IO"; |
| 910 | phb->mem_resources[0].flags = IORESOURCE_MEM; |
| 911 | phb->mem_resources[0].start = BASE_IO_MEMORY; |
| 912 | phb->mem_resources[0].end = END_IO_MEMORY; |
| 913 | phb->mem_resources[0].name = "Series PCI MEM"; |
Benjamin Herrenschmidt | 4cb3cee | 2006-11-11 17:25:10 +1100 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | of_node_put(root); |
| 917 | |
| 918 | pci_devs_phb_init(); |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 919 | } |
Stephen Rothwell | caf8132 | 2006-09-21 18:00:00 +1000 | [diff] [blame] | 920 | |