blob: d88e81be6368d2e2a07e34a8c0d28bbf9366a878 [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
Andrew Murray29b635c2013-05-16 17:55:17 +02007struct of_pci_range_parser {
8 struct device_node *node;
9 const __be32 *range;
10 const __be32 *end;
11 int np;
12 int pna;
13};
14
15struct of_pci_range {
16 u32 pci_space;
17 u64 pci_addr;
18 u64 cpu_addr;
19 u64 size;
20 u32 flags;
21};
22
23#define for_each_of_pci_range(parser, range) \
24 for (; of_pci_range_parser_one(parser, range);)
25
Rob Herringd0dfa162013-09-16 21:05:05 -050026/* Translate a DMA address from device space to CPU space */
27extern u64 of_translate_dma_address(struct device_node *dev,
28 const __be32 *in_addr);
29
Grant Likelya850a752012-02-14 14:06:55 -070030#ifdef CONFIG_OF_ADDRESS
Sebastian Andrzej Siewior0131d892010-12-01 10:54:46 +010031extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
Grant Likely1f5bef32010-06-08 07:48:09 -060032extern int of_address_to_resource(struct device_node *dev, int index,
33 struct resource *r);
Grant Likely90e33f62011-07-05 23:42:28 -060034extern struct device_node *of_find_matching_node_by_address(
35 struct device_node *from,
36 const struct of_device_id *matches,
37 u64 base_address);
Grant Likely6b884a82010-06-08 07:48:09 -060038extern void __iomem *of_iomap(struct device_node *device, int index);
39
Grant Likely22ae7822010-07-29 11:49:01 -060040/* Extract an address from a device, returns the region size and
41 * the address space flags too. The PCI version uses a BAR number
42 * instead of an absolute index
43 */
Kim Phillips47b1e682012-10-08 19:41:58 -050044extern const __be32 *of_get_address(struct device_node *dev, int index,
Grant Likely22ae7822010-07-29 11:49:01 -060045 u64 *size, unsigned int *flags);
46
Liviu Dudau41f8bba2014-09-29 15:29:21 +010047extern int pci_register_io_range(phys_addr_t addr, resource_size_t size);
Rob Herring25ff7942013-09-07 14:07:11 -050048extern unsigned long pci_address_to_pio(phys_addr_t addr);
Liviu Dudau41f8bba2014-09-29 15:29:21 +010049extern phys_addr_t pci_pio_to_address(unsigned long pio);
Grant Likely22ae7822010-07-29 11:49:01 -060050
Andrew Murray29b635c2013-05-16 17:55:17 +020051extern int of_pci_range_parser_init(struct of_pci_range_parser *parser,
52 struct device_node *node);
53extern struct of_pci_range *of_pci_range_parser_one(
54 struct of_pci_range_parser *parser,
55 struct of_pci_range *range);
Grygorii Strashko18308c92014-04-24 11:30:02 -040056extern int of_dma_get_range(struct device_node *np, u64 *dma_addr,
57 u64 *paddr, u64 *size);
Santosh Shilimkar92ea6372014-04-24 11:30:03 -040058extern bool of_dma_is_coherent(struct device_node *np);
Grant Likelya850a752012-02-14 14:06:55 -070059#else /* CONFIG_OF_ADDRESS */
Grant Likelya850a752012-02-14 14:06:55 -070060static inline struct device_node *of_find_matching_node_by_address(
61 struct device_node *from,
62 const struct of_device_id *matches,
63 u64 base_address)
64{
65 return NULL;
66}
Rob Herring4acf4b92013-09-16 21:03:24 -050067
Kim Phillips47b1e682012-10-08 19:41:58 -050068static inline const __be32 *of_get_address(struct device_node *dev, int index,
Grant Likelya850a752012-02-14 14:06:55 -070069 u64 *size, unsigned int *flags)
70{
71 return NULL;
72}
Andrew Murray29b635c2013-05-16 17:55:17 +020073
Liviu Dudau41f8bba2014-09-29 15:29:21 +010074static inline phys_addr_t pci_pio_to_address(unsigned long pio)
75{
76 return 0;
77}
78
Andrew Murray29b635c2013-05-16 17:55:17 +020079static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser,
80 struct device_node *node)
81{
82 return -1;
83}
84
85static inline struct of_pci_range *of_pci_range_parser_one(
86 struct of_pci_range_parser *parser,
87 struct of_pci_range *range)
88{
89 return NULL;
90}
Grygorii Strashko18308c92014-04-24 11:30:02 -040091
92static inline int of_dma_get_range(struct device_node *np, u64 *dma_addr,
93 u64 *paddr, u64 *size)
94{
95 return -ENODEV;
96}
Santosh Shilimkar92ea6372014-04-24 11:30:03 -040097
98static inline bool of_dma_is_coherent(struct device_node *np)
99{
100 return false;
101}
Grant Likelya850a752012-02-14 14:06:55 -0700102#endif /* CONFIG_OF_ADDRESS */
103
Rob Herring4acf4b92013-09-16 21:03:24 -0500104#ifdef CONFIG_OF
105extern int of_address_to_resource(struct device_node *dev, int index,
106 struct resource *r);
107void __iomem *of_iomap(struct device_node *node, int index);
Matthias Bruggerefd342f2014-07-18 11:36:39 +0200108void __iomem *of_io_request_and_map(struct device_node *device,
Matthias Bruggerb75b2762014-10-21 18:27:25 +0200109 int index, const char *name);
Rob Herring4acf4b92013-09-16 21:03:24 -0500110#else
Matthias Bruggerefd342f2014-07-18 11:36:39 +0200111
112#include <linux/io.h>
113
Rob Herring4acf4b92013-09-16 21:03:24 -0500114static inline int of_address_to_resource(struct device_node *dev, int index,
115 struct resource *r)
116{
117 return -EINVAL;
118}
119
120static inline void __iomem *of_iomap(struct device_node *device, int index)
121{
122 return NULL;
123}
Matthias Bruggerefd342f2014-07-18 11:36:39 +0200124
125static inline void __iomem *of_io_request_and_map(struct device_node *device,
Matthias Bruggerb75b2762014-10-21 18:27:25 +0200126 int index, const char *name)
Matthias Bruggerefd342f2014-07-18 11:36:39 +0200127{
128 return IOMEM_ERR_PTR(-EINVAL);
129}
Rob Herring4acf4b92013-09-16 21:03:24 -0500130#endif
Grant Likelya850a752012-02-14 14:06:55 -0700131
132#if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
Sebastian Andrzej Siewior0131d892010-12-01 10:54:46 +0100133extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
Grant Likely22ae7822010-07-29 11:49:01 -0600134 u64 *size, unsigned int *flags);
135extern int of_pci_address_to_resource(struct device_node *dev, int bar,
136 struct resource *r);
Liviu Dudau0b0b0892014-09-29 15:29:25 +0100137extern int of_pci_range_to_resource(struct of_pci_range *range,
138 struct device_node *np,
139 struct resource *res);
Grant Likelya850a752012-02-14 14:06:55 -0700140#else /* CONFIG_OF_ADDRESS && CONFIG_PCI */
Grant Likely22ae7822010-07-29 11:49:01 -0600141static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
142 struct resource *r)
143{
144 return -ENOSYS;
145}
146
Sebastian Andrzej Siewior0131d892010-12-01 10:54:46 +0100147static inline const __be32 *of_get_pci_address(struct device_node *dev,
Grant Likely22ae7822010-07-29 11:49:01 -0600148 int bar_no, u64 *size, unsigned int *flags)
149{
150 return NULL;
151}
Liviu Dudau0b0b0892014-09-29 15:29:25 +0100152static inline int of_pci_range_to_resource(struct of_pci_range *range,
153 struct device_node *np,
154 struct resource *res)
Liviu Dudau83bbde12014-09-29 15:29:24 +0100155{
156 return -ENOSYS;
157}
Grant Likelya850a752012-02-14 14:06:55 -0700158#endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */
Grant Likely22ae7822010-07-29 11:49:01 -0600159
Grant Likely6b884a82010-06-08 07:48:09 -0600160#endif /* __OF_ADDRESS_H */
161