blob: 67ab8d271df30beda5438fb4fb9a9c9542ff50d5 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Marek Szyprowski3f0c8202014-02-28 14:42:48 +01002#ifndef __OF_RESERVED_MEM_H
3#define __OF_RESERVED_MEM_H
4
Marek Szyprowski59ce4032016-05-24 15:31:24 +02005#include <linux/device.h>
6
Marek Szyprowskif618c472014-02-28 14:42:49 +01007struct of_phandle_args;
8struct reserved_mem_ops;
9
Marek Szyprowski3f0c8202014-02-28 14:42:48 +010010struct reserved_mem {
11 const char *name;
12 unsigned long fdt_node;
Marek Szyprowski9dcfee02014-07-14 10:28:04 +020013 unsigned long phandle;
Marek Szyprowskif618c472014-02-28 14:42:49 +010014 const struct reserved_mem_ops *ops;
Marek Szyprowski3f0c8202014-02-28 14:42:48 +010015 phys_addr_t base;
16 phys_addr_t size;
Marek Szyprowskif618c472014-02-28 14:42:49 +010017 void *priv;
Marek Szyprowski3f0c8202014-02-28 14:42:48 +010018};
19
Marek Szyprowskif618c472014-02-28 14:42:49 +010020struct reserved_mem_ops {
Marek Szyprowski47f29df2014-10-29 14:50:29 -070021 int (*device_init)(struct reserved_mem *rmem,
Marek Szyprowskif618c472014-02-28 14:42:49 +010022 struct device *dev);
23 void (*device_release)(struct reserved_mem *rmem,
24 struct device *dev);
25};
26
Rob Herring9dd31072014-05-08 16:06:17 -050027typedef int (*reservedmem_of_init_fn)(struct reserved_mem *rmem);
28
Rob Herring54196cc2014-05-08 16:09:24 -050029#define RESERVEDMEM_OF_DECLARE(name, compat, init) \
30 _OF_DECLARE(reservedmem, name, compat, init, reservedmem_of_init_fn)
Marek Szyprowskif618c472014-02-28 14:42:49 +010031
Marek Szyprowski3f0c8202014-02-28 14:42:48 +010032#ifdef CONFIG_OF_RESERVED_MEM
Marek Szyprowski59ce4032016-05-24 15:31:24 +020033
34int of_reserved_mem_device_init_by_idx(struct device *dev,
35 struct device_node *np, int idx);
Marek Szyprowski9dcfee02014-07-14 10:28:04 +020036void of_reserved_mem_device_release(struct device *dev);
37
Ben Dooks06dfeef2016-06-09 11:38:34 +010038int early_init_dt_alloc_reserved_memory_arch(phys_addr_t size,
39 phys_addr_t align,
40 phys_addr_t start,
41 phys_addr_t end,
42 bool nomap,
43 phys_addr_t *res_base);
44
Marek Szyprowski3f0c8202014-02-28 14:42:48 +010045void fdt_init_reserved_mem(void);
46void fdt_reserved_mem_save_node(unsigned long node, const char *uname,
47 phys_addr_t base, phys_addr_t size);
Bjorn Anderssoneb297bc2017-10-10 22:08:54 -070048struct reserved_mem *of_reserved_mem_lookup(struct device_node *np);
Marek Szyprowski3f0c8202014-02-28 14:42:48 +010049#else
Marek Szyprowski59ce4032016-05-24 15:31:24 +020050static inline int of_reserved_mem_device_init_by_idx(struct device *dev,
51 struct device_node *np, int idx)
Marek Szyprowski47f29df2014-10-29 14:50:29 -070052{
53 return -ENOSYS;
54}
Marek Szyprowski9dcfee02014-07-14 10:28:04 +020055static inline void of_reserved_mem_device_release(struct device *pdev) { }
56
Marek Szyprowski3f0c8202014-02-28 14:42:48 +010057static inline void fdt_init_reserved_mem(void) { }
58static inline void fdt_reserved_mem_save_node(unsigned long node,
59 const char *uname, phys_addr_t base, phys_addr_t size) { }
Bjorn Anderssoneb297bc2017-10-10 22:08:54 -070060static inline struct reserved_mem *of_reserved_mem_lookup(struct device_node *np)
61{
62 return NULL;
63}
Marek Szyprowski3f0c8202014-02-28 14:42:48 +010064#endif
65
Marek Szyprowski59ce4032016-05-24 15:31:24 +020066/**
67 * of_reserved_mem_device_init() - assign reserved memory region to given device
68 * @dev: Pointer to the device to configure
69 *
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.
73 *
74 * Returns error code or zero on success.
75 */
76static inline int of_reserved_mem_device_init(struct device *dev)
77{
78 return of_reserved_mem_device_init_by_idx(dev, dev->of_node, 0);
79}
80
Marek Szyprowski3f0c8202014-02-28 14:42:48 +010081#endif /* __OF_RESERVED_MEM_H */