]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/open-amp.git/blob - lib/include/openamp/sh_mem.h
09d7becd070a610b4ddbd811dc4244f38ec194c3
[processor-sdk/open-amp.git] / lib / include / openamp / sh_mem.h
1 /*
2  * Copyright (c) 2014, Mentor Graphics Corporation
3  * All rights reserved.
4  * Copyright (c) 2016 NXP Semiconductor, Inc. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright notice,
10  *    this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  *    this list of conditions and the following disclaimer in the documentation
13  *    and/or other materials provided with the distribution.
14  * 3. Neither the name of Mentor Graphics Corporation nor the names of its
15  *    contributors may be used to endorse or promote products derived from this
16  *    software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
31 /**************************************************************************
32  * FILE NAME
33  *
34  *       sh_mem.c
35  *
36  * COMPONENT
37  *
38  *         IPC Stack for uAMP systems.
39  *
40  * DESCRIPTION
41  *
42  *       Header file for fixed buffer size memory management service. Currently
43  *       it is being used to manage shared memory.
44  *
45  **************************************************************************/
46 #ifndef SH_MEM_H_
47 #define SH_MEM_H_
49 #include "openamp/env.h"
51 /* Macros */
52 #define BITMAP_WORD_SIZE         32
53 #define WORD_SIZE                sizeof(unsigned long)
54 #define WORD_ALIGN(a)            (((a) & (WORD_SIZE-1)) != 0)? \
55                                  (((a) & (~(WORD_SIZE-1))) + 4):(a)
56 #define SH_MEM_POOL_LOCATE_BITMAP(pool,idx) ((unsigned char *) pool \
57                                              + sizeof(struct sh_mem_pool) \
58                                              + (BITMAP_WORD_SIZE * idx))
60 /*
61  * This structure represents a  shared memory pool.
62  *
63  * @start_addr      - start address of shared memory region
64  * @lock            - lock to ensure exclusive access
65  * @size            - size of shared memory*
66  * @buff_size       - size of each buffer
67  * @total_buffs     - total number of buffers in shared memory region
68  * @used_buffs      - number of used buffers
69  * @bmp_size        - size of bitmap array
70  *
71  */
73 struct sh_mem_pool {
74         void *start_addr;
75         LOCK *lock;
76         int size;
77         int buff_size;
78         int total_buffs;
79         int used_buffs;
80         int bmp_size;
81 };
83 /* APIs */
84 struct sh_mem_pool *sh_mem_create_pool(void *start_addr, unsigned int size,
85                                        unsigned int buff_size);
86 void sh_mem_delete_pool(struct sh_mem_pool *pool);
87 void *sh_mem_get_buffer(struct sh_mem_pool *pool);
88 void sh_mem_free_buffer(void *ptr, struct sh_mem_pool *pool);
89 unsigned int get_first_zero_bit(unsigned long value);
91 #endif                          /* SH_MEM_H_ */