pci.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. /*
  2. * pci.c - Low-Level PCI Access in IA-64
  3. *
  4. * Derived from bios32.c of i386 tree.
  5. *
  6. * (c) Copyright 2002, 2005 Hewlett-Packard Development Company, L.P.
  7. * David Mosberger-Tang <davidm@hpl.hp.com>
  8. * Bjorn Helgaas <bjorn.helgaas@hp.com>
  9. * Copyright (C) 2004 Silicon Graphics, Inc.
  10. *
  11. * Note: Above list of copyright holders is incomplete...
  12. */
  13. #include <linux/acpi.h>
  14. #include <linux/types.h>
  15. #include <linux/kernel.h>
  16. #include <linux/pci.h>
  17. #include <linux/init.h>
  18. #include <linux/ioport.h>
  19. #include <linux/slab.h>
  20. #include <linux/smp_lock.h>
  21. #include <linux/spinlock.h>
  22. #include <asm/machvec.h>
  23. #include <asm/page.h>
  24. #include <asm/system.h>
  25. #include <asm/io.h>
  26. #include <asm/sal.h>
  27. #include <asm/smp.h>
  28. #include <asm/irq.h>
  29. #include <asm/hw_irq.h>
  30. /*
  31. * Low-level SAL-based PCI configuration access functions. Note that SAL
  32. * calls are already serialized (via sal_lock), so we don't need another
  33. * synchronization mechanism here.
  34. */
  35. #define PCI_SAL_ADDRESS(seg, bus, devfn, reg) \
  36. (((u64) seg << 24) | (bus << 16) | (devfn << 8) | (reg))
  37. /* SAL 3.2 adds support for extended config space. */
  38. #define PCI_SAL_EXT_ADDRESS(seg, bus, devfn, reg) \
  39. (((u64) seg << 28) | (bus << 20) | (devfn << 12) | (reg))
  40. static int
  41. pci_sal_read (unsigned int seg, unsigned int bus, unsigned int devfn,
  42. int reg, int len, u32 *value)
  43. {
  44. u64 addr, data = 0;
  45. int mode, result;
  46. if (!value || (seg > 65535) || (bus > 255) || (devfn > 255) || (reg > 4095))
  47. return -EINVAL;
  48. if ((seg | reg) <= 255) {
  49. addr = PCI_SAL_ADDRESS(seg, bus, devfn, reg);
  50. mode = 0;
  51. } else {
  52. addr = PCI_SAL_EXT_ADDRESS(seg, bus, devfn, reg);
  53. mode = 1;
  54. }
  55. result = ia64_sal_pci_config_read(addr, mode, len, &data);
  56. if (result != 0)
  57. return -EINVAL;
  58. *value = (u32) data;
  59. return 0;
  60. }
  61. static int
  62. pci_sal_write (unsigned int seg, unsigned int bus, unsigned int devfn,
  63. int reg, int len, u32 value)
  64. {
  65. u64 addr;
  66. int mode, result;
  67. if ((seg > 65535) || (bus > 255) || (devfn > 255) || (reg > 4095))
  68. return -EINVAL;
  69. if ((seg | reg) <= 255) {
  70. addr = PCI_SAL_ADDRESS(seg, bus, devfn, reg);
  71. mode = 0;
  72. } else {
  73. addr = PCI_SAL_EXT_ADDRESS(seg, bus, devfn, reg);
  74. mode = 1;
  75. }
  76. result = ia64_sal_pci_config_write(addr, mode, len, value);
  77. if (result != 0)
  78. return -EINVAL;
  79. return 0;
  80. }
  81. static struct pci_raw_ops pci_sal_ops = {
  82. .read = pci_sal_read,
  83. .write = pci_sal_write
  84. };
  85. struct pci_raw_ops *raw_pci_ops = &pci_sal_ops;
  86. static int
  87. pci_read (struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
  88. {
  89. return raw_pci_ops->read(pci_domain_nr(bus), bus->number,
  90. devfn, where, size, value);
  91. }
  92. static int
  93. pci_write (struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
  94. {
  95. return raw_pci_ops->write(pci_domain_nr(bus), bus->number,
  96. devfn, where, size, value);
  97. }
  98. struct pci_ops pci_root_ops = {
  99. .read = pci_read,
  100. .write = pci_write,
  101. };
  102. /* Called by ACPI when it finds a new root bus. */
  103. static struct pci_controller * __devinit
  104. alloc_pci_controller (int seg)
  105. {
  106. struct pci_controller *controller;
  107. controller = kzalloc(sizeof(*controller), GFP_KERNEL);
  108. if (!controller)
  109. return NULL;
  110. controller->segment = seg;
  111. controller->node = -1;
  112. return controller;
  113. }
  114. struct pci_root_info {
  115. struct pci_controller *controller;
  116. char *name;
  117. };
  118. static unsigned int
  119. new_space (u64 phys_base, int sparse)
  120. {
  121. u64 mmio_base;
  122. int i;
  123. if (phys_base == 0)
  124. return 0; /* legacy I/O port space */
  125. mmio_base = (u64) ioremap(phys_base, 0);
  126. for (i = 0; i < num_io_spaces; i++)
  127. if (io_space[i].mmio_base == mmio_base &&
  128. io_space[i].sparse == sparse)
  129. return i;
  130. if (num_io_spaces == MAX_IO_SPACES) {
  131. printk(KERN_ERR "PCI: Too many IO port spaces "
  132. "(MAX_IO_SPACES=%lu)\n", MAX_IO_SPACES);
  133. return ~0;
  134. }
  135. i = num_io_spaces++;
  136. io_space[i].mmio_base = mmio_base;
  137. io_space[i].sparse = sparse;
  138. return i;
  139. }
  140. static u64 __devinit
  141. add_io_space (struct pci_root_info *info, struct acpi_resource_address64 *addr)
  142. {
  143. struct resource *resource;
  144. char *name;
  145. u64 base, min, max, base_port;
  146. unsigned int sparse = 0, space_nr, len;
  147. resource = kzalloc(sizeof(*resource), GFP_KERNEL);
  148. if (!resource) {
  149. printk(KERN_ERR "PCI: No memory for %s I/O port space\n",
  150. info->name);
  151. goto out;
  152. }
  153. len = strlen(info->name) + 32;
  154. name = kzalloc(len, GFP_KERNEL);
  155. if (!name) {
  156. printk(KERN_ERR "PCI: No memory for %s I/O port space name\n",
  157. info->name);
  158. goto free_resource;
  159. }
  160. min = addr->minimum;
  161. max = min + addr->address_length - 1;
  162. if (addr->info.io.translation_type == ACPI_SPARSE_TRANSLATION)
  163. sparse = 1;
  164. space_nr = new_space(addr->translation_offset, sparse);
  165. if (space_nr == ~0)
  166. goto free_name;
  167. base = __pa(io_space[space_nr].mmio_base);
  168. base_port = IO_SPACE_BASE(space_nr);
  169. snprintf(name, len, "%s I/O Ports %08lx-%08lx", info->name,
  170. base_port + min, base_port + max);
  171. /*
  172. * The SDM guarantees the legacy 0-64K space is sparse, but if the
  173. * mapping is done by the processor (not the bridge), ACPI may not
  174. * mark it as sparse.
  175. */
  176. if (space_nr == 0)
  177. sparse = 1;
  178. resource->name = name;
  179. resource->flags = IORESOURCE_MEM;
  180. resource->start = base + (sparse ? IO_SPACE_SPARSE_ENCODING(min) : min);
  181. resource->end = base + (sparse ? IO_SPACE_SPARSE_ENCODING(max) : max);
  182. insert_resource(&iomem_resource, resource);
  183. return base_port;
  184. free_name:
  185. kfree(name);
  186. free_resource:
  187. kfree(resource);
  188. out:
  189. return ~0;
  190. }
  191. static acpi_status __devinit resource_to_window(struct acpi_resource *resource,
  192. struct acpi_resource_address64 *addr)
  193. {
  194. acpi_status status;
  195. /*
  196. * We're only interested in _CRS descriptors that are
  197. * - address space descriptors for memory or I/O space
  198. * - non-zero size
  199. * - producers, i.e., the address space is routed downstream,
  200. * not consumed by the bridge itself
  201. */
  202. status = acpi_resource_to_address64(resource, addr);
  203. if (ACPI_SUCCESS(status) &&
  204. (addr->resource_type == ACPI_MEMORY_RANGE ||
  205. addr->resource_type == ACPI_IO_RANGE) &&
  206. addr->address_length &&
  207. addr->producer_consumer == ACPI_PRODUCER)
  208. return AE_OK;
  209. return AE_ERROR;
  210. }
  211. static acpi_status __devinit
  212. count_window (struct acpi_resource *resource, void *data)
  213. {
  214. unsigned int *windows = (unsigned int *) data;
  215. struct acpi_resource_address64 addr;
  216. acpi_status status;
  217. status = resource_to_window(resource, &addr);
  218. if (ACPI_SUCCESS(status))
  219. (*windows)++;
  220. return AE_OK;
  221. }
  222. static __devinit acpi_status add_window(struct acpi_resource *res, void *data)
  223. {
  224. struct pci_root_info *info = data;
  225. struct pci_window *window;
  226. struct acpi_resource_address64 addr;
  227. acpi_status status;
  228. unsigned long flags, offset = 0;
  229. struct resource *root;
  230. /* Return AE_OK for non-window resources to keep scanning for more */
  231. status = resource_to_window(res, &addr);
  232. if (!ACPI_SUCCESS(status))
  233. return AE_OK;
  234. if (addr.resource_type == ACPI_MEMORY_RANGE) {
  235. flags = IORESOURCE_MEM;
  236. root = &iomem_resource;
  237. offset = addr.translation_offset;
  238. } else if (addr.resource_type == ACPI_IO_RANGE) {
  239. flags = IORESOURCE_IO;
  240. root = &ioport_resource;
  241. offset = add_io_space(info, &addr);
  242. if (offset == ~0)
  243. return AE_OK;
  244. } else
  245. return AE_OK;
  246. window = &info->controller->window[info->controller->windows++];
  247. window->resource.name = info->name;
  248. window->resource.flags = flags;
  249. window->resource.start = addr.minimum + offset;
  250. window->resource.end = window->resource.start + addr.address_length - 1;
  251. window->resource.child = NULL;
  252. window->offset = offset;
  253. if (insert_resource(root, &window->resource)) {
  254. printk(KERN_ERR "alloc 0x%lx-0x%lx from %s for %s failed\n",
  255. window->resource.start, window->resource.end,
  256. root->name, info->name);
  257. }
  258. return AE_OK;
  259. }
  260. static void __devinit
  261. pcibios_setup_root_windows(struct pci_bus *bus, struct pci_controller *ctrl)
  262. {
  263. int i, j;
  264. j = 0;
  265. for (i = 0; i < ctrl->windows; i++) {
  266. struct resource *res = &ctrl->window[i].resource;
  267. /* HP's firmware has a hack to work around a Windows bug.
  268. * Ignore these tiny memory ranges */
  269. if ((res->flags & IORESOURCE_MEM) &&
  270. (res->end - res->start < 16))
  271. continue;
  272. if (j >= PCI_BUS_NUM_RESOURCES) {
  273. printk("Ignoring range [%lx-%lx] (%lx)\n", res->start,
  274. res->end, res->flags);
  275. continue;
  276. }
  277. bus->resource[j++] = res;
  278. }
  279. }
  280. struct pci_bus * __devinit
  281. pci_acpi_scan_root(struct acpi_device *device, int domain, int bus)
  282. {
  283. struct pci_root_info info;
  284. struct pci_controller *controller;
  285. unsigned int windows = 0;
  286. struct pci_bus *pbus;
  287. char *name;
  288. int pxm;
  289. controller = alloc_pci_controller(domain);
  290. if (!controller)
  291. goto out1;
  292. controller->acpi_handle = device->handle;
  293. pxm = acpi_get_pxm(controller->acpi_handle);
  294. #ifdef CONFIG_NUMA
  295. if (pxm >= 0)
  296. controller->node = pxm_to_node(pxm);
  297. #endif
  298. acpi_walk_resources(device->handle, METHOD_NAME__CRS, count_window,
  299. &windows);
  300. controller->window = kmalloc_node(sizeof(*controller->window) * windows,
  301. GFP_KERNEL, controller->node);
  302. if (!controller->window)
  303. goto out2;
  304. name = kmalloc(16, GFP_KERNEL);
  305. if (!name)
  306. goto out3;
  307. sprintf(name, "PCI Bus %04x:%02x", domain, bus);
  308. info.controller = controller;
  309. info.name = name;
  310. acpi_walk_resources(device->handle, METHOD_NAME__CRS, add_window,
  311. &info);
  312. pbus = pci_scan_bus_parented(NULL, bus, &pci_root_ops, controller);
  313. if (pbus)
  314. pcibios_setup_root_windows(pbus, controller);
  315. return pbus;
  316. out3:
  317. kfree(controller->window);
  318. out2:
  319. kfree(controller);
  320. out1:
  321. return NULL;
  322. }
  323. void pcibios_resource_to_bus(struct pci_dev *dev,
  324. struct pci_bus_region *region, struct resource *res)
  325. {
  326. struct pci_controller *controller = PCI_CONTROLLER(dev);
  327. unsigned long offset = 0;
  328. int i;
  329. for (i = 0; i < controller->windows; i++) {
  330. struct pci_window *window = &controller->window[i];
  331. if (!(window->resource.flags & res->flags))
  332. continue;
  333. if (window->resource.start > res->start)
  334. continue;
  335. if (window->resource.end < res->end)
  336. continue;
  337. offset = window->offset;
  338. break;
  339. }
  340. region->start = res->start - offset;
  341. region->end = res->end - offset;
  342. }
  343. EXPORT_SYMBOL(pcibios_resource_to_bus);
  344. void pcibios_bus_to_resource(struct pci_dev *dev,
  345. struct resource *res, struct pci_bus_region *region)
  346. {
  347. struct pci_controller *controller = PCI_CONTROLLER(dev);
  348. unsigned long offset = 0;
  349. int i;
  350. for (i = 0; i < controller->windows; i++) {
  351. struct pci_window *window = &controller->window[i];
  352. if (!(window->resource.flags & res->flags))
  353. continue;
  354. if (window->resource.start - window->offset > region->start)
  355. continue;
  356. if (window->resource.end - window->offset < region->end)
  357. continue;
  358. offset = window->offset;
  359. break;
  360. }
  361. res->start = region->start + offset;
  362. res->end = region->end + offset;
  363. }
  364. EXPORT_SYMBOL(pcibios_bus_to_resource);
  365. static int __devinit is_valid_resource(struct pci_dev *dev, int idx)
  366. {
  367. unsigned int i, type_mask = IORESOURCE_IO | IORESOURCE_MEM;
  368. struct resource *devr = &dev->resource[idx];
  369. if (!dev->bus)
  370. return 0;
  371. for (i=0; i<PCI_BUS_NUM_RESOURCES; i++) {
  372. struct resource *busr = dev->bus->resource[i];
  373. if (!busr || ((busr->flags ^ devr->flags) & type_mask))
  374. continue;
  375. if ((devr->start) && (devr->start >= busr->start) &&
  376. (devr->end <= busr->end))
  377. return 1;
  378. }
  379. return 0;
  380. }
  381. static void __devinit
  382. pcibios_fixup_resources(struct pci_dev *dev, int start, int limit)
  383. {
  384. struct pci_bus_region region;
  385. int i;
  386. for (i = start; i < limit; i++) {
  387. if (!dev->resource[i].flags)
  388. continue;
  389. region.start = dev->resource[i].start;
  390. region.end = dev->resource[i].end;
  391. pcibios_bus_to_resource(dev, &dev->resource[i], &region);
  392. if ((is_valid_resource(dev, i)))
  393. pci_claim_resource(dev, i);
  394. }
  395. }
  396. void __devinit pcibios_fixup_device_resources(struct pci_dev *dev)
  397. {
  398. pcibios_fixup_resources(dev, 0, PCI_BRIDGE_RESOURCES);
  399. }
  400. EXPORT_SYMBOL_GPL(pcibios_fixup_device_resources);
  401. static void __devinit pcibios_fixup_bridge_resources(struct pci_dev *dev)
  402. {
  403. pcibios_fixup_resources(dev, PCI_BRIDGE_RESOURCES, PCI_NUM_RESOURCES);
  404. }
  405. /*
  406. * Called after each bus is probed, but before its children are examined.
  407. */
  408. void __devinit
  409. pcibios_fixup_bus (struct pci_bus *b)
  410. {
  411. struct pci_dev *dev;
  412. if (b->self) {
  413. pci_read_bridge_bases(b);
  414. pcibios_fixup_bridge_resources(b->self);
  415. }
  416. list_for_each_entry(dev, &b->devices, bus_list)
  417. pcibios_fixup_device_resources(dev);
  418. platform_pci_fixup_bus(b);
  419. return;
  420. }
  421. void __devinit
  422. pcibios_update_irq (struct pci_dev *dev, int irq)
  423. {
  424. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);
  425. /* ??? FIXME -- record old value for shutdown. */
  426. }
  427. static inline int
  428. pcibios_enable_resources (struct pci_dev *dev, int mask)
  429. {
  430. u16 cmd, old_cmd;
  431. int idx;
  432. struct resource *r;
  433. unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM;
  434. if (!dev)
  435. return -EINVAL;
  436. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  437. old_cmd = cmd;
  438. for (idx=0; idx<PCI_NUM_RESOURCES; idx++) {
  439. /* Only set up the desired resources. */
  440. if (!(mask & (1 << idx)))
  441. continue;
  442. r = &dev->resource[idx];
  443. if (!(r->flags & type_mask))
  444. continue;
  445. if ((idx == PCI_ROM_RESOURCE) &&
  446. (!(r->flags & IORESOURCE_ROM_ENABLE)))
  447. continue;
  448. if (!r->start && r->end) {
  449. printk(KERN_ERR
  450. "PCI: Device %s not available because of resource collisions\n",
  451. pci_name(dev));
  452. return -EINVAL;
  453. }
  454. if (r->flags & IORESOURCE_IO)
  455. cmd |= PCI_COMMAND_IO;
  456. if (r->flags & IORESOURCE_MEM)
  457. cmd |= PCI_COMMAND_MEMORY;
  458. }
  459. if (cmd != old_cmd) {
  460. printk("PCI: Enabling device %s (%04x -> %04x)\n", pci_name(dev), old_cmd, cmd);
  461. pci_write_config_word(dev, PCI_COMMAND, cmd);
  462. }
  463. return 0;
  464. }
  465. int
  466. pcibios_enable_device (struct pci_dev *dev, int mask)
  467. {
  468. int ret;
  469. ret = pcibios_enable_resources(dev, mask);
  470. if (ret < 0)
  471. return ret;
  472. return acpi_pci_irq_enable(dev);
  473. }
  474. void
  475. pcibios_disable_device (struct pci_dev *dev)
  476. {
  477. BUG_ON(atomic_read(&dev->enable_cnt));
  478. acpi_pci_irq_disable(dev);
  479. }
  480. void
  481. pcibios_align_resource (void *data, struct resource *res,
  482. resource_size_t size, resource_size_t align)
  483. {
  484. }
  485. /*
  486. * PCI BIOS setup, always defaults to SAL interface
  487. */
  488. char * __init
  489. pcibios_setup (char *str)
  490. {
  491. return str;
  492. }
  493. int
  494. pci_mmap_page_range (struct pci_dev *dev, struct vm_area_struct *vma,
  495. enum pci_mmap_state mmap_state, int write_combine)
  496. {
  497. /*
  498. * I/O space cannot be accessed via normal processor loads and
  499. * stores on this platform.
  500. */
  501. if (mmap_state == pci_mmap_io)
  502. /*
  503. * XXX we could relax this for I/O spaces for which ACPI
  504. * indicates that the space is 1-to-1 mapped. But at the
  505. * moment, we don't support multiple PCI address spaces and
  506. * the legacy I/O space is not 1-to-1 mapped, so this is moot.
  507. */
  508. return -EINVAL;
  509. /*
  510. * Leave vm_pgoff as-is, the PCI space address is the physical
  511. * address on this platform.
  512. */
  513. if (write_combine && efi_range_is_wc(vma->vm_start,
  514. vma->vm_end - vma->vm_start))
  515. vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
  516. else
  517. vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  518. if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
  519. vma->vm_end - vma->vm_start, vma->vm_page_prot))
  520. return -EAGAIN;
  521. return 0;
  522. }
  523. /**
  524. * ia64_pci_get_legacy_mem - generic legacy mem routine
  525. * @bus: bus to get legacy memory base address for
  526. *
  527. * Find the base of legacy memory for @bus. This is typically the first
  528. * megabyte of bus address space for @bus or is simply 0 on platforms whose
  529. * chipsets support legacy I/O and memory routing. Returns the base address
  530. * or an error pointer if an error occurred.
  531. *
  532. * This is the ia64 generic version of this routine. Other platforms
  533. * are free to override it with a machine vector.
  534. */
  535. char *ia64_pci_get_legacy_mem(struct pci_bus *bus)
  536. {
  537. return (char *)__IA64_UNCACHED_OFFSET;
  538. }
  539. /**
  540. * pci_mmap_legacy_page_range - map legacy memory space to userland
  541. * @bus: bus whose legacy space we're mapping
  542. * @vma: vma passed in by mmap
  543. *
  544. * Map legacy memory space for this device back to userspace using a machine
  545. * vector to get the base address.
  546. */
  547. int
  548. pci_mmap_legacy_page_range(struct pci_bus *bus, struct vm_area_struct *vma)
  549. {
  550. unsigned long size = vma->vm_end - vma->vm_start;
  551. pgprot_t prot;
  552. char *addr;
  553. /*
  554. * Avoid attribute aliasing. See Documentation/ia64/aliasing.txt
  555. * for more details.
  556. */
  557. if (!valid_mmap_phys_addr_range(vma->vm_pgoff, size))
  558. return -EINVAL;
  559. prot = phys_mem_access_prot(NULL, vma->vm_pgoff, size,
  560. vma->vm_page_prot);
  561. if (pgprot_val(prot) != pgprot_val(pgprot_noncached(vma->vm_page_prot)))
  562. return -EINVAL;
  563. addr = pci_get_legacy_mem(bus);
  564. if (IS_ERR(addr))
  565. return PTR_ERR(addr);
  566. vma->vm_pgoff += (unsigned long)addr >> PAGE_SHIFT;
  567. vma->vm_page_prot = prot;
  568. if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
  569. size, vma->vm_page_prot))
  570. return -EAGAIN;
  571. return 0;
  572. }
  573. /**
  574. * ia64_pci_legacy_read - read from legacy I/O space
  575. * @bus: bus to read
  576. * @port: legacy port value
  577. * @val: caller allocated storage for returned value
  578. * @size: number of bytes to read
  579. *
  580. * Simply reads @size bytes from @port and puts the result in @val.
  581. *
  582. * Again, this (and the write routine) are generic versions that can be
  583. * overridden by the platform. This is necessary on platforms that don't
  584. * support legacy I/O routing or that hard fail on legacy I/O timeouts.
  585. */
  586. int ia64_pci_legacy_read(struct pci_bus *bus, u16 port, u32 *val, u8 size)
  587. {
  588. int ret = size;
  589. switch (size) {
  590. case 1:
  591. *val = inb(port);
  592. break;
  593. case 2:
  594. *val = inw(port);
  595. break;
  596. case 4:
  597. *val = inl(port);
  598. break;
  599. default:
  600. ret = -EINVAL;
  601. break;
  602. }
  603. return ret;
  604. }
  605. /**
  606. * ia64_pci_legacy_write - perform a legacy I/O write
  607. * @bus: bus pointer
  608. * @port: port to write
  609. * @val: value to write
  610. * @size: number of bytes to write from @val
  611. *
  612. * Simply writes @size bytes of @val to @port.
  613. */
  614. int ia64_pci_legacy_write(struct pci_bus *bus, u16 port, u32 val, u8 size)
  615. {
  616. int ret = size;
  617. switch (size) {
  618. case 1:
  619. outb(val, port);
  620. break;
  621. case 2:
  622. outw(val, port);
  623. break;
  624. case 4:
  625. outl(val, port);
  626. break;
  627. default:
  628. ret = -EINVAL;
  629. break;
  630. }
  631. return ret;
  632. }
  633. /* It's defined in drivers/pci/pci.c */
  634. extern u8 pci_cache_line_size;
  635. /**
  636. * set_pci_cacheline_size - determine cacheline size for PCI devices
  637. *
  638. * We want to use the line-size of the outer-most cache. We assume
  639. * that this line-size is the same for all CPUs.
  640. *
  641. * Code mostly taken from arch/ia64/kernel/palinfo.c:cache_info().
  642. */
  643. static void __init set_pci_cacheline_size(void)
  644. {
  645. u64 levels, unique_caches;
  646. s64 status;
  647. pal_cache_config_info_t cci;
  648. status = ia64_pal_cache_summary(&levels, &unique_caches);
  649. if (status != 0) {
  650. printk(KERN_ERR "%s: ia64_pal_cache_summary() failed "
  651. "(status=%ld)\n", __FUNCTION__, status);
  652. return;
  653. }
  654. status = ia64_pal_cache_config_info(levels - 1,
  655. /* cache_type (data_or_unified)= */ 2, &cci);
  656. if (status != 0) {
  657. printk(KERN_ERR "%s: ia64_pal_cache_config_info() failed "
  658. "(status=%ld)\n", __FUNCTION__, status);
  659. return;
  660. }
  661. pci_cache_line_size = (1 << cci.pcci_line_size) / 4;
  662. }
  663. static int __init pcibios_init(void)
  664. {
  665. set_pci_cacheline_size();
  666. return 0;
  667. }
  668. subsys_initcall(pcibios_init);