2 * Support for Intel Camera Imaging ISP subsystem.
3 * Copyright (c) 2015, Intel Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 #ifndef __MEMORY_ACCESS_H_INCLUDED__
16 #define __MEMORY_ACCESS_H_INCLUDED__
20 * Define the public interface for virtual memory
21 * access functions. Access types are limited to
22 * those defined in <stdint.h>
24 * The address representation is private to the system
25 * and represented as "hrt_vaddress" rather than a
26 * pointer, as the memory allocation cannot be accessed
27 * by dereferencing but reaquires load and store access
30 * The page table selection or virtual memory context;
31 * The page table base index; Is implicit. This page
32 * table base index must be set by the implementation
33 * of the access function
35 * "store" is a transfer to the system
36 * "load" is a transfer from the system
38 * Allocation properties can be specified by setting
39 * attributes (see below) in case of multiple physical
40 * memories the memory ID is encoded on the attribute
42 * Allocations in the same physical memory, but in a
43 * different (set of) page tables can be shared through
44 * a page table information mapping function
47 #include <type_support.h>
48 #include "platform_support.h" /* for __func__ */
51 * User provided file that defines the (sub)system address types:
52 * - hrt_vaddress a type that can hold the (sub)system virtual address range
54 #include "system_types.h"
57 * The MMU base address is a physical address, thus the same type is used
58 * as for the device base address
60 #include "device_access.h"
64 * Bit masks for specialised allocation functions
65 * the default is "uncached", "not contiguous",
66 * "not page aligned" and "not cleared"
68 * Forcing alignment (usually) returns a pointer
69 * at an alignment boundary that is offset from
70 * the allocated pointer. Without storing this
71 * pointer/offset, we cannot free it. The memory
72 * manager is responsible for the bookkeeping, e.g.
73 * the allocation function creates a sentinel
74 * within the allocation referencable from the
75 * returned pointer/address.
77 #define MMGR_ATTRIBUTE_MASK 0x000f
78 #define MMGR_ATTRIBUTE_CACHED 0x0001
79 #define MMGR_ATTRIBUTE_CONTIGUOUS 0x0002
80 #define MMGR_ATTRIBUTE_PAGEALIGN 0x0004
81 #define MMGR_ATTRIBUTE_CLEARED 0x0008
82 #define MMGR_ATTRIBUTE_UNUSED 0xfff0
84 /* #define MMGR_ATTRIBUTE_DEFAULT (MMGR_ATTRIBUTE_CACHED) */
85 #define MMGR_ATTRIBUTE_DEFAULT 0
87 extern const hrt_vaddress mmgr_NULL;
88 extern const hrt_vaddress mmgr_EXCEPTION;
90 /*! Set the (sub)system virtual memory page table base address
92 \param base_addr[in] The address where page table 0 is located
94 \Note: The base_addr is an absolute system address, thus it is not
95 relative to the DDR base address
99 extern void mmgr_set_base_address(
100 const sys_address base_addr);
102 /*! Get the (sub)system virtual memory page table base address
104 \return base_address,
107 extern sys_address mmgr_get_base_address(void);
110 /*! Set the (sub)system virtual memory page table base index
112 \param base_addr[in] The index where page table 0 is located
114 \Note: The base_index is the MSB section of an absolute system address,
115 the in-page address bits are discared. The base address is not
116 relative to the DDR base address
121 extern void mmgr_set_base_index(
122 const hrt_data base_index);
124 /*! Get the (sub)system virtual memory page table base index
126 \return base_address,
129 extern hrt_data mmgr_get_base_index(void);
131 /*! Return the address of an allocation in memory
133 \param size[in] Size in bytes of the allocation
134 \param caller_func[in] Caller function name
135 \param caller_line[in] Caller function line number
139 #define mmgr_malloc(__size) mmgr_malloc_ex(__size, __func__, __LINE__)
140 extern hrt_vaddress mmgr_malloc_ex(
142 const char *caller_func,
145 /*! Return the address of a zero initialised allocation in memory
147 \param N[in] Horizontal dimension of array
148 \param size[in] Vertical dimension of array Total size is N*size
149 \param caller_func[in] Caller function name
150 \param caller_line[in] Caller function line number
154 #define mmgr_calloc(__N, __size) mmgr_calloc_ex(__N, __size, __func__, __LINE__)
155 extern hrt_vaddress mmgr_calloc_ex(
158 const char *caller_func,
161 /*! Return the address of a reallocated allocation in memory
163 \param vaddr[in] Address of an allocation
164 \param size[in] Size in bytes of the allocation
167 All limitations and particularities of the C stdlib
168 realloc function apply
173 extern hrt_vaddress mmgr_realloc(
177 /*! Free the memory allocation identified by the address
179 \param vaddr[in] Address of the allocation
180 \param caller_func[in] Caller function name
181 \param caller_line[in] Caller function line number
185 #define mmgr_free(__vaddr) mmgr_free_ex(__vaddr, __func__, __LINE__)
186 extern void mmgr_free_ex(
188 const char *caller_func,
191 /*! Return the address of an allocation in memory
193 \param size[in] Size in bytes of the allocation
194 \param attribute[in] Bit vector specifying the properties
195 of the allocation including zero initialisation
196 \param caller_func[in] Caller function name
197 \param caller_line[in] Caller function line number
201 #define mmgr_alloc_attr(__size, __attribute) mmgr_alloc_attr_ex(__size, __attribute, __func__, __LINE__)
202 extern hrt_vaddress mmgr_alloc_attr_ex(
204 const uint16_t attribute,
205 const char *caller_func,
208 /*! Return the address of a reallocated allocation in memory
210 \param vaddr[in] Address of an allocation
211 \param size[in] Size in bytes of the allocation
212 \param attribute[in] Bit vector specifying the properties
217 All limitations and particularities of the C stdlib
218 realloc function apply
223 extern hrt_vaddress mmgr_realloc_attr(
226 const uint16_t attribute);
228 /*! Return the address of a mapped existing allocation in memory
230 \param ptr[in] Pointer to an allocation in a different
231 virtual memory page table, but the same
233 \param size[in] Size of the memory of the pointer
234 \param attribute[in] Bit vector specifying the properties
236 \param context Pointer of a context provided by
237 client/driver for additonal parameters
238 needed by the implementation
240 This interface is tentative, limited to the desired function
241 the actual interface may require furhter parameters
245 extern hrt_vaddress mmgr_mmap(
251 /*! Zero initialise an allocation in memory
253 \param vaddr[in] Address of an allocation
254 \param size[in] Size in bytes of the area to be cleared
255 \param caller_func[in] Caller function name
256 \param caller_line[in] Caller function line number
260 #define mmgr_clear(__vaddr, __size) mmgr_clear_ex(__vaddr, __size, __func__, __LINE__)
261 extern void mmgr_clear_ex(
264 const char *caller_func,
267 /*! Set an allocation in memory to a value
269 \param vaddr[in] Address of an allocation
270 \param data[in] Value to set
271 \param size[in] Size in bytes of the area to be set
276 extern void mmgr_set(
281 /*! Read an array of bytes from a virtual memory address
283 \param vaddr[in] Address of an allocation
284 \param data[out] pointer to the destination array
285 \param size[in] number of bytes to read
286 \param caller_func[in] Caller function name
287 \param caller_line[in] Caller function line number
291 #define mmgr_load(__vaddr, __data, __size) mmgr_load_ex(__vaddr, __data, __size, __func__, __LINE__)
292 extern void mmgr_load_ex(
293 const hrt_vaddress vaddr,
296 const char *caller_func,
299 /*! Write an array of bytes to device registers or memory in the device
301 \param vaddr[in] Address of an allocation
302 \param data[in] pointer to the source array
303 \param size[in] number of bytes to write
304 \param caller_func[in] Caller function name
305 \param caller_line[in] Caller function line number
309 #define mmgr_store(__vaddr, __data, __size) mmgr_store_ex(__vaddr, __data, __size, __func__, __LINE__)
310 extern void mmgr_store_ex(
311 const hrt_vaddress vaddr,
314 const char *caller_func,
317 #endif /* __MEMORY_ACCESS_H_INCLUDED__ */