blob: c0291969216c714f822c913ed55d4cda8c2ba1dd [file] [log] [blame]
Rebecca Schultza4ff0e82008-07-24 11:22:53 -07001/* include/linux/android_pmem.h
2 *
3 * Copyright (C) 2007 Google, Inc.
4 *
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 */
15
16#ifndef _ANDROID_PMEM_H_
17#define _ANDROID_PMEM_H_
18
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070019#include <linux/fs.h>
20
21#define PMEM_KERNEL_TEST_MAGIC 0xc0
22#define PMEM_KERNEL_TEST_NOMINAL_TEST_IOCTL \
23 _IO(PMEM_KERNEL_TEST_MAGIC, 1)
24#define PMEM_KERNEL_TEST_ADVERSARIAL_TEST_IOCTL \
25 _IO(PMEM_KERNEL_TEST_MAGIC, 2)
26#define PMEM_KERNEL_TEST_HUGE_ALLOCATION_TEST_IOCTL \
27 _IO(PMEM_KERNEL_TEST_MAGIC, 3)
28#define PMEM_KERNEL_TEST_FREE_UNALLOCATED_TEST_IOCTL \
29 _IO(PMEM_KERNEL_TEST_MAGIC, 4)
30#define PMEM_KERNEL_TEST_LARGE_REGION_NUMBER_TEST_IOCTL \
31 _IO(PMEM_KERNEL_TEST_MAGIC, 5)
32
Rebecca Schultza4ff0e82008-07-24 11:22:53 -070033#define PMEM_IOCTL_MAGIC 'p'
34#define PMEM_GET_PHYS _IOW(PMEM_IOCTL_MAGIC, 1, unsigned int)
35#define PMEM_MAP _IOW(PMEM_IOCTL_MAGIC, 2, unsigned int)
36#define PMEM_GET_SIZE _IOW(PMEM_IOCTL_MAGIC, 3, unsigned int)
37#define PMEM_UNMAP _IOW(PMEM_IOCTL_MAGIC, 4, unsigned int)
38/* This ioctl will allocate pmem space, backing the file, it will fail
39 * if the file already has an allocation, pass it the len as the argument
40 * to the ioctl */
41#define PMEM_ALLOCATE _IOW(PMEM_IOCTL_MAGIC, 5, unsigned int)
42/* This will connect a one pmem file to another, pass the file that is already
43 * backed in memory as the argument to the ioctl
44 */
45#define PMEM_CONNECT _IOW(PMEM_IOCTL_MAGIC, 6, unsigned int)
46/* Returns the total size of the pmem region it is sent to as a pmem_region
47 * struct (with offset set to 0).
48 */
49#define PMEM_GET_TOTAL_SIZE _IOW(PMEM_IOCTL_MAGIC, 7, unsigned int)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070050/* Revokes gpu registers and resets the gpu. Pass a pointer to the
51 * start of the mapped gpu regs (the vaddr returned by mmap) as the argument.
52 */
53#define HW3D_REVOKE_GPU _IOW(PMEM_IOCTL_MAGIC, 8, unsigned int)
54#define HW3D_GRANT_GPU _IOW(PMEM_IOCTL_MAGIC, 9, unsigned int)
55#define HW3D_WAIT_FOR_INTERRUPT _IOW(PMEM_IOCTL_MAGIC, 10, unsigned int)
56
57#define PMEM_CLEAN_INV_CACHES _IOW(PMEM_IOCTL_MAGIC, 11, unsigned int)
58#define PMEM_CLEAN_CACHES _IOW(PMEM_IOCTL_MAGIC, 12, unsigned int)
59#define PMEM_INV_CACHES _IOW(PMEM_IOCTL_MAGIC, 13, unsigned int)
60
61#define PMEM_GET_FREE_SPACE _IOW(PMEM_IOCTL_MAGIC, 14, unsigned int)
62#define PMEM_ALLOCATE_ALIGNED _IOW(PMEM_IOCTL_MAGIC, 15, unsigned int)
63struct pmem_region {
64 unsigned long offset;
65 unsigned long len;
66};
67
68struct pmem_addr {
69 unsigned long vaddr;
70 unsigned long offset;
71 unsigned long length;
72};
73
74struct pmem_freespace {
75 unsigned long total;
76 unsigned long largest;
77};
78
79struct pmem_allocation {
80 unsigned long size;
81 unsigned int align;
82};
83
84#ifdef __KERNEL__
85int get_pmem_file(unsigned int fd, unsigned long *start, unsigned long *vstart,
86 unsigned long *end, struct file **filp);
87int get_pmem_fd(int fd, unsigned long *start, unsigned long *end);
88int get_pmem_user_addr(struct file *file, unsigned long *start,
89 unsigned long *end);
90void put_pmem_file(struct file* file);
91void put_pmem_fd(int fd);
92void flush_pmem_fd(int fd, unsigned long start, unsigned long len);
93void flush_pmem_file(struct file *file, unsigned long start, unsigned long len);
94int pmem_cache_maint(struct file *file, unsigned int cmd,
95 struct pmem_addr *pmem_addr);
96
97enum pmem_allocator_type {
98 /* Zero is a default in platform PMEM structures in the board files,
99 * when the "allocator_type" structure element is not explicitly
100 * defined
101 */
102 PMEM_ALLOCATORTYPE_BITMAP = 0, /* forced to be zero here */
103 PMEM_ALLOCATORTYPE_SYSTEM,
104
105 PMEM_ALLOCATORTYPE_ALLORNOTHING,
106 PMEM_ALLOCATORTYPE_BUDDYBESTFIT,
107
108 PMEM_ALLOCATORTYPE_MAX,
109};
110
111#define PMEM_MEMTYPE_MASK 0x7
112#define PMEM_INVALID_MEMTYPE 0x0
113#define PMEM_MEMTYPE_EBI1 0x1
114#define PMEM_MEMTYPE_SMI 0x2
115#define PMEM_MEMTYPE_RESERVED_INVALID2 0x3
116#define PMEM_MEMTYPE_RESERVED_INVALID3 0x4
117#define PMEM_MEMTYPE_RESERVED_INVALID4 0x5
118#define PMEM_MEMTYPE_RESERVED_INVALID5 0x6
119#define PMEM_MEMTYPE_RESERVED_INVALID6 0x7
120
121#define PMEM_ALIGNMENT_MASK 0x18
122#define PMEM_ALIGNMENT_RESERVED_INVALID1 0x0
123#define PMEM_ALIGNMENT_4K 0x8 /* the default */
124#define PMEM_ALIGNMENT_1M 0x10
125#define PMEM_ALIGNMENT_RESERVED_INVALID2 0x18
126
127/* flags in the following function defined as above. */
128int32_t pmem_kalloc(const size_t size, const uint32_t flags);
129int32_t pmem_kfree(const int32_t physaddr);
130
131/* kernel api names for board specific data structures */
132#define PMEM_KERNEL_EBI1_DATA_NAME "pmem_kernel_ebi1"
133#define PMEM_KERNEL_SMI_DATA_NAME "pmem_kernel_smi"
Rebecca Schultza4ff0e82008-07-24 11:22:53 -0700134
135struct android_pmem_platform_data
136{
137 const char* name;
Rebecca Schultza4ff0e82008-07-24 11:22:53 -0700138 /* size of memory region */
139 unsigned long size;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700140
141 enum pmem_allocator_type allocator_type;
142 /* treated as a 'hidden' variable in the board files. Can be
143 * set, but default is the system init value of 0 which becomes a
144 * quantum of 4K pages.
145 */
146 unsigned int quantum;
147
Rebecca Schultza4ff0e82008-07-24 11:22:53 -0700148 /* set to indicate maps of this region should be cached, if a mix of
149 * cached and uncached is desired, set this and open the device with
150 * O_SYNC to get an uncached region */
151 unsigned cached;
152 /* The MSM7k has bits to enable a write buffer in the bus controller*/
153 unsigned buffered;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700154 /* which memory type (i.e. SMI, EBI1) this PMEM device is backed by */
155 unsigned memory_type;
Laura Abbott1e36a022011-06-22 17:08:13 -0700156 /*
157 * function to be called when the number of allocations goes from
158 * 0 -> 1
159 */
160 void (*request_region)(void *);
161 /*
162 * function to be called when the number of allocations goes from
163 * 1 -> 0
164 */
165 void (*release_region)(void *);
166 /*
167 * function to be called upon pmem registration
168 */
169 void *(*setup_region)(void);
170 /*
171 * indicates that this region should be mapped/unmaped as needed
172 */
173 int map_on_demand;
Rebecca Schultza4ff0e82008-07-24 11:22:53 -0700174};
175
Rebecca Schultza4ff0e82008-07-24 11:22:53 -0700176int pmem_setup(struct android_pmem_platform_data *pdata,
177 long (*ioctl)(struct file *, unsigned int, unsigned long),
178 int (*release)(struct inode *, struct file *));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700179
Rebecca Schultza4ff0e82008-07-24 11:22:53 -0700180int pmem_remap(struct pmem_region *region, struct file *file,
181 unsigned operation);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700182#endif /* __KERNEL__ */
Rebecca Schultza4ff0e82008-07-24 11:22:53 -0700183
184#endif //_ANDROID_PPP_H_
185