2 * Support for Intel Camera Imaging ISP subsystem.
3 * Copyright (c) 2015-2017, 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 /*! Return the address of an allocation in memory
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
98 extern hrt_vaddress mmgr_malloc(const size_t size);
100 /*! Return the address of a zero initialised allocation in memory
102 \param N[in] Horizontal dimension of array
103 \param size[in] Vertical dimension of array Total size is N*size
107 extern hrt_vaddress mmgr_calloc(const size_t N, const size_t size);
109 /*! Free the memory allocation identified by the address
111 \param vaddr[in] Address of the allocation
115 extern void mmgr_free(hrt_vaddress vaddr);
117 /*! Return the address of an allocation in memory
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
126 extern hrt_vaddress mmgr_alloc_attr(const size_t size, const uint16_t attribute);
128 /*! Return the address of a mapped existing allocation in memory
130 \param ptr[in] Pointer to an allocation in a different
131 virtual memory page table, but the same
133 \param size[in] Size of the memory of the pointer
134 \param attribute[in] Bit vector specifying the properties
136 \param context Pointer of a context provided by
137 client/driver for additonal parameters
138 needed by the implementation
140 This interface is tentative, limited to the desired function
141 the actual interface may require furhter parameters
145 extern hrt_vaddress mmgr_mmap(
151 /*! Zero initialise an allocation in memory
153 \param vaddr[in] Address of an allocation
154 \param size[in] Size in bytes of the area to be cleared
158 extern void mmgr_clear(hrt_vaddress vaddr, const size_t size);
160 /*! Read an array of bytes from a virtual memory address
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
168 extern void mmgr_load(const hrt_vaddress vaddr, void *data, const size_t size);
170 /*! Write an array of bytes to device registers or memory in the device
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
178 extern void mmgr_store(const hrt_vaddress vaddr, const void *data, const size_t size);
180 #endif /* __MEMORY_ACCESS_H_INCLUDED__ */