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