blob: 763022ed34564c41fe7652a7e707b0c082fda5bb [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;
Rob Herringbc5e5222020-02-06 14:01:05 +000013 int na;
14 int ns;
Andrew Murray29b635c2013-05-16 17:55:17 +020015 int pna;
Rob Herring645c1382019-09-05 10:47:26 +010016 bool dma;
Andrew Murray29b635c2013-05-16 17:55:17 +020017};
Rob Herringbc5e5222020-02-06 14:01:05 +000018#define of_range_parser of_pci_range_parser
Andrew Murray29b635c2013-05-16 17:55:17 +020019
20struct of_pci_range {
Rob Herringbc5e5222020-02-06 14:01:05 +000021 union {
22 u64 pci_addr;
23 u64 bus_addr;
24 };
Andrew Murray29b635c2013-05-16 17:55:17 +020025 u64 cpu_addr;
26 u64 size;
27 u32 flags;
28};
Rob Herringbc5e5222020-02-06 14:01:05 +000029#define of_range of_pci_range
Andrew Murray29b635c2013-05-16 17:55:17 +020030
31#define for_each_of_pci_range(parser, range) \
32 for (; of_pci_range_parser_one(parser, range);)
Rob Herringbc5e5222020-02-06 14:01:05 +000033#define for_each_of_range for_each_of_pci_range
Andrew Murray29b635c2013-05-16 17:55:17 +020034
Rob Herringd0dfa162013-09-16 21:05:05 -050035/* Translate a DMA address from device space to CPU space */
36extern u64 of_translate_dma_address(struct device_node *dev,
37 const __be32 *in_addr);
38
Grant Likelya850a752012-02-14 14:06:55 -070039#ifdef CONFIG_OF_ADDRESS
Sebastian Andrzej Siewior0131d892010-12-01 10:54:46 +010040extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
Grant Likely1f5bef32010-06-08 07:48:09 -060041extern int of_address_to_resource(struct device_node *dev, int index,
42 struct resource *r);
Grant Likely6b884a82010-06-08 07:48:09 -060043extern void __iomem *of_iomap(struct device_node *device, int index);
Sudip Mukherjeefcd71d92015-12-08 14:17:55 +053044void __iomem *of_io_request_and_map(struct device_node *device,
45 int index, const char *name);
Grant Likely6b884a82010-06-08 07:48:09 -060046
Grant Likely22ae7822010-07-29 11:49:01 -060047/* Extract an address from a device, returns the region size and
48 * the address space flags too. The PCI version uses a BAR number
49 * instead of an absolute index
50 */
Kim Phillips47b1e682012-10-08 19:41:58 -050051extern const __be32 *of_get_address(struct device_node *dev, int index,
Grant Likely22ae7822010-07-29 11:49:01 -060052 u64 *size, unsigned int *flags);
53
Andrew Murray29b635c2013-05-16 17:55:17 +020054extern int of_pci_range_parser_init(struct of_pci_range_parser *parser,
55 struct device_node *node);
Marc Gonzaleza060c212017-09-26 12:22:54 +020056extern int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser,
57 struct device_node *node);
Andrew Murray29b635c2013-05-16 17:55:17 +020058extern struct of_pci_range *of_pci_range_parser_one(
59 struct of_pci_range_parser *parser,
60 struct of_pci_range *range);
Santosh Shilimkar92ea6372014-04-24 11:30:03 -040061extern bool of_dma_is_coherent(struct device_node *np);
Grant Likelya850a752012-02-14 14:06:55 -070062#else /* CONFIG_OF_ADDRESS */
Sudip Mukherjeefcd71d92015-12-08 14:17:55 +053063static inline void __iomem *of_io_request_and_map(struct device_node *device,
64 int index, const char *name)
65{
66 return IOMEM_ERR_PTR(-EINVAL);
67}
Guenter Roeckb1d06b62015-11-06 19:28:22 -080068
69static inline u64 of_translate_address(struct device_node *np,
70 const __be32 *addr)
71{
72 return OF_BAD_ADDR;
73}
74
Kim Phillips47b1e682012-10-08 19:41:58 -050075static inline const __be32 *of_get_address(struct device_node *dev, int index,
Grant Likelya850a752012-02-14 14:06:55 -070076 u64 *size, unsigned int *flags)
77{
78 return NULL;
79}
Andrew Murray29b635c2013-05-16 17:55:17 +020080
81static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser,
82 struct device_node *node)
83{
Marc Gonzaleza060c212017-09-26 12:22:54 +020084 return -ENOSYS;
85}
86
87static inline int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser,
88 struct device_node *node)
89{
90 return -ENOSYS;
Andrew Murray29b635c2013-05-16 17:55:17 +020091}
92
93static inline struct of_pci_range *of_pci_range_parser_one(
94 struct of_pci_range_parser *parser,
95 struct of_pci_range *range)
96{
97 return NULL;
98}
Grygorii Strashko18308c92014-04-24 11:30:02 -040099
Santosh Shilimkar92ea6372014-04-24 11:30:03 -0400100static inline bool of_dma_is_coherent(struct device_node *np)
101{
102 return false;
103}
Grant Likelya850a752012-02-14 14:06:55 -0700104#endif /* CONFIG_OF_ADDRESS */
105
Rob Herring4acf4b92013-09-16 21:03:24 -0500106#ifdef CONFIG_OF
107extern int of_address_to_resource(struct device_node *dev, int index,
108 struct resource *r);
109void __iomem *of_iomap(struct device_node *node, int index);
110#else
111static inline int of_address_to_resource(struct device_node *dev, int index,
112 struct resource *r)
113{
114 return -EINVAL;
115}
116
117static inline void __iomem *of_iomap(struct device_node *device, int index)
118{
119 return NULL;
120}
121#endif
Grant Likelya850a752012-02-14 14:06:55 -0700122
123#if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
Sebastian Andrzej Siewior0131d892010-12-01 10:54:46 +0100124extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
Grant Likely22ae7822010-07-29 11:49:01 -0600125 u64 *size, unsigned int *flags);
126extern int of_pci_address_to_resource(struct device_node *dev, int bar,
127 struct resource *r);
Liviu Dudau0b0b0892014-09-29 15:29:25 +0100128extern int of_pci_range_to_resource(struct of_pci_range *range,
129 struct device_node *np,
130 struct resource *res);
Grant Likelya850a752012-02-14 14:06:55 -0700131#else /* CONFIG_OF_ADDRESS && CONFIG_PCI */
Grant Likely22ae7822010-07-29 11:49:01 -0600132static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
133 struct resource *r)
134{
135 return -ENOSYS;
136}
137
Sebastian Andrzej Siewior0131d892010-12-01 10:54:46 +0100138static inline const __be32 *of_get_pci_address(struct device_node *dev,
Grant Likely22ae7822010-07-29 11:49:01 -0600139 int bar_no, u64 *size, unsigned int *flags)
140{
141 return NULL;
142}
Liviu Dudau0b0b0892014-09-29 15:29:25 +0100143static inline int of_pci_range_to_resource(struct of_pci_range *range,
144 struct device_node *np,
145 struct resource *res)
Liviu Dudau83bbde12014-09-29 15:29:24 +0100146{
147 return -ENOSYS;
148}
Grant Likelya850a752012-02-14 14:06:55 -0700149#endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */
Grant Likely22ae7822010-07-29 11:49:01 -0600150
Grant Likely6b884a82010-06-08 07:48:09 -0600151#endif /* __OF_ADDRESS_H */