pci.c 34 KB

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