blob: eac7ab109df40892e55d2fdb5a003bbf294b7b87 [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;
Rob Herring645c1382019-09-05 10:47:26 +010015 bool dma;
Andrew Murray29b635c2013-05-16 17:55:17 +020016};
17
18struct of_pci_range {
19 u32 pci_space;
20 u64 pci_addr;
21 u64 cpu_addr;
22 u64 size;
23 u32 flags;
24};
25
26#define for_each_of_pci_range(parser, range) \
27 for (; of_pci_range_parser_one(parser, range);)
28
Rob Herringd0dfa162013-09-16 21:05:05 -050029/* Translate a DMA address from device space to CPU space */
30extern u64 of_translate_dma_address(struct device_node *dev,
31 const __be32 *in_addr);
32
Grant Likelya850a752012-02-14 14:06:55 -070033#ifdef CONFIG_OF_ADDRESS
Sebastian Andrzej Siewior0131d892010-12-01 10:54:46 +010034extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
Grant Likely1f5bef32010-06-08 07:48:09 -060035extern int of_address_to_resource(struct device_node *dev, int index,
36 struct resource *r);
Grant Likely6b884a82010-06-08 07:48:09 -060037extern void __iomem *of_iomap(struct device_node *device, int index);
Sudip Mukherjeefcd71d92015-12-08 14:17:55 +053038void __iomem *of_io_request_and_map(struct device_node *device,
39 int index, const char *name);
Grant Likely6b884a82010-06-08 07:48:09 -060040
Grant Likely22ae7822010-07-29 11:49:01 -060041/* Extract an address from a device, returns the region size and
42 * the address space flags too. The PCI version uses a BAR number
43 * instead of an absolute index
44 */
Kim Phillips47b1e682012-10-08 19:41:58 -050045extern const __be32 *of_get_address(struct device_node *dev, int index,
Grant Likely22ae7822010-07-29 11:49:01 -060046 u64 *size, unsigned int *flags);
47
Andrew Murray29b635c2013-05-16 17:55:17 +020048extern int of_pci_range_parser_init(struct of_pci_range_parser *parser,
49 struct device_node *node);
Marc Gonzaleza060c212017-09-26 12:22:54 +020050extern int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser,
51 struct device_node *node);
Andrew Murray29b635c2013-05-16 17:55:17 +020052extern struct of_pci_range *of_pci_range_parser_one(
53 struct of_pci_range_parser *parser,
54 struct of_pci_range *range);
Santosh Shilimkar92ea6372014-04-24 11:30:03 -040055extern bool of_dma_is_coherent(struct device_node *np);
Grant Likelya850a752012-02-14 14:06:55 -070056#else /* CONFIG_OF_ADDRESS */
Sudip Mukherjeefcd71d92015-12-08 14:17:55 +053057static inline void __iomem *of_io_request_and_map(struct device_node *device,
58 int index, const char *name)
59{
60 return IOMEM_ERR_PTR(-EINVAL);
61}
Guenter Roeckb1d06b62015-11-06 19:28:22 -080062
63static inline u64 of_translate_address(struct device_node *np,
64 const __be32 *addr)
65{
66 return OF_BAD_ADDR;
67}
68
Kim Phillips47b1e682012-10-08 19:41:58 -050069static inline const __be32 *of_get_address(struct device_node *dev, int index,
Grant Likelya850a752012-02-14 14:06:55 -070070 u64 *size, unsigned int *flags)
71{
72 return NULL;
73}
Andrew Murray29b635c2013-05-16 17:55:17 +020074
75static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser,
76 struct device_node *node)
77{
Marc Gonzaleza060c212017-09-26 12:22:54 +020078 return -ENOSYS;
79}
80
81static inline int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser,
82 struct device_node *node)
83{
84 return -ENOSYS;
Andrew Murray29b635c2013-05-16 17:55:17 +020085}
86
87static inline struct of_pci_range *of_pci_range_parser_one(
88 struct of_pci_range_parser *parser,
89 struct of_pci_range *range)
90{
91 return NULL;
92}
Grygorii Strashko18308c92014-04-24 11:30:02 -040093
Santosh Shilimkar92ea6372014-04-24 11:30:03 -040094static inline bool of_dma_is_coherent(struct device_node *np)
95{
96 return false;
97}
Grant Likelya850a752012-02-14 14:06:55 -070098#endif /* CONFIG_OF_ADDRESS */
99
Rob Herring4acf4b92013-09-16 21:03:24 -0500100#ifdef CONFIG_OF
101extern int of_address_to_resource(struct device_node *dev, int index,
102 struct resource *r);
103void __iomem *of_iomap(struct device_node *node, int index);
104#else
105static inline int of_address_to_resource(struct device_node *dev, int index,
106 struct resource *r)
107{
108 return -EINVAL;
109}
110
111static inline void __iomem *of_iomap(struct device_node *device, int index)
112{
113 return NULL;
114}
115#endif
Grant Likelya850a752012-02-14 14:06:55 -0700116
117#if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
Sebastian Andrzej Siewior0131d892010-12-01 10:54:46 +0100118extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
Grant Likely22ae7822010-07-29 11:49:01 -0600119 u64 *size, unsigned int *flags);
120extern int of_pci_address_to_resource(struct device_node *dev, int bar,
121 struct resource *r);
Liviu Dudau0b0b0892014-09-29 15:29:25 +0100122extern int of_pci_range_to_resource(struct of_pci_range *range,
123 struct device_node *np,
124 struct resource *res);
Grant Likelya850a752012-02-14 14:06:55 -0700125#else /* CONFIG_OF_ADDRESS && CONFIG_PCI */
Grant Likely22ae7822010-07-29 11:49:01 -0600126static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
127 struct resource *r)
128{
129 return -ENOSYS;
130}
131
Sebastian Andrzej Siewior0131d892010-12-01 10:54:46 +0100132static inline const __be32 *of_get_pci_address(struct device_node *dev,
Grant Likely22ae7822010-07-29 11:49:01 -0600133 int bar_no, u64 *size, unsigned int *flags)
134{
135 return NULL;
136}
Liviu Dudau0b0b0892014-09-29 15:29:25 +0100137static inline int of_pci_range_to_resource(struct of_pci_range *range,
138 struct device_node *np,
139 struct resource *res)
Liviu Dudau83bbde12014-09-29 15:29:24 +0100140{
141 return -ENOSYS;
142}
Grant Likelya850a752012-02-14 14:06:55 -0700143#endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */
Grant Likely22ae7822010-07-29 11:49:01 -0600144
Grant Likely6b884a82010-06-08 07:48:09 -0600145#endif /* __OF_ADDRESS_H */
146