VPP: Fix Coverity alert on unitialized vpp_kernels
[platform/upstream/libva-intel-driver.git] / src / i965_device_info.c
1 /*
2  * Copyright © 2014 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sub license, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19  * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
20  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */
25
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include "i965_drv_video.h"
29
30 #include <string.h>
31 #include <strings.h>
32 #include <errno.h>
33 #include <cpuid.h>
34
35 /* Extra set of chroma formats supported for H.264 decoding (beyond YUV 4:2:0) */
36 #define EXTRA_H264_DEC_CHROMA_FORMATS \
37     (VA_RT_FORMAT_YUV400)
38
39 /* Extra set of chroma formats supported for JPEG decoding (beyond YUV 4:2:0) */
40 #define EXTRA_JPEG_DEC_CHROMA_FORMATS \
41     (VA_RT_FORMAT_YUV400 | VA_RT_FORMAT_YUV411 | VA_RT_FORMAT_YUV422 | \
42      VA_RT_FORMAT_YUV444)
43
44 /* Defines VA profile as a 32-bit unsigned integer mask */
45 #define VA_PROFILE_MASK(PROFILE) \
46     (1U << VAProfile##PROFILE)
47
48 extern struct hw_context *i965_proc_context_init(VADriverContextP, struct object_config *);
49 extern struct hw_context *g4x_dec_hw_context_init(VADriverContextP, struct object_config *);
50 extern bool genx_render_init(VADriverContextP);
51
52 static struct hw_codec_info g4x_hw_codec_info = {
53     .dec_hw_context_init = g4x_dec_hw_context_init,
54     .enc_hw_context_init = NULL,
55     .proc_hw_context_init = NULL,
56     .render_init = genx_render_init,
57     .post_processing_context_init = NULL,
58
59     .max_width = 2048,
60     .max_height = 2048,
61     .min_linear_wpitch = 16,
62     .min_linear_hpitch = 16,
63
64     .has_mpeg2_decoding = 1,
65
66     .num_filters = 0,
67 };
68
69 extern struct hw_context *ironlake_dec_hw_context_init(VADriverContextP, struct object_config *);
70 extern void i965_post_processing_context_init(VADriverContextP, void *, struct intel_batchbuffer *);
71
72 static struct hw_codec_info ilk_hw_codec_info = {
73     .dec_hw_context_init = ironlake_dec_hw_context_init,
74     .enc_hw_context_init = NULL,
75     .proc_hw_context_init = i965_proc_context_init,
76     .render_init = genx_render_init,
77     .post_processing_context_init = i965_post_processing_context_init,
78
79     .max_width = 2048,
80     .max_height = 2048,
81     .min_linear_wpitch = 16,
82     .min_linear_hpitch = 16,
83
84     .has_mpeg2_decoding = 1,
85     .has_h264_decoding = 1,
86     .has_vpp = 1,
87     .has_accelerated_putimage = 1,
88
89     .num_filters = 0,
90 };
91
92 extern struct hw_context *gen6_dec_hw_context_init(VADriverContextP, struct object_config *);
93 extern struct hw_context *gen6_enc_hw_context_init(VADriverContextP, struct object_config *);
94 static struct hw_codec_info snb_hw_codec_info = {
95     .dec_hw_context_init = gen6_dec_hw_context_init,
96     .enc_hw_context_init = gen6_enc_hw_context_init,
97     .proc_hw_context_init = i965_proc_context_init,
98     .render_init = genx_render_init,
99     .post_processing_context_init = i965_post_processing_context_init,
100
101     .max_width = 2048,
102     .max_height = 2048,
103     .min_linear_wpitch = 16,
104     .min_linear_hpitch = 16,
105
106     .h264_mvc_dec_profiles = VA_PROFILE_MASK(H264StereoHigh),
107     .h264_dec_chroma_formats = EXTRA_H264_DEC_CHROMA_FORMATS,
108
109     .has_mpeg2_decoding = 1,
110     .has_h264_decoding = 1,
111     .has_h264_encoding = 1,
112     .has_vc1_decoding = 1,
113     .has_vpp = 1,
114     .has_accelerated_getimage = 1,
115     .has_accelerated_putimage = 1,
116     .has_tiled_surface = 1,
117     .has_di_motion_adptive = 1,
118
119     .num_filters = 2,
120     .filters = {
121         { VAProcFilterNoiseReduction, I965_RING_NULL },
122         { VAProcFilterDeinterlacing, I965_RING_NULL },
123     },
124 };
125
126 extern struct hw_context *gen7_dec_hw_context_init(VADriverContextP, struct object_config *);
127 extern struct hw_context *gen7_enc_hw_context_init(VADriverContextP, struct object_config *);
128 static struct hw_codec_info ivb_hw_codec_info = {
129     .dec_hw_context_init = gen7_dec_hw_context_init,
130     .enc_hw_context_init = gen7_enc_hw_context_init,
131     .proc_hw_context_init = i965_proc_context_init,
132     .render_init = genx_render_init,
133     .post_processing_context_init = i965_post_processing_context_init,
134
135     .max_width = 4096,
136     .max_height = 4096,
137     .min_linear_wpitch = 64,
138     .min_linear_hpitch = 16,
139
140     .h264_mvc_dec_profiles = VA_PROFILE_MASK(H264StereoHigh),
141     .h264_dec_chroma_formats = EXTRA_H264_DEC_CHROMA_FORMATS,
142     .jpeg_dec_chroma_formats = EXTRA_JPEG_DEC_CHROMA_FORMATS,
143
144     .has_mpeg2_decoding = 1,
145     .has_mpeg2_encoding = 1,
146     .has_h264_decoding = 1,
147     .has_h264_encoding = 1,
148     .has_vc1_decoding = 1,
149     .has_jpeg_decoding = 1,
150     .has_vpp = 1,
151     .has_accelerated_getimage = 1,
152     .has_accelerated_putimage = 1,
153     .has_tiled_surface = 1,
154     .has_di_motion_adptive = 1,
155
156     .num_filters = 2,
157     .filters = {
158         { VAProcFilterNoiseReduction, I965_RING_NULL },
159         { VAProcFilterDeinterlacing, I965_RING_NULL },
160     },
161 };
162
163 static void hsw_hw_codec_preinit(VADriverContextP ctx, struct hw_codec_info *codec_info);
164
165 extern struct hw_context *gen75_dec_hw_context_init(VADriverContextP, struct object_config *);
166 extern struct hw_context *gen75_enc_hw_context_init(VADriverContextP, struct object_config *);
167 extern struct hw_context *gen75_proc_context_init(VADriverContextP, struct object_config *);
168 static struct hw_codec_info hsw_hw_codec_info = {
169     .dec_hw_context_init = gen75_dec_hw_context_init,
170     .enc_hw_context_init = gen75_enc_hw_context_init,
171     .proc_hw_context_init = gen75_proc_context_init,
172     .render_init = genx_render_init,
173     .post_processing_context_init = i965_post_processing_context_init,
174     .preinit_hw_codec = hsw_hw_codec_preinit,
175
176     .max_width = 4096,
177     .max_height = 4096,
178     .min_linear_wpitch = 64,
179     .min_linear_hpitch = 16,
180
181     .h264_mvc_dec_profiles = (VA_PROFILE_MASK(H264StereoHigh) |
182                               VA_PROFILE_MASK(H264MultiviewHigh)),
183     .h264_dec_chroma_formats = EXTRA_H264_DEC_CHROMA_FORMATS,
184     .jpeg_dec_chroma_formats = EXTRA_JPEG_DEC_CHROMA_FORMATS,
185
186     .has_mpeg2_decoding = 1,
187     .has_mpeg2_encoding = 1,
188     .has_h264_decoding = 1,
189     .has_h264_encoding = 1,
190     .has_vc1_decoding = 1,
191     .has_jpeg_decoding = 1,
192     .has_vpp = 1,
193     .has_accelerated_getimage = 1,
194     .has_accelerated_putimage = 1,
195     .has_tiled_surface = 1,
196     .has_di_motion_adptive = 1,
197     .has_di_motion_compensated = 1,
198     .has_h264_mvc_encoding = 1,
199
200     .num_filters = 5,
201     .filters = {
202         { VAProcFilterNoiseReduction, I965_RING_VEBOX },
203         { VAProcFilterDeinterlacing, I965_RING_VEBOX },
204         { VAProcFilterSharpening, I965_RING_NULL },
205         { VAProcFilterColorBalance, I965_RING_VEBOX},
206         { VAProcFilterSkinToneEnhancement, I965_RING_VEBOX},
207     },
208 };
209
210 extern struct hw_context *gen8_dec_hw_context_init(VADriverContextP, struct object_config *);
211 extern struct hw_context *gen8_enc_hw_context_init(VADriverContextP, struct object_config *);
212 extern void gen8_post_processing_context_init(VADriverContextP, void *, struct intel_batchbuffer *);
213 static struct hw_codec_info bdw_hw_codec_info = {
214     .dec_hw_context_init = gen8_dec_hw_context_init,
215     .enc_hw_context_init = gen8_enc_hw_context_init,
216     .proc_hw_context_init = gen75_proc_context_init,
217     .render_init = gen8_render_init,
218     .post_processing_context_init = gen8_post_processing_context_init,
219
220     .max_width = 4096,
221     .max_height = 4096,
222     .min_linear_wpitch = 64,
223     .min_linear_hpitch = 16,
224
225     .h264_mvc_dec_profiles = (VA_PROFILE_MASK(H264StereoHigh) |
226                               VA_PROFILE_MASK(H264MultiviewHigh)),
227     .h264_dec_chroma_formats = EXTRA_H264_DEC_CHROMA_FORMATS,
228     .jpeg_dec_chroma_formats = EXTRA_JPEG_DEC_CHROMA_FORMATS,
229
230     .has_mpeg2_decoding = 1,
231     .has_mpeg2_encoding = 1,
232     .has_h264_decoding = 1,
233     .has_h264_encoding = 1,
234     .has_vc1_decoding = 1,
235     .has_jpeg_decoding = 1,
236     .has_vpp = 1,
237     .has_accelerated_getimage = 1,
238     .has_accelerated_putimage = 1,
239     .has_tiled_surface = 1,
240     .has_di_motion_adptive = 1,
241     .has_di_motion_compensated = 1,
242     .has_vp8_decoding = 1,
243     .has_h264_mvc_encoding = 1,
244
245     .num_filters = 5,
246     .filters = {
247         { VAProcFilterNoiseReduction, I965_RING_VEBOX },
248         { VAProcFilterDeinterlacing, I965_RING_VEBOX },
249         { VAProcFilterSharpening, I965_RING_NULL }, /* need to rebuild the shader for BDW */
250         { VAProcFilterColorBalance, I965_RING_VEBOX},
251         { VAProcFilterSkinToneEnhancement, I965_RING_VEBOX},
252     },
253 };
254
255 static struct hw_codec_info chv_hw_codec_info = {
256     .dec_hw_context_init = gen8_dec_hw_context_init,
257     .enc_hw_context_init = gen8_enc_hw_context_init,
258     .proc_hw_context_init = gen75_proc_context_init,
259     .render_init = gen8_render_init,
260     .post_processing_context_init = gen8_post_processing_context_init,
261
262     .max_width = 4096,
263     .max_height = 4096,
264     .min_linear_wpitch = 64,
265     .min_linear_hpitch = 16,
266
267     .h264_mvc_dec_profiles = (VA_PROFILE_MASK(H264StereoHigh) |
268                               VA_PROFILE_MASK(H264MultiviewHigh)),
269     .h264_dec_chroma_formats = EXTRA_H264_DEC_CHROMA_FORMATS,
270     .jpeg_dec_chroma_formats = EXTRA_JPEG_DEC_CHROMA_FORMATS,
271
272     .has_mpeg2_decoding = 1,
273     .has_mpeg2_encoding = 1,
274     .has_h264_decoding = 1,
275     .has_h264_encoding = 1,
276     .has_vc1_decoding = 1,
277     .has_jpeg_decoding = 1,
278     .has_vpp = 1,
279     .has_accelerated_getimage = 1,
280     .has_accelerated_putimage = 1,
281     .has_tiled_surface = 1,
282     .has_di_motion_adptive = 1,
283     .has_di_motion_compensated = 1,
284     .has_vp8_decoding = 1,
285     .has_h264_mvc_encoding = 1,
286
287     .num_filters = 5,
288     .filters = {
289         { VAProcFilterNoiseReduction, I965_RING_VEBOX },
290         { VAProcFilterDeinterlacing, I965_RING_VEBOX },
291         { VAProcFilterSharpening, I965_RING_NULL }, /* need to rebuild the shader for BDW */
292         { VAProcFilterColorBalance, I965_RING_VEBOX},
293         { VAProcFilterSkinToneEnhancement, I965_RING_VEBOX},
294     },
295 };
296
297 struct hw_codec_info *
298 i965_get_codec_info(int devid)
299 {
300     switch (devid) {
301 #undef CHIPSET
302 #define CHIPSET(id, family, dev, str) case id: return &family##_hw_codec_info;
303 #include "i965_pciids.h"
304     default:
305         return NULL;
306     }
307 }
308
309 static const struct intel_device_info g4x_device_info = {
310     .gen = 4,
311
312     .urb_size = 384,
313     .max_wm_threads = 50,       /* 10 * 5 */
314
315     .is_g4x = 1,
316 };
317
318 static const struct intel_device_info ilk_device_info = {
319     .gen = 5,
320
321     .urb_size = 1024,
322     .max_wm_threads = 72,       /* 12 * 6 */
323 };
324
325 static const struct intel_device_info snb_gt1_device_info = {
326     .gen = 6,
327     .gt = 1,
328
329     .urb_size = 1024,
330     .max_wm_threads = 40,
331 };
332
333 static const struct intel_device_info snb_gt2_device_info = {
334     .gen = 6,
335     .gt = 2,
336
337     .urb_size = 1024,
338     .max_wm_threads = 80,
339 };
340
341 static const struct intel_device_info ivb_gt1_device_info = {
342     .gen = 7,
343     .gt = 1,
344
345     .urb_size = 4096,
346     .max_wm_threads = 48,
347
348     .is_ivybridge = 1,
349 };
350
351 static const struct intel_device_info ivb_gt2_device_info = {
352     .gen = 7,
353     .gt = 2,
354
355     .urb_size = 4096,
356     .max_wm_threads = 172,
357
358     .is_ivybridge = 1,
359 };
360
361 static const struct intel_device_info byt_device_info = {
362     .gen = 7,
363     .gt = 1,
364
365     .urb_size = 4096,
366     .max_wm_threads = 48,
367
368     .is_ivybridge = 1,
369     .is_baytrail = 1,
370 };
371
372 static const struct intel_device_info hsw_gt1_device_info = {
373     .gen = 7,
374     .gt = 1,
375
376     .urb_size = 4096,
377     .max_wm_threads = 102,
378
379     .is_haswell = 1,
380 };
381
382 static const struct intel_device_info hsw_gt2_device_info = {
383     .gen = 7,
384     .gt = 2,
385
386     .urb_size = 4096,
387     .max_wm_threads = 204,
388
389     .is_haswell = 1,
390 };
391
392 static const struct intel_device_info hsw_gt3_device_info = {
393     .gen = 7,
394     .gt = 3,
395
396     .urb_size = 4096,
397     .max_wm_threads = 408,
398
399     .is_haswell = 1,
400 };
401
402 static const struct intel_device_info bdw_device_info = {
403     .gen = 8,
404
405     .urb_size = 4096,
406     .max_wm_threads = 64,       /* per PSD */
407 };
408
409 static const struct intel_device_info chv_device_info = {
410     .gen = 8,
411
412     .urb_size = 4096,
413     .max_wm_threads = 64,       /* per PSD */
414
415     .is_cherryview = 1,
416 };
417
418 const struct intel_device_info *
419 i965_get_device_info(int devid)
420 {
421     switch (devid) {
422 #undef CHIPSET
423 #define CHIPSET(id, family, dev, str) case id: return &dev##_device_info;
424 #include "i965_pciids.h"
425     default:
426         return NULL;
427     }
428 }
429
430 static void cpuid(unsigned int op,
431                          uint32_t *eax, uint32_t *ebx,
432                          uint32_t *ecx, uint32_t *edx)
433 {
434         __cpuid_count(op, 0, *eax, *ebx, *ecx, *edx);
435 }
436
437 /*
438  * This function doesn't check the length. And the caller should
439  * assure that the length of input string should be greater than 48.
440  */
441
442 static int intel_driver_detect_cpustring(char *model_id)
443 {
444     uint32_t *rdata;
445
446     if (model_id == NULL)
447         return -EINVAL;
448
449     rdata = (uint32_t *)model_id;
450
451     /* obtain the max supported extended CPUID info */
452     cpuid(0x80000000, &rdata[0], &rdata[1], &rdata[2], &rdata[3]);
453
454     /* If the max extended CPUID info is less than 0x80000004, fail */
455     if (rdata[0] < 0x80000004)
456         return -EINVAL;
457
458     /* obtain the CPUID string */
459     cpuid(0x80000002, &rdata[0], &rdata[1], &rdata[2], &rdata[3]);
460     cpuid(0x80000003, &rdata[4], &rdata[5], &rdata[6], &rdata[7]);
461     cpuid(0x80000004, &rdata[8], &rdata[9], &rdata[10], &rdata[11]);
462
463     *(model_id + 48) = '\0';
464     return 0;
465 }
466
467 /*
468  * the hook_list for HSW.
469  * It is captured by /proc/cpuinfo and the space character is stripped.
470  */
471 const static char *hsw_cpu_hook_list[] =  {
472 "Intel(R)Pentium(R)3556U",
473 "Intel(R)Pentium(R)3560Y",
474 "Intel(R)Pentium(R)3550M",
475 "Intel(R)Celeron(R)2980U",
476 "Intel(R)Celeron(R)2955U",
477 "Intel(R)Celeron(R)2950M",
478 };
479
480 static void hsw_hw_codec_preinit(VADriverContextP ctx, struct hw_codec_info *codec_info)
481 {
482     char model_string[64];
483     char *model_ptr, *tmp_ptr;
484     int i, model_len, list_len;
485     bool found;
486
487     memset(model_string, 0, sizeof(model_string));
488
489     /* If it can't detect cpu model_string, leave it alone */
490     if (intel_driver_detect_cpustring(model_string))
491         return;
492
493     /* strip the cpufreq info */
494     model_ptr = model_string;
495     tmp_ptr = strstr(model_ptr, "@");
496
497     if (tmp_ptr)
498         *tmp_ptr = '\0';
499
500     /* strip the space character */
501     model_ptr = model_string;
502     model_len = strlen(model_string);
503     for (i = 0; i < model_len; i++) {
504         if (model_string[i] != ' ') {
505             *model_ptr = model_string[i];
506             model_ptr++;
507         }
508     }
509     *model_ptr = '\0';
510
511     found = false;
512     list_len = sizeof(hsw_cpu_hook_list) / sizeof(char *);
513     model_len = strlen(model_string);
514     for (i = 0; i < list_len; i++) {
515         model_ptr = (char *)hsw_cpu_hook_list[i];
516
517         if (strlen(model_ptr) != model_len)
518             continue;
519
520         if (strncasecmp(model_string, model_ptr, model_len) == 0) {
521             found = true;
522             break;
523         }
524     }
525
526     if (found) {
527         codec_info->has_h264_encoding = 0;
528         codec_info->has_h264_mvc_encoding = 0;
529         codec_info->has_mpeg2_encoding = 0;
530     }
531 }