Linux Utils Application Programming Interface (API)  linuxutils-n02
 All Data Structures Files Functions Variables Typedefs Groups Pages
cmem.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007-2014 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  */
315 #ifndef ti_CMEM_H
316 #define ti_CMEM_H
317 
318 #if defined (__cplusplus)
319 extern "C" {
320 #endif
321 
324 
325 #define CMEM_VERSION 0x04000300U
326 
327 #define MAX_POOLS 32
328 
329 /* magic "block" corresponding to CMA regions */
330 #define CMEM_CMABLOCKID -1
331 
332 /* ioctl cmd "flavors" */
333 #define CMEM_WB 0x00010000
334 #define CMEM_INV 0x00020000
335 #define CMEM_HEAP 0x00040000
336 #define CMEM_POOL 0x00000000
337 #define CMEM_CACHED 0x00080000
338 #define CMEM_NONCACHED 0x00000000
339 #define CMEM_PHYS 0x00100000
340 
341 #define CMEM_IOCMAGIC 0x0000fe00
342 
343 /* supported "base" ioctl cmds for the driver. */
344 #define CMEM_IOCALLOC 1
345 #define CMEM_IOCALLOCHEAP 2
346 #define CMEM_IOCFREE 3
347 #define CMEM_IOCGETPHYS 4
348 #define CMEM_IOCGETSIZE 5
349 #define CMEM_IOCGETPOOL 6
350 #define CMEM_IOCCACHE 7
351 #define CMEM_IOCGETVERSION 8
352 #define CMEM_IOCGETBLOCK 9
353 #define CMEM_IOCREGUSER 10
354 #define CMEM_IOCGETNUMBLOCKS 11
355 #define CMEM_IOCCACHEWBINVALL 12
356 /*
357  * New ioctl cmds should use integers greater than the largest current cmd
358  * in order to not break backward compatibility.
359  */
360 
361 /* supported "flavors" to "base" ioctl cmds for the driver. */
362 #define CMEM_IOCCACHEWBINV CMEM_IOCCACHE | CMEM_WB | CMEM_INV
363 #define CMEM_IOCCACHEWB CMEM_IOCCACHE | CMEM_WB
364 #define CMEM_IOCCACHEINV CMEM_IOCCACHE | CMEM_INV
365 #define CMEM_IOCALLOCCACHED CMEM_IOCALLOC | CMEM_CACHED
366 #define CMEM_IOCALLOCHEAPCACHED CMEM_IOCALLOCHEAP | CMEM_CACHED
367 #define CMEM_IOCFREEHEAP CMEM_IOCFREE | CMEM_HEAP
368 #define CMEM_IOCFREEPHYS CMEM_IOCFREE | CMEM_PHYS
369 #define CMEM_IOCFREEHEAPPHYS CMEM_IOCFREE | CMEM_HEAP | CMEM_PHYS
370 
371 #define CMEM_IOCCMDMASK 0x000000ff
372 
377 typedef struct CMEM_AllocParams {
378  int type;
379  int flags;
380  size_t alignment;
384 
386 
387 typedef struct CMEM_BlockAttrs {
388  off_t phys_base;
389  unsigned long long size;
391 
396 union CMEM_AllocUnion {
397  struct {
398  size_t size;
399  size_t align;
400  int blockid;
401  } alloc_heap_inparams;
402  struct {
403  int poolid;
404  int blockid;
405  } alloc_pool_inparams;
406  struct {
407  int poolid;
408  int blockid;
409  } get_size_inparams;
410  struct {
411  unsigned long long size;
412  int blockid;
413  } get_pool_inparams;
414  struct {
415  unsigned long long physp;
416  unsigned long long size;
417  } alloc_pool_outparams;
418  struct {
419  unsigned long long physp;
420  unsigned long long size;
421  } get_block_outparams;
422  struct {
423  int poolid;
424  size_t size;
425  } free_outparams;
426  unsigned long long physp;
427  void *virtp;
428  size_t size;
429  int poolid;
430  int blockid;
431 };
432 
442 int CMEM_init(void);
443 
459 int CMEM_getPool(unsigned long long size);
460 
477 int CMEM_getPool2(int blockid, unsigned long long size);
478 
500 void *CMEM_allocPool(int poolid, CMEM_AllocParams *params);
501 
524 void *CMEM_allocPool2(int blockid, int poolid, CMEM_AllocParams *params);
525 
551 void *CMEM_alloc(size_t size, CMEM_AllocParams *params);
552 
580 void *CMEM_alloc2(int blockid, size_t size, CMEM_AllocParams *params);
581 
602 off_t CMEM_allocPoolPhys(int poolid, CMEM_AllocParams *params);
603 
626 off_t CMEM_allocPoolPhys2(int blockid, int poolid, CMEM_AllocParams *params);
627 
628 #if defined(LINUXUTILS_BUILDOS_ANDROID)
629 
651 off64_t CMEM_allocPoolPhys64(int blockid, int poolid, CMEM_AllocParams *params);
652 #endif
653 
678 off_t CMEM_allocPhys(size_t size, CMEM_AllocParams *params);
679 
707 off_t CMEM_allocPhys2(int blockid, size_t size, CMEM_AllocParams *params);
708 
709 #if defined(LINUXUTILS_BUILDOS_ANDROID)
710 
737 off64_t CMEM_allocPhys64(int blockid, size_t size, CMEM_AllocParams *params);
738 #endif
739 
763 void *CMEM_registerAlloc(off_t physp);
764 
765 #if defined(LINUXUTILS_BUILDOS_ANDROID)
766 
790 void *CMEM_registerAlloc64(off64_t physp);
791 #endif
792 
815 int CMEM_free(void *ptr, CMEM_AllocParams *params);
816 
838 int CMEM_freePhys(off_t physp, CMEM_AllocParams *params);
839 
840 #if defined(LINUXUTILS_BUILDOS_ANDROID)
841 
862 int CMEM_freePhys64(off64_t physp, CMEM_AllocParams *params);
863 #endif
864 
887 int CMEM_unregister(void *ptr, CMEM_AllocParams *params);
888 
898 off_t CMEM_getPhys(void *ptr);
899 
900 #if defined(LINUXUTILS_BUILDOS_ANDROID)
901 
910 off64_t CMEM_getPhys64(void *ptr);
911 #endif
912 
924 int CMEM_cacheWbInvAll(void);
925 
940 int CMEM_cacheWb(void *ptr, size_t size);
941 
956 void *CMEM_map(off_t physp, size_t size);
957 
958 #if defined(LINUXUTILS_BUILDOS_ANDROID)
959 
973 void *CMEM_map64(off64_t physp, size_t size);
974 #endif
975 
989 int CMEM_unmap(void *userp, size_t size);
990 
1005 int CMEM_cacheInv(void *ptr, size_t size);
1006 
1022 int CMEM_cacheWbInv(void *ptr, size_t size);
1023 
1031 int CMEM_getVersion(void);
1032 
1047 int CMEM_getBlock(off_t *pphys_base, unsigned long long *psize);
1048 
1064 int CMEM_getBlockAttrs(int blockid, CMEM_BlockAttrs *pattrs);
1065 
1081 int CMEM_getNumBlocks(int *pnblocks);
1082 
1095 int CMEM_exit(void);
1096 
1099 #if defined (__cplusplus)
1100 }
1101 #endif
1102 
1103 #endif
struct CMEM_BlockAttrs CMEM_BlockAttrs
off64_t CMEM_allocPoolPhys64(int blockid, int poolid, CMEM_AllocParams *params)
Allocate unmapped memory from a specified pool in a specified memory block (Android only)...
off64_t CMEM_getPhys64(void *ptr)
Get the physical address of a contiguous buffer (Android only).
int CMEM_freePhys(off_t physp, CMEM_AllocParams *params)
Free an unmapped buffer previously allocated with CMEM_allocPhys()/CMEM_allocPoolPhys().
CMEM_AllocParams CMEM_DEFAULTPARAMS
void * CMEM_map64(off64_t physp, size_t size)
Map allocated memory using mmap64 (Android only)
int CMEM_unmap(void *userp, size_t size)
Unmap allocated memory.
void * CMEM_registerAlloc64(off64_t physp)
Register shared usage of an already-allocated buffer using mmap64 (Android only)
int CMEM_freePhys64(off64_t physp, CMEM_AllocParams *params)
Free an unmapped buffer previously allocated with CMEM_allocPhys64()/CMEM_allocPoolPhys64() (Android ...
int CMEM_cacheWb(void *ptr, size_t size)
Do a cache writeback of the block pointed to by ptr/size.
int CMEM_free(void *ptr, CMEM_AllocParams *params)
Free a buffer previously allocated with CMEM_alloc()/CMEM_allocPool().
int CMEM_getPool(unsigned long long size)
Find the pool that best fits a given buffer size and has a buffer available.
off_t CMEM_getPhys(void *ptr)
Get the physical address of a contiguous buffer.
off_t CMEM_allocPhys(size_t size, CMEM_AllocParams *params)
Allocate unmapped memory of a specified size.
size_t alignment
Definition: cmem.h:380
void * CMEM_alloc(size_t size, CMEM_AllocParams *params)
Allocate memory of a specified size.
off64_t CMEM_allocPhys64(int blockid, size_t size, CMEM_AllocParams *params)
Allocate unmapped memory of a specified size from a specified memory block (Android only) ...
Parameters for CMEM_alloc(), CMEM_alloc2(), CMEM_allocPool(), CMEM_allocPool2(), CMEM_free().
Definition: cmem.h:377
void * CMEM_allocPool2(int blockid, int poolid, CMEM_AllocParams *params)
Allocate memory from a specified pool in a specified memory block.
off_t phys_base
Definition: cmem.h:388
unsigned long long size
Definition: cmem.h:389
struct CMEM_AllocParams CMEM_AllocParams
Parameters for CMEM_alloc(), CMEM_alloc2(), CMEM_allocPool(), CMEM_allocPool2(), CMEM_free().
void * CMEM_registerAlloc(off_t physp)
Register shared usage of an already-allocated buffer.
int CMEM_exit(void)
Finalize the CMEM module.
int CMEM_getBlock(off_t *pphys_base, unsigned long long *psize)
Retrieve memory block bounds from CMEM driver.
int CMEM_getNumBlocks(int *pnblocks)
Retrieve number of blocks configured into CMEM driver.
off_t CMEM_allocPoolPhys2(int blockid, int poolid, CMEM_AllocParams *params)
Allocate unmapped memory from a specified pool in a specified memory block.
void * CMEM_allocPool(int poolid, CMEM_AllocParams *params)
Allocate memory from a specified pool.
int type
Definition: cmem.h:378
Definition: cmem.h:387
int CMEM_getPool2(int blockid, unsigned long long size)
Find the pool in memory block blockid that best fits a given buffer size and has a buffer available...
int CMEM_cacheWbInv(void *ptr, size_t size)
Do a cache writeback/invalidate of the block pointed to by ptr/size.
int CMEM_getBlockAttrs(int blockid, CMEM_BlockAttrs *pattrs)
Retrieve extended memory block attributes from CMEM driver.
void * CMEM_alloc2(int blockid, size_t size, CMEM_AllocParams *params)
Allocate memory of a specified size from a specified memory block.
off_t CMEM_allocPhys2(int blockid, size_t size, CMEM_AllocParams *params)
Allocate unmapped memory of a specified size from a specified memory block.
int CMEM_cacheWbInvAll(void)
Do a cache writeback/invalidate of the whole cache.
int CMEM_getVersion(void)
Retrieve version from CMEM driver.
void * CMEM_map(off_t physp, size_t size)
Map allocated memory.
int flags
Definition: cmem.h:379
int CMEM_unregister(void *ptr, CMEM_AllocParams *params)
Unregister use of a buffer previously registered with CMEM_registerAlloc().
int CMEM_init(void)
Initialize the CMEM module. Must be called before other API calls.
off_t CMEM_allocPoolPhys(int poolid, CMEM_AllocParams *params)
Allocate unmapped memory from a specified pool.
int CMEM_cacheInv(void *ptr, size_t size)
Do a cache invalidate of the block pointed to by ptr/size.
Copyright 2015, Texas Instruments Incorporated