Limit the minimum pitch for linear surface
[platform/upstream/libva-intel-driver.git] / src / i965_drv_video.c
index 1703dfb..bf15208 100755 (executable)
 
 #define HAS_TILED_SURFACE(ctx) ((ctx)->codec_info->has_tiled_surface)
 
+#define HAS_VP8_DECODING(ctx)   ((ctx)->codec_info->has_vp8_decoding && \
+                                 (ctx)->intel.has_bsd)
+
+#define HAS_VP8_ENCODING(ctx)   ((ctx)->codec_info->has_vp8_encoding && \
+                                 (ctx)->intel.has_bsd)
+
+
 static int get_sampling_from_fourcc(unsigned int fourcc);
 
 /* Check whether we are rendering to X11 (VA/X11 or VA/GLX API) */
@@ -136,19 +143,21 @@ typedef struct {
 static const i965_image_format_map_t
 i965_image_formats_map[I965_MAX_IMAGE_FORMATS + 1] = {
     { I965_SURFACETYPE_YUV,
-      { VA_FOURCC('Y','V','1','2'), VA_LSB_FIRST, 12, } },
+      { VA_FOURCC_YV12, VA_LSB_FIRST, 12, } },
+    { I965_SURFACETYPE_YUV,
+      { VA_FOURCC_I420, VA_LSB_FIRST, 12, } },
     { I965_SURFACETYPE_YUV,
-      { VA_FOURCC('I','4','2','0'), VA_LSB_FIRST, 12, } },
+      { VA_FOURCC_NV12, VA_LSB_FIRST, 12, } },
     { I965_SURFACETYPE_YUV,
-      { VA_FOURCC('N','V','1','2'), VA_LSB_FIRST, 12, } },
+      { VA_FOURCC_YUY2, VA_LSB_FIRST, 16, } },
     { I965_SURFACETYPE_YUV,
-      { VA_FOURCC('Y','U','Y','2'), VA_LSB_FIRST, 16, } },
+      { VA_FOURCC_UYVY, VA_LSB_FIRST, 16, } },
     { I965_SURFACETYPE_YUV,
-      { VA_FOURCC('U','Y','V','Y'), VA_LSB_FIRST, 16, } },
+      { VA_FOURCC_422H, VA_LSB_FIRST, 16, } },
     { I965_SURFACETYPE_RGBA,
-      { VA_FOURCC('R','G','B','X'), VA_LSB_FIRST, 32, 24, 0x000000ff, 0x0000ff00, 0x00ff0000 } },
+      { VA_FOURCC_RGBX, VA_LSB_FIRST, 32, 24, 0x000000ff, 0x0000ff00, 0x00ff0000 } },
     { I965_SURFACETYPE_RGBA,
-      { VA_FOURCC('B','G','R','X'), VA_LSB_FIRST, 32, 24, 0x00ff0000, 0x0000ff00, 0x000000ff } },
+      { VA_FOURCC_BGRX, VA_LSB_FIRST, 32, 24, 0x00ff0000, 0x0000ff00, 0x000000ff } },
 };
 
 /* List of supported subpicture formats */
@@ -166,23 +175,23 @@ typedef struct {
 static const i965_subpic_format_map_t
 i965_subpic_formats_map[I965_MAX_SUBPIC_FORMATS + 1] = {
     { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P4A4_UNORM,
-      { VA_FOURCC('I','A','4','4'), VA_MSB_FIRST, 8, },
+      { VA_FOURCC_IA44, VA_MSB_FIRST, 8, },
       COMMON_SUBPICTURE_FLAGS },
     { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A4P4_UNORM,
-      { VA_FOURCC('A','I','4','4'), VA_MSB_FIRST, 8, },
+      { VA_FOURCC_AI44, VA_MSB_FIRST, 8, },
       COMMON_SUBPICTURE_FLAGS },
     { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_P8A8_UNORM,
-      { VA_FOURCC('I','A','8','8'), VA_MSB_FIRST, 16, },
+      { VA_FOURCC_IA88, VA_MSB_FIRST, 16, },
       COMMON_SUBPICTURE_FLAGS },
     { I965_SURFACETYPE_INDEXED, I965_SURFACEFORMAT_A8P8_UNORM,
-      { VA_FOURCC('A','I','8','8'), VA_MSB_FIRST, 16, },
+      { VA_FOURCC_AI88, VA_MSB_FIRST, 16, },
       COMMON_SUBPICTURE_FLAGS },
      { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_B8G8R8A8_UNORM,
-      { VA_FOURCC('B','G','R','A'), VA_LSB_FIRST, 32,
+      { VA_FOURCC_BGRA, VA_LSB_FIRST, 32,
         32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 },
       COMMON_SUBPICTURE_FLAGS },
     { I965_SURFACETYPE_RGBA, I965_SURFACEFORMAT_R8G8B8A8_UNORM,
-      { VA_FOURCC('R','G','B','A'), VA_LSB_FIRST, 32,
+      { VA_FOURCC_RGBA, VA_LSB_FIRST, 32,
         32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000 },
       COMMON_SUBPICTURE_FLAGS },
 };
@@ -205,119 +214,6 @@ get_subpic_format(const VAImageFormat *va_format)
     return NULL;
 }
 
-extern struct hw_context *i965_proc_context_init(VADriverContextP, struct object_config *);
-extern struct hw_context *g4x_dec_hw_context_init(VADriverContextP, struct object_config *);
-static struct hw_codec_info g4x_hw_codec_info = {
-    .dec_hw_context_init = g4x_dec_hw_context_init,
-    .enc_hw_context_init = NULL,
-    .proc_hw_context_init = NULL,
-    .max_width = 2048,
-    .max_height = 2048,
-
-    .has_mpeg2_decoding = 1,
-
-    .num_filters = 0,
-};
-
-extern struct hw_context *ironlake_dec_hw_context_init(VADriverContextP, struct object_config *);
-static struct hw_codec_info ironlake_hw_codec_info = {
-    .dec_hw_context_init = ironlake_dec_hw_context_init,
-    .enc_hw_context_init = NULL,
-    .proc_hw_context_init = i965_proc_context_init,
-    .max_width = 2048,
-    .max_height = 2048,
-
-    .has_mpeg2_decoding = 1,
-    .has_h264_decoding = 1,
-    .has_vpp = 1,
-    .has_accelerated_putimage = 1,
-
-    .num_filters = 0,
-};
-
-extern struct hw_context *gen6_dec_hw_context_init(VADriverContextP, struct object_config *);
-extern struct hw_context *gen6_enc_hw_context_init(VADriverContextP, struct object_config *);
-static struct hw_codec_info gen6_hw_codec_info = {
-    .dec_hw_context_init = gen6_dec_hw_context_init,
-    .enc_hw_context_init = gen6_enc_hw_context_init,
-    .proc_hw_context_init = i965_proc_context_init,
-    .max_width = 2048,
-    .max_height = 2048,
-
-    .has_mpeg2_decoding = 1,
-    .has_h264_decoding = 1,
-    .has_h264_encoding = 1,
-    .has_vc1_decoding = 1,
-    .has_vpp = 1,
-    .has_accelerated_getimage = 1,
-    .has_accelerated_putimage = 1,
-    .has_tiled_surface = 1,
-
-    .num_filters = 2,
-    .filters = {
-        { VAProcFilterNoiseReduction, I965_RING_NULL },
-        { VAProcFilterDeinterlacing, I965_RING_NULL },
-    },
-};
-
-extern struct hw_context *gen7_dec_hw_context_init(VADriverContextP, struct object_config *);
-extern struct hw_context *gen7_enc_hw_context_init(VADriverContextP, struct object_config *);
-static struct hw_codec_info gen7_hw_codec_info = {
-    .dec_hw_context_init = gen7_dec_hw_context_init,
-    .enc_hw_context_init = gen7_enc_hw_context_init,
-    .proc_hw_context_init = i965_proc_context_init,
-    .max_width = 4096,
-    .max_height = 4096,
-
-    .has_mpeg2_decoding = 1,
-    .has_mpeg2_encoding = 1,
-    .has_h264_decoding = 1,
-    .has_h264_encoding = 1,
-    .has_vc1_decoding = 1,
-    .has_jpeg_decoding = 1,
-    .has_vpp = 1,
-    .has_accelerated_getimage = 1,
-    .has_accelerated_putimage = 1,
-    .has_tiled_surface = 1,
-    .has_di_motion_adptive = 1,
-
-    .num_filters = 2,
-    .filters = {
-        { VAProcFilterNoiseReduction, I965_RING_NULL },
-        { VAProcFilterDeinterlacing, I965_RING_NULL },
-    },
-};
-
-extern struct hw_context *gen75_proc_context_init(VADriverContextP, struct object_config *);
-static struct hw_codec_info gen75_hw_codec_info = {
-    .dec_hw_context_init = gen75_dec_hw_context_init,
-    .enc_hw_context_init = gen75_enc_hw_context_init,
-    .proc_hw_context_init = gen75_proc_context_init,
-    .max_width = 4096,
-    .max_height = 4096,
-
-    .has_mpeg2_decoding = 1,
-    .has_mpeg2_encoding = 1,
-    .has_h264_decoding = 1,
-    .has_h264_encoding = 1,
-    .has_vc1_decoding = 1,
-    .has_jpeg_decoding = 1,
-    .has_vpp = 1,
-    .has_accelerated_getimage = 1,
-    .has_accelerated_putimage = 1,
-    .has_tiled_surface = 1,
-    .has_di_motion_adptive = 1,
-    .has_di_motion_compensated = 1,
-
-    .num_filters = 4,
-    .filters = {
-        { VAProcFilterNoiseReduction, I965_RING_VEBOX },
-        { VAProcFilterDeinterlacing, I965_RING_VEBOX },
-        { VAProcFilterSharpening, I965_RING_NULL },
-        { VAProcFilterColorBalance, I965_RING_VEBOX},
-    },
-};
-
 #define I965_PACKED_HEADER_BASE         0
 #define I965_PACKED_MISC_HEADER_BASE    3
 
@@ -329,7 +225,7 @@ va_enc_packed_type_to_idx(int packed_type)
     if (packed_type & VAEncPackedHeaderMiscMask) {
         idx = I965_PACKED_MISC_HEADER_BASE;
         packed_type = (~VAEncPackedHeaderMiscMask & packed_type);
-        assert(packed_type > 0);
+        ASSERT_RET(packed_type > 0, 0);
         idx += (packed_type - 1);
     } else {
         idx = I965_PACKED_HEADER_BASE;
@@ -349,16 +245,15 @@ va_enc_packed_type_to_idx(int packed_type)
 
         default:
             /* Should not get here */
-            assert(0);
+            ASSERT_RET(0, 0);
             break;
         }
     }
 
-    assert(idx < 4);
+    ASSERT_RET(idx < 4, 0);
     return idx;
 }
 
-
 VAStatus 
 i965_QueryConfigProfiles(VADriverContextP ctx,
                          VAProfile *profile_list,       /* out */
@@ -375,7 +270,7 @@ i965_QueryConfigProfiles(VADriverContextP ctx,
 
     if (HAS_H264_DECODING(i965) ||
         HAS_H264_ENCODING(i965)) {
-        profile_list[i++] = VAProfileH264Baseline;
+        profile_list[i++] = VAProfileH264ConstrainedBaseline;
         profile_list[i++] = VAProfileH264Main;
         profile_list[i++] = VAProfileH264High;
     }
@@ -394,8 +289,13 @@ i965_QueryConfigProfiles(VADriverContextP ctx,
         profile_list[i++] = VAProfileJPEGBaseline;
     }
 
+    if (HAS_VP8_DECODING(i965) ||
+        HAS_VP8_ENCODING(i965)) {
+        profile_list[i++] = VAProfileVP8Version0_3;
+    }
+
     /* If the assert fails then I965_MAX_PROFILES needs to be bigger */
-    assert(i <= I965_MAX_PROFILES);
+    ASSERT_RET(i <= I965_MAX_PROFILES, VA_STATUS_ERROR_OPERATION_FAILED);
     *num_profiles = i;
 
     return VA_STATUS_SUCCESS;
@@ -421,7 +321,7 @@ i965_QueryConfigEntrypoints(VADriverContextP ctx,
 
         break;
 
-    case VAProfileH264Baseline:
+    case VAProfileH264ConstrainedBaseline:
     case VAProfileH264Main:
     case VAProfileH264High:
         if (HAS_H264_DECODING(i965))
@@ -449,12 +349,19 @@ i965_QueryConfigEntrypoints(VADriverContextP ctx,
             entrypoint_list[n++] = VAEntrypointVLD;
         break;
 
+    case VAProfileVP8Version0_3:
+        if (HAS_VP8_DECODING(i965))
+            entrypoint_list[n++] = VAEntrypointVLD;
+        
+        if (HAS_VP8_ENCODING(i965))
+            entrypoint_list[n++] = VAEntrypointEncSlice;
+
     default:
         break;
     }
 
     /* If the assert fails then I965_MAX_ENTRYPOINTS needs to be bigger */
-    assert(n <= I965_MAX_ENTRYPOINTS);
+    ASSERT_RET(n <= I965_MAX_ENTRYPOINTS, VA_STATUS_ERROR_OPERATION_FAILED);
     *num_entrypoints = n;
     return n > 0 ? VA_STATUS_SUCCESS : VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
 }
@@ -478,7 +385,11 @@ i965_GetConfigAttributes(VADriverContextP ctx,
 
         case VAConfigAttribRateControl:
             if (entrypoint == VAEntrypointEncSlice) {
-                attrib_list[i].value = VA_RC_CBR | VA_RC_CQP;
+                attrib_list[i].value = VA_RC_CQP;
+
+                if (profile != VAProfileMPEG2Main &&
+                    profile != VAProfileMPEG2Simple)
+                    attrib_list[i].value |= VA_RC_CBR;
                 break;
             }
 
@@ -561,7 +472,7 @@ i965_CreateConfig(VADriverContextP ctx,
         }
         break;
 
-    case VAProfileH264Baseline:
+    case VAProfileH264ConstrainedBaseline:
     case VAProfileH264Main:
     case VAProfileH264High:
         if ((HAS_H264_DECODING(i965) && VAEntrypointVLD == entrypoint) ||
@@ -602,6 +513,15 @@ i965_CreateConfig(VADriverContextP ctx,
 
         break;
 
+    case VAProfileVP8Version0_3:
+        if ((HAS_VP8_DECODING(i965) && VAEntrypointVLD == entrypoint) ||
+            (HAS_VP8_ENCODING(i965) && VAEntrypointEncSlice == entrypoint))
+            vaStatus = VA_STATUS_SUCCESS;
+        else
+            vaStatus = VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT;
+
+        break;
+
     default:
         vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
         break;
@@ -671,7 +591,7 @@ VAStatus i965_QueryConfigAttributes(VADriverContextP ctx,
     VAStatus vaStatus = VA_STATUS_SUCCESS;
     int i;
 
-    assert(obj_config);
+    ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
     *profile = obj_config->profile;
     *entrypoint = obj_config->entrypoint;
     *num_attribs = obj_config->num_attribs;
@@ -712,9 +632,10 @@ i965_surface_native_memory(VADriverContextP ctx,
         return VA_STATUS_SUCCESS;
 
     // todo, should we disable tiling for 422 format?
-    if (expected_fourcc == VA_FOURCC('I', '4', '2', '0') ||
-        expected_fourcc == VA_FOURCC('I', 'Y', 'U', 'V') ||
-        expected_fourcc == VA_FOURCC('Y', 'V', '1', '2'))
+    if (expected_fourcc == VA_FOURCC_I420 ||
+        expected_fourcc == VA_FOURCC_IYUV ||
+        expected_fourcc == VA_FOURCC_YV12 ||
+        expected_fourcc == VA_FOURCC_YV16)
         tiling = 0;
                
     i965_check_alloc_surface_bo(ctx, obj_surface, tiling, expected_fourcc, get_sampling_from_fourcc(expected_fourcc));
@@ -736,9 +657,9 @@ i965_suface_external_memory(VADriverContextP ctx,
         index > memory_attibute->num_buffers)
         return VA_STATUS_ERROR_INVALID_PARAMETER;
 
-    assert(obj_surface->orig_width == memory_attibute->width);
-    assert(obj_surface->orig_height == memory_attibute->height);
-    assert(memory_attibute->num_planes >= 1);
+    ASSERT_RET(obj_surface->orig_width == memory_attibute->width, VA_STATUS_ERROR_INVALID_PARAMETER);
+    ASSERT_RET(obj_surface->orig_height == memory_attibute->height, VA_STATUS_ERROR_INVALID_PARAMETER);
+    ASSERT_RET(memory_attibute->num_planes >= 1, VA_STATUS_ERROR_INVALID_PARAMETER);
 
     obj_surface->fourcc = memory_attibute->pixel_format;
     obj_surface->width = memory_attibute->pitches[0];
@@ -753,9 +674,9 @@ i965_suface_external_memory(VADriverContextP ctx,
     obj_surface->x_cr_offset = 0;
 
     switch (obj_surface->fourcc) {
-    case VA_FOURCC('N', 'V', '1', '2'):
-        assert(memory_attibute->num_planes == 2);
-        assert(memory_attibute->pitches[0] == memory_attibute->pitches[1]);
+    case VA_FOURCC_NV12:
+        ASSERT_RET(memory_attibute->num_planes == 2, VA_STATUS_ERROR_INVALID_PARAMETER);
+        ASSERT_RET(memory_attibute->pitches[0] == memory_attibute->pitches[1], VA_STATUS_ERROR_INVALID_PARAMETER);
 
         obj_surface->subsampling = SUBSAMPLE_YUV420;
         obj_surface->y_cb_offset = obj_surface->height;
@@ -766,10 +687,10 @@ i965_suface_external_memory(VADriverContextP ctx,
 
         break;
 
-    case VA_FOURCC('Y', 'V', '1', '2'):
-    case VA_FOURCC('I', 'M', 'C', '1'):
-        assert(memory_attibute->num_planes == 3);
-        assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
+    case VA_FOURCC_YV12:
+    case VA_FOURCC_IMC1:
+        ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
+        ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
 
         obj_surface->subsampling = SUBSAMPLE_YUV420;
         obj_surface->y_cr_offset = obj_surface->height;
@@ -780,11 +701,11 @@ i965_suface_external_memory(VADriverContextP ctx,
         
         break;
 
-    case VA_FOURCC('I', '4', '2', '0'):
-    case VA_FOURCC('I', 'Y', 'U', 'V'):
-    case VA_FOURCC('I', 'M', 'C', '3'):
-        assert(memory_attibute->num_planes == 3);
-        assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
+    case VA_FOURCC_I420:
+    case VA_FOURCC_IYUV:
+    case VA_FOURCC_IMC3:
+        ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
+        ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
 
         obj_surface->subsampling = SUBSAMPLE_YUV420;
         obj_surface->y_cb_offset = obj_surface->height;
@@ -795,9 +716,9 @@ i965_suface_external_memory(VADriverContextP ctx,
 
         break;
 
-    case VA_FOURCC('Y', 'U', 'Y', '2'):
-    case VA_FOURCC('U', 'Y', 'V', 'Y'):
-        assert(memory_attibute->num_planes == 1);
+    case VA_FOURCC_YUY2:
+    case VA_FOURCC_UYVY:
+        ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
 
         obj_surface->subsampling = SUBSAMPLE_YUV422H;
         obj_surface->y_cb_offset = 0;
@@ -808,11 +729,11 @@ i965_suface_external_memory(VADriverContextP ctx,
 
         break;
 
-    case VA_FOURCC('R', 'G', 'B', 'A'):
-    case VA_FOURCC('R', 'G', 'B', 'X'):
-    case VA_FOURCC('B', 'G', 'R', 'A'):
-    case VA_FOURCC('B', 'G', 'R', 'X'):
-        assert(memory_attibute->num_planes == 1);
+    case VA_FOURCC_RGBA:
+    case VA_FOURCC_RGBX:
+    case VA_FOURCC_BGRA:
+    case VA_FOURCC_BGRX:
+        ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
 
         obj_surface->subsampling = SUBSAMPLE_RGBX;
         obj_surface->y_cb_offset = 0;
@@ -823,8 +744,8 @@ i965_suface_external_memory(VADriverContextP ctx,
 
         break;
 
-    case VA_FOURCC('Y', '8', '0', '0'): /* monochrome surface */
-        assert(memory_attibute->num_planes == 1);
+    case VA_FOURCC_Y800: /* monochrome surface */
+        ASSERT_RET(memory_attibute->num_planes == 1, VA_STATUS_ERROR_INVALID_PARAMETER);
         
         obj_surface->subsampling = SUBSAMPLE_YUV400;
         obj_surface->y_cb_offset = 0;
@@ -835,9 +756,9 @@ i965_suface_external_memory(VADriverContextP ctx,
 
         break;
 
-    case VA_FOURCC('4', '1', '1', 'P'):
-        assert(memory_attibute->num_planes == 3);
-        assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
+    case VA_FOURCC_411P:
+        ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
+        ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
 
         obj_surface->subsampling = SUBSAMPLE_YUV411;
         obj_surface->y_cb_offset = 0;
@@ -848,9 +769,9 @@ i965_suface_external_memory(VADriverContextP ctx,
 
         break;
 
-    case VA_FOURCC('4', '2', '2', 'H'):
-        assert(memory_attibute->num_planes == 3);
-        assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
+    case VA_FOURCC_422H:
+        ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
+        ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
 
         obj_surface->subsampling = SUBSAMPLE_YUV422H;
         obj_surface->y_cb_offset = obj_surface->height;
@@ -861,11 +782,24 @@ i965_suface_external_memory(VADriverContextP ctx,
 
         break;
 
-    case VA_FOURCC('4', '2', '2', 'V'):
+    case VA_FOURCC_YV16:
         assert(memory_attibute->num_planes == 3);
         assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
 
         obj_surface->subsampling = SUBSAMPLE_YUV422H;
+        obj_surface->y_cr_offset = memory_attibute->offsets[1] / obj_surface->width;
+        obj_surface->y_cb_offset = memory_attibute->offsets[2] / obj_surface->width;
+        obj_surface->cb_cr_width = obj_surface->orig_width / 2;
+        obj_surface->cb_cr_height = obj_surface->orig_height;
+        obj_surface->cb_cr_pitch = memory_attibute->pitches[1];
+
+        break;
+
+    case VA_FOURCC_422V:
+        ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
+        ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
+
+        obj_surface->subsampling = SUBSAMPLE_YUV422H;
         obj_surface->y_cb_offset = obj_surface->height;
         obj_surface->y_cr_offset = memory_attibute->offsets[2] / obj_surface->width;
         obj_surface->cb_cr_width = obj_surface->orig_width;
@@ -874,9 +808,9 @@ i965_suface_external_memory(VADriverContextP ctx,
 
         break;
 
-    case VA_FOURCC('4', '4', '4', 'P'):
-        assert(memory_attibute->num_planes == 3);
-        assert(memory_attibute->pitches[1] == memory_attibute->pitches[2]);
+    case VA_FOURCC_444P:
+        ASSERT_RET(memory_attibute->num_planes == 3, VA_STATUS_ERROR_INVALID_PARAMETER);
+        ASSERT_RET(memory_attibute->pitches[1] == memory_attibute->pitches[2], VA_STATUS_ERROR_INVALID_PARAMETER);
 
         obj_surface->subsampling = SUBSAMPLE_YUV444;
         obj_surface->y_cb_offset = obj_surface->height;
@@ -907,6 +841,40 @@ i965_suface_external_memory(VADriverContextP ctx,
     return VA_STATUS_SUCCESS;
 }
 
+/* byte-per-pixel of the first plane */
+static int
+bpp_1stplane_by_fourcc(unsigned int fourcc)
+{
+    switch (fourcc) {
+        case VA_FOURCC_RGBA:
+        case VA_FOURCC_RGBX:
+        case VA_FOURCC_BGRA:
+        case VA_FOURCC_BGRX:
+        case VA_FOURCC_ARGB:
+        case VA_FOURCC_XRGB:
+        case VA_FOURCC_ABGR:
+        case VA_FOURCC_XBGR:
+        case VA_FOURCC_AYUV:
+            return 4;
+
+        case VA_FOURCC_UYVY:
+        case VA_FOURCC_YUY2:
+            return 2;
+
+        case VA_FOURCC_YV12:
+        case VA_FOURCC_IMC3:
+        case VA_FOURCC_IYUV:
+        case VA_FOURCC_NV12:
+        case VA_FOURCC_NV11:
+        case VA_FOURCC_YV16:
+            return 1;
+
+        default:
+            ASSERT_RET(0, 0);
+            return 0;
+    }
+}
+
 static VAStatus
 i965_CreateSurfaces2(
     VADriverContextP    ctx,
@@ -929,24 +897,26 @@ i965_CreateSurfaces2(
     for (i = 0; i < num_attribs && attrib_list; i++) {
         if ((attrib_list[i].type == VASurfaceAttribPixelFormat) &&
             (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
-            assert(attrib_list[i].value.type == VAGenericValueTypeInteger);
+            ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
             expected_fourcc = attrib_list[i].value.value.i;
         }
 
         if ((attrib_list[i].type == VASurfaceAttribMemoryType) &&
             (attrib_list[i].flags & VA_SURFACE_ATTRIB_SETTABLE)) {
             
-            assert(attrib_list[i].value.type == VAGenericValueTypeInteger);
+            ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypeInteger, VA_STATUS_ERROR_INVALID_PARAMETER);
 
             if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM)
                 memory_type = I965_SURFACE_MEM_GEM_FLINK; /* flinked GEM handle */
             else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME)
                 memory_type = I965_SURFACE_MEM_DRM_PRIME; /* drm prime fd */
+            else if (attrib_list[i].value.value.i == VA_SURFACE_ATTRIB_MEM_TYPE_VA)
+                memory_type = I965_SURFACE_MEM_NATIVE; /* va native memory, to be allocated */
         }
 
         if ((attrib_list[i].type == VASurfaceAttribExternalBufferDescriptor) &&
             (attrib_list[i].flags == VA_SURFACE_ATTRIB_SETTABLE)) {
-            assert(attrib_list[i].value.type == VAGenericValueTypePointer);
+            ASSERT_RET(attrib_list[i].value.type == VAGenericValueTypePointer, VA_STATUS_ERROR_INVALID_PARAMETER);
             memory_attibute = (VASurfaceAttribExternalBuffers *)attrib_list[i].value.value.p;
         }
     }
@@ -975,6 +945,9 @@ i965_CreateSurfaces2(
         obj_surface->status = VASurfaceReady;
         obj_surface->orig_width = width;
         obj_surface->orig_height = height;
+        obj_surface->user_disable_tiling = false;
+        obj_surface->user_h_stride_set = false;
+        obj_surface->user_v_stride_set = false;
 
         obj_surface->subpic_render_idx = 0;
         for(j = 0; j < I965_MAX_SUBPIC_SUM; j++){
@@ -982,8 +955,10 @@ i965_CreateSurfaces2(
            obj_surface->obj_subpic[j] = NULL;
         }
 
-        obj_surface->width = ALIGN(width, 16);
-        obj_surface->height = ALIGN(height, 16);
+        assert(i965->codec_info->min_linear_wpitch);
+        assert(i965->codec_info->min_linear_hpitch);
+        obj_surface->width = ALIGN(width, i965->codec_info->min_linear_wpitch);
+        obj_surface->height = ALIGN(height, i965->codec_info->min_linear_hpitch);
         obj_surface->flags = SURFACE_REFERENCED;
         obj_surface->fourcc = 0;
         obj_surface->bo = NULL;
@@ -994,6 +969,34 @@ i965_CreateSurfaces2(
 
         switch (memory_type) {
         case I965_SURFACE_MEM_NATIVE:
+            if (memory_attibute) {
+                if (!(memory_attibute->flags & VA_SURFACE_EXTBUF_DESC_ENABLE_TILING))
+                    obj_surface->user_disable_tiling = true;
+
+                if (memory_attibute->pixel_format) {
+                    if (expected_fourcc)
+                        ASSERT_RET(memory_attibute->pixel_format == expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
+                    else
+                        expected_fourcc = memory_attibute->pixel_format;
+                }
+                ASSERT_RET(expected_fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
+                if (memory_attibute->pitches[0]) {
+                    int bpp_1stplane = bpp_1stplane_by_fourcc(expected_fourcc);
+                    ASSERT_RET(bpp_1stplane, VA_STATUS_ERROR_INVALID_PARAMETER);
+                    obj_surface->width = memory_attibute->pitches[0]/bpp_1stplane;
+                    obj_surface->user_h_stride_set = true;
+                    ASSERT_RET(IS_ALIGNED(obj_surface->width, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
+                    ASSERT_RET(obj_surface->width >= width, VA_STATUS_ERROR_INVALID_PARAMETER);
+
+                    if (memory_attibute->offsets[1]) {
+                        ASSERT_RET(!memory_attibute->offsets[0], VA_STATUS_ERROR_INVALID_PARAMETER);
+                        obj_surface->height = memory_attibute->offsets[1]/memory_attibute->pitches[0];
+                        obj_surface->user_v_stride_set = true;
+                        ASSERT_RET(IS_ALIGNED(obj_surface->height, 16), VA_STATUS_ERROR_INVALID_PARAMETER);
+                        ASSERT_RET(obj_surface->height >= height, VA_STATUS_ERROR_INVALID_PARAMETER);
+                    }
+                }
+            }
             i965_surface_native_memory(ctx,
                                        obj_surface,
                                        format,
@@ -1055,7 +1058,7 @@ i965_DestroySurfaces(VADriverContextP ctx,
     for (i = num_surfaces; i--; ) {
         struct object_surface *obj_surface = SURFACE(surface_list[i]);
 
-        assert(obj_surface);
+        ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
         i965_destroy_surface(&i965->surface_heap, (struct object_base *)obj_surface);
     }
 
@@ -1098,7 +1101,7 @@ i965_guess_surface_format(VADriverContextP ctx,
     struct object_context *obj_context = NULL;
     struct object_config *obj_config = NULL;
 
-    *fourcc = VA_FOURCC('Y', 'V', '1', '2');
+    *fourcc = VA_FOURCC_YV12;
     *is_tiled = 0;
 
     if (i965->current_context_id == VA_INVALID_ID)
@@ -1115,8 +1118,10 @@ i965_guess_surface_format(VADriverContextP ctx,
     if (!obj_config)
         return;
 
-    if (IS_GEN6(i965->intel.device_id) || IS_GEN7(i965->intel.device_id)) {
-        *fourcc = VA_FOURCC('N', 'V', '1', '2');
+    if (IS_GEN6(i965->intel.device_info) ||
+        IS_GEN7(i965->intel.device_info) ||
+        IS_GEN8(i965->intel.device_info)) {
+        *fourcc = VA_FOURCC_NV12;
         *is_tiled = 1;
         return;
     }
@@ -1124,12 +1129,12 @@ i965_guess_surface_format(VADriverContextP ctx,
     switch (obj_config->profile) {
     case VAProfileMPEG2Simple:
     case VAProfileMPEG2Main:
-        *fourcc = VA_FOURCC('I', '4', '2', '0');
+        *fourcc = VA_FOURCC_I420;
         *is_tiled = 0;
         break;
 
     default:
-        *fourcc = VA_FOURCC('N', 'V', '1', '2');
+        *fourcc = VA_FOURCC_NV12;
         *is_tiled = 0;
         break;
     }
@@ -1208,7 +1213,7 @@ i965_DestroySubpicture(VADriverContextP ctx,
     if (!obj_subpic)
         return VA_STATUS_ERROR_INVALID_SUBPICTURE;
 
-    assert(obj_subpic->obj_image);
+    ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
     i965_destroy_subpic(&i965->subpic_heap, (struct object_base *)obj_subpic);
     return VA_STATUS_SUCCESS;
 }
@@ -1279,7 +1284,7 @@ i965_AssociateSubpicture(VADriverContextP ctx,
     if (!obj_subpic)
         return VA_STATUS_ERROR_INVALID_SUBPICTURE;
     
-    assert(obj_subpic->obj_image);
+    ASSERT_RET(obj_subpic->obj_image, VA_STATUS_ERROR_INVALID_SUBPICTURE);
 
     obj_subpic->src_rect.x      = src_x;
     obj_subpic->src_rect.y      = src_y;
@@ -1488,7 +1493,7 @@ i965_CreateContext(VADriverContextP ctx,
     render_state->inited = 1;
 
     switch (obj_config->profile) {
-    case VAProfileH264Baseline:
+    case VAProfileH264ConstrainedBaseline:
     case VAProfileH264Main:
     case VAProfileH264High:
         if (!HAS_H264_DECODING(i965) &&
@@ -1497,7 +1502,7 @@ i965_CreateContext(VADriverContextP ctx,
         render_state->interleaved_uv = 1;
         break;
     default:
-        render_state->interleaved_uv = !!(IS_GEN6(i965->intel.device_id) || IS_GEN7(i965->intel.device_id));
+        render_state->interleaved_uv = !!(IS_GEN6(i965->intel.device_info) || IS_GEN7(i965->intel.device_info) || IS_GEN8(i965->intel.device_info));
         break;
     }
 
@@ -1569,7 +1574,7 @@ i965_DestroyContext(VADriverContextP ctx, VAContextID context)
     struct i965_driver_data *i965 = i965_driver_data(ctx);
     struct object_context *obj_context = CONTEXT(context);
 
-    assert(obj_context);
+    ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
 
     if (i965->current_context_id == context)
         i965->current_context_id = VA_INVALID_ID;
@@ -1627,6 +1632,7 @@ i965_create_buffer_internal(VADriverContextP ctx,
     case VAProcPipelineParameterBufferType:
     case VAProcFilterParameterBufferType:
     case VAHuffmanTableBufferType:
+    case VAProbabilityBufferType:
         /* Ok */
         break;
 
@@ -1663,7 +1669,8 @@ i965_create_buffer_internal(VADriverContextP ctx,
             dri_bo_subdata(buffer_store->bo, 0, size * num_elements, data);
     } else if (type == VASliceDataBufferType || 
                type == VAImageBufferType || 
-               type == VAEncCodedBufferType) {
+               type == VAEncCodedBufferType ||
+               type == VAProbabilityBufferType) {
         buffer_store->bo = dri_bo_alloc(i965->intel.bufmgr, 
                                         "Buffer", 
                                         size * num_elements, 64);
@@ -1730,10 +1737,7 @@ i965_BufferSetNumElements(VADriverContextP ctx,
     struct object_buffer *obj_buffer = BUFFER(buf_id);
     VAStatus vaStatus = VA_STATUS_SUCCESS;
 
-    assert(obj_buffer);
-
-    if (!obj_buffer)
-        return VA_STATUS_ERROR_INVALID_BUFFER;
+    ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
 
     if ((num_elements < 0) || 
         (num_elements > obj_buffer->max_num_elements)) {
@@ -1757,12 +1761,9 @@ i965_MapBuffer(VADriverContextP ctx,
     struct object_buffer *obj_buffer = BUFFER(buf_id);
     VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
 
-    assert(obj_buffer && obj_buffer->buffer_store);
-    assert(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer);
-    assert(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer));
-
-    if (!obj_buffer || !obj_buffer->buffer_store)
-        return VA_STATUS_ERROR_INVALID_BUFFER;
+    ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
+    ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
+    ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_INVALID_BUFFER);
 
     if (NULL != obj_buffer->buffer_store->bo) {
         unsigned int tiling, swizzle;
@@ -1774,7 +1775,7 @@ i965_MapBuffer(VADriverContextP ctx,
         else
             dri_bo_map(obj_buffer->buffer_store->bo, 1);
 
-        assert(obj_buffer->buffer_store->bo->virtual);
+        ASSERT_RET(obj_buffer->buffer_store->bo->virtual, VA_STATUS_ERROR_OPERATION_FAILED);
         *pbuf = obj_buffer->buffer_store->bo->virtual;
 
         if (obj_buffer->type == VAEncCodedBufferType) {
@@ -1800,7 +1801,7 @@ i965_MapBuffer(VADriverContextP ctx,
                     delimiter3 = MPEG2_DELIMITER3;
                     delimiter4 = MPEG2_DELIMITER4;
                 } else {
-                    assert(0);
+                    ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_PROFILE);
                 }
 
                 for (i = 0; i < obj_buffer->size_element - I965_CODEDBUFFER_HEADER_SIZE - 3 - 0x1000; i++) {
@@ -1842,12 +1843,9 @@ i965_UnmapBuffer(VADriverContextP ctx, VABufferID buf_id)
     if ((buf_id & OBJECT_HEAP_OFFSET_MASK) != BUFFER_ID_OFFSET)
         return VA_STATUS_ERROR_INVALID_BUFFER;
 
-    assert(obj_buffer && obj_buffer->buffer_store);
-    assert(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer);
-    assert(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer));
-
-    if (!obj_buffer || !obj_buffer->buffer_store)
-        return VA_STATUS_ERROR_INVALID_BUFFER;
+    ASSERT_RET(obj_buffer && obj_buffer->buffer_store, VA_STATUS_ERROR_INVALID_BUFFER);
+    ASSERT_RET(obj_buffer->buffer_store->bo || obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_OPERATION_FAILED);
+    ASSERT_RET(!(obj_buffer->buffer_store->bo && obj_buffer->buffer_store->buffer), VA_STATUS_ERROR_OPERATION_FAILED);
 
     if (NULL != obj_buffer->buffer_store->bo) {
         unsigned int tiling, swizzle;
@@ -1874,10 +1872,7 @@ i965_DestroyBuffer(VADriverContextP ctx, VABufferID buffer_id)
     struct i965_driver_data *i965 = i965_driver_data(ctx);
     struct object_buffer *obj_buffer = BUFFER(buffer_id);
 
-    assert(obj_buffer);
-
-    if (!obj_buffer)
-        return VA_STATUS_ERROR_INVALID_BUFFER;
+    ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
 
     i965_destroy_buffer(&i965->buffer_heap, (struct object_base *)obj_buffer);
 
@@ -1896,18 +1891,10 @@ i965_BeginPicture(VADriverContextP ctx,
     VAStatus vaStatus;
     int i;
 
-    assert(obj_context);
-
-    if (!obj_context)
-        return VA_STATUS_ERROR_INVALID_CONTEXT;
-
-    assert(obj_surface);
-
-    if (!obj_surface)
-        return VA_STATUS_ERROR_INVALID_SURFACE;
-
+    ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
+    ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
     obj_config = obj_context->obj_config;
-    assert(obj_config);
+    ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
 
     switch (obj_config->profile) {
     case VAProfileMPEG2Simple:
@@ -1915,7 +1902,7 @@ i965_BeginPicture(VADriverContextP ctx,
         vaStatus = VA_STATUS_SUCCESS;
         break;
 
-    case VAProfileH264Baseline:
+    case VAProfileH264ConstrainedBaseline:
     case VAProfileH264Main:
     case VAProfileH264High:
         vaStatus = VA_STATUS_SUCCESS;
@@ -1935,9 +1922,12 @@ i965_BeginPicture(VADriverContextP ctx,
         vaStatus = VA_STATUS_SUCCESS;
         break;
 
+    case VAProfileVP8Version0_3:
+        vaStatus = VA_STATUS_SUCCESS;
+        break;
+
     default:
-        assert(0);
-        vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
+        ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_PROFILE);
         break;
     }
 
@@ -1995,8 +1985,6 @@ i965_BeginPicture(VADriverContextP ctx,
                                              struct object_buffer *obj_buffer) \
     {                                                                   \
         struct category##_state *category = &obj_context->codec_state.category; \
-        assert(obj_buffer->buffer_store->bo == NULL);                   \
-        assert(obj_buffer->buffer_store->buffer);                       \
         i965_release_buffer_store(&category->member);                   \
         i965_reference_buffer_store(&category->member, obj_buffer->buffer_store); \
         return VA_STATUS_SUCCESS;                                       \
@@ -2027,6 +2015,7 @@ DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(picture_parameter, pic_param)
 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(iq_matrix, iq_matrix)
 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(bit_plane, bit_plane)
 DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(huffman_table, huffman_table)
+DEF_RENDER_DECODE_SINGLE_BUFFER_FUNC(probability_data, probability_data)
 
 #define DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(name, member) DEF_RENDER_MULTI_BUFFER_FUNC(decode, name, member)
 DEF_RENDER_DECODE_MULTI_BUFFER_FUNC(slice_parameter, slice_params)
@@ -2043,10 +2032,7 @@ i965_decoder_render_picture(VADriverContextP ctx,
     VAStatus vaStatus = VA_STATUS_SUCCESS;
     int i;
     
-    assert(obj_context);
-
-    if (!obj_context)
-        return VA_STATUS_ERROR_INVALID_CONTEXT;
+    ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
 
     for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
         struct object_buffer *obj_buffer = BUFFER(buffers[i]);
@@ -2079,6 +2065,10 @@ i965_decoder_render_picture(VADriverContextP ctx,
             vaStatus = I965_RENDER_DECODE_BUFFER(huffman_table);
             break;
 
+        case VAProbabilityBufferType:
+            vaStatus = I965_RENDER_DECODE_BUFFER(probability_data);
+            break;
+
         default:
             vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
             break;
@@ -2112,8 +2102,8 @@ i965_encoder_render_packed_header_parameter_buffer(VADriverContextP ctx,
 {
     struct encode_state *encode = &obj_context->codec_state.encode;
 
-    assert(obj_buffer->buffer_store->bo == NULL);
-    assert(obj_buffer->buffer_store->buffer);
+    ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
+    ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
     i965_release_buffer_store(&encode->packed_header_param[type_index]);
     i965_reference_buffer_store(&encode->packed_header_param[type_index], obj_buffer->buffer_store);
 
@@ -2128,8 +2118,8 @@ i965_encoder_render_packed_header_data_buffer(VADriverContextP ctx,
 {
     struct encode_state *encode = &obj_context->codec_state.encode;
 
-    assert(obj_buffer->buffer_store->bo == NULL);
-    assert(obj_buffer->buffer_store->buffer);
+    ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
+    ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
     i965_release_buffer_store(&encode->packed_header_data[type_index]);
     i965_reference_buffer_store(&encode->packed_header_data[type_index], obj_buffer->buffer_store);
 
@@ -2144,12 +2134,12 @@ i965_encoder_render_misc_parameter_buffer(VADriverContextP ctx,
     struct encode_state *encode = &obj_context->codec_state.encode;
     VAEncMiscParameterBuffer *param = NULL;
 
-    assert(obj_buffer->buffer_store->bo == NULL);
-    assert(obj_buffer->buffer_store->buffer);
+    ASSERT_RET(obj_buffer->buffer_store->bo == NULL, VA_STATUS_ERROR_INVALID_BUFFER);
+    ASSERT_RET(obj_buffer->buffer_store->buffer, VA_STATUS_ERROR_INVALID_BUFFER);
 
     param = (VAEncMiscParameterBuffer *)obj_buffer->buffer_store->buffer;
 
-    if (param->type > ARRAY_ELEMS(encode->misc_param))
+    if (param->type >= ARRAY_ELEMS(encode->misc_param))
         return VA_STATUS_ERROR_INVALID_PARAMETER;
 
     i965_release_buffer_store(&encode->misc_param[param->type]);
@@ -2169,10 +2159,7 @@ i965_encoder_render_picture(VADriverContextP ctx,
     VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
     int i;
 
-    assert(obj_context);
-
-    if (!obj_context)
-        return VA_STATUS_ERROR_INVALID_CONTEXT;
+    ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
 
     for (i = 0; i < num_buffers; i++) {  
         struct object_buffer *obj_buffer = BUFFER(buffers[i]);
@@ -2218,11 +2205,12 @@ i965_encoder_render_picture(VADriverContextP ctx,
         {
             struct encode_state *encode = &obj_context->codec_state.encode;
 
-            assert(encode->last_packed_header_type == VAEncPackedHeaderSequence ||
+            ASSERT_RET(encode->last_packed_header_type == VAEncPackedHeaderSequence ||
                    encode->last_packed_header_type == VAEncPackedHeaderPicture ||
                    encode->last_packed_header_type == VAEncPackedHeaderSlice ||
                    (((encode->last_packed_header_type & VAEncPackedHeaderMiscMask) == VAEncPackedHeaderMiscMask) &&
-                    ((encode->last_packed_header_type & (~VAEncPackedHeaderMiscMask)) != 0)));
+                    ((encode->last_packed_header_type & (~VAEncPackedHeaderMiscMask)) != 0)),
+                    VA_STATUS_ERROR_ENCODING_ERROR);
             vaStatus = i965_encoder_render_packed_header_data_buffer(ctx, 
                                                                      obj_context,
                                                                      obj_buffer,
@@ -2261,10 +2249,7 @@ i965_proc_render_picture(VADriverContextP ctx,
     VAStatus vaStatus = VA_STATUS_SUCCESS;
     int i;
 
-    assert(obj_context);
-
-    if (!obj_context)
-        return VA_STATUS_ERROR_INVALID_CONTEXT;
+    ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
 
     for (i = 0; i < num_buffers && vaStatus == VA_STATUS_SUCCESS; i++) {
         struct object_buffer *obj_buffer = BUFFER(buffers[i]);
@@ -2298,16 +2283,13 @@ i965_RenderPicture(VADriverContextP ctx,
     VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN;
 
     obj_context = CONTEXT(context);
-    assert(obj_context);
-
-    if (!obj_context)
-        return VA_STATUS_ERROR_INVALID_CONTEXT;
+    ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
 
     if (num_buffers <= 0)
         return VA_STATUS_ERROR_INVALID_PARAMETER;
 
     obj_config = obj_context->obj_config;
-    assert(obj_config);
+    ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
 
     if (VAEntrypointVideoProc == obj_config->entrypoint) {
         vaStatus = i965_proc_render_picture(ctx, context, buffers, num_buffers);
@@ -2327,18 +2309,14 @@ i965_EndPicture(VADriverContextP ctx, VAContextID context)
     struct object_context *obj_context = CONTEXT(context);
     struct object_config *obj_config;
 
-    assert(obj_context);
-
-    if (!obj_context)
-        return VA_STATUS_ERROR_INVALID_CONTEXT;
-
+    ASSERT_RET(obj_context, VA_STATUS_ERROR_INVALID_CONTEXT);
     obj_config = obj_context->obj_config;
-    assert(obj_config);
+    ASSERT_RET(obj_config, VA_STATUS_ERROR_INVALID_CONFIG);
 
     if (obj_context->codec_type == CODEC_PROC) {
-        assert(VAEntrypointVideoProc == obj_config->entrypoint);
+        ASSERT_RET(VAEntrypointVideoProc == obj_config->entrypoint, VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
     } else if (obj_context->codec_type == CODEC_ENC) {
-        assert(VAEntrypointEncSlice == obj_config->entrypoint);
+        ASSERT_RET(VAEntrypointEncSlice == obj_config->entrypoint, VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT);
 
         if (!(obj_context->codec_state.encode.pic_param ||
                 obj_context->codec_state.encode.pic_param_ext)) {
@@ -2369,7 +2347,7 @@ i965_EndPicture(VADriverContextP ctx, VAContextID context)
         }
     }
 
-    assert(obj_context->hw_context->run);
+    ASSERT_RET(obj_context->hw_context->run, VA_STATUS_ERROR_OPERATION_FAILED);
     return obj_context->hw_context->run(ctx, obj_config->profile, &obj_context->codec_state, obj_context->hw_context);
 }
 
@@ -2380,7 +2358,7 @@ i965_SyncSurface(VADriverContextP ctx,
     struct i965_driver_data *i965 = i965_driver_data(ctx); 
     struct object_surface *obj_surface = SURFACE(render_target);
 
-    assert(obj_surface);
+    ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
 
     if(obj_surface->bo)
         drm_intel_bo_wait_rendering(obj_surface->bo);
@@ -2396,7 +2374,7 @@ i965_QuerySurfaceStatus(VADriverContextP ctx,
     struct i965_driver_data *i965 = i965_driver_data(ctx); 
     struct object_surface *obj_surface = SURFACE(render_target);
 
-    assert(obj_surface);
+    ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
 
     if (obj_surface->bo) {
         if (drm_intel_bo_busy(obj_surface->bo)){
@@ -2610,7 +2588,7 @@ i965_CreateImage(VADriverContextP ctx,
     struct object_image *obj_image;
     VAStatus va_status = VA_STATUS_ERROR_OPERATION_FAILED;
     VAImageID image_id;
-    unsigned int width2, height2, size2, size;
+    unsigned int size2, size, awidth, aheight;
 
     out_image->image_id = VA_INVALID_ID;
     out_image->buf      = VA_INVALID_ID;
@@ -2630,83 +2608,101 @@ i965_CreateImage(VADriverContextP ctx,
     image->image_id       = image_id;
     image->buf            = VA_INVALID_ID;
 
-    size    = width * height;
-    width2  = (width  + 1) / 2;
-    height2 = (height + 1) / 2;
-    size2   = width2 * height2;
+    awidth = ALIGN(width, i965->codec_info->min_linear_wpitch);
+
+    if ((format->fourcc == VA_FOURCC_YV12) ||
+               (format->fourcc == VA_FOURCC_I420)) {
+       if (awidth % 128 != 0) {
+               awidth = ALIGN(width, 128);     
+       }
+    }
+
+    aheight = ALIGN(height, i965->codec_info->min_linear_hpitch);
+    size    = awidth * aheight;
+    size2    = (awidth / 2) * (aheight / 2);
 
     image->num_palette_entries = 0;
     image->entry_bytes         = 0;
     memset(image->component_order, 0, sizeof(image->component_order));
 
     switch (format->fourcc) {
-    case VA_FOURCC('I','A','4','4'):
-    case VA_FOURCC('A','I','4','4'):
+    case VA_FOURCC_IA44:
+    case VA_FOURCC_AI44:
         image->num_planes = 1;
-        image->pitches[0] = width;
+        image->pitches[0] = awidth;
         image->offsets[0] = 0;
-        image->data_size  = image->offsets[0] + image->pitches[0] * height;
+        image->data_size  = image->offsets[0] + image->pitches[0] * aheight;
         image->num_palette_entries = 16;
         image->entry_bytes         = 3;
         image->component_order[0]  = 'R';
         image->component_order[1]  = 'G';
         image->component_order[2]  = 'B';
         break;
-    case VA_FOURCC('I','A','8','8'):
-    case VA_FOURCC('A','I','8','8'):
+    case VA_FOURCC_IA88:
+    case VA_FOURCC_AI88:
         image->num_planes = 1;
-        image->pitches[0] = width * 2;
+        image->pitches[0] = awidth * 2;
         image->offsets[0] = 0;
-        image->data_size  = image->offsets[0] + image->pitches[0] * height;
+        image->data_size  = image->offsets[0] + image->pitches[0] * aheight;
         image->num_palette_entries = 256;
         image->entry_bytes         = 3;
         image->component_order[0]  = 'R';
         image->component_order[1]  = 'G';
         image->component_order[2]  = 'B';
         break;
-    case VA_FOURCC('A','R','G','B'):
-    case VA_FOURCC('A','B','G','R'):
-    case VA_FOURCC('B','G','R','A'):
-    case VA_FOURCC('R','G','B','A'):
-    case VA_FOURCC('B','G','R','X'):
-    case VA_FOURCC('R','G','B','X'):
+    case VA_FOURCC_ARGB:
+    case VA_FOURCC_ABGR:
+    case VA_FOURCC_BGRA:
+    case VA_FOURCC_RGBA:
+    case VA_FOURCC_BGRX:
+    case VA_FOURCC_RGBX:
         image->num_planes = 1;
-        image->pitches[0] = width * 4;
+        image->pitches[0] = awidth * 4;
         image->offsets[0] = 0;
-        image->data_size  = image->offsets[0] + image->pitches[0] * height;
+        image->data_size  = image->offsets[0] + image->pitches[0] * aheight;
         break;
-    case VA_FOURCC('Y','V','1','2'):
+    case VA_FOURCC_YV12:
         image->num_planes = 3;
-        image->pitches[0] = width;
+        image->pitches[0] = awidth;
         image->offsets[0] = 0;
-        image->pitches[1] = width2;
-        image->offsets[1] = size + size2;
-        image->pitches[2] = width2;
-        image->offsets[2] = size;
+        image->pitches[1] = awidth / 2;
+        image->offsets[1] = size;
+        image->pitches[2] = awidth / 2;
+        image->offsets[2] = size + size2;
         image->data_size  = size + 2 * size2;
         break;
-    case VA_FOURCC('I','4','2','0'):
+    case VA_FOURCC_I420:
         image->num_planes = 3;
-        image->pitches[0] = width;
+        image->pitches[0] = awidth;
         image->offsets[0] = 0;
-        image->pitches[1] = width2;
+        image->pitches[1] = awidth / 2;
         image->offsets[1] = size;
-        image->pitches[2] = width2;
+        image->pitches[2] = awidth / 2;
         image->offsets[2] = size + size2;
         image->data_size  = size + 2 * size2;
         break;
-    case VA_FOURCC('N','V','1','2'):
+    case VA_FOURCC_422H:
+        image->num_planes = 3;
+        image->pitches[0] = awidth;
+        image->offsets[0] = 0;
+        image->pitches[1] = awidth / 2;
+        image->offsets[1] = size;
+        image->pitches[2] = awidth / 2;
+        image->offsets[2] = size + (awidth / 2) * aheight;
+        image->data_size  = size + 2 * ((awidth / 2) * aheight);
+        break;
+    case VA_FOURCC_NV12:
         image->num_planes = 2;
-        image->pitches[0] = width;
+        image->pitches[0] = awidth;
         image->offsets[0] = 0;
-        image->pitches[1] = width;
+        image->pitches[1] = awidth;
         image->offsets[1] = size;
         image->data_size  = size + 2 * size2;
         break;
-    case VA_FOURCC('Y','U','Y','2'):
-    case VA_FOURCC('U','Y','V','Y'):
+    case VA_FOURCC_YUY2:
+    case VA_FOURCC_UYVY:
         image->num_planes = 1;
-        image->pitches[0] = width * 2;
+        image->pitches[0] = awidth * 2;
         image->offsets[0] = 0;
         image->data_size  = size * 2;
         break;
@@ -2748,7 +2744,7 @@ i965_CreateImage(VADriverContextP ctx,
     return va_status;
 }
 
-void 
+VAStatus
 i965_check_alloc_surface_bo(VADriverContextP ctx,
                             struct object_surface *obj_surface,
                             int tiled,
@@ -2759,26 +2755,34 @@ i965_check_alloc_surface_bo(VADriverContextP ctx,
     int region_width, region_height;
 
     if (obj_surface->bo) {
-        assert(obj_surface->fourcc);
-        assert(obj_surface->fourcc == fourcc);
-        assert(obj_surface->subsampling == subsampling);
-        return;
+        ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
+        ASSERT_RET(obj_surface->fourcc == fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
+        ASSERT_RET(obj_surface->subsampling == subsampling, VA_STATUS_ERROR_INVALID_SURFACE);
+        return VA_STATUS_SUCCESS;
     }
 
     obj_surface->x_cb_offset = 0; /* X offset is always 0 */
     obj_surface->x_cr_offset = 0;
 
-    if (tiled) {
-        assert(fourcc != VA_FOURCC('I', '4', '2', '0') &&
-               fourcc != VA_FOURCC('I', 'Y', 'U', 'V') &&
-               fourcc != VA_FOURCC('Y', 'V', '1', '2'));
+    if ((tiled && !obj_surface->user_disable_tiling)) {
+        ASSERT_RET(fourcc != VA_FOURCC_I420 &&
+               fourcc != VA_FOURCC_IYUV &&
+               fourcc != VA_FOURCC_YV12,
+               VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
+        if (obj_surface->user_h_stride_set) {
+            ASSERT_RET(IS_ALIGNED(obj_surface->width, 128), VA_STATUS_ERROR_INVALID_PARAMETER);
+        } else
+            obj_surface->width = ALIGN(obj_surface->orig_width, 128);
+
+        if (obj_surface->user_v_stride_set) {
+            ASSERT_RET(IS_ALIGNED(obj_surface->height, 32), VA_STATUS_ERROR_INVALID_PARAMETER);
+        } else
+            obj_surface->height = ALIGN(obj_surface->orig_height, 32);
 
-        obj_surface->width = ALIGN(obj_surface->orig_width, 128);
-        obj_surface->height = ALIGN(obj_surface->orig_height, 32);
         region_height = obj_surface->height;
 
         switch (fourcc) {
-        case VA_FOURCC('N', 'V', '1', '2'):
+        case VA_FOURCC_NV12:
             assert(subsampling == SUBSAMPLE_YUV420);
             obj_surface->cb_cr_pitch = obj_surface->width;
             obj_surface->cb_cr_width = obj_surface->orig_width / 2;
@@ -2790,7 +2794,7 @@ i965_check_alloc_surface_bo(VADriverContextP ctx,
             
             break;
 
-        case VA_FOURCC('I', 'M', 'C', '1'):
+        case VA_FOURCC_IMC1:
             assert(subsampling == SUBSAMPLE_YUV420);
             obj_surface->cb_cr_pitch = obj_surface->width;
             obj_surface->cb_cr_width = obj_surface->orig_width / 2;
@@ -2802,7 +2806,7 @@ i965_check_alloc_surface_bo(VADriverContextP ctx,
 
             break;
 
-        case VA_FOURCC('I', 'M', 'C', '3'):
+        case VA_FOURCC_IMC3:
             assert(subsampling == SUBSAMPLE_YUV420);
             obj_surface->cb_cr_pitch = obj_surface->width;
             obj_surface->cb_cr_width = obj_surface->orig_width / 2;
@@ -2814,7 +2818,7 @@ i965_check_alloc_surface_bo(VADriverContextP ctx,
             
             break;
 
-        case VA_FOURCC('4', '2', '2', 'H'):
+        case VA_FOURCC_422H:
             assert(subsampling == SUBSAMPLE_YUV422H);
             obj_surface->cb_cr_pitch = obj_surface->width;
             obj_surface->cb_cr_width = obj_surface->orig_width / 2;
@@ -2826,7 +2830,7 @@ i965_check_alloc_surface_bo(VADriverContextP ctx,
 
             break;
 
-        case VA_FOURCC('4', '2', '2', 'V'):
+        case VA_FOURCC_422V:
             assert(subsampling == SUBSAMPLE_YUV422V);
             obj_surface->cb_cr_pitch = obj_surface->width;
             obj_surface->cb_cr_width = obj_surface->orig_width;
@@ -2838,7 +2842,7 @@ i965_check_alloc_surface_bo(VADriverContextP ctx,
 
             break;
 
-        case VA_FOURCC('4', '1', '1', 'P'):
+        case VA_FOURCC_411P:
             assert(subsampling == SUBSAMPLE_YUV411);
             obj_surface->cb_cr_pitch = obj_surface->width;
             obj_surface->cb_cr_width = obj_surface->orig_width / 4;
@@ -2850,7 +2854,7 @@ i965_check_alloc_surface_bo(VADriverContextP ctx,
 
             break;
 
-        case VA_FOURCC('4', '4', '4', 'P'):
+        case VA_FOURCC_444P:
             assert(subsampling == SUBSAMPLE_YUV444);
             obj_surface->cb_cr_pitch = obj_surface->width;
             obj_surface->cb_cr_width = obj_surface->orig_width;
@@ -2862,7 +2866,7 @@ i965_check_alloc_surface_bo(VADriverContextP ctx,
 
             break;
 
-        case VA_FOURCC('Y', '8', '0', '0'):
+        case VA_FOURCC_Y800:
             assert(subsampling == SUBSAMPLE_YUV400);
             obj_surface->cb_cr_pitch = obj_surface->width;
             obj_surface->cb_cr_width = 0;
@@ -2874,8 +2878,8 @@ i965_check_alloc_surface_bo(VADriverContextP ctx,
 
             break;
 
-        case VA_FOURCC('Y', 'U', 'Y', '2'):
-        case VA_FOURCC('U', 'Y', 'V', 'Y'):
+        case VA_FOURCC_YUY2:
+        case VA_FOURCC_UYVY:
             assert(subsampling == SUBSAMPLE_YUV422H);
             obj_surface->width = ALIGN(obj_surface->orig_width * 2, 128);
             obj_surface->cb_cr_pitch = obj_surface->width;
@@ -2888,10 +2892,10 @@ i965_check_alloc_surface_bo(VADriverContextP ctx,
             
             break;
 
-        case VA_FOURCC('R', 'G', 'B', 'A'):
-        case VA_FOURCC('R', 'G', 'B', 'X'):
-        case VA_FOURCC('B', 'G', 'R', 'A'):
-        case VA_FOURCC('B', 'G', 'R', 'X'):
+        case VA_FOURCC_RGBA:
+        case VA_FOURCC_RGBX:
+        case VA_FOURCC_BGRA:
+        case VA_FOURCC_BGRX:
             assert(subsampling == SUBSAMPLE_RGBX);
 
             obj_surface->width = ALIGN(obj_surface->orig_width * 4, 128);
@@ -2901,7 +2905,7 @@ i965_check_alloc_surface_bo(VADriverContextP ctx,
 
         default:
             /* Never get here */
-            assert(0);
+            ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
             break;
         }
     } else {
@@ -2914,7 +2918,7 @@ i965_check_alloc_surface_bo(VADriverContextP ctx,
         region_height = obj_surface->height;
 
         switch (fourcc) {
-        case VA_FOURCC('N', 'V', '1', '2'):
+        case VA_FOURCC_NV12:
             obj_surface->y_cb_offset = obj_surface->height;
             obj_surface->y_cr_offset = obj_surface->height;
             obj_surface->cb_cr_width = obj_surface->orig_width / 2;
@@ -2923,9 +2927,18 @@ i965_check_alloc_surface_bo(VADriverContextP ctx,
             region_height = obj_surface->height + obj_surface->height / 2;
             break;
 
-        case VA_FOURCC('Y', 'V', '1', '2'):
-        case VA_FOURCC('I', '4', '2', '0'):
-            if (fourcc == VA_FOURCC('Y', 'V', '1', '2')) {
+        case VA_FOURCC_YV16:
+            obj_surface->cb_cr_width = obj_surface->orig_width / 2;
+            obj_surface->cb_cr_height = obj_surface->orig_height;
+            obj_surface->y_cr_offset = obj_surface->height;
+            obj_surface->y_cb_offset = obj_surface->y_cr_offset + ALIGN(obj_surface->cb_cr_height, 32) / 2;
+            obj_surface->cb_cr_pitch = obj_surface->width / 2;
+            region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
+            break;
+
+        case VA_FOURCC_YV12:
+        case VA_FOURCC_I420:
+            if (fourcc == VA_FOURCC_YV12) {
                 obj_surface->y_cr_offset = obj_surface->height;
                 obj_surface->y_cb_offset = obj_surface->height + obj_surface->height / 4;
             } else {
@@ -2939,9 +2952,9 @@ i965_check_alloc_surface_bo(VADriverContextP ctx,
             region_height = obj_surface->height + obj_surface->height / 2;
             break;
 
-        case VA_FOURCC('Y', 'U', 'Y', '2'):
-        case VA_FOURCC('U', 'Y', 'V', 'Y'):
-            obj_surface->width = ALIGN(obj_surface->orig_width * 2, 16);
+        case VA_FOURCC_YUY2:
+        case VA_FOURCC_UYVY:
+            obj_surface->width = ALIGN(obj_surface->orig_width * 2, i965->codec_info->min_linear_wpitch);
             obj_surface->y_cb_offset = 0;
             obj_surface->y_cr_offset = 0;
             obj_surface->cb_cr_width = obj_surface->orig_width / 2;
@@ -2950,25 +2963,25 @@ i965_check_alloc_surface_bo(VADriverContextP ctx,
             region_width = obj_surface->width;
             region_height = obj_surface->height;
             break;
-        case VA_FOURCC('R', 'G', 'B', 'A'):
-        case VA_FOURCC('R', 'G', 'B', 'X'):
-        case VA_FOURCC('B', 'G', 'R', 'A'):
-        case VA_FOURCC('B', 'G', 'R', 'X'):
-            obj_surface->width = ALIGN(obj_surface->orig_width * 4, 16);
+        case VA_FOURCC_RGBA:
+        case VA_FOURCC_RGBX:
+        case VA_FOURCC_BGRA:
+        case VA_FOURCC_BGRX:
+            obj_surface->width = ALIGN(obj_surface->orig_width * 4, i965->codec_info->min_linear_wpitch);
             region_width = obj_surface->width;
             region_height = obj_surface->height;
             break;
 
         default:
             /* Never get here */
-            assert(0);
+            ASSERT_RET(0, VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT);
             break;
         }
     }
 
     obj_surface->size = ALIGN(region_width * region_height, 0x1000);
 
-    if (tiled) {
+    if ((tiled && !obj_surface->user_disable_tiling)) {
         uint32_t tiling_mode = I915_TILING_Y; /* always uses Y-tiled format */
         unsigned long pitch;
 
@@ -2992,6 +3005,7 @@ i965_check_alloc_surface_bo(VADriverContextP ctx,
     obj_surface->fourcc = fourcc;
     obj_surface->subsampling = subsampling;
     assert(obj_surface->bo);
+    return VA_STATUS_SUCCESS;
 }
 
 VAStatus i965_DeriveImage(VADriverContextP ctx,
@@ -3013,13 +3027,15 @@ VAStatus i965_DeriveImage(VADriverContextP ctx,
 
     if (!obj_surface->bo) {
         unsigned int is_tiled = 0;
-        unsigned int fourcc = VA_FOURCC('Y', 'V', '1', '2');
+        unsigned int fourcc = VA_FOURCC_YV12;
         i965_guess_surface_format(ctx, surface, &fourcc, &is_tiled);
         int sampling = get_sampling_from_fourcc(fourcc);
-        i965_check_alloc_surface_bo(ctx, obj_surface, is_tiled, fourcc, sampling);
+        va_status = i965_check_alloc_surface_bo(ctx, obj_surface, is_tiled, fourcc, sampling);
+        if (va_status != VA_STATUS_SUCCESS)
+            return va_status;
     }
 
-    assert(obj_surface->fourcc);
+    ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
 
     w_pitch = obj_surface->width;
 
@@ -3053,7 +3069,7 @@ VAStatus i965_DeriveImage(VADriverContextP ctx,
     image->format.bits_per_pixel = 12;
 
     switch (image->format.fourcc) {
-    case VA_FOURCC('Y', 'V', '1', '2'):
+    case VA_FOURCC_YV12:
         image->num_planes = 3;
         image->pitches[0] = w_pitch; /* Y */
         image->offsets[0] = 0;
@@ -3063,7 +3079,17 @@ VAStatus i965_DeriveImage(VADriverContextP ctx,
         image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
         break;
 
-    case VA_FOURCC('N', 'V', '1', '2'):
+    case VA_FOURCC_YV16:
+        image->num_planes = 3;
+        image->pitches[0] = w_pitch; /* Y */
+        image->offsets[0] = 0;
+        image->pitches[1] = obj_surface->cb_cr_pitch; /* V */
+        image->offsets[1] = w_pitch * obj_surface->y_cr_offset;
+        image->pitches[2] = obj_surface->cb_cr_pitch; /* U */
+        image->offsets[2] = w_pitch * obj_surface->y_cb_offset;
+        break;
+
+    case VA_FOURCC_NV12:
         image->num_planes = 2;
         image->pitches[0] = w_pitch; /* Y */
         image->offsets[0] = 0;
@@ -3071,7 +3097,12 @@ VAStatus i965_DeriveImage(VADriverContextP ctx,
         image->offsets[1] = w_pitch * obj_surface->y_cb_offset;
         break;
 
-    case VA_FOURCC('I', '4', '2', '0'):
+    case VA_FOURCC_I420:
+    case VA_FOURCC_422H:
+    case VA_FOURCC_IMC3:
+    case VA_FOURCC_444P:
+    case VA_FOURCC_422V:
+    case VA_FOURCC_411P:
         image->num_planes = 3;
         image->pitches[0] = w_pitch; /* Y */
         image->offsets[0] = 0;
@@ -3080,16 +3111,18 @@ VAStatus i965_DeriveImage(VADriverContextP ctx,
         image->pitches[2] = obj_surface->cb_cr_pitch; /* V */
         image->offsets[2] = w_pitch * obj_surface->y_cr_offset;
         break;
-    case VA_FOURCC('Y', 'U', 'Y', '2'):
-    case VA_FOURCC('U', 'Y', 'V', 'Y'):
+
+    case VA_FOURCC_YUY2:
+    case VA_FOURCC_UYVY:
+    case VA_FOURCC_Y800:
         image->num_planes = 1;
         image->pitches[0] = obj_surface->width; /* Y, width is aligned already */
         image->offsets[0] = 0;
         break;
-    case VA_FOURCC('R', 'G', 'B', 'A'):
-    case VA_FOURCC('R', 'G', 'B', 'X'):
-    case VA_FOURCC('B', 'G', 'R', 'A'):
-    case VA_FOURCC('B', 'G', 'R', 'X'):
+    case VA_FOURCC_RGBA:
+    case VA_FOURCC_RGBX:
+    case VA_FOURCC_BGRA:
+    case VA_FOURCC_BGRX:
         image->num_planes = 1;
         image->pitches[0] = obj_surface->width;
         break;
@@ -3205,43 +3238,44 @@ get_sampling_from_fourcc(unsigned int fourcc)
     int surface_sampling = -1;
 
     switch (fourcc) {
-    case VA_FOURCC('N', 'V', '1', '2'):
-    case VA_FOURCC('Y', 'V', '1', '2'):
-    case VA_FOURCC('I', '4', '2', '0'):
-    case VA_FOURCC('I', 'Y', 'U', 'V'):
-    case VA_FOURCC('I', 'M', 'C', '1'):
-    case VA_FOURCC('I', 'M', 'C', '3'):
+    case VA_FOURCC_NV12:
+    case VA_FOURCC_YV12:
+    case VA_FOURCC_I420:
+    case VA_FOURCC_IYUV:
+    case VA_FOURCC_IMC1:
+    case VA_FOURCC_IMC3:
         surface_sampling = SUBSAMPLE_YUV420;
         break;
-    case VA_FOURCC('Y', 'U', 'Y', '2'):
-    case VA_FOURCC('U', 'Y', 'V', 'Y'):
-    case VA_FOURCC('4', '2', '2', 'H'):
+    case VA_FOURCC_YUY2:
+    case VA_FOURCC_UYVY:
+    case VA_FOURCC_422H:
+    case VA_FOURCC_YV16:
         surface_sampling = SUBSAMPLE_YUV422H;
         break;
-    case VA_FOURCC('4', '2', '2', 'V'):
+    case VA_FOURCC_422V:
         surface_sampling = SUBSAMPLE_YUV422V;
         break;
         
-    case VA_FOURCC('4', '4', '4', 'P'):
+    case VA_FOURCC_444P:
         surface_sampling = SUBSAMPLE_YUV444;
         break;
 
-    case VA_FOURCC('4', '1', '1', 'P'):
+    case VA_FOURCC_411P:
         surface_sampling = SUBSAMPLE_YUV411;
         break;
 
-    case VA_FOURCC('Y', '8', '0', '0'):
+    case VA_FOURCC_Y800:
         surface_sampling = SUBSAMPLE_YUV400;
         break;
-    case VA_FOURCC('R','G','B','A'):
-    case VA_FOURCC('R','G','B','X'):
-    case VA_FOURCC('B','G','R','A'):
-    case VA_FOURCC('B','G','R','X'):
+    case VA_FOURCC_RGBA:
+    case VA_FOURCC_RGBX:
+    case VA_FOURCC_BGRA:
+    case VA_FOURCC_BGRX:
     surface_sampling = SUBSAMPLE_RGBX; 
         break;
     default:
         /* Never get here */
-        assert(0);
+        ASSERT_RET(0, 0);
         break;
 
     }
@@ -3263,7 +3297,7 @@ memcpy_pic(uint8_t *dst, unsigned int dst_stride,
     }
 }
 
-static void
+static VAStatus
 get_image_i420(struct object_image *obj_image, uint8_t *image_data,
                struct object_surface *obj_surface,
                const VARectangle *rect)
@@ -3273,11 +3307,12 @@ get_image_i420(struct object_image *obj_image, uint8_t *image_data,
     const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
     const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
     unsigned int tiling, swizzle;
+    VAStatus va_status = VA_STATUS_SUCCESS;
 
     if (!obj_surface->bo)
-        return;
+        return VA_STATUS_ERROR_INVALID_SURFACE;
 
-    assert(obj_surface->fourcc);
+    ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
     dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
 
     if (tiling != I915_TILING_NONE)
@@ -3286,7 +3321,7 @@ get_image_i420(struct object_image *obj_image, uint8_t *image_data,
         dri_bo_map(obj_surface->bo, 0);
 
     if (!obj_surface->bo->virtual)
-        return;
+        return VA_STATUS_ERROR_INVALID_SURFACE;
 
     /* Dest VA image has either I420 or YV12 format.
        Source VA surface alway has I420 format */
@@ -3322,18 +3357,21 @@ get_image_i420(struct object_image *obj_image, uint8_t *image_data,
         drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
     else
         dri_bo_unmap(obj_surface->bo);
+
+    return va_status;
 }
 
-static void
+static VAStatus
 get_image_nv12(struct object_image *obj_image, uint8_t *image_data,
                struct object_surface *obj_surface,
                const VARectangle *rect)
 {
     uint8_t *dst[2], *src[2];
     unsigned int tiling, swizzle;
+    VAStatus va_status = VA_STATUS_SUCCESS;
 
     if (!obj_surface->bo)
-        return;
+        return VA_STATUS_ERROR_INVALID_SURFACE;
 
     assert(obj_surface->fourcc);
     dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
@@ -3344,7 +3382,7 @@ get_image_nv12(struct object_image *obj_image, uint8_t *image_data,
         dri_bo_map(obj_surface->bo, 0);
 
     if (!obj_surface->bo->virtual)
-        return;
+        return VA_STATUS_ERROR_INVALID_SURFACE;
 
     /* Both dest VA image and source surface have NV12 format */
     dst[0] = image_data + obj_image->image.offsets[0];
@@ -3370,18 +3408,21 @@ get_image_nv12(struct object_image *obj_image, uint8_t *image_data,
         drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
     else
         dri_bo_unmap(obj_surface->bo);
+
+    return va_status;
 }
 
-static void
+static VAStatus
 get_image_yuy2(struct object_image *obj_image, uint8_t *image_data,
                struct object_surface *obj_surface,
                const VARectangle *rect)
 {
     uint8_t *dst, *src;
     unsigned int tiling, swizzle;
+    VAStatus va_status = VA_STATUS_SUCCESS;
 
     if (!obj_surface->bo)
-        return;
+        return VA_STATUS_ERROR_INVALID_SURFACE;
 
     assert(obj_surface->fourcc);
     dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
@@ -3392,7 +3433,7 @@ get_image_yuy2(struct object_image *obj_image, uint8_t *image_data,
         dri_bo_map(obj_surface->bo, 0);
 
     if (!obj_surface->bo->virtual)
-        return;
+        return VA_STATUS_ERROR_INVALID_SURFACE;
 
     /* Both dest VA image and source surface have YUYV format */
     dst = image_data + obj_image->image.offsets[0];
@@ -3409,6 +3450,8 @@ get_image_yuy2(struct object_image *obj_image, uint8_t *image_data,
         drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
     else
         dri_bo_unmap(obj_surface->bo);
+
+    return va_status;
 }
 
 static VAStatus 
@@ -3422,6 +3465,7 @@ i965_sw_getimage(VADriverContextP ctx,
 {
     struct i965_driver_data *i965 = i965_driver_data(ctx);
     struct i965_render_state *render_state = &i965->render_state;
+    VAStatus va_status = VA_STATUS_SUCCESS;
 
     struct object_surface *obj_surface = SURFACE(surface);
     if (!obj_surface)
@@ -3443,7 +3487,6 @@ i965_sw_getimage(VADriverContextP ctx,
     if (obj_surface->fourcc != obj_image->image.format.fourcc)
         return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
 
-    VAStatus va_status;
     void *image_data = NULL;
 
     va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
@@ -3457,20 +3500,20 @@ i965_sw_getimage(VADriverContextP ctx,
     rect.height = height;
 
     switch (obj_image->image.format.fourcc) {
-    case VA_FOURCC('Y','V','1','2'):
-    case VA_FOURCC('I','4','2','0'):
+    case VA_FOURCC_YV12:
+    case VA_FOURCC_I420:
         /* I420 is native format for MPEG-2 decoded surfaces */
         if (render_state->interleaved_uv)
             goto operation_failed;
         get_image_i420(obj_image, image_data, obj_surface, &rect);
         break;
-    case VA_FOURCC('N','V','1','2'):
+    case VA_FOURCC_NV12:
         /* NV12 is native format for H.264 decoded surfaces */
         if (!render_state->interleaved_uv)
             goto operation_failed;
         get_image_nv12(obj_image, image_data, obj_surface, &rect);
         break;
-    case VA_FOURCC('Y','U','Y','2'):
+    case VA_FOURCC_YUY2:
         /* YUY2 is the format supported by overlay plane */
         get_image_yuy2(obj_image, image_data, obj_surface, &rect);
         break;
@@ -3480,7 +3523,10 @@ i965_sw_getimage(VADriverContextP ctx,
         break;
     }
 
-    i965_UnmapBuffer(ctx, obj_image->image.buf);
+    if (va_status != VA_STATUS_SUCCESS)
+        return va_status;
+
+    va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
     return va_status;
 }
 
@@ -3496,7 +3542,7 @@ i965_hw_getimage(VADriverContextP ctx,
     struct i965_driver_data *i965 = i965_driver_data(ctx);
     struct i965_surface src_surface;
     struct i965_surface dst_surface;
-    VAStatus va_status;
+    VAStatus va_status = VA_STATUS_SUCCESS;
     VARectangle rect;
     struct object_surface *obj_surface = SURFACE(surface);
     struct object_image *obj_image = IMAGE(image);
@@ -3553,7 +3599,7 @@ i965_GetImage(VADriverContextP ctx,
               VAImageID image)
 {
     struct i965_driver_data * const i965 = i965_driver_data(ctx);
-    VAStatus va_status;
+    VAStatus va_status = VA_STATUS_SUCCESS;
 
     if (HAS_ACCELERATED_GETIMAGE(i965))
         va_status = i965_hw_getimage(ctx,
@@ -3571,7 +3617,7 @@ i965_GetImage(VADriverContextP ctx,
     return va_status;
 }
 
-static void
+static VAStatus
 put_image_i420(struct object_surface *obj_surface,
                const VARectangle *dst_rect,
                struct object_image *obj_image, uint8_t *image_data,
@@ -3582,13 +3628,13 @@ put_image_i420(struct object_surface *obj_surface,
     const int U = obj_image->image.format.fourcc == obj_surface->fourcc ? 1 : 2;
     const int V = obj_image->image.format.fourcc == obj_surface->fourcc ? 2 : 1;
     unsigned int tiling, swizzle;
+    VAStatus va_status = VA_STATUS_SUCCESS;
 
-    if (!obj_surface->bo)
-        return;
+    ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
 
-    assert(obj_surface->fourcc);
-    assert(dst_rect->width == src_rect->width);
-    assert(dst_rect->height == src_rect->height);
+    ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
+    ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
+    ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
     dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
 
     if (tiling != I915_TILING_NONE)
@@ -3597,7 +3643,7 @@ put_image_i420(struct object_surface *obj_surface,
         dri_bo_map(obj_surface->bo, 0);
 
     if (!obj_surface->bo->virtual)
-        return;
+        return VA_STATUS_ERROR_INVALID_SURFACE;
 
     /* Dest VA image has either I420 or YV12 format.
        Source VA surface alway has I420 format */
@@ -3633,9 +3679,11 @@ put_image_i420(struct object_surface *obj_surface,
         drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
     else
         dri_bo_unmap(obj_surface->bo);
+
+    return va_status;
 }
 
-static void
+static VAStatus
 put_image_nv12(struct object_surface *obj_surface,
                const VARectangle *dst_rect,
                struct object_image *obj_image, uint8_t *image_data,
@@ -3643,13 +3691,14 @@ put_image_nv12(struct object_surface *obj_surface,
 {
     uint8_t *dst[2], *src[2];
     unsigned int tiling, swizzle;
+    VAStatus va_status = VA_STATUS_SUCCESS;
 
     if (!obj_surface->bo)
-        return;
+        return VA_STATUS_ERROR_INVALID_SURFACE;
 
-    assert(obj_surface->fourcc);
-    assert(dst_rect->width == src_rect->width);
-    assert(dst_rect->height == src_rect->height);
+    ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
+    ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
+    ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
     dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
 
     if (tiling != I915_TILING_NONE)
@@ -3658,7 +3707,7 @@ put_image_nv12(struct object_surface *obj_surface,
         dri_bo_map(obj_surface->bo, 0);
 
     if (!obj_surface->bo->virtual)
-        return;
+        return VA_STATUS_ERROR_INVALID_SURFACE;
 
     /* Both dest VA image and source surface have NV12 format */
     dst[0] = (uint8_t *)obj_surface->bo->virtual;
@@ -3684,9 +3733,11 @@ put_image_nv12(struct object_surface *obj_surface,
         drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
     else
         dri_bo_unmap(obj_surface->bo);
+
+    return va_status;
 }
 
-static void
+static VAStatus
 put_image_yuy2(struct object_surface *obj_surface,
                const VARectangle *dst_rect,
                struct object_image *obj_image, uint8_t *image_data,
@@ -3694,13 +3745,12 @@ put_image_yuy2(struct object_surface *obj_surface,
 {
     uint8_t *dst, *src;
     unsigned int tiling, swizzle;
+    VAStatus va_status = VA_STATUS_SUCCESS;
 
-    if (!obj_surface->bo)
-        return;
-
-    assert(obj_surface->fourcc);
-    assert(dst_rect->width == src_rect->width);
-    assert(dst_rect->height == src_rect->height);
+    ASSERT_RET(obj_surface->bo, VA_STATUS_ERROR_INVALID_SURFACE);
+    ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
+    ASSERT_RET(dst_rect->width == src_rect->width, VA_STATUS_ERROR_UNIMPLEMENTED);
+    ASSERT_RET(dst_rect->height == src_rect->height, VA_STATUS_ERROR_UNIMPLEMENTED);
     dri_bo_get_tiling(obj_surface->bo, &tiling, &swizzle);
 
     if (tiling != I915_TILING_NONE)
@@ -3709,7 +3759,7 @@ put_image_yuy2(struct object_surface *obj_surface,
         dri_bo_map(obj_surface->bo, 0);
 
     if (!obj_surface->bo->virtual)
-        return;
+        return VA_STATUS_ERROR_INVALID_SURFACE;
 
     /* Both dest VA image and source surface have YUY2 format */
     dst = (uint8_t *)obj_surface->bo->virtual;
@@ -3726,6 +3776,8 @@ put_image_yuy2(struct object_surface *obj_surface,
         drm_intel_gem_bo_unmap_gtt(obj_surface->bo);
     else
         dri_bo_unmap(obj_surface->bo);
+
+    return va_status;
 }
 
 
@@ -3744,13 +3796,12 @@ i965_sw_putimage(VADriverContextP ctx,
 {
     struct i965_driver_data *i965 = i965_driver_data(ctx);
     struct object_surface *obj_surface = SURFACE(surface);
-
-    if (!obj_surface)
-        return VA_STATUS_ERROR_INVALID_SURFACE;
-
     struct object_image *obj_image = IMAGE(image);
-    if (!obj_image)
-        return VA_STATUS_ERROR_INVALID_IMAGE;
+    VAStatus va_status = VA_STATUS_SUCCESS;
+    void *image_data = NULL;
+
+    ASSERT_RET(obj_surface, VA_STATUS_ERROR_INVALID_SURFACE);
+    ASSERT_RET(obj_image, VA_STATUS_ERROR_INVALID_IMAGE);
 
     if (src_x < 0 || src_y < 0)
         return VA_STATUS_ERROR_INVALID_PARAMETER;
@@ -3775,7 +3826,7 @@ i965_sw_putimage(VADriverContextP ctx,
 
     else {
         /* VA is surface not used for decoding, use same VA image format */
-        i965_check_alloc_surface_bo(
+        va_status = i965_check_alloc_surface_bo(
             ctx,
             obj_surface,
             0, /* XXX: don't use tiled surface */
@@ -3783,8 +3834,8 @@ i965_sw_putimage(VADriverContextP ctx,
             get_sampling_from_fourcc (obj_image->image.format.fourcc));
     }
 
-    VAStatus va_status;
-    void *image_data = NULL;
+    if (va_status != VA_STATUS_SUCCESS)
+        return va_status;
 
     va_status = i965_MapBuffer(ctx, obj_image->image.buf, &image_data);
     if (va_status != VA_STATUS_SUCCESS)
@@ -3801,22 +3852,24 @@ i965_sw_putimage(VADriverContextP ctx,
     dest_rect.height = dest_height;
      
     switch (obj_image->image.format.fourcc) {
-    case VA_FOURCC('Y','V','1','2'):
-    case VA_FOURCC('I','4','2','0'):
-        put_image_i420(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
+    case VA_FOURCC_YV12:
+    case VA_FOURCC_I420:
+        va_status = put_image_i420(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
         break;
-    case VA_FOURCC('N','V','1','2'):
-        put_image_nv12(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
+    case VA_FOURCC_NV12:
+        va_status = put_image_nv12(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
         break;
-    case VA_FOURCC('Y','U','Y','2'):
-        put_image_yuy2(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
+    case VA_FOURCC_YUY2:
+        va_status = put_image_yuy2(obj_surface, &dest_rect, obj_image, image_data, &src_rect);
         break;
     default:
         va_status = VA_STATUS_ERROR_OPERATION_FAILED;
         break;
     }
+    if (va_status != VA_STATUS_SUCCESS)
+        return va_status;
 
-    i965_UnmapBuffer(ctx, obj_image->image.buf);
+    va_status = i965_UnmapBuffer(ctx, obj_image->image.buf);
     return va_status;
 }
 
@@ -3840,11 +3893,8 @@ i965_hw_putimage(VADriverContextP ctx,
     VAStatus va_status = VA_STATUS_SUCCESS;
     VARectangle src_rect, dst_rect;
 
-    if (!obj_surface)
-        return VA_STATUS_ERROR_INVALID_SURFACE;
-
-    if (!obj_image || !obj_image->bo)
-        return VA_STATUS_ERROR_INVALID_IMAGE;
+    ASSERT_RET(obj_surface,VA_STATUS_ERROR_INVALID_SURFACE);
+    ASSERT_RET(obj_image && obj_image->bo, VA_STATUS_ERROR_INVALID_IMAGE);
 
     if (src_x < 0 ||
         src_y < 0 ||
@@ -3870,7 +3920,7 @@ i965_hw_putimage(VADriverContextP ctx,
                                     surface_sampling);
     }
 
-    assert(obj_surface->fourcc);
+    ASSERT_RET(obj_surface->fourcc, VA_STATUS_ERROR_INVALID_SURFACE);
 
     src_surface.base = (struct object_base *)obj_image;
     src_surface.type = I965_SURFACE_TYPE_IMAGE;
@@ -3993,10 +4043,7 @@ i965_BufferInfo(
     i965 = i965_driver_data(ctx);
     obj_buffer = BUFFER(buf_id);
 
-    assert(obj_buffer);
-
-    if (!obj_buffer)
-        return VA_STATUS_ERROR_INVALID_BUFFER;
+    ASSERT_RET(obj_buffer, VA_STATUS_ERROR_INVALID_BUFFER);
 
     *type = obj_buffer->type;
     *size = obj_buffer->size_element;
@@ -4025,15 +4072,15 @@ i965_LockSurface(
     struct object_surface *obj_surface = NULL;
     VAImage tmpImage;
 
-    assert(fourcc);
-    assert(luma_stride);
-    assert(chroma_u_stride);
-    assert(chroma_v_stride);
-    assert(luma_offset);
-    assert(chroma_u_offset);
-    assert(chroma_v_offset);
-    assert(buffer_name);
-    assert(buffer);
+    ASSERT_RET(fourcc, VA_STATUS_ERROR_INVALID_PARAMETER);
+    ASSERT_RET(luma_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
+    ASSERT_RET(chroma_u_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
+    ASSERT_RET(chroma_v_stride, VA_STATUS_ERROR_INVALID_PARAMETER);
+    ASSERT_RET(luma_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
+    ASSERT_RET(chroma_u_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
+    ASSERT_RET(chroma_v_offset, VA_STATUS_ERROR_INVALID_PARAMETER);
+    ASSERT_RET(buffer_name, VA_STATUS_ERROR_INVALID_PARAMETER);
+    ASSERT_RET(buffer, VA_STATUS_ERROR_INVALID_PARAMETER);
 
     tmpImage.image_id = VA_INVALID_ID;
 
@@ -4168,41 +4215,42 @@ i965_GetSurfaceAttributes(
             attrib_list[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
 
             if (attrib_list[i].value.value.i == 0) {
-                if (IS_G4X(i965->intel.device_id)) {
+                if (IS_G4X(i965->intel.device_info)) {
                     if (obj_config->profile == VAProfileMPEG2Simple ||
                         obj_config->profile == VAProfileMPEG2Main) {
-                        attrib_list[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
+                        attrib_list[i].value.value.i = VA_FOURCC_I420;
                     } else {
                         assert(0);
                         attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
                     }
-                } else if (IS_IRONLAKE(i965->intel.device_id)) {
+                } else if (IS_IRONLAKE(i965->intel.device_info)) {
                     if (obj_config->profile == VAProfileMPEG2Simple ||
                         obj_config->profile == VAProfileMPEG2Main) {
-                        attrib_list[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
-                    } else if (obj_config->profile == VAProfileH264Baseline ||
+                        attrib_list[i].value.value.i = VA_FOURCC_I420;
+                    } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
                                obj_config->profile == VAProfileH264Main ||
                                obj_config->profile == VAProfileH264High) {
-                        attrib_list[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
+                        attrib_list[i].value.value.i = VA_FOURCC_NV12;
                     } else if (obj_config->profile == VAProfileNone) {
-                        attrib_list[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
+                        attrib_list[i].value.value.i = VA_FOURCC_NV12;
                     } else {
                         assert(0);
                         attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
                     }
-                } else if (IS_GEN6(i965->intel.device_id)) {
-                    attrib_list[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');                    
-                } else if (IS_GEN7(i965->intel.device_id)) {
+                } else if (IS_GEN6(i965->intel.device_info)) {
+                    attrib_list[i].value.value.i = VA_FOURCC_NV12;
+                } else if (IS_GEN7(i965->intel.device_info) ||
+                           IS_GEN8(i965->intel.device_info)) {
                     if (obj_config->profile == VAProfileJPEGBaseline)
                         attrib_list[i].value.value.i = 0; /* internal format */
                     else
-                        attrib_list[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
+                        attrib_list[i].value.value.i = VA_FOURCC_NV12;
                 }
             } else {
-                if (IS_G4X(i965->intel.device_id)) {
+                if (IS_G4X(i965->intel.device_info)) {
                     if (obj_config->profile == VAProfileMPEG2Simple ||
                         obj_config->profile == VAProfileMPEG2Main) {
-                        if (attrib_list[i].value.value.i != VA_FOURCC('I', '4', '2', '0')) {
+                        if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
                             attrib_list[i].value.value.i = 0;
                             attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
                         }
@@ -4210,30 +4258,30 @@ i965_GetSurfaceAttributes(
                         assert(0);
                         attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
                     }
-                } else if (IS_IRONLAKE(i965->intel.device_id)) {
+                } else if (IS_IRONLAKE(i965->intel.device_info)) {
                     if (obj_config->profile == VAProfileMPEG2Simple ||
                         obj_config->profile == VAProfileMPEG2Main) {
-                        if (attrib_list[i].value.value.i != VA_FOURCC('I', '4', '2', '0')) {
+                        if (attrib_list[i].value.value.i != VA_FOURCC_I420) {
                             attrib_list[i].value.value.i = 0;                            
                             attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
                         }
-                    } else if (obj_config->profile == VAProfileH264Baseline ||
+                    } else if (obj_config->profile == VAProfileH264ConstrainedBaseline ||
                                obj_config->profile == VAProfileH264Main ||
                                obj_config->profile == VAProfileH264High) {
-                        if (attrib_list[i].value.value.i != VA_FOURCC('N', 'V', '1', '2')) {
+                        if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
                             attrib_list[i].value.value.i = 0;
                             attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
                         }
                     } else if (obj_config->profile == VAProfileNone) {
                         switch (attrib_list[i].value.value.i) {
-                        case VA_FOURCC('N', 'V', '1', '2'):
-                        case VA_FOURCC('I', '4', '2', '0'):
-                        case VA_FOURCC('Y', 'V', '1', '2'):
-                        case VA_FOURCC('Y', 'U', 'Y', '2'):
-                        case VA_FOURCC('B', 'G', 'R', 'A'):
-                        case VA_FOURCC('B', 'G', 'R', 'X'):
-                        case VA_FOURCC('R', 'G', 'B', 'X'):
-                        case VA_FOURCC('R', 'G', 'B', 'A'):
+                        case VA_FOURCC_NV12:
+                        case VA_FOURCC_I420:
+                        case VA_FOURCC_YV12:
+                        case VA_FOURCC_YUY2:
+                        case VA_FOURCC_BGRA:
+                        case VA_FOURCC_BGRX:
+                        case VA_FOURCC_RGBX:
+                        case VA_FOURCC_RGBA:
                             break;
                         default:
                             attrib_list[i].value.value.i = 0;                            
@@ -4244,18 +4292,18 @@ i965_GetSurfaceAttributes(
                         assert(0);
                         attrib_list[i].flags = VA_SURFACE_ATTRIB_NOT_SUPPORTED;
                     }
-                } else if (IS_GEN6(i965->intel.device_id)) {
+                } else if (IS_GEN6(i965->intel.device_info)) {
                     if (obj_config->entrypoint == VAEntrypointEncSlice ||
                         obj_config->entrypoint == VAEntrypointVideoProc) {
                         switch (attrib_list[i].value.value.i) {
-                        case VA_FOURCC('N', 'V', '1', '2'):
-                        case VA_FOURCC('I', '4', '2', '0'):
-                        case VA_FOURCC('Y', 'V', '1', '2'):
-                        case VA_FOURCC('Y', 'U', 'Y', '2'):
-                        case VA_FOURCC('B', 'G', 'R', 'A'):
-                        case VA_FOURCC('B', 'G', 'R', 'X'):
-                        case VA_FOURCC('R', 'G', 'B', 'X'):
-                        case VA_FOURCC('R', 'G', 'B', 'A'):
+                        case VA_FOURCC_NV12:
+                        case VA_FOURCC_I420:
+                        case VA_FOURCC_YV12:
+                        case VA_FOURCC_YUY2:
+                        case VA_FOURCC_BGRA:
+                        case VA_FOURCC_BGRX:
+                        case VA_FOURCC_RGBX:
+                        case VA_FOURCC_RGBA:
                             break;
                         default:
                             attrib_list[i].value.value.i = 0;                            
@@ -4263,18 +4311,19 @@ i965_GetSurfaceAttributes(
                             break;
                         }
                     } else {
-                        if (attrib_list[i].value.value.i != VA_FOURCC('N', 'V', '1', '2')) {
+                        if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
                             attrib_list[i].value.value.i = 0;
                             attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
                         }
                     }
-                } else if (IS_GEN7(i965->intel.device_id)) {
+                } else if (IS_GEN7(i965->intel.device_info) ||
+                           IS_GEN8(i965->intel.device_info)) {
                     if (obj_config->entrypoint == VAEntrypointEncSlice ||
                         obj_config->entrypoint == VAEntrypointVideoProc) {
                         switch (attrib_list[i].value.value.i) {
-                        case VA_FOURCC('N', 'V', '1', '2'):
-                        case VA_FOURCC('I', '4', '2', '0'):
-                        case VA_FOURCC('Y', 'V', '1', '2'):
+                        case VA_FOURCC_NV12:
+                        case VA_FOURCC_I420:
+                        case VA_FOURCC_YV12:
                             break;
                         default:
                             attrib_list[i].value.value.i = 0;                            
@@ -4286,7 +4335,7 @@ i965_GetSurfaceAttributes(
                             attrib_list[i].value.value.i = 0;   /* JPEG decoding always uses an internal format */
                             attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
                         } else {
-                            if (attrib_list[i].value.value.i != VA_FOURCC('N', 'V', '1', '2')) {
+                            if (attrib_list[i].value.value.i != VA_FOURCC_NV12) {
                                 attrib_list[i].value.value.i = 0;
                                 attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
                             }
@@ -4351,47 +4400,47 @@ i965_QuerySurfaceAttributes(VADriverContextP ctx,
     if (attribs == NULL)
         return VA_STATUS_ERROR_ALLOCATION_FAILED;
 
-    if (IS_G4X(i965->intel.device_id)) {
+    if (IS_G4X(i965->intel.device_info)) {
         if (obj_config->profile == VAProfileMPEG2Simple ||
             obj_config->profile == VAProfileMPEG2Main) {
             attribs[i].type = VASurfaceAttribPixelFormat;
             attribs[i].value.type = VAGenericValueTypeInteger;
             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
-            attribs[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
+            attribs[i].value.value.i = VA_FOURCC_I420;
             i++;
         }
-    } else if (IS_IRONLAKE(i965->intel.device_id)) {
+    } else if (IS_IRONLAKE(i965->intel.device_info)) {
         switch (obj_config->profile) {
         case VAProfileMPEG2Simple:
         case VAProfileMPEG2Main:
             attribs[i].type = VASurfaceAttribPixelFormat;
             attribs[i].value.type = VAGenericValueTypeInteger;
             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
-            attribs[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
+            attribs[i].value.value.i = VA_FOURCC_I420;
             i++;
             
             break;
 
-        case VAProfileH264Baseline:
+        case VAProfileH264ConstrainedBaseline:
         case VAProfileH264Main:
         case VAProfileH264High:
             attribs[i].type = VASurfaceAttribPixelFormat;
             attribs[i].value.type = VAGenericValueTypeInteger;
             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
-            attribs[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
+            attribs[i].value.value.i = VA_FOURCC_NV12;
             i++;
 
         case VAProfileNone:
             attribs[i].type = VASurfaceAttribPixelFormat;
             attribs[i].value.type = VAGenericValueTypeInteger;
             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
-            attribs[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
+            attribs[i].value.value.i = VA_FOURCC_NV12;
             i++;
 
             attribs[i].type = VASurfaceAttribPixelFormat;
             attribs[i].value.type = VAGenericValueTypeInteger;
             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
-            attribs[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
+            attribs[i].value.value.i = VA_FOURCC_I420;
             i++;
 
             break;
@@ -4399,102 +4448,102 @@ i965_QuerySurfaceAttributes(VADriverContextP ctx,
         default:
             break;
         }
-    } else if (IS_GEN6(i965->intel.device_id)) {
+    } else if (IS_GEN6(i965->intel.device_info)) {
         if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
             attribs[i].type = VASurfaceAttribPixelFormat;
             attribs[i].value.type = VAGenericValueTypeInteger;
             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
-            attribs[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
+            attribs[i].value.value.i = VA_FOURCC_NV12;
             i++;
         } else if (obj_config->entrypoint == VAEntrypointEncSlice ||  /* encode */
                    obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */ 
             attribs[i].type = VASurfaceAttribPixelFormat;
             attribs[i].value.type = VAGenericValueTypeInteger;
             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
-            attribs[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
+            attribs[i].value.value.i = VA_FOURCC_NV12;
             i++;
 
             attribs[i].type = VASurfaceAttribPixelFormat;
             attribs[i].value.type = VAGenericValueTypeInteger;
             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
-            attribs[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
+            attribs[i].value.value.i = VA_FOURCC_I420;
             i++;
 
             attribs[i].type = VASurfaceAttribPixelFormat;
             attribs[i].value.type = VAGenericValueTypeInteger;
             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
-            attribs[i].value.value.i = VA_FOURCC('Y', 'V', '1', '2');
+            attribs[i].value.value.i = VA_FOURCC_YV12;
             i++;
 
             if (obj_config->entrypoint == VAEntrypointVideoProc) {
                 attribs[i].type = VASurfaceAttribPixelFormat;
                 attribs[i].value.type = VAGenericValueTypeInteger;
                 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
-                attribs[i].value.value.i = VA_FOURCC('Y', 'U', 'Y', '2');
+                attribs[i].value.value.i = VA_FOURCC_YUY2;
                 i++;
 
                 attribs[i].type = VASurfaceAttribPixelFormat;
                 attribs[i].value.type = VAGenericValueTypeInteger;
                 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
-                attribs[i].value.value.i = VA_FOURCC('R', 'G', 'B', 'A');
+                attribs[i].value.value.i = VA_FOURCC_RGBA;
                 i++;
 
                 attribs[i].type = VASurfaceAttribPixelFormat;
                 attribs[i].value.type = VAGenericValueTypeInteger;
                 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
-                attribs[i].value.value.i = VA_FOURCC('R', 'G', 'B', 'X');
+                attribs[i].value.value.i = VA_FOURCC_RGBX;
                 i++;
             }
         }
-    } else if (IS_GEN7(i965->intel.device_id)) {
+    } else if (IS_GEN7(i965->intel.device_info)) {
         if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
             if (obj_config->profile == VAProfileJPEGBaseline) {
                 attribs[i].type = VASurfaceAttribPixelFormat;
                 attribs[i].value.type = VAGenericValueTypeInteger;
                 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
-                attribs[i].value.value.i = VA_FOURCC('I', 'M', 'C', '3');
+                attribs[i].value.value.i = VA_FOURCC_IMC3;
                 i++;
 
                 attribs[i].type = VASurfaceAttribPixelFormat;
                 attribs[i].value.type = VAGenericValueTypeInteger;
                 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
-                attribs[i].value.value.i = VA_FOURCC('I', 'M', 'C', '1');
+                attribs[i].value.value.i = VA_FOURCC_IMC1;
                 i++;
 
                 attribs[i].type = VASurfaceAttribPixelFormat;
                 attribs[i].value.type = VAGenericValueTypeInteger;
                 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
-                attribs[i].value.value.i = VA_FOURCC('Y', '8', '0', '0');
+                attribs[i].value.value.i = VA_FOURCC_Y800;
                 i++;
 
                 attribs[i].type = VASurfaceAttribPixelFormat;
                 attribs[i].value.type = VAGenericValueTypeInteger;
                 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
-                attribs[i].value.value.i = VA_FOURCC('4', '1', '1', 'P');
+                attribs[i].value.value.i = VA_FOURCC_411P;
                 i++;
 
                 attribs[i].type = VASurfaceAttribPixelFormat;
                 attribs[i].value.type = VAGenericValueTypeInteger;
                 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
-                attribs[i].value.value.i = VA_FOURCC('4', '2', '2', 'H');
+                attribs[i].value.value.i = VA_FOURCC_422H;
                 i++;
 
                 attribs[i].type = VASurfaceAttribPixelFormat;
                 attribs[i].value.type = VAGenericValueTypeInteger;
                 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
-                attribs[i].value.value.i = VA_FOURCC('4', '2', '2', 'V');
+                attribs[i].value.value.i = VA_FOURCC_422V;
                 i++;
 
                 attribs[i].type = VASurfaceAttribPixelFormat;
                 attribs[i].value.type = VAGenericValueTypeInteger;
                 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
-                attribs[i].value.value.i = VA_FOURCC('4', '4', '4', 'P');
+                attribs[i].value.value.i = VA_FOURCC_444P;
                 i++;
             } else {
                 attribs[i].type = VASurfaceAttribPixelFormat;
                 attribs[i].value.type = VAGenericValueTypeInteger;
                 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
-                attribs[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
+                attribs[i].value.value.i = VA_FOURCC_NV12;
                 i++;
             }
         } else if (obj_config->entrypoint == VAEntrypointEncSlice ||  /* encode */
@@ -4502,44 +4551,166 @@ i965_QuerySurfaceAttributes(VADriverContextP ctx,
             attribs[i].type = VASurfaceAttribPixelFormat;
             attribs[i].value.type = VAGenericValueTypeInteger;
             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
-            attribs[i].value.value.i = VA_FOURCC('N', 'V', '1', '2');
+            attribs[i].value.value.i = VA_FOURCC_NV12;
             i++;
 
             attribs[i].type = VASurfaceAttribPixelFormat;
             attribs[i].value.type = VAGenericValueTypeInteger;
             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
-            attribs[i].value.value.i = VA_FOURCC('I', '4', '2', '0');
+            attribs[i].value.value.i = VA_FOURCC_I420;
             i++;
 
             attribs[i].type = VASurfaceAttribPixelFormat;
             attribs[i].value.type = VAGenericValueTypeInteger;
             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
-            attribs[i].value.value.i = VA_FOURCC('Y', 'V', '1', '2');
+            attribs[i].value.value.i = VA_FOURCC_YV12;
             i++;
 
             attribs[i].type = VASurfaceAttribPixelFormat;
             attribs[i].value.type = VAGenericValueTypeInteger;
             attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
-            attribs[i].value.value.i = VA_FOURCC('I', 'M', 'C', '3');
+            attribs[i].value.value.i = VA_FOURCC_IMC3;
             i++;
 
             if (obj_config->entrypoint == VAEntrypointVideoProc) {
                 attribs[i].type = VASurfaceAttribPixelFormat;
                 attribs[i].value.type = VAGenericValueTypeInteger;
                 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
-                attribs[i].value.value.i = VA_FOURCC('Y', 'U', 'Y', '2');
+                attribs[i].value.value.i = VA_FOURCC_YUY2;
+                i++;
+
+                attribs[i].type = VASurfaceAttribPixelFormat;
+                attribs[i].value.type = VAGenericValueTypeInteger;
+                attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
+                attribs[i].value.value.i = VA_FOURCC_RGBA;
                 i++;
 
                 attribs[i].type = VASurfaceAttribPixelFormat;
                 attribs[i].value.type = VAGenericValueTypeInteger;
                 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
-                attribs[i].value.value.i = VA_FOURCC('R', 'G', 'B', 'A');
+                attribs[i].value.value.i = VA_FOURCC_RGBX;
                 i++;
 
                 attribs[i].type = VASurfaceAttribPixelFormat;
                 attribs[i].value.type = VAGenericValueTypeInteger;
                 attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
-                attribs[i].value.value.i = VA_FOURCC('R', 'G', 'B', 'X');
+                attribs[i].value.value.i = VA_FOURCC_YV16;
+                i++;
+            }
+        }
+    } else if (IS_GEN8(i965->intel.device_info)) {
+        if (obj_config->entrypoint == VAEntrypointVLD) { /* decode */
+            if (obj_config->profile == VAProfileJPEGBaseline) {
+                attribs[i].type = VASurfaceAttribPixelFormat;
+                attribs[i].value.type = VAGenericValueTypeInteger;
+                attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
+                attribs[i].value.value.i = VA_FOURCC_IMC3;
+                i++;
+
+                attribs[i].type = VASurfaceAttribPixelFormat;
+                attribs[i].value.type = VAGenericValueTypeInteger;
+                attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
+                attribs[i].value.value.i = VA_FOURCC_IMC1;
+                i++;
+
+                attribs[i].type = VASurfaceAttribPixelFormat;
+                attribs[i].value.type = VAGenericValueTypeInteger;
+                attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
+                attribs[i].value.value.i = VA_FOURCC_Y800;
+                i++;
+
+                attribs[i].type = VASurfaceAttribPixelFormat;
+                attribs[i].value.type = VAGenericValueTypeInteger;
+                attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
+                attribs[i].value.value.i = VA_FOURCC_411P;
+                i++;
+
+                attribs[i].type = VASurfaceAttribPixelFormat;
+                attribs[i].value.type = VAGenericValueTypeInteger;
+                attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
+                attribs[i].value.value.i = VA_FOURCC_422H;
+                i++;
+
+                attribs[i].type = VASurfaceAttribPixelFormat;
+                attribs[i].value.type = VAGenericValueTypeInteger;
+                attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
+                attribs[i].value.value.i = VA_FOURCC_422V;
+                i++;
+
+                attribs[i].type = VASurfaceAttribPixelFormat;
+                attribs[i].value.type = VAGenericValueTypeInteger;
+                attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
+                attribs[i].value.value.i = VA_FOURCC_444P;
+                i++;
+            } else {
+                attribs[i].type = VASurfaceAttribPixelFormat;
+                attribs[i].value.type = VAGenericValueTypeInteger;
+                attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
+                attribs[i].value.value.i = VA_FOURCC_NV12;
+                i++;
+            }
+        } else if (obj_config->entrypoint == VAEntrypointEncSlice ||  /* encode */
+                   obj_config->entrypoint == VAEntrypointVideoProc) { /* vpp */
+
+            attribs[i].type = VASurfaceAttribPixelFormat;
+            attribs[i].value.type = VAGenericValueTypeInteger;
+            attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
+            attribs[i].value.value.i = VA_FOURCC_NV12;
+            i++;
+
+            attribs[i].type = VASurfaceAttribPixelFormat;
+            attribs[i].value.type = VAGenericValueTypeInteger;
+            attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
+            attribs[i].value.value.i = VA_FOURCC_I420;
+            i++;
+
+            attribs[i].type = VASurfaceAttribPixelFormat;
+            attribs[i].value.type = VAGenericValueTypeInteger;
+            attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
+            attribs[i].value.value.i = VA_FOURCC_YV12;
+            i++;
+
+            attribs[i].type = VASurfaceAttribPixelFormat;
+            attribs[i].value.type = VAGenericValueTypeInteger;
+            attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
+            attribs[i].value.value.i = VA_FOURCC_IMC3;
+            i++;
+
+            if (obj_config->entrypoint == VAEntrypointVideoProc) {
+                attribs[i].type = VASurfaceAttribPixelFormat;
+                attribs[i].value.type = VAGenericValueTypeInteger;
+                attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
+                attribs[i].value.value.i = VA_FOURCC_YUY2;
+                i++;
+
+                attribs[i].type = VASurfaceAttribPixelFormat;
+                attribs[i].value.type = VAGenericValueTypeInteger;
+                attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
+                attribs[i].value.value.i = VA_FOURCC_RGBA;
+                i++;
+
+                attribs[i].type = VASurfaceAttribPixelFormat;
+                attribs[i].value.type = VAGenericValueTypeInteger;
+                attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
+                attribs[i].value.value.i = VA_FOURCC_RGBX;
+                i++;
+
+                attribs[i].type = VASurfaceAttribPixelFormat;
+                attribs[i].value.type = VAGenericValueTypeInteger;
+                attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
+                attribs[i].value.value.i = VA_FOURCC_BGRA;
+                i++;
+
+                attribs[i].type = VASurfaceAttribPixelFormat;
+                attribs[i].value.type = VAGenericValueTypeInteger;
+                attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
+                attribs[i].value.value.i = VA_FOURCC_BGRX;
+                i++;
+
+                attribs[i].type = VASurfaceAttribPixelFormat;
+                attribs[i].value.type = VAGenericValueTypeInteger;
+                attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | VA_SURFACE_ATTRIB_SETTABLE;
+                attribs[i].value.value.i = VA_FOURCC_YV16;
                 i++;
             }
         }
@@ -4805,35 +4976,33 @@ VAStatus i965_QueryVideoProcPipelineCaps(
         } else if (base->type == VAProcFilterDeinterlacing) {
             VAProcFilterParameterBufferDeinterlacing *deint = (VAProcFilterParameterBufferDeinterlacing *)base;
 
-            assert(deint->algorithm == VAProcDeinterlacingBob ||
+            ASSERT_RET(deint->algorithm == VAProcDeinterlacingBob ||
                    deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
-                   deint->algorithm == VAProcDeinterlacingMotionCompensated);
+                   deint->algorithm == VAProcDeinterlacingMotionCompensated,
+                   VA_STATUS_ERROR_INVALID_PARAMETER);
             
             if (deint->algorithm == VAProcDeinterlacingMotionAdaptive ||
                 deint->algorithm == VAProcDeinterlacingMotionCompensated);
                 pipeline_cap->num_forward_references++;
+        } else if (base->type == VAProcFilterSkinToneEnhancement) {
+                VAProcFilterParameterBuffer *stde = (VAProcFilterParameterBuffer *)base;
+                (void)stde;
         }
     }
 
     return VA_STATUS_SUCCESS;
 }
 
+extern const struct hw_codec_info *i965_get_codec_info(int devid);
+
 static bool
 i965_driver_data_init(VADriverContextP ctx)
 {
     struct i965_driver_data *i965 = i965_driver_data(ctx); 
 
-    if (IS_HASWELL(i965->intel.device_id))
-       i965->codec_info = &gen75_hw_codec_info;
-    else if (IS_G4X(i965->intel.device_id))
-        i965->codec_info = &g4x_hw_codec_info;
-    else if (IS_IRONLAKE(i965->intel.device_id))
-        i965->codec_info = &ironlake_hw_codec_info;
-    else if (IS_GEN6(i965->intel.device_id))
-        i965->codec_info = &gen6_hw_codec_info;
-    else if (IS_GEN7(i965->intel.device_id))
-        i965->codec_info = &gen7_hw_codec_info;
-    else
+    i965->codec_info = i965_get_codec_info(i965->intel.device_id);
+
+    if (!i965->codec_info)
         return false;
 
     if (object_heap_init(&i965->config_heap,
@@ -4963,6 +5132,7 @@ i965_Init(VADriverContextP ctx)
 {
     struct i965_driver_data *i965 = i965_driver_data(ctx); 
     int i;
+    const char *chipset;
 
     for (i = 0; i < ARRAY_ELEMS(i965_sub_ops); i++) {
         if ((i965_sub_ops[i].display_type == 0 ||
@@ -4972,9 +5142,19 @@ i965_Init(VADriverContextP ctx)
     }
 
     if (i == ARRAY_ELEMS(i965_sub_ops)) {
-        sprintf(i965->va_vendor, "%s %s driver - %d.%d.%d",
+        switch (i965->intel.device_id) {
+#undef CHIPSET
+#define CHIPSET(id, family, dev, str) case id: chipset = str; break;
+#include "i965_pciids.h"
+        default:
+            chipset = "Unknown Intel Chipset";
+            break;
+        }
+
+        sprintf(i965->va_vendor, "%s %s driver for %s - %d.%d.%d",
                 INTEL_STR_DRIVER_VENDOR,
                 INTEL_STR_DRIVER_NAME,
+                chipset,
                 INTEL_DRIVER_MAJOR_VERSION,
                 INTEL_DRIVER_MINOR_VERSION,
                 INTEL_DRIVER_MICRO_VERSION);
@@ -5045,7 +5225,6 @@ VA_DRIVER_INIT_FUNC(  VADriverContextP ctx )
     vtable->vaTerminate = i965_Terminate;
     vtable->vaQueryConfigEntrypoints = i965_QueryConfigEntrypoints;
     vtable->vaQueryConfigProfiles = i965_QueryConfigProfiles;
-    vtable->vaQueryConfigEntrypoints = i965_QueryConfigEntrypoints;
     vtable->vaQueryConfigAttributes = i965_QueryConfigAttributes;
     vtable->vaCreateConfig = i965_CreateConfig;
     vtable->vaDestroyConfig = i965_DestroyConfig;