blob: f8e1992d6423ca837e731ddb32c83c6ff9a6fe98 [file] [log] [blame]
Marek Szyprowski3f0c8202014-02-28 14:42:48 +01001#ifndef __OF_RESERVED_MEM_H
2#define __OF_RESERVED_MEM_H
3
Marek Szyprowski59ce4032016-05-24 15:31:24 +02004#include <linux/device.h>
5
Marek Szyprowskif618c472014-02-28 14:42:49 +01006struct of_phandle_args;
7struct reserved_mem_ops;
8
Marek Szyprowski3f0c8202014-02-28 14:42:48 +01009struct reserved_mem {
10 const char *name;
11 unsigned long fdt_node;
Marek Szyprowski9dcfee02014-07-14 10:28:04 +020012 unsigned long phandle;
Marek Szyprowskif618c472014-02-28 14:42:49 +010013 const struct reserved_mem_ops *ops;
Marek Szyprowski3f0c8202014-02-28 14:42:48 +010014 phys_addr_t base;
15 phys_addr_t size;
Marek Szyprowskif618c472014-02-28 14:42:49 +010016 void *priv;
Marek Szyprowski3f0c8202014-02-28 14:42:48 +010017};
18
Marek Szyprowskif618c472014-02-28 14:42:49 +010019struct reserved_mem_ops {
Marek Szyprowski47f29df2014-10-29 14:50:29 -070020 int (*device_init)(struct reserved_mem *rmem,
Marek Szyprowskif618c472014-02-28 14:42:49 +010021 struct device *dev);
22 void (*device_release)(struct reserved_mem *rmem,
23 struct device *dev);
24};
25
Rob Herring9dd31072014-05-08 16:06:17 -050026typedef int (*reservedmem_of_init_fn)(struct reserved_mem *rmem);
27
Rob Herring54196cc2014-05-08 16:09:24 -050028#define RESERVEDMEM_OF_DECLARE(name, compat, init) \
29 _OF_DECLARE(reservedmem, name, compat, init, reservedmem_of_init_fn)
Marek Szyprowskif618c472014-02-28 14:42:49 +010030
Marek Szyprowski3f0c8202014-02-28 14:42:48 +010031#ifdef CONFIG_OF_RESERVED_MEM
Marek Szyprowski59ce4032016-05-24 15:31:24 +020032
33int of_reserved_mem_device_init_by_idx(struct device *dev,
34 struct device_node *np, int idx);
Marek Szyprowski9dcfee02014-07-14 10:28:04 +020035void of_reserved_mem_device_release(struct device *dev);
36
Ben Dooks06dfeef2016-06-09 11:38:34 +010037int early_init_dt_alloc_reserved_memory_arch(phys_addr_t size,
38 phys_addr_t align,
39 phys_addr_t start,
40 phys_addr_t end,
41 bool nomap,
42 phys_addr_t *res_base);
43
Marek Szyprowski3f0c8202014-02-28 14:42:48 +010044void fdt_init_reserved_mem(void);
45void fdt_reserved_mem_save_node(unsigned long node, const char *uname,
46 phys_addr_t base, phys_addr_t size);
47#else
Marek Szyprowski59ce4032016-05-24 15:31:24 +020048static inline int of_reserved_mem_device_init_by_idx(struct device *dev,
49 struct device_node *np, int idx)
Marek Szyprowski47f29df2014-10-29 14:50:29 -070050{
51 return -ENOSYS;
52}
Marek Szyprowski9dcfee02014-07-14 10:28:04 +020053static inline void of_reserved_mem_device_release(struct device *pdev) { }
54
Marek Szyprowski3f0c8202014-02-28 14:42:48 +010055static inline void fdt_init_reserved_mem(void) { }
56static inline void fdt_reserved_mem_save_node(unsigned long node,
57 const char *uname, phys_addr_t base, phys_addr_t size) { }
Marek Szyprowski3f0c8202014-02-28 14:42:48 +010058#endif
59
Marek Szyprowski59ce4032016-05-24 15:31:24 +020060/**
61 * of_reserved_mem_device_init() - assign reserved memory region to given device
62 * @dev: Pointer to the device to configure
63 *
64 * This function assigns respective DMA-mapping operations based on the first
65 * reserved memory region specified by 'memory-region' property in device tree
66 * node of the given device.
67 *
68 * Returns error code or zero on success.
69 */
70static inline int of_reserved_mem_device_init(struct device *dev)
71{
72 return of_reserved_mem_device_init_by_idx(dev, dev->of_node, 0);
73}
74
Marek Szyprowski3f0c8202014-02-28 14:42:48 +010075#endif /* __OF_RESERVED_MEM_H */