bios32.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. /*
  2. * linux/arch/arm/kernel/bios32.c
  3. *
  4. * PCI bios-type initialisation for PCI machines
  5. *
  6. * Bits taken from various places.
  7. */
  8. #include <linux/config.h>
  9. #include <linux/module.h>
  10. #include <linux/kernel.h>
  11. #include <linux/pci.h>
  12. #include <linux/slab.h>
  13. #include <linux/init.h>
  14. #include <asm/io.h>
  15. #include <asm/mach-types.h>
  16. #include <asm/mach/pci.h>
  17. static int debug_pci;
  18. static int use_firmware;
  19. /*
  20. * We can't use pci_find_device() here since we are
  21. * called from interrupt context.
  22. */
  23. static void pcibios_bus_report_status(struct pci_bus *bus, u_int status_mask, int warn)
  24. {
  25. struct pci_dev *dev;
  26. list_for_each_entry(dev, &bus->devices, bus_list) {
  27. u16 status;
  28. /*
  29. * ignore host bridge - we handle
  30. * that separately
  31. */
  32. if (dev->bus->number == 0 && dev->devfn == 0)
  33. continue;
  34. pci_read_config_word(dev, PCI_STATUS, &status);
  35. if (status == 0xffff)
  36. continue;
  37. if ((status & status_mask) == 0)
  38. continue;
  39. /* clear the status errors */
  40. pci_write_config_word(dev, PCI_STATUS, status & status_mask);
  41. if (warn)
  42. printk("(%s: %04X) ", pci_name(dev), status);
  43. }
  44. list_for_each_entry(dev, &bus->devices, bus_list)
  45. if (dev->subordinate)
  46. pcibios_bus_report_status(dev->subordinate, status_mask, warn);
  47. }
  48. void pcibios_report_status(u_int status_mask, int warn)
  49. {
  50. struct list_head *l;
  51. list_for_each(l, &pci_root_buses) {
  52. struct pci_bus *bus = pci_bus_b(l);
  53. pcibios_bus_report_status(bus, status_mask, warn);
  54. }
  55. }
  56. /*
  57. * We don't use this to fix the device, but initialisation of it.
  58. * It's not the correct use for this, but it works.
  59. * Note that the arbiter/ISA bridge appears to be buggy, specifically in
  60. * the following area:
  61. * 1. park on CPU
  62. * 2. ISA bridge ping-pong
  63. * 3. ISA bridge master handling of target RETRY
  64. *
  65. * Bug 3 is responsible for the sound DMA grinding to a halt. We now
  66. * live with bug 2.
  67. */
  68. static void __devinit pci_fixup_83c553(struct pci_dev *dev)
  69. {
  70. /*
  71. * Set memory region to start at address 0, and enable IO
  72. */
  73. pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, PCI_BASE_ADDRESS_SPACE_MEMORY);
  74. pci_write_config_word(dev, PCI_COMMAND, PCI_COMMAND_IO);
  75. dev->resource[0].end -= dev->resource[0].start;
  76. dev->resource[0].start = 0;
  77. /*
  78. * All memory requests from ISA to be channelled to PCI
  79. */
  80. pci_write_config_byte(dev, 0x48, 0xff);
  81. /*
  82. * Enable ping-pong on bus master to ISA bridge transactions.
  83. * This improves the sound DMA substantially. The fixed
  84. * priority arbiter also helps (see below).
  85. */
  86. pci_write_config_byte(dev, 0x42, 0x01);
  87. /*
  88. * Enable PCI retry
  89. */
  90. pci_write_config_byte(dev, 0x40, 0x22);
  91. /*
  92. * We used to set the arbiter to "park on last master" (bit
  93. * 1 set), but unfortunately the CyberPro does not park the
  94. * bus. We must therefore park on CPU. Unfortunately, this
  95. * may trigger yet another bug in the 553.
  96. */
  97. pci_write_config_byte(dev, 0x83, 0x02);
  98. /*
  99. * Make the ISA DMA request lowest priority, and disable
  100. * rotating priorities completely.
  101. */
  102. pci_write_config_byte(dev, 0x80, 0x11);
  103. pci_write_config_byte(dev, 0x81, 0x00);
  104. /*
  105. * Route INTA input to IRQ 11, and set IRQ11 to be level
  106. * sensitive.
  107. */
  108. pci_write_config_word(dev, 0x44, 0xb000);
  109. outb(0x08, 0x4d1);
  110. }
  111. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_WINBOND, PCI_DEVICE_ID_WINBOND_83C553, pci_fixup_83c553);
  112. static void __devinit pci_fixup_unassign(struct pci_dev *dev)
  113. {
  114. dev->resource[0].end -= dev->resource[0].start;
  115. dev->resource[0].start = 0;
  116. }
  117. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_WINBOND2, PCI_DEVICE_ID_WINBOND2_89C940F, pci_fixup_unassign);
  118. /*
  119. * Prevent the PCI layer from seeing the resources allocated to this device
  120. * if it is the host bridge by marking it as such. These resources are of
  121. * no consequence to the PCI layer (they are handled elsewhere).
  122. */
  123. static void __devinit pci_fixup_dec21285(struct pci_dev *dev)
  124. {
  125. int i;
  126. if (dev->devfn == 0) {
  127. dev->class &= 0xff;
  128. dev->class |= PCI_CLASS_BRIDGE_HOST << 8;
  129. for (i = 0; i < PCI_NUM_RESOURCES; i++) {
  130. dev->resource[i].start = 0;
  131. dev->resource[i].end = 0;
  132. dev->resource[i].flags = 0;
  133. }
  134. }
  135. }
  136. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_21285, pci_fixup_dec21285);
  137. /*
  138. * Same as above. The PrPMC800 carrier board for the PrPMC1100
  139. * card maps the host-bridge @ 00:01:00 for some reason and it
  140. * ends up getting scanned. Note that we only want to do this
  141. * fixup when we find the IXP4xx on a PrPMC system, which is why
  142. * we check the machine type. We could be running on a board
  143. * with an IXP4xx target device and we don't want to kill the
  144. * resources in that case.
  145. */
  146. static void __devinit pci_fixup_prpmc1100(struct pci_dev *dev)
  147. {
  148. int i;
  149. if (machine_is_prpmc1100()) {
  150. dev->class &= 0xff;
  151. dev->class |= PCI_CLASS_BRIDGE_HOST << 8;
  152. for (i = 0; i < PCI_NUM_RESOURCES; i++) {
  153. dev->resource[i].start = 0;
  154. dev->resource[i].end = 0;
  155. dev->resource[i].flags = 0;
  156. }
  157. }
  158. }
  159. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IXP4XX, pci_fixup_prpmc1100);
  160. /*
  161. * PCI IDE controllers use non-standard I/O port decoding, respect it.
  162. */
  163. static void __devinit pci_fixup_ide_bases(struct pci_dev *dev)
  164. {
  165. struct resource *r;
  166. int i;
  167. if ((dev->class >> 8) != PCI_CLASS_STORAGE_IDE)
  168. return;
  169. for (i = 0; i < PCI_NUM_RESOURCES; i++) {
  170. r = dev->resource + i;
  171. if ((r->start & ~0x80) == 0x374) {
  172. r->start |= 2;
  173. r->end = r->start;
  174. }
  175. }
  176. }
  177. DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, pci_fixup_ide_bases);
  178. /*
  179. * Put the DEC21142 to sleep
  180. */
  181. static void __devinit pci_fixup_dec21142(struct pci_dev *dev)
  182. {
  183. pci_write_config_dword(dev, 0x40, 0x80000000);
  184. }
  185. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_21142, pci_fixup_dec21142);
  186. /*
  187. * The CY82C693 needs some rather major fixups to ensure that it does
  188. * the right thing. Idea from the Alpha people, with a few additions.
  189. *
  190. * We ensure that the IDE base registers are set to 1f0/3f4 for the
  191. * primary bus, and 170/374 for the secondary bus. Also, hide them
  192. * from the PCI subsystem view as well so we won't try to perform
  193. * our own auto-configuration on them.
  194. *
  195. * In addition, we ensure that the PCI IDE interrupts are routed to
  196. * IRQ 14 and IRQ 15 respectively.
  197. *
  198. * The above gets us to a point where the IDE on this device is
  199. * functional. However, The CY82C693U _does not work_ in bus
  200. * master mode without locking the PCI bus solid.
  201. */
  202. static void __devinit pci_fixup_cy82c693(struct pci_dev *dev)
  203. {
  204. if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE) {
  205. u32 base0, base1;
  206. if (dev->class & 0x80) { /* primary */
  207. base0 = 0x1f0;
  208. base1 = 0x3f4;
  209. } else { /* secondary */
  210. base0 = 0x170;
  211. base1 = 0x374;
  212. }
  213. pci_write_config_dword(dev, PCI_BASE_ADDRESS_0,
  214. base0 | PCI_BASE_ADDRESS_SPACE_IO);
  215. pci_write_config_dword(dev, PCI_BASE_ADDRESS_1,
  216. base1 | PCI_BASE_ADDRESS_SPACE_IO);
  217. dev->resource[0].start = 0;
  218. dev->resource[0].end = 0;
  219. dev->resource[0].flags = 0;
  220. dev->resource[1].start = 0;
  221. dev->resource[1].end = 0;
  222. dev->resource[1].flags = 0;
  223. } else if (PCI_FUNC(dev->devfn) == 0) {
  224. /*
  225. * Setup IDE IRQ routing.
  226. */
  227. pci_write_config_byte(dev, 0x4b, 14);
  228. pci_write_config_byte(dev, 0x4c, 15);
  229. /*
  230. * Disable FREQACK handshake, enable USB.
  231. */
  232. pci_write_config_byte(dev, 0x4d, 0x41);
  233. /*
  234. * Enable PCI retry, and PCI post-write buffer.
  235. */
  236. pci_write_config_byte(dev, 0x44, 0x17);
  237. /*
  238. * Enable ISA master and DMA post write buffering.
  239. */
  240. pci_write_config_byte(dev, 0x45, 0x03);
  241. }
  242. }
  243. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_CONTAQ, PCI_DEVICE_ID_CONTAQ_82C693, pci_fixup_cy82c693);
  244. void __devinit pcibios_update_irq(struct pci_dev *dev, int irq)
  245. {
  246. if (debug_pci)
  247. printk("PCI: Assigning IRQ %02d to %s\n", irq, pci_name(dev));
  248. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);
  249. }
  250. /*
  251. * If the bus contains any of these devices, then we must not turn on
  252. * parity checking of any kind. Currently this is CyberPro 20x0 only.
  253. */
  254. static inline int pdev_bad_for_parity(struct pci_dev *dev)
  255. {
  256. return (dev->vendor == PCI_VENDOR_ID_INTERG &&
  257. (dev->device == PCI_DEVICE_ID_INTERG_2000 ||
  258. dev->device == PCI_DEVICE_ID_INTERG_2010));
  259. }
  260. /*
  261. * Adjust the device resources from bus-centric to Linux-centric.
  262. */
  263. static void __devinit
  264. pdev_fixup_device_resources(struct pci_sys_data *root, struct pci_dev *dev)
  265. {
  266. unsigned long offset;
  267. int i;
  268. for (i = 0; i < PCI_NUM_RESOURCES; i++) {
  269. if (dev->resource[i].start == 0)
  270. continue;
  271. if (dev->resource[i].flags & IORESOURCE_MEM)
  272. offset = root->mem_offset;
  273. else
  274. offset = root->io_offset;
  275. dev->resource[i].start += offset;
  276. dev->resource[i].end += offset;
  277. }
  278. }
  279. static void __devinit
  280. pbus_assign_bus_resources(struct pci_bus *bus, struct pci_sys_data *root)
  281. {
  282. struct pci_dev *dev = bus->self;
  283. int i;
  284. if (!dev) {
  285. /*
  286. * Assign root bus resources.
  287. */
  288. for (i = 0; i < 3; i++)
  289. bus->resource[i] = root->resource[i];
  290. }
  291. }
  292. /*
  293. * pcibios_fixup_bus - Called after each bus is probed,
  294. * but before its children are examined.
  295. */
  296. void __devinit pcibios_fixup_bus(struct pci_bus *bus)
  297. {
  298. struct pci_sys_data *root = bus->sysdata;
  299. struct pci_dev *dev;
  300. u16 features = PCI_COMMAND_SERR | PCI_COMMAND_PARITY | PCI_COMMAND_FAST_BACK;
  301. pbus_assign_bus_resources(bus, root);
  302. /*
  303. * Walk the devices on this bus, working out what we can
  304. * and can't support.
  305. */
  306. list_for_each_entry(dev, &bus->devices, bus_list) {
  307. u16 status;
  308. pdev_fixup_device_resources(root, dev);
  309. pci_read_config_word(dev, PCI_STATUS, &status);
  310. /*
  311. * If any device on this bus does not support fast back
  312. * to back transfers, then the bus as a whole is not able
  313. * to support them. Having fast back to back transfers
  314. * on saves us one PCI cycle per transaction.
  315. */
  316. if (!(status & PCI_STATUS_FAST_BACK))
  317. features &= ~PCI_COMMAND_FAST_BACK;
  318. if (pdev_bad_for_parity(dev))
  319. features &= ~(PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
  320. switch (dev->class >> 8) {
  321. #if defined(CONFIG_ISA) || defined(CONFIG_EISA)
  322. case PCI_CLASS_BRIDGE_ISA:
  323. case PCI_CLASS_BRIDGE_EISA:
  324. /*
  325. * If this device is an ISA bridge, set isa_bridge
  326. * to point at this device. We will then go looking
  327. * for things like keyboard, etc.
  328. */
  329. isa_bridge = dev;
  330. break;
  331. #endif
  332. case PCI_CLASS_BRIDGE_PCI:
  333. pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &status);
  334. status |= PCI_BRIDGE_CTL_PARITY|PCI_BRIDGE_CTL_MASTER_ABORT;
  335. status &= ~(PCI_BRIDGE_CTL_BUS_RESET|PCI_BRIDGE_CTL_FAST_BACK);
  336. pci_write_config_word(dev, PCI_BRIDGE_CONTROL, status);
  337. break;
  338. case PCI_CLASS_BRIDGE_CARDBUS:
  339. pci_read_config_word(dev, PCI_CB_BRIDGE_CONTROL, &status);
  340. status |= PCI_CB_BRIDGE_CTL_PARITY|PCI_CB_BRIDGE_CTL_MASTER_ABORT;
  341. pci_write_config_word(dev, PCI_CB_BRIDGE_CONTROL, status);
  342. break;
  343. }
  344. }
  345. /*
  346. * Now walk the devices again, this time setting them up.
  347. */
  348. list_for_each_entry(dev, &bus->devices, bus_list) {
  349. u16 cmd;
  350. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  351. cmd |= features;
  352. pci_write_config_word(dev, PCI_COMMAND, cmd);
  353. pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE,
  354. L1_CACHE_BYTES >> 2);
  355. }
  356. /*
  357. * Propagate the flags to the PCI bridge.
  358. */
  359. if (bus->self && bus->self->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
  360. if (features & PCI_COMMAND_FAST_BACK)
  361. bus->bridge_ctl |= PCI_BRIDGE_CTL_FAST_BACK;
  362. if (features & PCI_COMMAND_PARITY)
  363. bus->bridge_ctl |= PCI_BRIDGE_CTL_PARITY;
  364. }
  365. /*
  366. * Report what we did for this bus
  367. */
  368. printk(KERN_INFO "PCI: bus%d: Fast back to back transfers %sabled\n",
  369. bus->number, (features & PCI_COMMAND_FAST_BACK) ? "en" : "dis");
  370. }
  371. /*
  372. * Convert from Linux-centric to bus-centric addresses for bridge devices.
  373. */
  374. void __devinit
  375. pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region,
  376. struct resource *res)
  377. {
  378. struct pci_sys_data *root = dev->sysdata;
  379. unsigned long offset = 0;
  380. if (res->flags & IORESOURCE_IO)
  381. offset = root->io_offset;
  382. if (res->flags & IORESOURCE_MEM)
  383. offset = root->mem_offset;
  384. region->start = res->start - offset;
  385. region->end = res->end - offset;
  386. }
  387. void __devinit
  388. pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res,
  389. struct pci_bus_region *region)
  390. {
  391. struct pci_sys_data *root = dev->sysdata;
  392. unsigned long offset = 0;
  393. if (res->flags & IORESOURCE_IO)
  394. offset = root->io_offset;
  395. if (res->flags & IORESOURCE_MEM)
  396. offset = root->mem_offset;
  397. res->start = region->start + offset;
  398. res->end = region->end + offset;
  399. }
  400. #ifdef CONFIG_HOTPLUG
  401. EXPORT_SYMBOL(pcibios_fixup_bus);
  402. EXPORT_SYMBOL(pcibios_resource_to_bus);
  403. EXPORT_SYMBOL(pcibios_bus_to_resource);
  404. #endif
  405. /*
  406. * This is the standard PCI-PCI bridge swizzling algorithm:
  407. *
  408. * Dev: 0 1 2 3
  409. * A A B C D
  410. * B B C D A
  411. * C C D A B
  412. * D D A B C
  413. * ^^^^^^^^^^ irq pin on bridge
  414. */
  415. u8 __devinit pci_std_swizzle(struct pci_dev *dev, u8 *pinp)
  416. {
  417. int pin = *pinp - 1;
  418. while (dev->bus->self) {
  419. pin = (pin + PCI_SLOT(dev->devfn)) & 3;
  420. /*
  421. * move up the chain of bridges,
  422. * swizzling as we go.
  423. */
  424. dev = dev->bus->self;
  425. }
  426. *pinp = pin + 1;
  427. return PCI_SLOT(dev->devfn);
  428. }
  429. /*
  430. * Swizzle the device pin each time we cross a bridge.
  431. * This might update pin and returns the slot number.
  432. */
  433. static u8 __devinit pcibios_swizzle(struct pci_dev *dev, u8 *pin)
  434. {
  435. struct pci_sys_data *sys = dev->sysdata;
  436. int slot = 0, oldpin = *pin;
  437. if (sys->swizzle)
  438. slot = sys->swizzle(dev, pin);
  439. if (debug_pci)
  440. printk("PCI: %s swizzling pin %d => pin %d slot %d\n",
  441. pci_name(dev), oldpin, *pin, slot);
  442. return slot;
  443. }
  444. /*
  445. * Map a slot/pin to an IRQ.
  446. */
  447. static int pcibios_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
  448. {
  449. struct pci_sys_data *sys = dev->sysdata;
  450. int irq = -1;
  451. if (sys->map_irq)
  452. irq = sys->map_irq(dev, slot, pin);
  453. if (debug_pci)
  454. printk("PCI: %s mapping slot %d pin %d => irq %d\n",
  455. pci_name(dev), slot, pin, irq);
  456. return irq;
  457. }
  458. static void __init pcibios_init_hw(struct hw_pci *hw)
  459. {
  460. struct pci_sys_data *sys = NULL;
  461. int ret;
  462. int nr, busnr;
  463. for (nr = busnr = 0; nr < hw->nr_controllers; nr++) {
  464. sys = kmalloc(sizeof(struct pci_sys_data), GFP_KERNEL);
  465. if (!sys)
  466. panic("PCI: unable to allocate sys data!");
  467. memset(sys, 0, sizeof(struct pci_sys_data));
  468. sys->hw = hw;
  469. sys->busnr = busnr;
  470. sys->swizzle = hw->swizzle;
  471. sys->map_irq = hw->map_irq;
  472. sys->resource[0] = &ioport_resource;
  473. sys->resource[1] = &iomem_resource;
  474. ret = hw->setup(nr, sys);
  475. if (ret > 0) {
  476. sys->bus = hw->scan(nr, sys);
  477. if (!sys->bus)
  478. panic("PCI: unable to scan bus!");
  479. busnr = sys->bus->subordinate + 1;
  480. list_add(&sys->node, &hw->buses);
  481. } else {
  482. kfree(sys);
  483. if (ret < 0)
  484. break;
  485. }
  486. }
  487. }
  488. void __init pci_common_init(struct hw_pci *hw)
  489. {
  490. struct pci_sys_data *sys;
  491. INIT_LIST_HEAD(&hw->buses);
  492. if (hw->preinit)
  493. hw->preinit();
  494. pcibios_init_hw(hw);
  495. if (hw->postinit)
  496. hw->postinit();
  497. pci_fixup_irqs(pcibios_swizzle, pcibios_map_irq);
  498. list_for_each_entry(sys, &hw->buses, node) {
  499. struct pci_bus *bus = sys->bus;
  500. if (!use_firmware) {
  501. /*
  502. * Size the bridge windows.
  503. */
  504. pci_bus_size_bridges(bus);
  505. /*
  506. * Assign resources.
  507. */
  508. pci_bus_assign_resources(bus);
  509. }
  510. /*
  511. * Tell drivers about devices found.
  512. */
  513. pci_bus_add_devices(bus);
  514. }
  515. }
  516. char * __init pcibios_setup(char *str)
  517. {
  518. if (!strcmp(str, "debug")) {
  519. debug_pci = 1;
  520. return NULL;
  521. } else if (!strcmp(str, "firmware")) {
  522. use_firmware = 1;
  523. return NULL;
  524. }
  525. return str;
  526. }
  527. /*
  528. * From arch/i386/kernel/pci-i386.c:
  529. *
  530. * We need to avoid collisions with `mirrored' VGA ports
  531. * and other strange ISA hardware, so we always want the
  532. * addresses to be allocated in the 0x000-0x0ff region
  533. * modulo 0x400.
  534. *
  535. * Why? Because some silly external IO cards only decode
  536. * the low 10 bits of the IO address. The 0x00-0xff region
  537. * is reserved for motherboard devices that decode all 16
  538. * bits, so it's ok to allocate at, say, 0x2800-0x28ff,
  539. * but we want to try to avoid allocating at 0x2900-0x2bff
  540. * which might be mirrored at 0x0100-0x03ff..
  541. */
  542. void pcibios_align_resource(void *data, struct resource *res,
  543. unsigned long size, unsigned long align)
  544. {
  545. unsigned long start = res->start;
  546. if (res->flags & IORESOURCE_IO && start & 0x300)
  547. start = (start + 0x3ff) & ~0x3ff;
  548. res->start = (start + align - 1) & ~(align - 1);
  549. }
  550. /**
  551. * pcibios_enable_device - Enable I/O and memory.
  552. * @dev: PCI device to be enabled
  553. */
  554. int pcibios_enable_device(struct pci_dev *dev, int mask)
  555. {
  556. u16 cmd, old_cmd;
  557. int idx;
  558. struct resource *r;
  559. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  560. old_cmd = cmd;
  561. for (idx = 0; idx < 6; idx++) {
  562. /* Only set up the requested stuff */
  563. if (!(mask & (1 << idx)))
  564. continue;
  565. r = dev->resource + idx;
  566. if (!r->start && r->end) {
  567. printk(KERN_ERR "PCI: Device %s not available because"
  568. " of resource collisions\n", pci_name(dev));
  569. return -EINVAL;
  570. }
  571. if (r->flags & IORESOURCE_IO)
  572. cmd |= PCI_COMMAND_IO;
  573. if (r->flags & IORESOURCE_MEM)
  574. cmd |= PCI_COMMAND_MEMORY;
  575. }
  576. /*
  577. * Bridges (eg, cardbus bridges) need to be fully enabled
  578. */
  579. if ((dev->class >> 16) == PCI_BASE_CLASS_BRIDGE)
  580. cmd |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY;
  581. if (cmd != old_cmd) {
  582. printk("PCI: enabling device %s (%04x -> %04x)\n",
  583. pci_name(dev), old_cmd, cmd);
  584. pci_write_config_word(dev, PCI_COMMAND, cmd);
  585. }
  586. return 0;
  587. }
  588. int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
  589. enum pci_mmap_state mmap_state, int write_combine)
  590. {
  591. struct pci_sys_data *root = dev->sysdata;
  592. unsigned long phys;
  593. if (mmap_state == pci_mmap_io) {
  594. return -EINVAL;
  595. } else {
  596. phys = vma->vm_pgoff + (root->mem_offset >> PAGE_SHIFT);
  597. }
  598. /*
  599. * Mark this as IO
  600. */
  601. vma->vm_flags |= VM_SHM | VM_LOCKED | VM_IO;
  602. vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  603. if (remap_pfn_range(vma, vma->vm_start, phys,
  604. vma->vm_end - vma->vm_start,
  605. vma->vm_page_prot))
  606. return -EAGAIN;
  607. return 0;
  608. }