pci.c 19 KB

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