pci.c 18 KB

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