1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __OF_RESERVED_MEM_H
3 #define __OF_RESERVED_MEM_H
5 #include <linux/device.h>
7 struct of_phandle_args
;
8 struct reserved_mem_ops
;
12 unsigned long fdt_node
;
13 unsigned long phandle
;
14 const struct reserved_mem_ops
*ops
;
20 struct reserved_mem_ops
{
21 int (*device_init
)(struct reserved_mem
*rmem
,
23 void (*device_release
)(struct reserved_mem
*rmem
,
27 typedef int (*reservedmem_of_init_fn
)(struct reserved_mem
*rmem
);
29 #define RESERVEDMEM_OF_DECLARE(name, compat, init) \
30 _OF_DECLARE(reservedmem, name, compat, init, reservedmem_of_init_fn)
32 #ifdef CONFIG_OF_RESERVED_MEM
34 int of_reserved_mem_device_init_by_idx(struct device
*dev
,
35 struct device_node
*np
, int idx
);
36 void of_reserved_mem_device_release(struct device
*dev
);
38 int early_init_dt_alloc_reserved_memory_arch(phys_addr_t size
,
43 phys_addr_t
*res_base
);
45 void fdt_init_reserved_mem(void);
46 void fdt_reserved_mem_save_node(unsigned long node
, const char *uname
,
47 phys_addr_t base
, phys_addr_t size
);
48 struct reserved_mem
*of_reserved_mem_lookup(struct device_node
*np
);
50 static inline int of_reserved_mem_device_init_by_idx(struct device
*dev
,
51 struct device_node
*np
, int idx
)
55 static inline void of_reserved_mem_device_release(struct device
*pdev
) { }
57 static inline void fdt_init_reserved_mem(void) { }
58 static inline void fdt_reserved_mem_save_node(unsigned long node
,
59 const char *uname
, phys_addr_t base
, phys_addr_t size
) { }
60 static inline struct reserved_mem
*of_reserved_mem_lookup(struct device_node
*np
)
67 * of_reserved_mem_device_init() - assign reserved memory region to given device
68 * @dev: Pointer to the device to configure
70 * This function assigns respective DMA-mapping operations based on the first
71 * reserved memory region specified by 'memory-region' property in device tree
72 * node of the given device.
74 * Returns error code or zero on success.
76 static inline int of_reserved_mem_device_init(struct device
*dev
)
78 return of_reserved_mem_device_init_by_idx(dev
, dev
->of_node
, 0);
81 #endif /* __OF_RESERVED_MEM_H */