summaryrefslogtreecommitdiff
path: root/include/linux/nvmap.h
blob: ff1f6549102534c4693309dad73ed9bf14bf5a86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
 * include/linux/nvmap.h
 *
 * structure declarations for nvmem and nvmap user-space ioctls
 *
 * Copyright (c) 2009, NVIDIA Corporation.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include <linux/ioctl.h>
#include <linux/file.h>

#if !defined(__KERNEL__)
#define __user
#endif

#ifndef __NVMAP_H
#define __NVMAP_H

struct nvmem_create_handle {
	union {
		__u32 key;	/* ClaimPreservedHandle */
		__u32 id;	/* FromId */
		__u32 size;	/* CreateHandle */
	};
	__u32 handle;
};

#define NVMEM_HEAP_SYSMEM  (1ul<<31)
#define NVMEM_HEAP_IOVMM   (1ul<<30)

/* common carveout heaps */
#define NVMEM_HEAP_CARVEOUT_IRAM    (1ul<<29)
#define NVMEM_HEAP_CARVEOUT_GENERIC (1ul<<0)

#define NVMEM_HEAP_CARVEOUT_MASK    (NVMEM_HEAP_IOVMM - 1)

#define NVMEM_HANDLE_UNCACHEABLE     (0x0ul << 0)
#define NVMEM_HANDLE_WRITE_COMBINE   (0x1ul << 0)
#define NVMEM_HANDLE_INNER_CACHEABLE (0x2ul << 0)
#define NVMEM_HANDLE_CACHEABLE       (0x3ul << 0)

#define NVMEM_HANDLE_SECURE          (0x1ul << 2)

struct nvmem_alloc_handle {
	__u32 handle;
	__u32 heap_mask;
	__u32 flags;
	__u32 align;
};

struct nvmem_map_caller {
	__u32 handle;		/* hmem */
	__u32 offset;		/* offset into hmem; should be page-aligned */
	__u32 length;		/* number of bytes to map */
	__u32 flags;
	unsigned long addr;	/* user pointer */
};

struct nvmem_rw_handle {
	unsigned long addr;	/* user pointer */
	__u32 handle;		/* hmem */
	__u32 offset;		/* offset into hmem */
	__u32 elem_size;	/* individual atom size */
	__u32 hmem_stride;	/* delta in bytes between atoms in hmem */
	__u32 user_stride;	/* delta in bytes between atoms in user */
	__u32 count;		/* number of atoms to copy */
};

struct nvmem_pin_handle {
	unsigned long handles;	/* array of handles to pin/unpin */
	unsigned long addr;	/* array of addresses to return */
	__u32 count;		/* number of entries in handles */
};

struct nvmem_handle_param {
	__u32 handle;
	__u32 param;
	unsigned long result;
};

enum {
	NVMEM_HANDLE_PARAM_SIZE = 1,
	NVMEM_HANDLE_PARAM_ALIGNMENT,
	NVMEM_HANDLE_PARAM_BASE,
	NVMEM_HANDLE_PARAM_HEAP,
};

enum {
	NVMEM_CACHE_OP_WB = 0,
	NVMEM_CACHE_OP_INV,
	NVMEM_CACHE_OP_WB_INV,
};

struct nvmem_cache_op {
	unsigned long addr;
	__u32 handle;
	__u32 len;
	__s32 op;
};

#define NVMEM_IOC_MAGIC 'N'

/* Creates a new memory handle. On input, the argument is the size of the new
 * handle; on return, the argument is the name of the new handle
 */
#define NVMEM_IOC_CREATE  _IOWR(NVMEM_IOC_MAGIC, 0, struct nvmem_create_handle)
#define NVMEM_IOC_CLAIM   _IOWR(NVMEM_IOC_MAGIC, 1, struct nvmem_create_handle)
#define NVMEM_IOC_FROM_ID _IOWR(NVMEM_IOC_MAGIC, 2, struct nvmem_create_handle)

/* Actually allocates memory for the specified handle */
#define NVMEM_IOC_ALLOC    _IOW (NVMEM_IOC_MAGIC, 3, struct nvmem_alloc_handle)

/* Frees a memory handle, unpinning any pinned pages and unmapping any mappings
 */
#define NVMEM_IOC_FREE       _IO (NVMEM_IOC_MAGIC, 4)

/* Maps the region of the specified handle into a user-provided virtual address
 * that was previously created via an mmap syscall on this fd */
#define NVMEM_IOC_MMAP       _IOWR(NVMEM_IOC_MAGIC, 5, struct nvmem_map_caller)

/* Reads/writes data (possibly strided) from a user-provided buffer into the
 * hmem at the specified offset */
#define NVMEM_IOC_WRITE      _IOW (NVMEM_IOC_MAGIC, 6, struct nvmem_rw_handle)
#define NVMEM_IOC_READ       _IOW (NVMEM_IOC_MAGIC, 7, struct nvmem_rw_handle)

#define NVMEM_IOC_PARAM _IOWR(NVMEM_IOC_MAGIC, 8, struct nvmem_handle_param)

/* Pins a list of memory handles into IO-addressable memory (either IOVMM
 * space or physical memory, depending on the allocation), and returns the
 * address. Handles may be pinned recursively. */
#define NVMEM_IOC_PIN_MULT   _IOWR(NVMEM_IOC_MAGIC, 10, struct nvmem_pin_handle)
#define NVMEM_IOC_UNPIN_MULT _IOW (NVMEM_IOC_MAGIC, 11, struct nvmem_pin_handle)

#define NVMEM_IOC_CACHE      _IOW (NVMEM_IOC_MAGIC, 12, struct nvmem_cache_op)

/* Returns a global ID usable to allow a remote process to create a handle
 * reference to the same handle */
#define NVMEM_IOC_GET_ID  _IOWR(NVMEM_IOC_MAGIC, 13, struct nvmem_create_handle)

#define NVMEM_IOC_MAXNR (_IOC_NR(NVMEM_IOC_GET_ID))

#if defined(__KERNEL__)

struct nvmap_handle;

struct nvmap_pinarray_elem {
	struct nvmap_handle *patch_mem;
	u32 patch_offset;
	struct nvmap_handle *pin_mem;
	u32 pin_offset;
};

int nvmap_validate_file(struct file *filep);
struct nvmap_handle *nvmap_alloc(
	size_t size, size_t align,
	unsigned int flags, void **map);
void nvmap_free(struct nvmap_handle *h, void *map);
u32 nvmap_pin_single(struct nvmap_handle *h);
int nvmap_pin_array(struct file *filp,
		struct nvmap_pinarray_elem *arr, int num_elems,
		struct nvmap_handle **unique_arr, int *num_unique, bool wait);
void nvmap_unpin(struct nvmap_handle **h, int num_handles);

int nvmap_add_carveout_heap(unsigned long base, size_t size,
	const char *name, unsigned int bitmask);

#endif

#endif