Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 1 | #ifndef __OF_RESERVED_MEM_H |
| 2 | #define __OF_RESERVED_MEM_H |
| 3 | |
Marek Szyprowski | 59ce403 | 2016-05-24 15:31:24 +0200 | [diff] [blame] | 4 | #include <linux/device.h> |
| 5 | |
Marek Szyprowski | f618c47 | 2014-02-28 14:42:49 +0100 | [diff] [blame] | 6 | struct of_phandle_args; |
| 7 | struct reserved_mem_ops; |
| 8 | |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 9 | struct reserved_mem { |
| 10 | const char *name; |
| 11 | unsigned long fdt_node; |
Marek Szyprowski | 9dcfee0 | 2014-07-14 10:28:04 +0200 | [diff] [blame] | 12 | unsigned long phandle; |
Marek Szyprowski | f618c47 | 2014-02-28 14:42:49 +0100 | [diff] [blame] | 13 | const struct reserved_mem_ops *ops; |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 14 | phys_addr_t base; |
| 15 | phys_addr_t size; |
Marek Szyprowski | f618c47 | 2014-02-28 14:42:49 +0100 | [diff] [blame] | 16 | void *priv; |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 17 | }; |
| 18 | |
Marek Szyprowski | f618c47 | 2014-02-28 14:42:49 +0100 | [diff] [blame] | 19 | struct reserved_mem_ops { |
Marek Szyprowski | 47f29df | 2014-10-29 14:50:29 -0700 | [diff] [blame] | 20 | int (*device_init)(struct reserved_mem *rmem, |
Marek Szyprowski | f618c47 | 2014-02-28 14:42:49 +0100 | [diff] [blame] | 21 | struct device *dev); |
| 22 | void (*device_release)(struct reserved_mem *rmem, |
| 23 | struct device *dev); |
| 24 | }; |
| 25 | |
Rob Herring | 9dd3107 | 2014-05-08 16:06:17 -0500 | [diff] [blame] | 26 | typedef int (*reservedmem_of_init_fn)(struct reserved_mem *rmem); |
| 27 | |
Rob Herring | 54196cc | 2014-05-08 16:09:24 -0500 | [diff] [blame] | 28 | #define RESERVEDMEM_OF_DECLARE(name, compat, init) \ |
| 29 | _OF_DECLARE(reservedmem, name, compat, init, reservedmem_of_init_fn) |
Marek Szyprowski | f618c47 | 2014-02-28 14:42:49 +0100 | [diff] [blame] | 30 | |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 31 | #ifdef CONFIG_OF_RESERVED_MEM |
Marek Szyprowski | 59ce403 | 2016-05-24 15:31:24 +0200 | [diff] [blame] | 32 | |
| 33 | int of_reserved_mem_device_init_by_idx(struct device *dev, |
| 34 | struct device_node *np, int idx); |
Marek Szyprowski | 9dcfee0 | 2014-07-14 10:28:04 +0200 | [diff] [blame] | 35 | void of_reserved_mem_device_release(struct device *dev); |
| 36 | |
Ben Dooks | 06dfeef | 2016-06-09 11:38:34 +0100 | [diff] [blame] | 37 | int 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 Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 44 | void fdt_init_reserved_mem(void); |
| 45 | void fdt_reserved_mem_save_node(unsigned long node, const char *uname, |
| 46 | phys_addr_t base, phys_addr_t size); |
| 47 | #else |
Marek Szyprowski | 59ce403 | 2016-05-24 15:31:24 +0200 | [diff] [blame] | 48 | static inline int of_reserved_mem_device_init_by_idx(struct device *dev, |
| 49 | struct device_node *np, int idx) |
Marek Szyprowski | 47f29df | 2014-10-29 14:50:29 -0700 | [diff] [blame] | 50 | { |
| 51 | return -ENOSYS; |
| 52 | } |
Marek Szyprowski | 9dcfee0 | 2014-07-14 10:28:04 +0200 | [diff] [blame] | 53 | static inline void of_reserved_mem_device_release(struct device *pdev) { } |
| 54 | |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 55 | static inline void fdt_init_reserved_mem(void) { } |
| 56 | static inline void fdt_reserved_mem_save_node(unsigned long node, |
| 57 | const char *uname, phys_addr_t base, phys_addr_t size) { } |
Marek Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 58 | #endif |
| 59 | |
Marek Szyprowski | 59ce403 | 2016-05-24 15:31:24 +0200 | [diff] [blame] | 60 | /** |
| 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 | */ |
| 70 | static 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 Szyprowski | 3f0c820 | 2014-02-28 14:42:48 +0100 | [diff] [blame] | 75 | #endif /* __OF_RESERVED_MEM_H */ |