of_reserved_mem.h 2.14 KB
Newer Older
1 2 3
#ifndef __OF_RESERVED_MEM_H
#define __OF_RESERVED_MEM_H

4 5
#include <linux/device.h>

6 7 8
struct of_phandle_args;
struct reserved_mem_ops;

9 10 11
struct reserved_mem {
	const char			*name;
	unsigned long			fdt_node;
12
	unsigned long			phandle;
13
	const struct reserved_mem_ops	*ops;
14 15
	phys_addr_t			base;
	phys_addr_t			size;
16 17 18 19
	void				*priv;
};

struct reserved_mem_ops {
20
	int	(*device_init)(struct reserved_mem *rmem,
21 22 23
			       struct device *dev);
	void	(*device_release)(struct reserved_mem *rmem,
				  struct device *dev);
24 25
};

26 27
typedef int (*reservedmem_of_init_fn)(struct reserved_mem *rmem);

28 29
#define RESERVEDMEM_OF_DECLARE(name, compat, init)			\
	_OF_DECLARE(reservedmem, name, compat, init, reservedmem_of_init_fn)
30

31
#ifdef CONFIG_OF_RESERVED_MEM
32 33 34

int of_reserved_mem_device_init_by_idx(struct device *dev,
				       struct device_node *np, int idx);
35 36
void of_reserved_mem_device_release(struct device *dev);

37 38 39 40 41 42 43
int early_init_dt_alloc_reserved_memory_arch(phys_addr_t size,
					     phys_addr_t align,
					     phys_addr_t start,
					     phys_addr_t end,
					     bool nomap,
					     phys_addr_t *res_base);

44 45 46 47
void fdt_init_reserved_mem(void);
void fdt_reserved_mem_save_node(unsigned long node, const char *uname,
			       phys_addr_t base, phys_addr_t size);
#else
48 49
static inline int of_reserved_mem_device_init_by_idx(struct device *dev,
					struct device_node *np, int idx)
50 51 52
{
	return -ENOSYS;
}
53 54
static inline void of_reserved_mem_device_release(struct device *pdev) { }

55 56 57 58 59
static inline void fdt_init_reserved_mem(void) { }
static inline void fdt_reserved_mem_save_node(unsigned long node,
		const char *uname, phys_addr_t base, phys_addr_t size) { }
#endif

60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
/**
 * of_reserved_mem_device_init() - assign reserved memory region to given device
 * @dev:	Pointer to the device to configure
 *
 * This function assigns respective DMA-mapping operations based on the first
 * reserved memory region specified by 'memory-region' property in device tree
 * node of the given device.
 *
 * Returns error code or zero on success.
 */
static inline int of_reserved_mem_device_init(struct device *dev)
{
	return of_reserved_mem_device_init_by_idx(dev, dev->of_node, 0);
}

75
#endif /* __OF_RESERVED_MEM_H */