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