OSDN Git Service

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