pci.c 18 KB

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