pci.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * arch/xtensa/kernel/pci.c
  4. *
  5. * PCI bios-type initialisation for PCI machines
  6. *
  7. * Copyright (C) 2001-2005 Tensilica Inc.
  8. *
  9. * Based largely on work from Cort (ppc/kernel/pci.c)
  10. * IO functions copied from sparc.
  11. *
  12. * Chris Zankel <chris@zankel.net>
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/pci.h>
  16. #include <linux/delay.h>
  17. #include <linux/string.h>
  18. #include <linux/init.h>
  19. #include <linux/sched.h>
  20. #include <linux/errno.h>
  21. #include <linux/memblock.h>
  22. #include <asm/pci-bridge.h>
  23. #include <asm/platform.h>
  24. /*
  25. * We need to avoid collisions with `mirrored' VGA ports
  26. * and other strange ISA hardware, so we always want the
  27. * addresses to be allocated in the 0x000-0x0ff region
  28. * modulo 0x400.
  29. *
  30. * Why? Because some silly external IO cards only decode
  31. * the low 10 bits of the IO address. The 0x00-0xff region
  32. * is reserved for motherboard devices that decode all 16
  33. * bits, so it's ok to allocate at, say, 0x2800-0x28ff,
  34. * but we want to try to avoid allocating at 0x2900-0x2bff
  35. * which might have be mirrored at 0x0100-0x03ff..
  36. */
  37. resource_size_t
  38. pcibios_align_resource(void *data, const struct resource *res,
  39. resource_size_t size, resource_size_t align)
  40. {
  41. struct pci_dev *dev = data;
  42. resource_size_t start = res->start;
  43. if (res->flags & IORESOURCE_IO) {
  44. if (size > 0x100) {
  45. pr_err("PCI: I/O Region %s/%d too large (%u bytes)\n",
  46. pci_name(dev), dev->resource - res,
  47. size);
  48. }
  49. if (start & 0x300)
  50. start = (start + 0x3ff) & ~0x3ff;
  51. }
  52. return start;
  53. }
  54. void pcibios_fixup_bus(struct pci_bus *bus)
  55. {
  56. if (bus->parent) {
  57. /* This is a subordinate bridge */
  58. pci_read_bridge_bases(bus);
  59. }
  60. }
  61. /*
  62. * Platform support for /proc/bus/pci/X/Y mmap()s.
  63. * -- paulus.
  64. */
  65. int pci_iobar_pfn(struct pci_dev *pdev, int bar, struct vm_area_struct *vma)
  66. {
  67. struct pci_controller *pci_ctrl = (struct pci_controller*) pdev->sysdata;
  68. resource_size_t ioaddr = pci_resource_start(pdev, bar);
  69. if (pci_ctrl == 0)
  70. return -EINVAL; /* should never happen */
  71. /* Convert to an offset within this PCI controller */
  72. ioaddr -= (unsigned long)pci_ctrl->io_space.base;
  73. vma->vm_pgoff += (ioaddr + pci_ctrl->io_space.start) >> PAGE_SHIFT;
  74. return 0;
  75. }