bios32.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  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/export.h>
  9. #include <linux/kernel.h>
  10. #include <linux/pci.h>
  11. #include <linux/slab.h>
  12. #include <linux/init.h>
  13. #include <linux/io.h>
  14. #include <asm/mach-types.h>
  15. #include <asm/mach/map.h>
  16. #include <asm/mach/pci.h>
  17. static int debug_pci;
  18. /*
  19. * We can't use pci_get_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 pci_bus *bus;
  50. list_for_each_entry(bus, &pci_root_buses, node)
  51. pcibios_bus_report_status(bus, status_mask, warn);
  52. }
  53. /*
  54. * We don't use this to fix the device, but initialisation of it.
  55. * It's not the correct use for this, but it works.
  56. * Note that the arbiter/ISA bridge appears to be buggy, specifically in
  57. * the following area:
  58. * 1. park on CPU
  59. * 2. ISA bridge ping-pong
  60. * 3. ISA bridge master handling of target RETRY
  61. *
  62. * Bug 3 is responsible for the sound DMA grinding to a halt. We now
  63. * live with bug 2.
  64. */
  65. static void pci_fixup_83c553(struct pci_dev *dev)
  66. {
  67. /*
  68. * Set memory region to start at address 0, and enable IO
  69. */
  70. pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, PCI_BASE_ADDRESS_SPACE_MEMORY);
  71. pci_write_config_word(dev, PCI_COMMAND, PCI_COMMAND_IO);
  72. dev->resource[0].end -= dev->resource[0].start;
  73. dev->resource[0].start = 0;
  74. /*
  75. * All memory requests from ISA to be channelled to PCI
  76. */
  77. pci_write_config_byte(dev, 0x48, 0xff);
  78. /*
  79. * Enable ping-pong on bus master to ISA bridge transactions.
  80. * This improves the sound DMA substantially. The fixed
  81. * priority arbiter also helps (see below).
  82. */
  83. pci_write_config_byte(dev, 0x42, 0x01);
  84. /*
  85. * Enable PCI retry
  86. */
  87. pci_write_config_byte(dev, 0x40, 0x22);
  88. /*
  89. * We used to set the arbiter to "park on last master" (bit
  90. * 1 set), but unfortunately the CyberPro does not park the
  91. * bus. We must therefore park on CPU. Unfortunately, this
  92. * may trigger yet another bug in the 553.
  93. */
  94. pci_write_config_byte(dev, 0x83, 0x02);
  95. /*
  96. * Make the ISA DMA request lowest priority, and disable
  97. * rotating priorities completely.
  98. */
  99. pci_write_config_byte(dev, 0x80, 0x11);
  100. pci_write_config_byte(dev, 0x81, 0x00);
  101. /*
  102. * Route INTA input to IRQ 11, and set IRQ11 to be level
  103. * sensitive.
  104. */
  105. pci_write_config_word(dev, 0x44, 0xb000);
  106. outb(0x08, 0x4d1);
  107. }
  108. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_WINBOND, PCI_DEVICE_ID_WINBOND_83C553, pci_fixup_83c553);
  109. static void pci_fixup_unassign(struct pci_dev *dev)
  110. {
  111. dev->resource[0].end -= dev->resource[0].start;
  112. dev->resource[0].start = 0;
  113. }
  114. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_WINBOND2, PCI_DEVICE_ID_WINBOND2_89C940F, pci_fixup_unassign);
  115. /*
  116. * Prevent the PCI layer from seeing the resources allocated to this device
  117. * if it is the host bridge by marking it as such. These resources are of
  118. * no consequence to the PCI layer (they are handled elsewhere).
  119. */
  120. static void pci_fixup_dec21285(struct pci_dev *dev)
  121. {
  122. int i;
  123. if (dev->devfn == 0) {
  124. dev->class &= 0xff;
  125. dev->class |= PCI_CLASS_BRIDGE_HOST << 8;
  126. for (i = 0; i < PCI_NUM_RESOURCES; i++) {
  127. dev->resource[i].start = 0;
  128. dev->resource[i].end = 0;
  129. dev->resource[i].flags = 0;
  130. }
  131. }
  132. }
  133. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_21285, pci_fixup_dec21285);
  134. /*
  135. * PCI IDE controllers use non-standard I/O port decoding, respect it.
  136. */
  137. static void pci_fixup_ide_bases(struct pci_dev *dev)
  138. {
  139. struct resource *r;
  140. int i;
  141. if ((dev->class >> 8) != PCI_CLASS_STORAGE_IDE)
  142. return;
  143. for (i = 0; i < PCI_NUM_RESOURCES; i++) {
  144. r = dev->resource + i;
  145. if ((r->start & ~0x80) == 0x374) {
  146. r->start |= 2;
  147. r->end = r->start;
  148. }
  149. }
  150. }
  151. DECLARE_PCI_FIXUP_HEADER(PCI_ANY_ID, PCI_ANY_ID, pci_fixup_ide_bases);
  152. /*
  153. * Put the DEC21142 to sleep
  154. */
  155. static void pci_fixup_dec21142(struct pci_dev *dev)
  156. {
  157. pci_write_config_dword(dev, 0x40, 0x80000000);
  158. }
  159. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_21142, pci_fixup_dec21142);
  160. /*
  161. * The CY82C693 needs some rather major fixups to ensure that it does
  162. * the right thing. Idea from the Alpha people, with a few additions.
  163. *
  164. * We ensure that the IDE base registers are set to 1f0/3f4 for the
  165. * primary bus, and 170/374 for the secondary bus. Also, hide them
  166. * from the PCI subsystem view as well so we won't try to perform
  167. * our own auto-configuration on them.
  168. *
  169. * In addition, we ensure that the PCI IDE interrupts are routed to
  170. * IRQ 14 and IRQ 15 respectively.
  171. *
  172. * The above gets us to a point where the IDE on this device is
  173. * functional. However, The CY82C693U _does not work_ in bus
  174. * master mode without locking the PCI bus solid.
  175. */
  176. static void pci_fixup_cy82c693(struct pci_dev *dev)
  177. {
  178. if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE) {
  179. u32 base0, base1;
  180. if (dev->class & 0x80) { /* primary */
  181. base0 = 0x1f0;
  182. base1 = 0x3f4;
  183. } else { /* secondary */
  184. base0 = 0x170;
  185. base1 = 0x374;
  186. }
  187. pci_write_config_dword(dev, PCI_BASE_ADDRESS_0,
  188. base0 | PCI_BASE_ADDRESS_SPACE_IO);
  189. pci_write_config_dword(dev, PCI_BASE_ADDRESS_1,
  190. base1 | PCI_BASE_ADDRESS_SPACE_IO);
  191. dev->resource[0].start = 0;
  192. dev->resource[0].end = 0;
  193. dev->resource[0].flags = 0;
  194. dev->resource[1].start = 0;
  195. dev->resource[1].end = 0;
  196. dev->resource[1].flags = 0;
  197. } else if (PCI_FUNC(dev->devfn) == 0) {
  198. /*
  199. * Setup IDE IRQ routing.
  200. */
  201. pci_write_config_byte(dev, 0x4b, 14);
  202. pci_write_config_byte(dev, 0x4c, 15);
  203. /*
  204. * Disable FREQACK handshake, enable USB.
  205. */
  206. pci_write_config_byte(dev, 0x4d, 0x41);
  207. /*
  208. * Enable PCI retry, and PCI post-write buffer.
  209. */
  210. pci_write_config_byte(dev, 0x44, 0x17);
  211. /*
  212. * Enable ISA master and DMA post write buffering.
  213. */
  214. pci_write_config_byte(dev, 0x45, 0x03);
  215. }
  216. }
  217. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_CONTAQ, PCI_DEVICE_ID_CONTAQ_82C693, pci_fixup_cy82c693);
  218. static void pci_fixup_it8152(struct pci_dev *dev)
  219. {
  220. int i;
  221. /* fixup for ITE 8152 devices */
  222. /* FIXME: add defines for class 0x68000 and 0x80103 */
  223. if ((dev->class >> 8) == PCI_CLASS_BRIDGE_HOST ||
  224. dev->class == 0x68000 ||
  225. dev->class == 0x80103) {
  226. for (i = 0; i < PCI_NUM_RESOURCES; i++) {
  227. dev->resource[i].start = 0;
  228. dev->resource[i].end = 0;
  229. dev->resource[i].flags = 0;
  230. }
  231. }
  232. }
  233. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ITE, PCI_DEVICE_ID_ITE_8152, pci_fixup_it8152);
  234. /*
  235. * If the bus contains any of these devices, then we must not turn on
  236. * parity checking of any kind. Currently this is CyberPro 20x0 only.
  237. */
  238. static inline int pdev_bad_for_parity(struct pci_dev *dev)
  239. {
  240. return ((dev->vendor == PCI_VENDOR_ID_INTERG &&
  241. (dev->device == PCI_DEVICE_ID_INTERG_2000 ||
  242. dev->device == PCI_DEVICE_ID_INTERG_2010)) ||
  243. (dev->vendor == PCI_VENDOR_ID_ITE &&
  244. dev->device == PCI_DEVICE_ID_ITE_8152));
  245. }
  246. /*
  247. * pcibios_fixup_bus - Called after each bus is probed,
  248. * but before its children are examined.
  249. */
  250. void pcibios_fixup_bus(struct pci_bus *bus)
  251. {
  252. struct pci_dev *dev;
  253. u16 features = PCI_COMMAND_SERR | PCI_COMMAND_PARITY | PCI_COMMAND_FAST_BACK;
  254. /*
  255. * Walk the devices on this bus, working out what we can
  256. * and can't support.
  257. */
  258. list_for_each_entry(dev, &bus->devices, bus_list) {
  259. u16 status;
  260. pci_read_config_word(dev, PCI_STATUS, &status);
  261. /*
  262. * If any device on this bus does not support fast back
  263. * to back transfers, then the bus as a whole is not able
  264. * to support them. Having fast back to back transfers
  265. * on saves us one PCI cycle per transaction.
  266. */
  267. if (!(status & PCI_STATUS_FAST_BACK))
  268. features &= ~PCI_COMMAND_FAST_BACK;
  269. if (pdev_bad_for_parity(dev))
  270. features &= ~(PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
  271. switch (dev->class >> 8) {
  272. case PCI_CLASS_BRIDGE_PCI:
  273. pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &status);
  274. status |= PCI_BRIDGE_CTL_PARITY|PCI_BRIDGE_CTL_MASTER_ABORT;
  275. status &= ~(PCI_BRIDGE_CTL_BUS_RESET|PCI_BRIDGE_CTL_FAST_BACK);
  276. pci_write_config_word(dev, PCI_BRIDGE_CONTROL, status);
  277. break;
  278. case PCI_CLASS_BRIDGE_CARDBUS:
  279. pci_read_config_word(dev, PCI_CB_BRIDGE_CONTROL, &status);
  280. status |= PCI_CB_BRIDGE_CTL_PARITY|PCI_CB_BRIDGE_CTL_MASTER_ABORT;
  281. pci_write_config_word(dev, PCI_CB_BRIDGE_CONTROL, status);
  282. break;
  283. }
  284. }
  285. /*
  286. * Now walk the devices again, this time setting them up.
  287. */
  288. list_for_each_entry(dev, &bus->devices, bus_list) {
  289. u16 cmd;
  290. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  291. cmd |= features;
  292. pci_write_config_word(dev, PCI_COMMAND, cmd);
  293. pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE,
  294. L1_CACHE_BYTES >> 2);
  295. }
  296. /*
  297. * Propagate the flags to the PCI bridge.
  298. */
  299. if (bus->self && bus->self->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
  300. if (features & PCI_COMMAND_FAST_BACK)
  301. bus->bridge_ctl |= PCI_BRIDGE_CTL_FAST_BACK;
  302. if (features & PCI_COMMAND_PARITY)
  303. bus->bridge_ctl |= PCI_BRIDGE_CTL_PARITY;
  304. }
  305. /*
  306. * Report what we did for this bus
  307. */
  308. printk(KERN_INFO "PCI: bus%d: Fast back to back transfers %sabled\n",
  309. bus->number, (features & PCI_COMMAND_FAST_BACK) ? "en" : "dis");
  310. }
  311. EXPORT_SYMBOL(pcibios_fixup_bus);
  312. void pcibios_add_bus(struct pci_bus *bus)
  313. {
  314. struct pci_sys_data *sys = bus->sysdata;
  315. if (sys->add_bus)
  316. sys->add_bus(bus);
  317. }
  318. void pcibios_remove_bus(struct pci_bus *bus)
  319. {
  320. struct pci_sys_data *sys = bus->sysdata;
  321. if (sys->remove_bus)
  322. sys->remove_bus(bus);
  323. }
  324. /*
  325. * Swizzle the device pin each time we cross a bridge. If a platform does
  326. * not provide a swizzle function, we perform the standard PCI swizzling.
  327. *
  328. * The default swizzling walks up the bus tree one level at a time, applying
  329. * the standard swizzle function at each step, stopping when it finds the PCI
  330. * root bus. This will return the slot number of the bridge device on the
  331. * root bus and the interrupt pin on that device which should correspond
  332. * with the downstream device interrupt.
  333. *
  334. * Platforms may override this, in which case the slot and pin returned
  335. * depend entirely on the platform code. However, please note that the
  336. * PCI standard swizzle is implemented on plug-in cards and Cardbus based
  337. * PCI extenders, so it can not be ignored.
  338. */
  339. static u8 pcibios_swizzle(struct pci_dev *dev, u8 *pin)
  340. {
  341. struct pci_sys_data *sys = dev->sysdata;
  342. int slot, oldpin = *pin;
  343. if (sys->swizzle)
  344. slot = sys->swizzle(dev, pin);
  345. else
  346. slot = pci_common_swizzle(dev, pin);
  347. if (debug_pci)
  348. printk("PCI: %s swizzling pin %d => pin %d slot %d\n",
  349. pci_name(dev), oldpin, *pin, slot);
  350. return slot;
  351. }
  352. /*
  353. * Map a slot/pin to an IRQ.
  354. */
  355. static int pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  356. {
  357. struct pci_sys_data *sys = dev->sysdata;
  358. int irq = -1;
  359. if (sys->map_irq)
  360. irq = sys->map_irq(dev, slot, pin);
  361. if (debug_pci)
  362. printk("PCI: %s mapping slot %d pin %d => irq %d\n",
  363. pci_name(dev), slot, pin, irq);
  364. return irq;
  365. }
  366. static int pcibios_init_resources(int busnr, struct pci_sys_data *sys)
  367. {
  368. int ret;
  369. struct pci_host_bridge_window *window;
  370. if (list_empty(&sys->resources)) {
  371. pci_add_resource_offset(&sys->resources,
  372. &iomem_resource, sys->mem_offset);
  373. }
  374. list_for_each_entry(window, &sys->resources, list) {
  375. if (resource_type(window->res) == IORESOURCE_IO)
  376. return 0;
  377. }
  378. sys->io_res.start = (busnr * SZ_64K) ? : pcibios_min_io;
  379. sys->io_res.end = (busnr + 1) * SZ_64K - 1;
  380. sys->io_res.flags = IORESOURCE_IO;
  381. sys->io_res.name = sys->io_res_name;
  382. sprintf(sys->io_res_name, "PCI%d I/O", busnr);
  383. ret = request_resource(&ioport_resource, &sys->io_res);
  384. if (ret) {
  385. pr_err("PCI: unable to allocate I/O port region (%d)\n", ret);
  386. return ret;
  387. }
  388. pci_add_resource_offset(&sys->resources, &sys->io_res,
  389. sys->io_offset);
  390. return 0;
  391. }
  392. static void pcibios_init_hw(struct device *parent, struct hw_pci *hw,
  393. struct list_head *head)
  394. {
  395. struct pci_sys_data *sys = NULL;
  396. int ret;
  397. int nr, busnr;
  398. for (nr = busnr = 0; nr < hw->nr_controllers; nr++) {
  399. sys = kzalloc(sizeof(struct pci_sys_data), GFP_KERNEL);
  400. if (!sys)
  401. panic("PCI: unable to allocate sys data!");
  402. #ifdef CONFIG_PCI_DOMAINS
  403. sys->domain = hw->domain;
  404. #endif
  405. sys->busnr = busnr;
  406. sys->swizzle = hw->swizzle;
  407. sys->map_irq = hw->map_irq;
  408. sys->align_resource = hw->align_resource;
  409. sys->add_bus = hw->add_bus;
  410. sys->remove_bus = hw->remove_bus;
  411. INIT_LIST_HEAD(&sys->resources);
  412. if (hw->private_data)
  413. sys->private_data = hw->private_data[nr];
  414. ret = hw->setup(nr, sys);
  415. if (ret > 0) {
  416. ret = pcibios_init_resources(nr, sys);
  417. if (ret) {
  418. kfree(sys);
  419. break;
  420. }
  421. if (hw->scan)
  422. sys->bus = hw->scan(nr, sys);
  423. else
  424. sys->bus = pci_scan_root_bus(parent, sys->busnr,
  425. hw->ops, sys, &sys->resources);
  426. if (!sys->bus)
  427. panic("PCI: unable to scan bus!");
  428. busnr = sys->bus->busn_res.end + 1;
  429. list_add(&sys->node, head);
  430. } else {
  431. kfree(sys);
  432. if (ret < 0)
  433. break;
  434. }
  435. }
  436. }
  437. void pci_common_init_dev(struct device *parent, struct hw_pci *hw)
  438. {
  439. struct pci_sys_data *sys;
  440. LIST_HEAD(head);
  441. pci_add_flags(PCI_REASSIGN_ALL_RSRC);
  442. if (hw->preinit)
  443. hw->preinit();
  444. pcibios_init_hw(parent, hw, &head);
  445. if (hw->postinit)
  446. hw->postinit();
  447. pci_fixup_irqs(pcibios_swizzle, pcibios_map_irq);
  448. list_for_each_entry(sys, &head, node) {
  449. struct pci_bus *bus = sys->bus;
  450. if (!pci_has_flag(PCI_PROBE_ONLY)) {
  451. /*
  452. * Size the bridge windows.
  453. */
  454. pci_bus_size_bridges(bus);
  455. /*
  456. * Assign resources.
  457. */
  458. pci_bus_assign_resources(bus);
  459. }
  460. /*
  461. * Tell drivers about devices found.
  462. */
  463. pci_bus_add_devices(bus);
  464. }
  465. list_for_each_entry(sys, &head, node) {
  466. struct pci_bus *bus = sys->bus;
  467. /* Configure PCI Express settings */
  468. if (bus && !pci_has_flag(PCI_PROBE_ONLY)) {
  469. struct pci_bus *child;
  470. list_for_each_entry(child, &bus->children, node)
  471. pcie_bus_configure_settings(child);
  472. }
  473. }
  474. }
  475. #ifndef CONFIG_PCI_HOST_ITE8152
  476. void pcibios_set_master(struct pci_dev *dev)
  477. {
  478. /* No special bus mastering setup handling */
  479. }
  480. #endif
  481. char * __init pcibios_setup(char *str)
  482. {
  483. if (!strcmp(str, "debug")) {
  484. debug_pci = 1;
  485. return NULL;
  486. } else if (!strcmp(str, "firmware")) {
  487. pci_add_flags(PCI_PROBE_ONLY);
  488. return NULL;
  489. }
  490. return str;
  491. }
  492. /*
  493. * From arch/i386/kernel/pci-i386.c:
  494. *
  495. * We need to avoid collisions with `mirrored' VGA ports
  496. * and other strange ISA hardware, so we always want the
  497. * addresses to be allocated in the 0x000-0x0ff region
  498. * modulo 0x400.
  499. *
  500. * Why? Because some silly external IO cards only decode
  501. * the low 10 bits of the IO address. The 0x00-0xff region
  502. * is reserved for motherboard devices that decode all 16
  503. * bits, so it's ok to allocate at, say, 0x2800-0x28ff,
  504. * but we want to try to avoid allocating at 0x2900-0x2bff
  505. * which might be mirrored at 0x0100-0x03ff..
  506. */
  507. resource_size_t pcibios_align_resource(void *data, const struct resource *res,
  508. resource_size_t size, resource_size_t align)
  509. {
  510. struct pci_dev *dev = data;
  511. struct pci_sys_data *sys = dev->sysdata;
  512. resource_size_t start = res->start;
  513. if (res->flags & IORESOURCE_IO && start & 0x300)
  514. start = (start + 0x3ff) & ~0x3ff;
  515. start = (start + align - 1) & ~(align - 1);
  516. if (sys->align_resource)
  517. return sys->align_resource(dev, res, start, size, align);
  518. return start;
  519. }
  520. /**
  521. * pcibios_enable_device - Enable I/O and memory.
  522. * @dev: PCI device to be enabled
  523. */
  524. int pcibios_enable_device(struct pci_dev *dev, int mask)
  525. {
  526. if (pci_has_flag(PCI_PROBE_ONLY))
  527. return 0;
  528. return pci_enable_resources(dev, mask);
  529. }
  530. int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
  531. enum pci_mmap_state mmap_state, int write_combine)
  532. {
  533. struct pci_sys_data *root = dev->sysdata;
  534. unsigned long phys;
  535. if (mmap_state == pci_mmap_io) {
  536. return -EINVAL;
  537. } else {
  538. phys = vma->vm_pgoff + (root->mem_offset >> PAGE_SHIFT);
  539. }
  540. /*
  541. * Mark this as IO
  542. */
  543. vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  544. if (remap_pfn_range(vma, vma->vm_start, phys,
  545. vma->vm_end - vma->vm_start,
  546. vma->vm_page_prot))
  547. return -EAGAIN;
  548. return 0;
  549. }
  550. void __init pci_map_io_early(unsigned long pfn)
  551. {
  552. struct map_desc pci_io_desc = {
  553. .virtual = PCI_IO_VIRT_BASE,
  554. .type = MT_DEVICE,
  555. .length = SZ_64K,
  556. };
  557. pci_io_desc.pfn = pfn;
  558. iotable_init(&pci_io_desc, 1);
  559. }