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 /*! Return the address of an allocation in memory
104 \param size[in] Size in bytes of the allocation
105 \param caller_func[in] Caller function name
106 \param caller_line[in] Caller function line number
110 #define mmgr_malloc(__size) mmgr_malloc_ex(__size, __func__, __LINE__)
111 extern hrt_vaddress mmgr_malloc_ex(
113 const char *caller_func,
116 /*! Return the address of a zero initialised allocation in memory
118 \param N[in] Horizontal dimension of array
119 \param size[in] Vertical dimension of array Total size is N*size
120 \param caller_func[in] Caller function name
121 \param caller_line[in] Caller function line number
125 #define mmgr_calloc(__N, __size) mmgr_calloc_ex(__N, __size, __func__, __LINE__)
126 extern hrt_vaddress mmgr_calloc_ex(
129 const char *caller_func,
132 /*! Free the memory allocation identified by the address
134 \param vaddr[in] Address of the allocation
135 \param caller_func[in] Caller function name
136 \param caller_line[in] Caller function line number
140 #define mmgr_free(__vaddr) mmgr_free_ex(__vaddr, __func__, __LINE__)
141 extern void mmgr_free_ex(
143 const char *caller_func,
146 /*! Return the address of an allocation in memory
148 \param size[in] Size in bytes of the allocation
149 \param attribute[in] Bit vector specifying the properties
150 of the allocation including zero initialisation
151 \param caller_func[in] Caller function name
152 \param caller_line[in] Caller function line number
156 #define mmgr_alloc_attr(__size, __attribute) mmgr_alloc_attr_ex(__size, __attribute, __func__, __LINE__)
157 extern hrt_vaddress mmgr_alloc_attr_ex(
159 const uint16_t attribute,
160 const char *caller_func,
163 /*! Return the address of a mapped existing allocation in memory
165 \param ptr[in] Pointer to an allocation in a different
166 virtual memory page table, but the same
168 \param size[in] Size of the memory of the pointer
169 \param attribute[in] Bit vector specifying the properties
171 \param context Pointer of a context provided by
172 client/driver for additonal parameters
173 needed by the implementation
175 This interface is tentative, limited to the desired function
176 the actual interface may require furhter parameters
180 extern hrt_vaddress mmgr_mmap(
186 /*! Zero initialise an allocation in memory
188 \param vaddr[in] Address of an allocation
189 \param size[in] Size in bytes of the area to be cleared
190 \param caller_func[in] Caller function name
191 \param caller_line[in] Caller function line number
195 #define mmgr_clear(__vaddr, __size) mmgr_clear_ex(__vaddr, __size, __func__, __LINE__)
196 extern void mmgr_clear_ex(
199 const char *caller_func,
202 /*! Read an array of bytes from a virtual memory address
204 \param vaddr[in] Address of an allocation
205 \param data[out] pointer to the destination array
206 \param size[in] number of bytes to read
207 \param caller_func[in] Caller function name
208 \param caller_line[in] Caller function line number
212 #define mmgr_load(__vaddr, __data, __size) mmgr_load_ex(__vaddr, __data, __size, __func__, __LINE__)
213 extern void mmgr_load_ex(
214 const hrt_vaddress vaddr,
217 const char *caller_func,
220 /*! Write an array of bytes to device registers or memory in the device
222 \param vaddr[in] Address of an allocation
223 \param data[in] pointer to the source array
224 \param size[in] number of bytes to write
225 \param caller_func[in] Caller function name
226 \param caller_line[in] Caller function line number
230 #define mmgr_store(__vaddr, __data, __size) mmgr_store_ex(__vaddr, __data, __size, __func__, __LINE__)
231 extern void mmgr_store_ex(
232 const hrt_vaddress vaddr,
235 const char *caller_func,
238 #endif /* __MEMORY_ACCESS_H_INCLUDED__ */