]> www.infradead.org Git - users/jedix/linux-maple.git/blob
e78d4626a0034dd61e256b6ae78f09764e2573e5
[users/jedix/linux-maple.git] /
1 /*
2  * Support for Intel Camera Imaging ISP subsystem.
3  * Copyright (c) 2015, 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 /*! Set the (sub)system virtual memory page table base address
91
92  \param base_addr[in]           The address where page table 0 is located
93
94  \Note: The base_addr is an absolute system address, thus it is not
95         relative to the DDR base address
96
97  \return none,
98  */
99 extern void mmgr_set_base_address(
100         const sys_address               base_addr);
101
102 /*! Return the address of an allocation in memory
103
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
107
108  \return vaddress
109  */
110 #define mmgr_malloc(__size) mmgr_malloc_ex(__size, __func__, __LINE__)
111 extern hrt_vaddress mmgr_malloc_ex(
112         const size_t                    size,
113         const char                              *caller_func,
114         int                                             caller_line);
115
116 /*! Return the address of a zero initialised allocation in memory
117
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
122
123  \return vaddress
124  */
125 #define mmgr_calloc(__N, __size) mmgr_calloc_ex(__N, __size, __func__, __LINE__)
126 extern hrt_vaddress mmgr_calloc_ex(
127         const size_t                    N,
128         const size_t                    size,
129         const char                              *caller_func,
130         int                                             caller_line);
131
132 /*! Free the memory allocation identified by the address
133
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
137
138  \return vaddress
139  */
140 #define mmgr_free(__vaddr) mmgr_free_ex(__vaddr, __func__, __LINE__)
141 extern void mmgr_free_ex(
142         hrt_vaddress                    vaddr,
143         const char                              *caller_func,
144         int                                             caller_line);
145
146 /*! Return the address of an allocation in memory
147
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
153
154  \return vaddress
155  */
156 #define mmgr_alloc_attr(__size, __attribute) mmgr_alloc_attr_ex(__size, __attribute, __func__, __LINE__)
157 extern hrt_vaddress mmgr_alloc_attr_ex(
158         const size_t                    size,
159         const uint16_t                  attribute,
160         const char                              *caller_func,
161         int                                             caller_line);
162
163 /*! Return the address of a mapped existing allocation in memory
164
165  \param ptr[in]                 Pointer to an allocation in a different
166                                 virtual memory page table, but the same
167                                 physical memory
168  \param size[in]                Size of the memory of the pointer
169  \param attribute[in]           Bit vector specifying the properties
170                                 of the allocation
171  \param context                 Pointer of a context provided by
172                                 client/driver for additonal parameters
173                                 needed by the implementation
174  \Note
175         This interface is tentative, limited to the desired function
176         the actual interface may require furhter parameters
177
178  \return vaddress
179  */
180 extern hrt_vaddress mmgr_mmap(
181         const void *ptr,
182         const size_t size,
183         uint16_t attribute,
184         void *context);
185
186 /*! Zero initialise an allocation in memory
187
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
192
193  \return none
194  */
195 #define mmgr_clear(__vaddr, __size) mmgr_clear_ex(__vaddr, __size, __func__, __LINE__)
196 extern void mmgr_clear_ex(
197         hrt_vaddress                    vaddr,
198         const size_t                    size,
199         const char                      *caller_func,
200         int                             caller_line);
201
202 /*! Read an array of bytes from a virtual memory address
203
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
209
210  \return none
211  */
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,
215         void                            *data,
216         const size_t                    size,
217         const char                      *caller_func,
218         int                             caller_line);
219
220 /*! Write an array of bytes to device registers or memory in the device
221
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
227
228  \return none
229  */
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,
233         const void                              *data,
234         const size_t                    size,
235         const char                              *caller_func,
236         int                                             caller_line);
237
238 #endif /* __MEMORY_ACCESS_H_INCLUDED__ */