pci_64.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365
  1. /*
  2. * Port for PPC64 David Engebretsen, IBM Corp.
  3. * Contains common pci routines for ppc64 platform, pSeries and iSeries brands.
  4. *
  5. * Copyright (C) 2003 Anton Blanchard <anton@au.ibm.com>, IBM
  6. * Rework, based on alpha PCI code.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version
  11. * 2 of the License, or (at your option) any later version.
  12. */
  13. #undef DEBUG
  14. #include <linux/config.h>
  15. #include <linux/kernel.h>
  16. #include <linux/pci.h>
  17. #include <linux/string.h>
  18. #include <linux/init.h>
  19. #include <linux/bootmem.h>
  20. #include <linux/mm.h>
  21. #include <linux/list.h>
  22. #include <linux/syscalls.h>
  23. #include <asm/processor.h>
  24. #include <asm/io.h>
  25. #include <asm/prom.h>
  26. #include <asm/pci-bridge.h>
  27. #include <asm/byteorder.h>
  28. #include <asm/irq.h>
  29. #include <asm/machdep.h>
  30. #include <asm/ppc-pci.h>
  31. #ifdef DEBUG
  32. #include <asm/udbg.h>
  33. #define DBG(fmt...) udbg_printf(fmt)
  34. #else
  35. #define DBG(fmt...)
  36. #endif
  37. unsigned long pci_probe_only = 1;
  38. int pci_assign_all_buses = 0;
  39. /*
  40. * legal IO pages under MAX_ISA_PORT. This is to ensure we don't touch
  41. * devices we don't have access to.
  42. */
  43. unsigned long io_page_mask;
  44. EXPORT_SYMBOL(io_page_mask);
  45. #ifdef CONFIG_PPC_MULTIPLATFORM
  46. static void fixup_resource(struct resource *res, struct pci_dev *dev);
  47. static void do_bus_setup(struct pci_bus *bus);
  48. #endif
  49. /* pci_io_base -- the base address from which io bars are offsets.
  50. * This is the lowest I/O base address (so bar values are always positive),
  51. * and it *must* be the start of ISA space if an ISA bus exists because
  52. * ISA drivers use hard coded offsets. If no ISA bus exists a dummy
  53. * page is mapped and isa_io_limit prevents access to it.
  54. */
  55. unsigned long isa_io_base; /* NULL if no ISA bus */
  56. EXPORT_SYMBOL(isa_io_base);
  57. unsigned long pci_io_base;
  58. EXPORT_SYMBOL(pci_io_base);
  59. void iSeries_pcibios_init(void);
  60. LIST_HEAD(hose_list);
  61. struct dma_mapping_ops pci_dma_ops;
  62. EXPORT_SYMBOL(pci_dma_ops);
  63. int global_phb_number; /* Global phb counter */
  64. /* Cached ISA bridge dev. */
  65. struct pci_dev *ppc64_isabridge_dev = NULL;
  66. static void fixup_broken_pcnet32(struct pci_dev* dev)
  67. {
  68. if ((dev->class>>8 == PCI_CLASS_NETWORK_ETHERNET)) {
  69. dev->vendor = PCI_VENDOR_ID_AMD;
  70. pci_write_config_word(dev, PCI_VENDOR_ID, PCI_VENDOR_ID_AMD);
  71. }
  72. }
  73. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TRIDENT, PCI_ANY_ID, fixup_broken_pcnet32);
  74. void pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region,
  75. struct resource *res)
  76. {
  77. unsigned long offset = 0;
  78. struct pci_controller *hose = pci_bus_to_host(dev->bus);
  79. if (!hose)
  80. return;
  81. if (res->flags & IORESOURCE_IO)
  82. offset = (unsigned long)hose->io_base_virt - pci_io_base;
  83. if (res->flags & IORESOURCE_MEM)
  84. offset = hose->pci_mem_offset;
  85. region->start = res->start - offset;
  86. region->end = res->end - offset;
  87. }
  88. void pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res,
  89. struct pci_bus_region *region)
  90. {
  91. unsigned long offset = 0;
  92. struct pci_controller *hose = pci_bus_to_host(dev->bus);
  93. if (!hose)
  94. return;
  95. if (res->flags & IORESOURCE_IO)
  96. offset = (unsigned long)hose->io_base_virt - pci_io_base;
  97. if (res->flags & IORESOURCE_MEM)
  98. offset = hose->pci_mem_offset;
  99. res->start = region->start + offset;
  100. res->end = region->end + offset;
  101. }
  102. #ifdef CONFIG_HOTPLUG
  103. EXPORT_SYMBOL(pcibios_resource_to_bus);
  104. EXPORT_SYMBOL(pcibios_bus_to_resource);
  105. #endif
  106. /*
  107. * We need to avoid collisions with `mirrored' VGA ports
  108. * and other strange ISA hardware, so we always want the
  109. * addresses to be allocated in the 0x000-0x0ff region
  110. * modulo 0x400.
  111. *
  112. * Why? Because some silly external IO cards only decode
  113. * the low 10 bits of the IO address. The 0x00-0xff region
  114. * is reserved for motherboard devices that decode all 16
  115. * bits, so it's ok to allocate at, say, 0x2800-0x28ff,
  116. * but we want to try to avoid allocating at 0x2900-0x2bff
  117. * which might have be mirrored at 0x0100-0x03ff..
  118. */
  119. void pcibios_align_resource(void *data, struct resource *res,
  120. unsigned long size, unsigned long align)
  121. {
  122. struct pci_dev *dev = data;
  123. struct pci_controller *hose = pci_bus_to_host(dev->bus);
  124. unsigned long start = res->start;
  125. unsigned long alignto;
  126. if (res->flags & IORESOURCE_IO) {
  127. unsigned long offset = (unsigned long)hose->io_base_virt -
  128. pci_io_base;
  129. /* Make sure we start at our min on all hoses */
  130. if (start - offset < PCIBIOS_MIN_IO)
  131. start = PCIBIOS_MIN_IO + offset;
  132. /*
  133. * Put everything into 0x00-0xff region modulo 0x400
  134. */
  135. if (start & 0x300)
  136. start = (start + 0x3ff) & ~0x3ff;
  137. } else if (res->flags & IORESOURCE_MEM) {
  138. /* Make sure we start at our min on all hoses */
  139. if (start - hose->pci_mem_offset < PCIBIOS_MIN_MEM)
  140. start = PCIBIOS_MIN_MEM + hose->pci_mem_offset;
  141. /* Align to multiple of size of minimum base. */
  142. alignto = max(0x1000UL, align);
  143. start = ALIGN(start, alignto);
  144. }
  145. res->start = start;
  146. }
  147. static DEFINE_SPINLOCK(hose_spinlock);
  148. /*
  149. * pci_controller(phb) initialized common variables.
  150. */
  151. static void __devinit pci_setup_pci_controller(struct pci_controller *hose)
  152. {
  153. memset(hose, 0, sizeof(struct pci_controller));
  154. spin_lock(&hose_spinlock);
  155. hose->global_number = global_phb_number++;
  156. list_add_tail(&hose->list_node, &hose_list);
  157. spin_unlock(&hose_spinlock);
  158. }
  159. static void add_linux_pci_domain(struct device_node *dev,
  160. struct pci_controller *phb)
  161. {
  162. struct property *of_prop;
  163. unsigned int size;
  164. of_prop = (struct property *)
  165. get_property(dev, "linux,pci-domain", &size);
  166. if (of_prop != NULL)
  167. return;
  168. WARN_ON(of_prop && size < sizeof(int));
  169. if (of_prop && size < sizeof(int))
  170. of_prop = NULL;
  171. size = sizeof(struct property) + sizeof(int);
  172. if (of_prop == NULL) {
  173. if (mem_init_done)
  174. of_prop = kmalloc(size, GFP_KERNEL);
  175. else
  176. of_prop = alloc_bootmem(size);
  177. }
  178. memset(of_prop, 0, sizeof(struct property));
  179. of_prop->name = "linux,pci-domain";
  180. of_prop->length = sizeof(int);
  181. of_prop->value = (unsigned char *)&of_prop[1];
  182. *((int *)of_prop->value) = phb->global_number;
  183. prom_add_property(dev, of_prop);
  184. }
  185. struct pci_controller * pcibios_alloc_controller(struct device_node *dev)
  186. {
  187. struct pci_controller *phb;
  188. if (mem_init_done)
  189. phb = kmalloc(sizeof(struct pci_controller), GFP_KERNEL);
  190. else
  191. phb = alloc_bootmem(sizeof (struct pci_controller));
  192. if (phb == NULL)
  193. return NULL;
  194. pci_setup_pci_controller(phb);
  195. phb->arch_data = dev;
  196. phb->is_dynamic = mem_init_done;
  197. if (dev)
  198. add_linux_pci_domain(dev, phb);
  199. return phb;
  200. }
  201. void pcibios_free_controller(struct pci_controller *phb)
  202. {
  203. if (phb->arch_data) {
  204. struct device_node *np = phb->arch_data;
  205. int *domain = (int *)get_property(np,
  206. "linux,pci-domain", NULL);
  207. if (domain)
  208. *domain = -1;
  209. }
  210. if (phb->is_dynamic)
  211. kfree(phb);
  212. }
  213. static void __init pcibios_claim_one_bus(struct pci_bus *b)
  214. {
  215. struct pci_dev *dev;
  216. struct pci_bus *child_bus;
  217. list_for_each_entry(dev, &b->devices, bus_list) {
  218. int i;
  219. for (i = 0; i < PCI_NUM_RESOURCES; i++) {
  220. struct resource *r = &dev->resource[i];
  221. if (r->parent || !r->start || !r->flags)
  222. continue;
  223. pci_claim_resource(dev, i);
  224. }
  225. }
  226. list_for_each_entry(child_bus, &b->children, node)
  227. pcibios_claim_one_bus(child_bus);
  228. }
  229. #ifndef CONFIG_PPC_ISERIES
  230. static void __init pcibios_claim_of_setup(void)
  231. {
  232. struct pci_bus *b;
  233. list_for_each_entry(b, &pci_root_buses, node)
  234. pcibios_claim_one_bus(b);
  235. }
  236. #endif
  237. #ifdef CONFIG_PPC_MULTIPLATFORM
  238. static u32 get_int_prop(struct device_node *np, const char *name, u32 def)
  239. {
  240. u32 *prop;
  241. int len;
  242. prop = (u32 *) get_property(np, name, &len);
  243. if (prop && len >= 4)
  244. return *prop;
  245. return def;
  246. }
  247. static unsigned int pci_parse_of_flags(u32 addr0)
  248. {
  249. unsigned int flags = 0;
  250. if (addr0 & 0x02000000) {
  251. flags = IORESOURCE_MEM | PCI_BASE_ADDRESS_SPACE_MEMORY;
  252. flags |= (addr0 >> 22) & PCI_BASE_ADDRESS_MEM_TYPE_64;
  253. flags |= (addr0 >> 28) & PCI_BASE_ADDRESS_MEM_TYPE_1M;
  254. if (addr0 & 0x40000000)
  255. flags |= IORESOURCE_PREFETCH
  256. | PCI_BASE_ADDRESS_MEM_PREFETCH;
  257. } else if (addr0 & 0x01000000)
  258. flags = IORESOURCE_IO | PCI_BASE_ADDRESS_SPACE_IO;
  259. return flags;
  260. }
  261. #define GET_64BIT(prop, i) ((((u64) (prop)[(i)]) << 32) | (prop)[(i)+1])
  262. static void pci_parse_of_addrs(struct device_node *node, struct pci_dev *dev)
  263. {
  264. u64 base, size;
  265. unsigned int flags;
  266. struct resource *res;
  267. u32 *addrs, i;
  268. int proplen;
  269. addrs = (u32 *) get_property(node, "assigned-addresses", &proplen);
  270. if (!addrs)
  271. return;
  272. for (; proplen >= 20; proplen -= 20, addrs += 5) {
  273. flags = pci_parse_of_flags(addrs[0]);
  274. if (!flags)
  275. continue;
  276. base = GET_64BIT(addrs, 1);
  277. size = GET_64BIT(addrs, 3);
  278. if (!size)
  279. continue;
  280. i = addrs[0] & 0xff;
  281. if (PCI_BASE_ADDRESS_0 <= i && i <= PCI_BASE_ADDRESS_5) {
  282. res = &dev->resource[(i - PCI_BASE_ADDRESS_0) >> 2];
  283. } else if (i == dev->rom_base_reg) {
  284. res = &dev->resource[PCI_ROM_RESOURCE];
  285. flags |= IORESOURCE_READONLY | IORESOURCE_CACHEABLE;
  286. } else {
  287. printk(KERN_ERR "PCI: bad cfg reg num 0x%x\n", i);
  288. continue;
  289. }
  290. res->start = base;
  291. res->end = base + size - 1;
  292. res->flags = flags;
  293. res->name = pci_name(dev);
  294. fixup_resource(res, dev);
  295. }
  296. }
  297. struct pci_dev *of_create_pci_dev(struct device_node *node,
  298. struct pci_bus *bus, int devfn)
  299. {
  300. struct pci_dev *dev;
  301. const char *type;
  302. dev = kmalloc(sizeof(struct pci_dev), GFP_KERNEL);
  303. if (!dev)
  304. return NULL;
  305. type = get_property(node, "device_type", NULL);
  306. if (type == NULL)
  307. type = "";
  308. memset(dev, 0, sizeof(struct pci_dev));
  309. dev->bus = bus;
  310. dev->sysdata = node;
  311. dev->dev.parent = bus->bridge;
  312. dev->dev.bus = &pci_bus_type;
  313. dev->devfn = devfn;
  314. dev->multifunction = 0; /* maybe a lie? */
  315. dev->vendor = get_int_prop(node, "vendor-id", 0xffff);
  316. dev->device = get_int_prop(node, "device-id", 0xffff);
  317. dev->subsystem_vendor = get_int_prop(node, "subsystem-vendor-id", 0);
  318. dev->subsystem_device = get_int_prop(node, "subsystem-id", 0);
  319. dev->cfg_size = 256; /*pci_cfg_space_size(dev);*/
  320. sprintf(pci_name(dev), "%04x:%02x:%02x.%d", pci_domain_nr(bus),
  321. dev->bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn));
  322. dev->class = get_int_prop(node, "class-code", 0);
  323. dev->current_state = 4; /* unknown power state */
  324. if (!strcmp(type, "pci")) {
  325. /* a PCI-PCI bridge */
  326. dev->hdr_type = PCI_HEADER_TYPE_BRIDGE;
  327. dev->rom_base_reg = PCI_ROM_ADDRESS1;
  328. } else if (!strcmp(type, "cardbus")) {
  329. dev->hdr_type = PCI_HEADER_TYPE_CARDBUS;
  330. } else {
  331. dev->hdr_type = PCI_HEADER_TYPE_NORMAL;
  332. dev->rom_base_reg = PCI_ROM_ADDRESS;
  333. dev->irq = NO_IRQ;
  334. if (node->n_intrs > 0) {
  335. dev->irq = node->intrs[0].line;
  336. pci_write_config_byte(dev, PCI_INTERRUPT_LINE,
  337. dev->irq);
  338. }
  339. }
  340. pci_parse_of_addrs(node, dev);
  341. pci_device_add(dev, bus);
  342. /* XXX pci_scan_msi_device(dev); */
  343. return dev;
  344. }
  345. EXPORT_SYMBOL(of_create_pci_dev);
  346. void __devinit of_scan_bus(struct device_node *node,
  347. struct pci_bus *bus)
  348. {
  349. struct device_node *child = NULL;
  350. u32 *reg;
  351. int reglen, devfn;
  352. struct pci_dev *dev;
  353. while ((child = of_get_next_child(node, child)) != NULL) {
  354. reg = (u32 *) get_property(child, "reg", &reglen);
  355. if (reg == NULL || reglen < 20)
  356. continue;
  357. devfn = (reg[0] >> 8) & 0xff;
  358. /* create a new pci_dev for this device */
  359. dev = of_create_pci_dev(child, bus, devfn);
  360. if (!dev)
  361. continue;
  362. if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
  363. dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
  364. of_scan_pci_bridge(child, dev);
  365. }
  366. do_bus_setup(bus);
  367. }
  368. EXPORT_SYMBOL(of_scan_bus);
  369. void __devinit of_scan_pci_bridge(struct device_node *node,
  370. struct pci_dev *dev)
  371. {
  372. struct pci_bus *bus;
  373. u32 *busrange, *ranges;
  374. int len, i, mode;
  375. struct resource *res;
  376. unsigned int flags;
  377. u64 size;
  378. /* parse bus-range property */
  379. busrange = (u32 *) get_property(node, "bus-range", &len);
  380. if (busrange == NULL || len != 8) {
  381. printk(KERN_ERR "Can't get bus-range for PCI-PCI bridge %s\n",
  382. node->full_name);
  383. return;
  384. }
  385. ranges = (u32 *) get_property(node, "ranges", &len);
  386. if (ranges == NULL) {
  387. printk(KERN_ERR "Can't get ranges for PCI-PCI bridge %s\n",
  388. node->full_name);
  389. return;
  390. }
  391. bus = pci_add_new_bus(dev->bus, dev, busrange[0]);
  392. if (!bus) {
  393. printk(KERN_ERR "Failed to create pci bus for %s\n",
  394. node->full_name);
  395. return;
  396. }
  397. bus->primary = dev->bus->number;
  398. bus->subordinate = busrange[1];
  399. bus->bridge_ctl = 0;
  400. bus->sysdata = node;
  401. /* parse ranges property */
  402. /* PCI #address-cells == 3 and #size-cells == 2 always */
  403. res = &dev->resource[PCI_BRIDGE_RESOURCES];
  404. for (i = 0; i < PCI_NUM_RESOURCES - PCI_BRIDGE_RESOURCES; ++i) {
  405. res->flags = 0;
  406. bus->resource[i] = res;
  407. ++res;
  408. }
  409. i = 1;
  410. for (; len >= 32; len -= 32, ranges += 8) {
  411. flags = pci_parse_of_flags(ranges[0]);
  412. size = GET_64BIT(ranges, 6);
  413. if (flags == 0 || size == 0)
  414. continue;
  415. if (flags & IORESOURCE_IO) {
  416. res = bus->resource[0];
  417. if (res->flags) {
  418. printk(KERN_ERR "PCI: ignoring extra I/O range"
  419. " for bridge %s\n", node->full_name);
  420. continue;
  421. }
  422. } else {
  423. if (i >= PCI_NUM_RESOURCES - PCI_BRIDGE_RESOURCES) {
  424. printk(KERN_ERR "PCI: too many memory ranges"
  425. " for bridge %s\n", node->full_name);
  426. continue;
  427. }
  428. res = bus->resource[i];
  429. ++i;
  430. }
  431. res->start = GET_64BIT(ranges, 1);
  432. res->end = res->start + size - 1;
  433. res->flags = flags;
  434. fixup_resource(res, dev);
  435. }
  436. sprintf(bus->name, "PCI Bus %04x:%02x", pci_domain_nr(bus),
  437. bus->number);
  438. mode = PCI_PROBE_NORMAL;
  439. if (ppc_md.pci_probe_mode)
  440. mode = ppc_md.pci_probe_mode(bus);
  441. if (mode == PCI_PROBE_DEVTREE)
  442. of_scan_bus(node, bus);
  443. else if (mode == PCI_PROBE_NORMAL)
  444. pci_scan_child_bus(bus);
  445. }
  446. EXPORT_SYMBOL(of_scan_pci_bridge);
  447. #endif /* CONFIG_PPC_MULTIPLATFORM */
  448. void __devinit scan_phb(struct pci_controller *hose)
  449. {
  450. struct pci_bus *bus;
  451. struct device_node *node = hose->arch_data;
  452. int i, mode;
  453. struct resource *res;
  454. bus = pci_create_bus(NULL, hose->first_busno, hose->ops, node);
  455. if (bus == NULL) {
  456. printk(KERN_ERR "Failed to create bus for PCI domain %04x\n",
  457. hose->global_number);
  458. return;
  459. }
  460. bus->secondary = hose->first_busno;
  461. hose->bus = bus;
  462. bus->resource[0] = res = &hose->io_resource;
  463. if (res->flags && request_resource(&ioport_resource, res))
  464. printk(KERN_ERR "Failed to request PCI IO region "
  465. "on PCI domain %04x\n", hose->global_number);
  466. for (i = 0; i < 3; ++i) {
  467. res = &hose->mem_resources[i];
  468. bus->resource[i+1] = res;
  469. if (res->flags && request_resource(&iomem_resource, res))
  470. printk(KERN_ERR "Failed to request PCI memory region "
  471. "on PCI domain %04x\n", hose->global_number);
  472. }
  473. mode = PCI_PROBE_NORMAL;
  474. #ifdef CONFIG_PPC_MULTIPLATFORM
  475. if (ppc_md.pci_probe_mode)
  476. mode = ppc_md.pci_probe_mode(bus);
  477. if (mode == PCI_PROBE_DEVTREE) {
  478. bus->subordinate = hose->last_busno;
  479. of_scan_bus(node, bus);
  480. }
  481. #endif /* CONFIG_PPC_MULTIPLATFORM */
  482. if (mode == PCI_PROBE_NORMAL)
  483. hose->last_busno = bus->subordinate = pci_scan_child_bus(bus);
  484. pci_bus_add_devices(bus);
  485. }
  486. static int __init pcibios_init(void)
  487. {
  488. struct pci_controller *hose, *tmp;
  489. /* For now, override phys_mem_access_prot. If we need it,
  490. * later, we may move that initialization to each ppc_md
  491. */
  492. ppc_md.phys_mem_access_prot = pci_phys_mem_access_prot;
  493. #ifdef CONFIG_PPC_ISERIES
  494. iSeries_pcibios_init();
  495. #endif
  496. printk("PCI: Probing PCI hardware\n");
  497. /* Scan all of the recorded PCI controllers. */
  498. list_for_each_entry_safe(hose, tmp, &hose_list, list_node)
  499. scan_phb(hose);
  500. #ifndef CONFIG_PPC_ISERIES
  501. if (pci_probe_only)
  502. pcibios_claim_of_setup();
  503. else
  504. /* FIXME: `else' will be removed when
  505. pci_assign_unassigned_resources() is able to work
  506. correctly with [partially] allocated PCI tree. */
  507. pci_assign_unassigned_resources();
  508. #endif /* !CONFIG_PPC_ISERIES */
  509. /* Call machine dependent final fixup */
  510. if (ppc_md.pcibios_fixup)
  511. ppc_md.pcibios_fixup();
  512. /* Cache the location of the ISA bridge (if we have one) */
  513. ppc64_isabridge_dev = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, NULL);
  514. if (ppc64_isabridge_dev != NULL)
  515. printk("ISA bridge at %s\n", pci_name(ppc64_isabridge_dev));
  516. #ifdef CONFIG_PPC_MULTIPLATFORM
  517. /* map in PCI I/O space */
  518. phbs_remap_io();
  519. #endif
  520. printk("PCI: Probing PCI hardware done\n");
  521. return 0;
  522. }
  523. subsys_initcall(pcibios_init);
  524. char __init *pcibios_setup(char *str)
  525. {
  526. return str;
  527. }
  528. int pcibios_enable_device(struct pci_dev *dev, int mask)
  529. {
  530. u16 cmd, oldcmd;
  531. int i;
  532. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  533. oldcmd = cmd;
  534. for (i = 0; i < PCI_NUM_RESOURCES; i++) {
  535. struct resource *res = &dev->resource[i];
  536. /* Only set up the requested stuff */
  537. if (!(mask & (1<<i)))
  538. continue;
  539. if (res->flags & IORESOURCE_IO)
  540. cmd |= PCI_COMMAND_IO;
  541. if (res->flags & IORESOURCE_MEM)
  542. cmd |= PCI_COMMAND_MEMORY;
  543. }
  544. if (cmd != oldcmd) {
  545. printk(KERN_DEBUG "PCI: Enabling device: (%s), cmd %x\n",
  546. pci_name(dev), cmd);
  547. /* Enable the appropriate bits in the PCI command register. */
  548. pci_write_config_word(dev, PCI_COMMAND, cmd);
  549. }
  550. return 0;
  551. }
  552. /*
  553. * Return the domain number for this bus.
  554. */
  555. int pci_domain_nr(struct pci_bus *bus)
  556. {
  557. #ifdef CONFIG_PPC_ISERIES
  558. return 0;
  559. #else
  560. struct pci_controller *hose = pci_bus_to_host(bus);
  561. return hose->global_number;
  562. #endif
  563. }
  564. EXPORT_SYMBOL(pci_domain_nr);
  565. /* Decide whether to display the domain number in /proc */
  566. int pci_proc_domain(struct pci_bus *bus)
  567. {
  568. #ifdef CONFIG_PPC_ISERIES
  569. return 0;
  570. #else
  571. struct pci_controller *hose = pci_bus_to_host(bus);
  572. return hose->buid;
  573. #endif
  574. }
  575. /*
  576. * Platform support for /proc/bus/pci/X/Y mmap()s,
  577. * modelled on the sparc64 implementation by Dave Miller.
  578. * -- paulus.
  579. */
  580. /*
  581. * Adjust vm_pgoff of VMA such that it is the physical page offset
  582. * corresponding to the 32-bit pci bus offset for DEV requested by the user.
  583. *
  584. * Basically, the user finds the base address for his device which he wishes
  585. * to mmap. They read the 32-bit value from the config space base register,
  586. * add whatever PAGE_SIZE multiple offset they wish, and feed this into the
  587. * offset parameter of mmap on /proc/bus/pci/XXX for that device.
  588. *
  589. * Returns negative error code on failure, zero on success.
  590. */
  591. static struct resource *__pci_mmap_make_offset(struct pci_dev *dev,
  592. unsigned long *offset,
  593. enum pci_mmap_state mmap_state)
  594. {
  595. struct pci_controller *hose = pci_bus_to_host(dev->bus);
  596. unsigned long io_offset = 0;
  597. int i, res_bit;
  598. if (hose == 0)
  599. return NULL; /* should never happen */
  600. /* If memory, add on the PCI bridge address offset */
  601. if (mmap_state == pci_mmap_mem) {
  602. *offset += hose->pci_mem_offset;
  603. res_bit = IORESOURCE_MEM;
  604. } else {
  605. io_offset = (unsigned long)hose->io_base_virt - pci_io_base;
  606. *offset += io_offset;
  607. res_bit = IORESOURCE_IO;
  608. }
  609. /*
  610. * Check that the offset requested corresponds to one of the
  611. * resources of the device.
  612. */
  613. for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
  614. struct resource *rp = &dev->resource[i];
  615. int flags = rp->flags;
  616. /* treat ROM as memory (should be already) */
  617. if (i == PCI_ROM_RESOURCE)
  618. flags |= IORESOURCE_MEM;
  619. /* Active and same type? */
  620. if ((flags & res_bit) == 0)
  621. continue;
  622. /* In the range of this resource? */
  623. if (*offset < (rp->start & PAGE_MASK) || *offset > rp->end)
  624. continue;
  625. /* found it! construct the final physical address */
  626. if (mmap_state == pci_mmap_io)
  627. *offset += hose->io_base_phys - io_offset;
  628. return rp;
  629. }
  630. return NULL;
  631. }
  632. /*
  633. * Set vm_page_prot of VMA, as appropriate for this architecture, for a pci
  634. * device mapping.
  635. */
  636. static pgprot_t __pci_mmap_set_pgprot(struct pci_dev *dev, struct resource *rp,
  637. pgprot_t protection,
  638. enum pci_mmap_state mmap_state,
  639. int write_combine)
  640. {
  641. unsigned long prot = pgprot_val(protection);
  642. /* Write combine is always 0 on non-memory space mappings. On
  643. * memory space, if the user didn't pass 1, we check for a
  644. * "prefetchable" resource. This is a bit hackish, but we use
  645. * this to workaround the inability of /sysfs to provide a write
  646. * combine bit
  647. */
  648. if (mmap_state != pci_mmap_mem)
  649. write_combine = 0;
  650. else if (write_combine == 0) {
  651. if (rp->flags & IORESOURCE_PREFETCH)
  652. write_combine = 1;
  653. }
  654. /* XXX would be nice to have a way to ask for write-through */
  655. prot |= _PAGE_NO_CACHE;
  656. if (write_combine)
  657. prot &= ~_PAGE_GUARDED;
  658. else
  659. prot |= _PAGE_GUARDED;
  660. printk("PCI map for %s:%lx, prot: %lx\n", pci_name(dev), rp->start,
  661. prot);
  662. return __pgprot(prot);
  663. }
  664. /*
  665. * This one is used by /dev/mem and fbdev who have no clue about the
  666. * PCI device, it tries to find the PCI device first and calls the
  667. * above routine
  668. */
  669. pgprot_t pci_phys_mem_access_prot(struct file *file,
  670. unsigned long pfn,
  671. unsigned long size,
  672. pgprot_t protection)
  673. {
  674. struct pci_dev *pdev = NULL;
  675. struct resource *found = NULL;
  676. unsigned long prot = pgprot_val(protection);
  677. unsigned long offset = pfn << PAGE_SHIFT;
  678. int i;
  679. if (page_is_ram(pfn))
  680. return __pgprot(prot);
  681. prot |= _PAGE_NO_CACHE | _PAGE_GUARDED;
  682. for_each_pci_dev(pdev) {
  683. for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
  684. struct resource *rp = &pdev->resource[i];
  685. int flags = rp->flags;
  686. /* Active and same type? */
  687. if ((flags & IORESOURCE_MEM) == 0)
  688. continue;
  689. /* In the range of this resource? */
  690. if (offset < (rp->start & PAGE_MASK) ||
  691. offset > rp->end)
  692. continue;
  693. found = rp;
  694. break;
  695. }
  696. if (found)
  697. break;
  698. }
  699. if (found) {
  700. if (found->flags & IORESOURCE_PREFETCH)
  701. prot &= ~_PAGE_GUARDED;
  702. pci_dev_put(pdev);
  703. }
  704. DBG("non-PCI map for %lx, prot: %lx\n", offset, prot);
  705. return __pgprot(prot);
  706. }
  707. /*
  708. * Perform the actual remap of the pages for a PCI device mapping, as
  709. * appropriate for this architecture. The region in the process to map
  710. * is described by vm_start and vm_end members of VMA, the base physical
  711. * address is found in vm_pgoff.
  712. * The pci device structure is provided so that architectures may make mapping
  713. * decisions on a per-device or per-bus basis.
  714. *
  715. * Returns a negative error code on failure, zero on success.
  716. */
  717. int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
  718. enum pci_mmap_state mmap_state,
  719. int write_combine)
  720. {
  721. unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
  722. struct resource *rp;
  723. int ret;
  724. rp = __pci_mmap_make_offset(dev, &offset, mmap_state);
  725. if (rp == NULL)
  726. return -EINVAL;
  727. vma->vm_pgoff = offset >> PAGE_SHIFT;
  728. vma->vm_flags |= VM_SHM | VM_LOCKED | VM_IO;
  729. vma->vm_page_prot = __pci_mmap_set_pgprot(dev, rp,
  730. vma->vm_page_prot,
  731. mmap_state, write_combine);
  732. ret = remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
  733. vma->vm_end - vma->vm_start, vma->vm_page_prot);
  734. return ret;
  735. }
  736. #ifdef CONFIG_PPC_MULTIPLATFORM
  737. static ssize_t pci_show_devspec(struct device *dev, struct device_attribute *attr, char *buf)
  738. {
  739. struct pci_dev *pdev;
  740. struct device_node *np;
  741. pdev = to_pci_dev (dev);
  742. np = pci_device_to_OF_node(pdev);
  743. if (np == NULL || np->full_name == NULL)
  744. return 0;
  745. return sprintf(buf, "%s", np->full_name);
  746. }
  747. static DEVICE_ATTR(devspec, S_IRUGO, pci_show_devspec, NULL);
  748. #endif /* CONFIG_PPC_MULTIPLATFORM */
  749. void pcibios_add_platform_entries(struct pci_dev *pdev)
  750. {
  751. #ifdef CONFIG_PPC_MULTIPLATFORM
  752. device_create_file(&pdev->dev, &dev_attr_devspec);
  753. #endif /* CONFIG_PPC_MULTIPLATFORM */
  754. }
  755. #ifdef CONFIG_PPC_MULTIPLATFORM
  756. #define ISA_SPACE_MASK 0x1
  757. #define ISA_SPACE_IO 0x1
  758. static void __devinit pci_process_ISA_OF_ranges(struct device_node *isa_node,
  759. unsigned long phb_io_base_phys,
  760. void __iomem * phb_io_base_virt)
  761. {
  762. struct isa_range *range;
  763. unsigned long pci_addr;
  764. unsigned int isa_addr;
  765. unsigned int size;
  766. int rlen = 0;
  767. range = (struct isa_range *) get_property(isa_node, "ranges", &rlen);
  768. if (range == NULL || (rlen < sizeof(struct isa_range))) {
  769. printk(KERN_ERR "no ISA ranges or unexpected isa range size,"
  770. "mapping 64k\n");
  771. __ioremap_explicit(phb_io_base_phys,
  772. (unsigned long)phb_io_base_virt,
  773. 0x10000, _PAGE_NO_CACHE | _PAGE_GUARDED);
  774. return;
  775. }
  776. /* From "ISA Binding to 1275"
  777. * The ranges property is laid out as an array of elements,
  778. * each of which comprises:
  779. * cells 0 - 1: an ISA address
  780. * cells 2 - 4: a PCI address
  781. * (size depending on dev->n_addr_cells)
  782. * cell 5: the size of the range
  783. */
  784. if ((range->isa_addr.a_hi && ISA_SPACE_MASK) == ISA_SPACE_IO) {
  785. isa_addr = range->isa_addr.a_lo;
  786. pci_addr = (unsigned long) range->pci_addr.a_mid << 32 |
  787. range->pci_addr.a_lo;
  788. /* Assume these are both zero */
  789. if ((pci_addr != 0) || (isa_addr != 0)) {
  790. printk(KERN_ERR "unexpected isa to pci mapping: %s\n",
  791. __FUNCTION__);
  792. return;
  793. }
  794. size = PAGE_ALIGN(range->size);
  795. __ioremap_explicit(phb_io_base_phys,
  796. (unsigned long) phb_io_base_virt,
  797. size, _PAGE_NO_CACHE | _PAGE_GUARDED);
  798. }
  799. }
  800. void __devinit pci_process_bridge_OF_ranges(struct pci_controller *hose,
  801. struct device_node *dev, int prim)
  802. {
  803. unsigned int *ranges, pci_space;
  804. unsigned long size;
  805. int rlen = 0;
  806. int memno = 0;
  807. struct resource *res;
  808. int np, na = prom_n_addr_cells(dev);
  809. unsigned long pci_addr, cpu_phys_addr;
  810. np = na + 5;
  811. /* From "PCI Binding to 1275"
  812. * The ranges property is laid out as an array of elements,
  813. * each of which comprises:
  814. * cells 0 - 2: a PCI address
  815. * cells 3 or 3+4: a CPU physical address
  816. * (size depending on dev->n_addr_cells)
  817. * cells 4+5 or 5+6: the size of the range
  818. */
  819. ranges = (unsigned int *) get_property(dev, "ranges", &rlen);
  820. if (ranges == NULL)
  821. return;
  822. hose->io_base_phys = 0;
  823. while ((rlen -= np * sizeof(unsigned int)) >= 0) {
  824. res = NULL;
  825. pci_space = ranges[0];
  826. pci_addr = ((unsigned long)ranges[1] << 32) | ranges[2];
  827. cpu_phys_addr = ranges[3];
  828. if (na >= 2)
  829. cpu_phys_addr = (cpu_phys_addr << 32) | ranges[4];
  830. size = ((unsigned long)ranges[na+3] << 32) | ranges[na+4];
  831. ranges += np;
  832. if (size == 0)
  833. continue;
  834. /* Now consume following elements while they are contiguous */
  835. while (rlen >= np * sizeof(unsigned int)) {
  836. unsigned long addr, phys;
  837. if (ranges[0] != pci_space)
  838. break;
  839. addr = ((unsigned long)ranges[1] << 32) | ranges[2];
  840. phys = ranges[3];
  841. if (na >= 2)
  842. phys = (phys << 32) | ranges[4];
  843. if (addr != pci_addr + size ||
  844. phys != cpu_phys_addr + size)
  845. break;
  846. size += ((unsigned long)ranges[na+3] << 32)
  847. | ranges[na+4];
  848. ranges += np;
  849. rlen -= np * sizeof(unsigned int);
  850. }
  851. switch ((pci_space >> 24) & 0x3) {
  852. case 1: /* I/O space */
  853. hose->io_base_phys = cpu_phys_addr;
  854. hose->pci_io_size = size;
  855. res = &hose->io_resource;
  856. res->flags = IORESOURCE_IO;
  857. res->start = pci_addr;
  858. DBG("phb%d: IO 0x%lx -> 0x%lx\n", hose->global_number,
  859. res->start, res->start + size - 1);
  860. break;
  861. case 2: /* memory space */
  862. memno = 0;
  863. while (memno < 3 && hose->mem_resources[memno].flags)
  864. ++memno;
  865. if (memno == 0)
  866. hose->pci_mem_offset = cpu_phys_addr - pci_addr;
  867. if (memno < 3) {
  868. res = &hose->mem_resources[memno];
  869. res->flags = IORESOURCE_MEM;
  870. res->start = cpu_phys_addr;
  871. DBG("phb%d: MEM 0x%lx -> 0x%lx\n", hose->global_number,
  872. res->start, res->start + size - 1);
  873. }
  874. break;
  875. }
  876. if (res != NULL) {
  877. res->name = dev->full_name;
  878. res->end = res->start + size - 1;
  879. res->parent = NULL;
  880. res->sibling = NULL;
  881. res->child = NULL;
  882. }
  883. }
  884. }
  885. void __init pci_setup_phb_io(struct pci_controller *hose, int primary)
  886. {
  887. unsigned long size = hose->pci_io_size;
  888. unsigned long io_virt_offset;
  889. struct resource *res;
  890. struct device_node *isa_dn;
  891. hose->io_base_virt = reserve_phb_iospace(size);
  892. DBG("phb%d io_base_phys 0x%lx io_base_virt 0x%lx\n",
  893. hose->global_number, hose->io_base_phys,
  894. (unsigned long) hose->io_base_virt);
  895. if (primary) {
  896. pci_io_base = (unsigned long)hose->io_base_virt;
  897. isa_dn = of_find_node_by_type(NULL, "isa");
  898. if (isa_dn) {
  899. isa_io_base = pci_io_base;
  900. pci_process_ISA_OF_ranges(isa_dn, hose->io_base_phys,
  901. hose->io_base_virt);
  902. of_node_put(isa_dn);
  903. /* Allow all IO */
  904. io_page_mask = -1;
  905. }
  906. }
  907. io_virt_offset = (unsigned long)hose->io_base_virt - pci_io_base;
  908. res = &hose->io_resource;
  909. res->start += io_virt_offset;
  910. res->end += io_virt_offset;
  911. }
  912. void __devinit pci_setup_phb_io_dynamic(struct pci_controller *hose,
  913. int primary)
  914. {
  915. unsigned long size = hose->pci_io_size;
  916. unsigned long io_virt_offset;
  917. struct resource *res;
  918. hose->io_base_virt = __ioremap(hose->io_base_phys, size,
  919. _PAGE_NO_CACHE | _PAGE_GUARDED);
  920. DBG("phb%d io_base_phys 0x%lx io_base_virt 0x%lx\n",
  921. hose->global_number, hose->io_base_phys,
  922. (unsigned long) hose->io_base_virt);
  923. if (primary)
  924. pci_io_base = (unsigned long)hose->io_base_virt;
  925. io_virt_offset = (unsigned long)hose->io_base_virt - pci_io_base;
  926. res = &hose->io_resource;
  927. res->start += io_virt_offset;
  928. res->end += io_virt_offset;
  929. }
  930. static int get_bus_io_range(struct pci_bus *bus, unsigned long *start_phys,
  931. unsigned long *start_virt, unsigned long *size)
  932. {
  933. struct pci_controller *hose = pci_bus_to_host(bus);
  934. struct pci_bus_region region;
  935. struct resource *res;
  936. if (bus->self) {
  937. res = bus->resource[0];
  938. pcibios_resource_to_bus(bus->self, &region, res);
  939. *start_phys = hose->io_base_phys + region.start;
  940. *start_virt = (unsigned long) hose->io_base_virt +
  941. region.start;
  942. if (region.end > region.start)
  943. *size = region.end - region.start + 1;
  944. else {
  945. printk("%s(): unexpected region 0x%lx->0x%lx\n",
  946. __FUNCTION__, region.start, region.end);
  947. return 1;
  948. }
  949. } else {
  950. /* Root Bus */
  951. res = &hose->io_resource;
  952. *start_phys = hose->io_base_phys;
  953. *start_virt = (unsigned long) hose->io_base_virt;
  954. if (res->end > res->start)
  955. *size = res->end - res->start + 1;
  956. else {
  957. printk("%s(): unexpected region 0x%lx->0x%lx\n",
  958. __FUNCTION__, res->start, res->end);
  959. return 1;
  960. }
  961. }
  962. return 0;
  963. }
  964. int unmap_bus_range(struct pci_bus *bus)
  965. {
  966. unsigned long start_phys;
  967. unsigned long start_virt;
  968. unsigned long size;
  969. if (!bus) {
  970. printk(KERN_ERR "%s() expected bus\n", __FUNCTION__);
  971. return 1;
  972. }
  973. if (get_bus_io_range(bus, &start_phys, &start_virt, &size))
  974. return 1;
  975. if (iounmap_explicit((void __iomem *) start_virt, size))
  976. return 1;
  977. return 0;
  978. }
  979. EXPORT_SYMBOL(unmap_bus_range);
  980. int remap_bus_range(struct pci_bus *bus)
  981. {
  982. unsigned long start_phys;
  983. unsigned long start_virt;
  984. unsigned long size;
  985. if (!bus) {
  986. printk(KERN_ERR "%s() expected bus\n", __FUNCTION__);
  987. return 1;
  988. }
  989. if (get_bus_io_range(bus, &start_phys, &start_virt, &size))
  990. return 1;
  991. if (start_phys == 0)
  992. return 1;
  993. printk("mapping IO %lx -> %lx, size: %lx\n", start_phys, start_virt, size);
  994. if (__ioremap_explicit(start_phys, start_virt, size,
  995. _PAGE_NO_CACHE | _PAGE_GUARDED))
  996. return 1;
  997. return 0;
  998. }
  999. EXPORT_SYMBOL(remap_bus_range);
  1000. void phbs_remap_io(void)
  1001. {
  1002. struct pci_controller *hose, *tmp;
  1003. list_for_each_entry_safe(hose, tmp, &hose_list, list_node)
  1004. remap_bus_range(hose->bus);
  1005. }
  1006. static void __devinit fixup_resource(struct resource *res, struct pci_dev *dev)
  1007. {
  1008. struct pci_controller *hose = pci_bus_to_host(dev->bus);
  1009. unsigned long start, end, mask, offset;
  1010. if (res->flags & IORESOURCE_IO) {
  1011. offset = (unsigned long)hose->io_base_virt - pci_io_base;
  1012. start = res->start += offset;
  1013. end = res->end += offset;
  1014. /* Need to allow IO access to pages that are in the
  1015. ISA range */
  1016. if (start < MAX_ISA_PORT) {
  1017. if (end > MAX_ISA_PORT)
  1018. end = MAX_ISA_PORT;
  1019. start >>= PAGE_SHIFT;
  1020. end >>= PAGE_SHIFT;
  1021. /* get the range of pages for the map */
  1022. mask = ((1 << (end+1)) - 1) ^ ((1 << start) - 1);
  1023. io_page_mask |= mask;
  1024. }
  1025. } else if (res->flags & IORESOURCE_MEM) {
  1026. res->start += hose->pci_mem_offset;
  1027. res->end += hose->pci_mem_offset;
  1028. }
  1029. }
  1030. void __devinit pcibios_fixup_device_resources(struct pci_dev *dev,
  1031. struct pci_bus *bus)
  1032. {
  1033. /* Update device resources. */
  1034. int i;
  1035. for (i = 0; i < PCI_NUM_RESOURCES; i++)
  1036. if (dev->resource[i].flags)
  1037. fixup_resource(&dev->resource[i], dev);
  1038. }
  1039. EXPORT_SYMBOL(pcibios_fixup_device_resources);
  1040. static void __devinit do_bus_setup(struct pci_bus *bus)
  1041. {
  1042. struct pci_dev *dev;
  1043. ppc_md.iommu_bus_setup(bus);
  1044. list_for_each_entry(dev, &bus->devices, bus_list)
  1045. ppc_md.iommu_dev_setup(dev);
  1046. if (ppc_md.irq_bus_setup)
  1047. ppc_md.irq_bus_setup(bus);
  1048. }
  1049. void __devinit pcibios_fixup_bus(struct pci_bus *bus)
  1050. {
  1051. struct pci_dev *dev = bus->self;
  1052. if (dev && pci_probe_only &&
  1053. (dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) {
  1054. /* This is a subordinate bridge */
  1055. pci_read_bridge_bases(bus);
  1056. pcibios_fixup_device_resources(dev, bus);
  1057. }
  1058. do_bus_setup(bus);
  1059. if (!pci_probe_only)
  1060. return;
  1061. list_for_each_entry(dev, &bus->devices, bus_list)
  1062. if ((dev->class >> 8) != PCI_CLASS_BRIDGE_PCI)
  1063. pcibios_fixup_device_resources(dev, bus);
  1064. }
  1065. EXPORT_SYMBOL(pcibios_fixup_bus);
  1066. /*
  1067. * Reads the interrupt pin to determine if interrupt is use by card.
  1068. * If the interrupt is used, then gets the interrupt line from the
  1069. * openfirmware and sets it in the pci_dev and pci_config line.
  1070. */
  1071. int pci_read_irq_line(struct pci_dev *pci_dev)
  1072. {
  1073. u8 intpin;
  1074. struct device_node *node;
  1075. pci_read_config_byte(pci_dev, PCI_INTERRUPT_PIN, &intpin);
  1076. if (intpin == 0)
  1077. return 0;
  1078. node = pci_device_to_OF_node(pci_dev);
  1079. if (node == NULL)
  1080. return -1;
  1081. if (node->n_intrs == 0)
  1082. return -1;
  1083. pci_dev->irq = node->intrs[0].line;
  1084. pci_write_config_byte(pci_dev, PCI_INTERRUPT_LINE, pci_dev->irq);
  1085. return 0;
  1086. }
  1087. EXPORT_SYMBOL(pci_read_irq_line);
  1088. void pci_resource_to_user(const struct pci_dev *dev, int bar,
  1089. const struct resource *rsrc,
  1090. u64 *start, u64 *end)
  1091. {
  1092. struct pci_controller *hose = pci_bus_to_host(dev->bus);
  1093. unsigned long offset = 0;
  1094. if (hose == NULL)
  1095. return;
  1096. if (rsrc->flags & IORESOURCE_IO)
  1097. offset = pci_io_base - (unsigned long)hose->io_base_virt +
  1098. hose->io_base_phys;
  1099. *start = rsrc->start + offset;
  1100. *end = rsrc->end + offset;
  1101. }
  1102. #endif /* CONFIG_PPC_MULTIPLATFORM */
  1103. #define IOBASE_BRIDGE_NUMBER 0
  1104. #define IOBASE_MEMORY 1
  1105. #define IOBASE_IO 2
  1106. #define IOBASE_ISA_IO 3
  1107. #define IOBASE_ISA_MEM 4
  1108. long sys_pciconfig_iobase(long which, unsigned long in_bus,
  1109. unsigned long in_devfn)
  1110. {
  1111. struct pci_controller* hose;
  1112. struct list_head *ln;
  1113. struct pci_bus *bus = NULL;
  1114. struct device_node *hose_node;
  1115. /* Argh ! Please forgive me for that hack, but that's the
  1116. * simplest way to get existing XFree to not lockup on some
  1117. * G5 machines... So when something asks for bus 0 io base
  1118. * (bus 0 is HT root), we return the AGP one instead.
  1119. */
  1120. if (machine_is_compatible("MacRISC4"))
  1121. if (in_bus == 0)
  1122. in_bus = 0xf0;
  1123. /* That syscall isn't quite compatible with PCI domains, but it's
  1124. * used on pre-domains setup. We return the first match
  1125. */
  1126. for (ln = pci_root_buses.next; ln != &pci_root_buses; ln = ln->next) {
  1127. bus = pci_bus_b(ln);
  1128. if (in_bus >= bus->number && in_bus < (bus->number + bus->subordinate))
  1129. break;
  1130. bus = NULL;
  1131. }
  1132. if (bus == NULL || bus->sysdata == NULL)
  1133. return -ENODEV;
  1134. hose_node = (struct device_node *)bus->sysdata;
  1135. hose = PCI_DN(hose_node)->phb;
  1136. switch (which) {
  1137. case IOBASE_BRIDGE_NUMBER:
  1138. return (long)hose->first_busno;
  1139. case IOBASE_MEMORY:
  1140. return (long)hose->pci_mem_offset;
  1141. case IOBASE_IO:
  1142. return (long)hose->io_base_phys;
  1143. case IOBASE_ISA_IO:
  1144. return (long)isa_io_base;
  1145. case IOBASE_ISA_MEM:
  1146. return -EINVAL;
  1147. }
  1148. return -EOPNOTSUPP;
  1149. }