[PATCH v2 04/17] drm/vmwgfx: Use enum to represent graphics context capabilities

2020-03-23 Thread Roland Scheidegger (VMware)
From: Deepak Rawat 

Instead of having different bool in device private to represent
incremental graphics context capabilities, add a new sm type enum.

v2: Use enum instead of bit flag.

v3: Incorporated review comments.

Signed-off-by: Deepak Rawat 
Reviewed-by: Thomas Hellström (VMware) 
Reviewed-by: Roland Scheidegger 
Signed-off-by: Roland Scheidegger 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_context.c |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 34 ++---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 40 +++--
 drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c |  6 ++--
 drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c   |  4 +--
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_mob.c |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 10 +++
 8 files changed, 69 insertions(+), 31 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_context.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_context.c
index a56c9d802382..0477d9a74fe8 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_context.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_context.c
@@ -731,7 +731,7 @@ static int vmw_context_define(struct drm_device *dev, void 
*data,
};
int ret;
 
-   if (!dev_priv->has_dx && dx) {
+   if (!has_sm4_context(dev_priv) && dx) {
VMW_DEBUG_USER("DX contexts not supported by device.\n");
return -EINVAL;
}
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index f976dabe18de..5277b9832d58 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -449,7 +449,7 @@ static int vmw_request_device(struct vmw_private *dev_priv)
dev_priv->cman = vmw_cmdbuf_man_create(dev_priv);
if (IS_ERR(dev_priv->cman)) {
dev_priv->cman = NULL;
-   dev_priv->has_dx = false;
+   dev_priv->sm_type = VMW_SM_LEGACY;
}
 
ret = vmw_request_device_late(dev_priv);
@@ -886,11 +886,22 @@ static int vmw_driver_load(struct drm_device *dev, 
unsigned long chipset)
if (dev_priv->has_mob && (dev_priv->capabilities & SVGA_CAP_DX)) {
spin_lock(_priv->cap_lock);
vmw_write(dev_priv, SVGA_REG_DEV_CAP, SVGA3D_DEVCAP_DXCONTEXT);
-   dev_priv->has_dx = !!vmw_read(dev_priv, SVGA_REG_DEV_CAP);
+   if (vmw_read(dev_priv, SVGA_REG_DEV_CAP))
+   dev_priv->sm_type = VMW_SM_4;
spin_unlock(_priv->cap_lock);
}
 
vmw_validation_mem_init_ttm(dev_priv, VMWGFX_VALIDATION_MEM_GRAN);
+
+   /* SVGA_CAP2_DX2 (DefineGBSurface_v3) is needed for SM4_1 support */
+   if (has_sm4_context(dev_priv) &&
+   (dev_priv->capabilities2 & SVGA_CAP2_DX2)) {
+   vmw_write(dev_priv, SVGA_REG_DEV_CAP, SVGA3D_DEVCAP_SM41);
+
+   if (vmw_read(dev_priv, SVGA_REG_DEV_CAP))
+   dev_priv->sm_type = VMW_SM_4_1;
+   }
+
ret = vmw_kms_init(dev_priv);
if (unlikely(ret != 0))
goto out_no_kms;
@@ -900,23 +911,12 @@ static int vmw_driver_load(struct drm_device *dev, 
unsigned long chipset)
if (ret)
goto out_no_fifo;
 
-   if (dev_priv->has_dx) {
-   /*
-* SVGA_CAP2_DX2 (DefineGBSurface_v3) is needed for SM4_1
-* support
-*/
-   if ((dev_priv->capabilities2 & SVGA_CAP2_DX2) != 0) {
-   vmw_write(dev_priv, SVGA_REG_DEV_CAP,
-   SVGA3D_DEVCAP_SM41);
-   dev_priv->has_sm4_1 = vmw_read(dev_priv,
-   SVGA_REG_DEV_CAP);
-   }
-   }
-
-   DRM_INFO("DX: %s\n", dev_priv->has_dx ? "yes." : "no.");
DRM_INFO("Atomic: %s\n", (dev->driver->driver_features & DRIVER_ATOMIC)
 ? "yes." : "no.");
-   DRM_INFO("SM4_1: %s\n", dev_priv->has_sm4_1 ? "yes." : "no.");
+   if (dev_priv->sm_type == VMW_SM_4_1)
+   DRM_INFO("SM4_1 support available.\n");
+   if (dev_priv->sm_type == VMW_SM_4)
+   DRM_INFO("SM4 support available.\n");
 
snprintf(host_log, sizeof(host_log), "vmwgfx: %s-%s",
VMWGFX_REPO, VMWGFX_GIT_VERSION);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h 
b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index b70d73225707..243731813887 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -441,6 +441,20 @@ enum {
VMW_IRQTHREAD_MAX
 };
 
+/**
+ * enum vmw_sm_type - Graphics context capability supported by device.
+ * @VMW_SM_LEGACY: Pre DX context.
+ * @VMW_SM_4: Context support upto SM4.
+ * @VMW_SM_4_1: Context support upto SM4_1.
+ * @VMW_SM_MAX: Should be the last.
+ */
+enum vmw_sm_type {
+   VMW_SM_LEGACY = 0,
+   VMW_SM_4,
+   VMW_SM_4_1,
+   VMW_SM_MAX
+};
+
 struct vmw_private {
struct 

[PATCH v2 04/17] drm/vmwgfx: Use enum to represent graphics context capabilities

2020-03-23 Thread Roland Scheidegger
From: Deepak Rawat 

Instead of having different bool in device private to represent
incremental graphics context capabilities, add a new sm type enum.

v2: Use enum instead of bit flag.

v3: Incorporated review comments.

Signed-off-by: Deepak Rawat 
Reviewed-by: Thomas Hellström (VMware) 
Reviewed-by: Roland Scheidegger 
Signed-off-by: Roland Scheidegger 
---
 drivers/gpu/drm/vmwgfx/vmwgfx_context.c |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 34 ++---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 40 +++--
 drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c |  6 ++--
 drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c   |  4 +--
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_mob.c |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 10 +++
 8 files changed, 69 insertions(+), 31 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_context.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_context.c
index a56c9d802382..0477d9a74fe8 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_context.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_context.c
@@ -731,7 +731,7 @@ static int vmw_context_define(struct drm_device *dev, void 
*data,
};
int ret;
 
-   if (!dev_priv->has_dx && dx) {
+   if (!has_sm4_context(dev_priv) && dx) {
VMW_DEBUG_USER("DX contexts not supported by device.\n");
return -EINVAL;
}
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index f976dabe18de..5277b9832d58 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -449,7 +449,7 @@ static int vmw_request_device(struct vmw_private *dev_priv)
dev_priv->cman = vmw_cmdbuf_man_create(dev_priv);
if (IS_ERR(dev_priv->cman)) {
dev_priv->cman = NULL;
-   dev_priv->has_dx = false;
+   dev_priv->sm_type = VMW_SM_LEGACY;
}
 
ret = vmw_request_device_late(dev_priv);
@@ -886,11 +886,22 @@ static int vmw_driver_load(struct drm_device *dev, 
unsigned long chipset)
if (dev_priv->has_mob && (dev_priv->capabilities & SVGA_CAP_DX)) {
spin_lock(_priv->cap_lock);
vmw_write(dev_priv, SVGA_REG_DEV_CAP, SVGA3D_DEVCAP_DXCONTEXT);
-   dev_priv->has_dx = !!vmw_read(dev_priv, SVGA_REG_DEV_CAP);
+   if (vmw_read(dev_priv, SVGA_REG_DEV_CAP))
+   dev_priv->sm_type = VMW_SM_4;
spin_unlock(_priv->cap_lock);
}
 
vmw_validation_mem_init_ttm(dev_priv, VMWGFX_VALIDATION_MEM_GRAN);
+
+   /* SVGA_CAP2_DX2 (DefineGBSurface_v3) is needed for SM4_1 support */
+   if (has_sm4_context(dev_priv) &&
+   (dev_priv->capabilities2 & SVGA_CAP2_DX2)) {
+   vmw_write(dev_priv, SVGA_REG_DEV_CAP, SVGA3D_DEVCAP_SM41);
+
+   if (vmw_read(dev_priv, SVGA_REG_DEV_CAP))
+   dev_priv->sm_type = VMW_SM_4_1;
+   }
+
ret = vmw_kms_init(dev_priv);
if (unlikely(ret != 0))
goto out_no_kms;
@@ -900,23 +911,12 @@ static int vmw_driver_load(struct drm_device *dev, 
unsigned long chipset)
if (ret)
goto out_no_fifo;
 
-   if (dev_priv->has_dx) {
-   /*
-* SVGA_CAP2_DX2 (DefineGBSurface_v3) is needed for SM4_1
-* support
-*/
-   if ((dev_priv->capabilities2 & SVGA_CAP2_DX2) != 0) {
-   vmw_write(dev_priv, SVGA_REG_DEV_CAP,
-   SVGA3D_DEVCAP_SM41);
-   dev_priv->has_sm4_1 = vmw_read(dev_priv,
-   SVGA_REG_DEV_CAP);
-   }
-   }
-
-   DRM_INFO("DX: %s\n", dev_priv->has_dx ? "yes." : "no.");
DRM_INFO("Atomic: %s\n", (dev->driver->driver_features & DRIVER_ATOMIC)
 ? "yes." : "no.");
-   DRM_INFO("SM4_1: %s\n", dev_priv->has_sm4_1 ? "yes." : "no.");
+   if (dev_priv->sm_type == VMW_SM_4_1)
+   DRM_INFO("SM4_1 support available.\n");
+   if (dev_priv->sm_type == VMW_SM_4)
+   DRM_INFO("SM4 support available.\n");
 
snprintf(host_log, sizeof(host_log), "vmwgfx: %s-%s",
VMWGFX_REPO, VMWGFX_GIT_VERSION);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h 
b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index b70d73225707..243731813887 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -441,6 +441,20 @@ enum {
VMW_IRQTHREAD_MAX
 };
 
+/**
+ * enum vmw_sm_type - Graphics context capability supported by device.
+ * @VMW_SM_LEGACY: Pre DX context.
+ * @VMW_SM_4: Context support upto SM4.
+ * @VMW_SM_4_1: Context support upto SM4_1.
+ * @VMW_SM_MAX: Should be the last.
+ */
+enum vmw_sm_type {
+   VMW_SM_LEGACY = 0,
+   VMW_SM_4,
+   VMW_SM_4_1,
+   VMW_SM_MAX
+};
+
 struct vmw_private {
struct