blob: 30e3d992dc0d9a1988d44c27bcedc54f0d651008 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Copyright (C) 2001 Allan Trautman, IBM Corporation
Stephen Rothwell1dee2022007-12-07 16:10:22 +11003 * Copyright (C) 2005,2007 Stephen Rothwell, IBM Corp
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 * iSeries specific routines for PCI.
Stephen Rothwelld3878992005-09-28 02:50:25 +10006 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * 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 Rothwelld3878992005-09-28 02:50:25 +100013 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 * 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 Rothwelld3878992005-09-28 02:50:25 +100018 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 * 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 Herrenschmidt50c9bc22007-12-20 14:54:55 +110023
24#undef DEBUG
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/kernel.h>
Stephen Rothwelld3878992005-09-28 02:50:25 +100027#include <linux/list.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/string.h>
29#include <linux/init.h>
30#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <linux/pci.h>
32
Stephen Rothwell1dee2022007-12-07 16:10:22 +110033#include <asm/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <asm/io.h>
35#include <asm/irq.h>
36#include <asm/prom.h>
37#include <asm/machdep.h>
38#include <asm/pci-bridge.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <asm/iommu.h>
Stephen Rothwell426c1a12005-10-14 14:51:42 +100040#include <asm/abs_addr.h>
Stephen Rothwellcaf81322006-09-21 18:00:00 +100041#include <asm/firmware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Stephen Rothwell1dee2022007-12-07 16:10:22 +110043#include <asm/iseries/hv_types.h>
Kelly Daly8021b8a2005-11-02 11:41:12 +110044#include <asm/iseries/hv_call_xm.h>
Kelly Dalybbc8b622005-11-02 15:10:38 +110045#include <asm/iseries/mf.h>
Stephen Rothwellc7f0e8c2006-04-27 17:23:32 +100046#include <asm/iseries/iommu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Stephen Rothwelld3878992005-09-28 02:50:25 +100048#include <asm/ppc-pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Stephen Rothwellb08567cb2005-09-28 23:37:01 +100050#include "irq.h"
Stephen Rothwell426c1a12005-10-14 14:51:42 +100051#include "pci.h"
Stephen Rothwellc6d2ea92005-10-14 17:16:17 +100052#include "call_pci.h"
Stephen Rothwellb08567cb2005-09-28 23:37:01 +100053
Stephen Rothwellb9b18122007-12-07 01:48:14 +110054#define PCI_RETRY_MAX 3
55static int limit_pci_retries = 1; /* Set Retry Error on. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Linus Torvalds1da177e2005-04-16 15:20:36 -070057/*
58 * Table defines
59 * Each Entry size is 4 MB * 1024 Entries = 4GB I/O address space.
60 */
61#define IOMM_TABLE_MAX_ENTRIES 1024
62#define IOMM_TABLE_ENTRY_SIZE 0x0000000000400000UL
63#define BASE_IO_MEMORY 0xE000000000000000UL
Benjamin Herrenschmidt50c9bc22007-12-20 14:54:55 +110064#define END_IO_MEMORY 0xEFFFFFFFFFFFFFFFUL
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Stephen Rothwellb58b7f92006-05-19 16:42:49 +100066static unsigned long max_io_memory = BASE_IO_MEMORY;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067static long current_iomm_table_entry;
68
69/*
70 * Lookup Tables.
71 */
Stephen Rothwellb58b7f92006-05-19 16:42:49 +100072static struct device_node *iomm_table[IOMM_TABLE_MAX_ENTRIES];
73static u8 iobar_table[IOMM_TABLE_MAX_ENTRIES];
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
Linus Torvalds1da177e2005-04-16 15:20:36 -070075static DEFINE_SPINLOCK(iomm_table_lock);
76
77/*
Stephen Rothwell2cd10082007-12-07 01:55:50 +110078 * Generate a Direct Select Address for the Hypervisor
79 */
80static inline u64 iseries_ds_addr(struct device_node *node)
81{
82 struct pci_dn *pdn = PCI_DN(node);
83
84 return ((u64)pdn->busno << 48) + ((u64)pdn->bussubno << 40)
85 + ((u64)0x10 << 32);
86}
87
88/*
Stephen Rothwell1dee2022007-12-07 16:10:22 +110089 * Size of Bus VPD data
90 */
91#define BUS_VPDSIZE 1024
92
93/*
94 * Bus Vpd Tags
95 */
96#define VPD_END_OF_AREA 0x79
97#define VPD_ID_STRING 0x82
98#define VPD_VENDOR_AREA 0x84
99
100/*
101 * Mfg Area Tags
102 */
103#define VPD_FRU_FRAME_ID 0x4649 /* "FI" */
104#define VPD_SLOT_MAP_FORMAT 0x4D46 /* "MF" */
105#define VPD_SLOT_MAP 0x534D /* "SM" */
106
107/*
108 * Structures of the areas
109 */
110struct mfg_vpd_area {
111 u16 tag;
112 u8 length;
113 u8 data1;
114 u8 data2;
115};
116#define MFG_ENTRY_SIZE 3
117
118struct slot_map {
119 u8 agent;
120 u8 secondary_agent;
121 u8 phb;
122 char card_location[3];
123 char parms[8];
124 char reserved[2];
125};
126#define SLOT_ENTRY_SIZE 16
127
128/*
129 * Parse the Slot Area
130 */
131static void __init iseries_parse_slot_area(struct slot_map *map, int len,
132 HvAgentId agent, u8 *phb, char card[4])
133{
134 /*
135 * Parse Slot label until we find the one requested
136 */
137 while (len > 0) {
138 if (map->agent == agent) {
139 /*
140 * If Phb wasn't found, grab the entry first one found.
141 */
142 if (*phb == 0xff)
143 *phb = map->phb;
144 /* Found it, extract the data. */
145 if (map->phb == *phb) {
146 memcpy(card, &map->card_location, 3);
147 card[3] = 0;
148 break;
149 }
150 }
151 /* Point to the next Slot */
152 map = (struct slot_map *)((char *)map + SLOT_ENTRY_SIZE);
153 len -= SLOT_ENTRY_SIZE;
154 }
155}
156
157/*
158 * Parse the Mfg Area
159 */
160static void __init iseries_parse_mfg_area(struct mfg_vpd_area *area, int len,
161 HvAgentId agent, u8 *phb, u8 *frame, char card[4])
162{
163 u16 slot_map_fmt = 0;
164
165 /* Parse Mfg Data */
166 while (len > 0) {
167 int mfg_tag_len = area->length;
168 /* Frame ID (FI 4649020310 ) */
169 if (area->tag == VPD_FRU_FRAME_ID)
170 *frame = area->data1;
171 /* Slot Map Format (MF 4D46020004 ) */
172 else if (area->tag == VPD_SLOT_MAP_FORMAT)
173 slot_map_fmt = (area->data1 * 256)
174 + area->data2;
175 /* Slot Map (SM 534D90 */
176 else if (area->tag == VPD_SLOT_MAP) {
177 struct slot_map *slot_map;
178
179 if (slot_map_fmt == 0x1004)
180 slot_map = (struct slot_map *)((char *)area
181 + MFG_ENTRY_SIZE + 1);
182 else
183 slot_map = (struct slot_map *)((char *)area
184 + MFG_ENTRY_SIZE);
185 iseries_parse_slot_area(slot_map, mfg_tag_len,
186 agent, phb, card);
187 }
188 /*
189 * Point to the next Mfg Area
190 * Use defined size, sizeof give wrong answer
191 */
192 area = (struct mfg_vpd_area *)((char *)area + mfg_tag_len
193 + MFG_ENTRY_SIZE);
194 len -= (mfg_tag_len + MFG_ENTRY_SIZE);
195 }
196}
197
198/*
199 * Look for "BUS".. Data is not Null terminated.
200 * PHBID of 0xFF indicates PHB was not found in VPD Data.
201 */
202static u8 __init iseries_parse_phbid(u8 *area, int len)
203{
204 while (len > 0) {
205 if ((*area == 'B') && (*(area + 1) == 'U')
206 && (*(area + 2) == 'S')) {
207 area += 3;
208 while (*area == ' ')
209 area++;
210 return *area & 0x0F;
211 }
212 area++;
213 len--;
214 }
215 return 0xff;
216}
217
218/*
219 * Parse out the VPD Areas
220 */
221static void __init iseries_parse_vpd(u8 *data, int data_len,
222 HvAgentId agent, u8 *frame, char card[4])
223{
224 u8 phb = 0xff;
225
226 while (data_len > 0) {
227 int len;
228 u8 tag = *data;
229
230 if (tag == VPD_END_OF_AREA)
231 break;
232 len = *(data + 1) + (*(data + 2) * 256);
233 data += 3;
234 data_len -= 3;
235 if (tag == VPD_ID_STRING)
236 phb = iseries_parse_phbid(data, len);
237 else if (tag == VPD_VENDOR_AREA)
238 iseries_parse_mfg_area((struct mfg_vpd_area *)data, len,
239 agent, &phb, frame, card);
240 /* Point to next Area. */
241 data += len;
242 data_len -= len;
243 }
244}
245
246static int __init iseries_get_location_code(u16 bus, HvAgentId agent,
247 u8 *frame, char card[4])
248{
249 int status = 0;
250 int bus_vpd_len = 0;
251 u8 *bus_vpd = kmalloc(BUS_VPDSIZE, GFP_KERNEL);
252
253 if (bus_vpd == NULL) {
254 printk("PCI: Bus VPD Buffer allocation failure.\n");
255 return 0;
256 }
257 bus_vpd_len = HvCallPci_getBusVpd(bus, iseries_hv_addr(bus_vpd),
258 BUS_VPDSIZE);
259 if (bus_vpd_len == 0) {
260 printk("PCI: Bus VPD Buffer zero length.\n");
261 goto out_free;
262 }
263 /* printk("PCI: bus_vpd: %p, %d\n",bus_vpd, bus_vpd_len); */
264 /* Make sure this is what I think it is */
265 if (*bus_vpd != VPD_ID_STRING) {
266 printk("PCI: Bus VPD Buffer missing starting tag.\n");
267 goto out_free;
268 }
269 iseries_parse_vpd(bus_vpd, bus_vpd_len, agent, frame, card);
270 status = 1;
271out_free:
272 kfree(bus_vpd);
273 return status;
274}
275
276/*
277 * Prints the device information.
278 * - Pass in pci_dev* pointer to the device.
279 * - Pass in the device count
280 *
281 * Format:
282 * PCI: Bus 0, Device 26, Vendor 0x12AE Frame 1, Card C10 Ethernet
283 * controller
284 */
Benjamin Herrenschmidt50c9bc22007-12-20 14:54:55 +1100285static void __init iseries_device_information(struct pci_dev *pdev,
286 u16 bus, HvSubBusNumber subbus)
Stephen Rothwell1dee2022007-12-07 16:10:22 +1100287{
288 u8 frame = 0;
289 char card[4];
290 HvAgentId agent;
291
292 agent = ISERIES_PCI_AGENTID(ISERIES_GET_DEVICE_FROM_SUBBUS(subbus),
293 ISERIES_GET_FUNCTION_FROM_SUBBUS(subbus));
294
295 if (iseries_get_location_code(bus, agent, &frame, card)) {
Benjamin Herrenschmidt50c9bc22007-12-20 14:54:55 +1100296 printk(KERN_INFO "PCI: %s, Vendor %04X Frame%3d, "
297 "Card %4s 0x%04X\n", pci_name(pdev), pdev->vendor,
298 frame, card, (int)(pdev->class >> 8));
Stephen Rothwell1dee2022007-12-07 16:10:22 +1100299 }
300}
301
302/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 * iomm_table_allocate_entry
304 *
305 * Adds pci_dev entry in address translation table
306 *
307 * - Allocates the number of entries required in table base on BAR
308 * size.
309 * - Allocates starting at BASE_IO_MEMORY and increases.
310 * - The size is round up to be a multiple of entry size.
311 * - CurrentIndex is incremented to keep track of the last entry.
312 * - Builds the resource entry for allocated BARs.
313 */
Stephen Rothwell1e105902007-11-19 17:03:59 +1100314static void __init iomm_table_allocate_entry(struct pci_dev *dev, int bar_num)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315{
316 struct resource *bar_res = &dev->resource[bar_num];
317 long bar_size = pci_resource_len(dev, bar_num);
318
319 /*
320 * No space to allocate, quick exit, skip Allocation.
321 */
322 if (bar_size == 0)
323 return;
324 /*
325 * Set Resource values.
326 */
327 spin_lock(&iomm_table_lock);
Stephen Rothwellb58b7f92006-05-19 16:42:49 +1000328 bar_res->start = BASE_IO_MEMORY +
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 IOMM_TABLE_ENTRY_SIZE * current_iomm_table_entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 bar_res->end = bar_res->start + bar_size - 1;
331 /*
332 * Allocate the number of table entries needed for BAR.
333 */
334 while (bar_size > 0 ) {
335 iomm_table[current_iomm_table_entry] = dev->sysdata;
336 iobar_table[current_iomm_table_entry] = bar_num;
337 bar_size -= IOMM_TABLE_ENTRY_SIZE;
338 ++current_iomm_table_entry;
339 }
340 max_io_memory = BASE_IO_MEMORY +
Stephen Rothwellb58b7f92006-05-19 16:42:49 +1000341 IOMM_TABLE_ENTRY_SIZE * current_iomm_table_entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 spin_unlock(&iomm_table_lock);
343}
344
345/*
346 * allocate_device_bars
347 *
348 * - Allocates ALL pci_dev BAR's and updates the resources with the
349 * BAR value. BARS with zero length will have the resources
350 * The HvCallPci_getBarParms is used to get the size of the BAR
351 * space. It calls iomm_table_allocate_entry to allocate
352 * each entry.
353 * - Loops through The Bar resources(0 - 5) including the ROM
354 * is resource(6).
355 */
Stephen Rothwell1e105902007-11-19 17:03:59 +1100356static void __init allocate_device_bars(struct pci_dev *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 int bar_num;
359
Stephen Rothwellb58b7f92006-05-19 16:42:49 +1000360 for (bar_num = 0; bar_num <= PCI_ROM_RESOURCE; ++bar_num)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 iomm_table_allocate_entry(dev, bar_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362}
363
364/*
365 * Log error information to system console.
366 * Filter out the device not there errors.
367 * PCI: EADs Connect Failed 0x18.58.10 Rc: 0x00xx
368 * PCI: Read Vendor Failed 0x18.58.10 Rc: 0x00xx
369 * PCI: Connect Bus Unit Failed 0x18.58.10 Rc: 0x00xx
370 */
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100371static void pci_log_error(char *error, int bus, int subbus,
372 int agent, int hv_res)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373{
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100374 if (hv_res == 0x0302)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 return;
376 printk(KERN_ERR "PCI: %s Failed: 0x%02X.%02X.%02X Rc: 0x%04X",
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100377 error, bus, subbus, agent, hv_res);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378}
379
380/*
Stephen Rothwell9103eb72007-12-07 01:46:40 +1100381 * Look down the chain to find the matching Device Device
382 */
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100383static struct device_node *find_device_node(int bus, int devfn)
Stephen Rothwell9103eb72007-12-07 01:46:40 +1100384{
385 struct device_node *node;
386
387 for (node = NULL; (node = of_find_all_nodes(node)); ) {
388 struct pci_dn *pdn = PCI_DN(node);
389
390 if (pdn && (bus == pdn->busno) && (devfn == pdn->devfn))
391 return node;
392 }
393 return NULL;
394}
395
396/*
Benjamin Herrenschmidt50c9bc22007-12-20 14:54:55 +1100397 * iSeries_pcibios_fixup_resources
398 *
399 * Fixes up all resources for devices
400 */
401void __init iSeries_pcibios_fixup_resources(struct pci_dev *pdev)
402{
403 const u32 *agent;
404 const u32 *sub_bus;
405 unsigned char bus = pdev->bus->number;
406 struct device_node *node;
407 int i;
408
409 node = find_device_node(bus, pdev->devfn);
410 pr_debug("PCI: iSeries %s, pdev %p, node %p\n",
411 pci_name(pdev), pdev, node);
412 if (!node) {
413 printk("PCI: %s disabled, device tree entry not found !\n",
414 pci_name(pdev));
415 for (i = 0; i <= PCI_ROM_RESOURCE; i++)
416 pdev->resource[i].flags = 0;
417 return;
418 }
419 sub_bus = of_get_property(node, "linux,subbus", NULL);
420 agent = of_get_property(node, "linux,agent-id", NULL);
421 if (agent && sub_bus) {
422 u8 irq = iSeries_allocate_IRQ(bus, 0, *sub_bus);
423 int err;
424
425 err = HvCallXm_connectBusUnit(bus, *sub_bus, *agent, irq);
426 if (err)
427 pci_log_error("Connect Bus Unit",
428 bus, *sub_bus, *agent, err);
429 else {
430 err = HvCallPci_configStore8(bus, *sub_bus,
431 *agent, PCI_INTERRUPT_LINE, irq);
432 if (err)
433 pci_log_error("PciCfgStore Irq Failed!",
434 bus, *sub_bus, *agent, err);
435 else
436 pdev->irq = irq;
437 }
438 }
439
440 pdev->sysdata = node;
441 PCI_DN(node)->pcidev = pdev;
442 allocate_device_bars(pdev);
443 iseries_device_information(pdev, bus, *sub_bus);
444 iommu_devnode_init_iSeries(pdev, node);
445}
446
447/*
Stephen Rothwelld3878992005-09-28 02:50:25 +1000448 * iSeries_pci_final_fixup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 */
450void __init iSeries_pci_final_fixup(void)
451{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 /* Fix up at the device node and pci_dev relationship */
453 mf_display_src(0xC9000100);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 iSeries_activate_IRQs();
455 mf_display_src(0xC9000200);
456}
457
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458/*
459 * Config space read and write functions.
460 * For now at least, we look for the device node for the bus and devfn
461 * that we are asked to access. It may be possible to translate the devfn
462 * to a subbus and deviceid more directly.
463 */
464static u64 hv_cfg_read_func[4] = {
465 HvCallPciConfigLoad8, HvCallPciConfigLoad16,
466 HvCallPciConfigLoad32, HvCallPciConfigLoad32
467};
468
469static u64 hv_cfg_write_func[4] = {
470 HvCallPciConfigStore8, HvCallPciConfigStore16,
471 HvCallPciConfigStore32, HvCallPciConfigStore32
472};
473
474/*
475 * Read PCI config space
476 */
477static int iSeries_pci_read_config(struct pci_bus *bus, unsigned int devfn,
478 int offset, int size, u32 *val)
479{
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100480 struct device_node *node = find_device_node(bus->number, devfn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 u64 fn;
482 struct HvCallPci_LoadReturn ret;
483
484 if (node == NULL)
485 return PCIBIOS_DEVICE_NOT_FOUND;
486 if (offset > 255) {
487 *val = ~0;
488 return PCIBIOS_BAD_REGISTER_NUMBER;
489 }
490
491 fn = hv_cfg_read_func[(size - 1) & 3];
Stephen Rothwell20f48cc2005-10-14 16:49:58 +1000492 HvCall3Ret16(fn, &ret, iseries_ds_addr(node), offset, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
494 if (ret.rc != 0) {
495 *val = ~0;
496 return PCIBIOS_DEVICE_NOT_FOUND; /* or something */
497 }
498
499 *val = ret.value;
500 return 0;
501}
502
503/*
504 * Write PCI config space
505 */
506
507static int iSeries_pci_write_config(struct pci_bus *bus, unsigned int devfn,
508 int offset, int size, u32 val)
509{
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100510 struct device_node *node = find_device_node(bus->number, devfn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 u64 fn;
512 u64 ret;
513
514 if (node == NULL)
515 return PCIBIOS_DEVICE_NOT_FOUND;
516 if (offset > 255)
517 return PCIBIOS_BAD_REGISTER_NUMBER;
518
519 fn = hv_cfg_write_func[(size - 1) & 3];
Stephen Rothwell20f48cc2005-10-14 16:49:58 +1000520 ret = HvCall4(fn, iseries_ds_addr(node), offset, val, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
522 if (ret != 0)
523 return PCIBIOS_DEVICE_NOT_FOUND;
524
525 return 0;
526}
527
528static struct pci_ops iSeries_pci_ops = {
529 .read = iSeries_pci_read_config,
530 .write = iSeries_pci_write_config
531};
532
533/*
534 * Check Return Code
535 * -> On Failure, print and log information.
536 * Increment Retry Count, if exceeds max, panic partition.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 *
538 * PCI: Device 23.90 ReadL I/O Error( 0): 0x1234
539 * PCI: Device 23.90 ReadL Retry( 1)
540 * PCI: Device 23.90 ReadL Retry Successful(1)
541 */
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100542static int check_return_code(char *type, struct device_node *dn,
Stephen Rothwella2ebaf22005-06-21 17:15:47 -0700543 int *retry, u64 ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544{
545 if (ret != 0) {
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100546 struct pci_dn *pdn = PCI_DN(dn);
Stephen Rothwell252e75a2005-09-28 14:40:40 +1000547
Stephen Rothwella2ebaf22005-06-21 17:15:47 -0700548 (*retry)++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 printk("PCI: %s: Device 0x%04X:%02X I/O Error(%2d): 0x%04X\n",
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100550 type, pdn->busno, pdn->devfn,
Stephen Rothwella2ebaf22005-06-21 17:15:47 -0700551 *retry, (int)ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 /*
553 * Bump the retry and check for retry count exceeded.
554 * If, Exceeded, panic the system.
555 */
Stephen Rothwellb9b18122007-12-07 01:48:14 +1100556 if (((*retry) > PCI_RETRY_MAX) &&
557 (limit_pci_retries > 0)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 mf_display_src(0xB6000103);
Stephen Rothwella2ebaf22005-06-21 17:15:47 -0700559 panic_timeout = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 panic("PCI: Hardware I/O Error, SRC B6000103, "
561 "Automatic Reboot Disabled.\n");
562 }
563 return -1; /* Retry Try */
564 }
Stephen Rothwella2ebaf22005-06-21 17:15:47 -0700565 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566}
567
568/*
569 * Translate the I/O Address into a device node, bar, and bar offset.
570 * Note: Make sure the passed variable end up on the stack to avoid
571 * the exposure of being device global.
572 */
Stephen Rothwell252e75a2005-09-28 14:40:40 +1000573static inline struct device_node *xlate_iomm_address(
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100574 const volatile void __iomem *addr,
Stephen Rothwell0d416f22007-12-07 01:52:45 +1100575 u64 *dsaptr, u64 *bar_offset, const char *func)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576{
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100577 unsigned long orig_addr;
578 unsigned long base_addr;
579 unsigned long ind;
580 struct device_node *dn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100582 orig_addr = (unsigned long __force)addr;
Stephen Rothwell0d416f22007-12-07 01:52:45 +1100583 if ((orig_addr < BASE_IO_MEMORY) || (orig_addr >= max_io_memory)) {
584 static unsigned long last_jiffies;
585 static int num_printed;
586
587 if ((jiffies - last_jiffies) > 60 * HZ) {
588 last_jiffies = jiffies;
589 num_printed = 0;
590 }
591 if (num_printed++ < 10)
592 printk(KERN_ERR
593 "iSeries_%s: invalid access at IO address %p\n",
594 func, addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 return NULL;
Stephen Rothwell0d416f22007-12-07 01:52:45 +1100596 }
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100597 base_addr = orig_addr - BASE_IO_MEMORY;
598 ind = base_addr / IOMM_TABLE_ENTRY_SIZE;
599 dn = iomm_table[ind];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100601 if (dn != NULL) {
602 int barnum = iobar_table[ind];
603 *dsaptr = iseries_ds_addr(dn) | (barnum << 24);
604 *bar_offset = base_addr % IOMM_TABLE_ENTRY_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 } else
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100606 panic("PCI: Invalid PCI IO address detected!\n");
607 return dn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608}
609
610/*
611 * Read MM I/O Instructions for the iSeries
612 * On MM I/O error, all ones are returned and iSeries_pci_IoError is cal
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100613 * else, data is returned in Big Endian format.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 */
Stephen Rothwell34489382007-12-07 01:53:44 +1100615static u8 iseries_readb(const volatile void __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616{
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100617 u64 bar_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 u64 dsa;
Stephen Rothwella2ebaf22005-06-21 17:15:47 -0700619 int retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 struct HvCallPci_LoadReturn ret;
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100621 struct device_node *dn =
Stephen Rothwell0d416f22007-12-07 01:52:45 +1100622 xlate_iomm_address(addr, &dsa, &bar_offset, "read_byte");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
Stephen Rothwell0d416f22007-12-07 01:52:45 +1100624 if (dn == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 return 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 do {
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100627 HvCall3Ret16(HvCallPciBarLoad8, &ret, dsa, bar_offset, 0);
628 } while (check_return_code("RDB", dn, &retry, ret.rc) != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100630 return ret.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
Stephen Rothwell34489382007-12-07 01:53:44 +1100633static u16 iseries_readw_be(const volatile void __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634{
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100635 u64 bar_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 u64 dsa;
Stephen Rothwella2ebaf22005-06-21 17:15:47 -0700637 int retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 struct HvCallPci_LoadReturn ret;
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100639 struct device_node *dn =
Stephen Rothwell0d416f22007-12-07 01:52:45 +1100640 xlate_iomm_address(addr, &dsa, &bar_offset, "read_word");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
Stephen Rothwell0d416f22007-12-07 01:52:45 +1100642 if (dn == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 return 0xffff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 do {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 HvCall3Ret16(HvCallPciBarLoad16, &ret, dsa,
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100646 bar_offset, 0);
647 } while (check_return_code("RDW", dn, &retry, ret.rc) != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100649 return ret.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
Stephen Rothwell34489382007-12-07 01:53:44 +1100652static u32 iseries_readl_be(const volatile void __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653{
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100654 u64 bar_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 u64 dsa;
Stephen Rothwella2ebaf22005-06-21 17:15:47 -0700656 int retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 struct HvCallPci_LoadReturn ret;
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100658 struct device_node *dn =
Stephen Rothwell0d416f22007-12-07 01:52:45 +1100659 xlate_iomm_address(addr, &dsa, &bar_offset, "read_long");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660
Stephen Rothwell0d416f22007-12-07 01:52:45 +1100661 if (dn == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 return 0xffffffff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 do {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 HvCall3Ret16(HvCallPciBarLoad32, &ret, dsa,
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100665 bar_offset, 0);
666 } while (check_return_code("RDL", dn, &retry, ret.rc) != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100668 return ret.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
671/*
672 * Write MM I/O Instructions for the iSeries
673 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 */
Stephen Rothwell34489382007-12-07 01:53:44 +1100675static void iseries_writeb(u8 data, volatile void __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676{
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100677 u64 bar_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 u64 dsa;
Stephen Rothwella2ebaf22005-06-21 17:15:47 -0700679 int retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 u64 rc;
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100681 struct device_node *dn =
Stephen Rothwell0d416f22007-12-07 01:52:45 +1100682 xlate_iomm_address(addr, &dsa, &bar_offset, "write_byte");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
Stephen Rothwell0d416f22007-12-07 01:52:45 +1100684 if (dn == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 do {
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100687 rc = HvCall4(HvCallPciBarStore8, dsa, bar_offset, data, 0);
688 } while (check_return_code("WWB", dn, &retry, rc) != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
Stephen Rothwell34489382007-12-07 01:53:44 +1100691static void iseries_writew_be(u16 data, volatile void __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692{
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100693 u64 bar_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 u64 dsa;
Stephen Rothwella2ebaf22005-06-21 17:15:47 -0700695 int retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 u64 rc;
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100697 struct device_node *dn =
Stephen Rothwell0d416f22007-12-07 01:52:45 +1100698 xlate_iomm_address(addr, &dsa, &bar_offset, "write_word");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
Stephen Rothwell0d416f22007-12-07 01:52:45 +1100700 if (dn == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 do {
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100703 rc = HvCall4(HvCallPciBarStore16, dsa, bar_offset, data, 0);
704 } while (check_return_code("WWW", dn, &retry, rc) != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
Stephen Rothwell34489382007-12-07 01:53:44 +1100707static void iseries_writel_be(u32 data, volatile void __iomem *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708{
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100709 u64 bar_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 u64 dsa;
Stephen Rothwella2ebaf22005-06-21 17:15:47 -0700711 int retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 u64 rc;
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100713 struct device_node *dn =
Stephen Rothwell0d416f22007-12-07 01:52:45 +1100714 xlate_iomm_address(addr, &dsa, &bar_offset, "write_long");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
Stephen Rothwell0d416f22007-12-07 01:52:45 +1100716 if (dn == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 do {
Stephen Rothwell7a73bd72007-12-07 01:49:27 +1100719 rc = HvCall4(HvCallPciBarStore32, dsa, bar_offset, data, 0);
720 } while (check_return_code("WWL", dn, &retry, rc) != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721}
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000722
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100723static u16 iseries_readw(const volatile void __iomem *addr)
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000724{
Stephen Rothwell34489382007-12-07 01:53:44 +1100725 return le16_to_cpu(iseries_readw_be(addr));
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000726}
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000727
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100728static u32 iseries_readl(const volatile void __iomem *addr)
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000729{
Stephen Rothwell34489382007-12-07 01:53:44 +1100730 return le32_to_cpu(iseries_readl_be(addr));
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000731}
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000732
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100733static void iseries_writew(u16 data, volatile void __iomem *addr)
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000734{
Stephen Rothwell34489382007-12-07 01:53:44 +1100735 iseries_writew_be(cpu_to_le16(data), addr);
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000736}
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000737
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100738static void iseries_writel(u32 data, volatile void __iomem *addr)
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000739{
Stephen Rothwell34489382007-12-07 01:53:44 +1100740 iseries_writel(cpu_to_le32(data), addr);
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000741}
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000742
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100743static void iseries_readsb(const volatile void __iomem *addr, void *buf,
744 unsigned long count)
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000745{
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100746 u8 *dst = buf;
747 while(count-- > 0)
Stephen Rothwell34489382007-12-07 01:53:44 +1100748 *(dst++) = iseries_readb(addr);
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000749}
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000750
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100751static void iseries_readsw(const volatile void __iomem *addr, void *buf,
752 unsigned long count)
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000753{
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100754 u16 *dst = buf;
755 while(count-- > 0)
Stephen Rothwell34489382007-12-07 01:53:44 +1100756 *(dst++) = iseries_readw_be(addr);
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000757}
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000758
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100759static void iseries_readsl(const volatile void __iomem *addr, void *buf,
760 unsigned long count)
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000761{
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100762 u32 *dst = buf;
763 while(count-- > 0)
Stephen Rothwell34489382007-12-07 01:53:44 +1100764 *(dst++) = iseries_readl_be(addr);
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000765}
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000766
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100767static void iseries_writesb(volatile void __iomem *addr, const void *buf,
768 unsigned long count)
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000769{
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100770 const u8 *src = buf;
771 while(count-- > 0)
Stephen Rothwell34489382007-12-07 01:53:44 +1100772 iseries_writeb(*(src++), addr);
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000773}
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000774
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100775static void iseries_writesw(volatile void __iomem *addr, const void *buf,
776 unsigned long count)
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000777{
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100778 const u16 *src = buf;
779 while(count-- > 0)
Stephen Rothwell34489382007-12-07 01:53:44 +1100780 iseries_writew_be(*(src++), addr);
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000781}
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000782
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100783static void iseries_writesl(volatile void __iomem *addr, const void *buf,
784 unsigned long count)
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000785{
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100786 const u32 *src = buf;
787 while(count-- > 0)
Stephen Rothwell34489382007-12-07 01:53:44 +1100788 iseries_writel_be(*(src++), addr);
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000789}
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000790
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100791static void iseries_memset_io(volatile void __iomem *addr, int c,
792 unsigned long n)
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000793{
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100794 volatile char __iomem *d = addr;
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000795
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100796 while (n-- > 0)
Stephen Rothwell34489382007-12-07 01:53:44 +1100797 iseries_writeb(c, d++);
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100798}
799
800static void iseries_memcpy_fromio(void *dest, const volatile void __iomem *src,
801 unsigned long n)
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000802{
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100803 char *d = dest;
804 const volatile char __iomem *s = src;
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000805
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100806 while (n-- > 0)
Stephen Rothwell34489382007-12-07 01:53:44 +1100807 *d++ = iseries_readb(s++);
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000808}
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000809
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100810static void iseries_memcpy_toio(volatile void __iomem *dest, const void *src,
811 unsigned long n)
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000812{
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100813 const char *s = src;
814 volatile char __iomem *d = dest;
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000815
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100816 while (n-- > 0)
Stephen Rothwell34489382007-12-07 01:53:44 +1100817 iseries_writeb(*s++, d++);
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000818}
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000819
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100820/* We only set MMIO ops. The default PIO ops will be default
821 * to the MMIO ops + pci_io_base which is 0 on iSeries as
822 * expected so both should work.
823 *
824 * Note that we don't implement the readq/writeq versions as
825 * I don't know of an HV call for doing so. Thus, the default
826 * operation will be used instead, which will fault a the value
827 * return by iSeries for MMIO addresses always hits a non mapped
828 * area. This is as good as the BUG() we used to have there.
829 */
830static struct ppc_pci_io __initdata iseries_pci_io = {
831 .readb = iseries_readb,
832 .readw = iseries_readw,
833 .readl = iseries_readl,
834 .readw_be = iseries_readw_be,
835 .readl_be = iseries_readl_be,
836 .writeb = iseries_writeb,
837 .writew = iseries_writew,
838 .writel = iseries_writel,
839 .writew_be = iseries_writew_be,
840 .writel_be = iseries_writel_be,
841 .readsb = iseries_readsb,
842 .readsw = iseries_readsw,
843 .readsl = iseries_readsl,
844 .writesb = iseries_writesb,
845 .writesw = iseries_writesw,
846 .writesl = iseries_writesl,
847 .memset_io = iseries_memset_io,
848 .memcpy_fromio = iseries_memcpy_fromio,
849 .memcpy_toio = iseries_memcpy_toio,
850};
851
852/*
853 * iSeries_pcibios_init
854 *
855 * Description:
856 * This function checks for all possible system PCI host bridges that connect
857 * PCI buses. The system hypervisor is queried as to the guest partition
858 * ownership status. A pci_controller is built for any bus which is partially
859 * owned or fully owned by this guest partition.
860 */
861void __init iSeries_pcibios_init(void)
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000862{
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100863 struct pci_controller *phb;
864 struct device_node *root = of_find_node_by_path("/");
865 struct device_node *node = NULL;
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000866
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100867 /* Install IO hooks */
868 ppc_pci_io = iseries_pci_io;
869
Stephen Rothwell9ccc4fd2007-12-07 02:03:23 +1100870 pci_probe_only = 1;
871
Benjamin Herrenschmidt3d5134e2007-06-04 15:15:36 +1000872 /* iSeries has no IO space in the common sense, it needs to set
873 * the IO base to 0
874 */
875 pci_io_base = 0;
876
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100877 if (root == NULL) {
878 printk(KERN_CRIT "iSeries_pcibios_init: can't find root "
879 "of device tree\n");
880 return;
881 }
882 while ((node = of_get_next_child(root, node)) != NULL) {
883 HvBusNumber bus;
884 const u32 *busp;
885
886 if ((node->type == NULL) || (strcmp(node->type, "pci") != 0))
887 continue;
888
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000889 busp = of_get_property(node, "bus-range", NULL);
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100890 if (busp == NULL)
891 continue;
892 bus = *busp;
893 printk("bus %d appears to exist\n", bus);
894 phb = pcibios_alloc_controller(node);
895 if (phb == NULL)
896 continue;
Stephen Rothwell6207e812007-12-07 02:04:33 +1100897 /* All legacy iSeries PHBs are in domain zero */
898 phb->global_number = 0;
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100899
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100900 phb->first_busno = bus;
901 phb->last_busno = bus;
902 phb->ops = &iSeries_pci_ops;
Benjamin Herrenschmidt50c9bc22007-12-20 14:54:55 +1100903 phb->io_base_virt = (void __iomem *)_IO_BASE;
904 phb->io_resource.flags = IORESOURCE_IO;
905 phb->io_resource.start = BASE_IO_MEMORY;
906 phb->io_resource.end = END_IO_MEMORY;
907 phb->io_resource.name = "iSeries PCI IO";
908 phb->mem_resources[0].flags = IORESOURCE_MEM;
909 phb->mem_resources[0].start = BASE_IO_MEMORY;
910 phb->mem_resources[0].end = END_IO_MEMORY;
911 phb->mem_resources[0].name = "Series PCI MEM";
Benjamin Herrenschmidt4cb3cee2006-11-11 17:25:10 +1100912 }
913
914 of_node_put(root);
915
916 pci_devs_phb_init();
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000917}
Stephen Rothwellcaf81322006-09-21 18:00:00 +1000918