]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/media/atomisp/pci/atomisp2/css2400/ia_css_env.h
staging/atomisp: Add support for the Intel IPU v2
[karo-tx-linux.git] / drivers / staging / media / atomisp / pci / atomisp2 / css2400 / ia_css_env.h
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 __IA_CSS_ENV_H
16 #define __IA_CSS_ENV_H
17
18 #include <type_support.h>
19 #include <stdarg.h> /* va_list */
20 #include "ia_css_types.h"
21 #include "ia_css_acc_types.h"
22
23 /** @file
24  * This file contains prototypes for functions that need to be provided to the
25  * CSS-API host-code by the environment in which the CSS-API code runs.
26  */
27
28 /** Memory allocation attributes, for use in ia_css_css_mem_env. */
29 enum ia_css_mem_attr {
30         IA_CSS_MEM_ATTR_CACHED = 1 << 0,
31         IA_CSS_MEM_ATTR_ZEROED = 1 << 1,
32         IA_CSS_MEM_ATTR_PAGEALIGN = 1 << 2,
33         IA_CSS_MEM_ATTR_CONTIGUOUS = 1 << 3,
34 };
35
36 /** Environment with function pointers for local IA memory allocation.
37  *  This provides the CSS code with environment specific functionality
38  *  for memory allocation of small local buffers such as local data structures.
39  *  This is never expected to allocate more than one page of memory (4K bytes).
40  */
41 struct ia_css_cpu_mem_env {
42         void * (*alloc)(size_t bytes, bool zero_mem);
43         /**< Allocation function with boolean argument to indicate whether
44              the allocated memory should be zeroed out or not, true (or 1)
45              meaning the memory given to CSS must be zeroed */
46         void (*free)(void *ptr);
47         /**< Corresponding free function. The function must also accept
48              a NULL argument, similar to C89 free(). */
49         void (*flush)(struct ia_css_acc_fw *fw);
50         /**< Flush function to flush the cache for given accelerator. */
51 #ifdef ISP2401
52
53         #if !defined(__SVOS__)
54         /* a set of matching functions with additional debug params */
55         void * (*alloc_ex)(size_t bytes, bool zero_mem, const char *caller_func, int caller_line);
56         /**< same as alloc above, only with additional debug parameters */
57         void (*free_ex)(void *ptr, const char *caller_func, int caller_line);
58         /**< same as free above, only with additional debug parameters */
59         #endif
60 #endif
61 };
62
63 /** Environment with function pointers for allocation of memory for the CSS.
64  *  The CSS uses its own MMU which has its own set of page tables. These
65  *  functions are expected to use and/or update those page tables.
66  *  This type of memory allocation is expected to be used for large buffers
67  *  for images and statistics.
68  *  ISP pointers are always 32 bits whereas IA pointer widths will depend
69  *  on the platform.
70  *  Attributes can be a combination (OR'ed) of ia_css_mem_attr values.
71  */
72 struct ia_css_css_mem_env {
73         ia_css_ptr(*alloc)(size_t bytes, uint32_t attributes);
74         /**< Allocate memory, cached or uncached, zeroed out or not. */
75         void (*free)(ia_css_ptr ptr);
76         /**< Free ISP shared memory. The function must also accept
77              a NULL argument, similar to C89 free(). */
78         int (*load)(ia_css_ptr ptr, void *data, size_t bytes);
79         /**< Load from ISP shared memory. This function is necessary because
80              the IA MMU does not share page tables with the ISP MMU. This means
81              that the IA needs to do the virtual-to-physical address
82              translation in software. This function performs this translation.*/
83         int (*store)(ia_css_ptr ptr, const void *data, size_t bytes);
84         /**< Same as the above load function but then to write data into ISP
85              shared memory. */
86         int (*set)(ia_css_ptr ptr, int c, size_t bytes);
87         /**< Set an ISP shared memory region to a particular value. Each byte
88              in this region will be set to this value. In most cases this is
89              used to zero-out memory sections in which case the argument c
90              would have the value zero. */
91         ia_css_ptr (*mmap)(const void *ptr, const size_t size,
92                            uint16_t attribute, void *context);
93         /**< Map an pre-allocated memory region to an address. */
94 #ifdef ISP2401
95
96         /* a set of matching functions with additional debug params */
97         ia_css_ptr(*alloc_ex)(size_t bytes, uint32_t attributes, const char *caller_func, int caller_line);
98         /**< same as alloc above, only with additional debug parameters */
99         void (*free_ex)(ia_css_ptr ptr, const char *caller_func, int caller_line);
100         /**< same as free above, only with additional debug parameters */
101         int (*load_ex)(ia_css_ptr ptr, void *data, size_t bytes, const char *caller_func, int caller_line);
102         /**< same as load above, only with additional debug parameters */
103         int (*store_ex)(ia_css_ptr ptr, const void *data, size_t bytes, const char *caller_func, int caller_line);
104         /**< same as store above, only with additional debug parameters */
105         int (*set_ex)(ia_css_ptr ptr, int c, size_t bytes, const char *caller_func, int caller_line);
106         /**< same as set above, only with additional debug parameters */
107 #endif
108 };
109
110 /** Environment with function pointers to access the CSS hardware. This includes
111  *  registers and local memories.
112  */
113 struct ia_css_hw_access_env {
114         void (*store_8)(hrt_address addr, uint8_t data);
115         /**< Store an 8 bit value into an address in the CSS HW address space.
116              The address must be an 8 bit aligned address. */
117         void (*store_16)(hrt_address addr, uint16_t data);
118         /**< Store a 16 bit value into an address in the CSS HW address space.
119              The address must be a 16 bit aligned address. */
120         void (*store_32)(hrt_address addr, uint32_t data);
121         /**< Store a 32 bit value into an address in the CSS HW address space.
122              The address must be a 32 bit aligned address. */
123         uint8_t (*load_8)(hrt_address addr);
124         /**< Load an 8 bit value from an address in the CSS HW address
125              space. The address must be an 8 bit aligned address. */
126         uint16_t (*load_16)(hrt_address addr);
127         /**< Load a 16 bit value from an address in the CSS HW address
128              space. The address must be a 16 bit aligned address. */
129         uint32_t (*load_32)(hrt_address addr);
130         /**< Load a 32 bit value from an address in the CSS HW address
131              space. The address must be a 32 bit aligned address. */
132         void (*store)(hrt_address addr, const void *data, uint32_t bytes);
133         /**< Store a number of bytes into a byte-aligned address in the CSS HW address space. */
134         void (*load)(hrt_address addr, void *data, uint32_t bytes);
135         /**< Load a number of bytes from a byte-aligned address in the CSS HW address space. */
136 };
137
138 /** Environment with function pointers to print error and debug messages.
139  */
140 struct ia_css_print_env {
141         int (*debug_print)(const char *fmt, va_list args);
142         /**< Print a debug message. */
143         int (*error_print)(const char *fmt, va_list args);
144         /**< Print an error message.*/
145 };
146
147 /** Environment structure. This includes function pointers to access several
148  *  features provided by the environment in which the CSS API is used.
149  *  This is used to run the camera IP in multiple platforms such as Linux,
150  *  Windows and several simulation environments.
151  */
152 struct ia_css_env {
153         struct ia_css_cpu_mem_env   cpu_mem_env;   /**< local malloc and free. */
154         struct ia_css_css_mem_env   css_mem_env;   /**< CSS/ISP buffer alloc/free */
155         struct ia_css_hw_access_env hw_access_env; /**< CSS HW access functions */
156         struct ia_css_print_env     print_env;     /**< Message printing env. */
157 };
158
159 #endif /* __IA_CSS_ENV_H */