OSDN Git Service

Fix a typo
[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     .has_h264_preenc = 1,
378
379     .lp_h264_brc_mode = VA_RC_CQP,
380     .h264_brc_mode = VA_RC_CQP | VA_RC_CBR | VA_RC_VBR | VA_RC_MB,
381
382     .num_filters = 5,
383     .filters = {
384         { VAProcFilterNoiseReduction, I965_RING_VEBOX },
385         { VAProcFilterDeinterlacing, I965_RING_VEBOX },
386         { VAProcFilterSharpening, I965_RING_NULL }, /* need to rebuild the shader for BDW */
387         { VAProcFilterColorBalance, I965_RING_VEBOX},
388         { VAProcFilterSkinToneEnhancement, I965_RING_VEBOX},
389     },
390 };
391
392
393 static struct hw_codec_info bxt_hw_codec_info = {
394     .dec_hw_context_init = gen9_dec_hw_context_init,
395     .enc_hw_context_init = gen9_enc_hw_context_init,
396     .proc_hw_context_init = gen75_proc_context_init,
397     .render_init = gen9_render_init,
398     .post_processing_context_init = gen9_post_processing_context_init,
399     .max_resolution = gen9_max_resolution,
400     .preinit_hw_codec = gen9_hw_codec_preinit,
401
402     .max_width = 4096,  /* default. See max_resolution */
403     .max_height = 4096, /* default. See max_resolution */
404     .min_linear_wpitch = 64,
405     .min_linear_hpitch = 4,
406
407     .h264_mvc_dec_profiles = (VA_PROFILE_MASK(H264StereoHigh) |
408     VA_PROFILE_MASK(H264MultiviewHigh)),
409     .vp9_dec_profiles = VP9_PROFILE_MASK(0),
410
411     .h264_dec_chroma_formats = EXTRA_H264_DEC_CHROMA_FORMATS,
412     .jpeg_dec_chroma_formats = EXTRA_JPEG_DEC_CHROMA_FORMATS,
413     .jpeg_enc_chroma_formats = EXTRA_JPEG_ENC_CHROMA_FORMATS,
414     .hevc_dec_chroma_formats = EXTRA_HEVC_DEC_CHROMA_FORMATS,
415
416     .has_mpeg2_decoding = 1,
417     .has_h264_decoding = 1,
418     .has_h264_encoding = 1,
419     .has_vc1_decoding = 1,
420     .has_jpeg_decoding = 1,
421     .has_jpeg_encoding = 1,
422     .has_vpp = 1,
423     .has_accelerated_getimage = 1,
424     .has_accelerated_putimage = 1,
425     .has_tiled_surface = 1,
426     .has_di_motion_adptive = 1,
427     .has_di_motion_compensated = 1,
428     .has_vp8_decoding = 1,
429     .has_vp8_encoding = 1,
430     .has_h264_mvc_encoding = 1,
431     .has_hevc_decoding = 1,
432     .has_hevc_encoding = 1,
433     .has_hevc10_decoding = 1,
434     .has_vp9_decoding = 1,
435     .has_vpp_p010 = 1,
436     .has_lp_h264_encoding = 1,
437
438     .lp_h264_brc_mode = VA_RC_CQP,
439     .h264_brc_mode = VA_RC_CQP | VA_RC_CBR | VA_RC_VBR | VA_RC_MB,
440
441     .num_filters = 5,
442     .filters = {
443         { VAProcFilterNoiseReduction, I965_RING_VEBOX },
444         { VAProcFilterDeinterlacing, I965_RING_VEBOX },
445         { VAProcFilterSharpening, I965_RING_NULL },
446         { VAProcFilterColorBalance, I965_RING_VEBOX},
447         { VAProcFilterSkinToneEnhancement, I965_RING_VEBOX},
448     },
449 };
450
451 static struct hw_codec_info kbl_hw_codec_info = {
452     .dec_hw_context_init = gen9_dec_hw_context_init,
453     .enc_hw_context_init = gen9_enc_hw_context_init,
454     .proc_hw_context_init = gen75_proc_context_init,
455     .render_init = gen9_render_init,
456     .post_processing_context_init = gen9_post_processing_context_init,
457     .max_resolution = gen9_max_resolution,
458     .preinit_hw_codec = gen9_hw_codec_preinit,
459
460     .max_width = 4096,   /* default. See max_resolution */
461     .max_height = 4096,  /* default. See max_resolution */
462     .min_linear_wpitch = 64,
463     .min_linear_hpitch = 4,
464
465     .h264_mvc_dec_profiles = (VA_PROFILE_MASK(H264StereoHigh) |
466     VA_PROFILE_MASK(H264MultiviewHigh)),
467     .vp9_dec_profiles = VP9_PROFILE_MASK(0) |
468     VP9_PROFILE_MASK(2),
469     .vp9_enc_profiles = VP9_PROFILE_MASK(0),
470
471     .h264_dec_chroma_formats = EXTRA_H264_DEC_CHROMA_FORMATS,
472     .jpeg_dec_chroma_formats = EXTRA_JPEG_DEC_CHROMA_FORMATS,
473     .jpeg_enc_chroma_formats = EXTRA_JPEG_ENC_CHROMA_FORMATS,
474     .hevc_dec_chroma_formats = EXTRA_HEVC_DEC_CHROMA_FORMATS,
475     .vp9_dec_chroma_formats = EXTRA_VP9_DEC_CHROMA_FORMATS,
476
477     .has_mpeg2_decoding = 1,
478     .has_mpeg2_encoding = 1,
479     .has_h264_decoding = 1,
480     .has_h264_encoding = 1,
481     .has_vc1_decoding = 1,
482     .has_jpeg_decoding = 1,
483     .has_jpeg_encoding = 1,
484     .has_vpp = 1,
485     .has_accelerated_getimage = 1,
486     .has_accelerated_putimage = 1,
487     .has_tiled_surface = 1,
488     .has_di_motion_adptive = 1,
489     .has_di_motion_compensated = 1,
490     .has_vp8_decoding = 1,
491     .has_vp8_encoding = 1,
492     .has_h264_mvc_encoding = 1,
493     .has_hevc_decoding = 1,
494     .has_hevc_encoding = 1,
495     .has_hevc10_encoding = 1,
496     .has_hevc10_decoding = 1,
497     .has_vp9_decoding = 1,
498     .has_vpp_p010 = 1,
499     .has_vp9_encoding = 1,
500     .has_lp_h264_encoding = 1,
501
502     .lp_h264_brc_mode = VA_RC_CQP,
503     .h264_brc_mode = VA_RC_CQP | VA_RC_CBR | VA_RC_VBR | VA_RC_MB,
504
505     .vp9_brc_mode = VA_RC_CQP | VA_RC_CBR | VA_RC_VBR,
506
507     .num_filters = 5,
508     .filters = {
509         { VAProcFilterNoiseReduction, I965_RING_VEBOX },
510         { VAProcFilterDeinterlacing, I965_RING_VEBOX },
511         { VAProcFilterSharpening, I965_RING_NULL },
512         { VAProcFilterColorBalance, I965_RING_VEBOX},
513         { VAProcFilterSkinToneEnhancement, I965_RING_VEBOX},
514     },
515 };
516
517 static struct hw_codec_info glk_hw_codec_info = {
518     .dec_hw_context_init = gen9_dec_hw_context_init,
519     .enc_hw_context_init = gen9_enc_hw_context_init,
520     .proc_hw_context_init = gen75_proc_context_init,
521     .render_init = gen9_render_init,
522     .post_processing_context_init = gen9_post_processing_context_init,
523
524     .max_resolution = gen9_max_resolution,
525     .preinit_hw_codec = gen9_hw_codec_preinit,
526
527     .max_width = 4096,
528     .max_height = 4096,
529     .min_linear_wpitch = 64,
530     .min_linear_hpitch = 4,
531
532     .h264_mvc_dec_profiles = (VA_PROFILE_MASK(H264StereoHigh) |
533     VA_PROFILE_MASK(H264MultiviewHigh)),
534     .vp9_dec_profiles = VP9_PROFILE_MASK(0) |
535     VP9_PROFILE_MASK(2),
536
537     .vp9_enc_profiles = VP9_PROFILE_MASK(0),
538
539     .h264_dec_chroma_formats = EXTRA_H264_DEC_CHROMA_FORMATS,
540     .jpeg_dec_chroma_formats = EXTRA_JPEG_DEC_CHROMA_FORMATS,
541     .jpeg_enc_chroma_formats = EXTRA_JPEG_ENC_CHROMA_FORMATS,
542     .hevc_dec_chroma_formats = EXTRA_HEVC_DEC_CHROMA_FORMATS,
543     .vp9_dec_chroma_formats = EXTRA_VP9_DEC_CHROMA_FORMATS,
544
545     .has_mpeg2_decoding = 1,
546     .has_h264_decoding = 1,
547     .has_h264_encoding = 1,
548     .has_vc1_decoding = 1,
549     .has_jpeg_decoding = 1,
550     .has_jpeg_encoding = 1,
551     .has_vpp = 1,
552     .has_accelerated_getimage = 1,
553     .has_accelerated_putimage = 1,
554     .has_tiled_surface = 1,
555     .has_di_motion_adptive = 1,
556     .has_di_motion_compensated = 1,
557     .has_vp8_decoding = 1,
558     .has_vp8_encoding = 1,
559     .has_h264_mvc_encoding = 1,
560     .has_hevc_decoding = 1,
561     .has_hevc_encoding = 1,
562     .has_hevc10_decoding = 1,
563     .has_hevc10_encoding = 1,
564     .has_vp9_decoding = 1,
565     .has_vpp_p010 = 1,
566     .has_vp9_encoding = 1,
567     .has_lp_h264_encoding = 1,
568
569     .lp_h264_brc_mode = VA_RC_CQP,
570     .h264_brc_mode = VA_RC_CQP | VA_RC_CBR | VA_RC_VBR | VA_RC_MB,
571
572     .vp9_brc_mode = VA_RC_CQP | VA_RC_CBR | VA_RC_VBR,
573
574     .num_filters = 5,
575     .filters = {
576         { VAProcFilterNoiseReduction, I965_RING_VEBOX },
577         { VAProcFilterDeinterlacing, I965_RING_VEBOX },
578         { VAProcFilterSharpening, I965_RING_NULL },
579         { VAProcFilterColorBalance, I965_RING_VEBOX},
580         { VAProcFilterSkinToneEnhancement, I965_RING_VEBOX},
581     },
582 };
583
584 static struct hw_codec_info cfl_hw_codec_info = {
585     .dec_hw_context_init = gen9_dec_hw_context_init,
586     .enc_hw_context_init = gen9_enc_hw_context_init,
587     .proc_hw_context_init = gen75_proc_context_init,
588     .render_init = gen9_render_init,
589     .post_processing_context_init = gen9_post_processing_context_init,
590     .max_resolution = gen9_max_resolution,
591     .preinit_hw_codec = gen9_hw_codec_preinit,
592
593     .max_width = 4096,   /* default. See max_resolution */
594     .max_height = 4096,  /* default. See max_resolution */
595     .min_linear_wpitch = 64,
596     .min_linear_hpitch = 16,
597
598     .h264_mvc_dec_profiles = (VA_PROFILE_MASK(H264StereoHigh) |
599     VA_PROFILE_MASK(H264MultiviewHigh)),
600     .vp9_dec_profiles = VP9_PROFILE_MASK(0) |
601     VP9_PROFILE_MASK(2),
602     .vp9_enc_profiles = VP9_PROFILE_MASK(0),
603
604     .h264_dec_chroma_formats = EXTRA_H264_DEC_CHROMA_FORMATS,
605     .jpeg_dec_chroma_formats = EXTRA_JPEG_DEC_CHROMA_FORMATS,
606     .jpeg_enc_chroma_formats = EXTRA_JPEG_ENC_CHROMA_FORMATS,
607     .hevc_dec_chroma_formats = EXTRA_HEVC_DEC_CHROMA_FORMATS,
608     .vp9_dec_chroma_formats = EXTRA_VP9_DEC_CHROMA_FORMATS,
609
610     .has_mpeg2_decoding = 1,
611     .has_mpeg2_encoding = 1,
612     .has_h264_decoding = 1,
613     .has_h264_encoding = 1,
614     .has_vc1_decoding = 1,
615     .has_jpeg_decoding = 1,
616     .has_jpeg_encoding = 1,
617     .has_vpp = 1,
618     .has_accelerated_getimage = 1,
619     .has_accelerated_putimage = 1,
620     .has_tiled_surface = 1,
621     .has_di_motion_adptive = 1,
622     .has_di_motion_compensated = 1,
623     .has_vp8_decoding = 1,
624     .has_vp8_encoding = 1,
625     .has_h264_mvc_encoding = 1,
626     .has_hevc_decoding = 1,
627     .has_hevc_encoding = 1,
628     .has_hevc10_encoding = 1,
629     .has_hevc10_decoding = 1,
630     .has_vp9_decoding = 1,
631     .has_vpp_p010 = 1,
632     .has_vp9_encoding = 1,
633     .has_lp_h264_encoding = 1,
634
635     .lp_h264_brc_mode = VA_RC_CQP,
636     .h264_brc_mode = VA_RC_CQP | VA_RC_CBR | VA_RC_VBR | VA_RC_MB,
637
638     .vp9_brc_mode = VA_RC_CQP | VA_RC_CBR | VA_RC_VBR,
639
640     .num_filters = 5,
641     .filters = {
642         { VAProcFilterNoiseReduction, I965_RING_VEBOX },
643         { VAProcFilterDeinterlacing, I965_RING_VEBOX },
644         { VAProcFilterSharpening, I965_RING_NULL },
645         { VAProcFilterColorBalance, I965_RING_VEBOX},
646         { VAProcFilterSkinToneEnhancement, I965_RING_VEBOX},
647     },
648 };
649
650 static struct hw_codec_info cnl_hw_codec_info = {
651     .dec_hw_context_init = gen9_dec_hw_context_init,
652     .enc_hw_context_init = gen9_enc_hw_context_init,
653     .proc_hw_context_init = gen75_proc_context_init,
654     .render_init = gen9_render_init,
655     .post_processing_context_init = gen9_post_processing_context_init,
656     .max_resolution = gen9_max_resolution,
657     .preinit_hw_codec = gen9_hw_codec_preinit,
658
659     .max_width = 4096,   /* default. See max_resolution */
660     .max_height = 4096,  /* default. See max_resolution */
661     .min_linear_wpitch = 64,
662     .min_linear_hpitch = 16,
663
664     .h264_mvc_dec_profiles = (VA_PROFILE_MASK(H264StereoHigh) | VA_PROFILE_MASK(H264MultiviewHigh)),
665     .vp9_dec_profiles = VP9_PROFILE_MASK(0) | VP9_PROFILE_MASK(2),
666     .vp9_enc_profiles = VP9_PROFILE_MASK(0),
667
668     .h264_dec_chroma_formats = EXTRA_H264_DEC_CHROMA_FORMATS,
669     .jpeg_dec_chroma_formats = EXTRA_JPEG_DEC_CHROMA_FORMATS,
670     .jpeg_enc_chroma_formats = EXTRA_JPEG_ENC_CHROMA_FORMATS,
671     .hevc_dec_chroma_formats = EXTRA_HEVC_DEC_CHROMA_FORMATS,
672     .vp9_dec_chroma_formats = EXTRA_VP9_DEC_CHROMA_FORMATS,
673
674     .has_mpeg2_decoding = 1,
675     .has_mpeg2_encoding = 1,
676     .has_h264_decoding = 1,
677     .has_h264_encoding = 1,
678     .has_vc1_decoding = 1,
679     .has_jpeg_decoding = 1,
680     .has_jpeg_encoding = 1,
681     .has_vpp = 1,
682     .has_accelerated_getimage = 1,
683     .has_accelerated_putimage = 1,
684     .has_tiled_surface = 1,
685     .has_di_motion_adptive = 1,
686     .has_di_motion_compensated = 1,
687     .has_vp8_decoding = 1,
688     .has_vp8_encoding = 1,
689     .has_h264_mvc_encoding = 1,
690     .has_hevc_decoding = 1,
691     .has_hevc_encoding = 1,
692     .has_hevc10_decoding = 1,
693     .has_hevc10_encoding = 1,
694     .has_vp9_decoding = 1,
695     .has_vpp_p010 = 1,
696     .has_vp9_encoding = 1,
697     .has_lp_h264_encoding = 1,
698     .has_lp_vp9_encoding = 1,
699
700     .lp_h264_brc_mode = VA_RC_CQP,
701     .h264_brc_mode = VA_RC_CQP | VA_RC_CBR | VA_RC_VBR | VA_RC_MB,
702
703     .vp9_brc_mode = VA_RC_CQP | VA_RC_CBR | VA_RC_VBR,
704
705     .num_filters = 5,
706     .filters = {
707         { VAProcFilterNoiseReduction, I965_RING_VEBOX },
708         { VAProcFilterDeinterlacing, I965_RING_VEBOX },
709         { VAProcFilterSharpening, I965_RING_NULL },
710         { VAProcFilterColorBalance, I965_RING_VEBOX},
711         { VAProcFilterSkinToneEnhancement, I965_RING_VEBOX},
712     },
713 };
714
715 struct hw_codec_info *
716 i965_get_codec_info(int devid)
717 {
718     switch (devid) {
719 #undef CHIPSET
720 #define CHIPSET(id, family, dev, str) case id: return &family##_hw_codec_info;
721 #include "i965_pciids.h"
722     default:
723         return NULL;
724     }
725 }
726
727 static const struct intel_device_info g4x_device_info = {
728     .gen = 4,
729
730     .urb_size = 384,
731     .max_wm_threads = 50,       /* 10 * 5 */
732
733     .is_g4x = 1,
734 };
735
736 static const struct intel_device_info ilk_device_info = {
737     .gen = 5,
738
739     .urb_size = 1024,
740     .max_wm_threads = 72,       /* 12 * 6 */
741 };
742
743 static const struct intel_device_info snb_gt1_device_info = {
744     .gen = 6,
745     .gt = 1,
746
747     .urb_size = 1024,
748     .max_wm_threads = 40,
749 };
750
751 static const struct intel_device_info snb_gt2_device_info = {
752     .gen = 6,
753     .gt = 2,
754
755     .urb_size = 1024,
756     .max_wm_threads = 80,
757 };
758
759 static const struct intel_device_info ivb_gt1_device_info = {
760     .gen = 7,
761     .gt = 1,
762
763     .urb_size = 4096,
764     .max_wm_threads = 48,
765
766     .is_ivybridge = 1,
767 };
768
769 static const struct intel_device_info ivb_gt2_device_info = {
770     .gen = 7,
771     .gt = 2,
772
773     .urb_size = 4096,
774     .max_wm_threads = 172,
775
776     .is_ivybridge = 1,
777 };
778
779 static const struct intel_device_info byt_device_info = {
780     .gen = 7,
781     .gt = 1,
782
783     .urb_size = 4096,
784     .max_wm_threads = 48,
785
786     .is_ivybridge = 1,
787     .is_baytrail = 1,
788 };
789
790 static const struct intel_device_info hsw_gt1_device_info = {
791     .gen = 7,
792     .gt = 1,
793
794     .urb_size = 4096,
795     .max_wm_threads = 102,
796
797     .is_haswell = 1,
798 };
799
800 static const struct intel_device_info hsw_gt2_device_info = {
801     .gen = 7,
802     .gt = 2,
803
804     .urb_size = 4096,
805     .max_wm_threads = 204,
806
807     .is_haswell = 1,
808 };
809
810 static const struct intel_device_info hsw_gt3_device_info = {
811     .gen = 7,
812     .gt = 3,
813
814     .urb_size = 4096,
815     .max_wm_threads = 408,
816
817     .is_haswell = 1,
818 };
819
820 static const struct intel_device_info bdw_device_info = {
821     .gen = 8,
822
823     .urb_size = 4096,
824     .max_wm_threads = 64,       /* per PSD */
825 };
826
827 static const struct intel_device_info chv_device_info = {
828     .gen = 8,
829
830     .urb_size = 4096,
831     .max_wm_threads = 64,       /* per PSD */
832
833     .is_cherryview = 1,
834 };
835
836 static const struct intel_device_info skl_device_info = {
837     .gen = 9,
838
839     .urb_size = 4096,
840     .max_wm_threads = 64,       /* per PSD */
841
842     .is_skylake = 1,
843 };
844
845 static const struct intel_device_info bxt_device_info = {
846     .gen = 9,
847
848     .urb_size = 4096,
849     .max_wm_threads = 64,       /* per PSD */
850     .is_broxton = 1,
851 };
852
853 static const struct intel_device_info kbl_device_info = {
854     .gen = 9,
855
856     .urb_size = 4096,
857     .max_wm_threads = 64,       /* per PSD */
858
859     .is_kabylake = 1,
860 };
861
862 static const struct intel_device_info glk_device_info = {
863     .gen = 9,
864
865     .urb_size = 4096,
866     .max_wm_threads = 64,       /* per PSD */
867
868     .is_glklake = 1,
869 };
870
871 static const struct intel_device_info cfl_device_info = {
872     .gen = 9,
873
874     .urb_size = 4096,
875     .max_wm_threads = 64,       /* per PSD */
876
877     .is_cfllake = 1,
878 };
879
880 static const struct intel_device_info cnl_device_info = {
881     .gen = 10,
882
883     .urb_size = 4096,
884     .max_wm_threads = 64,       /* per PSD */
885 };
886
887 const struct intel_device_info *
888 i965_get_device_info(int devid)
889 {
890     switch (devid) {
891 #undef CHIPSET
892 #define CHIPSET(id, family, dev, str) case id: return &dev##_device_info;
893 #include "i965_pciids.h"
894     default:
895         return NULL;
896     }
897 }
898
899 static void cpuid(unsigned int op,
900                   uint32_t *eax, uint32_t *ebx,
901                   uint32_t *ecx, uint32_t *edx)
902 {
903     __cpuid_count(op, 0, *eax, *ebx, *ecx, *edx);
904 }
905
906 /*
907  * This function doesn't check the length. And the caller should
908  * assure that the length of input string should be greater than 48.
909  */
910 static int intel_driver_detect_cpustring(char *model_id)
911 {
912     uint32_t *rdata;
913
914     if (model_id == NULL)
915         return -EINVAL;
916
917     rdata = (uint32_t *)model_id;
918
919     /* obtain the max supported extended CPUID info */
920     cpuid(0x80000000, &rdata[0], &rdata[1], &rdata[2], &rdata[3]);
921
922     /* If the max extended CPUID info is less than 0x80000004, fail */
923     if (rdata[0] < 0x80000004)
924         return -EINVAL;
925
926     /* obtain the CPUID string */
927     cpuid(0x80000002, &rdata[0], &rdata[1], &rdata[2], &rdata[3]);
928     cpuid(0x80000003, &rdata[4], &rdata[5], &rdata[6], &rdata[7]);
929     cpuid(0x80000004, &rdata[8], &rdata[9], &rdata[10], &rdata[11]);
930
931     *(model_id + 48) = '\0';
932     return 0;
933 }
934
935 /*
936  * the hook_list for HSW.
937  * It is captured by /proc/cpuinfo and the space character is stripped.
938  */
939 const static char *hsw_cpu_hook_list[] =  {
940     "Intel(R)Pentium(R)3556U",
941     "Intel(R)Pentium(R)3560Y",
942     "Intel(R)Pentium(R)3550M",
943     "Intel(R)Celeron(R)2980U",
944     "Intel(R)Celeron(R)2955U",
945     "Intel(R)Celeron(R)2950M",
946 };
947
948 static void hsw_hw_codec_preinit(VADriverContextP ctx, struct hw_codec_info *codec_info)
949 {
950     char model_string[64];
951     char *model_ptr, *tmp_ptr;
952     int i, model_len, list_len;
953     bool found;
954
955     memset(model_string, 0, sizeof(model_string));
956
957     /* If it can't detect cpu model_string, leave it alone */
958     if (intel_driver_detect_cpustring(model_string))
959         return;
960
961     /* strip the cpufreq info */
962     model_ptr = model_string;
963     tmp_ptr = strstr(model_ptr, "@");
964
965     if (tmp_ptr)
966         *tmp_ptr = '\0';
967
968     /* strip the space character and convert to the lower case */
969     model_ptr = model_string;
970     model_len = strlen(model_string);
971     for (i = 0; i < model_len; i++) {
972         if (model_string[i] != ' ') {
973             *model_ptr = model_string[i];
974             model_ptr++;
975         }
976     }
977     *model_ptr = '\0';
978
979     found = false;
980     list_len = sizeof(hsw_cpu_hook_list) / sizeof(char *);
981     model_len = strlen(model_string);
982     for (i = 0; i < list_len; i++) {
983         model_ptr = (char *)hsw_cpu_hook_list[i];
984
985         if (strlen(model_ptr) != model_len)
986             continue;
987
988         if (strncasecmp(model_string, model_ptr, model_len) == 0) {
989             found = true;
990             break;
991         }
992     }
993
994     if (found) {
995         codec_info->has_h264_encoding = 0;
996         codec_info->has_h264_mvc_encoding = 0;
997         codec_info->has_mpeg2_encoding = 0;
998     }
999     return;
1000 }
1001
1002 /*
1003  * the hook_list for Sandybride.
1004  * It is captured by /proc/cpuinfo and the space character is stripped.
1005  */
1006 const static char *gen6_cpu_hook_list[] =  {
1007     "Intel(R)Celeron(R)CPU847",
1008     "Intel(R)Celeron(R)CPU867",
1009 };
1010
1011 static void gen6_hw_codec_preinit(VADriverContextP ctx, struct hw_codec_info *codec_info)
1012 {
1013     char model_string[64];
1014     char *model_ptr, *tmp_ptr;
1015     int i, model_len, list_len;
1016     bool found;
1017
1018     memset(model_string, 0, sizeof(model_string));
1019
1020     /* If it can't detect cpu model_string, leave it alone */
1021     if (intel_driver_detect_cpustring(model_string))
1022         return;
1023
1024     /* strip the cpufreq info */
1025     model_ptr = model_string;
1026     tmp_ptr = strstr(model_ptr, "@");
1027
1028     if (tmp_ptr)
1029         *tmp_ptr = '\0';
1030
1031     /* strip the space character and convert to the lower case */
1032     model_ptr = model_string;
1033     model_len = strlen(model_string);
1034     for (i = 0; i < model_len; i++) {
1035         if (model_string[i] != ' ') {
1036             *model_ptr = model_string[i];
1037             model_ptr++;
1038         }
1039     }
1040     *model_ptr = '\0';
1041
1042     found = false;
1043     list_len = sizeof(gen6_cpu_hook_list) / sizeof(char *);
1044     model_len = strlen(model_string);
1045     for (i = 0; i < list_len; i++) {
1046         model_ptr = (char *)gen6_cpu_hook_list[i];
1047
1048         if (strlen(model_ptr) != model_len)
1049             continue;
1050
1051         if (strncasecmp(model_string, model_ptr, model_len) == 0) {
1052             found = true;
1053             break;
1054         }
1055     }
1056
1057     if (found) {
1058         codec_info->has_h264_encoding = 0;
1059     }
1060     return;
1061 }
1062
1063 /*
1064  * the hook_list for Ivybridge.
1065  * It is captured by /proc/cpuinfo and the space character is stripped.
1066  */
1067 const static char *gen7_cpu_hook_list[] =  {
1068     "Intel(R)Celeron(R)CPU1007U",
1069     "Intel(R)Celeron(R)CPU1037U",
1070     "Intel(R)Pentium(R)CPUG2130",
1071 };
1072
1073 static void gen7_hw_codec_preinit(VADriverContextP ctx, struct hw_codec_info *codec_info)
1074 {
1075     char model_string[64];
1076     char *model_ptr, *tmp_ptr;
1077     int i, model_len, list_len;
1078     bool found;
1079
1080     memset(model_string, 0, sizeof(model_string));
1081
1082     /* If it can't detect cpu model_string, leave it alone */
1083     if (intel_driver_detect_cpustring(model_string))
1084         return;
1085
1086     /* strip the cpufreq info */
1087     model_ptr = model_string;
1088     tmp_ptr = strstr(model_ptr, "@");
1089
1090     if (tmp_ptr)
1091         *tmp_ptr = '\0';
1092
1093     /* strip the space character and convert to the lower case */
1094     model_ptr = model_string;
1095     model_len = strlen(model_string);
1096     for (i = 0; i < model_len; i++) {
1097         if (model_string[i] != ' ') {
1098             *model_ptr = model_string[i];
1099             model_ptr++;
1100         }
1101     }
1102     *model_ptr = '\0';
1103
1104     found = false;
1105     list_len = sizeof(gen7_cpu_hook_list) / sizeof(char *);
1106     model_len = strlen(model_string);
1107     for (i = 0; i < list_len; i++) {
1108         model_ptr = (char *)gen7_cpu_hook_list[i];
1109
1110         if (strlen(model_ptr) != model_len)
1111             continue;
1112
1113         if (strncasecmp(model_string, model_ptr, model_len) == 0) {
1114             found = true;
1115             break;
1116         }
1117     }
1118
1119     if (found) {
1120         codec_info->has_h264_encoding = 0;
1121         codec_info->has_mpeg2_encoding = 0;
1122     }
1123     return;
1124 }
1125
1126 static void gen9_hw_codec_preinit(VADriverContextP ctx, struct hw_codec_info *codec_info)
1127 {
1128     struct i965_driver_data *i965 = i965_driver_data(ctx);
1129
1130     if (i965->intel.has_huc && codec_info->has_lp_h264_encoding)
1131         codec_info->lp_h264_brc_mode |= (VA_RC_CBR | VA_RC_VBR);
1132
1133     if (i965->intel.has_huc && codec_info->has_lp_vp9_encoding)
1134         codec_info->lp_vp9_brc_mode |= (VA_RC_CQP | VA_RC_CBR | VA_RC_VBR);
1135 }