Linux Utils Application Programming Interface (API)  linuxutils-m06
 All Data Structures Files Functions Variables Typedefs Groups Pages
cmem.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007-2013 Texas Instruments Incorporated - https://www.ti.com
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * * Neither the name of Texas Instruments Incorporated nor the names of
16  * its contributors may be used to endorse or promote products derived
17  * from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
206 #ifndef ti_CMEM_H
207 #define ti_CMEM_H
208 
209 #if defined (__cplusplus)
210 extern "C" {
211 #endif
212 
215 
216 #define CMEM_VERSION 0x04000000U
217 
218 #define MAX_POOLS 32
219 
220 /* magic "block" corresponding to CMA regions */
221 #define CMEM_CMABLOCKID -1
222 
223 /* ioctl cmd "flavors" */
224 #define CMEM_WB 0x00010000
225 #define CMEM_INV 0x00020000
226 #define CMEM_HEAP 0x00040000
227 #define CMEM_POOL 0x00000000
228 #define CMEM_CACHED 0x00080000
229 #define CMEM_NONCACHED 0x00000000
230 #define CMEM_PHYS 0x00100000
231 
232 #define CMEM_IOCMAGIC 0x0000fe00
233 
234 /* supported "base" ioctl cmds for the driver. */
235 #define CMEM_IOCALLOC 1
236 #define CMEM_IOCALLOCHEAP 2
237 #define CMEM_IOCFREE 3
238 #define CMEM_IOCGETPHYS 4
239 #define CMEM_IOCGETSIZE 5
240 #define CMEM_IOCGETPOOL 6
241 #define CMEM_IOCCACHE 7
242 #define CMEM_IOCGETVERSION 8
243 #define CMEM_IOCGETBLOCK 9
244 #define CMEM_IOCREGUSER 10
245 #define CMEM_IOCGETNUMBLOCKS 11
246 /*
247  * New ioctl cmds should use integers greater than the largest current cmd
248  * in order to not break backward compatibility.
249  */
250 
251 /* supported "flavors" to "base" ioctl cmds for the driver. */
252 #define CMEM_IOCCACHEWBINV CMEM_IOCCACHE | CMEM_WB | CMEM_INV
253 #define CMEM_IOCCACHEWB CMEM_IOCCACHE | CMEM_WB
254 #define CMEM_IOCCACHEINV CMEM_IOCCACHE | CMEM_INV
255 #define CMEM_IOCALLOCCACHED CMEM_IOCALLOC | CMEM_CACHED
256 #define CMEM_IOCALLOCHEAPCACHED CMEM_IOCALLOCHEAP | CMEM_CACHED
257 #define CMEM_IOCFREEHEAP CMEM_IOCFREE | CMEM_HEAP
258 #define CMEM_IOCFREEPHYS CMEM_IOCFREE | CMEM_PHYS
259 #define CMEM_IOCFREEHEAPPHYS CMEM_IOCFREE | CMEM_HEAP | CMEM_PHYS
260 
261 #define CMEM_IOCCMDMASK 0x000000ff
262 
267 typedef struct CMEM_AllocParams {
268  int type;
269  int flags;
270  size_t alignment;
274 
276 
277 typedef struct CMEM_BlockAttrs {
278  off_t phys_base;
279  size_t size;
281 
286 union CMEM_AllocUnion {
287  struct {
288  size_t size;
289  size_t align;
290  int blockid;
291  } alloc_heap_inparams;
292  struct {
293  int poolid;
294  int blockid;
295  } alloc_pool_inparams;
296  struct {
297  int poolid;
298  int blockid;
299  } get_size_inparams;
300  struct {
301  size_t size;
302  int blockid;
303  } get_pool_inparams;
304  struct {
305  unsigned long long physp;
306  size_t size;
307  } alloc_pool_outparams;
308  struct {
309  unsigned long long physp;
310  size_t size;
311  } get_block_outparams;
312  struct {
313  int poolid;
314  size_t size;
315  } free_outparams;
316  unsigned long long physp;
317  void *virtp;
318  size_t size;
319  int poolid;
320  int blockid;
321 };
322 
332 int CMEM_init(void);
333 
349 int CMEM_getPool(size_t size);
350 
367 int CMEM_getPool2(int blockid, size_t size);
368 
390 void *CMEM_allocPool(int poolid, CMEM_AllocParams *params);
391 
414 void *CMEM_allocPool2(int blockid, int poolid, CMEM_AllocParams *params);
415 
441 void *CMEM_alloc(size_t size, CMEM_AllocParams *params);
442 
470 void *CMEM_alloc2(int blockid, size_t size, CMEM_AllocParams *params);
471 
495 void *CMEM_registerAlloc(off_t physp);
496 
519 int CMEM_free(void *ptr, CMEM_AllocParams *params);
520 
543 int CMEM_unregister(void *ptr, CMEM_AllocParams *params);
544 
554 off_t CMEM_getPhys(void *ptr);
555 
569 int CMEM_cacheWb(void *ptr, size_t size);
570 
584 int CMEM_cacheInv(void *ptr, size_t size);
585 
600 int CMEM_cacheWbInv(void *ptr, size_t size);
601 
609 int CMEM_getVersion(void);
610 
625 int CMEM_getBlock(off_t *pphys_base, size_t *psize);
626 
642 int CMEM_getBlockAttrs(int blockid, CMEM_BlockAttrs *pattrs);
643 
659 int CMEM_getNumBlocks(int *pnblocks);
660 
673 int CMEM_exit(void);
674 
677 #if defined (__cplusplus)
678 }
679 #endif
680 
681 #endif
Copyright 2013, Texas Instruments Incorporated