blob: 88bc943405cd9cadb6cfc4e1c070dff44c6c4b97 [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
Jiaxun Yang2f965932020-07-28 23:36:55 +08009struct of_bus;
10
Andrew Murray29b635c2013-05-16 17:55:17 +020011struct of_pci_range_parser {
12 struct device_node *node;
Jiaxun Yang2f965932020-07-28 23:36:55 +080013 struct of_bus *bus;
Andrew Murray29b635c2013-05-16 17:55:17 +020014 const __be32 *range;
15 const __be32 *end;
Rob Herringbc5e5222020-02-06 14:01:05 +000016 int na;
17 int ns;
Andrew Murray29b635c2013-05-16 17:55:17 +020018 int pna;
Rob Herring645c1382019-09-05 10:47:26 +010019 bool dma;
Andrew Murray29b635c2013-05-16 17:55:17 +020020};
Rob Herringbc5e5222020-02-06 14:01:05 +000021#define of_range_parser of_pci_range_parser
Andrew Murray29b635c2013-05-16 17:55:17 +020022
23struct of_pci_range {
Rob Herringbc5e5222020-02-06 14:01:05 +000024 union {
25 u64 pci_addr;
26 u64 bus_addr;
27 };
Andrew Murray29b635c2013-05-16 17:55:17 +020028 u64 cpu_addr;
29 u64 size;
30 u32 flags;
31};
Rob Herringbc5e5222020-02-06 14:01:05 +000032#define of_range of_pci_range
Andrew Murray29b635c2013-05-16 17:55:17 +020033
34#define for_each_of_pci_range(parser, range) \
35 for (; of_pci_range_parser_one(parser, range);)
Rob Herringbc5e5222020-02-06 14:01:05 +000036#define for_each_of_range for_each_of_pci_range
Andrew Murray29b635c2013-05-16 17:55:17 +020037
Rob Herringd0dfa162013-09-16 21:05:05 -050038/* Translate a DMA address from device space to CPU space */
39extern u64 of_translate_dma_address(struct device_node *dev,
40 const __be32 *in_addr);
41
Grant Likelya850a752012-02-14 14:06:55 -070042#ifdef CONFIG_OF_ADDRESS
Sebastian Andrzej Siewior0131d892010-12-01 10:54:46 +010043extern u64 of_translate_address(struct device_node *np, const __be32 *addr);
Grant Likely1f5bef32010-06-08 07:48:09 -060044extern int of_address_to_resource(struct device_node *dev, int index,
45 struct resource *r);
Grant Likely6b884a82010-06-08 07:48:09 -060046extern void __iomem *of_iomap(struct device_node *device, int index);
Sudip Mukherjeefcd71d92015-12-08 14:17:55 +053047void __iomem *of_io_request_and_map(struct device_node *device,
48 int index, const char *name);
Grant Likely6b884a82010-06-08 07:48:09 -060049
Grant Likely22ae7822010-07-29 11:49:01 -060050/* Extract an address from a device, returns the region size and
51 * the address space flags too. The PCI version uses a BAR number
52 * instead of an absolute index
53 */
Kim Phillips47b1e682012-10-08 19:41:58 -050054extern const __be32 *of_get_address(struct device_node *dev, int index,
Grant Likely22ae7822010-07-29 11:49:01 -060055 u64 *size, unsigned int *flags);
56
Andrew Murray29b635c2013-05-16 17:55:17 +020057extern int of_pci_range_parser_init(struct of_pci_range_parser *parser,
58 struct device_node *node);
Marc Gonzaleza060c212017-09-26 12:22:54 +020059extern int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser,
60 struct device_node *node);
Andrew Murray29b635c2013-05-16 17:55:17 +020061extern struct of_pci_range *of_pci_range_parser_one(
62 struct of_pci_range_parser *parser,
63 struct of_pci_range *range);
Santosh Shilimkar92ea6372014-04-24 11:30:03 -040064extern bool of_dma_is_coherent(struct device_node *np);
Grant Likelya850a752012-02-14 14:06:55 -070065#else /* CONFIG_OF_ADDRESS */
Sudip Mukherjeefcd71d92015-12-08 14:17:55 +053066static inline void __iomem *of_io_request_and_map(struct device_node *device,
67 int index, const char *name)
68{
69 return IOMEM_ERR_PTR(-EINVAL);
70}
Guenter Roeckb1d06b62015-11-06 19:28:22 -080071
72static inline u64 of_translate_address(struct device_node *np,
73 const __be32 *addr)
74{
75 return OF_BAD_ADDR;
76}
77
Kim Phillips47b1e682012-10-08 19:41:58 -050078static inline const __be32 *of_get_address(struct device_node *dev, int index,
Grant Likelya850a752012-02-14 14:06:55 -070079 u64 *size, unsigned int *flags)
80{
81 return NULL;
82}
Andrew Murray29b635c2013-05-16 17:55:17 +020083
84static inline int of_pci_range_parser_init(struct of_pci_range_parser *parser,
85 struct device_node *node)
86{
Marc Gonzaleza060c212017-09-26 12:22:54 +020087 return -ENOSYS;
88}
89
90static inline int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser,
91 struct device_node *node)
92{
93 return -ENOSYS;
Andrew Murray29b635c2013-05-16 17:55:17 +020094}
95
96static inline struct of_pci_range *of_pci_range_parser_one(
97 struct of_pci_range_parser *parser,
98 struct of_pci_range *range)
99{
100 return NULL;
101}
Grygorii Strashko18308c92014-04-24 11:30:02 -0400102
Santosh Shilimkar92ea6372014-04-24 11:30:03 -0400103static inline bool of_dma_is_coherent(struct device_node *np)
104{
105 return false;
106}
Grant Likelya850a752012-02-14 14:06:55 -0700107#endif /* CONFIG_OF_ADDRESS */
108
Rob Herring4acf4b92013-09-16 21:03:24 -0500109#ifdef CONFIG_OF
110extern int of_address_to_resource(struct device_node *dev, int index,
111 struct resource *r);
112void __iomem *of_iomap(struct device_node *node, int index);
113#else
114static 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}
124#endif
Jiaxun Yang2f965932020-07-28 23:36:55 +0800125#define of_range_parser_init of_pci_range_parser_init
Grant Likelya850a752012-02-14 14:06:55 -0700126
127#if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)
Sebastian Andrzej Siewior0131d892010-12-01 10:54:46 +0100128extern const __be32 *of_get_pci_address(struct device_node *dev, int bar_no,
Grant Likely22ae7822010-07-29 11:49:01 -0600129 u64 *size, unsigned int *flags);
130extern int of_pci_address_to_resource(struct device_node *dev, int bar,
131 struct resource *r);
Liviu Dudau0b0b0892014-09-29 15:29:25 +0100132extern int of_pci_range_to_resource(struct of_pci_range *range,
133 struct device_node *np,
134 struct resource *res);
Grant Likelya850a752012-02-14 14:06:55 -0700135#else /* CONFIG_OF_ADDRESS && CONFIG_PCI */
Grant Likely22ae7822010-07-29 11:49:01 -0600136static inline int of_pci_address_to_resource(struct device_node *dev, int bar,
137 struct resource *r)
138{
139 return -ENOSYS;
140}
141
Sebastian Andrzej Siewior0131d892010-12-01 10:54:46 +0100142static inline const __be32 *of_get_pci_address(struct device_node *dev,
Grant Likely22ae7822010-07-29 11:49:01 -0600143 int bar_no, u64 *size, unsigned int *flags)
144{
145 return NULL;
146}
Liviu Dudau0b0b0892014-09-29 15:29:25 +0100147static inline int of_pci_range_to_resource(struct of_pci_range *range,
148 struct device_node *np,
149 struct resource *res)
Liviu Dudau83bbde12014-09-29 15:29:24 +0100150{
151 return -ENOSYS;
152}
Grant Likelya850a752012-02-14 14:06:55 -0700153#endif /* CONFIG_OF_ADDRESS && CONFIG_PCI */
Grant Likely22ae7822010-07-29 11:49:01 -0600154
Grant Likely6b884a82010-06-08 07:48:09 -0600155#endif /* __OF_ADDRESS_H */