Merge branch 'rework/printk_safe-removal' into for-linus
[linux-2.6-microblaze.git] / include / linux / of_reserved_mem.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __OF_RESERVED_MEM_H
3 #define __OF_RESERVED_MEM_H
4
5 #include <linux/device.h>
6 #include <linux/of.h>
7
8 struct of_phandle_args;
9 struct reserved_mem_ops;
10
11 struct reserved_mem {
12         const char                      *name;
13         unsigned long                   fdt_node;
14         unsigned long                   phandle;
15         const struct reserved_mem_ops   *ops;
16         phys_addr_t                     base;
17         phys_addr_t                     size;
18         void                            *priv;
19 };
20
21 struct reserved_mem_ops {
22         int     (*device_init)(struct reserved_mem *rmem,
23                                struct device *dev);
24         void    (*device_release)(struct reserved_mem *rmem,
25                                   struct device *dev);
26 };
27
28 typedef int (*reservedmem_of_init_fn)(struct reserved_mem *rmem);
29
30 #ifdef CONFIG_OF_RESERVED_MEM
31
32 #define RESERVEDMEM_OF_DECLARE(name, compat, init)                      \
33         _OF_DECLARE(reservedmem, name, compat, init, reservedmem_of_init_fn)
34
35 int of_reserved_mem_device_init_by_idx(struct device *dev,
36                                        struct device_node *np, int idx);
37 int of_reserved_mem_device_init_by_name(struct device *dev,
38                                         struct device_node *np,
39                                         const char *name);
40 void of_reserved_mem_device_release(struct device *dev);
41
42 struct reserved_mem *of_reserved_mem_lookup(struct device_node *np);
43 #else
44
45 #define RESERVEDMEM_OF_DECLARE(name, compat, init)                      \
46         _OF_DECLARE_STUB(reservedmem, name, compat, init, reservedmem_of_init_fn)
47
48 static inline int of_reserved_mem_device_init_by_idx(struct device *dev,
49                                         struct device_node *np, int idx)
50 {
51         return -ENOSYS;
52 }
53
54 static inline int of_reserved_mem_device_init_by_name(struct device *dev,
55                                                       struct device_node *np,
56                                                       const char *name)
57 {
58         return -ENOSYS;
59 }
60
61 static inline void of_reserved_mem_device_release(struct device *pdev) { }
62
63 static inline struct reserved_mem *of_reserved_mem_lookup(struct device_node *np)
64 {
65         return NULL;
66 }
67 #endif
68
69 /**
70  * of_reserved_mem_device_init() - assign reserved memory region to given device
71  * @dev:        Pointer to the device to configure
72  *
73  * This function assigns respective DMA-mapping operations based on the first
74  * reserved memory region specified by 'memory-region' property in device tree
75  * node of the given device.
76  *
77  * Returns error code or zero on success.
78  */
79 static inline int of_reserved_mem_device_init(struct device *dev)
80 {
81         return of_reserved_mem_device_init_by_idx(dev, dev->of_node, 0);
82 }
83
84 #endif /* __OF_RESERVED_MEM_H */