Developer World
Spresense SDK Library v3.2.0-ebc0364
tile.h
1/****************************************************************************
2 * modules/include/mm/tile.h
3 *
4 * Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved.
5 * Author: Gregory Nutt <gnutt@nuttx.org>
6 * Copyright 2018 Sony Semiconductor Solutions Corporation
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 * 3. Neither the name NuttX nor the names of its contributors may be
19 * used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 *
35 ****************************************************************************/
36
37#ifndef __INCLUDE_MM_TILE_H
38#define __INCLUDE_MM_TILE_H
39
40/****************************************************************************
41 * Included Files
42 ****************************************************************************/
43
44#include <sdk/config.h>
45
46#include <sys/types.h>
47#include <stdint.h>
48
49#ifdef CONFIG_MM_TILE
50
51/****************************************************************************
52 * Pre-processor Definitions
53 ****************************************************************************/
54/* Configuration ************************************************************/
55/* CONFIG_MM_TILE - Enable tile allocator support
56 * CONFIG_DEBUG_TILE - Just like CONFIG_DEBUG_MM, but only generates output
57 * from the tile allocation logic.
58 */
59
60/****************************************************************************
61 * Public Types
62 ****************************************************************************/
63
64/****************************************************************************
65 * Public Function Prototypes
66 ****************************************************************************/
67
68#ifdef __cplusplus
69#define EXTERN extern "C"
70extern "C"
71{
72#else
73#define EXTERN extern
74#endif
75
76/****************************************************************************
77 * Name: tile_initialize
78 *
79 * Description:
80 * Set up one tile allocator instance. Allocations will be aligned to
81 * the tile block (128KiB). Larger tiles will give better performance
82 * and less overhead but more losses of memory due to quantization waste.
83 * Additional memory waste can occur from alignment.
84 *
85 * The actual memory allocates will be 64 byte (wasting 17 bytes) and
86 * will be aligned at least to (1 << log2align).
87 *
88 * NOTE: The current implementation also restricts the maximum allocation
89 * size to 32 tiles.
90 *
91 * Input Parameters:
92 * heapstart - Start of the tile allocation heap
93 * heapsize - Size of heap in bytes
94 * log2tile - Log base 2 of the size of one tile. 0->1 byte,
95 * 1->2 bytes, 2->4 bytes, 3->8 bytes, etc.
96 *
97 * Returned Value:
98 * On success, a non-NULL handle is returned that may be used with other
99 * tile allocator interfaces.
100 *
101 ****************************************************************************/
102
103int tile_initialize(FAR void *heapstart, size_t heapsize, uint8_t log2tile);
104
105/****************************************************************************
106 * Name: tile_release
107 *
108 * Description:
109 * Uninitialize a tile memory allocator and release resources held by the
110 * allocator.
111 *
112 * Input Parameters:
113 * handle - The handle previously returned by tile_initialize
114 *
115 * Returned Value:
116 * None.
117 *
118 ****************************************************************************/
119
120void tile_release(void);
121
122/****************************************************************************
123 * Name: tile_alloc
124 *
125 * Description:
126 * Allocate memory from the tile heap.
127 *
128 * Input Parameters:
129 * size - The size of the memory region to allocate.
130 *
131 * Returned Value:
132 * On success, either a non-NULL pointer to the allocated memory or zero
133 * is returned.
134 *
135 ****************************************************************************/
136
137FAR void *tile_alloc(size_t size);
138
139/****************************************************************************
140 * Name: tile_alignalloc
141 *
142 * Description:
143 * Allocate aligned memory from the tile heap.
144 *
145 * Input Parameters:
146 * size - The size of the memory region to allocate.
147 * log2align - Log base 2 of the alignment
148 *
149 * Returned Value:
150 * On success, either a non-NULL pointer to the allocated memory or zero
151 * is returned.
152 *
153 ****************************************************************************/
154
155FAR void *tile_alignalloc(size_t size, uint32_t log2align);
156
157 /****************************************************************************
158 * Name: tile_free
159 *
160 * Description:
161 * Return memory to the tile heap.
162 *
163 * Input Parameters:
164 * handle - The handle previously returned by tile_initialize
165 * memory - A pointer to memory previously allocated by tile_alloc.
166 *
167 * Returned Value:
168 * None
169 *
170 ****************************************************************************/
171
172void tile_free(FAR void *memory, size_t size);
173
174#undef EXTERN
175#ifdef __cplusplus
176}
177#endif
178
179#endif /* CONFIG_MM_TILE */
180#endif /* __INCLUDE_MM_TILE_H */