Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 2 | #ifndef __OF_RESERVED_MEM_H |
| 3 | #define __OF_RESERVED_MEM_H |
| 4 | |
Marek Szyprowski | 59ce403 | 2016-05-24 15:31:24 +0200 | [diff] [blame] | 5 | #include <linux/device.h> |
Geert Uytterhoeven | 4a470f0 | 2020-05-06 14:32:35 +0200 | [diff] [blame] | 6 | #include <linux/of.h> |
Marek Szyprowski | 59ce403 | 2016-05-24 15:31:24 +0200 | [diff] [blame] | 7 | |
Marek Szyprowski | f618c47 | 2014-02-28 14:42:49 +0100 | [diff] [blame] | 8 | struct of_phandle_args; |
| 9 | struct reserved_mem_ops; |
| 10 | |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 11 | struct reserved_mem { |
| 12 | const char *name; |
| 13 | unsigned long fdt_node; |
Marek Szyprowski | 9dcfee0 | 2014-07-14 10:28:04 +0200 | [diff] [blame] | 14 | unsigned long phandle; |
Marek Szyprowski | f618c47 | 2014-02-28 14:42:49 +0100 | [diff] [blame] | 15 | const struct reserved_mem_ops *ops; |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 16 | phys_addr_t base; |
| 17 | phys_addr_t size; |
Marek Szyprowski | f618c47 | 2014-02-28 14:42:49 +0100 | [diff] [blame] | 18 | void *priv; |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 19 | }; |
| 20 | |
Marek Szyprowski | f618c47 | 2014-02-28 14:42:49 +0100 | [diff] [blame] | 21 | struct reserved_mem_ops { |
Marek Szyprowski | 47f29df | 2014-10-29 14:50:29 -0700 | [diff] [blame] | 22 | int (*device_init)(struct reserved_mem *rmem, |
Marek Szyprowski | f618c47 | 2014-02-28 14:42:49 +0100 | [diff] [blame] | 23 | struct device *dev); |
| 24 | void (*device_release)(struct reserved_mem *rmem, |
| 25 | struct device *dev); |
| 26 | }; |
| 27 | |
Rob Herring | 9dd3107 | 2014-05-08 16:06:17 -0500 | [diff] [blame] | 28 | typedef int (*reservedmem_of_init_fn)(struct reserved_mem *rmem); |
| 29 | |
Rob Herring | 54196cc | 2014-05-08 16:09:24 -0500 | [diff] [blame] | 30 | #define RESERVEDMEM_OF_DECLARE(name, compat, init) \ |
| 31 | _OF_DECLARE(reservedmem, name, compat, init, reservedmem_of_init_fn) |
Marek Szyprowski | f618c47 | 2014-02-28 14:42:49 +0100 | [diff] [blame] | 32 | |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 33 | #ifdef CONFIG_OF_RESERVED_MEM |
Marek Szyprowski | 59ce403 | 2016-05-24 15:31:24 +0200 | [diff] [blame] | 34 | |
| 35 | int of_reserved_mem_device_init_by_idx(struct device *dev, |
| 36 | struct device_node *np, int idx); |
Thierry Reding | 0da0e31 | 2020-04-03 19:44:52 +0200 | [diff] [blame] | 37 | int of_reserved_mem_device_init_by_name(struct device *dev, |
| 38 | struct device_node *np, |
| 39 | const char *name); |
Marek Szyprowski | 9dcfee0 | 2014-07-14 10:28:04 +0200 | [diff] [blame] | 40 | void of_reserved_mem_device_release(struct device *dev); |
| 41 | |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 42 | void fdt_init_reserved_mem(void); |
| 43 | void fdt_reserved_mem_save_node(unsigned long node, const char *uname, |
| 44 | phys_addr_t base, phys_addr_t size); |
Bjorn Andersson | eb297bc | 2017-10-10 22:08:54 -0700 | [diff] [blame] | 45 | struct reserved_mem *of_reserved_mem_lookup(struct device_node *np); |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 46 | #else |
Marek Szyprowski | 59ce403 | 2016-05-24 15:31:24 +0200 | [diff] [blame] | 47 | static inline int of_reserved_mem_device_init_by_idx(struct device *dev, |
| 48 | struct device_node *np, int idx) |
Marek Szyprowski | 47f29df | 2014-10-29 14:50:29 -0700 | [diff] [blame] | 49 | { |
| 50 | return -ENOSYS; |
| 51 | } |
Thierry Reding | 0da0e31 | 2020-04-03 19:44:52 +0200 | [diff] [blame] | 52 | |
| 53 | static 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 Szyprowski | 9dcfee0 | 2014-07-14 10:28:04 +0200 | [diff] [blame] | 60 | static inline void of_reserved_mem_device_release(struct device *pdev) { } |
| 61 | |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 62 | static inline void fdt_init_reserved_mem(void) { } |
| 63 | static inline void fdt_reserved_mem_save_node(unsigned long node, |
| 64 | const char *uname, phys_addr_t base, phys_addr_t size) { } |
Bjorn Andersson | eb297bc | 2017-10-10 22:08:54 -0700 | [diff] [blame] | 65 | static inline struct reserved_mem *of_reserved_mem_lookup(struct device_node *np) |
| 66 | { |
| 67 | return NULL; |
| 68 | } |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 69 | #endif |
| 70 | |
Marek Szyprowski | 59ce403 | 2016-05-24 15:31:24 +0200 | [diff] [blame] | 71 | /** |
| 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 | */ |
| 81 | static 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 Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 86 | #endif /* __OF_RESERVED_MEM_H */ |