Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/alpha/kernel/pci.c |
| 3 | * |
| 4 | * Extruded from code written by |
| 5 | * Dave Rusling (david.rusling@reo.mts.dec.com) |
| 6 | * David Mosberger (davidm@cs.arizona.edu) |
| 7 | */ |
| 8 | |
| 9 | /* 2.3.x PCI/resources, 1999 Andrea Arcangeli <andrea@suse.de> */ |
| 10 | |
| 11 | /* |
| 12 | * Nov 2000, Ivan Kokshaysky <ink@jurassic.park.msu.ru> |
| 13 | * PCI-PCI bridges cleanup |
| 14 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/string.h> |
| 16 | #include <linux/pci.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/ioport.h> |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/bootmem.h> |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/cache.h> |
| 23 | #include <linux/slab.h> |
| 24 | #include <asm/machvec.h> |
| 25 | |
| 26 | #include "proto.h" |
| 27 | #include "pci_impl.h" |
| 28 | |
| 29 | |
| 30 | /* |
| 31 | * Some string constants used by the various core logics. |
| 32 | */ |
| 33 | |
| 34 | const char *const pci_io_names[] = { |
| 35 | "PCI IO bus 0", "PCI IO bus 1", "PCI IO bus 2", "PCI IO bus 3", |
| 36 | "PCI IO bus 4", "PCI IO bus 5", "PCI IO bus 6", "PCI IO bus 7" |
| 37 | }; |
| 38 | |
| 39 | const char *const pci_mem_names[] = { |
| 40 | "PCI mem bus 0", "PCI mem bus 1", "PCI mem bus 2", "PCI mem bus 3", |
| 41 | "PCI mem bus 4", "PCI mem bus 5", "PCI mem bus 6", "PCI mem bus 7" |
| 42 | }; |
| 43 | |
| 44 | const char pci_hae0_name[] = "HAE0"; |
| 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | /* |
Bjorn Helgaas | 151d16d | 2012-02-23 20:18:56 -0700 | [diff] [blame^] | 47 | * If PCI_PROBE_ONLY in pci_flags is set, we don't change any PCI resource |
| 48 | * assignments. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | /* |
| 52 | * The PCI controller list. |
| 53 | */ |
| 54 | |
| 55 | struct pci_controller *hose_head, **hose_tail = &hose_head; |
| 56 | struct pci_controller *pci_isa_hose; |
| 57 | |
| 58 | /* |
| 59 | * Quirks. |
| 60 | */ |
| 61 | |
| 62 | static void __init |
| 63 | quirk_isa_bridge(struct pci_dev *dev) |
| 64 | { |
| 65 | dev->class = PCI_CLASS_BRIDGE_ISA << 8; |
| 66 | } |
| 67 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82378, quirk_isa_bridge); |
| 68 | |
| 69 | static void __init |
| 70 | quirk_cypress(struct pci_dev *dev) |
| 71 | { |
Ivan Kokshaysky | a744e01 | 2008-06-21 03:28:54 +0400 | [diff] [blame] | 72 | /* The Notorious Cy82C693 chip. */ |
| 73 | |
| 74 | /* The generic legacy mode IDE fixup in drivers/pci/probe.c |
| 75 | doesn't work correctly with the Cypress IDE controller as |
| 76 | it has non-standard register layout. Fix that. */ |
| 77 | if (dev->class >> 8 == PCI_CLASS_STORAGE_IDE) { |
| 78 | dev->resource[2].start = dev->resource[3].start = 0; |
| 79 | dev->resource[2].end = dev->resource[3].end = 0; |
| 80 | dev->resource[2].flags = dev->resource[3].flags = 0; |
| 81 | if (PCI_FUNC(dev->devfn) == 2) { |
| 82 | dev->resource[0].start = 0x170; |
| 83 | dev->resource[0].end = 0x177; |
| 84 | dev->resource[1].start = 0x376; |
| 85 | dev->resource[1].end = 0x376; |
| 86 | } |
| 87 | } |
| 88 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | /* The Cypress bridge responds on the PCI bus in the address range |
| 90 | 0xffff0000-0xffffffff (conventional x86 BIOS ROM). There is no |
| 91 | way to turn this off. The bridge also supports several extended |
| 92 | BIOS ranges (disabled after power-up), and some consoles do turn |
| 93 | them on. So if we use a large direct-map window, or a large SG |
| 94 | window, we must avoid the entire 0xfff00000-0xffffffff region. */ |
Ivan Kokshaysky | 72cff12 | 2008-04-24 16:51:55 +0400 | [diff] [blame] | 95 | if (dev->class >> 8 == PCI_CLASS_BRIDGE_ISA) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | if (__direct_map_base + __direct_map_size >= 0xfff00000UL) |
| 97 | __direct_map_size = 0xfff00000UL - __direct_map_base; |
| 98 | else { |
| 99 | struct pci_controller *hose = dev->sysdata; |
| 100 | struct pci_iommu_arena *pci = hose->sg_pci; |
| 101 | if (pci && pci->dma_base + pci->size >= 0xfff00000UL) |
| 102 | pci->size = 0xfff00000UL - pci->dma_base; |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_CONTAQ, PCI_DEVICE_ID_CONTAQ_82C693, quirk_cypress); |
| 107 | |
| 108 | /* Called for each device after PCI setup is done. */ |
| 109 | static void __init |
| 110 | pcibios_fixup_final(struct pci_dev *dev) |
| 111 | { |
| 112 | unsigned int class = dev->class >> 8; |
| 113 | |
| 114 | if (class == PCI_CLASS_BRIDGE_ISA || class == PCI_CLASS_BRIDGE_EISA) { |
| 115 | dev->dma_mask = MAX_ISA_DMA_ADDRESS - 1; |
| 116 | isa_bridge = dev; |
| 117 | } |
| 118 | } |
| 119 | DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, pcibios_fixup_final); |
| 120 | |
| 121 | /* Just declaring that the power-of-ten prefixes are actually the |
| 122 | power-of-two ones doesn't make it true :) */ |
| 123 | #define KB 1024 |
| 124 | #define MB (1024*KB) |
| 125 | #define GB (1024*MB) |
| 126 | |
Dominik Brodowski | b26b2d4 | 2010-01-01 17:40:49 +0100 | [diff] [blame] | 127 | resource_size_t |
Dominik Brodowski | 3b7a17f | 2010-01-01 17:40:50 +0100 | [diff] [blame] | 128 | pcibios_align_resource(void *data, const struct resource *res, |
Greg Kroah-Hartman | e31dd6e | 2006-06-12 17:06:02 -0700 | [diff] [blame] | 129 | resource_size_t size, resource_size_t align) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | { |
| 131 | struct pci_dev *dev = data; |
| 132 | struct pci_controller *hose = dev->sysdata; |
| 133 | unsigned long alignto; |
Greg Kroah-Hartman | e31dd6e | 2006-06-12 17:06:02 -0700 | [diff] [blame] | 134 | resource_size_t start = res->start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
| 136 | if (res->flags & IORESOURCE_IO) { |
| 137 | /* Make sure we start at our min on all hoses */ |
| 138 | if (start - hose->io_space->start < PCIBIOS_MIN_IO) |
| 139 | start = PCIBIOS_MIN_IO + hose->io_space->start; |
| 140 | |
| 141 | /* |
| 142 | * Put everything into 0x00-0xff region modulo 0x400 |
| 143 | */ |
| 144 | if (start & 0x300) |
| 145 | start = (start + 0x3ff) & ~0x3ff; |
| 146 | } |
| 147 | else if (res->flags & IORESOURCE_MEM) { |
| 148 | /* Make sure we start at our min on all hoses */ |
| 149 | if (start - hose->mem_space->start < PCIBIOS_MIN_MEM) |
| 150 | start = PCIBIOS_MIN_MEM + hose->mem_space->start; |
| 151 | |
| 152 | /* |
| 153 | * The following holds at least for the Low Cost |
| 154 | * Alpha implementation of the PCI interface: |
| 155 | * |
| 156 | * In sparse memory address space, the first |
| 157 | * octant (16MB) of every 128MB segment is |
| 158 | * aliased to the very first 16 MB of the |
| 159 | * address space (i.e., it aliases the ISA |
| 160 | * memory address space). Thus, we try to |
| 161 | * avoid allocating PCI devices in that range. |
| 162 | * Can be allocated in 2nd-7th octant only. |
| 163 | * Devices that need more than 112MB of |
| 164 | * address space must be accessed through |
| 165 | * dense memory space only! |
| 166 | */ |
| 167 | |
| 168 | /* Align to multiple of size of minimum base. */ |
Randy Dunlap | 5f0e3da | 2009-03-31 15:23:36 -0700 | [diff] [blame] | 169 | alignto = max_t(resource_size_t, 0x1000, align); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | start = ALIGN(start, alignto); |
| 171 | if (hose->sparse_mem_base && size <= 7 * 16*MB) { |
| 172 | if (((start / (16*MB)) & 0x7) == 0) { |
| 173 | start &= ~(128*MB - 1); |
| 174 | start += 16*MB; |
| 175 | start = ALIGN(start, alignto); |
| 176 | } |
| 177 | if (start/(128*MB) != (start + size - 1)/(128*MB)) { |
| 178 | start &= ~(128*MB - 1); |
| 179 | start += (128 + 16)*MB; |
| 180 | start = ALIGN(start, alignto); |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | |
Dominik Brodowski | b26b2d4 | 2010-01-01 17:40:49 +0100 | [diff] [blame] | 185 | return start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | } |
| 187 | #undef KB |
| 188 | #undef MB |
| 189 | #undef GB |
| 190 | |
| 191 | static int __init |
| 192 | pcibios_init(void) |
| 193 | { |
| 194 | if (alpha_mv.init_pci) |
| 195 | alpha_mv.init_pci(); |
| 196 | return 0; |
| 197 | } |
| 198 | |
| 199 | subsys_initcall(pcibios_init); |
| 200 | |
Al Viro | ed5f656 | 2007-07-26 17:34:19 +0100 | [diff] [blame] | 201 | char * __devinit |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | pcibios_setup(char *str) |
| 203 | { |
| 204 | return str; |
| 205 | } |
| 206 | |
| 207 | #ifdef ALPHA_RESTORE_SRM_SETUP |
| 208 | static struct pdev_srm_saved_conf *srm_saved_configs; |
| 209 | |
Al Viro | ed5f656 | 2007-07-26 17:34:19 +0100 | [diff] [blame] | 210 | void __devinit |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | pdev_save_srm_config(struct pci_dev *dev) |
| 212 | { |
| 213 | struct pdev_srm_saved_conf *tmp; |
| 214 | static int printed = 0; |
| 215 | |
Bjorn Helgaas | 151d16d | 2012-02-23 20:18:56 -0700 | [diff] [blame^] | 216 | if (!alpha_using_srm || pci_has_flag(PCI_PROBE_ONLY)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | return; |
| 218 | |
| 219 | if (!printed) { |
| 220 | printk(KERN_INFO "pci: enabling save/restore of SRM state\n"); |
| 221 | printed = 1; |
| 222 | } |
| 223 | |
| 224 | tmp = kmalloc(sizeof(*tmp), GFP_KERNEL); |
| 225 | if (!tmp) { |
Harvey Harrison | bbb8d34 | 2008-04-28 02:13:46 -0700 | [diff] [blame] | 226 | printk(KERN_ERR "%s: kmalloc() failed!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | return; |
| 228 | } |
| 229 | tmp->next = srm_saved_configs; |
| 230 | tmp->dev = dev; |
| 231 | |
| 232 | pci_save_state(dev); |
| 233 | |
| 234 | srm_saved_configs = tmp; |
| 235 | } |
| 236 | |
| 237 | void |
| 238 | pci_restore_srm_config(void) |
| 239 | { |
| 240 | struct pdev_srm_saved_conf *tmp; |
| 241 | |
| 242 | /* No need to restore if probed only. */ |
Bjorn Helgaas | 151d16d | 2012-02-23 20:18:56 -0700 | [diff] [blame^] | 243 | if (pci_has_flag(PCI_PROBE_ONLY)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | return; |
| 245 | |
| 246 | /* Restore SRM config. */ |
| 247 | for (tmp = srm_saved_configs; tmp; tmp = tmp->next) { |
| 248 | pci_restore_state(tmp->dev); |
| 249 | } |
| 250 | } |
| 251 | #endif |
| 252 | |
Al Viro | ed5f656 | 2007-07-26 17:34:19 +0100 | [diff] [blame] | 253 | void __devinit |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | pcibios_fixup_resource(struct resource *res, struct resource *root) |
| 255 | { |
| 256 | res->start += root->start; |
| 257 | res->end += root->start; |
| 258 | } |
| 259 | |
Al Viro | ed5f656 | 2007-07-26 17:34:19 +0100 | [diff] [blame] | 260 | void __devinit |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | pcibios_fixup_device_resources(struct pci_dev *dev, struct pci_bus *bus) |
| 262 | { |
| 263 | /* Update device resources. */ |
| 264 | struct pci_controller *hose = (struct pci_controller *)bus->sysdata; |
| 265 | int i; |
| 266 | |
| 267 | for (i = 0; i < PCI_NUM_RESOURCES; i++) { |
| 268 | if (!dev->resource[i].start) |
| 269 | continue; |
| 270 | if (dev->resource[i].flags & IORESOURCE_IO) |
| 271 | pcibios_fixup_resource(&dev->resource[i], |
| 272 | hose->io_space); |
| 273 | else if (dev->resource[i].flags & IORESOURCE_MEM) |
| 274 | pcibios_fixup_resource(&dev->resource[i], |
| 275 | hose->mem_space); |
| 276 | } |
| 277 | } |
| 278 | |
Al Viro | ed5f656 | 2007-07-26 17:34:19 +0100 | [diff] [blame] | 279 | void __devinit |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | pcibios_fixup_bus(struct pci_bus *bus) |
| 281 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | struct pci_dev *dev = bus->self; |
| 283 | |
Bjorn Helgaas | 151d16d | 2012-02-23 20:18:56 -0700 | [diff] [blame^] | 284 | if (pci_has_flag(PCI_PROBE_ONLY) && dev && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | (dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) { |
| 286 | pci_read_bridge_bases(bus); |
| 287 | pcibios_fixup_device_resources(dev, bus); |
| 288 | } |
| 289 | |
| 290 | list_for_each_entry(dev, &bus->devices, bus_list) { |
| 291 | pdev_save_srm_config(dev); |
| 292 | if ((dev->class >> 8) != PCI_CLASS_BRIDGE_PCI) |
| 293 | pcibios_fixup_device_resources(dev, bus); |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | void __init |
| 298 | pcibios_update_irq(struct pci_dev *dev, int irq) |
| 299 | { |
| 300 | pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq); |
| 301 | } |
| 302 | |
Al Viro | 4bcc17d | 2008-11-22 17:37:04 +0000 | [diff] [blame] | 303 | void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region, |
| 305 | struct resource *res) |
| 306 | { |
| 307 | struct pci_controller *hose = (struct pci_controller *)dev->sysdata; |
| 308 | unsigned long offset = 0; |
| 309 | |
| 310 | if (res->flags & IORESOURCE_IO) |
| 311 | offset = hose->io_space->start; |
| 312 | else if (res->flags & IORESOURCE_MEM) |
| 313 | offset = hose->mem_space->start; |
| 314 | |
| 315 | region->start = res->start - offset; |
| 316 | region->end = res->end - offset; |
| 317 | } |
| 318 | |
Dominik Brodowski | 43c3473 | 2005-08-04 18:06:21 -0700 | [diff] [blame] | 319 | void pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res, |
| 320 | struct pci_bus_region *region) |
| 321 | { |
| 322 | struct pci_controller *hose = (struct pci_controller *)dev->sysdata; |
| 323 | unsigned long offset = 0; |
| 324 | |
| 325 | if (res->flags & IORESOURCE_IO) |
| 326 | offset = hose->io_space->start; |
| 327 | else if (res->flags & IORESOURCE_MEM) |
| 328 | offset = hose->mem_space->start; |
| 329 | |
| 330 | res->start = region->start + offset; |
| 331 | res->end = region->end + offset; |
| 332 | } |
| 333 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | #ifdef CONFIG_HOTPLUG |
| 335 | EXPORT_SYMBOL(pcibios_resource_to_bus); |
Dominik Brodowski | 43c3473 | 2005-08-04 18:06:21 -0700 | [diff] [blame] | 336 | EXPORT_SYMBOL(pcibios_bus_to_resource); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | #endif |
| 338 | |
| 339 | int |
| 340 | pcibios_enable_device(struct pci_dev *dev, int mask) |
| 341 | { |
Bjorn Helgaas | 10f000a | 2008-03-04 11:56:48 -0700 | [diff] [blame] | 342 | return pci_enable_resources(dev, mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | /* |
| 346 | * If we set up a device for bus mastering, we need to check the latency |
| 347 | * timer as certain firmware forgets to set it properly, as seen |
| 348 | * on SX164 and LX164 with SRM. |
| 349 | */ |
| 350 | void |
| 351 | pcibios_set_master(struct pci_dev *dev) |
| 352 | { |
| 353 | u8 lat; |
| 354 | pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lat); |
| 355 | if (lat >= 16) return; |
| 356 | printk("PCI: Setting latency timer of device %s to 64\n", |
| 357 | pci_name(dev)); |
| 358 | pci_write_config_byte(dev, PCI_LATENCY_TIMER, 64); |
| 359 | } |
| 360 | |
Ivan Kokshaysky | 72cff12 | 2008-04-24 16:51:55 +0400 | [diff] [blame] | 361 | void __init |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | pcibios_claim_one_bus(struct pci_bus *b) |
| 363 | { |
| 364 | struct pci_dev *dev; |
| 365 | struct pci_bus *child_bus; |
| 366 | |
| 367 | list_for_each_entry(dev, &b->devices, bus_list) { |
| 368 | int i; |
| 369 | |
| 370 | for (i = 0; i < PCI_NUM_RESOURCES; i++) { |
| 371 | struct resource *r = &dev->resource[i]; |
| 372 | |
| 373 | if (r->parent || !r->start || !r->flags) |
| 374 | continue; |
Bjorn Helgaas | 151d16d | 2012-02-23 20:18:56 -0700 | [diff] [blame^] | 375 | if (pci_has_flag(PCI_PROBE_ONLY) || |
| 376 | (r->flags & IORESOURCE_PCI_FIXED)) |
Ivan Kokshaysky | 72cff12 | 2008-04-24 16:51:55 +0400 | [diff] [blame] | 377 | pci_claim_resource(dev, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | } |
| 379 | } |
| 380 | |
| 381 | list_for_each_entry(child_bus, &b->children, node) |
| 382 | pcibios_claim_one_bus(child_bus); |
| 383 | } |
| 384 | |
| 385 | static void __init |
| 386 | pcibios_claim_console_setup(void) |
| 387 | { |
| 388 | struct pci_bus *b; |
| 389 | |
| 390 | list_for_each_entry(b, &pci_root_buses, node) |
| 391 | pcibios_claim_one_bus(b); |
| 392 | } |
| 393 | |
| 394 | void __init |
| 395 | common_init_pci(void) |
| 396 | { |
| 397 | struct pci_controller *hose; |
Bjorn Helgaas | a2f33da | 2011-10-28 16:26:11 -0600 | [diff] [blame] | 398 | struct list_head resources; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | struct pci_bus *bus; |
| 400 | int next_busno; |
| 401 | int need_domain_info = 0; |
Bjorn Helgaas | a2f33da | 2011-10-28 16:26:11 -0600 | [diff] [blame] | 402 | u32 pci_mem_end; |
| 403 | u32 sg_base; |
| 404 | unsigned long end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | |
| 406 | /* Scan all of the recorded PCI controllers. */ |
| 407 | for (next_busno = 0, hose = hose_head; hose; hose = hose->next) { |
Bjorn Helgaas | a2f33da | 2011-10-28 16:26:11 -0600 | [diff] [blame] | 408 | sg_base = hose->sg_pci ? hose->sg_pci->dma_base : ~0; |
| 409 | |
| 410 | /* Adjust hose mem_space limit to prevent PCI allocations |
| 411 | in the iommu windows. */ |
| 412 | pci_mem_end = min((u32)__direct_map_base, sg_base) - 1; |
| 413 | end = hose->mem_space->start + pci_mem_end; |
| 414 | if (hose->mem_space->end > end) |
| 415 | hose->mem_space->end = end; |
| 416 | |
| 417 | INIT_LIST_HEAD(&resources); |
| 418 | pci_add_resource(&resources, hose->io_space); |
| 419 | pci_add_resource(&resources, hose->mem_space); |
| 420 | |
| 421 | bus = pci_scan_root_bus(NULL, next_busno, alpha_mv.pci_ops, |
| 422 | hose, &resources); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | hose->bus = bus; |
| 424 | hose->need_domain_info = need_domain_info; |
| 425 | next_busno = bus->subordinate + 1; |
| 426 | /* Don't allow 8-bit bus number overflow inside the hose - |
| 427 | reserve some space for bridges. */ |
| 428 | if (next_busno > 224) { |
| 429 | next_busno = 0; |
| 430 | need_domain_info = 1; |
| 431 | } |
| 432 | } |
| 433 | |
Ivan Kokshaysky | 72cff12 | 2008-04-24 16:51:55 +0400 | [diff] [blame] | 434 | pcibios_claim_console_setup(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | |
| 436 | pci_assign_unassigned_resources(); |
| 437 | pci_fixup_irqs(alpha_mv.pci_swizzle, alpha_mv.pci_map_irq); |
| 438 | } |
| 439 | |
| 440 | |
| 441 | struct pci_controller * __init |
| 442 | alloc_pci_controller(void) |
| 443 | { |
| 444 | struct pci_controller *hose; |
| 445 | |
| 446 | hose = alloc_bootmem(sizeof(*hose)); |
| 447 | |
| 448 | *hose_tail = hose; |
| 449 | hose_tail = &hose->next; |
| 450 | |
| 451 | return hose; |
| 452 | } |
| 453 | |
| 454 | struct resource * __init |
| 455 | alloc_resource(void) |
| 456 | { |
| 457 | struct resource *res; |
| 458 | |
| 459 | res = alloc_bootmem(sizeof(*res)); |
| 460 | |
| 461 | return res; |
| 462 | } |
| 463 | |
| 464 | |
| 465 | /* Provide information on locations of various I/O regions in physical |
| 466 | memory. Do this on a per-card basis so that we choose the right hose. */ |
| 467 | |
| 468 | asmlinkage long |
| 469 | sys_pciconfig_iobase(long which, unsigned long bus, unsigned long dfn) |
| 470 | { |
| 471 | struct pci_controller *hose; |
| 472 | struct pci_dev *dev; |
| 473 | |
| 474 | /* from hose or from bus.devfn */ |
| 475 | if (which & IOBASE_FROM_HOSE) { |
| 476 | for(hose = hose_head; hose; hose = hose->next) |
| 477 | if (hose->index == bus) break; |
| 478 | if (!hose) return -ENODEV; |
| 479 | } else { |
| 480 | /* Special hook for ISA access. */ |
| 481 | if (bus == 0 && dfn == 0) { |
| 482 | hose = pci_isa_hose; |
| 483 | } else { |
Alan Cox | 074cec5 | 2006-12-06 20:33:59 -0800 | [diff] [blame] | 484 | dev = pci_get_bus_and_slot(bus, dfn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | if (!dev) |
| 486 | return -ENODEV; |
| 487 | hose = dev->sysdata; |
Alan Cox | 074cec5 | 2006-12-06 20:33:59 -0800 | [diff] [blame] | 488 | pci_dev_put(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | } |
| 490 | } |
| 491 | |
| 492 | switch (which & ~IOBASE_FROM_HOSE) { |
| 493 | case IOBASE_HOSE: |
| 494 | return hose->index; |
| 495 | case IOBASE_SPARSE_MEM: |
| 496 | return hose->sparse_mem_base; |
| 497 | case IOBASE_DENSE_MEM: |
| 498 | return hose->dense_mem_base; |
| 499 | case IOBASE_SPARSE_IO: |
| 500 | return hose->sparse_io_base; |
| 501 | case IOBASE_DENSE_IO: |
| 502 | return hose->dense_io_base; |
| 503 | case IOBASE_ROOT_BUS: |
| 504 | return hose->bus->number; |
| 505 | } |
| 506 | |
| 507 | return -EOPNOTSUPP; |
| 508 | } |
| 509 | |
Michael S. Tsirkin | f2971c4 | 2011-11-24 20:48:56 +0200 | [diff] [blame] | 510 | /* Destroy an __iomem token. Not copied from lib/iomap.c. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | |
| 512 | void pci_iounmap(struct pci_dev *dev, void __iomem * addr) |
| 513 | { |
| 514 | if (__is_mmio(addr)) |
| 515 | iounmap(addr); |
| 516 | } |
| 517 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | EXPORT_SYMBOL(pci_iounmap); |
Adrian Bunk | 8255cf3 | 2007-01-06 21:48:41 +0100 | [diff] [blame] | 519 | |
| 520 | /* FIXME: Some boxes have multiple ISA bridges! */ |
| 521 | struct pci_dev *isa_bridge; |
| 522 | EXPORT_SYMBOL(isa_bridge); |