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