ecam.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2022-10-24 GuEe-GUI first version
  9. */
  10. #ifndef __RT_PCI_ECAM_H__
  11. #define __RT_PCI_ECAM_H__
  12. #include <drivers/pci.h>
  13. #include <drivers/ofw.h>
  14. #include <drivers/ofw_io.h>
  15. #include <drivers/platform.h>
  16. /*
  17. * Memory address shift values for the byte-level address that
  18. * can be used when accessing the PCI Express Configuration Space.
  19. */
  20. /*
  21. * Enhanced Configuration Access Mechanism (ECAM)
  22. *
  23. * See PCI Express Base Specification, Revision 5.0, Version 1.0,
  24. * Section 7.2.2, Table 7-1, p. 677.
  25. */
  26. #define PCIE_ECAM_BUS_SHIFT 20 /* Bus number */
  27. #define PCIE_ECAM_DEVFN_SHIFT 12 /* Device and Function number */
  28. #define PCIE_ECAM_BUS_MASK 0xff
  29. #define PCIE_ECAM_DEVFN_MASK 0xff
  30. #define PCIE_ECAM_REG_MASK 0xfff /* Limit offset to a maximum of 4K */
  31. #define PCIE_ECAM_BUS(x) (((x) & PCIE_ECAM_BUS_MASK) << PCIE_ECAM_BUS_SHIFT)
  32. #define PCIE_ECAM_DEVFN(x) (((x) & PCIE_ECAM_DEVFN_MASK) << PCIE_ECAM_DEVFN_SHIFT)
  33. #define PCIE_ECAM_REG(x) ((x) & PCIE_ECAM_REG_MASK)
  34. #define PCIE_ECAM_OFFSET(bus, devfn, where) \
  35. (PCIE_ECAM_BUS(bus) | PCIE_ECAM_DEVFN(devfn) | PCIE_ECAM_REG(where))
  36. struct pci_ecam_ops
  37. {
  38. rt_uint32_t bus_shift;
  39. const struct rt_pci_ops pci_ops;
  40. };
  41. struct pci_ecam_config_window
  42. {
  43. rt_uint32_t *bus_range;
  44. rt_uint32_t bus_shift;
  45. void *win;
  46. void *priv;
  47. const struct pci_ecam_ops *ops;
  48. };
  49. /* Default ECAM ops */
  50. extern const struct pci_ecam_ops pci_generic_ecam_ops;
  51. void *pci_ecam_map(struct rt_pci_bus *bus, rt_uint32_t devfn, int where);
  52. struct pci_ecam_config_window *pci_ecam_create(struct rt_pci_host_bridge *host_bridge,
  53. const struct pci_ecam_ops *ops);
  54. rt_err_t pci_host_common_probe(struct rt_platform_device *pdev);
  55. rt_err_t pci_host_common_remove(struct rt_platform_device *pdev);
  56. #endif /* __RT_PCI_ECAM_H__ */