Skip to content

Commit 61ff410

Browse files
committed
Merge branch 'vmwgfx-next' of git://people.freedesktop.org/~thomash/linux into drm-next
vmwgfx updates + new logging uapi https://patchwork.freedesktop.org/patch/349809/ is appropriate userpsace patch. Signed-off-by: Dave Airlie <[email protected]> From: =?UTF-8?q?Thomas=20Hellstr=C3=B6m=20=28VMware=29?= Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
2 parents d7ca2d1 + b204142 commit 61ff410

File tree

8 files changed

+200
-34
lines changed

8 files changed

+200
-34
lines changed

drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf_res.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,10 @@ int vmw_cmdbuf_res_add(struct vmw_cmdbuf_res_manager *man,
209209

210210
cres->hash.key = user_key | (res_type << 24);
211211
ret = drm_ht_insert_item(&man->resources, &cres->hash);
212-
if (unlikely(ret != 0))
212+
if (unlikely(ret != 0)) {
213+
kfree(cres);
213214
goto out_invalid_key;
215+
}
214216

215217
cres->state = VMW_CMDBUF_RES_ADD;
216218
cres->res = vmw_resource_reference(res);

drivers/gpu/drm/vmwgfx/vmwgfx_drv.c

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
#include <linux/console.h>
2929
#include <linux/dma-mapping.h>
3030
#include <linux/module.h>
31+
#include <linux/pci.h>
3132

3233
#include <drm/drm_drv.h>
3334
#include <drm/drm_ioctl.h>
34-
#include <drm/drm_pci.h>
3535
#include <drm/drm_sysfs.h>
3636
#include <drm/ttm/ttm_bo_driver.h>
3737
#include <drm/ttm/ttm_module.h>
@@ -150,6 +150,9 @@
150150
#define DRM_IOCTL_VMW_GB_SURFACE_REF_EXT \
151151
DRM_IOWR(DRM_COMMAND_BASE + DRM_VMW_GB_SURFACE_REF_EXT, \
152152
union drm_vmw_gb_surface_reference_ext_arg)
153+
#define DRM_IOCTL_VMW_MSG \
154+
DRM_IOWR(DRM_COMMAND_BASE + DRM_VMW_MSG, \
155+
struct drm_vmw_msg_arg)
153156

154157
/**
155158
* The core DRM version of this macro doesn't account for
@@ -165,9 +168,9 @@
165168

166169
static const struct drm_ioctl_desc vmw_ioctls[] = {
167170
VMW_IOCTL_DEF(VMW_GET_PARAM, vmw_getparam_ioctl,
168-
DRM_AUTH | DRM_RENDER_ALLOW),
171+
DRM_RENDER_ALLOW),
169172
VMW_IOCTL_DEF(VMW_ALLOC_DMABUF, vmw_bo_alloc_ioctl,
170-
DRM_AUTH | DRM_RENDER_ALLOW),
173+
DRM_RENDER_ALLOW),
171174
VMW_IOCTL_DEF(VMW_UNREF_DMABUF, vmw_bo_unref_ioctl,
172175
DRM_RENDER_ALLOW),
173176
VMW_IOCTL_DEF(VMW_CURSOR_BYPASS,
@@ -182,16 +185,16 @@ static const struct drm_ioctl_desc vmw_ioctls[] = {
182185
DRM_MASTER),
183186

184187
VMW_IOCTL_DEF(VMW_CREATE_CONTEXT, vmw_context_define_ioctl,
185-
DRM_AUTH | DRM_RENDER_ALLOW),
188+
DRM_RENDER_ALLOW),
186189
VMW_IOCTL_DEF(VMW_UNREF_CONTEXT, vmw_context_destroy_ioctl,
187190
DRM_RENDER_ALLOW),
188191
VMW_IOCTL_DEF(VMW_CREATE_SURFACE, vmw_surface_define_ioctl,
189-
DRM_AUTH | DRM_RENDER_ALLOW),
192+
DRM_RENDER_ALLOW),
190193
VMW_IOCTL_DEF(VMW_UNREF_SURFACE, vmw_surface_destroy_ioctl,
191194
DRM_RENDER_ALLOW),
192195
VMW_IOCTL_DEF(VMW_REF_SURFACE, vmw_surface_reference_ioctl,
193-
DRM_AUTH | DRM_RENDER_ALLOW),
194-
VMW_IOCTL_DEF(VMW_EXECBUF, vmw_execbuf_ioctl, DRM_AUTH |
196+
DRM_RENDER_ALLOW),
197+
VMW_IOCTL_DEF(VMW_EXECBUF, vmw_execbuf_ioctl,
195198
DRM_RENDER_ALLOW),
196199
VMW_IOCTL_DEF(VMW_FENCE_WAIT, vmw_fence_obj_wait_ioctl,
197200
DRM_RENDER_ALLOW),
@@ -201,9 +204,9 @@ static const struct drm_ioctl_desc vmw_ioctls[] = {
201204
VMW_IOCTL_DEF(VMW_FENCE_UNREF, vmw_fence_obj_unref_ioctl,
202205
DRM_RENDER_ALLOW),
203206
VMW_IOCTL_DEF(VMW_FENCE_EVENT, vmw_fence_event_ioctl,
204-
DRM_AUTH | DRM_RENDER_ALLOW),
207+
DRM_RENDER_ALLOW),
205208
VMW_IOCTL_DEF(VMW_GET_3D_CAP, vmw_get_cap_3d_ioctl,
206-
DRM_AUTH | DRM_RENDER_ALLOW),
209+
DRM_RENDER_ALLOW),
207210

208211
/* these allow direct access to the framebuffers mark as master only */
209212
VMW_IOCTL_DEF(VMW_PRESENT, vmw_present_ioctl,
@@ -221,28 +224,31 @@ static const struct drm_ioctl_desc vmw_ioctls[] = {
221224
DRM_RENDER_ALLOW),
222225
VMW_IOCTL_DEF(VMW_CREATE_SHADER,
223226
vmw_shader_define_ioctl,
224-
DRM_AUTH | DRM_RENDER_ALLOW),
227+
DRM_RENDER_ALLOW),
225228
VMW_IOCTL_DEF(VMW_UNREF_SHADER,
226229
vmw_shader_destroy_ioctl,
227230
DRM_RENDER_ALLOW),
228231
VMW_IOCTL_DEF(VMW_GB_SURFACE_CREATE,
229232
vmw_gb_surface_define_ioctl,
230-
DRM_AUTH | DRM_RENDER_ALLOW),
233+
DRM_RENDER_ALLOW),
231234
VMW_IOCTL_DEF(VMW_GB_SURFACE_REF,
232235
vmw_gb_surface_reference_ioctl,
233-
DRM_AUTH | DRM_RENDER_ALLOW),
236+
DRM_RENDER_ALLOW),
234237
VMW_IOCTL_DEF(VMW_SYNCCPU,
235238
vmw_user_bo_synccpu_ioctl,
236239
DRM_RENDER_ALLOW),
237240
VMW_IOCTL_DEF(VMW_CREATE_EXTENDED_CONTEXT,
238241
vmw_extended_context_define_ioctl,
239-
DRM_AUTH | DRM_RENDER_ALLOW),
242+
DRM_RENDER_ALLOW),
240243
VMW_IOCTL_DEF(VMW_GB_SURFACE_CREATE_EXT,
241244
vmw_gb_surface_define_ext_ioctl,
242-
DRM_AUTH | DRM_RENDER_ALLOW),
245+
DRM_RENDER_ALLOW),
243246
VMW_IOCTL_DEF(VMW_GB_SURFACE_REF_EXT,
244247
vmw_gb_surface_reference_ext_ioctl,
245-
DRM_AUTH | DRM_RENDER_ALLOW),
248+
DRM_RENDER_ALLOW),
249+
VMW_IOCTL_DEF(VMW_MSG,
250+
vmw_msg_ioctl,
251+
DRM_RENDER_ALLOW),
246252
};
247253

248254
static const struct pci_device_id vmw_pci_id_list[] = {
@@ -1211,8 +1217,10 @@ static void vmw_remove(struct pci_dev *pdev)
12111217
{
12121218
struct drm_device *dev = pci_get_drvdata(pdev);
12131219

1220+
drm_dev_unregister(dev);
1221+
vmw_driver_unload(dev);
1222+
drm_dev_put(dev);
12141223
pci_disable_device(pdev);
1215-
drm_put_dev(dev);
12161224
}
12171225

12181226
static int vmwgfx_pm_notifier(struct notifier_block *nb, unsigned long val,
@@ -1391,8 +1399,6 @@ static const struct file_operations vmwgfx_driver_fops = {
13911399
static struct drm_driver driver = {
13921400
.driver_features =
13931401
DRIVER_MODESET | DRIVER_RENDER | DRIVER_ATOMIC,
1394-
.load = vmw_driver_load,
1395-
.unload = vmw_driver_unload,
13961402
.get_vblank_counter = vmw_get_vblank_counter,
13971403
.enable_vblank = vmw_enable_vblank,
13981404
.disable_vblank = vmw_disable_vblank,
@@ -1431,7 +1437,39 @@ static struct pci_driver vmw_pci_driver = {
14311437

14321438
static int vmw_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
14331439
{
1434-
return drm_get_pci_dev(pdev, ent, &driver);
1440+
struct drm_device *dev;
1441+
int ret;
1442+
1443+
ret = pci_enable_device(pdev);
1444+
if (ret)
1445+
return ret;
1446+
1447+
dev = drm_dev_alloc(&driver, &pdev->dev);
1448+
if (IS_ERR(dev)) {
1449+
ret = PTR_ERR(dev);
1450+
goto err_pci_disable_device;
1451+
}
1452+
1453+
dev->pdev = pdev;
1454+
pci_set_drvdata(pdev, dev);
1455+
1456+
ret = vmw_driver_load(dev, ent->driver_data);
1457+
if (ret)
1458+
goto err_drm_dev_put;
1459+
1460+
ret = drm_dev_register(dev, ent->driver_data);
1461+
if (ret)
1462+
goto err_vmw_driver_unload;
1463+
1464+
return 0;
1465+
1466+
err_vmw_driver_unload:
1467+
vmw_driver_unload(dev);
1468+
err_drm_dev_put:
1469+
drm_dev_put(dev);
1470+
err_pci_disable_device:
1471+
pci_disable_device(pdev);
1472+
return ret;
14351473
}
14361474

14371475
static int __init vmwgfx_init(void)

drivers/gpu/drm/vmwgfx/vmwgfx_drv.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@
5656

5757

5858
#define VMWGFX_DRIVER_NAME "vmwgfx"
59-
#define VMWGFX_DRIVER_DATE "20190328"
59+
#define VMWGFX_DRIVER_DATE "20200114"
6060
#define VMWGFX_DRIVER_MAJOR 2
61-
#define VMWGFX_DRIVER_MINOR 16
61+
#define VMWGFX_DRIVER_MINOR 17
6262
#define VMWGFX_DRIVER_PATCHLEVEL 0
6363
#define VMWGFX_FIFO_STATIC_SIZE (1024*1024)
6464
#define VMWGFX_MAX_RELOCATIONS 2048
@@ -1403,6 +1403,8 @@ int vmw_bo_cpu_blit(struct ttm_buffer_object *dst,
14031403
int vmw_host_get_guestinfo(const char *guest_info_param,
14041404
char *buffer, size_t *length);
14051405
int vmw_host_log(const char *log);
1406+
int vmw_msg_ioctl(struct drm_device *dev, void *data,
1407+
struct drm_file *file_priv);
14061408

14071409
/* VMW logging */
14081410

drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2377,9 +2377,12 @@ static int vmw_cmd_dx_clear_rendertarget_view(struct vmw_private *dev_priv,
23772377
{
23782378
VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXClearRenderTargetView) =
23792379
container_of(header, typeof(*cmd), header);
2380+
struct vmw_resource *ret;
23802381

2381-
return PTR_RET(vmw_view_id_val_add(sw_context, vmw_view_rt,
2382-
cmd->body.renderTargetViewId));
2382+
ret = vmw_view_id_val_add(sw_context, vmw_view_rt,
2383+
cmd->body.renderTargetViewId);
2384+
2385+
return PTR_ERR_OR_ZERO(ret);
23832386
}
23842387

23852388
/**
@@ -2396,9 +2399,12 @@ static int vmw_cmd_dx_clear_depthstencil_view(struct vmw_private *dev_priv,
23962399
{
23972400
VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXClearDepthStencilView) =
23982401
container_of(header, typeof(*cmd), header);
2402+
struct vmw_resource *ret;
2403+
2404+
ret = vmw_view_id_val_add(sw_context, vmw_view_ds,
2405+
cmd->body.depthStencilViewId);
23992406

2400-
return PTR_RET(vmw_view_id_val_add(sw_context, vmw_view_ds,
2401-
cmd->body.depthStencilViewId));
2407+
return PTR_ERR_OR_ZERO(ret);
24022408
}
24032409

24042410
static int vmw_cmd_dx_view_define(struct vmw_private *dev_priv,
@@ -2741,9 +2747,12 @@ static int vmw_cmd_dx_genmips(struct vmw_private *dev_priv,
27412747
{
27422748
VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXGenMips) =
27432749
container_of(header, typeof(*cmd), header);
2750+
struct vmw_resource *ret;
2751+
2752+
ret = vmw_view_id_val_add(sw_context, vmw_view_sr,
2753+
cmd->body.shaderResourceViewId);
27442754

2745-
return PTR_RET(vmw_view_id_val_add(sw_context, vmw_view_sr,
2746-
cmd->body.shaderResourceViewId));
2755+
return PTR_ERR_OR_ZERO(ret);
27472756
}
27482757

27492758
/**

drivers/gpu/drm/vmwgfx/vmwgfx_msg.c

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <linux/kernel.h>
2929
#include <linux/module.h>
3030
#include <linux/slab.h>
31+
#include <linux/mem_encrypt.h>
3132

3233
#include <asm/hypervisor.h>
3334

@@ -56,6 +57,8 @@
5657

5758
#define HIGH_WORD(X) ((X & 0xFFFF0000) >> 16)
5859

60+
#define MAX_USER_MSG_LENGTH PAGE_SIZE
61+
5962
static u32 vmw_msg_enabled = 1;
6063

6164
enum rpc_msg_type {
@@ -148,7 +151,8 @@ static unsigned long vmw_port_hb_out(struct rpc_channel *channel,
148151
unsigned long si, di, eax, ebx, ecx, edx;
149152
unsigned long msg_len = strlen(msg);
150153

151-
if (hb) {
154+
/* HB port can't access encrypted memory. */
155+
if (hb && !mem_encrypt_active()) {
152156
unsigned long bp = channel->cookie_high;
153157

154158
si = (uintptr_t) msg;
@@ -202,7 +206,8 @@ static unsigned long vmw_port_hb_in(struct rpc_channel *channel, char *reply,
202206
{
203207
unsigned long si, di, eax, ebx, ecx, edx;
204208

205-
if (hb) {
209+
/* HB port can't access encrypted memory */
210+
if (hb && !mem_encrypt_active()) {
206211
unsigned long bp = channel->cookie_low;
207212

208213
si = channel->cookie_high;
@@ -514,3 +519,84 @@ int vmw_host_log(const char *log)
514519

515520
return -EINVAL;
516521
}
522+
523+
524+
/**
525+
* vmw_msg_ioctl: Sends and receveives a message to/from host from/to user-space
526+
*
527+
* Sends a message from user-space to host.
528+
* Can also receive a result from host and return that to user-space.
529+
*
530+
* @dev: Identifies the drm device.
531+
* @data: Pointer to the ioctl argument.
532+
* @file_priv: Identifies the caller.
533+
* Return: Zero on success, negative error code on error.
534+
*/
535+
536+
int vmw_msg_ioctl(struct drm_device *dev, void *data,
537+
struct drm_file *file_priv)
538+
{
539+
struct drm_vmw_msg_arg *arg =
540+
(struct drm_vmw_msg_arg *) data;
541+
struct rpc_channel channel;
542+
char *msg;
543+
int length;
544+
545+
msg = kmalloc(MAX_USER_MSG_LENGTH, GFP_KERNEL);
546+
if (!msg) {
547+
DRM_ERROR("Cannot allocate memory for log message.\n");
548+
return -ENOMEM;
549+
}
550+
551+
length = strncpy_from_user(msg, (void __user *)((unsigned long)arg->send),
552+
MAX_USER_MSG_LENGTH);
553+
if (length < 0 || length >= MAX_USER_MSG_LENGTH) {
554+
DRM_ERROR("Userspace message access failure.\n");
555+
kfree(msg);
556+
return -EINVAL;
557+
}
558+
559+
560+
if (vmw_open_channel(&channel, RPCI_PROTOCOL_NUM)) {
561+
DRM_ERROR("Failed to open channel.\n");
562+
goto out_open;
563+
}
564+
565+
if (vmw_send_msg(&channel, msg)) {
566+
DRM_ERROR("Failed to send message to host.\n");
567+
goto out_msg;
568+
}
569+
570+
if (!arg->send_only) {
571+
char *reply = NULL;
572+
size_t reply_len = 0;
573+
574+
if (vmw_recv_msg(&channel, (void *) &reply, &reply_len)) {
575+
DRM_ERROR("Failed to receive message from host.\n");
576+
goto out_msg;
577+
}
578+
if (reply && reply_len > 0) {
579+
if (copy_to_user((void __user *)((unsigned long)arg->receive),
580+
reply, reply_len)) {
581+
DRM_ERROR("Failed to copy message to userspace.\n");
582+
kfree(reply);
583+
goto out_msg;
584+
}
585+
arg->receive_len = (__u32)reply_len;
586+
}
587+
kfree(reply);
588+
}
589+
590+
vmw_close_channel(&channel);
591+
kfree(msg);
592+
593+
return 0;
594+
595+
out_msg:
596+
vmw_close_channel(&channel);
597+
out_open:
598+
kfree(msg);
599+
600+
return -EINVAL;
601+
}
602+

0 commit comments

Comments
 (0)