pci.c 18 KB

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