of_address.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #ifndef __OF_ADDRESS_H
  2. #define __OF_ADDRESS_H
  3. #include <linux/ioport.h>
  4. #include <linux/errno.h>
  5. #include <linux/of.h>
  6. struct of_pci_range_parser {
  7. struct device_node *node;
  8. const __be32 *range;
  9. const __be32 *end;
  10. int np;
  11. int pna;
  12. };
  13. struct of_pci_range {
  14. u32 pci_space;
  15. u64 pci_addr;
  16. u64 cpu_addr;
  17. u64 size;
  18. u32 flags;
  19. };
  20. #define for_each_of_pci_range(parser, range) \
  21. for (; of_pci_range_parser_one(parser, range);)
  22. static inline void of_pci_range_to_resource(struct of_pci_range *range,
  23. struct device_node *np,
  24. struct resource *res)
  25. {
  26. res->flags = range->flags;
  27. res->start = range->cpu_addr;
  28. res->end = range->cpu_addr + range->size - 1;
  29. res->parent = res->child = res->sibling = NULL;
  30. res->name = np->full_name;
  31. }
  32. #ifdef CONFIG_OF_ADDRESS
  33. extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
  34. extern bool of_can_translate_address(struct device_node *dev);
  35. extern int of_address_to_resource(struct device_node *dev, int index,
  36. struct resource *r);
  37. extern struct device_node *of_find_matching_node_by_address(
  38. struct device_node *from,
  39. const struct of_device_id *matches,
  40. u64 base_address);
  41. extern void __iomem *of_iomap(struct device_node *device, int index);
  42. /* Extract an address from a device, returns the region size and
  43. * the address space flags too. The PCI version uses a BAR number
  44. * instead of an absolute index
  45. */
  46. extern const __be32 *of_get_address(struct device_node *dev, int index,
  47. u64 *size, unsigned int *flags);
  48. #ifndef pci_address_to_pio
  49. static inline unsigned long pci_address_to_pio(phys_addr_t addr) { return -1; }
  50. #define pci_address_to_pio pci_address_to_pio
  51. #endif
  52. extern int of_pci_range_parser_init(struct of_pci_range_parser *parser,
  53. struct device_node *node);
  54. extern struct of_pci_range *of_pci_range_parser_one(
  55. struct of_pci_range_parser *parser,
  56. struct of_pci_range *range);
  57. #else /* CONFIG_OF_ADDRESS */
  58. #ifndef of_address_to_resource
  59. static inline int of_address_to_resource(struct device_node *dev, int index,
  60. struct resource *r)
  61. {
  62. return -EINVAL;
  63. }
  64. #endif
  65. static inline struct device_node *of_find_matching_node_by_address(
  66. struct device_node *from,
  67. const struct of_device_id *matches,
  68. u64 base_address)
  69. {
  70. return NULL;
  71. }
  72. #ifndef of_iomap
  73. static inline void __iomem *of_iomap(struct device_node *device, int index)
  74. {
  75. return NULL;
  76. }
  77. #endif
  78. static inline const __be32 *of_get_address(struct device_node *dev, int index,
  79. u64 *size, unsigned int *flags)
  80. {
  81. return NULL;
  82. }
  83. static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser,
  84. struct device_node *node)
  85. {
  86. return -1;
  87. }
  88. static inline struct of_pci_range *of_pci_range_parser_one(
  89. struct of_pci_range_parser *parser,
  90. struct of_pci_range *range)
  91. {
  92. return NULL;
  93. }
  94. #endif /* CONFIG_OF_ADDRESS */
  95. #if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
  96. extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
  97. u64 *size, unsigned int *flags);
  98. extern int of_pci_address_to_resource(struct device_node *dev, int bar,
  99. struct resource *r);
  100. #else /* CONFIG_OF_ADDRESS && CONFIG_PCI */
  101. static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
  102. struct resource *r)
  103. {
  104. return -ENOSYS;
  105. }
  106. static inline const __be32 *of_get_pci_address(struct device_node *dev,
  107. int bar_no, u64 *size, unsigned int *flags)
  108. {
  109. return NULL;
  110. }
  111. #endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */
  112. #endif /* __OF_ADDRESS_H */