pci.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293
  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. static 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. static void of_scan_pci_bridge(struct device_node *node, struct pci_dev *dev);
  296. static 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. static void __devinit of_scan_pci_bridge(struct device_node *node,
  319. struct pci_dev *dev)
  320. {
  321. struct pci_bus *bus;
  322. u32 *busrange, *ranges;
  323. int len, i, mode;
  324. struct resource *res;
  325. unsigned int flags;
  326. u64 size;
  327. /* parse bus-range property */
  328. busrange = (u32 *) get_property(node, "bus-range", &len);
  329. if (busrange == NULL || len != 8) {
  330. printk(KERN_ERR "Can't get bus-range for PCI-PCI bridge %s\n",
  331. node->full_name);
  332. return;
  333. }
  334. ranges = (u32 *) get_property(node, "ranges", &len);
  335. if (ranges == NULL) {
  336. printk(KERN_ERR "Can't get ranges for PCI-PCI bridge %s\n",
  337. node->full_name);
  338. return;
  339. }
  340. bus = pci_add_new_bus(dev->bus, dev, busrange[0]);
  341. if (!bus) {
  342. printk(KERN_ERR "Failed to create pci bus for %s\n",
  343. node->full_name);
  344. return;
  345. }
  346. bus->primary = dev->bus->number;
  347. bus->subordinate = busrange[1];
  348. bus->bridge_ctl = 0;
  349. bus->sysdata = node;
  350. /* parse ranges property */
  351. /* PCI #address-cells == 3 and #size-cells == 2 always */
  352. res = &dev->resource[PCI_BRIDGE_RESOURCES];
  353. for (i = 0; i < PCI_NUM_RESOURCES - PCI_BRIDGE_RESOURCES; ++i) {
  354. res->flags = 0;
  355. bus->resource[i] = res;
  356. ++res;
  357. }
  358. i = 1;
  359. for (; len >= 32; len -= 32, ranges += 8) {
  360. flags = pci_parse_of_flags(ranges[0]);
  361. size = GET_64BIT(ranges, 6);
  362. if (flags == 0 || size == 0)
  363. continue;
  364. if (flags & IORESOURCE_IO) {
  365. res = bus->resource[0];
  366. if (res->flags) {
  367. printk(KERN_ERR "PCI: ignoring extra I/O range"
  368. " for bridge %s\n", node->full_name);
  369. continue;
  370. }
  371. } else {
  372. if (i >= PCI_NUM_RESOURCES - PCI_BRIDGE_RESOURCES) {
  373. printk(KERN_ERR "PCI: too many memory ranges"
  374. " for bridge %s\n", node->full_name);
  375. continue;
  376. }
  377. res = bus->resource[i];
  378. ++i;
  379. }
  380. res->start = GET_64BIT(ranges, 1);
  381. res->end = res->start + size - 1;
  382. res->flags = flags;
  383. fixup_resource(res, dev);
  384. }
  385. sprintf(bus->name, "PCI Bus %04x:%02x", pci_domain_nr(bus),
  386. bus->number);
  387. mode = PCI_PROBE_NORMAL;
  388. if (ppc_md.pci_probe_mode)
  389. mode = ppc_md.pci_probe_mode(bus);
  390. if (mode == PCI_PROBE_DEVTREE)
  391. of_scan_bus(node, bus);
  392. else if (mode == PCI_PROBE_NORMAL)
  393. pci_scan_child_bus(bus);
  394. }
  395. #endif /* CONFIG_PPC_MULTIPLATFORM */
  396. static void __devinit scan_phb(struct pci_controller *hose)
  397. {
  398. struct pci_bus *bus;
  399. struct device_node *node = hose->arch_data;
  400. int i, mode;
  401. struct resource *res;
  402. bus = pci_create_bus(NULL, hose->first_busno, hose->ops, node);
  403. if (bus == NULL) {
  404. printk(KERN_ERR "Failed to create bus for PCI domain %04x\n",
  405. hose->global_number);
  406. return;
  407. }
  408. bus->secondary = hose->first_busno;
  409. hose->bus = bus;
  410. bus->resource[0] = res = &hose->io_resource;
  411. if (res->flags && request_resource(&ioport_resource, res))
  412. printk(KERN_ERR "Failed to request PCI IO region "
  413. "on PCI domain %04x\n", hose->global_number);
  414. for (i = 0; i < 3; ++i) {
  415. res = &hose->mem_resources[i];
  416. bus->resource[i+1] = res;
  417. if (res->flags && request_resource(&iomem_resource, res))
  418. printk(KERN_ERR "Failed to request PCI memory region "
  419. "on PCI domain %04x\n", hose->global_number);
  420. }
  421. mode = PCI_PROBE_NORMAL;
  422. #ifdef CONFIG_PPC_MULTIPLATFORM
  423. if (ppc_md.pci_probe_mode)
  424. mode = ppc_md.pci_probe_mode(bus);
  425. if (mode == PCI_PROBE_DEVTREE) {
  426. bus->subordinate = hose->last_busno;
  427. of_scan_bus(node, bus);
  428. }
  429. #endif /* CONFIG_PPC_MULTIPLATFORM */
  430. if (mode == PCI_PROBE_NORMAL)
  431. hose->last_busno = bus->subordinate = pci_scan_child_bus(bus);
  432. pci_bus_add_devices(bus);
  433. }
  434. static int __init pcibios_init(void)
  435. {
  436. struct pci_controller *hose, *tmp;
  437. /* For now, override phys_mem_access_prot. If we need it,
  438. * later, we may move that initialization to each ppc_md
  439. */
  440. ppc_md.phys_mem_access_prot = pci_phys_mem_access_prot;
  441. #ifdef CONFIG_PPC_ISERIES
  442. iSeries_pcibios_init();
  443. #endif
  444. printk("PCI: Probing PCI hardware\n");
  445. /* Scan all of the recorded PCI controllers. */
  446. list_for_each_entry_safe(hose, tmp, &hose_list, list_node)
  447. scan_phb(hose);
  448. #ifndef CONFIG_PPC_ISERIES
  449. if (pci_probe_only)
  450. pcibios_claim_of_setup();
  451. else
  452. /* FIXME: `else' will be removed when
  453. pci_assign_unassigned_resources() is able to work
  454. correctly with [partially] allocated PCI tree. */
  455. pci_assign_unassigned_resources();
  456. #endif /* !CONFIG_PPC_ISERIES */
  457. /* Call machine dependent final fixup */
  458. if (ppc_md.pcibios_fixup)
  459. ppc_md.pcibios_fixup();
  460. /* Cache the location of the ISA bridge (if we have one) */
  461. ppc64_isabridge_dev = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, NULL);
  462. if (ppc64_isabridge_dev != NULL)
  463. printk("ISA bridge at %s\n", pci_name(ppc64_isabridge_dev));
  464. printk("PCI: Probing PCI hardware done\n");
  465. return 0;
  466. }
  467. subsys_initcall(pcibios_init);
  468. char __init *pcibios_setup(char *str)
  469. {
  470. return str;
  471. }
  472. int pcibios_enable_device(struct pci_dev *dev, int mask)
  473. {
  474. u16 cmd, oldcmd;
  475. int i;
  476. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  477. oldcmd = cmd;
  478. for (i = 0; i < PCI_NUM_RESOURCES; i++) {
  479. struct resource *res = &dev->resource[i];
  480. /* Only set up the requested stuff */
  481. if (!(mask & (1<<i)))
  482. continue;
  483. if (res->flags & IORESOURCE_IO)
  484. cmd |= PCI_COMMAND_IO;
  485. if (res->flags & IORESOURCE_MEM)
  486. cmd |= PCI_COMMAND_MEMORY;
  487. }
  488. if (cmd != oldcmd) {
  489. printk(KERN_DEBUG "PCI: Enabling device: (%s), cmd %x\n",
  490. pci_name(dev), cmd);
  491. /* Enable the appropriate bits in the PCI command register. */
  492. pci_write_config_word(dev, PCI_COMMAND, cmd);
  493. }
  494. return 0;
  495. }
  496. /*
  497. * Return the domain number for this bus.
  498. */
  499. int pci_domain_nr(struct pci_bus *bus)
  500. {
  501. #ifdef CONFIG_PPC_ISERIES
  502. return 0;
  503. #else
  504. struct pci_controller *hose = pci_bus_to_host(bus);
  505. return hose->global_number;
  506. #endif
  507. }
  508. EXPORT_SYMBOL(pci_domain_nr);
  509. /* Decide whether to display the domain number in /proc */
  510. int pci_proc_domain(struct pci_bus *bus)
  511. {
  512. #ifdef CONFIG_PPC_ISERIES
  513. return 0;
  514. #else
  515. struct pci_controller *hose = pci_bus_to_host(bus);
  516. return hose->buid;
  517. #endif
  518. }
  519. /*
  520. * Platform support for /proc/bus/pci/X/Y mmap()s,
  521. * modelled on the sparc64 implementation by Dave Miller.
  522. * -- paulus.
  523. */
  524. /*
  525. * Adjust vm_pgoff of VMA such that it is the physical page offset
  526. * corresponding to the 32-bit pci bus offset for DEV requested by the user.
  527. *
  528. * Basically, the user finds the base address for his device which he wishes
  529. * to mmap. They read the 32-bit value from the config space base register,
  530. * add whatever PAGE_SIZE multiple offset they wish, and feed this into the
  531. * offset parameter of mmap on /proc/bus/pci/XXX for that device.
  532. *
  533. * Returns negative error code on failure, zero on success.
  534. */
  535. static struct resource *__pci_mmap_make_offset(struct pci_dev *dev,
  536. unsigned long *offset,
  537. enum pci_mmap_state mmap_state)
  538. {
  539. struct pci_controller *hose = pci_bus_to_host(dev->bus);
  540. unsigned long io_offset = 0;
  541. int i, res_bit;
  542. if (hose == 0)
  543. return NULL; /* should never happen */
  544. /* If memory, add on the PCI bridge address offset */
  545. if (mmap_state == pci_mmap_mem) {
  546. *offset += hose->pci_mem_offset;
  547. res_bit = IORESOURCE_MEM;
  548. } else {
  549. io_offset = (unsigned long)hose->io_base_virt - pci_io_base;
  550. *offset += io_offset;
  551. res_bit = IORESOURCE_IO;
  552. }
  553. /*
  554. * Check that the offset requested corresponds to one of the
  555. * resources of the device.
  556. */
  557. for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
  558. struct resource *rp = &dev->resource[i];
  559. int flags = rp->flags;
  560. /* treat ROM as memory (should be already) */
  561. if (i == PCI_ROM_RESOURCE)
  562. flags |= IORESOURCE_MEM;
  563. /* Active and same type? */
  564. if ((flags & res_bit) == 0)
  565. continue;
  566. /* In the range of this resource? */
  567. if (*offset < (rp->start & PAGE_MASK) || *offset > rp->end)
  568. continue;
  569. /* found it! construct the final physical address */
  570. if (mmap_state == pci_mmap_io)
  571. *offset += hose->io_base_phys - io_offset;
  572. return rp;
  573. }
  574. return NULL;
  575. }
  576. /*
  577. * Set vm_page_prot of VMA, as appropriate for this architecture, for a pci
  578. * device mapping.
  579. */
  580. static pgprot_t __pci_mmap_set_pgprot(struct pci_dev *dev, struct resource *rp,
  581. pgprot_t protection,
  582. enum pci_mmap_state mmap_state,
  583. int write_combine)
  584. {
  585. unsigned long prot = pgprot_val(protection);
  586. /* Write combine is always 0 on non-memory space mappings. On
  587. * memory space, if the user didn't pass 1, we check for a
  588. * "prefetchable" resource. This is a bit hackish, but we use
  589. * this to workaround the inability of /sysfs to provide a write
  590. * combine bit
  591. */
  592. if (mmap_state != pci_mmap_mem)
  593. write_combine = 0;
  594. else if (write_combine == 0) {
  595. if (rp->flags & IORESOURCE_PREFETCH)
  596. write_combine = 1;
  597. }
  598. /* XXX would be nice to have a way to ask for write-through */
  599. prot |= _PAGE_NO_CACHE;
  600. if (write_combine)
  601. prot &= ~_PAGE_GUARDED;
  602. else
  603. prot |= _PAGE_GUARDED;
  604. printk("PCI map for %s:%lx, prot: %lx\n", pci_name(dev), rp->start,
  605. prot);
  606. return __pgprot(prot);
  607. }
  608. /*
  609. * This one is used by /dev/mem and fbdev who have no clue about the
  610. * PCI device, it tries to find the PCI device first and calls the
  611. * above routine
  612. */
  613. pgprot_t pci_phys_mem_access_prot(struct file *file,
  614. unsigned long offset,
  615. unsigned long size,
  616. pgprot_t protection)
  617. {
  618. struct pci_dev *pdev = NULL;
  619. struct resource *found = NULL;
  620. unsigned long prot = pgprot_val(protection);
  621. int i;
  622. if (page_is_ram(offset >> PAGE_SHIFT))
  623. return __pgprot(prot);
  624. prot |= _PAGE_NO_CACHE | _PAGE_GUARDED;
  625. for_each_pci_dev(pdev) {
  626. for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
  627. struct resource *rp = &pdev->resource[i];
  628. int flags = rp->flags;
  629. /* Active and same type? */
  630. if ((flags & IORESOURCE_MEM) == 0)
  631. continue;
  632. /* In the range of this resource? */
  633. if (offset < (rp->start & PAGE_MASK) ||
  634. offset > rp->end)
  635. continue;
  636. found = rp;
  637. break;
  638. }
  639. if (found)
  640. break;
  641. }
  642. if (found) {
  643. if (found->flags & IORESOURCE_PREFETCH)
  644. prot &= ~_PAGE_GUARDED;
  645. pci_dev_put(pdev);
  646. }
  647. DBG("non-PCI map for %lx, prot: %lx\n", offset, prot);
  648. return __pgprot(prot);
  649. }
  650. /*
  651. * Perform the actual remap of the pages for a PCI device mapping, as
  652. * appropriate for this architecture. The region in the process to map
  653. * is described by vm_start and vm_end members of VMA, the base physical
  654. * address is found in vm_pgoff.
  655. * The pci device structure is provided so that architectures may make mapping
  656. * decisions on a per-device or per-bus basis.
  657. *
  658. * Returns a negative error code on failure, zero on success.
  659. */
  660. int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
  661. enum pci_mmap_state mmap_state,
  662. int write_combine)
  663. {
  664. unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
  665. struct resource *rp;
  666. int ret;
  667. rp = __pci_mmap_make_offset(dev, &offset, mmap_state);
  668. if (rp == NULL)
  669. return -EINVAL;
  670. vma->vm_pgoff = offset >> PAGE_SHIFT;
  671. vma->vm_flags |= VM_SHM | VM_LOCKED | VM_IO;
  672. vma->vm_page_prot = __pci_mmap_set_pgprot(dev, rp,
  673. vma->vm_page_prot,
  674. mmap_state, write_combine);
  675. ret = remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
  676. vma->vm_end - vma->vm_start, vma->vm_page_prot);
  677. return ret;
  678. }
  679. #ifdef CONFIG_PPC_MULTIPLATFORM
  680. static ssize_t pci_show_devspec(struct device *dev, struct device_attribute *attr, char *buf)
  681. {
  682. struct pci_dev *pdev;
  683. struct device_node *np;
  684. pdev = to_pci_dev (dev);
  685. np = pci_device_to_OF_node(pdev);
  686. if (np == NULL || np->full_name == NULL)
  687. return 0;
  688. return sprintf(buf, "%s", np->full_name);
  689. }
  690. static DEVICE_ATTR(devspec, S_IRUGO, pci_show_devspec, NULL);
  691. #endif /* CONFIG_PPC_MULTIPLATFORM */
  692. void pcibios_add_platform_entries(struct pci_dev *pdev)
  693. {
  694. #ifdef CONFIG_PPC_MULTIPLATFORM
  695. device_create_file(&pdev->dev, &dev_attr_devspec);
  696. #endif /* CONFIG_PPC_MULTIPLATFORM */
  697. }
  698. #ifdef CONFIG_PPC_MULTIPLATFORM
  699. #define ISA_SPACE_MASK 0x1
  700. #define ISA_SPACE_IO 0x1
  701. static void __devinit pci_process_ISA_OF_ranges(struct device_node *isa_node,
  702. unsigned long phb_io_base_phys,
  703. void __iomem * phb_io_base_virt)
  704. {
  705. struct isa_range *range;
  706. unsigned long pci_addr;
  707. unsigned int isa_addr;
  708. unsigned int size;
  709. int rlen = 0;
  710. range = (struct isa_range *) get_property(isa_node, "ranges", &rlen);
  711. if (range == NULL || (rlen < sizeof(struct isa_range))) {
  712. printk(KERN_ERR "no ISA ranges or unexpected isa range size,"
  713. "mapping 64k\n");
  714. __ioremap_explicit(phb_io_base_phys,
  715. (unsigned long)phb_io_base_virt,
  716. 0x10000, _PAGE_NO_CACHE | _PAGE_GUARDED);
  717. return;
  718. }
  719. /* From "ISA Binding to 1275"
  720. * The ranges property is laid out as an array of elements,
  721. * each of which comprises:
  722. * cells 0 - 1: an ISA address
  723. * cells 2 - 4: a PCI address
  724. * (size depending on dev->n_addr_cells)
  725. * cell 5: the size of the range
  726. */
  727. if ((range->isa_addr.a_hi && ISA_SPACE_MASK) == ISA_SPACE_IO) {
  728. isa_addr = range->isa_addr.a_lo;
  729. pci_addr = (unsigned long) range->pci_addr.a_mid << 32 |
  730. range->pci_addr.a_lo;
  731. /* Assume these are both zero */
  732. if ((pci_addr != 0) || (isa_addr != 0)) {
  733. printk(KERN_ERR "unexpected isa to pci mapping: %s\n",
  734. __FUNCTION__);
  735. return;
  736. }
  737. size = PAGE_ALIGN(range->size);
  738. __ioremap_explicit(phb_io_base_phys,
  739. (unsigned long) phb_io_base_virt,
  740. size, _PAGE_NO_CACHE | _PAGE_GUARDED);
  741. }
  742. }
  743. void __devinit pci_process_bridge_OF_ranges(struct pci_controller *hose,
  744. struct device_node *dev)
  745. {
  746. unsigned int *ranges;
  747. unsigned long size;
  748. int rlen = 0;
  749. int memno = 0;
  750. struct resource *res;
  751. int np, na = prom_n_addr_cells(dev);
  752. unsigned long pci_addr, cpu_phys_addr;
  753. np = na + 5;
  754. /* From "PCI Binding to 1275"
  755. * The ranges property is laid out as an array of elements,
  756. * each of which comprises:
  757. * cells 0 - 2: a PCI address
  758. * cells 3 or 3+4: a CPU physical address
  759. * (size depending on dev->n_addr_cells)
  760. * cells 4+5 or 5+6: the size of the range
  761. */
  762. rlen = 0;
  763. hose->io_base_phys = 0;
  764. ranges = (unsigned int *) get_property(dev, "ranges", &rlen);
  765. while ((rlen -= np * sizeof(unsigned int)) >= 0) {
  766. res = NULL;
  767. pci_addr = (unsigned long)ranges[1] << 32 | ranges[2];
  768. cpu_phys_addr = ranges[3];
  769. if (na == 2)
  770. cpu_phys_addr = cpu_phys_addr << 32 | ranges[4];
  771. size = (unsigned long)ranges[na+3] << 32 | ranges[na+4];
  772. if (size == 0)
  773. continue;
  774. switch ((ranges[0] >> 24) & 0x3) {
  775. case 1: /* I/O space */
  776. hose->io_base_phys = cpu_phys_addr;
  777. hose->pci_io_size = size;
  778. res = &hose->io_resource;
  779. res->flags = IORESOURCE_IO;
  780. res->start = pci_addr;
  781. DBG("phb%d: IO 0x%lx -> 0x%lx\n", hose->global_number,
  782. res->start, res->start + size - 1);
  783. break;
  784. case 2: /* memory space */
  785. memno = 0;
  786. while (memno < 3 && hose->mem_resources[memno].flags)
  787. ++memno;
  788. if (memno == 0)
  789. hose->pci_mem_offset = cpu_phys_addr - pci_addr;
  790. if (memno < 3) {
  791. res = &hose->mem_resources[memno];
  792. res->flags = IORESOURCE_MEM;
  793. res->start = cpu_phys_addr;
  794. DBG("phb%d: MEM 0x%lx -> 0x%lx\n", hose->global_number,
  795. res->start, res->start + size - 1);
  796. }
  797. break;
  798. }
  799. if (res != NULL) {
  800. res->name = dev->full_name;
  801. res->end = res->start + size - 1;
  802. res->parent = NULL;
  803. res->sibling = NULL;
  804. res->child = NULL;
  805. }
  806. ranges += np;
  807. }
  808. }
  809. void __init pci_setup_phb_io(struct pci_controller *hose, int primary)
  810. {
  811. unsigned long size = hose->pci_io_size;
  812. unsigned long io_virt_offset;
  813. struct resource *res;
  814. struct device_node *isa_dn;
  815. hose->io_base_virt = reserve_phb_iospace(size);
  816. DBG("phb%d io_base_phys 0x%lx io_base_virt 0x%lx\n",
  817. hose->global_number, hose->io_base_phys,
  818. (unsigned long) hose->io_base_virt);
  819. if (primary) {
  820. pci_io_base = (unsigned long)hose->io_base_virt;
  821. isa_dn = of_find_node_by_type(NULL, "isa");
  822. if (isa_dn) {
  823. isa_io_base = pci_io_base;
  824. pci_process_ISA_OF_ranges(isa_dn, hose->io_base_phys,
  825. hose->io_base_virt);
  826. of_node_put(isa_dn);
  827. /* Allow all IO */
  828. io_page_mask = -1;
  829. }
  830. }
  831. io_virt_offset = (unsigned long)hose->io_base_virt - pci_io_base;
  832. res = &hose->io_resource;
  833. res->start += io_virt_offset;
  834. res->end += io_virt_offset;
  835. }
  836. void __devinit pci_setup_phb_io_dynamic(struct pci_controller *hose,
  837. int primary)
  838. {
  839. unsigned long size = hose->pci_io_size;
  840. unsigned long io_virt_offset;
  841. struct resource *res;
  842. hose->io_base_virt = __ioremap(hose->io_base_phys, size,
  843. _PAGE_NO_CACHE | _PAGE_GUARDED);
  844. DBG("phb%d io_base_phys 0x%lx io_base_virt 0x%lx\n",
  845. hose->global_number, hose->io_base_phys,
  846. (unsigned long) hose->io_base_virt);
  847. if (primary)
  848. pci_io_base = (unsigned long)hose->io_base_virt;
  849. io_virt_offset = (unsigned long)hose->io_base_virt - pci_io_base;
  850. res = &hose->io_resource;
  851. res->start += io_virt_offset;
  852. res->end += io_virt_offset;
  853. }
  854. static int get_bus_io_range(struct pci_bus *bus, unsigned long *start_phys,
  855. unsigned long *start_virt, unsigned long *size)
  856. {
  857. struct pci_controller *hose = pci_bus_to_host(bus);
  858. struct pci_bus_region region;
  859. struct resource *res;
  860. if (bus->self) {
  861. res = bus->resource[0];
  862. pcibios_resource_to_bus(bus->self, &region, res);
  863. *start_phys = hose->io_base_phys + region.start;
  864. *start_virt = (unsigned long) hose->io_base_virt +
  865. region.start;
  866. if (region.end > region.start)
  867. *size = region.end - region.start + 1;
  868. else {
  869. printk("%s(): unexpected region 0x%lx->0x%lx\n",
  870. __FUNCTION__, region.start, region.end);
  871. return 1;
  872. }
  873. } else {
  874. /* Root Bus */
  875. res = &hose->io_resource;
  876. *start_phys = hose->io_base_phys;
  877. *start_virt = (unsigned long) hose->io_base_virt;
  878. if (res->end > res->start)
  879. *size = res->end - res->start + 1;
  880. else {
  881. printk("%s(): unexpected region 0x%lx->0x%lx\n",
  882. __FUNCTION__, res->start, res->end);
  883. return 1;
  884. }
  885. }
  886. return 0;
  887. }
  888. int unmap_bus_range(struct pci_bus *bus)
  889. {
  890. unsigned long start_phys;
  891. unsigned long start_virt;
  892. unsigned long size;
  893. if (!bus) {
  894. printk(KERN_ERR "%s() expected bus\n", __FUNCTION__);
  895. return 1;
  896. }
  897. if (get_bus_io_range(bus, &start_phys, &start_virt, &size))
  898. return 1;
  899. if (iounmap_explicit((void __iomem *) start_virt, size))
  900. return 1;
  901. return 0;
  902. }
  903. EXPORT_SYMBOL(unmap_bus_range);
  904. int remap_bus_range(struct pci_bus *bus)
  905. {
  906. unsigned long start_phys;
  907. unsigned long start_virt;
  908. unsigned long size;
  909. if (!bus) {
  910. printk(KERN_ERR "%s() expected bus\n", __FUNCTION__);
  911. return 1;
  912. }
  913. if (get_bus_io_range(bus, &start_phys, &start_virt, &size))
  914. return 1;
  915. printk("mapping IO %lx -> %lx, size: %lx\n", start_phys, start_virt, size);
  916. if (__ioremap_explicit(start_phys, start_virt, size,
  917. _PAGE_NO_CACHE | _PAGE_GUARDED))
  918. return 1;
  919. return 0;
  920. }
  921. EXPORT_SYMBOL(remap_bus_range);
  922. void phbs_remap_io(void)
  923. {
  924. struct pci_controller *hose, *tmp;
  925. list_for_each_entry_safe(hose, tmp, &hose_list, list_node)
  926. remap_bus_range(hose->bus);
  927. }
  928. /*
  929. * ppc64 can have multifunction devices that do not respond to function 0.
  930. * In this case we must scan all functions.
  931. * XXX this can go now, we use the OF device tree in all the
  932. * cases that caused problems. -- paulus
  933. */
  934. int pcibios_scan_all_fns(struct pci_bus *bus, int devfn)
  935. {
  936. return 0;
  937. }
  938. static void __devinit fixup_resource(struct resource *res, struct pci_dev *dev)
  939. {
  940. struct pci_controller *hose = pci_bus_to_host(dev->bus);
  941. unsigned long start, end, mask, offset;
  942. if (res->flags & IORESOURCE_IO) {
  943. offset = (unsigned long)hose->io_base_virt - pci_io_base;
  944. start = res->start += offset;
  945. end = res->end += offset;
  946. /* Need to allow IO access to pages that are in the
  947. ISA range */
  948. if (start < MAX_ISA_PORT) {
  949. if (end > MAX_ISA_PORT)
  950. end = MAX_ISA_PORT;
  951. start >>= PAGE_SHIFT;
  952. end >>= PAGE_SHIFT;
  953. /* get the range of pages for the map */
  954. mask = ((1 << (end+1)) - 1) ^ ((1 << start) - 1);
  955. io_page_mask |= mask;
  956. }
  957. } else if (res->flags & IORESOURCE_MEM) {
  958. res->start += hose->pci_mem_offset;
  959. res->end += hose->pci_mem_offset;
  960. }
  961. }
  962. void __devinit pcibios_fixup_device_resources(struct pci_dev *dev,
  963. struct pci_bus *bus)
  964. {
  965. /* Update device resources. */
  966. int i;
  967. for (i = 0; i < PCI_NUM_RESOURCES; i++)
  968. if (dev->resource[i].flags)
  969. fixup_resource(&dev->resource[i], dev);
  970. }
  971. EXPORT_SYMBOL(pcibios_fixup_device_resources);
  972. static void __devinit do_bus_setup(struct pci_bus *bus)
  973. {
  974. struct pci_dev *dev;
  975. ppc_md.iommu_bus_setup(bus);
  976. list_for_each_entry(dev, &bus->devices, bus_list)
  977. ppc_md.iommu_dev_setup(dev);
  978. if (ppc_md.irq_bus_setup)
  979. ppc_md.irq_bus_setup(bus);
  980. }
  981. void __devinit pcibios_fixup_bus(struct pci_bus *bus)
  982. {
  983. struct pci_dev *dev = bus->self;
  984. if (dev && pci_probe_only &&
  985. (dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) {
  986. /* This is a subordinate bridge */
  987. pci_read_bridge_bases(bus);
  988. pcibios_fixup_device_resources(dev, bus);
  989. }
  990. do_bus_setup(bus);
  991. if (!pci_probe_only)
  992. return;
  993. list_for_each_entry(dev, &bus->devices, bus_list)
  994. if ((dev->class >> 8) != PCI_CLASS_BRIDGE_PCI)
  995. pcibios_fixup_device_resources(dev, bus);
  996. }
  997. EXPORT_SYMBOL(pcibios_fixup_bus);
  998. /*
  999. * Reads the interrupt pin to determine if interrupt is use by card.
  1000. * If the interrupt is used, then gets the interrupt line from the
  1001. * openfirmware and sets it in the pci_dev and pci_config line.
  1002. */
  1003. int pci_read_irq_line(struct pci_dev *pci_dev)
  1004. {
  1005. u8 intpin;
  1006. struct device_node *node;
  1007. pci_read_config_byte(pci_dev, PCI_INTERRUPT_PIN, &intpin);
  1008. if (intpin == 0)
  1009. return 0;
  1010. node = pci_device_to_OF_node(pci_dev);
  1011. if (node == NULL)
  1012. return -1;
  1013. if (node->n_intrs == 0)
  1014. return -1;
  1015. pci_dev->irq = node->intrs[0].line;
  1016. pci_write_config_byte(pci_dev, PCI_INTERRUPT_LINE, pci_dev->irq);
  1017. return 0;
  1018. }
  1019. EXPORT_SYMBOL(pci_read_irq_line);
  1020. void pci_resource_to_user(const struct pci_dev *dev, int bar,
  1021. const struct resource *rsrc,
  1022. u64 *start, u64 *end)
  1023. {
  1024. struct pci_controller *hose = pci_bus_to_host(dev->bus);
  1025. unsigned long offset = 0;
  1026. if (hose == NULL)
  1027. return;
  1028. if (rsrc->flags & IORESOURCE_IO)
  1029. offset = pci_io_base - (unsigned long)hose->io_base_virt +
  1030. hose->io_base_phys;
  1031. *start = rsrc->start + offset;
  1032. *end = rsrc->end + offset;
  1033. }
  1034. #endif /* CONFIG_PPC_MULTIPLATFORM */
  1035. #define IOBASE_BRIDGE_NUMBER 0
  1036. #define IOBASE_MEMORY 1
  1037. #define IOBASE_IO 2
  1038. #define IOBASE_ISA_IO 3
  1039. #define IOBASE_ISA_MEM 4
  1040. long sys_pciconfig_iobase(long which, unsigned long in_bus,
  1041. unsigned long in_devfn)
  1042. {
  1043. struct pci_controller* hose;
  1044. struct list_head *ln;
  1045. struct pci_bus *bus = NULL;
  1046. struct device_node *hose_node;
  1047. /* Argh ! Please forgive me for that hack, but that's the
  1048. * simplest way to get existing XFree to not lockup on some
  1049. * G5 machines... So when something asks for bus 0 io base
  1050. * (bus 0 is HT root), we return the AGP one instead.
  1051. */
  1052. #ifdef CONFIG_PPC_PMAC
  1053. if (systemcfg->platform == PLATFORM_POWERMAC &&
  1054. machine_is_compatible("MacRISC4"))
  1055. if (in_bus == 0)
  1056. in_bus = 0xf0;
  1057. #endif /* CONFIG_PPC_PMAC */
  1058. /* That syscall isn't quite compatible with PCI domains, but it's
  1059. * used on pre-domains setup. We return the first match
  1060. */
  1061. for (ln = pci_root_buses.next; ln != &pci_root_buses; ln = ln->next) {
  1062. bus = pci_bus_b(ln);
  1063. if (in_bus >= bus->number && in_bus < (bus->number + bus->subordinate))
  1064. break;
  1065. bus = NULL;
  1066. }
  1067. if (bus == NULL || bus->sysdata == NULL)
  1068. return -ENODEV;
  1069. hose_node = (struct device_node *)bus->sysdata;
  1070. hose = PCI_DN(hose_node)->phb;
  1071. switch (which) {
  1072. case IOBASE_BRIDGE_NUMBER:
  1073. return (long)hose->first_busno;
  1074. case IOBASE_MEMORY:
  1075. return (long)hose->pci_mem_offset;
  1076. case IOBASE_IO:
  1077. return (long)hose->io_base_phys;
  1078. case IOBASE_ISA_IO:
  1079. return (long)isa_io_base;
  1080. case IOBASE_ISA_MEM:
  1081. return -EINVAL;
  1082. }
  1083. return -EOPNOTSUPP;
  1084. }