Skip to content

Commit 878c6ec

Browse files
deepak-rawatRoland Scheidegger
authored andcommitted
drm/vmwgfx: Use enum to represent graphics context capabilities
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 <[email protected]> Reviewed-by: Thomas Hellström (VMware) <[email protected]> Reviewed-by: Roland Scheidegger <[email protected]> Signed-off-by: Roland Scheidegger <[email protected]>
1 parent 3d14395 commit 878c6ec

File tree

8 files changed

+69
-31
lines changed

8 files changed

+69
-31
lines changed

drivers/gpu/drm/vmwgfx/vmwgfx_context.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ static int vmw_context_define(struct drm_device *dev, void *data,
731731
};
732732
int ret;
733733

734-
if (!dev_priv->has_dx && dx) {
734+
if (!has_sm4_context(dev_priv) && dx) {
735735
VMW_DEBUG_USER("DX contexts not supported by device.\n");
736736
return -EINVAL;
737737
}

drivers/gpu/drm/vmwgfx/vmwgfx_drv.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ static int vmw_request_device(struct vmw_private *dev_priv)
449449
dev_priv->cman = vmw_cmdbuf_man_create(dev_priv);
450450
if (IS_ERR(dev_priv->cman)) {
451451
dev_priv->cman = NULL;
452-
dev_priv->has_dx = false;
452+
dev_priv->sm_type = VMW_SM_LEGACY;
453453
}
454454

455455
ret = vmw_request_device_late(dev_priv);
@@ -886,11 +886,22 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
886886
if (dev_priv->has_mob && (dev_priv->capabilities & SVGA_CAP_DX)) {
887887
spin_lock(&dev_priv->cap_lock);
888888
vmw_write(dev_priv, SVGA_REG_DEV_CAP, SVGA3D_DEVCAP_DXCONTEXT);
889-
dev_priv->has_dx = !!vmw_read(dev_priv, SVGA_REG_DEV_CAP);
889+
if (vmw_read(dev_priv, SVGA_REG_DEV_CAP))
890+
dev_priv->sm_type = VMW_SM_4;
890891
spin_unlock(&dev_priv->cap_lock);
891892
}
892893

893894
vmw_validation_mem_init_ttm(dev_priv, VMWGFX_VALIDATION_MEM_GRAN);
895+
896+
/* SVGA_CAP2_DX2 (DefineGBSurface_v3) is needed for SM4_1 support */
897+
if (has_sm4_context(dev_priv) &&
898+
(dev_priv->capabilities2 & SVGA_CAP2_DX2)) {
899+
vmw_write(dev_priv, SVGA_REG_DEV_CAP, SVGA3D_DEVCAP_SM41);
900+
901+
if (vmw_read(dev_priv, SVGA_REG_DEV_CAP))
902+
dev_priv->sm_type = VMW_SM_4_1;
903+
}
904+
894905
ret = vmw_kms_init(dev_priv);
895906
if (unlikely(ret != 0))
896907
goto out_no_kms;
@@ -900,23 +911,12 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
900911
if (ret)
901912
goto out_no_fifo;
902913

903-
if (dev_priv->has_dx) {
904-
/*
905-
* SVGA_CAP2_DX2 (DefineGBSurface_v3) is needed for SM4_1
906-
* support
907-
*/
908-
if ((dev_priv->capabilities2 & SVGA_CAP2_DX2) != 0) {
909-
vmw_write(dev_priv, SVGA_REG_DEV_CAP,
910-
SVGA3D_DEVCAP_SM41);
911-
dev_priv->has_sm4_1 = vmw_read(dev_priv,
912-
SVGA_REG_DEV_CAP);
913-
}
914-
}
915-
916-
DRM_INFO("DX: %s\n", dev_priv->has_dx ? "yes." : "no.");
917914
DRM_INFO("Atomic: %s\n", (dev->driver->driver_features & DRIVER_ATOMIC)
918915
? "yes." : "no.");
919-
DRM_INFO("SM4_1: %s\n", dev_priv->has_sm4_1 ? "yes." : "no.");
916+
if (dev_priv->sm_type == VMW_SM_4_1)
917+
DRM_INFO("SM4_1 support available.\n");
918+
if (dev_priv->sm_type == VMW_SM_4)
919+
DRM_INFO("SM4 support available.\n");
920920

921921
snprintf(host_log, sizeof(host_log), "vmwgfx: %s-%s",
922922
VMWGFX_REPO, VMWGFX_GIT_VERSION);

drivers/gpu/drm/vmwgfx/vmwgfx_drv.h

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,20 @@ enum {
441441
VMW_IRQTHREAD_MAX
442442
};
443443

444+
/**
445+
* enum vmw_sm_type - Graphics context capability supported by device.
446+
* @VMW_SM_LEGACY: Pre DX context.
447+
* @VMW_SM_4: Context support upto SM4.
448+
* @VMW_SM_4_1: Context support upto SM4_1.
449+
* @VMW_SM_MAX: Should be the last.
450+
*/
451+
enum vmw_sm_type {
452+
VMW_SM_LEGACY = 0,
453+
VMW_SM_4,
454+
VMW_SM_4_1,
455+
VMW_SM_MAX
456+
};
457+
444458
struct vmw_private {
445459
struct ttm_bo_device bdev;
446460

@@ -475,9 +489,9 @@ struct vmw_private {
475489
bool has_mob;
476490
spinlock_t hw_lock;
477491
spinlock_t cap_lock;
478-
bool has_dx;
479492
bool assume_16bpp;
480-
bool has_sm4_1;
493+
494+
enum vmw_sm_type sm_type;
481495

482496
/*
483497
* Framebuffer info.
@@ -648,6 +662,28 @@ static inline uint32_t vmw_read(struct vmw_private *dev_priv,
648662
return val;
649663
}
650664

665+
/**
666+
* has_sm4_context - Does the device support SM4 context.
667+
* @dev_priv: Device private.
668+
*
669+
* Return: Bool value if device support SM4 context or not.
670+
*/
671+
static inline bool has_sm4_context(const struct vmw_private *dev_priv)
672+
{
673+
return (dev_priv->sm_type >= VMW_SM_4);
674+
}
675+
676+
/**
677+
* has_sm4_1_context - Does the device support SM4_1 context.
678+
* @dev_priv: Device private.
679+
*
680+
* Return: Bool value if device support SM4_1 context or not.
681+
*/
682+
static inline bool has_sm4_1_context(const struct vmw_private *dev_priv)
683+
{
684+
return (dev_priv->sm_type >= VMW_SM_4_1);
685+
}
686+
651687
extern void vmw_svga_enable(struct vmw_private *dev_priv);
652688
extern void vmw_svga_disable(struct vmw_private *dev_priv);
653689

drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,8 @@ static int vmw_resource_context_res_add(struct vmw_private *dev_priv,
461461
u32 i;
462462

463463
/* Add all cotables to the validation list. */
464-
if (dev_priv->has_dx && vmw_res_type(ctx) == vmw_res_dx_context) {
464+
if (has_sm4_context(dev_priv) &&
465+
vmw_res_type(ctx) == vmw_res_dx_context) {
465466
for (i = 0; i < SVGA_COTABLE_DX10_MAX; ++i) {
466467
res = vmw_context_cotable(ctx, i);
467468
if (IS_ERR(res))
@@ -489,7 +490,8 @@ static int vmw_resource_context_res_add(struct vmw_private *dev_priv,
489490
break;
490491
}
491492

492-
if (dev_priv->has_dx && vmw_res_type(ctx) == vmw_res_dx_context) {
493+
if (has_sm4_context(dev_priv) &&
494+
vmw_res_type(ctx) == vmw_res_dx_context) {
493495
struct vmw_buffer_object *dx_query_mob;
494496

495497
dx_query_mob = vmw_context_get_dx_query_mob(ctx);

drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ int vmw_getparam_ioctl(struct drm_device *dev, void *data,
114114
(dev_priv->active_display_unit == vmw_du_screen_target);
115115
break;
116116
case DRM_VMW_PARAM_DX:
117-
param->value = dev_priv->has_dx;
117+
param->value = has_sm4_context(dev_priv);
118118
break;
119119
case DRM_VMW_PARAM_SM4_1:
120-
param->value = dev_priv->has_sm4_1;
120+
param->value = has_sm4_1_context(dev_priv);
121121
break;
122122
default:
123123
return -EINVAL;

drivers/gpu/drm/vmwgfx/vmwgfx_kms.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ static int vmw_kms_new_framebuffer_surface(struct vmw_private *dev_priv,
941941
* For DX, surface format validation is done when surface->scanout
942942
* is set.
943943
*/
944-
if (!dev_priv->has_dx && format != surface->format) {
944+
if (!has_sm4_context(dev_priv) && format != surface->format) {
945945
DRM_ERROR("Invalid surface format for requested mode.\n");
946946
return -EINVAL;
947947
}

drivers/gpu/drm/vmwgfx/vmwgfx_mob.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ int vmw_otables_setup(struct vmw_private *dev_priv)
320320
struct vmw_otable **otables = &dev_priv->otable_batch.otables;
321321
int ret;
322322

323-
if (dev_priv->has_dx) {
323+
if (has_sm4_context(dev_priv)) {
324324
*otables = kmemdup(dx_tables, sizeof(dx_tables), GFP_KERNEL);
325325
if (!(*otables))
326326
return -ENOMEM;

drivers/gpu/drm/vmwgfx/vmwgfx_surface.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,12 +1092,12 @@ static int vmw_gb_surface_create(struct vmw_resource *res)
10921092
goto out_no_fifo;
10931093
}
10941094

1095-
if (dev_priv->has_sm4_1 && srf->array_size > 0) {
1095+
if (has_sm4_1_context(dev_priv) && srf->array_size > 0) {
10961096
cmd_id = SVGA_3D_CMD_DEFINE_GB_SURFACE_V3;
10971097
cmd_len = sizeof(cmd3->body);
10981098
submit_len = sizeof(*cmd3);
10991099
} else if (srf->array_size > 0) {
1100-
/* has_dx checked on creation time. */
1100+
/* VMW_SM_4 support verified at creation time. */
11011101
cmd_id = SVGA_3D_CMD_DEFINE_GB_SURFACE_V2;
11021102
cmd_len = sizeof(cmd2->body);
11031103
submit_len = sizeof(*cmd2);
@@ -1115,7 +1115,7 @@ static int vmw_gb_surface_create(struct vmw_resource *res)
11151115
goto out_no_fifo;
11161116
}
11171117

1118-
if (dev_priv->has_sm4_1 && srf->array_size > 0) {
1118+
if (has_sm4_1_context(dev_priv) && srf->array_size > 0) {
11191119
cmd3->header.id = cmd_id;
11201120
cmd3->header.size = cmd_len;
11211121
cmd3->body.sid = srf->res.id;
@@ -1443,7 +1443,7 @@ int vmw_surface_gb_priv_define(struct drm_device *dev,
14431443
}
14441444

14451445
/* array_size must be null for non-GL3 host. */
1446-
if (array_size > 0 && !dev_priv->has_dx) {
1446+
if (array_size > 0 && !has_sm4_context(dev_priv)) {
14471447
VMW_DEBUG_USER("Tried to create DX surface on non-DX host.\n");
14481448
return -EINVAL;
14491449
}
@@ -1601,7 +1601,7 @@ vmw_gb_surface_define_internal(struct drm_device *dev,
16011601
SVGA3D_FLAGS_64(req->svga3d_flags_upper_32_bits,
16021602
req->base.svga3d_flags);
16031603

1604-
if (!dev_priv->has_sm4_1) {
1604+
if (!has_sm4_1_context(dev_priv)) {
16051605
/*
16061606
* If SM4_1 is not support then cannot send 64-bit flag to
16071607
* device.

0 commit comments

Comments
 (0)