pci.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  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/system.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 * __devinit
  102. alloc_pci_controller (int seg)
  103. {
  104. struct pci_controller *controller;
  105. controller = kzalloc(sizeof(*controller), GFP_KERNEL);
  106. if (!controller)
  107. return NULL;
  108. controller->segment = seg;
  109. controller->node = -1;
  110. return controller;
  111. }
  112. struct pci_root_info {
  113. struct acpi_device *bridge;
  114. struct pci_controller *controller;
  115. struct list_head resources;
  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. unsigned long 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. dev_err(&info->bridge->dev,
  255. "can't allocate host bridge window %pR\n",
  256. &window->resource);
  257. } else {
  258. if (offset)
  259. dev_info(&info->bridge->dev, "host bridge window %pR "
  260. "(PCI address [%#llx-%#llx])\n",
  261. &window->resource,
  262. window->resource.start - offset,
  263. window->resource.end - offset);
  264. else
  265. dev_info(&info->bridge->dev,
  266. "host bridge window %pR\n",
  267. &window->resource);
  268. }
  269. /* HP's firmware has a hack to work around a Windows bug.
  270. * Ignore these tiny memory ranges */
  271. if (!((window->resource.flags & IORESOURCE_MEM) &&
  272. (window->resource.end - window->resource.start < 16)))
  273. pci_add_resource(&info->resources, &window->resource);
  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. acpi_walk_resources(device->handle, METHOD_NAME__CRS, count_window,
  299. &windows);
  300. if (windows) {
  301. controller->window =
  302. kmalloc_node(sizeof(*controller->window) * windows,
  303. GFP_KERNEL, controller->node);
  304. if (!controller->window)
  305. goto out2;
  306. name = kmalloc(16, GFP_KERNEL);
  307. if (!name)
  308. goto out3;
  309. sprintf(name, "PCI Bus %04x:%02x", domain, bus);
  310. info.bridge = device;
  311. info.controller = controller;
  312. info.name = name;
  313. acpi_walk_resources(device->handle, METHOD_NAME__CRS,
  314. add_window, &info);
  315. }
  316. /*
  317. * See arch/x86/pci/acpi.c.
  318. * The desired pci bus might already be scanned in a quirk. We
  319. * should handle the case here, but it appears that IA64 hasn't
  320. * such quirk. So we just ignore the case now.
  321. */
  322. pbus = pci_create_root_bus(NULL, bus, &pci_root_ops, controller,
  323. &info.resources);
  324. if (!pbus) {
  325. pci_free_resource_list(&info.resources);
  326. return NULL;
  327. }
  328. pbus->subordinate = pci_scan_child_bus(pbus);
  329. return pbus;
  330. out3:
  331. kfree(controller->window);
  332. out2:
  333. kfree(controller);
  334. out1:
  335. return NULL;
  336. }
  337. void pcibios_resource_to_bus(struct pci_dev *dev,
  338. struct pci_bus_region *region, struct resource *res)
  339. {
  340. struct pci_controller *controller = PCI_CONTROLLER(dev);
  341. unsigned long offset = 0;
  342. int i;
  343. for (i = 0; i < controller->windows; i++) {
  344. struct pci_window *window = &controller->window[i];
  345. if (!(window->resource.flags & res->flags))
  346. continue;
  347. if (window->resource.start > res->start)
  348. continue;
  349. if (window->resource.end < res->end)
  350. continue;
  351. offset = window->offset;
  352. break;
  353. }
  354. region->start = res->start - offset;
  355. region->end = res->end - offset;
  356. }
  357. EXPORT_SYMBOL(pcibios_resource_to_bus);
  358. void pcibios_bus_to_resource(struct pci_dev *dev,
  359. struct resource *res, struct pci_bus_region *region)
  360. {
  361. struct pci_controller *controller = PCI_CONTROLLER(dev);
  362. unsigned long offset = 0;
  363. int i;
  364. for (i = 0; i < controller->windows; i++) {
  365. struct pci_window *window = &controller->window[i];
  366. if (!(window->resource.flags & res->flags))
  367. continue;
  368. if (window->resource.start - window->offset > region->start)
  369. continue;
  370. if (window->resource.end - window->offset < region->end)
  371. continue;
  372. offset = window->offset;
  373. break;
  374. }
  375. res->start = region->start + offset;
  376. res->end = region->end + offset;
  377. }
  378. EXPORT_SYMBOL(pcibios_bus_to_resource);
  379. static int __devinit is_valid_resource(struct pci_dev *dev, int idx)
  380. {
  381. unsigned int i, type_mask = IORESOURCE_IO | IORESOURCE_MEM;
  382. struct resource *devr = &dev->resource[idx], *busr;
  383. if (!dev->bus)
  384. return 0;
  385. pci_bus_for_each_resource(dev->bus, busr, i) {
  386. if (!busr || ((busr->flags ^ devr->flags) & type_mask))
  387. continue;
  388. if ((devr->start) && (devr->start >= busr->start) &&
  389. (devr->end <= busr->end))
  390. return 1;
  391. }
  392. return 0;
  393. }
  394. static void __devinit
  395. pcibios_fixup_resources(struct pci_dev *dev, int start, int limit)
  396. {
  397. struct pci_bus_region region;
  398. int i;
  399. for (i = start; i < limit; i++) {
  400. if (!dev->resource[i].flags)
  401. continue;
  402. region.start = dev->resource[i].start;
  403. region.end = dev->resource[i].end;
  404. pcibios_bus_to_resource(dev, &dev->resource[i], &region);
  405. if ((is_valid_resource(dev, i)))
  406. pci_claim_resource(dev, i);
  407. }
  408. }
  409. void __devinit pcibios_fixup_device_resources(struct pci_dev *dev)
  410. {
  411. pcibios_fixup_resources(dev, 0, PCI_BRIDGE_RESOURCES);
  412. }
  413. EXPORT_SYMBOL_GPL(pcibios_fixup_device_resources);
  414. static void __devinit pcibios_fixup_bridge_resources(struct pci_dev *dev)
  415. {
  416. pcibios_fixup_resources(dev, PCI_BRIDGE_RESOURCES, PCI_NUM_RESOURCES);
  417. }
  418. /*
  419. * Called after each bus is probed, but before its children are examined.
  420. */
  421. void __devinit
  422. pcibios_fixup_bus (struct pci_bus *b)
  423. {
  424. struct pci_dev *dev;
  425. if (b->self) {
  426. pci_read_bridge_bases(b);
  427. pcibios_fixup_bridge_resources(b->self);
  428. }
  429. list_for_each_entry(dev, &b->devices, bus_list)
  430. pcibios_fixup_device_resources(dev);
  431. platform_pci_fixup_bus(b);
  432. }
  433. void pcibios_set_master (struct pci_dev *dev)
  434. {
  435. /* No special bus mastering setup handling */
  436. }
  437. void __devinit
  438. pcibios_update_irq (struct pci_dev *dev, int irq)
  439. {
  440. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, irq);
  441. /* ??? FIXME -- record old value for shutdown. */
  442. }
  443. int
  444. pcibios_enable_device (struct pci_dev *dev, int mask)
  445. {
  446. int ret;
  447. ret = pci_enable_resources(dev, mask);
  448. if (ret < 0)
  449. return ret;
  450. if (!dev->msi_enabled)
  451. return acpi_pci_irq_enable(dev);
  452. return 0;
  453. }
  454. void
  455. pcibios_disable_device (struct pci_dev *dev)
  456. {
  457. BUG_ON(atomic_read(&dev->enable_cnt));
  458. if (!dev->msi_enabled)
  459. acpi_pci_irq_disable(dev);
  460. }
  461. resource_size_t
  462. pcibios_align_resource (void *data, const struct resource *res,
  463. resource_size_t size, resource_size_t align)
  464. {
  465. return res->start;
  466. }
  467. /*
  468. * PCI BIOS setup, always defaults to SAL interface
  469. */
  470. char * __init
  471. pcibios_setup (char *str)
  472. {
  473. return str;
  474. }
  475. int
  476. pci_mmap_page_range (struct pci_dev *dev, struct vm_area_struct *vma,
  477. enum pci_mmap_state mmap_state, int write_combine)
  478. {
  479. unsigned long size = vma->vm_end - vma->vm_start;
  480. pgprot_t prot;
  481. /*
  482. * I/O space cannot be accessed via normal processor loads and
  483. * stores on this platform.
  484. */
  485. if (mmap_state == pci_mmap_io)
  486. /*
  487. * XXX we could relax this for I/O spaces for which ACPI
  488. * indicates that the space is 1-to-1 mapped. But at the
  489. * moment, we don't support multiple PCI address spaces and
  490. * the legacy I/O space is not 1-to-1 mapped, so this is moot.
  491. */
  492. return -EINVAL;
  493. if (!valid_mmap_phys_addr_range(vma->vm_pgoff, size))
  494. return -EINVAL;
  495. prot = phys_mem_access_prot(NULL, vma->vm_pgoff, size,
  496. vma->vm_page_prot);
  497. /*
  498. * If the user requested WC, the kernel uses UC or WC for this region,
  499. * and the chipset supports WC, we can use WC. Otherwise, we have to
  500. * use the same attribute the kernel uses.
  501. */
  502. if (write_combine &&
  503. ((pgprot_val(prot) & _PAGE_MA_MASK) == _PAGE_MA_UC ||
  504. (pgprot_val(prot) & _PAGE_MA_MASK) == _PAGE_MA_WC) &&
  505. efi_range_is_wc(vma->vm_start, vma->vm_end - vma->vm_start))
  506. vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
  507. else
  508. vma->vm_page_prot = prot;
  509. if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
  510. vma->vm_end - vma->vm_start, vma->vm_page_prot))
  511. return -EAGAIN;
  512. return 0;
  513. }
  514. /**
  515. * ia64_pci_get_legacy_mem - generic legacy mem routine
  516. * @bus: bus to get legacy memory base address for
  517. *
  518. * Find the base of legacy memory for @bus. This is typically the first
  519. * megabyte of bus address space for @bus or is simply 0 on platforms whose
  520. * chipsets support legacy I/O and memory routing. Returns the base address
  521. * or an error pointer if an error occurred.
  522. *
  523. * This is the ia64 generic version of this routine. Other platforms
  524. * are free to override it with a machine vector.
  525. */
  526. char *ia64_pci_get_legacy_mem(struct pci_bus *bus)
  527. {
  528. return (char *)__IA64_UNCACHED_OFFSET;
  529. }
  530. /**
  531. * pci_mmap_legacy_page_range - map legacy memory space to userland
  532. * @bus: bus whose legacy space we're mapping
  533. * @vma: vma passed in by mmap
  534. *
  535. * Map legacy memory space for this device back to userspace using a machine
  536. * vector to get the base address.
  537. */
  538. int
  539. pci_mmap_legacy_page_range(struct pci_bus *bus, struct vm_area_struct *vma,
  540. enum pci_mmap_state mmap_state)
  541. {
  542. unsigned long size = vma->vm_end - vma->vm_start;
  543. pgprot_t prot;
  544. char *addr;
  545. /* We only support mmap'ing of legacy memory space */
  546. if (mmap_state != pci_mmap_mem)
  547. return -ENOSYS;
  548. /*
  549. * Avoid attribute aliasing. See Documentation/ia64/aliasing.txt
  550. * for more details.
  551. */
  552. if (!valid_mmap_phys_addr_range(vma->vm_pgoff, size))
  553. return -EINVAL;
  554. prot = phys_mem_access_prot(NULL, vma->vm_pgoff, size,
  555. vma->vm_page_prot);
  556. addr = pci_get_legacy_mem(bus);
  557. if (IS_ERR(addr))
  558. return PTR_ERR(addr);
  559. vma->vm_pgoff += (unsigned long)addr >> PAGE_SHIFT;
  560. vma->vm_page_prot = prot;
  561. if (remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
  562. size, vma->vm_page_prot))
  563. return -EAGAIN;
  564. return 0;
  565. }
  566. /**
  567. * ia64_pci_legacy_read - read from legacy I/O space
  568. * @bus: bus to read
  569. * @port: legacy port value
  570. * @val: caller allocated storage for returned value
  571. * @size: number of bytes to read
  572. *
  573. * Simply reads @size bytes from @port and puts the result in @val.
  574. *
  575. * Again, this (and the write routine) are generic versions that can be
  576. * overridden by the platform. This is necessary on platforms that don't
  577. * support legacy I/O routing or that hard fail on legacy I/O timeouts.
  578. */
  579. int ia64_pci_legacy_read(struct pci_bus *bus, u16 port, u32 *val, u8 size)
  580. {
  581. int ret = size;
  582. switch (size) {
  583. case 1:
  584. *val = inb(port);
  585. break;
  586. case 2:
  587. *val = inw(port);
  588. break;
  589. case 4:
  590. *val = inl(port);
  591. break;
  592. default:
  593. ret = -EINVAL;
  594. break;
  595. }
  596. return ret;
  597. }
  598. /**
  599. * ia64_pci_legacy_write - perform a legacy I/O write
  600. * @bus: bus pointer
  601. * @port: port to write
  602. * @val: value to write
  603. * @size: number of bytes to write from @val
  604. *
  605. * Simply writes @size bytes of @val to @port.
  606. */
  607. int ia64_pci_legacy_write(struct pci_bus *bus, u16 port, u32 val, u8 size)
  608. {
  609. int ret = size;
  610. switch (size) {
  611. case 1:
  612. outb(val, port);
  613. break;
  614. case 2:
  615. outw(val, port);
  616. break;
  617. case 4:
  618. outl(val, port);
  619. break;
  620. default:
  621. ret = -EINVAL;
  622. break;
  623. }
  624. return ret;
  625. }
  626. /**
  627. * set_pci_cacheline_size - determine cacheline size for PCI devices
  628. *
  629. * We want to use the line-size of the outer-most cache. We assume
  630. * that this line-size is the same for all CPUs.
  631. *
  632. * Code mostly taken from arch/ia64/kernel/palinfo.c:cache_info().
  633. */
  634. static void __init set_pci_dfl_cacheline_size(void)
  635. {
  636. unsigned long levels, unique_caches;
  637. long status;
  638. pal_cache_config_info_t cci;
  639. status = ia64_pal_cache_summary(&levels, &unique_caches);
  640. if (status != 0) {
  641. printk(KERN_ERR "%s: ia64_pal_cache_summary() failed "
  642. "(status=%ld)\n", __func__, status);
  643. return;
  644. }
  645. status = ia64_pal_cache_config_info(levels - 1,
  646. /* cache_type (data_or_unified)= */ 2, &cci);
  647. if (status != 0) {
  648. printk(KERN_ERR "%s: ia64_pal_cache_config_info() failed "
  649. "(status=%ld)\n", __func__, status);
  650. return;
  651. }
  652. pci_dfl_cache_line_size = (1 << cci.pcci_line_size) / 4;
  653. }
  654. u64 ia64_dma_get_required_mask(struct device *dev)
  655. {
  656. u32 low_totalram = ((max_pfn - 1) << PAGE_SHIFT);
  657. u32 high_totalram = ((max_pfn - 1) >> (32 - PAGE_SHIFT));
  658. u64 mask;
  659. if (!high_totalram) {
  660. /* convert to mask just covering totalram */
  661. low_totalram = (1 << (fls(low_totalram) - 1));
  662. low_totalram += low_totalram - 1;
  663. mask = low_totalram;
  664. } else {
  665. high_totalram = (1 << (fls(high_totalram) - 1));
  666. high_totalram += high_totalram - 1;
  667. mask = (((u64)high_totalram) << 32) + 0xffffffff;
  668. }
  669. return mask;
  670. }
  671. EXPORT_SYMBOL_GPL(ia64_dma_get_required_mask);
  672. u64 dma_get_required_mask(struct device *dev)
  673. {
  674. return platform_dma_get_required_mask(dev);
  675. }
  676. EXPORT_SYMBOL_GPL(dma_get_required_mask);
  677. static int __init pcibios_init(void)
  678. {
  679. set_pci_dfl_cacheline_size();
  680. return 0;
  681. }
  682. subsys_initcall(pcibios_init);