blob: 30e40fb6936b5983252a6d662234b49b239a70ac [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Grant Likely6b884a82010-06-08 07:48:09 -06002#ifndef __OF_ADDRESS_H
3#define __OF_ADDRESS_H
4#include <linux/ioport.h>
Grant Likely99ce39e2011-07-05 23:42:37 -06005#include <linux/errno.h>
Grant Likely6b884a82010-06-08 07:48:09 -06006#include <linux/of.h>
Sudip Mukherjeefcd71d92015-12-08 14:17:55 +05307#include <linux/io.h>
Grant Likely6b884a82010-06-08 07:48:09 -06008
Andrew Murray29b635c2013-05-16 17:55:17 +02009struct of_pci_range_parser {
10 struct device_node *node;
11 const __be32 *range;
12 const __be32 *end;
13 int np;
14 int pna;
15};
16
17struct of_pci_range {
18 u32 pci_space;
19 u64 pci_addr;
20 u64 cpu_addr;
21 u64 size;
22 u32 flags;
23};
24
25#define for_each_of_pci_range(parser, range) \
26 for (; of_pci_range_parser_one(parser, range);)
27
Rob Herringd0dfa162013-09-16 21:05:05 -050028/* Translate a DMA address from device space to CPU space */
29extern u64 of_translate_dma_address(struct device_node *dev,
30 const __be32 *in_addr);
31
Grant Likelya850a752012-02-14 14:06:55 -070032#ifdef CONFIG_OF_ADDRESS
Sebastian Andrzej Siewior0131d892010-12-01 10:54:46 +010033extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
Grant Likely1f5bef32010-06-08 07:48:09 -060034extern int of_address_to_resource(struct device_node *dev, int index,
35 struct resource *r);
Grant Likely90e33f62011-07-05 23:42:28 -060036extern struct device_node *of_find_matching_node_by_address(
37 struct device_node *from,
38 const struct of_device_id *matches,
39 u64 base_address);
Grant Likely6b884a82010-06-08 07:48:09 -060040extern void __iomem *of_iomap(struct device_node *device, int index);
Sudip Mukherjeefcd71d92015-12-08 14:17:55 +053041void __iomem *of_io_request_and_map(struct device_node *device,
42 int index, const char *name);
Grant Likely6b884a82010-06-08 07:48:09 -060043
Grant Likely22ae7822010-07-29 11:49:01 -060044/* Extract an address from a device, returns the region size and
45 * the address space flags too. The PCI version uses a BAR number
46 * instead of an absolute index
47 */
Kim Phillips47b1e682012-10-08 19:41:58 -050048extern const __be32 *of_get_address(struct device_node *dev, int index,
Grant Likely22ae7822010-07-29 11:49:01 -060049 u64 *size, unsigned int *flags);
50
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);
Marc Gonzaleza060c212017-09-26 12:22:54 +020053extern int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser,
54 struct device_node *node);
Andrew Murray29b635c2013-05-16 17:55:17 +020055extern struct of_pci_range *of_pci_range_parser_one(
56 struct of_pci_range_parser *parser,
57 struct of_pci_range *range);
Grygorii Strashko18308c92014-04-24 11:30:02 -040058extern int of_dma_get_range(struct device_node *np, u64 *dma_addr,
59 u64 *paddr, u64 *size);
Santosh Shilimkar92ea6372014-04-24 11:30:03 -040060extern bool of_dma_is_coherent(struct device_node *np);
Grant Likelya850a752012-02-14 14:06:55 -070061#else /* CONFIG_OF_ADDRESS */
Sudip Mukherjeefcd71d92015-12-08 14:17:55 +053062static inline void __iomem *of_io_request_and_map(struct device_node *device,
63 int index, const char *name)
64{
65 return IOMEM_ERR_PTR(-EINVAL);
66}
Guenter Roeckb1d06b62015-11-06 19:28:22 -080067
68static inline u64 of_translate_address(struct device_node *np,
69 const __be32 *addr)
70{
71 return OF_BAD_ADDR;
72}
73
Grant Likelya850a752012-02-14 14:06:55 -070074static inline struct device_node *of_find_matching_node_by_address(
75 struct device_node *from,
76 const struct of_device_id *matches,
77 u64 base_address)
78{
79 return NULL;
80}
Rob Herring4acf4b92013-09-16 21:03:24 -050081
Kim Phillips47b1e682012-10-08 19:41:58 -050082static inline const __be32 *of_get_address(struct device_node *dev, int index,
Grant Likelya850a752012-02-14 14:06:55 -070083 u64 *size, unsigned int *flags)
84{
85 return NULL;
86}
Andrew Murray29b635c2013-05-16 17:55:17 +020087
88static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser,
89 struct device_node *node)
90{
Marc Gonzaleza060c212017-09-26 12:22:54 +020091 return -ENOSYS;
92}
93
94static inline int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser,
95 struct device_node *node)
96{
97 return -ENOSYS;
Andrew Murray29b635c2013-05-16 17:55:17 +020098}
99
100static inline struct of_pci_range *of_pci_range_parser_one(
101 struct of_pci_range_parser *parser,
102 struct of_pci_range *range)
103{
104 return NULL;
105}
Grygorii Strashko18308c92014-04-24 11:30:02 -0400106
107static inline int of_dma_get_range(struct device_node *np, u64 *dma_addr,
108 u64 *paddr, u64 *size)
109{
110 return -ENODEV;
111}
Santosh Shilimkar92ea6372014-04-24 11:30:03 -0400112
113static inline bool of_dma_is_coherent(struct device_node *np)
114{
115 return false;
116}
Grant Likelya850a752012-02-14 14:06:55 -0700117#endif /* CONFIG_OF_ADDRESS */
118
Rob Herring4acf4b92013-09-16 21:03:24 -0500119#ifdef CONFIG_OF
120extern int of_address_to_resource(struct device_node *dev, int index,
121 struct resource *r);
122void __iomem *of_iomap(struct device_node *node, int index);
123#else
124static inline int of_address_to_resource(struct device_node *dev, int index,
125 struct resource *r)
126{
127 return -EINVAL;
128}
129
130static inline void __iomem *of_iomap(struct device_node *device, int index)
131{
132 return NULL;
133}
134#endif
Grant Likelya850a752012-02-14 14:06:55 -0700135
136#if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
Sebastian Andrzej Siewior0131d892010-12-01 10:54:46 +0100137extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
Grant Likely22ae7822010-07-29 11:49:01 -0600138 u64 *size, unsigned int *flags);
139extern int of_pci_address_to_resource(struct device_node *dev, int bar,
140 struct resource *r);
Liviu Dudau0b0b0892014-09-29 15:29:25 +0100141extern int of_pci_range_to_resource(struct of_pci_range *range,
142 struct device_node *np,
143 struct resource *res);
Grant Likelya850a752012-02-14 14:06:55 -0700144#else /* CONFIG_OF_ADDRESS && CONFIG_PCI */
Grant Likely22ae7822010-07-29 11:49:01 -0600145static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
146 struct resource *r)
147{
148 return -ENOSYS;
149}
150
Sebastian Andrzej Siewior0131d892010-12-01 10:54:46 +0100151static inline const __be32 *of_get_pci_address(struct device_node *dev,
Grant Likely22ae7822010-07-29 11:49:01 -0600152 int bar_no, u64 *size, unsigned int *flags)
153{
154 return NULL;
155}
Liviu Dudau0b0b0892014-09-29 15:29:25 +0100156static inline int of_pci_range_to_resource(struct of_pci_range *range,
157 struct device_node *np,
158 struct resource *res)
Liviu Dudau83bbde12014-09-29 15:29:24 +0100159{
160 return -ENOSYS;
161}
Grant Likelya850a752012-02-14 14:06:55 -0700162#endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */
Grant Likely22ae7822010-07-29 11:49:01 -0600163
Grant Likely6b884a82010-06-08 07:48:09 -0600164#endif /* __OF_ADDRESS_H */
165