pci-generic.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2016 Imagination Technologies
  4. * Author: Paul Burton <[email protected]>
  5. *
  6. * pcibios_align_resource taken from arch/arm/kernel/bios32.c.
  7. */
  8. #include <linux/pci.h>
  9. /*
  10. * We need to avoid collisions with `mirrored' VGA ports
  11. * and other strange ISA hardware, so we always want the
  12. * addresses to be allocated in the 0x000-0x0ff region
  13. * modulo 0x400.
  14. *
  15. * Why? Because some silly external IO cards only decode
  16. * the low 10 bits of the IO address. The 0x00-0xff region
  17. * is reserved for motherboard devices that decode all 16
  18. * bits, so it's ok to allocate at, say, 0x2800-0x28ff,
  19. * but we want to try to avoid allocating at 0x2900-0x2bff
  20. * which might have be mirrored at 0x0100-0x03ff..
  21. */
  22. resource_size_t pcibios_align_resource(void *data, const struct resource *res,
  23. resource_size_t size, resource_size_t align)
  24. {
  25. struct pci_dev *dev = data;
  26. resource_size_t start = res->start;
  27. struct pci_host_bridge *host_bridge;
  28. if (res->flags & IORESOURCE_IO && start & 0x300)
  29. start = (start + 0x3ff) & ~0x3ff;
  30. start = (start + align - 1) & ~(align - 1);
  31. host_bridge = pci_find_host_bridge(dev->bus);
  32. if (host_bridge->align_resource)
  33. return host_bridge->align_resource(dev, res,
  34. start, size, align);
  35. return start;
  36. }
  37. void pcibios_fixup_bus(struct pci_bus *bus)
  38. {
  39. pci_read_bridge_bases(bus);
  40. }
  41. #ifdef pci_remap_iospace
  42. int pci_remap_iospace(const struct resource *res, phys_addr_t phys_addr)
  43. {
  44. unsigned long vaddr;
  45. if (res->start != 0) {
  46. WARN_ONCE(1, "resource start address is not zero\n");
  47. return -ENODEV;
  48. }
  49. vaddr = (unsigned long)ioremap(phys_addr, resource_size(res));
  50. set_io_port_base(vaddr);
  51. return 0;
  52. }
  53. #endif