blob: 0506eb53519b635286be2b2c54b8a4c7e524a3d7 [file] [log] [blame]
Grant Likely6b884a82010-06-08 07:48:09 -06001#ifndef __OF_ADDRESS_H
2#define __OF_ADDRESS_H
3#include <linux/ioport.h>
Grant Likely99ce39e2011-07-05 23:42:37 -06004#include <linux/errno.h>
Grant Likely6b884a82010-06-08 07:48:09 -06005#include <linux/of.h>
6
Grant Likelya850a752012-02-14 14:06:55 -07007#ifdef CONFIG_OF_ADDRESS
Sebastian Andrzej Siewior0131d892010-12-01 10:54:46 +01008extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
Stephen Warren5d61b162012-07-25 17:34:37 -06009extern bool of_can_translate_address(struct device_node *dev);
Grant Likely1f5bef32010-06-08 07:48:09 -060010extern int of_address_to_resource(struct device_node *dev, int index,
11 struct resource *r);
Grant Likely90e33f62011-07-05 23:42:28 -060012extern struct device_node *of_find_matching_node_by_address(
13 struct device_node *from,
14 const struct of_device_id *matches,
15 u64 base_address);
Grant Likely6b884a82010-06-08 07:48:09 -060016extern void __iomem *of_iomap(struct device_node *device, int index);
17
Grant Likely22ae7822010-07-29 11:49:01 -060018/* Extract an address from a device, returns the region size and
19 * the address space flags too. The PCI version uses a BAR number
20 * instead of an absolute index
21 */
Kim Phillips47b1e682012-10-08 19:41:58 -050022extern const __be32 *of_get_address(struct device_node *dev, int index,
Grant Likely22ae7822010-07-29 11:49:01 -060023 u64 *size, unsigned int *flags);
24
25#ifndef pci_address_to_pio
26static inline unsigned long pci_address_to_pio(phys_addr_t addr) { return -1; }
27#define pci_address_to_pio pci_address_to_pio
28#endif
29
Grant Likelya850a752012-02-14 14:06:55 -070030#else /* CONFIG_OF_ADDRESS */
Andreas Larsson0bce04b2012-11-06 00:12:03 +000031#ifndef of_address_to_resource
Grant Likelya850a752012-02-14 14:06:55 -070032static inline int of_address_to_resource(struct device_node *dev, int index,
33 struct resource *r)
34{
35 return -EINVAL;
36}
Andreas Larsson0bce04b2012-11-06 00:12:03 +000037#endif
Grant Likelya850a752012-02-14 14:06:55 -070038static inline struct device_node *of_find_matching_node_by_address(
39 struct device_node *from,
40 const struct of_device_id *matches,
41 u64 base_address)
42{
43 return NULL;
44}
Andreas Larsson0e622d32012-11-23 12:24:09 +010045#ifndef of_iomap
Grant Likelya850a752012-02-14 14:06:55 -070046static inline void __iomem *of_iomap(struct device_node *device, int index)
47{
48 return NULL;
49}
Andreas Larsson0e622d32012-11-23 12:24:09 +010050#endif
Kim Phillips47b1e682012-10-08 19:41:58 -050051static inline const __be32 *of_get_address(struct device_node *dev, int index,
Grant Likelya850a752012-02-14 14:06:55 -070052 u64 *size, unsigned int *flags)
53{
54 return NULL;
55}
56#endif /* CONFIG_OF_ADDRESS */
57
58
59#if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
Sebastian Andrzej Siewior0131d892010-12-01 10:54:46 +010060extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
Grant Likely22ae7822010-07-29 11:49:01 -060061 u64 *size, unsigned int *flags);
62extern int of_pci_address_to_resource(struct device_node *dev, int bar,
63 struct resource *r);
Grant Likelya850a752012-02-14 14:06:55 -070064#else /* CONFIG_OF_ADDRESS && CONFIG_PCI */
Grant Likely22ae7822010-07-29 11:49:01 -060065static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
66 struct resource *r)
67{
68 return -ENOSYS;
69}
70
Sebastian Andrzej Siewior0131d892010-12-01 10:54:46 +010071static inline const __be32 *of_get_pci_address(struct device_node *dev,
Grant Likely22ae7822010-07-29 11:49:01 -060072 int bar_no, u64 *size, unsigned int *flags)
73{
74 return NULL;
75}
Grant Likelya850a752012-02-14 14:06:55 -070076#endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */
Grant Likely22ae7822010-07-29 11:49:01 -060077
Grant Likely6b884a82010-06-08 07:48:09 -060078#endif /* __OF_ADDRESS_H */
79