4 * Copyright (C) 2001 Allan Trautman, IBM Corporation
6 * iSeries specific routines for PCI.
8 * Based on code from pci.c and iSeries_pci.c 32bit
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <linux/kernel.h>
25 #include <linux/list.h>
26 #include <linux/string.h>
27 #include <linux/init.h>
28 #include <linux/module.h>
29 #include <linux/ide.h>
30 #include <linux/pci.h>
35 #include <asm/machdep.h>
36 #include <asm/pci-bridge.h>
37 #include <asm/ppcdebug.h>
38 #include <asm/iommu.h>
40 #include <asm/iSeries/HvCallPci.h>
41 #include <asm/iSeries/HvCallSm.h>
42 #include <asm/iSeries/HvCallXm.h>
43 #include <asm/iSeries/LparData.h>
44 #include <asm/iSeries/iSeries_irq.h>
45 #include <asm/iSeries/iSeries_pci.h>
46 #include <asm/iSeries/mf.h>
50 extern unsigned long io_page_mask;
53 * Forward declares of prototypes.
55 static struct iSeries_Device_Node *find_Device_Node(int bus, int devfn);
56 static void scan_PHB_slots(struct pci_controller *Phb);
57 static void scan_EADS_bridge(HvBusNumber Bus, HvSubBusNumber SubBus, int IdSel);
58 static int scan_bridge_slot(HvBusNumber Bus, struct HvCallPci_BridgeInfo *Info);
60 LIST_HEAD(iSeries_Global_Device_List);
62 static int DeviceCount;
64 /* Counters and control flags. */
65 static long Pci_Io_Read_Count;
66 static long Pci_Io_Write_Count;
68 static long Pci_Cfg_Read_Count;
69 static long Pci_Cfg_Write_Count;
71 static long Pci_Error_Count;
73 static int Pci_Retry_Max = 3; /* Only retry 3 times */
74 static int Pci_Error_Flag = 1; /* Set Retry Error on. */
76 static struct pci_ops iSeries_pci_ops;
80 * Each Entry size is 4 MB * 1024 Entries = 4GB I/O address space.
82 #define IOMM_TABLE_MAX_ENTRIES 1024
83 #define IOMM_TABLE_ENTRY_SIZE 0x0000000000400000UL
84 #define BASE_IO_MEMORY 0xE000000000000000UL
86 static unsigned long max_io_memory = 0xE000000000000000UL;
87 static long current_iomm_table_entry;
92 static struct iSeries_Device_Node **iomm_table;
93 static u8 *iobar_table;
96 * Static and Global variables
98 static char *pci_io_text = "iSeries PCI I/O";
99 static DEFINE_SPINLOCK(iomm_table_lock);
102 * iomm_table_initialize
104 * Allocates and initalizes the Address Translation Table and Bar
105 * Tables to get them ready for use. Must be called before any
106 * I/O space is handed out to the device BARs.
108 static void iomm_table_initialize(void)
110 spin_lock(&iomm_table_lock);
111 iomm_table = kmalloc(sizeof(*iomm_table) * IOMM_TABLE_MAX_ENTRIES,
113 iobar_table = kmalloc(sizeof(*iobar_table) * IOMM_TABLE_MAX_ENTRIES,
115 spin_unlock(&iomm_table_lock);
116 if ((iomm_table == NULL) || (iobar_table == NULL))
117 panic("PCI: I/O tables allocation failed.\n");
121 * iomm_table_allocate_entry
123 * Adds pci_dev entry in address translation table
125 * - Allocates the number of entries required in table base on BAR
127 * - Allocates starting at BASE_IO_MEMORY and increases.
128 * - The size is round up to be a multiple of entry size.
129 * - CurrentIndex is incremented to keep track of the last entry.
130 * - Builds the resource entry for allocated BARs.
132 static void iomm_table_allocate_entry(struct pci_dev *dev, int bar_num)
134 struct resource *bar_res = &dev->resource[bar_num];
135 long bar_size = pci_resource_len(dev, bar_num);
138 * No space to allocate, quick exit, skip Allocation.
143 * Set Resource values.
145 spin_lock(&iomm_table_lock);
146 bar_res->name = pci_io_text;
148 IOMM_TABLE_ENTRY_SIZE * current_iomm_table_entry;
149 bar_res->start += BASE_IO_MEMORY;
150 bar_res->end = bar_res->start + bar_size - 1;
152 * Allocate the number of table entries needed for BAR.
154 while (bar_size > 0 ) {
155 iomm_table[current_iomm_table_entry] = dev->sysdata;
156 iobar_table[current_iomm_table_entry] = bar_num;
157 bar_size -= IOMM_TABLE_ENTRY_SIZE;
158 ++current_iomm_table_entry;
160 max_io_memory = BASE_IO_MEMORY +
161 (IOMM_TABLE_ENTRY_SIZE * current_iomm_table_entry);
162 spin_unlock(&iomm_table_lock);
166 * allocate_device_bars
168 * - Allocates ALL pci_dev BAR's and updates the resources with the
169 * BAR value. BARS with zero length will have the resources
170 * The HvCallPci_getBarParms is used to get the size of the BAR
171 * space. It calls iomm_table_allocate_entry to allocate
173 * - Loops through The Bar resources(0 - 5) including the ROM
176 static void allocate_device_bars(struct pci_dev *dev)
178 struct resource *bar_res;
181 for (bar_num = 0; bar_num <= PCI_ROM_RESOURCE; ++bar_num) {
182 bar_res = &dev->resource[bar_num];
183 iomm_table_allocate_entry(dev, bar_num);
188 * Log error information to system console.
189 * Filter out the device not there errors.
190 * PCI: EADs Connect Failed 0x18.58.10 Rc: 0x00xx
191 * PCI: Read Vendor Failed 0x18.58.10 Rc: 0x00xx
192 * PCI: Connect Bus Unit Failed 0x18.58.10 Rc: 0x00xx
194 static void pci_Log_Error(char *Error_Text, int Bus, int SubBus,
195 int AgentId, int HvRc)
199 printk(KERN_ERR "PCI: %s Failed: 0x%02X.%02X.%02X Rc: 0x%04X",
200 Error_Text, Bus, SubBus, AgentId, HvRc);
204 * build_device_node(u16 Bus, int SubBus, u8 DevFn)
206 static struct iSeries_Device_Node *build_device_node(HvBusNumber Bus,
207 HvSubBusNumber SubBus, int AgentId, int Function)
209 struct iSeries_Device_Node *node;
211 PPCDBG(PPCDBG_BUSWALK,
212 "-build_device_node 0x%02X.%02X.%02X Function: %02X\n",
213 Bus, SubBus, AgentId, Function);
215 node = kmalloc(sizeof(struct iSeries_Device_Node), GFP_KERNEL);
219 memset(node, 0, sizeof(struct iSeries_Device_Node));
220 list_add_tail(&node->Device_List, &iSeries_Global_Device_List);
222 node->DsaAddr = ((u64)Bus << 48) + ((u64)SubBus << 40) + ((u64)0x10 << 32);
224 node->DsaAddr.DsaAddr = 0;
225 node->DsaAddr.Dsa.busNumber = Bus;
226 node->DsaAddr.Dsa.subBusNumber = SubBus;
227 node->DsaAddr.Dsa.deviceId = 0x10;
228 node->AgentId = AgentId;
229 node->DevFn = PCI_DEVFN(ISERIES_ENCODE_DEVICE(AgentId), Function);
231 iSeries_Get_Location_Code(node);
236 * unsigned long __init find_and_init_phbs(void)
239 * This function checks for all possible system PCI host bridges that connect
240 * PCI buses. The system hypervisor is queried as to the guest partition
241 * ownership status. A pci_controller is built for any bus which is partially
242 * owned or fully owned by this guest partition.
244 unsigned long __init find_and_init_phbs(void)
246 struct pci_controller *phb;
249 PPCDBG(PPCDBG_BUSWALK, "find_and_init_phbs Entry\n");
251 /* Check all possible buses. */
252 for (bus = 0; bus < 256; bus++) {
253 int ret = HvCallXm_testBus(bus);
255 printk("bus %d appears to exist\n", bus);
257 phb = (struct pci_controller *)kmalloc(sizeof(struct pci_controller), GFP_KERNEL);
260 pci_setup_pci_controller(phb);
262 phb->pci_mem_offset = phb->local_number = bus;
263 phb->first_busno = bus;
264 phb->last_busno = bus;
265 phb->ops = &iSeries_pci_ops;
267 PPCDBG(PPCDBG_BUSWALK, "PCI:Create iSeries pci_controller(%p), Bus: %04X\n",
270 /* Find and connect the devices. */
274 * Check for Unexpected Return code, a clue that something
277 else if (ret != 0x0301)
278 printk(KERN_ERR "Unexpected Return on Probe(0x%04X): 0x%04X",
285 * iSeries_pcibios_init
287 * Chance to initialize and structures or variable before PCI Bus walk.
289 void iSeries_pcibios_init(void)
291 PPCDBG(PPCDBG_BUSWALK, "iSeries_pcibios_init Entry.\n");
292 iomm_table_initialize();
293 find_and_init_phbs();
295 PPCDBG(PPCDBG_BUSWALK, "iSeries_pcibios_init Exit.\n");
299 * iSeries_pci_final_fixup(void)
301 void __init iSeries_pci_final_fixup(void)
303 struct pci_dev *pdev = NULL;
304 struct iSeries_Device_Node *node;
308 PPCDBG(PPCDBG_BUSWALK, "iSeries_pcibios_fixup Entry.\n");
310 /* Fix up at the device node and pci_dev relationship */
311 mf_display_src(0xC9000100);
313 printk("pcibios_final_fixup\n");
314 for_each_pci_dev(pdev) {
315 node = find_Device_Node(pdev->bus->number, pdev->devfn);
316 printk("pci dev %p (%x.%x), node %p\n", pdev,
317 pdev->bus->number, pdev->devfn, node);
321 pdev->sysdata = (void *)node;
323 PPCDBG(PPCDBG_BUSWALK,
324 "pdev 0x%p <==> DevNode 0x%p\n",
326 allocate_device_bars(pdev);
327 iSeries_Device_Information(pdev, Buffer,
329 printk("%d. %s\n", DeviceCount, Buffer);
330 iommu_devnode_init_iSeries(node);
332 printk("PCI: Device Tree not found for 0x%016lX\n",
333 (unsigned long)pdev);
334 pdev->irq = node->Irq;
336 iSeries_activate_IRQs();
337 mf_display_src(0xC9000200);
340 void pcibios_fixup_bus(struct pci_bus *PciBus)
342 PPCDBG(PPCDBG_BUSWALK, "iSeries_pcibios_fixup_bus(0x%04X) Entry.\n",
346 void pcibios_fixup_resources(struct pci_dev *pdev)
348 PPCDBG(PPCDBG_BUSWALK, "fixup_resources pdev %p\n", pdev);
352 * Loop through each node function to find usable EADs bridges.
354 static void scan_PHB_slots(struct pci_controller *Phb)
356 struct HvCallPci_DeviceInfo *DevInfo;
357 HvBusNumber bus = Phb->local_number; /* System Bus */
358 const HvSubBusNumber SubBus = 0; /* EADs is always 0. */
361 const int MaxAgents = 8;
363 DevInfo = (struct HvCallPci_DeviceInfo*)
364 kmalloc(sizeof(struct HvCallPci_DeviceInfo), GFP_KERNEL);
369 * Probe for EADs Bridges
371 for (IdSel = 1; IdSel < MaxAgents; ++IdSel) {
372 HvRc = HvCallPci_getDeviceInfo(bus, SubBus, IdSel,
373 ISERIES_HV_ADDR(DevInfo),
374 sizeof(struct HvCallPci_DeviceInfo));
376 if (DevInfo->deviceType == HvCallPci_NodeDevice)
377 scan_EADS_bridge(bus, SubBus, IdSel);
379 printk("PCI: Invalid System Configuration(0x%02X)"
380 " for bus 0x%02x id 0x%02x.\n",
381 DevInfo->deviceType, bus, IdSel);
384 pci_Log_Error("getDeviceInfo", bus, SubBus, IdSel, HvRc);
389 static void scan_EADS_bridge(HvBusNumber bus, HvSubBusNumber SubBus,
392 struct HvCallPci_BridgeInfo *BridgeInfo;
397 BridgeInfo = (struct HvCallPci_BridgeInfo *)
398 kmalloc(sizeof(struct HvCallPci_BridgeInfo), GFP_KERNEL);
399 if (BridgeInfo == NULL)
402 /* Note: hvSubBus and irq is always be 0 at this level! */
403 for (Function = 0; Function < 8; ++Function) {
404 AgentId = ISERIES_PCI_AGENTID(IdSel, Function);
405 HvRc = HvCallXm_connectBusUnit(bus, SubBus, AgentId, 0);
407 printk("found device at bus %d idsel %d func %d (AgentId %x)\n",
408 bus, IdSel, Function, AgentId);
409 /* Connect EADs: 0x18.00.12 = 0x00 */
410 PPCDBG(PPCDBG_BUSWALK,
411 "PCI:Connect EADs: 0x%02X.%02X.%02X\n",
412 bus, SubBus, AgentId);
413 HvRc = HvCallPci_getBusUnitInfo(bus, SubBus, AgentId,
414 ISERIES_HV_ADDR(BridgeInfo),
415 sizeof(struct HvCallPci_BridgeInfo));
417 printk("bridge info: type %x subbus %x maxAgents %x maxsubbus %x logslot %x\n",
418 BridgeInfo->busUnitInfo.deviceType,
419 BridgeInfo->subBusNumber,
420 BridgeInfo->maxAgents,
421 BridgeInfo->maxSubBusNumber,
422 BridgeInfo->logicalSlotNumber);
423 PPCDBG(PPCDBG_BUSWALK,
424 "PCI: BridgeInfo, Type:0x%02X, SubBus:0x%02X, MaxAgents:0x%02X, MaxSubBus: 0x%02X, LSlot: 0x%02X\n",
425 BridgeInfo->busUnitInfo.deviceType,
426 BridgeInfo->subBusNumber,
427 BridgeInfo->maxAgents,
428 BridgeInfo->maxSubBusNumber,
429 BridgeInfo->logicalSlotNumber);
431 if (BridgeInfo->busUnitInfo.deviceType ==
432 HvCallPci_BridgeDevice) {
433 /* Scan_Bridge_Slot...: 0x18.00.12 */
434 scan_bridge_slot(bus, BridgeInfo);
436 printk("PCI: Invalid Bridge Configuration(0x%02X)",
437 BridgeInfo->busUnitInfo.deviceType);
439 } else if (HvRc != 0x000B)
440 pci_Log_Error("EADs Connect",
441 bus, SubBus, AgentId, HvRc);
447 * This assumes that the node slot is always on the primary bus!
449 static int scan_bridge_slot(HvBusNumber Bus,
450 struct HvCallPci_BridgeInfo *BridgeInfo)
452 struct iSeries_Device_Node *node;
453 HvSubBusNumber SubBus = BridgeInfo->subBusNumber;
457 int IdSel = ISERIES_GET_DEVICE_FROM_SUBBUS(SubBus);
458 int Function = ISERIES_GET_FUNCTION_FROM_SUBBUS(SubBus);
459 HvAgentId EADsIdSel = ISERIES_PCI_AGENTID(IdSel, Function);
461 /* iSeries_allocate_IRQ.: 0x18.00.12(0xA3) */
462 Irq = iSeries_allocate_IRQ(Bus, 0, EADsIdSel);
463 PPCDBG(PPCDBG_BUSWALK,
464 "PCI:- allocate and assign IRQ 0x%02X.%02X.%02X = 0x%02X\n",
465 Bus, 0, EADsIdSel, Irq);
468 * Connect all functions of any device found.
470 for (IdSel = 1; IdSel <= BridgeInfo->maxAgents; ++IdSel) {
471 for (Function = 0; Function < 8; ++Function) {
472 HvAgentId AgentId = ISERIES_PCI_AGENTID(IdSel, Function);
473 HvRc = HvCallXm_connectBusUnit(Bus, SubBus,
476 pci_Log_Error("Connect Bus Unit",
477 Bus, SubBus, AgentId, HvRc);
481 HvRc = HvCallPci_configLoad16(Bus, SubBus, AgentId,
482 PCI_VENDOR_ID, &VendorId);
484 pci_Log_Error("Read Vendor",
485 Bus, SubBus, AgentId, HvRc);
488 printk("read vendor ID: %x\n", VendorId);
490 /* FoundDevice: 0x18.28.10 = 0x12AE */
491 PPCDBG(PPCDBG_BUSWALK,
492 "PCI:- FoundDevice: 0x%02X.%02X.%02X = 0x%04X, irq %d\n",
493 Bus, SubBus, AgentId, VendorId, Irq);
494 HvRc = HvCallPci_configStore8(Bus, SubBus, AgentId,
495 PCI_INTERRUPT_LINE, Irq);
497 pci_Log_Error("PciCfgStore Irq Failed!",
498 Bus, SubBus, AgentId, HvRc);
501 node = build_device_node(Bus, SubBus, EADsIdSel, Function);
502 node->Vendor = VendorId;
504 node->LogicalSlot = BridgeInfo->logicalSlotNumber;
506 } /* for (Function = 0; Function < 8; ++Function) */
507 } /* for (IdSel = 1; IdSel <= MaxAgents; ++IdSel) */
512 * I/0 Memory copy MUST use mmio commands on iSeries
513 * To do; For performance, include the hv call directly
515 void iSeries_memset_io(volatile void __iomem *dest, char c, size_t Count)
518 long NumberOfBytes = Count;
520 while (NumberOfBytes > 0) {
521 iSeries_Write_Byte(ByteValue, dest++);
525 EXPORT_SYMBOL(iSeries_memset_io);
527 void iSeries_memcpy_toio(volatile void __iomem *dest, void *source, size_t count)
530 long NumberOfBytes = count;
532 while (NumberOfBytes > 0) {
533 iSeries_Write_Byte(*src++, dest++);
537 EXPORT_SYMBOL(iSeries_memcpy_toio);
539 void iSeries_memcpy_fromio(void *dest, const volatile void __iomem *src, size_t count)
542 long NumberOfBytes = count;
544 while (NumberOfBytes > 0) {
545 *dst++ = iSeries_Read_Byte(src++);
549 EXPORT_SYMBOL(iSeries_memcpy_fromio);
552 * Look down the chain to find the matching Device Device
554 static struct iSeries_Device_Node *find_Device_Node(int bus, int devfn)
556 struct list_head *pos;
558 list_for_each(pos, &iSeries_Global_Device_List) {
559 struct iSeries_Device_Node *node =
560 list_entry(pos, struct iSeries_Device_Node, Device_List);
562 if ((bus == ISERIES_BUS(node)) && (devfn == node->DevFn))
570 * Returns the device node for the passed pci_dev
571 * Sanity Check Node PciDev to passed pci_dev
572 * If none is found, returns a NULL which the client must handle.
574 static struct iSeries_Device_Node *get_Device_Node(struct pci_dev *pdev)
576 struct iSeries_Device_Node *node;
578 node = pdev->sysdata;
579 if (node == NULL || node->PciDev != pdev)
580 node = find_Device_Node(pdev->bus->number, pdev->devfn);
586 * Config space read and write functions.
587 * For now at least, we look for the device node for the bus and devfn
588 * that we are asked to access. It may be possible to translate the devfn
589 * to a subbus and deviceid more directly.
591 static u64 hv_cfg_read_func[4] = {
592 HvCallPciConfigLoad8, HvCallPciConfigLoad16,
593 HvCallPciConfigLoad32, HvCallPciConfigLoad32
596 static u64 hv_cfg_write_func[4] = {
597 HvCallPciConfigStore8, HvCallPciConfigStore16,
598 HvCallPciConfigStore32, HvCallPciConfigStore32
602 * Read PCI config space
604 static int iSeries_pci_read_config(struct pci_bus *bus, unsigned int devfn,
605 int offset, int size, u32 *val)
607 struct iSeries_Device_Node *node = find_Device_Node(bus->number, devfn);
609 struct HvCallPci_LoadReturn ret;
612 return PCIBIOS_DEVICE_NOT_FOUND;
615 return PCIBIOS_BAD_REGISTER_NUMBER;
618 fn = hv_cfg_read_func[(size - 1) & 3];
619 HvCall3Ret16(fn, &ret, node->DsaAddr.DsaAddr, offset, 0);
623 return PCIBIOS_DEVICE_NOT_FOUND; /* or something */
631 * Write PCI config space
634 static int iSeries_pci_write_config(struct pci_bus *bus, unsigned int devfn,
635 int offset, int size, u32 val)
637 struct iSeries_Device_Node *node = find_Device_Node(bus->number, devfn);
642 return PCIBIOS_DEVICE_NOT_FOUND;
644 return PCIBIOS_BAD_REGISTER_NUMBER;
646 fn = hv_cfg_write_func[(size - 1) & 3];
647 ret = HvCall4(fn, node->DsaAddr.DsaAddr, offset, val, 0);
650 return PCIBIOS_DEVICE_NOT_FOUND;
655 static struct pci_ops iSeries_pci_ops = {
656 .read = iSeries_pci_read_config,
657 .write = iSeries_pci_write_config
662 * -> On Failure, print and log information.
663 * Increment Retry Count, if exceeds max, panic partition.
664 * -> If in retry, print and log success
666 * PCI: Device 23.90 ReadL I/O Error( 0): 0x1234
667 * PCI: Device 23.90 ReadL Retry( 1)
668 * PCI: Device 23.90 ReadL Retry Successful(1)
670 static int CheckReturnCode(char *TextHdr, struct iSeries_Device_Node *DevNode,
676 printk("PCI: %s: Device 0x%04X:%02X I/O Error(%2d): 0x%04X\n",
677 TextHdr, DevNode->DsaAddr.Dsa.busNumber, DevNode->DevFn,
678 DevNode->IoRetry, (int)ret);
680 * Bump the retry and check for retry count exceeded.
681 * If, Exceeded, panic the system.
683 if ((DevNode->IoRetry > Pci_Retry_Max) &&
684 (Pci_Error_Flag > 0)) {
685 mf_display_src(0xB6000103);
687 panic("PCI: Hardware I/O Error, SRC B6000103, "
688 "Automatic Reboot Disabled.\n");
690 return -1; /* Retry Try */
692 /* If retry was in progress, log success and rest retry count */
693 if (DevNode->IoRetry > 0)
694 DevNode->IoRetry = 0;
699 * Translate the I/O Address into a device node, bar, and bar offset.
700 * Note: Make sure the passed variable end up on the stack to avoid
701 * the exposure of being device global.
703 static inline struct iSeries_Device_Node *xlate_iomm_address(
704 const volatile void __iomem *IoAddress,
705 u64 *dsaptr, u64 *BarOffsetPtr)
707 unsigned long OrigIoAddr;
708 unsigned long BaseIoAddr;
709 unsigned long TableIndex;
710 struct iSeries_Device_Node *DevNode;
712 OrigIoAddr = (unsigned long __force)IoAddress;
713 if ((OrigIoAddr < BASE_IO_MEMORY) || (OrigIoAddr >= max_io_memory))
715 BaseIoAddr = OrigIoAddr - BASE_IO_MEMORY;
716 TableIndex = BaseIoAddr / IOMM_TABLE_ENTRY_SIZE;
717 DevNode = iomm_table[TableIndex];
719 if (DevNode != NULL) {
720 int barnum = iobar_table[TableIndex];
721 *dsaptr = DevNode->DsaAddr.DsaAddr | (barnum << 24);
722 *BarOffsetPtr = BaseIoAddr % IOMM_TABLE_ENTRY_SIZE;
724 panic("PCI: Invalid PCI IoAddress detected!\n");
729 * Read MM I/O Instructions for the iSeries
730 * On MM I/O error, all ones are returned and iSeries_pci_IoError is cal
731 * else, data is returned in big Endian format.
733 * iSeries_Read_Byte = Read Byte ( 8 bit)
734 * iSeries_Read_Word = Read Word (16 bit)
735 * iSeries_Read_Long = Read Long (32 bit)
737 u8 iSeries_Read_Byte(const volatile void __iomem *IoAddress)
741 struct HvCallPci_LoadReturn ret;
742 struct iSeries_Device_Node *DevNode =
743 xlate_iomm_address(IoAddress, &dsa, &BarOffset);
745 if (DevNode == NULL) {
746 static unsigned long last_jiffies;
747 static int num_printed;
749 if ((jiffies - last_jiffies) > 60 * HZ) {
750 last_jiffies = jiffies;
753 if (num_printed++ < 10)
754 printk(KERN_ERR "iSeries_Read_Byte: invalid access at IO address %p\n", IoAddress);
759 HvCall3Ret16(HvCallPciBarLoad8, &ret, dsa, BarOffset, 0);
760 } while (CheckReturnCode("RDB", DevNode, ret.rc) != 0);
762 return (u8)ret.value;
764 EXPORT_SYMBOL(iSeries_Read_Byte);
766 u16 iSeries_Read_Word(const volatile void __iomem *IoAddress)
770 struct HvCallPci_LoadReturn ret;
771 struct iSeries_Device_Node *DevNode =
772 xlate_iomm_address(IoAddress, &dsa, &BarOffset);
774 if (DevNode == NULL) {
775 static unsigned long last_jiffies;
776 static int num_printed;
778 if ((jiffies - last_jiffies) > 60 * HZ) {
779 last_jiffies = jiffies;
782 if (num_printed++ < 10)
783 printk(KERN_ERR "iSeries_Read_Word: invalid access at IO address %p\n", IoAddress);
788 HvCall3Ret16(HvCallPciBarLoad16, &ret, dsa,
790 } while (CheckReturnCode("RDW", DevNode, ret.rc) != 0);
792 return swab16((u16)ret.value);
794 EXPORT_SYMBOL(iSeries_Read_Word);
796 u32 iSeries_Read_Long(const volatile void __iomem *IoAddress)
800 struct HvCallPci_LoadReturn ret;
801 struct iSeries_Device_Node *DevNode =
802 xlate_iomm_address(IoAddress, &dsa, &BarOffset);
804 if (DevNode == NULL) {
805 static unsigned long last_jiffies;
806 static int num_printed;
808 if ((jiffies - last_jiffies) > 60 * HZ) {
809 last_jiffies = jiffies;
812 if (num_printed++ < 10)
813 printk(KERN_ERR "iSeries_Read_Long: invalid access at IO address %p\n", IoAddress);
818 HvCall3Ret16(HvCallPciBarLoad32, &ret, dsa,
820 } while (CheckReturnCode("RDL", DevNode, ret.rc) != 0);
822 return swab32((u32)ret.value);
824 EXPORT_SYMBOL(iSeries_Read_Long);
827 * Write MM I/O Instructions for the iSeries
829 * iSeries_Write_Byte = Write Byte (8 bit)
830 * iSeries_Write_Word = Write Word(16 bit)
831 * iSeries_Write_Long = Write Long(32 bit)
833 void iSeries_Write_Byte(u8 data, volatile void __iomem *IoAddress)
838 struct iSeries_Device_Node *DevNode =
839 xlate_iomm_address(IoAddress, &dsa, &BarOffset);
841 if (DevNode == NULL) {
842 static unsigned long last_jiffies;
843 static int num_printed;
845 if ((jiffies - last_jiffies) > 60 * HZ) {
846 last_jiffies = jiffies;
849 if (num_printed++ < 10)
850 printk(KERN_ERR "iSeries_Write_Byte: invalid access at IO address %p\n", IoAddress);
854 ++Pci_Io_Write_Count;
855 rc = HvCall4(HvCallPciBarStore8, dsa, BarOffset, data, 0);
856 } while (CheckReturnCode("WWB", DevNode, rc) != 0);
858 EXPORT_SYMBOL(iSeries_Write_Byte);
860 void iSeries_Write_Word(u16 data, volatile void __iomem *IoAddress)
865 struct iSeries_Device_Node *DevNode =
866 xlate_iomm_address(IoAddress, &dsa, &BarOffset);
868 if (DevNode == NULL) {
869 static unsigned long last_jiffies;
870 static int num_printed;
872 if ((jiffies - last_jiffies) > 60 * HZ) {
873 last_jiffies = jiffies;
876 if (num_printed++ < 10)
877 printk(KERN_ERR "iSeries_Write_Word: invalid access at IO address %p\n", IoAddress);
881 ++Pci_Io_Write_Count;
882 rc = HvCall4(HvCallPciBarStore16, dsa, BarOffset, swab16(data), 0);
883 } while (CheckReturnCode("WWW", DevNode, rc) != 0);
885 EXPORT_SYMBOL(iSeries_Write_Word);
887 void iSeries_Write_Long(u32 data, volatile void __iomem *IoAddress)
892 struct iSeries_Device_Node *DevNode =
893 xlate_iomm_address(IoAddress, &dsa, &BarOffset);
895 if (DevNode == NULL) {
896 static unsigned long last_jiffies;
897 static int num_printed;
899 if ((jiffies - last_jiffies) > 60 * HZ) {
900 last_jiffies = jiffies;
903 if (num_printed++ < 10)
904 printk(KERN_ERR "iSeries_Write_Long: invalid access at IO address %p\n", IoAddress);
908 ++Pci_Io_Write_Count;
909 rc = HvCall4(HvCallPciBarStore32, dsa, BarOffset, swab32(data), 0);
910 } while (CheckReturnCode("WWL", DevNode, rc) != 0);
912 EXPORT_SYMBOL(iSeries_Write_Long);