David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 1 | /* pci.c: UltraSparc PCI controller support. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
| 3 | * Copyright (C) 1997, 1998, 1999 David S. Miller (davem@redhat.com) |
| 4 | * Copyright (C) 1998, 1999 Eddie C. Dost (ecd@skynet.be) |
| 5 | * Copyright (C) 1999 Jakub Jelinek (jj@ultra.linux.cz) |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 6 | * |
| 7 | * OF tree based PCI bus probing taken from the PowerPC port |
| 8 | * with minor modifications, see there for credits. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/module.h> |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/string.h> |
| 14 | #include <linux/sched.h> |
| 15 | #include <linux/capability.h> |
| 16 | #include <linux/errno.h> |
David S. Miller | c57c2ff | 2007-05-08 00:43:56 -0700 | [diff] [blame] | 17 | #include <linux/pci.h> |
David S. Miller | 35a17eb | 2007-02-10 17:41:02 -0800 | [diff] [blame] | 18 | #include <linux/msi.h> |
| 19 | #include <linux/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/init.h> |
David S. Miller | 356d164 | 2008-08-30 00:36:11 -0700 | [diff] [blame] | 21 | #include <linux/of.h> |
| 22 | #include <linux/of_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
| 24 | #include <asm/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <asm/pgtable.h> |
| 26 | #include <asm/irq.h> |
David S. Miller | e87dc35 | 2006-06-21 18:18:47 -0700 | [diff] [blame] | 27 | #include <asm/prom.h> |
David S. Miller | 01f94c4 | 2007-03-04 12:53:19 -0800 | [diff] [blame] | 28 | #include <asm/apb.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
David S. Miller | 1e8a8cc | 2007-02-28 23:38:38 -0800 | [diff] [blame] | 30 | #include "pci_impl.h" |
| 31 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | /* List of all PCI controllers found in the system. */ |
David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 33 | struct pci_pbm_info *pci_pbm_root = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 35 | /* Each PBM found gets a unique index. */ |
| 36 | int pci_num_pbms = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | volatile int pci_poke_in_progress; |
| 39 | volatile int pci_poke_cpu = -1; |
| 40 | volatile int pci_poke_faulted; |
| 41 | |
| 42 | static DEFINE_SPINLOCK(pci_poke_lock); |
| 43 | |
| 44 | void pci_config_read8(u8 *addr, u8 *ret) |
| 45 | { |
| 46 | unsigned long flags; |
| 47 | u8 byte; |
| 48 | |
| 49 | spin_lock_irqsave(&pci_poke_lock, flags); |
| 50 | pci_poke_cpu = smp_processor_id(); |
| 51 | pci_poke_in_progress = 1; |
| 52 | pci_poke_faulted = 0; |
| 53 | __asm__ __volatile__("membar #Sync\n\t" |
| 54 | "lduba [%1] %2, %0\n\t" |
| 55 | "membar #Sync" |
| 56 | : "=r" (byte) |
| 57 | : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L) |
| 58 | : "memory"); |
| 59 | pci_poke_in_progress = 0; |
| 60 | pci_poke_cpu = -1; |
| 61 | if (!pci_poke_faulted) |
| 62 | *ret = byte; |
| 63 | spin_unlock_irqrestore(&pci_poke_lock, flags); |
| 64 | } |
| 65 | |
| 66 | void pci_config_read16(u16 *addr, u16 *ret) |
| 67 | { |
| 68 | unsigned long flags; |
| 69 | u16 word; |
| 70 | |
| 71 | spin_lock_irqsave(&pci_poke_lock, flags); |
| 72 | pci_poke_cpu = smp_processor_id(); |
| 73 | pci_poke_in_progress = 1; |
| 74 | pci_poke_faulted = 0; |
| 75 | __asm__ __volatile__("membar #Sync\n\t" |
| 76 | "lduha [%1] %2, %0\n\t" |
| 77 | "membar #Sync" |
| 78 | : "=r" (word) |
| 79 | : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L) |
| 80 | : "memory"); |
| 81 | pci_poke_in_progress = 0; |
| 82 | pci_poke_cpu = -1; |
| 83 | if (!pci_poke_faulted) |
| 84 | *ret = word; |
| 85 | spin_unlock_irqrestore(&pci_poke_lock, flags); |
| 86 | } |
| 87 | |
| 88 | void pci_config_read32(u32 *addr, u32 *ret) |
| 89 | { |
| 90 | unsigned long flags; |
| 91 | u32 dword; |
| 92 | |
| 93 | spin_lock_irqsave(&pci_poke_lock, flags); |
| 94 | pci_poke_cpu = smp_processor_id(); |
| 95 | pci_poke_in_progress = 1; |
| 96 | pci_poke_faulted = 0; |
| 97 | __asm__ __volatile__("membar #Sync\n\t" |
| 98 | "lduwa [%1] %2, %0\n\t" |
| 99 | "membar #Sync" |
| 100 | : "=r" (dword) |
| 101 | : "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L) |
| 102 | : "memory"); |
| 103 | pci_poke_in_progress = 0; |
| 104 | pci_poke_cpu = -1; |
| 105 | if (!pci_poke_faulted) |
| 106 | *ret = dword; |
| 107 | spin_unlock_irqrestore(&pci_poke_lock, flags); |
| 108 | } |
| 109 | |
| 110 | void pci_config_write8(u8 *addr, u8 val) |
| 111 | { |
| 112 | unsigned long flags; |
| 113 | |
| 114 | spin_lock_irqsave(&pci_poke_lock, flags); |
| 115 | pci_poke_cpu = smp_processor_id(); |
| 116 | pci_poke_in_progress = 1; |
| 117 | pci_poke_faulted = 0; |
| 118 | __asm__ __volatile__("membar #Sync\n\t" |
| 119 | "stba %0, [%1] %2\n\t" |
| 120 | "membar #Sync" |
| 121 | : /* no outputs */ |
| 122 | : "r" (val), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L) |
| 123 | : "memory"); |
| 124 | pci_poke_in_progress = 0; |
| 125 | pci_poke_cpu = -1; |
| 126 | spin_unlock_irqrestore(&pci_poke_lock, flags); |
| 127 | } |
| 128 | |
| 129 | void pci_config_write16(u16 *addr, u16 val) |
| 130 | { |
| 131 | unsigned long flags; |
| 132 | |
| 133 | spin_lock_irqsave(&pci_poke_lock, flags); |
| 134 | pci_poke_cpu = smp_processor_id(); |
| 135 | pci_poke_in_progress = 1; |
| 136 | pci_poke_faulted = 0; |
| 137 | __asm__ __volatile__("membar #Sync\n\t" |
| 138 | "stha %0, [%1] %2\n\t" |
| 139 | "membar #Sync" |
| 140 | : /* no outputs */ |
| 141 | : "r" (val), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L) |
| 142 | : "memory"); |
| 143 | pci_poke_in_progress = 0; |
| 144 | pci_poke_cpu = -1; |
| 145 | spin_unlock_irqrestore(&pci_poke_lock, flags); |
| 146 | } |
| 147 | |
| 148 | void pci_config_write32(u32 *addr, u32 val) |
| 149 | { |
| 150 | unsigned long flags; |
| 151 | |
| 152 | spin_lock_irqsave(&pci_poke_lock, flags); |
| 153 | pci_poke_cpu = smp_processor_id(); |
| 154 | pci_poke_in_progress = 1; |
| 155 | pci_poke_faulted = 0; |
| 156 | __asm__ __volatile__("membar #Sync\n\t" |
| 157 | "stwa %0, [%1] %2\n\t" |
| 158 | "membar #Sync" |
| 159 | : /* no outputs */ |
| 160 | : "r" (val), "r" (addr), "i" (ASI_PHYS_BYPASS_EC_E_L) |
| 161 | : "memory"); |
| 162 | pci_poke_in_progress = 0; |
| 163 | pci_poke_cpu = -1; |
| 164 | spin_unlock_irqrestore(&pci_poke_lock, flags); |
| 165 | } |
| 166 | |
| 167 | /* Probe for all PCI controllers in the system. */ |
David S. Miller | e87dc35 | 2006-06-21 18:18:47 -0700 | [diff] [blame] | 168 | extern void sabre_init(struct device_node *, const char *); |
| 169 | extern void psycho_init(struct device_node *, const char *); |
David S. Miller | e87dc35 | 2006-06-21 18:18:47 -0700 | [diff] [blame] | 170 | extern void sun4v_pci_init(struct device_node *, const char *); |
David S. Miller | 861fe90 | 2007-05-02 17:31:36 -0700 | [diff] [blame] | 171 | extern void fire_pci_init(struct device_node *, const char *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
| 173 | static struct { |
| 174 | char *model_name; |
David S. Miller | e87dc35 | 2006-06-21 18:18:47 -0700 | [diff] [blame] | 175 | void (*init)(struct device_node *, const char *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | } pci_controller_table[] __initdata = { |
| 177 | { "SUNW,sabre", sabre_init }, |
| 178 | { "pci108e,a000", sabre_init }, |
| 179 | { "pci108e,a001", sabre_init }, |
| 180 | { "SUNW,psycho", psycho_init }, |
| 181 | { "pci108e,8000", psycho_init }, |
David S. Miller | 8f6a93a | 2006-02-09 21:32:07 -0800 | [diff] [blame] | 182 | { "SUNW,sun4v-pci", sun4v_pci_init }, |
David S. Miller | 861fe90 | 2007-05-02 17:31:36 -0700 | [diff] [blame] | 183 | { "pciex108e,80f0", fire_pci_init }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | }; |
Alejandro Martinez Ruiz | 29f139c | 2007-10-22 17:24:19 -0700 | [diff] [blame] | 185 | #define PCI_NUM_CONTROLLER_TYPES ARRAY_SIZE(pci_controller_table) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | |
David S. Miller | e87dc35 | 2006-06-21 18:18:47 -0700 | [diff] [blame] | 187 | static int __init pci_controller_init(const char *model_name, int namelen, struct device_node *dp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | { |
| 189 | int i; |
| 190 | |
| 191 | for (i = 0; i < PCI_NUM_CONTROLLER_TYPES; i++) { |
| 192 | if (!strncmp(model_name, |
| 193 | pci_controller_table[i].model_name, |
| 194 | namelen)) { |
David S. Miller | e87dc35 | 2006-06-21 18:18:47 -0700 | [diff] [blame] | 195 | pci_controller_table[i].init(dp, model_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | return 1; |
| 197 | } |
| 198 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
| 200 | return 0; |
| 201 | } |
| 202 | |
David S. Miller | e87dc35 | 2006-06-21 18:18:47 -0700 | [diff] [blame] | 203 | static int __init pci_controller_scan(int (*handler)(const char *, int, struct device_node *)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | { |
David S. Miller | e87dc35 | 2006-06-21 18:18:47 -0700 | [diff] [blame] | 205 | struct device_node *dp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | int count = 0; |
| 207 | |
David S. Miller | e87dc35 | 2006-06-21 18:18:47 -0700 | [diff] [blame] | 208 | for_each_node_by_name(dp, "pci") { |
| 209 | struct property *prop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | int len; |
| 211 | |
David S. Miller | e87dc35 | 2006-06-21 18:18:47 -0700 | [diff] [blame] | 212 | prop = of_find_property(dp, "model", &len); |
| 213 | if (!prop) |
| 214 | prop = of_find_property(dp, "compatible", &len); |
| 215 | |
| 216 | if (prop) { |
| 217 | const char *model = prop->value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | int item_len = 0; |
| 219 | |
| 220 | /* Our value may be a multi-valued string in the |
| 221 | * case of some compatible properties. For sanity, |
David S. Miller | e87dc35 | 2006-06-21 18:18:47 -0700 | [diff] [blame] | 222 | * only try the first one. |
| 223 | */ |
| 224 | while (model[item_len] && len) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | len--; |
| 226 | item_len++; |
| 227 | } |
| 228 | |
David S. Miller | e87dc35 | 2006-06-21 18:18:47 -0700 | [diff] [blame] | 229 | if (handler(model, item_len, dp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | count++; |
| 231 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | return count; |
| 235 | } |
| 236 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | /* Find each controller in the system, attach and initialize |
| 238 | * software state structure for each and link into the |
David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 239 | * pci_pbm_root. Setup the controller enough such |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | * that bus scanning can be done. |
| 241 | */ |
| 242 | static void __init pci_controller_probe(void) |
| 243 | { |
| 244 | printk("PCI: Probing for controllers.\n"); |
| 245 | |
| 246 | pci_controller_scan(pci_controller_init); |
| 247 | } |
| 248 | |
David S. Miller | 5840fc6 | 2007-05-22 01:24:14 -0700 | [diff] [blame] | 249 | static int ofpci_verbose; |
| 250 | |
| 251 | static int __init ofpci_debug(char *str) |
| 252 | { |
| 253 | int val = 0; |
| 254 | |
| 255 | get_option(&str, &val); |
| 256 | if (val) |
| 257 | ofpci_verbose = 1; |
| 258 | return 1; |
| 259 | } |
| 260 | |
| 261 | __setup("ofpci_debug=", ofpci_debug); |
| 262 | |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 263 | static unsigned long pci_parse_of_flags(u32 addr0) |
| 264 | { |
| 265 | unsigned long flags = 0; |
| 266 | |
| 267 | if (addr0 & 0x02000000) { |
| 268 | flags = IORESOURCE_MEM | PCI_BASE_ADDRESS_SPACE_MEMORY; |
| 269 | flags |= (addr0 >> 22) & PCI_BASE_ADDRESS_MEM_TYPE_64; |
| 270 | flags |= (addr0 >> 28) & PCI_BASE_ADDRESS_MEM_TYPE_1M; |
| 271 | if (addr0 & 0x40000000) |
| 272 | flags |= IORESOURCE_PREFETCH |
| 273 | | PCI_BASE_ADDRESS_MEM_PREFETCH; |
| 274 | } else if (addr0 & 0x01000000) |
| 275 | flags = IORESOURCE_IO | PCI_BASE_ADDRESS_SPACE_IO; |
| 276 | return flags; |
| 277 | } |
| 278 | |
| 279 | /* The of_device layer has translated all of the assigned-address properties |
| 280 | * into physical address resources, we only have to figure out the register |
| 281 | * mapping. |
| 282 | */ |
| 283 | static void pci_parse_of_addrs(struct of_device *op, |
| 284 | struct device_node *node, |
| 285 | struct pci_dev *dev) |
| 286 | { |
| 287 | struct resource *op_res; |
| 288 | const u32 *addrs; |
| 289 | int proplen; |
| 290 | |
| 291 | addrs = of_get_property(node, "assigned-addresses", &proplen); |
| 292 | if (!addrs) |
| 293 | return; |
David S. Miller | 5840fc6 | 2007-05-22 01:24:14 -0700 | [diff] [blame] | 294 | if (ofpci_verbose) |
| 295 | printk(" parse addresses (%d bytes) @ %p\n", |
| 296 | proplen, addrs); |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 297 | op_res = &op->resource[0]; |
| 298 | for (; proplen >= 20; proplen -= 20, addrs += 5, op_res++) { |
| 299 | struct resource *res; |
| 300 | unsigned long flags; |
| 301 | int i; |
| 302 | |
| 303 | flags = pci_parse_of_flags(addrs[0]); |
| 304 | if (!flags) |
| 305 | continue; |
| 306 | i = addrs[0] & 0xff; |
David S. Miller | 5840fc6 | 2007-05-22 01:24:14 -0700 | [diff] [blame] | 307 | if (ofpci_verbose) |
| 308 | printk(" start: %lx, end: %lx, i: %x\n", |
| 309 | op_res->start, op_res->end, i); |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 310 | |
| 311 | if (PCI_BASE_ADDRESS_0 <= i && i <= PCI_BASE_ADDRESS_5) { |
| 312 | res = &dev->resource[(i - PCI_BASE_ADDRESS_0) >> 2]; |
| 313 | } else if (i == dev->rom_base_reg) { |
| 314 | res = &dev->resource[PCI_ROM_RESOURCE]; |
| 315 | flags |= IORESOURCE_READONLY | IORESOURCE_CACHEABLE; |
| 316 | } else { |
| 317 | printk(KERN_ERR "PCI: bad cfg reg num 0x%x\n", i); |
| 318 | continue; |
| 319 | } |
| 320 | res->start = op_res->start; |
| 321 | res->end = op_res->end; |
| 322 | res->flags = flags; |
| 323 | res->name = pci_name(dev); |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm, |
| 328 | struct device_node *node, |
David S. Miller | c26d3c0 | 2008-05-01 01:12:40 -0700 | [diff] [blame] | 329 | struct pci_bus *bus, int devfn) |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 330 | { |
| 331 | struct dev_archdata *sd; |
David S. Miller | ae05f87 | 2008-08-29 22:42:34 -0700 | [diff] [blame] | 332 | struct of_device *op; |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 333 | struct pci_dev *dev; |
| 334 | const char *type; |
David S. Miller | 01f94c4 | 2007-03-04 12:53:19 -0800 | [diff] [blame] | 335 | u32 class; |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 336 | |
David S. Miller | 26e6385 | 2007-05-10 02:16:27 -0700 | [diff] [blame] | 337 | dev = alloc_pci_dev(); |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 338 | if (!dev) |
| 339 | return NULL; |
| 340 | |
| 341 | sd = &dev->dev.archdata; |
| 342 | sd->iommu = pbm->iommu; |
| 343 | sd->stc = &pbm->stc; |
| 344 | sd->host_controller = pbm; |
| 345 | sd->prom_node = node; |
David S. Miller | ae05f87 | 2008-08-29 22:42:34 -0700 | [diff] [blame] | 346 | sd->op = op = of_find_device_by_node(node); |
David S. Miller | c1b1a5f | 2008-03-19 04:52:48 -0700 | [diff] [blame] | 347 | sd->numa_node = pbm->numa_node; |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 348 | |
David S. Miller | ae05f87 | 2008-08-29 22:42:34 -0700 | [diff] [blame] | 349 | sd = &op->dev.archdata; |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 350 | sd->iommu = pbm->iommu; |
| 351 | sd->stc = &pbm->stc; |
David S. Miller | c1b1a5f | 2008-03-19 04:52:48 -0700 | [diff] [blame] | 352 | sd->numa_node = pbm->numa_node; |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 353 | |
David S. Miller | ae05f87 | 2008-08-29 22:42:34 -0700 | [diff] [blame] | 354 | if (!strcmp(node->name, "ebus")) |
| 355 | of_propagate_archdata(op); |
| 356 | |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 357 | type = of_get_property(node, "device_type", NULL); |
| 358 | if (type == NULL) |
| 359 | type = ""; |
| 360 | |
David S. Miller | 5840fc6 | 2007-05-22 01:24:14 -0700 | [diff] [blame] | 361 | if (ofpci_verbose) |
| 362 | printk(" create device, devfn: %x, type: %s\n", |
| 363 | devfn, type); |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 364 | |
| 365 | dev->bus = bus; |
| 366 | dev->sysdata = node; |
| 367 | dev->dev.parent = bus->bridge; |
| 368 | dev->dev.bus = &pci_bus_type; |
| 369 | dev->devfn = devfn; |
| 370 | dev->multifunction = 0; /* maybe a lie? */ |
| 371 | |
David S. Miller | c26d3c0 | 2008-05-01 01:12:40 -0700 | [diff] [blame] | 372 | dev->vendor = of_getintprop_default(node, "vendor-id", 0xffff); |
| 373 | dev->device = of_getintprop_default(node, "device-id", 0xffff); |
| 374 | dev->subsystem_vendor = |
| 375 | of_getintprop_default(node, "subsystem-vendor-id", 0); |
| 376 | dev->subsystem_device = |
| 377 | of_getintprop_default(node, "subsystem-id", 0); |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 378 | |
David S. Miller | c26d3c0 | 2008-05-01 01:12:40 -0700 | [diff] [blame] | 379 | dev->cfg_size = pci_cfg_space_size(dev); |
David S. Miller | 01f94c4 | 2007-03-04 12:53:19 -0800 | [diff] [blame] | 380 | |
David S. Miller | c26d3c0 | 2008-05-01 01:12:40 -0700 | [diff] [blame] | 381 | /* We can't actually use the firmware value, we have |
| 382 | * to read what is in the register right now. One |
| 383 | * reason is that in the case of IDE interfaces the |
| 384 | * firmware can sample the value before the the IDE |
| 385 | * interface is programmed into native mode. |
| 386 | */ |
| 387 | pci_read_config_dword(dev, PCI_CLASS_REVISION, &class); |
| 388 | dev->class = class >> 8; |
| 389 | dev->revision = class & 0xff; |
David S. Miller | 28f57e7 | 2007-03-12 19:40:26 -0700 | [diff] [blame] | 390 | |
Greg Kroah-Hartman | 2222c31 | 2008-05-02 06:02:41 +0200 | [diff] [blame] | 391 | dev_set_name(&dev->dev, "%04x:%02x:%02x.%d", pci_domain_nr(bus), |
David S. Miller | c26d3c0 | 2008-05-01 01:12:40 -0700 | [diff] [blame] | 392 | dev->bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn)); |
| 393 | |
David S. Miller | 5840fc6 | 2007-05-22 01:24:14 -0700 | [diff] [blame] | 394 | if (ofpci_verbose) |
| 395 | printk(" class: 0x%x device name: %s\n", |
| 396 | dev->class, pci_name(dev)); |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 397 | |
David S. Miller | 861fe90 | 2007-05-02 17:31:36 -0700 | [diff] [blame] | 398 | /* I have seen IDE devices which will not respond to |
| 399 | * the bmdma simplex check reads if bus mastering is |
| 400 | * disabled. |
| 401 | */ |
| 402 | if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE) |
| 403 | pci_set_master(dev); |
| 404 | |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 405 | dev->current_state = 4; /* unknown power state */ |
| 406 | dev->error_state = pci_channel_io_normal; |
| 407 | |
David S. Miller | c26d3c0 | 2008-05-01 01:12:40 -0700 | [diff] [blame] | 408 | if (!strcmp(type, "pci") || !strcmp(type, "pciex")) { |
| 409 | /* a PCI-PCI bridge */ |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 410 | dev->hdr_type = PCI_HEADER_TYPE_BRIDGE; |
| 411 | dev->rom_base_reg = PCI_ROM_ADDRESS1; |
David S. Miller | c26d3c0 | 2008-05-01 01:12:40 -0700 | [diff] [blame] | 412 | } else if (!strcmp(type, "cardbus")) { |
| 413 | dev->hdr_type = PCI_HEADER_TYPE_CARDBUS; |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 414 | } else { |
David S. Miller | c26d3c0 | 2008-05-01 01:12:40 -0700 | [diff] [blame] | 415 | dev->hdr_type = PCI_HEADER_TYPE_NORMAL; |
| 416 | dev->rom_base_reg = PCI_ROM_ADDRESS; |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 417 | |
David S. Miller | c26d3c0 | 2008-05-01 01:12:40 -0700 | [diff] [blame] | 418 | dev->irq = sd->op->irqs[0]; |
| 419 | if (dev->irq == 0xffffffff) |
| 420 | dev->irq = PCI_IRQ_NONE; |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 421 | } |
David S. Miller | c26d3c0 | 2008-05-01 01:12:40 -0700 | [diff] [blame] | 422 | |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 423 | pci_parse_of_addrs(sd->op, node, dev); |
| 424 | |
David S. Miller | 5840fc6 | 2007-05-22 01:24:14 -0700 | [diff] [blame] | 425 | if (ofpci_verbose) |
| 426 | printk(" adding to system ...\n"); |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 427 | |
| 428 | pci_device_add(dev, bus); |
| 429 | |
| 430 | return dev; |
| 431 | } |
| 432 | |
David S. Miller | a6009dd | 2007-05-07 00:01:38 -0700 | [diff] [blame] | 433 | static void __devinit apb_calc_first_last(u8 map, u32 *first_p, u32 *last_p) |
David S. Miller | 01f94c4 | 2007-03-04 12:53:19 -0800 | [diff] [blame] | 434 | { |
| 435 | u32 idx, first, last; |
| 436 | |
| 437 | first = 8; |
| 438 | last = 0; |
| 439 | for (idx = 0; idx < 8; idx++) { |
| 440 | if ((map & (1 << idx)) != 0) { |
| 441 | if (first > idx) |
| 442 | first = idx; |
| 443 | if (last < idx) |
| 444 | last = idx; |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | *first_p = first; |
| 449 | *last_p = last; |
| 450 | } |
| 451 | |
David S. Miller | f16537b | 2007-05-11 14:29:43 -0700 | [diff] [blame] | 452 | static void pci_resource_adjust(struct resource *res, |
| 453 | struct resource *root) |
David S. Miller | 0bae5f8 | 2007-03-08 22:42:19 -0800 | [diff] [blame] | 454 | { |
| 455 | res->start += root->start; |
| 456 | res->end += root->start; |
| 457 | } |
| 458 | |
David S. Miller | 8c2786c | 2007-06-07 21:59:44 -0700 | [diff] [blame] | 459 | /* For PCI bus devices which lack a 'ranges' property we interrogate |
| 460 | * the config space values to set the resources, just like the generic |
| 461 | * Linux PCI probing code does. |
| 462 | */ |
| 463 | static void __devinit pci_cfg_fake_ranges(struct pci_dev *dev, |
| 464 | struct pci_bus *bus, |
| 465 | struct pci_pbm_info *pbm) |
| 466 | { |
| 467 | struct resource *res; |
| 468 | u8 io_base_lo, io_limit_lo; |
| 469 | u16 mem_base_lo, mem_limit_lo; |
| 470 | unsigned long base, limit; |
| 471 | |
| 472 | pci_read_config_byte(dev, PCI_IO_BASE, &io_base_lo); |
| 473 | pci_read_config_byte(dev, PCI_IO_LIMIT, &io_limit_lo); |
| 474 | base = (io_base_lo & PCI_IO_RANGE_MASK) << 8; |
| 475 | limit = (io_limit_lo & PCI_IO_RANGE_MASK) << 8; |
| 476 | |
| 477 | if ((io_base_lo & PCI_IO_RANGE_TYPE_MASK) == PCI_IO_RANGE_TYPE_32) { |
| 478 | u16 io_base_hi, io_limit_hi; |
| 479 | |
| 480 | pci_read_config_word(dev, PCI_IO_BASE_UPPER16, &io_base_hi); |
| 481 | pci_read_config_word(dev, PCI_IO_LIMIT_UPPER16, &io_limit_hi); |
| 482 | base |= (io_base_hi << 16); |
| 483 | limit |= (io_limit_hi << 16); |
| 484 | } |
| 485 | |
| 486 | res = bus->resource[0]; |
| 487 | if (base <= limit) { |
| 488 | res->flags = (io_base_lo & PCI_IO_RANGE_TYPE_MASK) | IORESOURCE_IO; |
| 489 | if (!res->start) |
| 490 | res->start = base; |
| 491 | if (!res->end) |
| 492 | res->end = limit + 0xfff; |
| 493 | pci_resource_adjust(res, &pbm->io_space); |
| 494 | } |
| 495 | |
| 496 | pci_read_config_word(dev, PCI_MEMORY_BASE, &mem_base_lo); |
| 497 | pci_read_config_word(dev, PCI_MEMORY_LIMIT, &mem_limit_lo); |
| 498 | base = (mem_base_lo & PCI_MEMORY_RANGE_MASK) << 16; |
| 499 | limit = (mem_limit_lo & PCI_MEMORY_RANGE_MASK) << 16; |
| 500 | |
| 501 | res = bus->resource[1]; |
| 502 | if (base <= limit) { |
| 503 | res->flags = ((mem_base_lo & PCI_MEMORY_RANGE_TYPE_MASK) | |
| 504 | IORESOURCE_MEM); |
| 505 | res->start = base; |
| 506 | res->end = limit + 0xfffff; |
| 507 | pci_resource_adjust(res, &pbm->mem_space); |
| 508 | } |
| 509 | |
| 510 | pci_read_config_word(dev, PCI_PREF_MEMORY_BASE, &mem_base_lo); |
| 511 | pci_read_config_word(dev, PCI_PREF_MEMORY_LIMIT, &mem_limit_lo); |
| 512 | base = (mem_base_lo & PCI_PREF_RANGE_MASK) << 16; |
| 513 | limit = (mem_limit_lo & PCI_PREF_RANGE_MASK) << 16; |
| 514 | |
| 515 | if ((mem_base_lo & PCI_PREF_RANGE_TYPE_MASK) == PCI_PREF_RANGE_TYPE_64) { |
| 516 | u32 mem_base_hi, mem_limit_hi; |
| 517 | |
| 518 | pci_read_config_dword(dev, PCI_PREF_BASE_UPPER32, &mem_base_hi); |
| 519 | pci_read_config_dword(dev, PCI_PREF_LIMIT_UPPER32, &mem_limit_hi); |
| 520 | |
| 521 | /* |
| 522 | * Some bridges set the base > limit by default, and some |
| 523 | * (broken) BIOSes do not initialize them. If we find |
| 524 | * this, just assume they are not being used. |
| 525 | */ |
| 526 | if (mem_base_hi <= mem_limit_hi) { |
| 527 | base |= ((long) mem_base_hi) << 32; |
| 528 | limit |= ((long) mem_limit_hi) << 32; |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | res = bus->resource[2]; |
| 533 | if (base <= limit) { |
| 534 | res->flags = ((mem_base_lo & PCI_MEMORY_RANGE_TYPE_MASK) | |
| 535 | IORESOURCE_MEM | IORESOURCE_PREFETCH); |
| 536 | res->start = base; |
| 537 | res->end = limit + 0xfffff; |
| 538 | pci_resource_adjust(res, &pbm->mem_space); |
| 539 | } |
| 540 | } |
| 541 | |
David S. Miller | 01f94c4 | 2007-03-04 12:53:19 -0800 | [diff] [blame] | 542 | /* Cook up fake bus resources for SUNW,simba PCI bridges which lack |
| 543 | * a proper 'ranges' property. |
| 544 | */ |
David S. Miller | a6009dd | 2007-05-07 00:01:38 -0700 | [diff] [blame] | 545 | static void __devinit apb_fake_ranges(struct pci_dev *dev, |
| 546 | struct pci_bus *bus, |
| 547 | struct pci_pbm_info *pbm) |
David S. Miller | 01f94c4 | 2007-03-04 12:53:19 -0800 | [diff] [blame] | 548 | { |
| 549 | struct resource *res; |
| 550 | u32 first, last; |
| 551 | u8 map; |
| 552 | |
| 553 | pci_read_config_byte(dev, APB_IO_ADDRESS_MAP, &map); |
| 554 | apb_calc_first_last(map, &first, &last); |
| 555 | res = bus->resource[0]; |
| 556 | res->start = (first << 21); |
| 557 | res->end = (last << 21) + ((1 << 21) - 1); |
| 558 | res->flags = IORESOURCE_IO; |
David S. Miller | 0bae5f8 | 2007-03-08 22:42:19 -0800 | [diff] [blame] | 559 | pci_resource_adjust(res, &pbm->io_space); |
David S. Miller | 01f94c4 | 2007-03-04 12:53:19 -0800 | [diff] [blame] | 560 | |
| 561 | pci_read_config_byte(dev, APB_MEM_ADDRESS_MAP, &map); |
| 562 | apb_calc_first_last(map, &first, &last); |
| 563 | res = bus->resource[1]; |
| 564 | res->start = (first << 21); |
| 565 | res->end = (last << 21) + ((1 << 21) - 1); |
| 566 | res->flags = IORESOURCE_MEM; |
David S. Miller | 0bae5f8 | 2007-03-08 22:42:19 -0800 | [diff] [blame] | 567 | pci_resource_adjust(res, &pbm->mem_space); |
David S. Miller | 01f94c4 | 2007-03-04 12:53:19 -0800 | [diff] [blame] | 568 | } |
| 569 | |
David S. Miller | a6009dd | 2007-05-07 00:01:38 -0700 | [diff] [blame] | 570 | static void __devinit pci_of_scan_bus(struct pci_pbm_info *pbm, |
| 571 | struct device_node *node, |
| 572 | struct pci_bus *bus); |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 573 | |
| 574 | #define GET_64BIT(prop, i) ((((u64) (prop)[(i)]) << 32) | (prop)[(i)+1]) |
| 575 | |
David S. Miller | a6009dd | 2007-05-07 00:01:38 -0700 | [diff] [blame] | 576 | static void __devinit of_scan_pci_bridge(struct pci_pbm_info *pbm, |
| 577 | struct device_node *node, |
| 578 | struct pci_dev *dev) |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 579 | { |
| 580 | struct pci_bus *bus; |
| 581 | const u32 *busrange, *ranges; |
David S. Miller | 01f94c4 | 2007-03-04 12:53:19 -0800 | [diff] [blame] | 582 | int len, i, simba; |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 583 | struct resource *res; |
| 584 | unsigned int flags; |
| 585 | u64 size; |
| 586 | |
David S. Miller | 5840fc6 | 2007-05-22 01:24:14 -0700 | [diff] [blame] | 587 | if (ofpci_verbose) |
| 588 | printk("of_scan_pci_bridge(%s)\n", node->full_name); |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 589 | |
| 590 | /* parse bus-range property */ |
| 591 | busrange = of_get_property(node, "bus-range", &len); |
| 592 | if (busrange == NULL || len != 8) { |
| 593 | printk(KERN_DEBUG "Can't get bus-range for PCI-PCI bridge %s\n", |
| 594 | node->full_name); |
| 595 | return; |
| 596 | } |
| 597 | ranges = of_get_property(node, "ranges", &len); |
David S. Miller | 01f94c4 | 2007-03-04 12:53:19 -0800 | [diff] [blame] | 598 | simba = 0; |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 599 | if (ranges == NULL) { |
David S. Miller | a165b42 | 2007-03-29 01:50:16 -0700 | [diff] [blame] | 600 | const char *model = of_get_property(node, "model", NULL); |
David S. Miller | 8c2786c | 2007-06-07 21:59:44 -0700 | [diff] [blame] | 601 | if (model && !strcmp(model, "SUNW,simba")) |
David S. Miller | 01f94c4 | 2007-03-04 12:53:19 -0800 | [diff] [blame] | 602 | simba = 1; |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | bus = pci_add_new_bus(dev->bus, dev, busrange[0]); |
| 606 | if (!bus) { |
| 607 | printk(KERN_ERR "Failed to create pci bus for %s\n", |
| 608 | node->full_name); |
| 609 | return; |
| 610 | } |
| 611 | |
| 612 | bus->primary = dev->bus->number; |
| 613 | bus->subordinate = busrange[1]; |
| 614 | bus->bridge_ctl = 0; |
| 615 | |
David S. Miller | 01f94c4 | 2007-03-04 12:53:19 -0800 | [diff] [blame] | 616 | /* parse ranges property, or cook one up by hand for Simba */ |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 617 | /* PCI #address-cells == 3 and #size-cells == 2 always */ |
| 618 | res = &dev->resource[PCI_BRIDGE_RESOURCES]; |
| 619 | for (i = 0; i < PCI_NUM_RESOURCES - PCI_BRIDGE_RESOURCES; ++i) { |
| 620 | res->flags = 0; |
| 621 | bus->resource[i] = res; |
| 622 | ++res; |
| 623 | } |
David S. Miller | 01f94c4 | 2007-03-04 12:53:19 -0800 | [diff] [blame] | 624 | if (simba) { |
| 625 | apb_fake_ranges(dev, bus, pbm); |
David S. Miller | 8c2786c | 2007-06-07 21:59:44 -0700 | [diff] [blame] | 626 | goto after_ranges; |
| 627 | } else if (ranges == NULL) { |
| 628 | pci_cfg_fake_ranges(dev, bus, pbm); |
| 629 | goto after_ranges; |
David S. Miller | 01f94c4 | 2007-03-04 12:53:19 -0800 | [diff] [blame] | 630 | } |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 631 | i = 1; |
| 632 | for (; len >= 32; len -= 32, ranges += 8) { |
| 633 | struct resource *root; |
| 634 | |
| 635 | flags = pci_parse_of_flags(ranges[0]); |
| 636 | size = GET_64BIT(ranges, 6); |
| 637 | if (flags == 0 || size == 0) |
| 638 | continue; |
| 639 | if (flags & IORESOURCE_IO) { |
| 640 | res = bus->resource[0]; |
| 641 | if (res->flags) { |
| 642 | printk(KERN_ERR "PCI: ignoring extra I/O range" |
| 643 | " for bridge %s\n", node->full_name); |
| 644 | continue; |
| 645 | } |
| 646 | root = &pbm->io_space; |
| 647 | } else { |
| 648 | if (i >= PCI_NUM_RESOURCES - PCI_BRIDGE_RESOURCES) { |
| 649 | printk(KERN_ERR "PCI: too many memory ranges" |
| 650 | " for bridge %s\n", node->full_name); |
| 651 | continue; |
| 652 | } |
| 653 | res = bus->resource[i]; |
| 654 | ++i; |
| 655 | root = &pbm->mem_space; |
| 656 | } |
| 657 | |
| 658 | res->start = GET_64BIT(ranges, 1); |
| 659 | res->end = res->start + size - 1; |
| 660 | res->flags = flags; |
| 661 | |
| 662 | /* Another way to implement this would be to add an of_device |
| 663 | * layer routine that can calculate a resource for a given |
| 664 | * range property value in a PCI device. |
| 665 | */ |
David S. Miller | 0bae5f8 | 2007-03-08 22:42:19 -0800 | [diff] [blame] | 666 | pci_resource_adjust(res, root); |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 667 | } |
David S. Miller | 8c2786c | 2007-06-07 21:59:44 -0700 | [diff] [blame] | 668 | after_ranges: |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 669 | sprintf(bus->name, "PCI Bus %04x:%02x", pci_domain_nr(bus), |
| 670 | bus->number); |
David S. Miller | 5840fc6 | 2007-05-22 01:24:14 -0700 | [diff] [blame] | 671 | if (ofpci_verbose) |
| 672 | printk(" bus name: %s\n", bus->name); |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 673 | |
| 674 | pci_of_scan_bus(pbm, node, bus); |
| 675 | } |
| 676 | |
David S. Miller | a6009dd | 2007-05-07 00:01:38 -0700 | [diff] [blame] | 677 | static void __devinit pci_of_scan_bus(struct pci_pbm_info *pbm, |
| 678 | struct device_node *node, |
| 679 | struct pci_bus *bus) |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 680 | { |
| 681 | struct device_node *child; |
| 682 | const u32 *reg; |
David S. Miller | 2cc7345 | 2007-09-12 10:15:59 +0200 | [diff] [blame] | 683 | int reglen, devfn, prev_devfn; |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 684 | struct pci_dev *dev; |
| 685 | |
David S. Miller | 5840fc6 | 2007-05-22 01:24:14 -0700 | [diff] [blame] | 686 | if (ofpci_verbose) |
| 687 | printk("PCI: scan_bus[%s] bus no %d\n", |
| 688 | node->full_name, bus->number); |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 689 | |
| 690 | child = NULL; |
David S. Miller | 2cc7345 | 2007-09-12 10:15:59 +0200 | [diff] [blame] | 691 | prev_devfn = -1; |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 692 | while ((child = of_get_next_child(node, child)) != NULL) { |
David S. Miller | 5840fc6 | 2007-05-22 01:24:14 -0700 | [diff] [blame] | 693 | if (ofpci_verbose) |
| 694 | printk(" * %s\n", child->full_name); |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 695 | reg = of_get_property(child, "reg", ®len); |
| 696 | if (reg == NULL || reglen < 20) |
| 697 | continue; |
David S. Miller | 2cc7345 | 2007-09-12 10:15:59 +0200 | [diff] [blame] | 698 | |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 699 | devfn = (reg[0] >> 8) & 0xff; |
| 700 | |
David S. Miller | 2cc7345 | 2007-09-12 10:15:59 +0200 | [diff] [blame] | 701 | /* This is a workaround for some device trees |
| 702 | * which list PCI devices twice. On the V100 |
| 703 | * for example, device number 3 is listed twice. |
| 704 | * Once as "pm" and once again as "lomp". |
| 705 | */ |
| 706 | if (devfn == prev_devfn) |
| 707 | continue; |
| 708 | prev_devfn = devfn; |
| 709 | |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 710 | /* create a new pci_dev for this device */ |
David S. Miller | c26d3c0 | 2008-05-01 01:12:40 -0700 | [diff] [blame] | 711 | dev = of_create_pci_dev(pbm, child, bus, devfn); |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 712 | if (!dev) |
| 713 | continue; |
David S. Miller | 5840fc6 | 2007-05-22 01:24:14 -0700 | [diff] [blame] | 714 | if (ofpci_verbose) |
| 715 | printk("PCI: dev header type: %x\n", |
| 716 | dev->hdr_type); |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 717 | |
| 718 | if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE || |
| 719 | dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) |
| 720 | of_scan_pci_bridge(pbm, child, dev); |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | static ssize_t |
| 725 | show_pciobppath_attr(struct device * dev, struct device_attribute * attr, char * buf) |
| 726 | { |
| 727 | struct pci_dev *pdev; |
| 728 | struct device_node *dp; |
| 729 | |
| 730 | pdev = to_pci_dev(dev); |
| 731 | dp = pdev->dev.archdata.prom_node; |
| 732 | |
| 733 | return snprintf (buf, PAGE_SIZE, "%s\n", dp->full_name); |
| 734 | } |
| 735 | |
| 736 | static DEVICE_ATTR(obppath, S_IRUSR | S_IRGRP | S_IROTH, show_pciobppath_attr, NULL); |
| 737 | |
| 738 | static void __devinit pci_bus_register_of_sysfs(struct pci_bus *bus) |
| 739 | { |
| 740 | struct pci_dev *dev; |
David S. Miller | a378fd0 | 2007-03-01 11:46:13 -0800 | [diff] [blame] | 741 | struct pci_bus *child_bus; |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 742 | int err; |
| 743 | |
| 744 | list_for_each_entry(dev, &bus->devices, bus_list) { |
| 745 | /* we don't really care if we can create this file or |
| 746 | * not, but we need to assign the result of the call |
| 747 | * or the world will fall under alien invasion and |
| 748 | * everybody will be frozen on a spaceship ready to be |
| 749 | * eaten on alpha centauri by some green and jelly |
| 750 | * humanoid. |
| 751 | */ |
| 752 | err = sysfs_create_file(&dev->dev.kobj, &dev_attr_obppath.attr); |
| 753 | } |
David S. Miller | a378fd0 | 2007-03-01 11:46:13 -0800 | [diff] [blame] | 754 | list_for_each_entry(child_bus, &bus->children, node) |
| 755 | pci_bus_register_of_sysfs(child_bus); |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 756 | } |
| 757 | |
David S. Miller | a6009dd | 2007-05-07 00:01:38 -0700 | [diff] [blame] | 758 | struct pci_bus * __devinit pci_scan_one_pbm(struct pci_pbm_info *pbm) |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 759 | { |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 760 | struct device_node *node = pbm->prom_node; |
| 761 | struct pci_bus *bus; |
| 762 | |
| 763 | printk("PCI: Scanning PBM %s\n", node->full_name); |
| 764 | |
| 765 | /* XXX parent device? XXX */ |
David S. Miller | f1cd8de | 2007-05-07 23:24:05 -0700 | [diff] [blame] | 766 | bus = pci_create_bus(NULL, pbm->pci_first_busno, pbm->pci_ops, pbm); |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 767 | if (!bus) { |
| 768 | printk(KERN_ERR "Failed to create bus for %s\n", |
| 769 | node->full_name); |
| 770 | return NULL; |
| 771 | } |
| 772 | bus->secondary = pbm->pci_first_busno; |
| 773 | bus->subordinate = pbm->pci_last_busno; |
| 774 | |
| 775 | bus->resource[0] = &pbm->io_space; |
| 776 | bus->resource[1] = &pbm->mem_space; |
| 777 | |
| 778 | pci_of_scan_bus(pbm, node, bus); |
| 779 | pci_bus_add_devices(bus); |
| 780 | pci_bus_register_of_sysfs(bus); |
| 781 | |
| 782 | return bus; |
| 783 | } |
| 784 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | static void __init pci_scan_each_controller_bus(void) |
| 786 | { |
David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 787 | struct pci_pbm_info *pbm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | |
David S. Miller | 6d19c88 | 2008-08-30 02:30:24 -0700 | [diff] [blame^] | 789 | for (pbm = pci_pbm_root; pbm; pbm = pbm->next) { |
| 790 | if (pbm->scan_bus) |
| 791 | pbm->scan_bus(pbm); |
| 792 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | } |
| 794 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | static int __init pcibios_init(void) |
| 796 | { |
| 797 | pci_controller_probe(); |
David S. Miller | 34768bc | 2007-05-07 23:06:27 -0700 | [diff] [blame] | 798 | if (pci_pbm_root == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | return 0; |
| 800 | |
| 801 | pci_scan_each_controller_bus(); |
| 802 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | return 0; |
| 804 | } |
| 805 | |
| 806 | subsys_initcall(pcibios_init); |
| 807 | |
Robert Reif | f6b45da | 2007-04-12 13:47:37 -0700 | [diff] [blame] | 808 | void __devinit pcibios_fixup_bus(struct pci_bus *pbus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | { |
| 810 | struct pci_pbm_info *pbm = pbus->sysdata; |
| 811 | |
| 812 | /* Generic PCI bus probing sets these to point at |
| 813 | * &io{port,mem}_resouce which is wrong for us. |
| 814 | */ |
| 815 | pbus->resource[0] = &pbm->io_space; |
| 816 | pbus->resource[1] = &pbm->mem_space; |
| 817 | } |
| 818 | |
David S. Miller | 085ae41 | 2005-08-08 13:19:08 -0700 | [diff] [blame] | 819 | struct resource *pcibios_select_root(struct pci_dev *pdev, struct resource *r) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | { |
| 821 | struct pci_pbm_info *pbm = pdev->bus->sysdata; |
David S. Miller | 085ae41 | 2005-08-08 13:19:08 -0700 | [diff] [blame] | 822 | struct resource *root = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | |
David S. Miller | 085ae41 | 2005-08-08 13:19:08 -0700 | [diff] [blame] | 824 | if (r->flags & IORESOURCE_IO) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | root = &pbm->io_space; |
David S. Miller | 085ae41 | 2005-08-08 13:19:08 -0700 | [diff] [blame] | 826 | if (r->flags & IORESOURCE_MEM) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | root = &pbm->mem_space; |
| 828 | |
David S. Miller | 085ae41 | 2005-08-08 13:19:08 -0700 | [diff] [blame] | 829 | return root; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | void pcibios_update_irq(struct pci_dev *pdev, int irq) |
| 833 | { |
| 834 | } |
| 835 | |
| 836 | void pcibios_align_resource(void *data, struct resource *res, |
Greg Kroah-Hartman | e31dd6e | 2006-06-12 17:06:02 -0700 | [diff] [blame] | 837 | resource_size_t size, resource_size_t align) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | { |
| 839 | } |
| 840 | |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 841 | int pcibios_enable_device(struct pci_dev *dev, int mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | { |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 843 | u16 cmd, oldcmd; |
| 844 | int i; |
| 845 | |
| 846 | pci_read_config_word(dev, PCI_COMMAND, &cmd); |
| 847 | oldcmd = cmd; |
| 848 | |
| 849 | for (i = 0; i < PCI_NUM_RESOURCES; i++) { |
| 850 | struct resource *res = &dev->resource[i]; |
| 851 | |
| 852 | /* Only set up the requested stuff */ |
| 853 | if (!(mask & (1<<i))) |
| 854 | continue; |
| 855 | |
| 856 | if (res->flags & IORESOURCE_IO) |
| 857 | cmd |= PCI_COMMAND_IO; |
| 858 | if (res->flags & IORESOURCE_MEM) |
| 859 | cmd |= PCI_COMMAND_MEMORY; |
| 860 | } |
| 861 | |
| 862 | if (cmd != oldcmd) { |
| 863 | printk(KERN_DEBUG "PCI: Enabling device: (%s), cmd %x\n", |
| 864 | pci_name(dev), cmd); |
| 865 | /* Enable the appropriate bits in the PCI command register. */ |
| 866 | pci_write_config_word(dev, PCI_COMMAND, cmd); |
| 867 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | return 0; |
| 869 | } |
| 870 | |
| 871 | void pcibios_resource_to_bus(struct pci_dev *pdev, struct pci_bus_region *region, |
| 872 | struct resource *res) |
| 873 | { |
| 874 | struct pci_pbm_info *pbm = pdev->bus->sysdata; |
| 875 | struct resource zero_res, *root; |
| 876 | |
| 877 | zero_res.start = 0; |
| 878 | zero_res.end = 0; |
| 879 | zero_res.flags = res->flags; |
| 880 | |
| 881 | if (res->flags & IORESOURCE_IO) |
| 882 | root = &pbm->io_space; |
| 883 | else |
| 884 | root = &pbm->mem_space; |
| 885 | |
David S. Miller | 0bae5f8 | 2007-03-08 22:42:19 -0800 | [diff] [blame] | 886 | pci_resource_adjust(&zero_res, root); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | |
| 888 | region->start = res->start - zero_res.start; |
| 889 | region->end = res->end - zero_res.start; |
| 890 | } |
David S. Miller | 5fdfd42 | 2006-04-17 13:34:44 -0700 | [diff] [blame] | 891 | EXPORT_SYMBOL(pcibios_resource_to_bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | |
| 893 | void pcibios_bus_to_resource(struct pci_dev *pdev, struct resource *res, |
| 894 | struct pci_bus_region *region) |
| 895 | { |
| 896 | struct pci_pbm_info *pbm = pdev->bus->sysdata; |
| 897 | struct resource *root; |
| 898 | |
| 899 | res->start = region->start; |
| 900 | res->end = region->end; |
| 901 | |
| 902 | if (res->flags & IORESOURCE_IO) |
| 903 | root = &pbm->io_space; |
| 904 | else |
| 905 | root = &pbm->mem_space; |
| 906 | |
David S. Miller | 0bae5f8 | 2007-03-08 22:42:19 -0800 | [diff] [blame] | 907 | pci_resource_adjust(res, root); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | } |
Keith Owens | 41290c1 | 2005-08-24 16:06:25 +1000 | [diff] [blame] | 909 | EXPORT_SYMBOL(pcibios_bus_to_resource); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | |
Robert Reif | f6b45da | 2007-04-12 13:47:37 -0700 | [diff] [blame] | 911 | char * __devinit pcibios_setup(char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | return str; |
| 914 | } |
| 915 | |
| 916 | /* Platform support for /proc/bus/pci/X/Y mmap()s. */ |
| 917 | |
| 918 | /* If the user uses a host-bridge as the PCI device, he may use |
| 919 | * this to perform a raw mmap() of the I/O or MEM space behind |
| 920 | * that controller. |
| 921 | * |
| 922 | * This can be useful for execution of x86 PCI bios initialization code |
| 923 | * on a PCI card, like the xfree86 int10 stuff does. |
| 924 | */ |
| 925 | static int __pci_mmap_make_offset_bus(struct pci_dev *pdev, struct vm_area_struct *vma, |
| 926 | enum pci_mmap_state mmap_state) |
| 927 | { |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 928 | struct pci_pbm_info *pbm = pdev->dev.archdata.host_controller; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | unsigned long space_size, user_offset, user_size; |
| 930 | |
David S. Miller | 3875c5c | 2007-03-08 22:52:11 -0800 | [diff] [blame] | 931 | if (mmap_state == pci_mmap_io) { |
| 932 | space_size = (pbm->io_space.end - |
| 933 | pbm->io_space.start) + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | } else { |
David S. Miller | 3875c5c | 2007-03-08 22:52:11 -0800 | [diff] [blame] | 935 | space_size = (pbm->mem_space.end - |
| 936 | pbm->mem_space.start) + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | /* Make sure the request is in range. */ |
| 940 | user_offset = vma->vm_pgoff << PAGE_SHIFT; |
| 941 | user_size = vma->vm_end - vma->vm_start; |
| 942 | |
| 943 | if (user_offset >= space_size || |
| 944 | (user_offset + user_size) > space_size) |
| 945 | return -EINVAL; |
| 946 | |
David S. Miller | 3875c5c | 2007-03-08 22:52:11 -0800 | [diff] [blame] | 947 | if (mmap_state == pci_mmap_io) { |
| 948 | vma->vm_pgoff = (pbm->io_space.start + |
| 949 | user_offset) >> PAGE_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | } else { |
David S. Miller | 3875c5c | 2007-03-08 22:52:11 -0800 | [diff] [blame] | 951 | vma->vm_pgoff = (pbm->mem_space.start + |
| 952 | user_offset) >> PAGE_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | return 0; |
| 956 | } |
| 957 | |
David S. Miller | bbe0b5e | 2007-10-11 15:41:01 -0700 | [diff] [blame] | 958 | /* Adjust vm_pgoff of VMA such that it is the physical page offset |
| 959 | * corresponding to the 32-bit pci bus offset for DEV requested by the user. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | * |
| 961 | * Basically, the user finds the base address for his device which he wishes |
| 962 | * to mmap. They read the 32-bit value from the config space base register, |
| 963 | * add whatever PAGE_SIZE multiple offset they wish, and feed this into the |
| 964 | * offset parameter of mmap on /proc/bus/pci/XXX for that device. |
| 965 | * |
| 966 | * Returns negative error code on failure, zero on success. |
| 967 | */ |
David S. Miller | bbe0b5e | 2007-10-11 15:41:01 -0700 | [diff] [blame] | 968 | static int __pci_mmap_make_offset(struct pci_dev *pdev, |
| 969 | struct vm_area_struct *vma, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | enum pci_mmap_state mmap_state) |
| 971 | { |
David S. Miller | bbe0b5e | 2007-10-11 15:41:01 -0700 | [diff] [blame] | 972 | unsigned long user_paddr, user_size; |
| 973 | int i, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | |
David S. Miller | bbe0b5e | 2007-10-11 15:41:01 -0700 | [diff] [blame] | 975 | /* First compute the physical address in vma->vm_pgoff, |
| 976 | * making sure the user offset is within range in the |
| 977 | * appropriate PCI space. |
| 978 | */ |
| 979 | err = __pci_mmap_make_offset_bus(pdev, vma, mmap_state); |
| 980 | if (err) |
| 981 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | |
David S. Miller | bbe0b5e | 2007-10-11 15:41:01 -0700 | [diff] [blame] | 983 | /* If this is a mapping on a host bridge, any address |
| 984 | * is OK. |
| 985 | */ |
| 986 | if ((pdev->class >> 8) == PCI_CLASS_BRIDGE_HOST) |
| 987 | return err; |
| 988 | |
| 989 | /* Otherwise make sure it's in the range for one of the |
| 990 | * device's resources. |
| 991 | */ |
| 992 | user_paddr = vma->vm_pgoff << PAGE_SHIFT; |
| 993 | user_size = vma->vm_end - vma->vm_start; |
| 994 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | for (i = 0; i <= PCI_ROM_RESOURCE; i++) { |
David S. Miller | bbe0b5e | 2007-10-11 15:41:01 -0700 | [diff] [blame] | 996 | struct resource *rp = &pdev->resource[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | |
| 998 | /* Active? */ |
| 999 | if (!rp->flags) |
| 1000 | continue; |
| 1001 | |
| 1002 | /* Same type? */ |
| 1003 | if (i == PCI_ROM_RESOURCE) { |
| 1004 | if (mmap_state != pci_mmap_mem) |
| 1005 | continue; |
| 1006 | } else { |
| 1007 | if ((mmap_state == pci_mmap_io && |
| 1008 | (rp->flags & IORESOURCE_IO) == 0) || |
| 1009 | (mmap_state == pci_mmap_mem && |
| 1010 | (rp->flags & IORESOURCE_MEM) == 0)) |
| 1011 | continue; |
| 1012 | } |
| 1013 | |
David S. Miller | bbe0b5e | 2007-10-11 15:41:01 -0700 | [diff] [blame] | 1014 | if ((rp->start <= user_paddr) && |
| 1015 | (user_paddr + user_size) <= (rp->end + 1UL)) |
| 1016 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | } |
| 1018 | |
David S. Miller | bbe0b5e | 2007-10-11 15:41:01 -0700 | [diff] [blame] | 1019 | if (i > PCI_ROM_RESOURCE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | return -EINVAL; |
| 1021 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | return 0; |
| 1023 | } |
| 1024 | |
| 1025 | /* Set vm_flags of VMA, as appropriate for this architecture, for a pci device |
| 1026 | * mapping. |
| 1027 | */ |
| 1028 | static void __pci_mmap_set_flags(struct pci_dev *dev, struct vm_area_struct *vma, |
| 1029 | enum pci_mmap_state mmap_state) |
| 1030 | { |
| 1031 | vma->vm_flags |= (VM_IO | VM_RESERVED); |
| 1032 | } |
| 1033 | |
| 1034 | /* Set vm_page_prot of VMA, as appropriate for this architecture, for a pci |
| 1035 | * device mapping. |
| 1036 | */ |
| 1037 | static void __pci_mmap_set_pgprot(struct pci_dev *dev, struct vm_area_struct *vma, |
| 1038 | enum pci_mmap_state mmap_state) |
| 1039 | { |
David S. Miller | a7a6cac | 2005-09-01 21:51:26 -0700 | [diff] [blame] | 1040 | /* Our io_remap_pfn_range takes care of this, do nothing. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | /* Perform the actual remap of the pages for a PCI device mapping, as appropriate |
| 1044 | * for this architecture. The region in the process to map is described by vm_start |
| 1045 | * and vm_end members of VMA, the base physical address is found in vm_pgoff. |
| 1046 | * The pci device structure is provided so that architectures may make mapping |
| 1047 | * decisions on a per-device or per-bus basis. |
| 1048 | * |
| 1049 | * Returns a negative error code on failure, zero on success. |
| 1050 | */ |
| 1051 | int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma, |
| 1052 | enum pci_mmap_state mmap_state, |
| 1053 | int write_combine) |
| 1054 | { |
| 1055 | int ret; |
| 1056 | |
| 1057 | ret = __pci_mmap_make_offset(dev, vma, mmap_state); |
| 1058 | if (ret < 0) |
| 1059 | return ret; |
| 1060 | |
| 1061 | __pci_mmap_set_flags(dev, vma, mmap_state); |
| 1062 | __pci_mmap_set_pgprot(dev, vma, mmap_state); |
| 1063 | |
David S. Miller | 14778d9 | 2006-03-21 02:29:39 -0800 | [diff] [blame] | 1064 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | ret = io_remap_pfn_range(vma, vma->vm_start, |
| 1066 | vma->vm_pgoff, |
| 1067 | vma->vm_end - vma->vm_start, |
| 1068 | vma->vm_page_prot); |
| 1069 | if (ret) |
| 1070 | return ret; |
| 1071 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | return 0; |
| 1073 | } |
| 1074 | |
David S. Miller | c1b1a5f | 2008-03-19 04:52:48 -0700 | [diff] [blame] | 1075 | #ifdef CONFIG_NUMA |
| 1076 | int pcibus_to_node(struct pci_bus *pbus) |
| 1077 | { |
| 1078 | struct pci_pbm_info *pbm = pbus->sysdata; |
| 1079 | |
| 1080 | return pbm->numa_node; |
| 1081 | } |
| 1082 | EXPORT_SYMBOL(pcibus_to_node); |
| 1083 | #endif |
| 1084 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | /* Return the domain nuber for this pci bus */ |
| 1086 | |
| 1087 | int pci_domain_nr(struct pci_bus *pbus) |
| 1088 | { |
| 1089 | struct pci_pbm_info *pbm = pbus->sysdata; |
| 1090 | int ret; |
| 1091 | |
| 1092 | if (pbm == NULL || pbm->parent == NULL) { |
| 1093 | ret = -ENXIO; |
| 1094 | } else { |
David S. Miller | 6c108f1 | 2007-05-07 23:49:01 -0700 | [diff] [blame] | 1095 | ret = pbm->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | return ret; |
| 1099 | } |
| 1100 | EXPORT_SYMBOL(pci_domain_nr); |
| 1101 | |
David S. Miller | 35a17eb | 2007-02-10 17:41:02 -0800 | [diff] [blame] | 1102 | #ifdef CONFIG_PCI_MSI |
| 1103 | int arch_setup_msi_irq(struct pci_dev *pdev, struct msi_desc *desc) |
| 1104 | { |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 1105 | struct pci_pbm_info *pbm = pdev->dev.archdata.host_controller; |
David S. Miller | e9870c4 | 2007-05-07 23:28:50 -0700 | [diff] [blame] | 1106 | int virt_irq; |
David S. Miller | 35a17eb | 2007-02-10 17:41:02 -0800 | [diff] [blame] | 1107 | |
David S. Miller | e9870c4 | 2007-05-07 23:28:50 -0700 | [diff] [blame] | 1108 | if (!pbm->setup_msi_irq) |
David S. Miller | 35a17eb | 2007-02-10 17:41:02 -0800 | [diff] [blame] | 1109 | return -EINVAL; |
| 1110 | |
David S. Miller | e9870c4 | 2007-05-07 23:28:50 -0700 | [diff] [blame] | 1111 | return pbm->setup_msi_irq(&virt_irq, pdev, desc); |
David S. Miller | 35a17eb | 2007-02-10 17:41:02 -0800 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | void arch_teardown_msi_irq(unsigned int virt_irq) |
| 1115 | { |
David S. Miller | abfd336 | 2007-02-26 09:40:34 -0800 | [diff] [blame] | 1116 | struct msi_desc *entry = get_irq_msi(virt_irq); |
David S. Miller | 35a17eb | 2007-02-10 17:41:02 -0800 | [diff] [blame] | 1117 | struct pci_dev *pdev = entry->dev; |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 1118 | struct pci_pbm_info *pbm = pdev->dev.archdata.host_controller; |
David S. Miller | 35a17eb | 2007-02-10 17:41:02 -0800 | [diff] [blame] | 1119 | |
David S. Miller | e9870c4 | 2007-05-07 23:28:50 -0700 | [diff] [blame] | 1120 | if (!pbm->teardown_msi_irq) |
David S. Miller | 35a17eb | 2007-02-10 17:41:02 -0800 | [diff] [blame] | 1121 | return; |
| 1122 | |
David S. Miller | e9870c4 | 2007-05-07 23:28:50 -0700 | [diff] [blame] | 1123 | return pbm->teardown_msi_irq(virt_irq, pdev); |
David S. Miller | 35a17eb | 2007-02-10 17:41:02 -0800 | [diff] [blame] | 1124 | } |
| 1125 | #endif /* !(CONFIG_PCI_MSI) */ |
| 1126 | |
David S. Miller | f6d0f9e | 2007-03-01 18:09:18 -0800 | [diff] [blame] | 1127 | struct device_node *pci_device_to_OF_node(struct pci_dev *pdev) |
| 1128 | { |
David S. Miller | a2fb23a | 2007-02-28 23:35:04 -0800 | [diff] [blame] | 1129 | return pdev->dev.archdata.prom_node; |
David S. Miller | f6d0f9e | 2007-03-01 18:09:18 -0800 | [diff] [blame] | 1130 | } |
| 1131 | EXPORT_SYMBOL(pci_device_to_OF_node); |
| 1132 | |
David S. Miller | ad7ad57 | 2007-07-27 22:39:14 -0700 | [diff] [blame] | 1133 | static void ali_sound_dma_hack(struct pci_dev *pdev, int set_bit) |
| 1134 | { |
| 1135 | struct pci_dev *ali_isa_bridge; |
| 1136 | u8 val; |
| 1137 | |
| 1138 | /* ALI sound chips generate 31-bits of DMA, a special register |
| 1139 | * determines what bit 31 is emitted as. |
| 1140 | */ |
| 1141 | ali_isa_bridge = pci_get_device(PCI_VENDOR_ID_AL, |
| 1142 | PCI_DEVICE_ID_AL_M1533, |
| 1143 | NULL); |
| 1144 | |
| 1145 | pci_read_config_byte(ali_isa_bridge, 0x7e, &val); |
| 1146 | if (set_bit) |
| 1147 | val |= 0x01; |
| 1148 | else |
| 1149 | val &= ~0x01; |
| 1150 | pci_write_config_byte(ali_isa_bridge, 0x7e, val); |
| 1151 | pci_dev_put(ali_isa_bridge); |
| 1152 | } |
| 1153 | |
| 1154 | int pci_dma_supported(struct pci_dev *pdev, u64 device_mask) |
| 1155 | { |
| 1156 | u64 dma_addr_mask; |
| 1157 | |
| 1158 | if (pdev == NULL) { |
| 1159 | dma_addr_mask = 0xffffffff; |
| 1160 | } else { |
| 1161 | struct iommu *iommu = pdev->dev.archdata.iommu; |
| 1162 | |
| 1163 | dma_addr_mask = iommu->dma_addr_mask; |
| 1164 | |
| 1165 | if (pdev->vendor == PCI_VENDOR_ID_AL && |
| 1166 | pdev->device == PCI_DEVICE_ID_AL_M5451 && |
| 1167 | device_mask == 0x7fffffff) { |
| 1168 | ali_sound_dma_hack(pdev, |
| 1169 | (dma_addr_mask & 0x80000000) != 0); |
| 1170 | return 1; |
| 1171 | } |
| 1172 | } |
| 1173 | |
| 1174 | if (device_mask >= (1UL << 32UL)) |
| 1175 | return 0; |
| 1176 | |
| 1177 | return (device_mask & dma_addr_mask) == dma_addr_mask; |
| 1178 | } |
| 1179 | |
David S. Miller | bcea1db | 2007-12-25 02:20:33 -0800 | [diff] [blame] | 1180 | void pci_resource_to_user(const struct pci_dev *pdev, int bar, |
| 1181 | const struct resource *rp, resource_size_t *start, |
| 1182 | resource_size_t *end) |
| 1183 | { |
| 1184 | struct pci_pbm_info *pbm = pdev->dev.archdata.host_controller; |
| 1185 | unsigned long offset; |
| 1186 | |
| 1187 | if (rp->flags & IORESOURCE_IO) |
| 1188 | offset = pbm->io_space.start; |
| 1189 | else |
| 1190 | offset = pbm->mem_space.start; |
| 1191 | |
| 1192 | *start = rp->start - offset; |
| 1193 | *end = rp->end - offset; |
| 1194 | } |