aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/drivers/staging/media/atomisp/pci/hive_isp_css_include/memory_access/memory_access.h
blob: dc63ff0c9c6aee00bf9249fd8e208e4cc52c0e68 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
 * Support for Intel Camera Imaging ISP subsystem.
 * Copyright (c) 2015-2017, Intel Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 */

#ifndef __MEMORY_ACCESS_H_INCLUDED__
#define __MEMORY_ACCESS_H_INCLUDED__

/*!
 * \brief
 * Define the public interface for virtual memory
 * access functions. Access types are limited to
 * those defined in <stdint.h>
 *
 * The address representation is private to the system
 * and represented as "hrt_vaddress" rather than a
 * pointer, as the memory allocation cannot be accessed
 * by dereferencing but reaquires load and store access
 * functions
 *
 * The page table selection or virtual memory context;
 * The page table base index; Is implicit. This page
 * table base index must be set by the implementation
 * of the access function
 *
 * "store" is a transfer to the system
 * "load" is a transfer from the system
 *
 * Allocation properties can be specified by setting
 * attributes (see below) in case of multiple physical
 * memories the memory ID is encoded on the attribute
 *
 * Allocations in the same physical memory, but in a
 * different (set of) page tables can be shared through
 * a page table information mapping function
 */

#include <type_support.h>
#include "platform_support.h"	/* for __func__ */

/*
 * User provided file that defines the (sub)system address types:
 *	- hrt_vaddress	a type that can hold the (sub)system virtual address range
 */
#include "system_types.h"

/*
 * The MMU base address is a physical address, thus the same type is used
 * as for the device base address
 */
#include "device_access.h"

#include "hmm/hmm.h"

/*!
 * \brief
 * Bit masks for specialised allocation functions
 * the default is "uncached", "not contiguous",
 * "not page aligned" and "not cleared"
 *
 * Forcing alignment (usually) returns a pointer
 * at an alignment boundary that is offset from
 * the allocated pointer. Without storing this
 * pointer/offset, we cannot free it. The memory
 * manager is responsible for the bookkeeping, e.g.
 * the allocation function creates a sentinel
 * within the allocation referencable from the
 * returned pointer/address.
 */
#define MMGR_ATTRIBUTE_MASK		0x000f
#define MMGR_ATTRIBUTE_CACHED		0x0001
#define MMGR_ATTRIBUTE_CONTIGUOUS	0x0002
#define MMGR_ATTRIBUTE_PAGEALIGN	0x0004
#define MMGR_ATTRIBUTE_CLEARED		0x0008
#define MMGR_ATTRIBUTE_UNUSED		0xfff0

/* #define MMGR_ATTRIBUTE_DEFAULT	(MMGR_ATTRIBUTE_CACHED) */
#define MMGR_ATTRIBUTE_DEFAULT	0

extern const hrt_vaddress	mmgr_NULL;
extern const hrt_vaddress	mmgr_EXCEPTION;

/*! Return the address of an allocation in memory

 \param	size[in]		Size in bytes of the allocation
 \param	caller_func[in]		Caller function name
 \param	caller_line[in]		Caller function line number

 \return vaddress
 */
hrt_vaddress mmgr_malloc(const size_t size);

/*! Return the address of a zero initialised allocation in memory

 \param	N[in]			Horizontal dimension of array
 \param	size[in]		Vertical dimension of array  Total size is N*size

 \return vaddress
 */
hrt_vaddress mmgr_calloc(const size_t N, const size_t size);

/*! Return the address of an allocation in memory

 \param	size[in]		Size in bytes of the allocation
 \param	attribute[in]		Bit vector specifying the properties
				of the allocation including zero initialisation

 \return vaddress
 */

hrt_vaddress mmgr_alloc_attr(const size_t size, const uint16_t attribute);

/*! Return the address of a mapped existing allocation in memory

 \param	ptr[in]			Pointer to an allocation in a different
				virtual memory page table, but the same
				physical memory
 \param size[in]		Size of the memory of the pointer
 \param	attribute[in]		Bit vector specifying the properties
				of the allocation
 \param context			Pointer of a context provided by
				client/driver for additional parameters
				needed by the implementation
 \Note
	This interface is tentative, limited to the desired function
	the actual interface may require furhter parameters

 \return vaddress
 */
hrt_vaddress mmgr_mmap(
    const void __user *ptr,
    const size_t size,
    u16 attribute,
    void *context);

/*! Zero initialise an allocation in memory

 \param	vaddr[in]		Address of an allocation
 \param	size[in]		Size in bytes of the area to be cleared

 \return none
 */
void mmgr_clear(hrt_vaddress vaddr, const size_t	size);

/*! Read an array of bytes from a virtual memory address

 \param	vaddr[in]		Address of an allocation
 \param	data[out]		pointer to the destination array
 \param	size[in]		number of bytes to read

 \return none
 */
void mmgr_load(const hrt_vaddress vaddr, void *data, const size_t size);

/*! Write an array of bytes to device registers or memory in the device

 \param	vaddr[in]		Address of an allocation
 \param	data[in]		pointer to the source array
 \param	size[in]		number of bytes to write

 \return none
 */
void mmgr_store(const hrt_vaddress vaddr, const void *data, const size_t size);

#endif /* __MEMORY_ACCESS_H_INCLUDED__ */