pci.c 19 KB

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