OSDN Git Service

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