pci-ecam.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright 2016 Broadcom
  4. */
  5. #ifndef DRIVERS_PCI_ECAM_H
  6. #define DRIVERS_PCI_ECAM_H
  7. #include <linux/pci.h>
  8. #include <linux/kernel.h>
  9. #include <linux/platform_device.h>
  10. /*
  11. * Memory address shift values for the byte-level address that
  12. * can be used when accessing the PCI Express Configuration Space.
  13. */
  14. /*
  15. * Enhanced Configuration Access Mechanism (ECAM)
  16. *
  17. * See PCI Express Base Specification, Revision 5.0, Version 1.0,
  18. * Section 7.2.2, Table 7-1, p. 677.
  19. */
  20. #define PCIE_ECAM_BUS_SHIFT 20 /* Bus number */
  21. #define PCIE_ECAM_DEVFN_SHIFT 12 /* Device and Function number */
  22. #define PCIE_ECAM_BUS_MASK 0xff
  23. #define PCIE_ECAM_DEVFN_MASK 0xff
  24. #define PCIE_ECAM_REG_MASK 0xfff /* Limit offset to a maximum of 4K */
  25. #define PCIE_ECAM_BUS(x) (((x) & PCIE_ECAM_BUS_MASK) << PCIE_ECAM_BUS_SHIFT)
  26. #define PCIE_ECAM_DEVFN(x) (((x) & PCIE_ECAM_DEVFN_MASK) << PCIE_ECAM_DEVFN_SHIFT)
  27. #define PCIE_ECAM_REG(x) ((x) & PCIE_ECAM_REG_MASK)
  28. #define PCIE_ECAM_OFFSET(bus, devfn, where) \
  29. (PCIE_ECAM_BUS(bus) | \
  30. PCIE_ECAM_DEVFN(devfn) | \
  31. PCIE_ECAM_REG(where))
  32. /*
  33. * struct to hold pci ops and bus shift of the config window
  34. * for a PCI controller.
  35. */
  36. struct pci_config_window;
  37. struct pci_ecam_ops {
  38. unsigned int bus_shift;
  39. struct pci_ops pci_ops;
  40. int (*init)(struct pci_config_window *);
  41. };
  42. /*
  43. * struct to hold the mappings of a config space window. This
  44. * is expected to be used as sysdata for PCI controllers that
  45. * use ECAM.
  46. */
  47. struct pci_config_window {
  48. struct resource res;
  49. struct resource busr;
  50. unsigned int bus_shift;
  51. void *priv;
  52. const struct pci_ecam_ops *ops;
  53. union {
  54. void __iomem *win; /* 64-bit single mapping */
  55. void __iomem **winp; /* 32-bit per-bus mapping */
  56. };
  57. struct device *parent;/* ECAM res was from this dev */
  58. };
  59. /* create and free pci_config_window */
  60. struct pci_config_window *pci_ecam_create(struct device *dev,
  61. struct resource *cfgres, struct resource *busr,
  62. const struct pci_ecam_ops *ops);
  63. void pci_ecam_free(struct pci_config_window *cfg);
  64. /* map_bus when ->sysdata is an instance of pci_config_window */
  65. void __iomem *pci_ecam_map_bus(struct pci_bus *bus, unsigned int devfn,
  66. int where);
  67. /* default ECAM ops */
  68. extern const struct pci_ecam_ops pci_generic_ecam_ops;
  69. #if defined(CONFIG_ACPI) && defined(CONFIG_PCI_QUIRKS)
  70. extern const struct pci_ecam_ops pci_32b_ops; /* 32-bit accesses only */
  71. extern const struct pci_ecam_ops pci_32b_read_ops; /* 32-bit read only */
  72. extern const struct pci_ecam_ops hisi_pcie_ops; /* HiSilicon */
  73. extern const struct pci_ecam_ops thunder_pem_ecam_ops; /* Cavium ThunderX 1.x & 2.x */
  74. extern const struct pci_ecam_ops pci_thunder_ecam_ops; /* Cavium ThunderX 1.x */
  75. extern const struct pci_ecam_ops xgene_v1_pcie_ecam_ops; /* APM X-Gene PCIe v1 */
  76. extern const struct pci_ecam_ops xgene_v2_pcie_ecam_ops; /* APM X-Gene PCIe v2.x */
  77. extern const struct pci_ecam_ops al_pcie_ops; /* Amazon Annapurna Labs PCIe */
  78. extern const struct pci_ecam_ops tegra194_pcie_ops; /* Tegra194 PCIe */
  79. extern const struct pci_ecam_ops loongson_pci_ecam_ops; /* Loongson PCIe */
  80. #endif
  81. #if IS_ENABLED(CONFIG_PCI_HOST_COMMON)
  82. /* for DT-based PCI controllers that support ECAM */
  83. int pci_host_common_probe(struct platform_device *pdev);
  84. int pci_host_common_remove(struct platform_device *pdev);
  85. #endif
  86. #endif