54ab3d948d3eb9f34594ee0acd21067ce62f42bb
[GitHub/moto-9609/android_kernel_motorola_exynos9610.git] /
1 /*
2 * Support for Intel Camera Imaging ISP subsystem.
3 * Copyright (c) 2015-2017, Intel Corporation.
4 *
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.
8 *
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
12 * more details.
13 */
14
15 #ifndef __MEMORY_ACCESS_H_INCLUDED__
16 #define __MEMORY_ACCESS_H_INCLUDED__
17
18 /*!
19 * \brief
20 * Define the public interface for virtual memory
21 * access functions. Access types are limited to
22 * those defined in <stdint.h>
23 *
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
28 * functions
29 *
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
34 *
35 * "store" is a transfer to the system
36 * "load" is a transfer from the system
37 *
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
41 *
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
45 */
46
47 #include <type_support.h>
48 #include "platform_support.h" /* for __func__ */
49
50 /*
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
53 */
54 #include "system_types.h"
55
56 /*
57 * The MMU base address is a physical address, thus the same type is used
58 * as for the device base address
59 */
60 #include "device_access.h"
61
62 /*!
63 * \brief
64 * Bit masks for specialised allocation functions
65 * the default is "uncached", "not contiguous",
66 * "not page aligned" and "not cleared"
67 *
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.
76 */
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
83
84 /* #define MMGR_ATTRIBUTE_DEFAULT (MMGR_ATTRIBUTE_CACHED) */
85 #define MMGR_ATTRIBUTE_DEFAULT 0
86
87 extern const hrt_vaddress mmgr_NULL;
88 extern const hrt_vaddress mmgr_EXCEPTION;
89
90 /*! Return the address of an allocation in memory
91
92 \param size[in] Size in bytes of the allocation
93 \param caller_func[in] Caller function name
94 \param caller_line[in] Caller function line number
95
96 \return vaddress
97 */
98 extern hrt_vaddress mmgr_malloc(const size_t size);
99
100 /*! Return the address of a zero initialised allocation in memory
101
102 \param N[in] Horizontal dimension of array
103 \param size[in] Vertical dimension of array Total size is N*size
104
105 \return vaddress
106 */
107 extern hrt_vaddress mmgr_calloc(const size_t N, const size_t size);
108
109 /*! Free the memory allocation identified by the address
110
111 \param vaddr[in] Address of the allocation
112
113 \return vaddress
114 */
115 extern void mmgr_free(hrt_vaddress vaddr);
116
117 /*! Return the address of an allocation in memory
118
119 \param size[in] Size in bytes of the allocation
120 \param attribute[in] Bit vector specifying the properties
121 of the allocation including zero initialisation
122
123 \return vaddress
124 */
125
126 extern hrt_vaddress mmgr_alloc_attr(const size_t size, const uint16_t attribute);
127
128 /*! Return the address of a mapped existing allocation in memory
129
130 \param ptr[in] Pointer to an allocation in a different
131 virtual memory page table, but the same
132 physical memory
133 \param size[in] Size of the memory of the pointer
134 \param attribute[in] Bit vector specifying the properties
135 of the allocation
136 \param context Pointer of a context provided by
137 client/driver for additonal parameters
138 needed by the implementation
139 \Note
140 This interface is tentative, limited to the desired function
141 the actual interface may require furhter parameters
142
143 \return vaddress
144 */
145 extern hrt_vaddress mmgr_mmap(
146 const void *ptr,
147 const size_t size,
148 uint16_t attribute,
149 void *context);
150
151 /*! Zero initialise an allocation in memory
152
153 \param vaddr[in] Address of an allocation
154 \param size[in] Size in bytes of the area to be cleared
155
156 \return none
157 */
158 extern void mmgr_clear(hrt_vaddress vaddr, const size_t size);
159
160 /*! Read an array of bytes from a virtual memory address
161
162 \param vaddr[in] Address of an allocation
163 \param data[out] pointer to the destination array
164 \param size[in] number of bytes to read
165
166 \return none
167 */
168 extern void mmgr_load(const hrt_vaddress vaddr, void *data, const size_t size);
169
170 /*! Write an array of bytes to device registers or memory in the device
171
172 \param vaddr[in] Address of an allocation
173 \param data[in] pointer to the source array
174 \param size[in] number of bytes to write
175
176 \return none
177 */
178 extern void mmgr_store(const hrt_vaddress vaddr, const void *data, const size_t size);
179
180 #endif /* __MEMORY_ACCESS_H_INCLUDED__ */