GNU Linux-libre 4.14.290-gnu1
[releases.git] / drivers / staging / media / atomisp / pci / atomisp2 / css2400 / runtime / isp_param / src / isp_param.c
1 #ifndef ISP2401
2 /*
3  * Support for Intel Camera Imaging ISP subsystem.
4  * Copyright (c) 2015, Intel Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  */
15 #else
16 /**
17 Support for Intel Camera Imaging ISP subsystem.
18 Copyright (c) 2010 - 2015, Intel Corporation.
19
20 This program is free software; you can redistribute it and/or modify it
21 under the terms and conditions of the GNU General Public License,
22 version 2, as published by the Free Software Foundation.
23
24 This program is distributed in the hope it will be useful, but WITHOUT
25 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
26 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
27 more details.
28 */
29 #endif
30
31 #include "memory_access.h"
32 #include "ia_css_pipeline.h"
33 #include "ia_css_isp_param.h"
34
35 /* Set functions for parameter memory descriptors */
36
37 void
38 ia_css_isp_param_set_mem_init(
39         struct ia_css_isp_param_host_segments *mem_init,
40         enum ia_css_param_class pclass,
41         enum ia_css_isp_memories mem,
42         char *address, size_t size)
43 {
44         mem_init->params[pclass][mem].address = address;
45         mem_init->params[pclass][mem].size = (uint32_t)size;
46 }
47
48 void
49 ia_css_isp_param_set_css_mem_init(
50         struct ia_css_isp_param_css_segments *mem_init,
51         enum ia_css_param_class pclass,
52         enum ia_css_isp_memories mem,
53         hrt_vaddress address, size_t size)
54 {
55         mem_init->params[pclass][mem].address = address;
56         mem_init->params[pclass][mem].size = (uint32_t)size;
57 }
58
59 void
60 ia_css_isp_param_set_isp_mem_init(
61         struct ia_css_isp_param_isp_segments *mem_init,
62         enum ia_css_param_class pclass,
63         enum ia_css_isp_memories mem,
64         uint32_t address, size_t size)
65 {
66         mem_init->params[pclass][mem].address = address;
67         mem_init->params[pclass][mem].size = (uint32_t)size;
68 }
69
70 /* Get functions for parameter memory descriptors */
71 const struct ia_css_host_data*
72 ia_css_isp_param_get_mem_init(
73         const struct ia_css_isp_param_host_segments *mem_init,
74         enum ia_css_param_class pclass,
75         enum ia_css_isp_memories mem)
76 {
77         return &mem_init->params[pclass][mem];
78 }
79
80 const struct ia_css_data*
81 ia_css_isp_param_get_css_mem_init(
82         const struct ia_css_isp_param_css_segments *mem_init,
83         enum ia_css_param_class pclass,
84         enum ia_css_isp_memories mem)
85 {
86         return &mem_init->params[pclass][mem];
87 }
88
89 const struct ia_css_isp_data*
90 ia_css_isp_param_get_isp_mem_init(
91         const struct ia_css_isp_param_isp_segments *mem_init,
92         enum ia_css_param_class pclass,
93         enum ia_css_isp_memories mem)
94 {
95         return &mem_init->params[pclass][mem];
96 }
97
98 void
99 ia_css_init_memory_interface(
100         struct ia_css_isp_param_css_segments *isp_mem_if,
101         const struct ia_css_isp_param_host_segments *mem_params,
102         const struct ia_css_isp_param_css_segments *css_params)
103 {
104         unsigned pclass, mem;
105         for (pclass = 0; pclass < IA_CSS_NUM_PARAM_CLASSES; pclass++) {
106                 memset(isp_mem_if->params[pclass], 0, sizeof(isp_mem_if->params[pclass]));
107                 for (mem = 0; mem < IA_CSS_NUM_MEMORIES; mem++) {
108                         if (!mem_params->params[pclass][mem].address)
109                                 continue;
110                         isp_mem_if->params[pclass][mem].size = mem_params->params[pclass][mem].size;
111                         if (pclass != IA_CSS_PARAM_CLASS_PARAM)
112                                 isp_mem_if->params[pclass][mem].address = css_params->params[pclass][mem].address;
113                 }
114         }
115 }
116
117 enum ia_css_err
118 ia_css_isp_param_allocate_isp_parameters(
119         struct ia_css_isp_param_host_segments *mem_params,
120         struct ia_css_isp_param_css_segments *css_params,
121         const struct ia_css_isp_param_isp_segments *mem_initializers)
122 {
123         enum ia_css_err err = IA_CSS_SUCCESS;
124         unsigned mem, pclass;
125
126         pclass = IA_CSS_PARAM_CLASS_PARAM;
127         for (mem = 0; mem < IA_CSS_NUM_MEMORIES; mem++) {
128                 for (pclass = 0; pclass < IA_CSS_NUM_PARAM_CLASSES; pclass++) {
129                         uint32_t size = 0;
130                         if (mem_initializers)
131                                 size = mem_initializers->params[pclass][mem].size;
132                         mem_params->params[pclass][mem].size = size;
133                         mem_params->params[pclass][mem].address = NULL;
134                         css_params->params[pclass][mem].size = size;
135                         css_params->params[pclass][mem].address = 0x0;
136                         if (size) {
137                                 mem_params->params[pclass][mem].address = sh_css_calloc(1, size);
138                                 if (!mem_params->params[pclass][mem].address) {
139                                         err = IA_CSS_ERR_CANNOT_ALLOCATE_MEMORY;
140                                         goto cleanup;
141                                 }
142                                 if (pclass != IA_CSS_PARAM_CLASS_PARAM) {
143                                         css_params->params[pclass][mem].address = mmgr_malloc(size);
144                                         if (!css_params->params[pclass][mem].address) {
145                                                 err = IA_CSS_ERR_CANNOT_ALLOCATE_MEMORY;
146                                                 goto cleanup;
147                                         }
148                                 }
149                         }
150                 }
151         }
152         return err;
153 cleanup:
154         ia_css_isp_param_destroy_isp_parameters(mem_params, css_params);
155         return err;
156 }
157
158 void
159 ia_css_isp_param_destroy_isp_parameters(
160         struct ia_css_isp_param_host_segments *mem_params,
161         struct ia_css_isp_param_css_segments *css_params)
162 {
163         unsigned mem, pclass;
164
165         for (mem = 0; mem < IA_CSS_NUM_MEMORIES; mem++) {
166                 for (pclass = 0; pclass < IA_CSS_NUM_PARAM_CLASSES; pclass++) {
167                         if (mem_params->params[pclass][mem].address)
168                                 sh_css_free(mem_params->params[pclass][mem].address);
169                         if (css_params->params[pclass][mem].address)
170                                 hmm_free(css_params->params[pclass][mem].address);
171                         mem_params->params[pclass][mem].address = NULL;
172                         css_params->params[pclass][mem].address = 0x0;
173                 }
174         }
175 }
176
177 void
178 ia_css_isp_param_load_fw_params(
179         const char *fw,
180         union ia_css_all_memory_offsets *mem_offsets,
181         const struct ia_css_isp_param_memory_offsets *memory_offsets,
182         bool init)
183 {
184         unsigned pclass;
185         for (pclass = 0; pclass < IA_CSS_NUM_PARAM_CLASSES; pclass++) {
186                 mem_offsets->array[pclass].ptr = NULL;
187                 if (init)
188                         mem_offsets->array[pclass].ptr = (void *)(fw + memory_offsets->offsets[pclass]);
189         }
190 }
191
192 enum ia_css_err
193 ia_css_isp_param_copy_isp_mem_if_to_ddr(
194         struct ia_css_isp_param_css_segments *ddr,
195         const struct ia_css_isp_param_host_segments *host,
196         enum ia_css_param_class pclass)
197 {
198         unsigned mem;
199
200         for (mem = 0; mem < N_IA_CSS_ISP_MEMORIES; mem++) {
201                 size_t       size         = host->params[pclass][mem].size;
202                 hrt_vaddress ddr_mem_ptr  = ddr->params[pclass][mem].address;
203                 char        *host_mem_ptr = host->params[pclass][mem].address;
204                 if (size != ddr->params[pclass][mem].size)
205                         return IA_CSS_ERR_INTERNAL_ERROR;
206                 if (!size)
207                         continue;
208                 mmgr_store(ddr_mem_ptr, host_mem_ptr, size);
209         }
210         return IA_CSS_SUCCESS;
211 }
212
213 void
214 ia_css_isp_param_enable_pipeline(
215         const struct ia_css_isp_param_host_segments *mem_params)
216 {
217         /* By protocol b0 of the mandatory uint32_t first field of the
218            input parameter is a disable bit*/
219         short dmem_offset = 0;
220
221         if (mem_params->params[IA_CSS_PARAM_CLASS_PARAM][IA_CSS_ISP_DMEM0].size == 0)
222                 return;
223
224         *(uint32_t *)&mem_params->params[IA_CSS_PARAM_CLASS_PARAM][IA_CSS_ISP_DMEM0].address[dmem_offset] = 0x0;
225 }
226
227