bios32.c 18 KB

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