Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/vmwgfx: Switch to mode_cmd2

Surprisingly few changes needed to make it happen. Compile-tested
only. The idea is that this replaces the 2 patches from Ville's big
fb->format patch series as a prep patch. Only impact to later patches
should be the one instace added in this patch where we look at
fb->pixel_format (instead of fb->bpp and fb->depth), so minor
adjustements in the cocci-generated patches needed.

v2: Restore pitch computation in vmw_fb_kms_framebuffer (Sinclair).

Cc: ville.syrjala@linux.intel.com
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: linux-graphics-maintainer@vmware.com
Cc: Sinclair Yeh <syeh@vmware.com>
Cc: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Sinclair Yeh <syeh@vmware.com>
Acked-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20161202070740.31689-1-daniel.vetter@ffwll.ch

+53 -84
+10 -9
drivers/gpu/drm/vmwgfx/vmwgfx_fb.c
··· 465 465 466 466 static int vmw_fb_kms_framebuffer(struct fb_info *info) 467 467 { 468 - struct drm_mode_fb_cmd mode_cmd; 468 + struct drm_mode_fb_cmd2 mode_cmd; 469 469 struct vmw_fb_par *par = info->par; 470 470 struct fb_var_screeninfo *var = &info->var; 471 471 struct drm_framebuffer *cur_fb; 472 472 struct vmw_framebuffer *vfb; 473 - int ret = 0; 473 + int ret = 0, depth; 474 474 size_t new_bo_size; 475 475 476 - ret = vmw_fb_compute_depth(var, &mode_cmd.depth); 476 + ret = vmw_fb_compute_depth(var, &depth); 477 477 if (ret) 478 478 return ret; 479 479 480 480 mode_cmd.width = var->xres; 481 481 mode_cmd.height = var->yres; 482 - mode_cmd.bpp = var->bits_per_pixel; 483 - mode_cmd.pitch = ((mode_cmd.bpp + 7) / 8) * mode_cmd.width; 482 + mode_cmd.pitches[0] = ((var->bits_per_pixel + 7) / 8) * mode_cmd.width; 483 + mode_cmd.pixel_format = 484 + drm_mode_legacy_fb_format(var->bits_per_pixel, 485 + ((var->bits_per_pixel + 7) / 8) * mode_cmd.width); 484 486 485 487 cur_fb = par->set_fb; 486 488 if (cur_fb && cur_fb->width == mode_cmd.width && 487 489 cur_fb->height == mode_cmd.height && 488 - cur_fb->bits_per_pixel == mode_cmd.bpp && 489 - cur_fb->depth == mode_cmd.depth && 490 - cur_fb->pitches[0] == mode_cmd.pitch) 490 + cur_fb->pixel_format == mode_cmd.pixel_format && 491 + cur_fb->pitches[0] == mode_cmd.pitches[0]) 491 492 return 0; 492 493 493 494 /* Need new buffer object ? */ 494 - new_bo_size = (size_t) mode_cmd.pitch * (size_t) mode_cmd.height; 495 + new_bo_size = (size_t) mode_cmd.pitches[0] * (size_t) mode_cmd.height; 495 496 ret = vmw_fb_kms_detach(par, 496 497 par->bo_size < new_bo_size || 497 498 par->bo_size > 2*new_bo_size,
+42 -74
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
··· 516 516 static int vmw_kms_new_framebuffer_surface(struct vmw_private *dev_priv, 517 517 struct vmw_surface *surface, 518 518 struct vmw_framebuffer **out, 519 - const struct drm_mode_fb_cmd 519 + const struct drm_mode_fb_cmd2 520 520 *mode_cmd, 521 521 bool is_dmabuf_proxy) 522 522 ··· 525 525 struct vmw_framebuffer_surface *vfbs; 526 526 enum SVGA3dSurfaceFormat format; 527 527 int ret; 528 + struct drm_format_name_buf format_name; 528 529 529 530 /* 3D is only supported on HWv8 and newer hosts */ 530 531 if (dev_priv->active_display_unit == vmw_du_legacy) ··· 549 548 return -EINVAL; 550 549 } 551 550 552 - switch (mode_cmd->depth) { 553 - case 32: 551 + switch (mode_cmd->pixel_format) { 552 + case DRM_FORMAT_ARGB8888: 554 553 format = SVGA3D_A8R8G8B8; 555 554 break; 556 - case 24: 555 + case DRM_FORMAT_XRGB8888: 557 556 format = SVGA3D_X8R8G8B8; 558 557 break; 559 - case 16: 558 + case DRM_FORMAT_RGB565: 560 559 format = SVGA3D_R5G6B5; 561 560 break; 562 - case 15: 561 + case DRM_FORMAT_XRGB1555: 563 562 format = SVGA3D_A1R5G5B5; 564 563 break; 565 564 default: 566 - DRM_ERROR("Invalid color depth: %d\n", mode_cmd->depth); 565 + DRM_ERROR("Invalid pixel format: %s\n", 566 + drm_get_format_name(mode_cmd->pixel_format, &format_name)); 567 567 return -EINVAL; 568 568 } 569 569 ··· 583 581 goto out_err1; 584 582 } 585 583 586 - /* XXX get the first 3 from the surface info */ 587 - vfbs->base.base.bits_per_pixel = mode_cmd->bpp; 588 - vfbs->base.base.pitches[0] = mode_cmd->pitch; 589 - vfbs->base.base.depth = mode_cmd->depth; 590 - vfbs->base.base.width = mode_cmd->width; 591 - vfbs->base.base.height = mode_cmd->height; 584 + drm_helper_mode_fill_fb_struct(&vfbs->base.base, mode_cmd); 592 585 vfbs->surface = vmw_surface_reference(surface); 593 - vfbs->base.user_handle = mode_cmd->handle; 586 + vfbs->base.user_handle = mode_cmd->handles[0]; 594 587 vfbs->is_dmabuf_proxy = is_dmabuf_proxy; 595 588 596 589 *out = &vfbs->base; ··· 752 755 * 0 on success, error code otherwise 753 756 */ 754 757 static int vmw_create_dmabuf_proxy(struct drm_device *dev, 755 - const struct drm_mode_fb_cmd *mode_cmd, 758 + const struct drm_mode_fb_cmd2 *mode_cmd, 756 759 struct vmw_dma_buffer *dmabuf_mob, 757 760 struct vmw_surface **srf_out) 758 761 { ··· 760 763 struct drm_vmw_size content_base_size; 761 764 struct vmw_resource *res; 762 765 unsigned int bytes_pp; 766 + struct drm_format_name_buf format_name; 763 767 int ret; 764 768 765 - switch (mode_cmd->depth) { 766 - case 32: 767 - case 24: 769 + switch (mode_cmd->pixel_format) { 770 + case DRM_FORMAT_ARGB8888: 771 + case DRM_FORMAT_XRGB8888: 768 772 format = SVGA3D_X8R8G8B8; 769 773 bytes_pp = 4; 770 774 break; 771 775 772 - case 16: 773 - case 15: 776 + case DRM_FORMAT_RGB565: 777 + case DRM_FORMAT_XRGB1555: 774 778 format = SVGA3D_R5G6B5; 775 779 bytes_pp = 2; 776 780 break; ··· 782 784 break; 783 785 784 786 default: 785 - DRM_ERROR("Invalid framebuffer format %d\n", mode_cmd->depth); 787 + DRM_ERROR("Invalid framebuffer format %s\n", 788 + drm_get_format_name(mode_cmd->pixel_format, &format_name)); 786 789 return -EINVAL; 787 790 } 788 791 789 - content_base_size.width = mode_cmd->pitch / bytes_pp; 792 + content_base_size.width = mode_cmd->pitches[0] / bytes_pp; 790 793 content_base_size.height = mode_cmd->height; 791 794 content_base_size.depth = 1; 792 795 ··· 825 826 static int vmw_kms_new_framebuffer_dmabuf(struct vmw_private *dev_priv, 826 827 struct vmw_dma_buffer *dmabuf, 827 828 struct vmw_framebuffer **out, 828 - const struct drm_mode_fb_cmd 829 + const struct drm_mode_fb_cmd2 829 830 *mode_cmd) 830 831 831 832 { 832 833 struct drm_device *dev = dev_priv->dev; 833 834 struct vmw_framebuffer_dmabuf *vfbd; 834 835 unsigned int requested_size; 836 + struct drm_format_name_buf format_name; 835 837 int ret; 836 838 837 - requested_size = mode_cmd->height * mode_cmd->pitch; 839 + requested_size = mode_cmd->height * mode_cmd->pitches[0]; 838 840 if (unlikely(requested_size > dmabuf->base.num_pages * PAGE_SIZE)) { 839 841 DRM_ERROR("Screen buffer object size is too small " 840 842 "for requested mode.\n"); ··· 844 844 845 845 /* Limited framebuffer color depth support for screen objects */ 846 846 if (dev_priv->active_display_unit == vmw_du_screen_object) { 847 - switch (mode_cmd->depth) { 848 - case 32: 849 - case 24: 850 - /* Only support 32 bpp for 32 and 24 depth fbs */ 851 - if (mode_cmd->bpp == 32) 852 - break; 853 - 854 - DRM_ERROR("Invalid color depth/bbp: %d %d\n", 855 - mode_cmd->depth, mode_cmd->bpp); 856 - return -EINVAL; 857 - case 16: 858 - case 15: 859 - /* Only support 16 bpp for 16 and 15 depth fbs */ 860 - if (mode_cmd->bpp == 16) 861 - break; 862 - 863 - DRM_ERROR("Invalid color depth/bbp: %d %d\n", 864 - mode_cmd->depth, mode_cmd->bpp); 865 - return -EINVAL; 847 + switch (mode_cmd->pixel_format) { 848 + case DRM_FORMAT_XRGB8888: 849 + case DRM_FORMAT_ARGB8888: 850 + break; 851 + case DRM_FORMAT_XRGB1555: 852 + case DRM_FORMAT_RGB565: 853 + break; 866 854 default: 867 - DRM_ERROR("Invalid color depth: %d\n", mode_cmd->depth); 855 + DRM_ERROR("Invalid pixel format: %s\n", 856 + drm_get_format_name(mode_cmd->pixel_format, &format_name)); 868 857 return -EINVAL; 869 858 } 870 859 } ··· 864 875 goto out_err1; 865 876 } 866 877 867 - vfbd->base.base.bits_per_pixel = mode_cmd->bpp; 868 - vfbd->base.base.pitches[0] = mode_cmd->pitch; 869 - vfbd->base.base.depth = mode_cmd->depth; 870 - vfbd->base.base.width = mode_cmd->width; 871 - vfbd->base.base.height = mode_cmd->height; 878 + drm_helper_mode_fill_fb_struct(&vfbd->base.base, mode_cmd); 872 879 vfbd->base.dmabuf = true; 873 880 vfbd->buffer = vmw_dmabuf_reference(dmabuf); 874 - vfbd->base.user_handle = mode_cmd->handle; 881 + vfbd->base.user_handle = mode_cmd->handles[0]; 875 882 *out = &vfbd->base; 876 883 877 884 ret = drm_framebuffer_init(dev, &vfbd->base.base, ··· 901 916 struct vmw_dma_buffer *dmabuf, 902 917 struct vmw_surface *surface, 903 918 bool only_2d, 904 - const struct drm_mode_fb_cmd *mode_cmd) 919 + const struct drm_mode_fb_cmd2 *mode_cmd) 905 920 { 906 921 struct vmw_framebuffer *vfb = NULL; 907 922 bool is_dmabuf_proxy = false; ··· 956 971 957 972 static struct drm_framebuffer *vmw_kms_fb_create(struct drm_device *dev, 958 973 struct drm_file *file_priv, 959 - const struct drm_mode_fb_cmd2 *mode_cmd2) 974 + const struct drm_mode_fb_cmd2 *mode_cmd) 960 975 { 961 976 struct vmw_private *dev_priv = vmw_priv(dev); 962 977 struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile; ··· 964 979 struct vmw_surface *surface = NULL; 965 980 struct vmw_dma_buffer *bo = NULL; 966 981 struct ttm_base_object *user_obj; 967 - struct drm_mode_fb_cmd mode_cmd; 968 - const struct drm_format_info *info; 969 982 int ret; 970 - 971 - info = drm_format_info(mode_cmd2->pixel_format); 972 - if (!info || !info->depth) { 973 - struct drm_format_name_buf format_name; 974 - DRM_ERROR("Unsupported framebuffer format %s\n", 975 - drm_get_format_name(mode_cmd2->pixel_format, &format_name)); 976 - return ERR_PTR(-EINVAL); 977 - } 978 - 979 - mode_cmd.width = mode_cmd2->width; 980 - mode_cmd.height = mode_cmd2->height; 981 - mode_cmd.pitch = mode_cmd2->pitches[0]; 982 - mode_cmd.handle = mode_cmd2->handles[0]; 983 - mode_cmd.depth = info->depth; 984 - mode_cmd.bpp = info->cpp[0] * 8; 985 983 986 984 /** 987 985 * This code should be conditioned on Screen Objects not being used. ··· 973 1005 */ 974 1006 975 1007 if (!vmw_kms_validate_mode_vram(dev_priv, 976 - mode_cmd.pitch, 977 - mode_cmd.height)) { 1008 + mode_cmd->pitches[0], 1009 + mode_cmd->height)) { 978 1010 DRM_ERROR("Requested mode exceed bounding box limit.\n"); 979 1011 return ERR_PTR(-ENOMEM); 980 1012 } ··· 988 1020 * command stream using user-space handles. 989 1021 */ 990 1022 991 - user_obj = ttm_base_object_lookup(tfile, mode_cmd.handle); 1023 + user_obj = ttm_base_object_lookup(tfile, mode_cmd->handles[0]); 992 1024 if (unlikely(user_obj == NULL)) { 993 1025 DRM_ERROR("Could not locate requested kms frame buffer.\n"); 994 1026 return ERR_PTR(-ENOENT); ··· 1000 1032 1001 1033 /* returns either a dmabuf or surface */ 1002 1034 ret = vmw_user_lookup_handle(dev_priv, tfile, 1003 - mode_cmd.handle, 1035 + mode_cmd->handles[0], 1004 1036 &surface, &bo); 1005 1037 if (ret) 1006 1038 goto err_out; 1007 1039 1008 1040 vfb = vmw_kms_new_framebuffer(dev_priv, bo, surface, 1009 1041 !(dev_priv->capabilities & SVGA_CAP_3D), 1010 - &mode_cmd); 1042 + mode_cmd); 1011 1043 if (IS_ERR(vfb)) { 1012 1044 ret = PTR_ERR(vfb); 1013 1045 goto err_out;
+1 -1
drivers/gpu/drm/vmwgfx/vmwgfx_kms.h
··· 248 248 struct vmw_dma_buffer *dmabuf, 249 249 struct vmw_surface *surface, 250 250 bool only_2d, 251 - const struct drm_mode_fb_cmd *mode_cmd); 251 + const struct drm_mode_fb_cmd2 *mode_cmd); 252 252 int vmw_kms_fbdev_init_data(struct vmw_private *dev_priv, 253 253 unsigned unit, 254 254 u32 max_width,