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