2 * Copyright 2001-2008 Texas Instruments - http://www.ti.com/
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * ======== memry.h ========
19 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
21 * Functional interface for the memory manager, exported by the DSP
22 * system API DLL. This interface is not publicly documented.
34 * MEMRY_UnMapLinearAddress
38 *! 01-Sep-2001 ag: Added MEMRY_[UnMap]LinearAddress.
39 *! 11-Oct-2000 ag: Added MEMRY_Reserve[Free]VM() & MEMRY_BindMem().
40 *! 12-Nov-1999 kc: Updated for WinCE.
56 * MEMRY_[GET]SET]VIRTUALSEGID is used by Node & Strm to access virtual
57 * address space in the correct client process context. The virtual to
58 * physical mapping is done in the client process context.
60 #define MEMRY_SETVIRTUALSEGID MEM_SETVIRTUALSEGID
61 #define MEMRY_GETVIRTUALSEGID MEM_GETVIRTUALSEGID
62 #define MEMRY_MASKVIRTUALSEGID MEM_MASKVIRTUALSEGID
67 * ======== MEMRY_Alloc ========
69 * Allocate memory from the paged or non-paged pools.
71 * cBytes: Number of bytes to allocate.
72 * type: Type of memory to allocate; one of:
73 * - MEM_PAGED: Allocate from the pageable memory.
74 * - MEM_NONPAGED:Allocate from page locked memory.
76 * Pointer to a block of memory; or NULL if memory couldn't be
80 * PVOID pointer returned is a valid memory location.
82 extern PVOID MEMRY_Alloc(ULONG cBytes, MEM_POOLATTRS type);
85 * ======== MEMRY_BindBuf ========
87 * Bind a Physical address to a Virtual Address.
88 * In WinCE performs a VirtualCopy().
90 * pVA: Ptr to reserved memory allocated by MEMRY_ReserveVM().
91 * pPA: Ptr to a physical memory location.
92 * ulBytes: Size of physical memory in bytes.
94 * TRUE if successful, else FALSE.
99 extern bool MEMRY_BindMem(PVOID pVA, PVOID pPA, ULONG ulBytes);
102 * ======== MEMRY_Calloc ========
104 * Allocate zero-initialized memory from the paged or non-paged pools.
106 * cBytes: Number of bytes to allocate.
107 * type: Type of memory to allocate; one of:
108 * - MEM_PAGED: Allocate from the pageable memory.
109 * - MEM_NONPAGED: Allocate from page locked memory.
111 * Pointer to a contiguous block of zeroed memory; or NULL if memory
112 * couldn't be allocated.
115 * PVOID pointer returned is a valid memory location.
117 extern PVOID WINAPI MEMRY_Calloc(ULONG cBytes, MEM_POOLATTRS type);
120 * ======== MEMRY_Free ========
122 * Free the given block of system memory.
124 * pMemBuf: Pointer to memory allocated by MEMRY_Alloc().
128 * pMemBuf is no longer a valid pointer to memory.
130 extern VOID MEMRY_Free(IN PVOID pMemBuf);
133 * ======== MEMRY_FreeVM ========
135 * Free VM reserved by MEMRY_ReserveVM.
137 * pVirtualAddr: Pointer to memory VM allocated by MEMRY_ReserveVM().
139 * TRUE on success, else FALSE.
145 extern bool MEMRY_FreeVM(PVOID pVirtualAddr);
148 * ======== MEMRY_PageLock ========
150 * Calls kernel services to map the set of pages identified by a private
151 * process pointer and a byte count into the calling process's globally
152 * shared address space.
154 * lpBuffer: Pointer to a process-private data buffer.
155 * cSize: Size in bytes of the data buffer.
157 * A pointer to linear page locked memory, or
158 * NULL if failure locking memory.
160 * The size (cSize) must accurately reflect the size of the buffer to
161 * be locked, since the page count is derived from this number.
163 * Memory locked by this service can be accessed at interrupt time, or
164 * from other memory contexts.
166 extern DSPAPIDLL PVOID WINAPI MEMRY_PageLock(PVOID pBuffer,
169 #endif /* ifndef LINUX */
172 * ======== MEMRY_LinearAddress ========
174 * Get the linear address corresponding to the given physical address.
176 * pPhysAddr: Physical address to be mapped.
177 * cBytes: Number of bytes in physical range to map.
179 * The corresponding linear address, or NULL if unsuccessful.
184 * If valid linear address is returned, be sure to call
185 * MEMRY_UnMapLinearAddress().
187 extern inline PVOID MEMRY_LinearAddress(PVOID pPhyAddr, ULONG cBytes) {
192 * ======== MEMRY_PageUnlock ========
194 * Unlocks a buffer previously locked using MEMRY_PageLock().
196 * pBuffer: Pointer to locked memory (as returned by MEMRY_PageLock()).
197 * cSize: Size in bytes of the buffer.
199 * Returns DSP_SOK if unlock successful; else, returns DSP_EFAIL;
201 * pBuffer must be a pointer to a locked, shared data buffer previously
202 * locked with MEMRY_PageLock().
204 * Will unlock the pages of memory when the lock count drops to zero.
205 * MEMRY_PageLock() increments the lock count, and MEMRY_PageUnlock
206 * decrements the count.
207 */ extern DSPAPIDLL MEMRY_PageUnlock(PVOID pBuffer, ULONG cSize);
210 * ======== MEMRY_ReserveVM ========
212 * Reserve at least ulBytes (page size inc) virtual memory for this process.
214 * ulBytes: Size in bytes of the minimum space to reserve.
216 * Returns NULL on failure, else valid VA of at least ulBytes size.
220 extern PVOID MEMRY_ReserveVM(ULONG cBytes);
222 #endif /* ifndef LINUX */
225 * ======== MEMRY_UnMapLinearAddress ========
227 * Unmap the linear address mapped in MEMRY_LinearAddress.
229 * pBaseAddr: Ptr to mapped memory (as returned by MEMRY_LinearAddress()).
232 * - pBaseAddr is a valid linear address mapped in MEMRY_LinearAddress.
234 * - pBaseAddr no longer points to a valid linear address.
236 extern inline VOID MEMRY_UnMapLinearAddress(PVOID pBaseAddr) {