of_address.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. /* Translate a DMA address from device space to CPU space */
  23. extern u64 of_translate_dma_address(struct device_node *dev,
  24. const __be32 *in_addr);
  25. #ifdef CONFIG_OF_ADDRESS
  26. extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
  27. extern int of_address_to_resource(struct device_node *dev, int index,
  28. struct resource *r);
  29. extern struct device_node *of_find_matching_node_by_address(
  30. struct device_node *from,
  31. const struct of_device_id *matches,
  32. u64 base_address);
  33. extern void __iomem *of_iomap(struct device_node *device, int index);
  34. /* Extract an address from a device, returns the region size and
  35. * the address space flags too. The PCI version uses a BAR number
  36. * instead of an absolute index
  37. */
  38. extern const __be32 *of_get_address(struct device_node *dev, int index,
  39. u64 *size, unsigned int *flags);
  40. extern int pci_register_io_range(phys_addr_t addr, resource_size_t size);
  41. extern unsigned long pci_address_to_pio(phys_addr_t addr);
  42. extern phys_addr_t pci_pio_to_address(unsigned long pio);
  43. extern int of_pci_range_parser_init(struct of_pci_range_parser *parser,
  44. struct device_node *node);
  45. extern struct of_pci_range *of_pci_range_parser_one(
  46. struct of_pci_range_parser *parser,
  47. struct of_pci_range *range);
  48. extern int of_dma_get_range(struct device_node *np, u64 *dma_addr,
  49. u64 *paddr, u64 *size);
  50. extern bool of_dma_is_coherent(struct device_node *np);
  51. #else /* CONFIG_OF_ADDRESS */
  52. static inline u64 of_translate_address(struct device_node *np,
  53. const __be32 *addr)
  54. {
  55. return OF_BAD_ADDR;
  56. }
  57. static inline struct device_node *of_find_matching_node_by_address(
  58. struct device_node *from,
  59. const struct of_device_id *matches,
  60. u64 base_address)
  61. {
  62. return NULL;
  63. }
  64. static inline const __be32 *of_get_address(struct device_node *dev, int index,
  65. u64 *size, unsigned int *flags)
  66. {
  67. return NULL;
  68. }
  69. static inline phys_addr_t pci_pio_to_address(unsigned long pio)
  70. {
  71. return 0;
  72. }
  73. static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser,
  74. struct device_node *node)
  75. {
  76. return -1;
  77. }
  78. static inline struct of_pci_range *of_pci_range_parser_one(
  79. struct of_pci_range_parser *parser,
  80. struct of_pci_range *range)
  81. {
  82. return NULL;
  83. }
  84. static inline int of_dma_get_range(struct device_node *np, u64 *dma_addr,
  85. u64 *paddr, u64 *size)
  86. {
  87. return -ENODEV;
  88. }
  89. static inline bool of_dma_is_coherent(struct device_node *np)
  90. {
  91. return false;
  92. }
  93. #endif /* CONFIG_OF_ADDRESS */
  94. #ifdef CONFIG_OF
  95. extern int of_address_to_resource(struct device_node *dev, int index,
  96. struct resource *r);
  97. void __iomem *of_iomap(struct device_node *node, int index);
  98. void __iomem *of_io_request_and_map(struct device_node *device,
  99. int index, const char *name);
  100. #else
  101. #include <linux/io.h>
  102. static inline int of_address_to_resource(struct device_node *dev, int index,
  103. struct resource *r)
  104. {
  105. return -EINVAL;
  106. }
  107. static inline void __iomem *of_iomap(struct device_node *device, int index)
  108. {
  109. return NULL;
  110. }
  111. static inline void __iomem *of_io_request_and_map(struct device_node *device,
  112. int index, const char *name)
  113. {
  114. return IOMEM_ERR_PTR(-EINVAL);
  115. }
  116. #endif
  117. #if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
  118. extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
  119. u64 *size, unsigned int *flags);
  120. extern int of_pci_address_to_resource(struct device_node *dev, int bar,
  121. struct resource *r);
  122. extern int of_pci_range_to_resource(struct of_pci_range *range,
  123. struct device_node *np,
  124. struct resource *res);
  125. #else /* CONFIG_OF_ADDRESS && CONFIG_PCI */
  126. static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
  127. struct resource *r)
  128. {
  129. return -ENOSYS;
  130. }
  131. static inline const __be32 *of_get_pci_address(struct device_node *dev,
  132. int bar_no, u64 *size, unsigned int *flags)
  133. {
  134. return NULL;
  135. }
  136. static inline int of_pci_range_to_resource(struct of_pci_range *range,
  137. struct device_node *np,
  138. struct resource *res)
  139. {
  140. return -ENOSYS;
  141. }
  142. #endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */
  143. #endif /* __OF_ADDRESS_H */