mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-06 10:58:48 +09:00
drm/virtio: implement context init: track valid capabilities in a mask
The valid capability IDs are between 1 to 63, and defined in the virtio gpu spec. This is used for error checking the subsequent patches. We're currently only using 2 capability IDs, so this should be plenty for the immediate future. Signed-off-by: Gurchetan Singh <gurchetansingh@chromium.org> Acked-by: Lingfeng Yang <lfy@google.com> Link: http://patchwork.freedesktop.org/patch/msgid/20210921232024.817-4-gurchetansingh@chromium.org Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
committed by
Gerd Hoffmann
parent
b10790434c
commit
1925d6a7e0
@@ -55,6 +55,8 @@
|
|||||||
#define STATE_OK 1
|
#define STATE_OK 1
|
||||||
#define STATE_ERR 2
|
#define STATE_ERR 2
|
||||||
|
|
||||||
|
#define MAX_CAPSET_ID 63
|
||||||
|
|
||||||
struct virtio_gpu_object_params {
|
struct virtio_gpu_object_params {
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
bool dumb;
|
bool dumb;
|
||||||
@@ -245,6 +247,7 @@ struct virtio_gpu_device {
|
|||||||
|
|
||||||
struct virtio_gpu_drv_capset *capsets;
|
struct virtio_gpu_drv_capset *capsets;
|
||||||
uint32_t num_capsets;
|
uint32_t num_capsets;
|
||||||
|
uint64_t capset_id_mask;
|
||||||
struct list_head cap_cache;
|
struct list_head cap_cache;
|
||||||
|
|
||||||
/* protects uuid state when exporting */
|
/* protects uuid state when exporting */
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ static void virtio_gpu_get_capsets(struct virtio_gpu_device *vgdev,
|
|||||||
int num_capsets)
|
int num_capsets)
|
||||||
{
|
{
|
||||||
int i, ret;
|
int i, ret;
|
||||||
|
bool invalid_capset_id = false;
|
||||||
|
|
||||||
vgdev->capsets = kcalloc(num_capsets,
|
vgdev->capsets = kcalloc(num_capsets,
|
||||||
sizeof(struct virtio_gpu_drv_capset),
|
sizeof(struct virtio_gpu_drv_capset),
|
||||||
@@ -78,19 +79,34 @@ static void virtio_gpu_get_capsets(struct virtio_gpu_device *vgdev,
|
|||||||
virtio_gpu_notify(vgdev);
|
virtio_gpu_notify(vgdev);
|
||||||
ret = wait_event_timeout(vgdev->resp_wq,
|
ret = wait_event_timeout(vgdev->resp_wq,
|
||||||
vgdev->capsets[i].id > 0, 5 * HZ);
|
vgdev->capsets[i].id > 0, 5 * HZ);
|
||||||
if (ret == 0) {
|
/*
|
||||||
|
* Capability ids are defined in the virtio-gpu spec and are
|
||||||
|
* between 1 to 63, inclusive.
|
||||||
|
*/
|
||||||
|
if (!vgdev->capsets[i].id ||
|
||||||
|
vgdev->capsets[i].id > MAX_CAPSET_ID)
|
||||||
|
invalid_capset_id = true;
|
||||||
|
|
||||||
|
if (ret == 0)
|
||||||
DRM_ERROR("timed out waiting for cap set %d\n", i);
|
DRM_ERROR("timed out waiting for cap set %d\n", i);
|
||||||
|
else if (invalid_capset_id)
|
||||||
|
DRM_ERROR("invalid capset id %u", vgdev->capsets[i].id);
|
||||||
|
|
||||||
|
if (ret == 0 || invalid_capset_id) {
|
||||||
spin_lock(&vgdev->display_info_lock);
|
spin_lock(&vgdev->display_info_lock);
|
||||||
kfree(vgdev->capsets);
|
kfree(vgdev->capsets);
|
||||||
vgdev->capsets = NULL;
|
vgdev->capsets = NULL;
|
||||||
spin_unlock(&vgdev->display_info_lock);
|
spin_unlock(&vgdev->display_info_lock);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vgdev->capset_id_mask |= 1 << vgdev->capsets[i].id;
|
||||||
DRM_INFO("cap set %d: id %d, max-version %d, max-size %d\n",
|
DRM_INFO("cap set %d: id %d, max-version %d, max-size %d\n",
|
||||||
i, vgdev->capsets[i].id,
|
i, vgdev->capsets[i].id,
|
||||||
vgdev->capsets[i].max_version,
|
vgdev->capsets[i].max_version,
|
||||||
vgdev->capsets[i].max_size);
|
vgdev->capsets[i].max_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
vgdev->num_capsets = num_capsets;
|
vgdev->num_capsets = num_capsets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user