OSDN Git Service

Export the Vp9 encoding profile/entrypoint for KBL
[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 = 128,
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 = 128,
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 extern struct hw_context *gen9_enc_hw_context_init(VADriverContextP, struct object_config *);
323 extern void gen9_post_processing_context_init(VADriverContextP, void *, struct intel_batchbuffer *);
324 static struct hw_codec_info skl_hw_codec_info = {
325     .dec_hw_context_init = gen9_dec_hw_context_init,
326     .enc_hw_context_init = gen9_enc_hw_context_init,
327     .proc_hw_context_init = gen75_proc_context_init,
328     .render_init = gen9_render_init,
329     .post_processing_context_init = gen9_post_processing_context_init,
330
331     .max_width = 4096,
332     .max_height = 4096,
333     .min_linear_wpitch = 128,
334     .min_linear_hpitch = 16,
335
336     .h264_mvc_dec_profiles = (VA_PROFILE_MASK(H264StereoHigh) |
337                               VA_PROFILE_MASK(H264MultiviewHigh)),
338     .h264_dec_chroma_formats = EXTRA_H264_DEC_CHROMA_FORMATS,
339     .jpeg_dec_chroma_formats = EXTRA_JPEG_DEC_CHROMA_FORMATS,
340     .jpeg_enc_chroma_formats = EXTRA_JPEG_ENC_CHROMA_FORMATS,
341
342     .has_mpeg2_decoding = 1,
343     .has_mpeg2_encoding = 1,
344     .has_h264_decoding = 1,
345     .has_h264_encoding = 1,
346     .has_vc1_decoding = 1,
347     .has_jpeg_decoding = 1,
348     .has_jpeg_encoding = 1,
349     .has_vpp = 1,
350     .has_accelerated_getimage = 1,
351     .has_accelerated_putimage = 1,
352     .has_tiled_surface = 1,
353     .has_di_motion_adptive = 1,
354     .has_di_motion_compensated = 1,
355     .has_vp8_decoding = 1,
356     .has_vp8_encoding = 1,
357     .has_h264_mvc_encoding = 1,
358     .has_hevc_decoding = 1,
359     .has_hevc_encoding = 1,
360     .has_lp_h264_encoding = 1,
361
362     .lp_h264_brc_mode = VA_RC_CQP,
363
364     .num_filters = 5,
365     .filters = {
366         { VAProcFilterNoiseReduction, I965_RING_VEBOX },
367         { VAProcFilterDeinterlacing, I965_RING_VEBOX },
368         { VAProcFilterSharpening, I965_RING_NULL }, /* need to rebuild the shader for BDW */
369         { VAProcFilterColorBalance, I965_RING_VEBOX},
370         { VAProcFilterSkinToneEnhancement, I965_RING_VEBOX},
371     },
372 };
373
374
375 static struct hw_codec_info bxt_hw_codec_info = {
376     .dec_hw_context_init = gen9_dec_hw_context_init,
377     .enc_hw_context_init = gen9_enc_hw_context_init,
378     .proc_hw_context_init = gen75_proc_context_init,
379     .render_init = gen9_render_init,
380     .post_processing_context_init = gen9_post_processing_context_init,
381
382     .max_width = 4096,
383     .max_height = 4096,
384     .min_linear_wpitch = 128,
385     .min_linear_hpitch = 16,
386
387     .h264_mvc_dec_profiles = (VA_PROFILE_MASK(H264StereoHigh) |
388                               VA_PROFILE_MASK(H264MultiviewHigh)),
389     .vp9_dec_profiles = VP9_PROFILE_MASK(0),
390
391     .h264_dec_chroma_formats = EXTRA_H264_DEC_CHROMA_FORMATS,
392     .jpeg_dec_chroma_formats = EXTRA_JPEG_DEC_CHROMA_FORMATS,
393     .jpeg_enc_chroma_formats = EXTRA_JPEG_ENC_CHROMA_FORMATS,
394     .hevc_dec_chroma_formats = EXTRA_HEVC_DEC_CHROMA_FORMATS,
395
396     .has_mpeg2_decoding = 1,
397     .has_h264_decoding = 1,
398     .has_h264_encoding = 1,
399     .has_vc1_decoding = 1,
400     .has_jpeg_decoding = 1,
401     .has_jpeg_encoding = 1,
402     .has_vpp = 1,
403     .has_accelerated_getimage = 1,
404     .has_accelerated_putimage = 1,
405     .has_tiled_surface = 1,
406     .has_di_motion_adptive = 1,
407     .has_di_motion_compensated = 1,
408     .has_vp8_decoding = 1,
409     .has_vp8_encoding = 1,
410     .has_h264_mvc_encoding = 1,
411     .has_hevc_decoding = 1,
412     .has_hevc_encoding = 1,
413     .has_hevc10_decoding = 1,
414     .has_vp9_decoding = 1,
415     .has_vpp_p010 = 1,
416
417     .num_filters = 5,
418     .filters = {
419         { VAProcFilterNoiseReduction, I965_RING_VEBOX },
420         { VAProcFilterDeinterlacing, I965_RING_VEBOX },
421         { VAProcFilterSharpening, I965_RING_NULL },
422         { VAProcFilterColorBalance, I965_RING_VEBOX},
423         { VAProcFilterSkinToneEnhancement, I965_RING_VEBOX},
424     },
425 };
426
427 static struct hw_codec_info kbl_hw_codec_info = {
428     .dec_hw_context_init = gen9_dec_hw_context_init,
429     .enc_hw_context_init = gen9_enc_hw_context_init,
430     .proc_hw_context_init = gen75_proc_context_init,
431     .render_init = gen9_render_init,
432     .post_processing_context_init = gen9_post_processing_context_init,
433
434     .max_width = 4096,
435     .max_height = 4096,
436     .min_linear_wpitch = 128,
437     .min_linear_hpitch = 16,
438
439     .h264_mvc_dec_profiles = (VA_PROFILE_MASK(H264StereoHigh) |
440                               VA_PROFILE_MASK(H264MultiviewHigh)),
441     .vp9_dec_profiles = VP9_PROFILE_MASK(0) |
442                         VP9_PROFILE_MASK(2),
443
444     .h264_dec_chroma_formats = EXTRA_H264_DEC_CHROMA_FORMATS,
445     .jpeg_dec_chroma_formats = EXTRA_JPEG_DEC_CHROMA_FORMATS,
446     .jpeg_enc_chroma_formats = EXTRA_JPEG_ENC_CHROMA_FORMATS,
447     .hevc_dec_chroma_formats = EXTRA_HEVC_DEC_CHROMA_FORMATS,
448     .vp9_dec_chroma_formats = EXTRA_VP9_DEC_CHROMA_FORMATS,
449
450     .has_mpeg2_decoding = 1,
451     .has_mpeg2_encoding = 1,
452     .has_h264_decoding = 1,
453     .has_h264_encoding = 1,
454     .has_vc1_decoding = 1,
455     .has_jpeg_decoding = 1,
456     .has_jpeg_encoding = 1,
457     .has_vpp = 1,
458     .has_accelerated_getimage = 1,
459     .has_accelerated_putimage = 1,
460     .has_tiled_surface = 1,
461     .has_di_motion_adptive = 1,
462     .has_di_motion_compensated = 1,
463     .has_vp8_decoding = 1,
464     .has_vp8_encoding = 1,
465     .has_h264_mvc_encoding = 1,
466     .has_hevc_decoding = 1,
467     .has_hevc_encoding = 1,
468     .has_hevc10_decoding = 1,
469     .has_vp9_decoding = 1,
470     .has_vpp_p010 = 1,
471     .has_vp9_encoding = 1,
472
473     .num_filters = 5,
474     .filters = {
475         { VAProcFilterNoiseReduction, I965_RING_VEBOX },
476         { VAProcFilterDeinterlacing, I965_RING_VEBOX },
477         { VAProcFilterSharpening, I965_RING_NULL },
478         { VAProcFilterColorBalance, I965_RING_VEBOX},
479         { VAProcFilterSkinToneEnhancement, I965_RING_VEBOX},
480     },
481 };
482
483 struct hw_codec_info *
484 i965_get_codec_info(int devid)
485 {
486     switch (devid) {
487 #undef CHIPSET
488 #define CHIPSET(id, family, dev, str) case id: return &family##_hw_codec_info;
489 #include "i965_pciids.h"
490     default:
491         return NULL;
492     }
493 }
494
495 static const struct intel_device_info g4x_device_info = {
496     .gen = 4,
497
498     .urb_size = 384,
499     .max_wm_threads = 50,       /* 10 * 5 */
500
501     .is_g4x = 1,
502 };
503
504 static const struct intel_device_info ilk_device_info = {
505     .gen = 5,
506
507     .urb_size = 1024,
508     .max_wm_threads = 72,       /* 12 * 6 */
509 };
510
511 static const struct intel_device_info snb_gt1_device_info = {
512     .gen = 6,
513     .gt = 1,
514
515     .urb_size = 1024,
516     .max_wm_threads = 40,
517 };
518
519 static const struct intel_device_info snb_gt2_device_info = {
520     .gen = 6,
521     .gt = 2,
522
523     .urb_size = 1024,
524     .max_wm_threads = 80,
525 };
526
527 static const struct intel_device_info ivb_gt1_device_info = {
528     .gen = 7,
529     .gt = 1,
530
531     .urb_size = 4096,
532     .max_wm_threads = 48,
533
534     .is_ivybridge = 1,
535 };
536
537 static const struct intel_device_info ivb_gt2_device_info = {
538     .gen = 7,
539     .gt = 2,
540
541     .urb_size = 4096,
542     .max_wm_threads = 172,
543
544     .is_ivybridge = 1,
545 };
546
547 static const struct intel_device_info byt_device_info = {
548     .gen = 7,
549     .gt = 1,
550
551     .urb_size = 4096,
552     .max_wm_threads = 48,
553
554     .is_ivybridge = 1,
555     .is_baytrail = 1,
556 };
557
558 static const struct intel_device_info hsw_gt1_device_info = {
559     .gen = 7,
560     .gt = 1,
561
562     .urb_size = 4096,
563     .max_wm_threads = 102,
564
565     .is_haswell = 1,
566 };
567
568 static const struct intel_device_info hsw_gt2_device_info = {
569     .gen = 7,
570     .gt = 2,
571
572     .urb_size = 4096,
573     .max_wm_threads = 204,
574
575     .is_haswell = 1,
576 };
577
578 static const struct intel_device_info hsw_gt3_device_info = {
579     .gen = 7,
580     .gt = 3,
581
582     .urb_size = 4096,
583     .max_wm_threads = 408,
584
585     .is_haswell = 1,
586 };
587
588 static const struct intel_device_info bdw_device_info = {
589     .gen = 8,
590
591     .urb_size = 4096,
592     .max_wm_threads = 64,       /* per PSD */
593 };
594
595 static const struct intel_device_info chv_device_info = {
596     .gen = 8,
597
598     .urb_size = 4096,
599     .max_wm_threads = 64,       /* per PSD */
600
601     .is_cherryview = 1,
602 };
603
604 static const struct intel_device_info skl_device_info = {
605     .gen = 9,
606
607     .urb_size = 4096,
608     .max_wm_threads = 64,       /* per PSD */
609
610     .is_skylake = 1,
611 };
612
613 static const struct intel_device_info bxt_device_info = {
614     .gen = 9,
615
616     .urb_size = 4096,
617     .max_wm_threads = 64,       /* per PSD */
618     .is_broxton = 1,
619 };
620
621 static const struct intel_device_info kbl_device_info = {
622     .gen = 9,
623
624     .urb_size = 4096,
625     .max_wm_threads = 64,       /* per PSD */
626
627     .is_kabylake = 1,
628 };
629
630 const struct intel_device_info *
631 i965_get_device_info(int devid)
632 {
633     switch (devid) {
634 #undef CHIPSET
635 #define CHIPSET(id, family, dev, str) case id: return &dev##_device_info;
636 #include "i965_pciids.h"
637     default:
638         return NULL;
639     }
640 }
641
642 static void cpuid(unsigned int op,
643                          uint32_t *eax, uint32_t *ebx,
644                          uint32_t *ecx, uint32_t *edx)
645 {
646     __cpuid_count(op, 0, *eax, *ebx, *ecx, *edx);
647 }
648
649 /*
650  * This function doesn't check the length. And the caller should
651  * assure that the length of input string should be greater than 48.
652  */
653 static int intel_driver_detect_cpustring(char *model_id)
654 {
655     uint32_t *rdata;
656
657     if (model_id == NULL)
658         return -EINVAL;
659
660     rdata = (uint32_t *)model_id;
661
662     /* obtain the max supported extended CPUID info */
663     cpuid(0x80000000, &rdata[0], &rdata[1], &rdata[2], &rdata[3]);
664
665     /* If the max extended CPUID info is less than 0x80000004, fail */
666     if (rdata[0] < 0x80000004)
667         return -EINVAL;
668
669     /* obtain the CPUID string */
670     cpuid(0x80000002, &rdata[0], &rdata[1], &rdata[2], &rdata[3]);
671     cpuid(0x80000003, &rdata[4], &rdata[5], &rdata[6], &rdata[7]);
672     cpuid(0x80000004, &rdata[8], &rdata[9], &rdata[10], &rdata[11]);
673
674     *(model_id + 48) = '\0';
675     return 0;
676 }
677
678 /*
679  * the hook_list for HSW.
680  * It is captured by /proc/cpuinfo and the space character is stripped.
681  */
682 const static char *hsw_cpu_hook_list[] =  {
683 "Intel(R)Pentium(R)3556U",
684 "Intel(R)Pentium(R)3560Y",
685 "Intel(R)Pentium(R)3550M",
686 "Intel(R)Celeron(R)2980U",
687 "Intel(R)Celeron(R)2955U",
688 "Intel(R)Celeron(R)2950M",
689 };
690
691 static void hsw_hw_codec_preinit(VADriverContextP ctx, struct hw_codec_info *codec_info)
692 {
693     char model_string[64];
694     char *model_ptr, *tmp_ptr;
695     int i, model_len, list_len;
696     bool found;
697
698     memset(model_string, 0, sizeof(model_string));
699
700     /* If it can't detect cpu model_string, leave it alone */
701     if (intel_driver_detect_cpustring(model_string))
702         return;
703
704     /* strip the cpufreq info */
705     model_ptr = model_string;
706     tmp_ptr = strstr(model_ptr, "@");
707    
708     if (tmp_ptr)
709         *tmp_ptr = '\0';
710
711     /* strip the space character and convert to the lower case */
712     model_ptr = model_string;
713     model_len = strlen(model_string);
714     for (i = 0; i < model_len; i++) {
715          if (model_string[i] != ' ') {
716              *model_ptr = model_string[i];
717              model_ptr++;
718          }
719     }
720     *model_ptr = '\0';
721
722     found = false;
723     list_len = sizeof(hsw_cpu_hook_list) / sizeof(char *);
724     model_len = strlen(model_string);
725     for (i = 0; i < list_len; i++) {
726         model_ptr = (char *)hsw_cpu_hook_list[i];
727
728         if (strlen(model_ptr) != model_len)
729             continue;
730
731         if (strncasecmp(model_string, model_ptr, model_len) == 0) {
732             found = true;
733             break;
734         }
735     }
736
737     if (found) {
738         codec_info->has_h264_encoding = 0;
739         codec_info->has_h264_mvc_encoding = 0;
740         codec_info->has_mpeg2_encoding = 0;
741     }
742     return;
743 }
744
745 /*
746  * the hook_list for Sandybride.
747  * It is captured by /proc/cpuinfo and the space character is stripped.
748  */
749 const static char *gen6_cpu_hook_list[] =  {
750 "Intel(R)Celeron(R)CPU847",
751 "Intel(R)Celeron(R)CPU867",
752 };
753
754 static void gen6_hw_codec_preinit(VADriverContextP ctx, struct hw_codec_info *codec_info)
755 {
756     char model_string[64];
757     char *model_ptr, *tmp_ptr;
758     int i, model_len, list_len;
759     bool found;
760
761     memset(model_string, 0, sizeof(model_string));
762
763     /* If it can't detect cpu model_string, leave it alone */
764     if (intel_driver_detect_cpustring(model_string))
765         return;
766
767     /* strip the cpufreq info */
768     model_ptr = model_string;
769     tmp_ptr = strstr(model_ptr, "@");
770
771     if (tmp_ptr)
772         *tmp_ptr = '\0';
773
774     /* strip the space character and convert to the lower case */
775     model_ptr = model_string;
776     model_len = strlen(model_string);
777     for (i = 0; i < model_len; i++) {
778          if (model_string[i] != ' ') {
779              *model_ptr = model_string[i];
780              model_ptr++;
781          }
782     }
783     *model_ptr = '\0';
784
785     found = false;
786     list_len = sizeof(gen6_cpu_hook_list) / sizeof(char *);
787     model_len = strlen(model_string);
788     for (i = 0; i < list_len; i++) {
789         model_ptr = (char *)gen6_cpu_hook_list[i];
790
791         if (strlen(model_ptr) != model_len)
792             continue;
793
794         if (strncasecmp(model_string, model_ptr, model_len) == 0) {
795             found = true;
796             break;
797         }
798     }
799
800     if (found) {
801         codec_info->has_h264_encoding = 0;
802     }
803     return;
804 }
805
806 /*
807  * the hook_list for Ivybridge.
808  * It is captured by /proc/cpuinfo and the space character is stripped.
809  */
810 const static char *gen7_cpu_hook_list[] =  {
811 "Intel(R)Celeron(R)CPU1007U",
812 };
813
814 static void gen7_hw_codec_preinit(VADriverContextP ctx, struct hw_codec_info *codec_info)
815 {
816     char model_string[64];
817     char *model_ptr, *tmp_ptr;
818     int i, model_len, list_len;
819     bool found;
820
821     memset(model_string, 0, sizeof(model_string));
822
823     /* If it can't detect cpu model_string, leave it alone */
824     if (intel_driver_detect_cpustring(model_string))
825         return;
826
827     /* strip the cpufreq info */
828     model_ptr = model_string;
829     tmp_ptr = strstr(model_ptr, "@");
830
831     if (tmp_ptr)
832         *tmp_ptr = '\0';
833
834     /* strip the space character and convert to the lower case */
835     model_ptr = model_string;
836     model_len = strlen(model_string);
837     for (i = 0; i < model_len; i++) {
838          if (model_string[i] != ' ') {
839              *model_ptr = model_string[i];
840              model_ptr++;
841          }
842     }
843     *model_ptr = '\0';
844
845     found = false;
846     list_len = sizeof(gen7_cpu_hook_list) / sizeof(char *);
847     model_len = strlen(model_string);
848     for (i = 0; i < list_len; i++) {
849         model_ptr = (char *)gen7_cpu_hook_list[i];
850
851         if (strlen(model_ptr) != model_len)
852             continue;
853
854         if (strncasecmp(model_string, model_ptr, model_len) == 0) {
855             found = true;
856             break;
857         }
858     }
859
860     if (found) {
861         codec_info->has_h264_encoding = 0;
862         codec_info->has_mpeg2_encoding = 0;
863     }
864     return;
865 }