Linux-libre 4.15.7-gnu
[librecmc/linux-libre.git] / drivers / staging / media / atomisp / pci / atomisp2 / css2400 / hive_isp_css_include / memory_access / memory_access.h
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 #include "hmm/hmm.h"
63
64 /*!
65  * \brief
66  * Bit masks for specialised allocation functions
67  * the default is "uncached", "not contiguous",
68  * "not page aligned" and "not cleared"
69  *
70  * Forcing alignment (usually) returns a pointer
71  * at an alignment boundary that is offset from
72  * the allocated pointer. Without storing this
73  * pointer/offset, we cannot free it. The memory
74  * manager is responsible for the bookkeeping, e.g.
75  * the allocation function creates a sentinel
76  * within the allocation referencable from the
77  * returned pointer/address.
78  */
79 #define MMGR_ATTRIBUTE_MASK             0x000f
80 #define MMGR_ATTRIBUTE_CACHED           0x0001
81 #define MMGR_ATTRIBUTE_CONTIGUOUS       0x0002
82 #define MMGR_ATTRIBUTE_PAGEALIGN        0x0004
83 #define MMGR_ATTRIBUTE_CLEARED          0x0008
84 #define MMGR_ATTRIBUTE_UNUSED           0xfff0
85
86 /* #define MMGR_ATTRIBUTE_DEFAULT       (MMGR_ATTRIBUTE_CACHED) */
87 #define MMGR_ATTRIBUTE_DEFAULT  0
88
89 extern const hrt_vaddress       mmgr_NULL;
90 extern const hrt_vaddress       mmgr_EXCEPTION;
91
92 /*! Return the address of an allocation in memory
93
94  \param size[in]                Size in bytes of the allocation
95  \param caller_func[in]         Caller function name
96  \param caller_line[in]         Caller function line number
97
98  \return vaddress
99  */
100 extern hrt_vaddress mmgr_malloc(const size_t size);
101
102 /*! Return the address of a zero initialised allocation in memory
103
104  \param N[in]                   Horizontal dimension of array
105  \param size[in]                Vertical dimension of array  Total size is N*size
106
107  \return vaddress
108  */
109 extern hrt_vaddress mmgr_calloc(const size_t N, const size_t size);
110
111 /*! Return the address of an allocation in memory
112
113  \param size[in]                Size in bytes of the allocation
114  \param attribute[in]           Bit vector specifying the properties
115                                 of the allocation including zero initialisation
116
117  \return vaddress
118  */
119
120 extern hrt_vaddress mmgr_alloc_attr(const size_t size, const uint16_t attribute);
121
122 /*! Return the address of a mapped existing allocation in memory
123
124  \param ptr[in]                 Pointer to an allocation in a different
125                                 virtual memory page table, but the same
126                                 physical memory
127  \param size[in]                Size of the memory of the pointer
128  \param attribute[in]           Bit vector specifying the properties
129                                 of the allocation
130  \param context                 Pointer of a context provided by
131                                 client/driver for additonal parameters
132                                 needed by the implementation
133  \Note
134         This interface is tentative, limited to the desired function
135         the actual interface may require furhter parameters
136
137  \return vaddress
138  */
139 extern hrt_vaddress mmgr_mmap(
140         const void *ptr,
141         const size_t size,
142         uint16_t attribute,
143         void *context);
144
145 /*! Zero initialise an allocation in memory
146
147  \param vaddr[in]               Address of an allocation
148  \param size[in]                Size in bytes of the area to be cleared
149
150  \return none
151  */
152 extern void mmgr_clear(hrt_vaddress vaddr, const size_t size);
153
154 /*! Read an array of bytes from a virtual memory address
155
156  \param vaddr[in]               Address of an allocation
157  \param data[out]               pointer to the destination array
158  \param size[in]                number of bytes to read
159
160  \return none
161  */
162 extern void mmgr_load(const hrt_vaddress vaddr, void *data, const size_t size);
163
164 /*! Write an array of bytes to device registers or memory in the device
165
166  \param vaddr[in]               Address of an allocation
167  \param data[in]                pointer to the source array
168  \param size[in]                number of bytes to write
169
170  \return none
171  */
172 extern void mmgr_store(const hrt_vaddress vaddr, const void *data, const size_t size);
173
174 #endif /* __MEMORY_ACCESS_H_INCLUDED__ */