blob: 8216a415626372ca4ca6da8bfb410be8de4a25c4 [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>
Geert Uytterhoeven4a470f02020-05-06 14:32:35 +02006#include <linux/of.h>
Marek Szyprowski59ce4032016-05-24 15:31:24 +02007
Marek Szyprowskif618c472014-02-28 14:42:49 +01008struct of_phandle_args;
9struct reserved_mem_ops;
10
Marek Szyprowski3f0c8202014-02-28 14:42:48 +010011struct reserved_mem {
12 const char *name;
13 unsigned long fdt_node;
Marek Szyprowski9dcfee02014-07-14 10:28:04 +020014 unsigned long phandle;
Marek Szyprowskif618c472014-02-28 14:42:49 +010015 const struct reserved_mem_ops *ops;
Marek Szyprowski3f0c8202014-02-28 14:42:48 +010016 phys_addr_t base;
17 phys_addr_t size;
Marek Szyprowskif618c472014-02-28 14:42:49 +010018 void *priv;
Marek Szyprowski3f0c8202014-02-28 14:42:48 +010019};
20
Marek Szyprowskif618c472014-02-28 14:42:49 +010021struct reserved_mem_ops {
Marek Szyprowski47f29df2014-10-29 14:50:29 -070022 int (*device_init)(struct reserved_mem *rmem,
Marek Szyprowskif618c472014-02-28 14:42:49 +010023 struct device *dev);
24 void (*device_release)(struct reserved_mem *rmem,
25 struct device *dev);
26};
27
Rob Herring9dd31072014-05-08 16:06:17 -050028typedef int (*reservedmem_of_init_fn)(struct reserved_mem *rmem);
29
Rob Herring54196cc2014-05-08 16:09:24 -050030#define RESERVEDMEM_OF_DECLARE(name, compat, init) \
31 _OF_DECLARE(reservedmem, name, compat, init, reservedmem_of_init_fn)
Marek Szyprowskif618c472014-02-28 14:42:49 +010032
Marek Szyprowski3f0c8202014-02-28 14:42:48 +010033#ifdef CONFIG_OF_RESERVED_MEM
Marek Szyprowski59ce4032016-05-24 15:31:24 +020034
35int of_reserved_mem_device_init_by_idx(struct device *dev,
36 struct device_node *np, int idx);
Thierry Reding0da0e312020-04-03 19:44:52 +020037int of_reserved_mem_device_init_by_name(struct device *dev,
38 struct device_node *np,
39 const char *name);
Marek Szyprowski9dcfee02014-07-14 10:28:04 +020040void of_reserved_mem_device_release(struct device *dev);
41
Marek Szyprowski3f0c8202014-02-28 14:42:48 +010042void fdt_init_reserved_mem(void);
43void fdt_reserved_mem_save_node(unsigned long node, const char *uname,
44 phys_addr_t base, phys_addr_t size);
Bjorn Anderssoneb297bc2017-10-10 22:08:54 -070045struct reserved_mem *of_reserved_mem_lookup(struct device_node *np);
Marek Szyprowski3f0c8202014-02-28 14:42:48 +010046#else
Marek Szyprowski59ce4032016-05-24 15:31:24 +020047static inline int of_reserved_mem_device_init_by_idx(struct device *dev,
48 struct device_node *np, int idx)
Marek Szyprowski47f29df2014-10-29 14:50:29 -070049{
50 return -ENOSYS;
51}
Thierry Reding0da0e312020-04-03 19:44:52 +020052
53static inline int of_reserved_mem_device_init_by_name(struct device *dev,
54 struct device_node *np,
55 const char *name)
56{
57 return -ENOSYS;
58}
59
Marek Szyprowski9dcfee02014-07-14 10:28:04 +020060static inline void of_reserved_mem_device_release(struct device *pdev) { }
61
Marek Szyprowski3f0c8202014-02-28 14:42:48 +010062static inline void fdt_init_reserved_mem(void) { }
63static inline void fdt_reserved_mem_save_node(unsigned long node,
64 const char *uname, phys_addr_t base, phys_addr_t size) { }
Bjorn Anderssoneb297bc2017-10-10 22:08:54 -070065static inline struct reserved_mem *of_reserved_mem_lookup(struct device_node *np)
66{
67 return NULL;
68}
Marek Szyprowski3f0c8202014-02-28 14:42:48 +010069#endif
70
Marek Szyprowski59ce4032016-05-24 15:31:24 +020071/**
72 * of_reserved_mem_device_init() - assign reserved memory region to given device
73 * @dev: Pointer to the device to configure
74 *
75 * This function assigns respective DMA-mapping operations based on the first
76 * reserved memory region specified by 'memory-region' property in device tree
77 * node of the given device.
78 *
79 * Returns error code or zero on success.
80 */
81static inline int of_reserved_mem_device_init(struct device *dev)
82{
83 return of_reserved_mem_device_init_by_idx(dev, dev->of_node, 0);
84}
85
Marek Szyprowski3f0c8202014-02-28 14:42:48 +010086#endif /* __OF_RESERVED_MEM_H */