OSDN Git Service

VC1: Fix for frame coding mode
[android-x86/hardware-intel-common-vaapi.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 /* Extra set of chroma formats supported for JPEG encoding (beyond YUV 4:2:0) */
45 #define EXTRA_JPEG_ENC_CHROMA_FORMATS \
46     (VA_RT_FORMAT_YUV400| VA_RT_FORMAT_YUV422 | VA_RT_FORMAT_YUV444 | VA_RT_FORMAT_RGB32)
47
48 #define EXTRA_HEVC_DEC_CHROMA_FORMATS \
49     (VA_RT_FORMAT_YUV420_10BPP)
50
51 #define EXTRA_VP9_DEC_CHROMA_FORMATS \
52     (VA_RT_FORMAT_YUV420_10BPP)
53
54 /* Defines VA profile as a 32-bit unsigned integer mask */
55 #define VA_PROFILE_MASK(PROFILE) \
56     (1U << VAProfile##PROFILE)
57
58 #define VP9_PROFILE_MASK(PROFILE) \
59     (1U << PROFILE)
60
61 extern struct hw_context *i965_proc_context_init(VADriverContextP, struct object_config *);
62 extern struct hw_context *g4x_dec_hw_context_init(VADriverContextP, struct object_config *);
63 extern bool genx_render_init(VADriverContextP);
64
65 static struct hw_codec_info g4x_hw_codec_info = {
66     .dec_hw_context_init = g4x_dec_hw_context_init,
67     .enc_hw_context_init = NULL,
68     .proc_hw_context_init = NULL,
69     .render_init = genx_render_init,
70     .post_processing_context_init = NULL,
71
72     .max_width = 2048,
73     .max_height = 2048,
74     .min_linear_wpitch = 16,
75     .min_linear_hpitch = 4,
76
77     .has_mpeg2_decoding = 1,
78
79     .num_filters = 0,
80 };
81
82 extern struct hw_context *ironlake_dec_hw_context_init(VADriverContextP, struct object_config *);
83 extern void i965_post_processing_context_init(VADriverContextP, void *, struct intel_batchbuffer *);
84
85 static struct hw_codec_info ilk_hw_codec_info = {
86     .dec_hw_context_init = ironlake_dec_hw_context_init,
87     .enc_hw_context_init = NULL,
88     .proc_hw_context_init = i965_proc_context_init,
89     .render_init = genx_render_init,
90     .post_processing_context_init = i965_post_processing_context_init,
91
92     .max_width = 2048,
93     .max_height = 2048,
94     .min_linear_wpitch = 16,
95     .min_linear_hpitch = 4,
96
97     .has_mpeg2_decoding = 1,
98     .has_h264_decoding = 1,
99     .has_vpp = 1,
100     .has_accelerated_putimage = 1,
101
102     .num_filters = 0,
103 };
104
105 static void gen6_hw_codec_preinit(VADriverContextP ctx, struct hw_codec_info *codec_info);
106
107 extern struct hw_context *gen6_dec_hw_context_init(VADriverContextP, struct object_config *);
108 extern struct hw_context *gen6_enc_hw_context_init(VADriverContextP, struct object_config *);
109 static struct hw_codec_info snb_hw_codec_info = {
110     .dec_hw_context_init = gen6_dec_hw_context_init,
111     .enc_hw_context_init = gen6_enc_hw_context_init,
112     .proc_hw_context_init = i965_proc_context_init,
113     .render_init = genx_render_init,
114     .post_processing_context_init = i965_post_processing_context_init,
115     .preinit_hw_codec = gen6_hw_codec_preinit,
116
117     .max_width = 2048,
118     .max_height = 2048,
119     .min_linear_wpitch = 16,
120     .min_linear_hpitch = 4,
121
122     .h264_mvc_dec_profiles = VA_PROFILE_MASK(H264StereoHigh),
123     .h264_dec_chroma_formats = EXTRA_H264_DEC_CHROMA_FORMATS,
124
125     .has_mpeg2_decoding = 1,
126     .has_h264_decoding = 1,
127     .has_h264_encoding = 1,
128     .has_vc1_decoding = 1,
129     .has_vpp = 1,
130     .has_accelerated_getimage = 1,
131     .has_accelerated_putimage = 1,
132     .has_tiled_surface = 1,
133     .has_di_motion_adptive = 1,
134
135     .h264_brc_mode = VA_RC_CQP | VA_RC_CBR | VA_RC_VBR,
136
137     .num_filters = 2,
138     .filters = {
139         { VAProcFilterNoiseReduction, I965_RING_NULL },
140         { VAProcFilterDeinterlacing, I965_RING_NULL },
141     },
142 };
143
144 static void gen7_hw_codec_preinit(VADriverContextP ctx, struct hw_codec_info *codec_info);
145
146 extern struct hw_context *gen7_dec_hw_context_init(VADriverContextP, struct object_config *);
147 extern struct hw_context *gen7_enc_hw_context_init(VADriverContextP, struct object_config *);
148 static struct hw_codec_info ivb_hw_codec_info = {
149     .dec_hw_context_init = gen7_dec_hw_context_init,
150     .enc_hw_context_init = gen7_enc_hw_context_init,
151     .proc_hw_context_init = i965_proc_context_init,
152     .render_init = genx_render_init,
153     .post_processing_context_init = i965_post_processing_context_init,
154     .preinit_hw_codec = gen7_hw_codec_preinit,
155
156     .max_width = 4096,
157     .max_height = 4096,
158     .min_linear_wpitch = 64,
159     .min_linear_hpitch = 4,
160
161     .h264_mvc_dec_profiles = VA_PROFILE_MASK(H264StereoHigh),
162     .h264_dec_chroma_formats = EXTRA_H264_DEC_CHROMA_FORMATS,
163     .jpeg_dec_chroma_formats = EXTRA_JPEG_DEC_CHROMA_FORMATS,
164
165     .has_mpeg2_decoding = 1,
166     .has_mpeg2_encoding = 1,
167     .has_h264_decoding = 1,
168     .has_h264_encoding = 1,
169     .has_vc1_decoding = 1,
170     .has_jpeg_decoding = 1,
171     .has_vpp = 1,
172     .has_accelerated_getimage = 1,
173     .has_accelerated_putimage = 1,
174     .has_tiled_surface = 1,
175     .has_di_motion_adptive = 1,
176     .has_di_motion_compensated = 1,
177
178     .h264_brc_mode = VA_RC_CQP | VA_RC_CBR | VA_RC_VBR,
179
180     .num_filters = 2,
181     .filters = {
182         { VAProcFilterNoiseReduction, I965_RING_NULL },
183         { VAProcFilterDeinterlacing, I965_RING_NULL },
184     },
185 };
186
187 static void hsw_hw_codec_preinit(VADriverContextP ctx, struct hw_codec_info *codec_info);
188
189 extern struct hw_context *gen75_dec_hw_context_init(VADriverContextP, struct object_config *);
190 extern struct hw_context *gen75_enc_hw_context_init(VADriverContextP, struct object_config *);
191 extern struct hw_context *gen75_proc_context_init(VADriverContextP, struct object_config *);
192 static struct hw_codec_info hsw_hw_codec_info = {
193     .dec_hw_context_init = gen75_dec_hw_context_init,
194     .enc_hw_context_init = gen75_enc_hw_context_init,
195     .proc_hw_context_init = gen75_proc_context_init,
196     .render_init = genx_render_init,
197     .post_processing_context_init = i965_post_processing_context_init,
198     .preinit_hw_codec = hsw_hw_codec_preinit,
199
200     .max_width = 4096,
201     .max_height = 4096,
202     .min_linear_wpitch = 64,
203     .min_linear_hpitch = 4,
204
205     .h264_mvc_dec_profiles = (VA_PROFILE_MASK(H264StereoHigh) |
206     VA_PROFILE_MASK(H264MultiviewHigh)),
207     .h264_dec_chroma_formats = EXTRA_H264_DEC_CHROMA_FORMATS,
208     .jpeg_dec_chroma_formats = EXTRA_JPEG_DEC_CHROMA_FORMATS,
209
210     .has_mpeg2_decoding = 1,
211     .has_mpeg2_encoding = 1,
212     .has_h264_decoding = 1,
213     .has_h264_encoding = 1,
214     .has_vc1_decoding = 1,
215     .has_jpeg_decoding = 1,
216     .has_vpp = 1,
217     .has_accelerated_getimage = 1,
218     .has_accelerated_putimage = 1,
219     .has_tiled_surface = 1,
220     .has_di_motion_adptive = 1,
221     .has_di_motion_compensated = 1,
222     .has_h264_mvc_encoding = 1,
223
224     .h264_brc_mode = VA_RC_CQP | VA_RC_CBR | VA_RC_VBR,
225
226     .num_filters = 5,
227     .filters = {
228         { VAProcFilterNoiseReduction, I965_RING_VEBOX },
229         { VAProcFilterDeinterlacing, I965_RING_VEBOX },
230         { VAProcFilterSharpening, I965_RING_NULL },
231         { VAProcFilterColorBalance, I965_RING_VEBOX},
232         { VAProcFilterSkinToneEnhancement, I965_RING_VEBOX},
233     },
234 };
235
236 extern struct hw_context *gen8_dec_hw_context_init(VADriverContextP, struct object_config *);
237 extern struct hw_context *gen8_enc_hw_context_init(VADriverContextP, struct object_config *);
238 extern void gen8_post_processing_context_init(VADriverContextP, void *, struct intel_batchbuffer *);
239 static struct hw_codec_info bdw_hw_codec_info = {
240     .dec_hw_context_init = gen8_dec_hw_context_init,
241     .enc_hw_context_init = gen8_enc_hw_context_init,
242     .proc_hw_context_init = gen75_proc_context_init,
243     .render_init = gen8_render_init,
244     .post_processing_context_init = gen8_post_processing_context_init,
245
246     .max_width = 4096,
247     .max_height = 4096,
248     .min_linear_wpitch = 64,
249     .min_linear_hpitch = 4,
250
251     .h264_mvc_dec_profiles = (VA_PROFILE_MASK(H264StereoHigh) |
252     VA_PROFILE_MASK(H264MultiviewHigh)),
253     .h264_dec_chroma_formats = EXTRA_H264_DEC_CHROMA_FORMATS,
254     .jpeg_dec_chroma_formats = EXTRA_JPEG_DEC_CHROMA_FORMATS,
255
256     .has_mpeg2_decoding = 1,
257     .has_mpeg2_encoding = 1,
258     .has_h264_decoding = 1,
259     .has_h264_encoding = 1,
260     .has_vc1_decoding = 1,
261     .has_jpeg_decoding = 1,
262     .has_vpp = 1,
263     .has_accelerated_getimage = 1,
264     .has_accelerated_putimage = 1,
265     .has_tiled_surface = 1,
266     .has_di_motion_adptive = 1,
267     .has_di_motion_compensated = 1,
268     .has_vp8_decoding = 1,
269     .has_h264_mvc_encoding = 1,
270
271     .h264_brc_mode = VA_RC_CQP | VA_RC_CBR | VA_RC_VBR,
272
273     .num_filters = 5,
274     .filters = {
275         { VAProcFilterNoiseReduction, I965_RING_VEBOX },
276         { VAProcFilterDeinterlacing, I965_RING_VEBOX },
277         { VAProcFilterSharpening, I965_RING_NULL }, /* need to rebuild the shader for BDW */
278         { VAProcFilterColorBalance, I965_RING_VEBOX},
279         { VAProcFilterSkinToneEnhancement, I965_RING_VEBOX},
280     },
281 };
282
283 extern struct hw_context *gen9_dec_hw_context_init(VADriverContextP, struct object_config *);
284 static struct hw_codec_info chv_hw_codec_info = {
285     .dec_hw_context_init = gen9_dec_hw_context_init,
286     .enc_hw_context_init = gen8_enc_hw_context_init,
287     .proc_hw_context_init = gen75_proc_context_init,
288     .render_init = gen8_render_init,
289     .post_processing_context_init = gen8_post_processing_context_init,
290
291     .max_width = 4096,
292     .max_height = 4096,
293     .min_linear_wpitch = 64,
294     .min_linear_hpitch = 4,
295
296     .h264_mvc_dec_profiles = (VA_PROFILE_MASK(H264StereoHigh) |
297     VA_PROFILE_MASK(H264MultiviewHigh)),
298     .h264_dec_chroma_formats = EXTRA_H264_DEC_CHROMA_FORMATS,
299     .jpeg_dec_chroma_formats = EXTRA_JPEG_DEC_CHROMA_FORMATS,
300     .jpeg_enc_chroma_formats = EXTRA_JPEG_ENC_CHROMA_FORMATS,
301
302     .has_mpeg2_decoding = 1,
303     .has_mpeg2_encoding = 1,
304     .has_h264_decoding = 1,
305     .has_h264_encoding = 1,
306     .has_vc1_decoding = 1,
307     .has_jpeg_decoding = 1,
308     .has_jpeg_encoding = 1,
309     .has_vpp = 1,
310     .has_accelerated_getimage = 1,
311     .has_accelerated_putimage = 1,
312     .has_tiled_surface = 1,
313     .has_di_motion_adptive = 1,
314     .has_di_motion_compensated = 1,
315     .has_vp8_decoding = 1,
316     .has_vp8_encoding = 1,
317     .has_h264_mvc_encoding = 1,
318     .has_hevc_decoding = 1,
319
320     .h264_brc_mode = VA_RC_CQP | VA_RC_CBR | VA_RC_VBR,
321
322     .num_filters = 5,
323     .filters = {
324         { VAProcFilterNoiseReduction, I965_RING_VEBOX },
325         { VAProcFilterDeinterlacing, I965_RING_VEBOX },
326         { VAProcFilterSharpening, I965_RING_NULL }, /* need to rebuild the shader for BDW */
327         { VAProcFilterColorBalance, I965_RING_VEBOX},
328         { VAProcFilterSkinToneEnhancement, I965_RING_VEBOX},
329     },
330 };
331
332 static void gen9_hw_codec_preinit(VADriverContextP ctx, struct hw_codec_info *codec_info);
333
334 extern struct hw_context *gen9_enc_hw_context_init(VADriverContextP, struct object_config *);
335 extern void gen9_post_processing_context_init(VADriverContextP, void *, struct intel_batchbuffer *);
336 extern void gen9_max_resolution(struct i965_driver_data *, struct object_config *, int *, int *);
337 static struct hw_codec_info skl_hw_codec_info = {
338     .dec_hw_context_init = gen9_dec_hw_context_init,
339     .enc_hw_context_init = gen9_enc_hw_context_init,
340     .proc_hw_context_init = gen75_proc_context_init,
341     .render_init = gen9_render_init,
342     .post_processing_context_init = gen9_post_processing_context_init,
343     .max_resolution = gen9_max_resolution,
344     .preinit_hw_codec = gen9_hw_codec_preinit,
345
346     .max_width = 4096,  /* default. See max_resolution */
347     .max_height = 4096, /* default. See max_resolution */
348     .min_linear_wpitch = 64,
349     .min_linear_hpitch = 4,
350
351     .h264_mvc_dec_profiles = (VA_PROFILE_MASK(H264StereoHigh) |
352     VA_PROFILE_MASK(H264MultiviewHigh)),
353     .h264_dec_chroma_formats = EXTRA_H264_DEC_CHROMA_FORMATS,
354     .jpeg_dec_chroma_formats = EXTRA_JPEG_DEC_CHROMA_FORMATS,
355     .jpeg_enc_chroma_formats = EXTRA_JPEG_ENC_CHROMA_FORMATS,
356
357     .has_mpeg2_decoding = 1,
358     .has_mpeg2_encoding = 1,
359     .has_h264_decoding = 1,
360     .has_h264_encoding = 1,
361     .has_vc1_decoding = 1,
362     .has_jpeg_decoding = 1,
363     .has_jpeg_encoding = 1,
364     .has_vpp = 1,
365     .has_accelerated_getimage = 1,
366     .has_accelerated_putimage = 1,
367     .has_tiled_surface = 1,
368     .has_di_motion_adptive = 1,
369     .has_di_motion_compensated = 1,
370     .has_vp8_decoding = 1,
371     .has_vp8_encoding = 1,
372     .has_h264_mvc_encoding = 1,
373     .has_hevc_decoding = 1,
374     .has_hevc_encoding = 1,
375     .has_lp_h264_encoding = 1,
376     .has_fei_h264_encoding = 1,
377
378     .lp_h264_brc_mode = VA_RC_CQP,
379     .h264_brc_mode = VA_RC_CQP | VA_RC_CBR | VA_RC_VBR | VA_RC_MB,
380
381     .num_filters = 5,
382     .filters = {
383         { VAProcFilterNoiseReduction, I965_RING_VEBOX },
384         { VAProcFilterDeinterlacing, I965_RING_VEBOX },
385         { VAProcFilterSharpening, I965_RING_NULL }, /* need to rebuild the shader for BDW */
386         { VAProcFilterColorBalance, I965_RING_VEBOX},
387         { VAProcFilterSkinToneEnhancement, I965_RING_VEBOX},
388     },
389 };
390
391
392 static struct hw_codec_info bxt_hw_codec_info = {
393     .dec_hw_context_init = gen9_dec_hw_context_init,
394     .enc_hw_context_init = gen9_enc_hw_context_init,
395     .proc_hw_context_init = gen75_proc_context_init,
396     .render_init = gen9_render_init,
397     .post_processing_context_init = gen9_post_processing_context_init,
398     .max_resolution = gen9_max_resolution,
399     .preinit_hw_codec = gen9_hw_codec_preinit,
400
401     .max_width = 4096,  /* default. See max_resolution */
402     .max_height = 4096, /* default. See max_resolution */
403     .min_linear_wpitch = 64,
404     .min_linear_hpitch = 4,
405
406     .h264_mvc_dec_profiles = (VA_PROFILE_MASK(H264StereoHigh) |
407     VA_PROFILE_MASK(H264MultiviewHigh)),
408     .vp9_dec_profiles = VP9_PROFILE_MASK(0),
409
410     .h264_dec_chroma_formats = EXTRA_H264_DEC_CHROMA_FORMATS,
411     .jpeg_dec_chroma_formats = EXTRA_JPEG_DEC_CHROMA_FORMATS,
412     .jpeg_enc_chroma_formats = EXTRA_JPEG_ENC_CHROMA_FORMATS,
413     .hevc_dec_chroma_formats = EXTRA_HEVC_DEC_CHROMA_FORMATS,
414
415     .has_mpeg2_decoding = 1,
416     .has_h264_decoding = 1,
417     .has_h264_encoding = 1,
418     .has_vc1_decoding = 1,
419     .has_jpeg_decoding = 1,
420     .has_jpeg_encoding = 1,
421     .has_vpp = 1,
422     .has_accelerated_getimage = 1,
423     .has_accelerated_putimage = 1,
424     .has_tiled_surface = 1,
425     .has_di_motion_adptive = 1,
426     .has_di_motion_compensated = 1,
427     .has_vp8_decoding = 1,
428     .has_vp8_encoding = 1,
429     .has_h264_mvc_encoding = 1,
430     .has_hevc_decoding = 1,
431     .has_hevc_encoding = 1,
432     .has_hevc10_decoding = 1,
433     .has_vp9_decoding = 1,
434     .has_vpp_p010 = 1,
435     .has_lp_h264_encoding = 1,
436
437     .lp_h264_brc_mode = VA_RC_CQP,
438     .h264_brc_mode = VA_RC_CQP | VA_RC_CBR | VA_RC_VBR | VA_RC_MB,
439
440     .num_filters = 5,
441     .filters = {
442         { VAProcFilterNoiseReduction, I965_RING_VEBOX },
443         { VAProcFilterDeinterlacing, I965_RING_VEBOX },
444         { VAProcFilterSharpening, I965_RING_NULL },
445         { VAProcFilterColorBalance, I965_RING_VEBOX},
446         { VAProcFilterSkinToneEnhancement, I965_RING_VEBOX},
447     },
448 };
449
450 static struct hw_codec_info kbl_hw_codec_info = {
451     .dec_hw_context_init = gen9_dec_hw_context_init,
452     .enc_hw_context_init = gen9_enc_hw_context_init,
453     .proc_hw_context_init = gen75_proc_context_init,
454     .render_init = gen9_render_init,
455     .post_processing_context_init = gen9_post_processing_context_init,
456     .max_resolution = gen9_max_resolution,
457     .preinit_hw_codec = gen9_hw_codec_preinit,
458
459     .max_width = 4096,   /* default. See max_resolution */
460     .max_height = 4096,  /* default. See max_resolution */
461     .min_linear_wpitch = 64,
462     .min_linear_hpitch = 4,
463
464     .h264_mvc_dec_profiles = (VA_PROFILE_MASK(H264StereoHigh) |
465     VA_PROFILE_MASK(H264MultiviewHigh)),
466     .vp9_dec_profiles = VP9_PROFILE_MASK(0) |
467     VP9_PROFILE_MASK(2),
468     .vp9_enc_profiles = VP9_PROFILE_MASK(0),
469
470     .h264_dec_chroma_formats = EXTRA_H264_DEC_CHROMA_FORMATS,
471     .jpeg_dec_chroma_formats = EXTRA_JPEG_DEC_CHROMA_FORMATS,
472     .jpeg_enc_chroma_formats = EXTRA_JPEG_ENC_CHROMA_FORMATS,
473     .hevc_dec_chroma_formats = EXTRA_HEVC_DEC_CHROMA_FORMATS,
474     .vp9_dec_chroma_formats = EXTRA_VP9_DEC_CHROMA_FORMATS,
475
476     .has_mpeg2_decoding = 1,
477     .has_mpeg2_encoding = 1,
478     .has_h264_decoding = 1,
479     .has_h264_encoding = 1,
480     .has_vc1_decoding = 1,
481     .has_jpeg_decoding = 1,
482     .has_jpeg_encoding = 1,
483     .has_vpp = 1,
484     .has_accelerated_getimage = 1,
485     .has_accelerated_putimage = 1,
486     .has_tiled_surface = 1,
487     .has_di_motion_adptive = 1,
488     .has_di_motion_compensated = 1,
489     .has_vp8_decoding = 1,
490     .has_vp8_encoding = 1,
491     .has_h264_mvc_encoding = 1,
492     .has_hevc_decoding = 1,
493     .has_hevc_encoding = 1,
494     .has_hevc10_encoding = 1,
495     .has_hevc10_decoding = 1,
496     .has_vp9_decoding = 1,
497     .has_vpp_p010 = 1,
498     .has_vp9_encoding = 1,
499     .has_lp_h264_encoding = 1,
500
501     .lp_h264_brc_mode = VA_RC_CQP,
502     .h264_brc_mode = VA_RC_CQP | VA_RC_CBR | VA_RC_VBR | VA_RC_MB,
503
504     .num_filters = 5,
505     .filters = {
506         { VAProcFilterNoiseReduction, I965_RING_VEBOX },
507         { VAProcFilterDeinterlacing, I965_RING_VEBOX },
508         { VAProcFilterSharpening, I965_RING_NULL },
509         { VAProcFilterColorBalance, I965_RING_VEBOX},
510         { VAProcFilterSkinToneEnhancement, I965_RING_VEBOX},
511     },
512 };
513
514 static struct hw_codec_info glk_hw_codec_info = {
515     .dec_hw_context_init = gen9_dec_hw_context_init,
516     .enc_hw_context_init = gen9_enc_hw_context_init,
517     .proc_hw_context_init = gen75_proc_context_init,
518     .render_init = gen9_render_init,
519     .post_processing_context_init = gen9_post_processing_context_init,
520
521     .max_resolution = gen9_max_resolution,
522     .preinit_hw_codec = gen9_hw_codec_preinit,
523
524     .max_width = 4096,
525     .max_height = 4096,
526     .min_linear_wpitch = 64,
527     .min_linear_hpitch = 4,
528
529     .h264_mvc_dec_profiles = (VA_PROFILE_MASK(H264StereoHigh) |
530     VA_PROFILE_MASK(H264MultiviewHigh)),
531     .vp9_dec_profiles = VP9_PROFILE_MASK(0) |
532     VP9_PROFILE_MASK(2),
533
534     .vp9_enc_profiles = VP9_PROFILE_MASK(0),
535
536     .h264_dec_chroma_formats = EXTRA_H264_DEC_CHROMA_FORMATS,
537     .jpeg_dec_chroma_formats = EXTRA_JPEG_DEC_CHROMA_FORMATS,
538     .jpeg_enc_chroma_formats = EXTRA_JPEG_ENC_CHROMA_FORMATS,
539     .hevc_dec_chroma_formats = EXTRA_HEVC_DEC_CHROMA_FORMATS,
540     .vp9_dec_chroma_formats = EXTRA_VP9_DEC_CHROMA_FORMATS,
541
542     .has_mpeg2_decoding = 1,
543     .has_h264_decoding = 1,
544     .has_h264_encoding = 1,
545     .has_vc1_decoding = 1,
546     .has_jpeg_decoding = 1,
547     .has_jpeg_encoding = 1,
548     .has_vpp = 1,
549     .has_accelerated_getimage = 1,
550     .has_accelerated_putimage = 1,
551     .has_tiled_surface = 1,
552     .has_di_motion_adptive = 1,
553     .has_di_motion_compensated = 1,
554     .has_vp8_decoding = 1,
555     .has_vp8_encoding = 1,
556     .has_h264_mvc_encoding = 1,
557     .has_hevc_decoding = 1,
558     .has_hevc_encoding = 1,
559     .has_hevc10_decoding = 1,
560     .has_hevc10_encoding = 1,
561     .has_vp9_decoding = 1,
562     .has_vpp_p010 = 1,
563     .has_vp9_encoding = 1,
564     .has_lp_h264_encoding = 1,
565
566     .lp_h264_brc_mode = VA_RC_CQP,
567     .h264_brc_mode = VA_RC_CQP | VA_RC_CBR | VA_RC_VBR | VA_RC_MB,
568
569     .num_filters = 5,
570     .filters = {
571         { VAProcFilterNoiseReduction, I965_RING_VEBOX },
572         { VAProcFilterDeinterlacing, I965_RING_VEBOX },
573         { VAProcFilterSharpening, I965_RING_NULL },
574         { VAProcFilterColorBalance, I965_RING_VEBOX},
575         { VAProcFilterSkinToneEnhancement, I965_RING_VEBOX},
576     },
577 };
578
579 static struct hw_codec_info cfl_hw_codec_info = {
580     .dec_hw_context_init = gen9_dec_hw_context_init,
581     .enc_hw_context_init = gen9_enc_hw_context_init,
582     .proc_hw_context_init = gen75_proc_context_init,
583     .render_init = gen9_render_init,
584     .post_processing_context_init = gen9_post_processing_context_init,
585     .max_resolution = gen9_max_resolution,
586     .preinit_hw_codec = gen9_hw_codec_preinit,
587
588     .max_width = 4096,   /* default. See max_resolution */
589     .max_height = 4096,  /* default. See max_resolution */
590     .min_linear_wpitch = 64,
591     .min_linear_hpitch = 16,
592
593     .h264_mvc_dec_profiles = (VA_PROFILE_MASK(H264StereoHigh) |
594     VA_PROFILE_MASK(H264MultiviewHigh)),
595     .vp9_dec_profiles = VP9_PROFILE_MASK(0) |
596     VP9_PROFILE_MASK(2),
597     .vp9_enc_profiles = VP9_PROFILE_MASK(0),
598
599     .h264_dec_chroma_formats = EXTRA_H264_DEC_CHROMA_FORMATS,
600     .jpeg_dec_chroma_formats = EXTRA_JPEG_DEC_CHROMA_FORMATS,
601     .jpeg_enc_chroma_formats = EXTRA_JPEG_ENC_CHROMA_FORMATS,
602     .hevc_dec_chroma_formats = EXTRA_HEVC_DEC_CHROMA_FORMATS,
603     .vp9_dec_chroma_formats = EXTRA_VP9_DEC_CHROMA_FORMATS,
604
605     .has_mpeg2_decoding = 1,
606     .has_mpeg2_encoding = 1,
607     .has_h264_decoding = 1,
608     .has_h264_encoding = 1,
609     .has_vc1_decoding = 1,
610     .has_jpeg_decoding = 1,
611     .has_jpeg_encoding = 1,
612     .has_vpp = 1,
613     .has_accelerated_getimage = 1,
614     .has_accelerated_putimage = 1,
615     .has_tiled_surface = 1,
616     .has_di_motion_adptive = 1,
617     .has_di_motion_compensated = 1,
618     .has_vp8_decoding = 1,
619     .has_vp8_encoding = 1,
620     .has_h264_mvc_encoding = 1,
621     .has_hevc_decoding = 1,
622     .has_hevc_encoding = 1,
623     .has_hevc10_encoding = 1,
624     .has_hevc10_decoding = 1,
625     .has_vp9_decoding = 1,
626     .has_vpp_p010 = 1,
627     .has_vp9_encoding = 1,
628     .has_lp_h264_encoding = 1,
629
630     .lp_h264_brc_mode = VA_RC_CQP,
631     .h264_brc_mode = VA_RC_CQP | VA_RC_CBR | VA_RC_VBR | VA_RC_MB,
632
633     .num_filters = 5,
634     .filters = {
635         { VAProcFilterNoiseReduction, I965_RING_VEBOX },
636         { VAProcFilterDeinterlacing, I965_RING_VEBOX },
637         { VAProcFilterSharpening, I965_RING_NULL },
638         { VAProcFilterColorBalance, I965_RING_VEBOX},
639         { VAProcFilterSkinToneEnhancement, I965_RING_VEBOX},
640     },
641 };
642
643 struct hw_codec_info *
644 i965_get_codec_info(int devid)
645 {
646     switch (devid) {
647 #undef CHIPSET
648 #define CHIPSET(id, family, dev, str) case id: return &family##_hw_codec_info;
649 #include "i965_pciids.h"
650     default:
651         return NULL;
652     }
653 }
654
655 static const struct intel_device_info g4x_device_info = {
656     .gen = 4,
657
658     .urb_size = 384,
659     .max_wm_threads = 50,       /* 10 * 5 */
660
661     .is_g4x = 1,
662 };
663
664 static const struct intel_device_info ilk_device_info = {
665     .gen = 5,
666
667     .urb_size = 1024,
668     .max_wm_threads = 72,       /* 12 * 6 */
669 };
670
671 static const struct intel_device_info snb_gt1_device_info = {
672     .gen = 6,
673     .gt = 1,
674
675     .urb_size = 1024,
676     .max_wm_threads = 40,
677 };
678
679 static const struct intel_device_info snb_gt2_device_info = {
680     .gen = 6,
681     .gt = 2,
682
683     .urb_size = 1024,
684     .max_wm_threads = 80,
685 };
686
687 static const struct intel_device_info ivb_gt1_device_info = {
688     .gen = 7,
689     .gt = 1,
690
691     .urb_size = 4096,
692     .max_wm_threads = 48,
693
694     .is_ivybridge = 1,
695 };
696
697 static const struct intel_device_info ivb_gt2_device_info = {
698     .gen = 7,
699     .gt = 2,
700
701     .urb_size = 4096,
702     .max_wm_threads = 172,
703
704     .is_ivybridge = 1,
705 };
706
707 static const struct intel_device_info byt_device_info = {
708     .gen = 7,
709     .gt = 1,
710
711     .urb_size = 4096,
712     .max_wm_threads = 48,
713
714     .is_ivybridge = 1,
715     .is_baytrail = 1,
716 };
717
718 static const struct intel_device_info hsw_gt1_device_info = {
719     .gen = 7,
720     .gt = 1,
721
722     .urb_size = 4096,
723     .max_wm_threads = 102,
724
725     .is_haswell = 1,
726 };
727
728 static const struct intel_device_info hsw_gt2_device_info = {
729     .gen = 7,
730     .gt = 2,
731
732     .urb_size = 4096,
733     .max_wm_threads = 204,
734
735     .is_haswell = 1,
736 };
737
738 static const struct intel_device_info hsw_gt3_device_info = {
739     .gen = 7,
740     .gt = 3,
741
742     .urb_size = 4096,
743     .max_wm_threads = 408,
744
745     .is_haswell = 1,
746 };
747
748 static const struct intel_device_info bdw_device_info = {
749     .gen = 8,
750
751     .urb_size = 4096,
752     .max_wm_threads = 64,       /* per PSD */
753 };
754
755 static const struct intel_device_info chv_device_info = {
756     .gen = 8,
757
758     .urb_size = 4096,
759     .max_wm_threads = 64,       /* per PSD */
760
761     .is_cherryview = 1,
762 };
763
764 static const struct intel_device_info skl_device_info = {
765     .gen = 9,
766
767     .urb_size = 4096,
768     .max_wm_threads = 64,       /* per PSD */
769
770     .is_skylake = 1,
771 };
772
773 static const struct intel_device_info bxt_device_info = {
774     .gen = 9,
775
776     .urb_size = 4096,
777     .max_wm_threads = 64,       /* per PSD */
778     .is_broxton = 1,
779 };
780
781 static const struct intel_device_info kbl_device_info = {
782     .gen = 9,
783
784     .urb_size = 4096,
785     .max_wm_threads = 64,       /* per PSD */
786
787     .is_kabylake = 1,
788 };
789
790 static const struct intel_device_info glk_device_info = {
791     .gen = 9,
792
793     .urb_size = 4096,
794     .max_wm_threads = 64,       /* per PSD */
795
796     .is_glklake = 1,
797 };
798
799 static const struct intel_device_info cfl_device_info = {
800     .gen = 9,
801
802     .urb_size = 4096,
803     .max_wm_threads = 64,       /* per PSD */
804
805     .is_cfllake = 1,
806 };
807
808 const struct intel_device_info *
809 i965_get_device_info(int devid)
810 {
811     switch (devid) {
812 #undef CHIPSET
813 #define CHIPSET(id, family, dev, str) case id: return &dev##_device_info;
814 #include "i965_pciids.h"
815     default:
816         return NULL;
817     }
818 }
819
820 static void cpuid(unsigned int op,
821                   uint32_t *eax, uint32_t *ebx,
822                   uint32_t *ecx, uint32_t *edx)
823 {
824     __cpuid_count(op, 0, *eax, *ebx, *ecx, *edx);
825 }
826
827 /*
828  * This function doesn't check the length. And the caller should
829  * assure that the length of input string should be greater than 48.
830  */
831 static int intel_driver_detect_cpustring(char *model_id)
832 {
833     uint32_t *rdata;
834
835     if (model_id == NULL)
836         return -EINVAL;
837
838     rdata = (uint32_t *)model_id;
839
840     /* obtain the max supported extended CPUID info */
841     cpuid(0x80000000, &rdata[0], &rdata[1], &rdata[2], &rdata[3]);
842
843     /* If the max extended CPUID info is less than 0x80000004, fail */
844     if (rdata[0] < 0x80000004)
845         return -EINVAL;
846
847     /* obtain the CPUID string */
848     cpuid(0x80000002, &rdata[0], &rdata[1], &rdata[2], &rdata[3]);
849     cpuid(0x80000003, &rdata[4], &rdata[5], &rdata[6], &rdata[7]);
850     cpuid(0x80000004, &rdata[8], &rdata[9], &rdata[10], &rdata[11]);
851
852     *(model_id + 48) = '\0';
853     return 0;
854 }
855
856 /*
857  * the hook_list for HSW.
858  * It is captured by /proc/cpuinfo and the space character is stripped.
859  */
860 const static char *hsw_cpu_hook_list[] =  {
861     "Intel(R)Pentium(R)3556U",
862     "Intel(R)Pentium(R)3560Y",
863     "Intel(R)Pentium(R)3550M",
864     "Intel(R)Celeron(R)2980U",
865     "Intel(R)Celeron(R)2955U",
866     "Intel(R)Celeron(R)2950M",
867 };
868
869 static void hsw_hw_codec_preinit(VADriverContextP ctx, struct hw_codec_info *codec_info)
870 {
871     char model_string[64];
872     char *model_ptr, *tmp_ptr;
873     int i, model_len, list_len;
874     bool found;
875
876     memset(model_string, 0, sizeof(model_string));
877
878     /* If it can't detect cpu model_string, leave it alone */
879     if (intel_driver_detect_cpustring(model_string))
880         return;
881
882     /* strip the cpufreq info */
883     model_ptr = model_string;
884     tmp_ptr = strstr(model_ptr, "@");
885
886     if (tmp_ptr)
887         *tmp_ptr = '\0';
888
889     /* strip the space character and convert to the lower case */
890     model_ptr = model_string;
891     model_len = strlen(model_string);
892     for (i = 0; i < model_len; i++) {
893         if (model_string[i] != ' ') {
894             *model_ptr = model_string[i];
895             model_ptr++;
896         }
897     }
898     *model_ptr = '\0';
899
900     found = false;
901     list_len = sizeof(hsw_cpu_hook_list) / sizeof(char *);
902     model_len = strlen(model_string);
903     for (i = 0; i < list_len; i++) {
904         model_ptr = (char *)hsw_cpu_hook_list[i];
905
906         if (strlen(model_ptr) != model_len)
907             continue;
908
909         if (strncasecmp(model_string, model_ptr, model_len) == 0) {
910             found = true;
911             break;
912         }
913     }
914
915     if (found) {
916         codec_info->has_h264_encoding = 0;
917         codec_info->has_h264_mvc_encoding = 0;
918         codec_info->has_mpeg2_encoding = 0;
919     }
920     return;
921 }
922
923 /*
924  * the hook_list for Sandybride.
925  * It is captured by /proc/cpuinfo and the space character is stripped.
926  */
927 const static char *gen6_cpu_hook_list[] =  {
928     "Intel(R)Celeron(R)CPU847",
929     "Intel(R)Celeron(R)CPU867",
930 };
931
932 static void gen6_hw_codec_preinit(VADriverContextP ctx, struct hw_codec_info *codec_info)
933 {
934     char model_string[64];
935     char *model_ptr, *tmp_ptr;
936     int i, model_len, list_len;
937     bool found;
938
939     memset(model_string, 0, sizeof(model_string));
940
941     /* If it can't detect cpu model_string, leave it alone */
942     if (intel_driver_detect_cpustring(model_string))
943         return;
944
945     /* strip the cpufreq info */
946     model_ptr = model_string;
947     tmp_ptr = strstr(model_ptr, "@");
948
949     if (tmp_ptr)
950         *tmp_ptr = '\0';
951
952     /* strip the space character and convert to the lower case */
953     model_ptr = model_string;
954     model_len = strlen(model_string);
955     for (i = 0; i < model_len; i++) {
956         if (model_string[i] != ' ') {
957             *model_ptr = model_string[i];
958             model_ptr++;
959         }
960     }
961     *model_ptr = '\0';
962
963     found = false;
964     list_len = sizeof(gen6_cpu_hook_list) / sizeof(char *);
965     model_len = strlen(model_string);
966     for (i = 0; i < list_len; i++) {
967         model_ptr = (char *)gen6_cpu_hook_list[i];
968
969         if (strlen(model_ptr) != model_len)
970             continue;
971
972         if (strncasecmp(model_string, model_ptr, model_len) == 0) {
973             found = true;
974             break;
975         }
976     }
977
978     if (found) {
979         codec_info->has_h264_encoding = 0;
980     }
981     return;
982 }
983
984 /*
985  * the hook_list for Ivybridge.
986  * It is captured by /proc/cpuinfo and the space character is stripped.
987  */
988 const static char *gen7_cpu_hook_list[] =  {
989     "Intel(R)Celeron(R)CPU1007U",
990     "Intel(R)Celeron(R)CPU1037U",
991     "Intel(R)Pentium(R)CPUG2130",
992 };
993
994 static void gen7_hw_codec_preinit(VADriverContextP ctx, struct hw_codec_info *codec_info)
995 {
996     char model_string[64];
997     char *model_ptr, *tmp_ptr;
998     int i, model_len, list_len;
999     bool found;
1000
1001     memset(model_string, 0, sizeof(model_string));
1002
1003     /* If it can't detect cpu model_string, leave it alone */
1004     if (intel_driver_detect_cpustring(model_string))
1005         return;
1006
1007     /* strip the cpufreq info */
1008     model_ptr = model_string;
1009     tmp_ptr = strstr(model_ptr, "@");
1010
1011     if (tmp_ptr)
1012         *tmp_ptr = '\0';
1013
1014     /* strip the space character and convert to the lower case */
1015     model_ptr = model_string;
1016     model_len = strlen(model_string);
1017     for (i = 0; i < model_len; i++) {
1018         if (model_string[i] != ' ') {
1019             *model_ptr = model_string[i];
1020             model_ptr++;
1021         }
1022     }
1023     *model_ptr = '\0';
1024
1025     found = false;
1026     list_len = sizeof(gen7_cpu_hook_list) / sizeof(char *);
1027     model_len = strlen(model_string);
1028     for (i = 0; i < list_len; i++) {
1029         model_ptr = (char *)gen7_cpu_hook_list[i];
1030
1031         if (strlen(model_ptr) != model_len)
1032             continue;
1033
1034         if (strncasecmp(model_string, model_ptr, model_len) == 0) {
1035             found = true;
1036             break;
1037         }
1038     }
1039
1040     if (found) {
1041         codec_info->has_h264_encoding = 0;
1042         codec_info->has_mpeg2_encoding = 0;
1043     }
1044     return;
1045 }
1046
1047 static void gen9_hw_codec_preinit(VADriverContextP ctx, struct hw_codec_info *codec_info)
1048 {
1049     struct i965_driver_data *i965 = i965_driver_data(ctx);
1050
1051     if (i965->intel.has_huc && codec_info->has_lp_h264_encoding)
1052         codec_info->lp_h264_brc_mode |= (VA_RC_CBR | VA_RC_VBR);
1053 }