Commit 145cbefc authored by Chia-I Wu's avatar Chia-I Wu Committed by Gerd Hoffmann
Browse files

drm/virtio: add virtio_gpu_vbuf_ctrl_hdr



It is a helper to return the virtio_gpu_ctrl_hdr in a vbuf.

Signed-off-by: default avatarChia-I Wu <olvaffe@gmail.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20200205181955.202485-4-olvaffe@gmail.com


Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
parent 1425a4ce
Loading
Loading
Loading
Loading
+15 −5
Original line number Diff line number Diff line
@@ -95,7 +95,8 @@ virtio_gpu_get_vbuf(struct virtio_gpu_device *vgdev,
	if (!vbuf)
		return ERR_PTR(-ENOMEM);

	BUG_ON(size > MAX_INLINE_CMD_SIZE);
	BUG_ON(size > MAX_INLINE_CMD_SIZE ||
	       size < sizeof(struct virtio_gpu_ctrl_hdr));
	vbuf->buf = (void *)vbuf + sizeof(*vbuf);
	vbuf->size = size;

@@ -109,6 +110,16 @@ virtio_gpu_get_vbuf(struct virtio_gpu_device *vgdev,
	return vbuf;
}

static struct virtio_gpu_ctrl_hdr *
virtio_gpu_vbuf_ctrl_hdr(struct virtio_gpu_vbuffer *vbuf)
{
	/* this assumes a vbuf contains a command that starts with a
	 * virtio_gpu_ctrl_hdr, which is true for both ctrl and cursor
	 * virtqueues.
	 */
	return (struct virtio_gpu_ctrl_hdr *)vbuf->buf;
}

static void *virtio_gpu_alloc_cmd(struct virtio_gpu_device *vgdev,
				  struct virtio_gpu_vbuffer **vbuffer_p,
				  int size)
@@ -211,7 +222,7 @@ void virtio_gpu_dequeue_ctrl_func(struct work_struct *work)
		if (resp->type != cpu_to_le32(VIRTIO_GPU_RESP_OK_NODATA)) {
			if (resp->type >= cpu_to_le32(VIRTIO_GPU_RESP_ERR_UNSPEC)) {
				struct virtio_gpu_ctrl_hdr *cmd;
				cmd = (struct virtio_gpu_ctrl_hdr *)entry->buf;
				cmd = virtio_gpu_vbuf_ctrl_hdr(entry);
				DRM_ERROR_RATELIMITED("response 0x%x (command 0x%x)\n",
						      le32_to_cpu(resp->type),
						      le32_to_cpu(cmd->type));
@@ -338,8 +349,7 @@ static bool virtio_gpu_queue_ctrl_buffer_locked(struct virtio_gpu_device *vgdev,
	ret = virtqueue_add_sgs(vq, sgs, outcnt, incnt, vbuf, GFP_ATOMIC);
	WARN_ON(ret);

	trace_virtio_gpu_cmd_queue(vq,
		(struct virtio_gpu_ctrl_hdr *)vbuf->buf);
	trace_virtio_gpu_cmd_queue(vq, virtio_gpu_vbuf_ctrl_hdr(vbuf));

	notify = virtqueue_kick_prepare(vq);

@@ -458,7 +468,7 @@ retry:
		goto retry;
	} else {
		trace_virtio_gpu_cmd_queue(vq,
			(struct virtio_gpu_ctrl_hdr *)vbuf->buf);
			virtio_gpu_vbuf_ctrl_hdr(vbuf));

		notify = virtqueue_kick_prepare(vq);
	}