[android-sdk/device-ti-proprietary-open.git] / jacinto6 / sgx_src / eurasia_km / services4 / srvkm / env / linux / mmap.h
1 /*************************************************************************/ /*!
2 @Title Linux mmap interface declaration
3 @Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
4 @License Dual MIT/GPLv2
6 The contents of this file are subject to the MIT license as set out below.
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
18 Alternatively, the contents of this file may be used under the terms of
19 the GNU General Public License Version 2 ("GPL") in which case the provisions
20 of GPL are applicable instead of those above.
22 If you wish to allow use of your version of this file only under the terms of
23 GPL, and not to allow others to use your version of this file under the terms
24 of the MIT license, indicate your decision by deleting the provisions above
25 and replace them with the notice and other provisions required by GPL as set
26 out in the file called "GPL-COPYING" included in this distribution. If you do
27 not delete the provisions above, a recipient may use your version of this file
28 under the terms of either the MIT license or GPL.
30 This License is also included in this distribution in the file called
31 "MIT-COPYING".
33 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
34 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
35 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
36 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
37 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
38 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
39 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 */ /**************************************************************************/
42 #if !defined(__MMAP_H__)
43 #define __MMAP_H__
45 #include <linux/mm.h>
46 #include <linux/list.h>
48 #if defined(VM_MIXEDMAP)
49 /*
50 * Mixed maps allow us to avoid using raw PFN mappings (VM_PFNMAP) for
51 * pages without pages structures ("struct page"), giving us more
52 * freedom in choosing the mmap offset for mappings. Mixed maps also
53 * allow both the mmap and the wrap code to be simplified somewhat.
54 */
55 #define PVR_MAKE_ALL_PFNS_SPECIAL
56 #endif
58 #include "perproc.h"
59 #include "mm.h"
61 /*
62 * This structure represents the relationship between an mmap2 file
63 * offset and a LinuxMemArea for a given process.
64 */
65 typedef struct KV_OFFSET_STRUCT_TAG
66 {
67 /*
68 * Mapping count. Incremented when the mapping is created, and
69 * if the mapping is inherited across a process fork.
70 */
71 IMG_UINT32 ui32Mapped;
73 /*
74 * Offset to be passed to mmap2 to map the associated memory area
75 * into user space. The offset may represent the page frame number
76 * of the first page in the area (if the area is physically
77 * contiguous), or it may represent the secure handle associated
78 * with the area.
79 */
80 IMG_UINTPTR_T uiMMapOffset;
82 IMG_SIZE_T uiRealByteSize;
84 /* Memory area associated with this offset structure */
85 LinuxMemArea *psLinuxMemArea;
87 #if !defined(PVR_MAKE_ALL_PFNS_SPECIAL)
88 /* ID of the thread that owns this structure */
89 IMG_UINT32 ui32TID;
90 #endif
92 /* ID of the process that owns this structure */
93 IMG_UINT32 ui32PID;
95 /*
96 * For offsets that represent actual page frame numbers, this structure
97 * is temporarily put on a list so that it can be found from the
98 * driver mmap entry point. This flag indicates the structure is
99 * on the list.
100 */
101 IMG_BOOL bOnMMapList;
103 /* Reference count for this structure */
104 IMG_UINT32 ui32RefCount;
106 /*
107 * User mode address of start of mapping. This is not necessarily the
108 * first user mode address of the memory area.
109 */
110 IMG_UINTPTR_T uiUserVAddr;
112 /* Extra entries to support proc filesystem debug info */
113 #if defined(DEBUG_LINUX_MMAP_AREAS)
114 const IMG_CHAR *pszName;
115 #endif
117 /* List entry field for MMap list */
118 struct list_head sMMapItem;
120 /* List entry field for per-memory area list */
121 struct list_head sAreaItem;
122 }KV_OFFSET_STRUCT, *PKV_OFFSET_STRUCT;
126 /*!
127 *******************************************************************************
128 * @Function Mmap initialisation code
129 ******************************************************************************/
130 IMG_VOID PVRMMapInit(IMG_VOID);
133 /*!
134 *******************************************************************************
135 * @Function Mmap de-initialisation code
136 ******************************************************************************/
137 IMG_VOID PVRMMapCleanup(IMG_VOID);
140 /*!
141 *******************************************************************************
142 * @Function Registers a memory area with the mmap code
143 *
144 * @Input psLinuxMemArea
145 *
146 * @Return PVRSRV_ERROR status
147 ******************************************************************************/
148 PVRSRV_ERROR PVRMMapRegisterArea(LinuxMemArea *psLinuxMemArea);
151 /*!
152 *******************************************************************************
153 * @Function Unregisters a memory area from the mmap code
154 *
155 * @Input psLinuxMemArea
156 *
157 * @Return PVRSRV_ERROR status
158 ******************************************************************************/
159 PVRSRV_ERROR PVRMMapRemoveRegisteredArea(LinuxMemArea *psLinuxMemArea);
162 /*!
163 ******************************************************************************
164 * @Function When a userspace services client, requests to map a memory
165 * area to userspace, this function validates the request and
166 * returns the details that the client must use when calling mmap(2).
167 *
168 * @Input psPerProc Per process data.
169 * @Input hMHandle Handle associated with the memory to map.
170 * This is a (secure) handle to the OS specific
171 * memory handle structure (hOSMemHandle), or
172 * a handle to a structure that contains the
173 * memory handle.
174 * @Output pui32MMapOffset The page aligned offset that the client must
175 * pass to the mmap2 system call.
176 * @Output pui32ByteOffset The real mapping that will be created for the
177 * services client may have a different
178 * size/alignment from it request. This offset
179 * is returned to the client and should be added
180 * to virtual address returned from mmap2 to get
181 * the first address corresponding to its request.
182 * @Output pui32RealByteOffset The size that the mapping will really be,
183 * that the client must also pass to mmap/munmap.
184 *
185 * @Output pui32UserVAddr Pointer to returned user mode address of
186 * mapping.
187 * @Return PVRSRV_ERROR
188 ******************************************************************************/
189 PVRSRV_ERROR PVRMMapOSMemHandleToMMapData(PVRSRV_PER_PROCESS_DATA *psPerProc,
190 IMG_HANDLE hMHandle,
191 IMG_UINTPTR_T *puiMMapOffset,
192 IMG_UINTPTR_T *puiByteOffset,
193 IMG_SIZE_T *puiRealByteSize,
194 IMG_UINTPTR_T *puiUserVAddr);
196 /*!
197 *******************************************************************************
199 @Function Release mmap data.
201 @Input psPerProc Per-process data.
202 @Input hMHandle Memory handle.
204 @Output pbMUnmap Flag that indicates whether an munmap is
205 required.
206 @Output pui32RealByteSize Location for size of mapping.
207 @Output pui32UserVAddr User mode address to munmap.
209 @Return PVRSRV_ERROR
210 ******************************************************************************/
211 PVRSRV_ERROR
212 PVRMMapReleaseMMapData(PVRSRV_PER_PROCESS_DATA *psPerProc,
213 IMG_HANDLE hMHandle,
214 IMG_BOOL *pbMUnmap,
215 IMG_SIZE_T *puiRealByteSize,
216 IMG_UINTPTR_T *puiUserVAddr);
218 /*!
219 *******************************************************************************
220 * @Function driver mmap entry point
221 *
222 * @Input pFile : user file structure
223 *
224 * @Input ps_vma : vm area structure
225 *
226 * @Return 0 for success, -errno for failure.
227 ******************************************************************************/
228 int PVRMMap(struct file* pFile, struct vm_area_struct* ps_vma);
231 #endif /* __MMAP_H__ */