From bfd6a184a16233a10d68e5d0889ffa6b8d999318 Mon Sep 17 00:00:00 2001 From: "Xue, Bosheng" Date: Wed, 21 Aug 2024 23:03:13 +0800 Subject: [PATCH] drm/i915: debug and log Tracked-On: OAM-121827 Signed-off-by: Xue, Bosheng --- drivers/gpu/drm/i915/pxp/intel_pxp_types.h | 24 ++--- drivers/gpu/drm/i915/pxp/virt/intel_pxp_fe.c | 28 +++--- drivers/gpu/drm/i915/pxp/virt/virtio_pxp.c | 100 +++++++++---------- drivers/gpu/drm/i915/pxp/virt/virtpxp_drv.h | 16 +-- 4 files changed, 84 insertions(+), 84 deletions(-) diff --git a/drivers/gpu/drm/i915/pxp/intel_pxp_types.h b/drivers/gpu/drm/i915/pxp/intel_pxp_types.h index 5c2074b460d7..784bc43195d4 100644 --- a/drivers/gpu/drm/i915/pxp/intel_pxp_types.h +++ b/drivers/gpu/drm/i915/pxp/intel_pxp_types.h @@ -44,18 +44,18 @@ struct intel_pxp_session { }; struct intel_pxp_fe { - struct drm_i915_private *i915; - bool enabled; - bool active; - struct mutex session_mutex; - int device_idx; - int device_vfid; - int max_sessions; - int avail_sessions; - struct virtio_pxp *vpxp; - spinlock_t irq_lock; - struct intel_pxp_session hwdrm_sessions[INTEL_PXP_MAX_HWDRM_SESSIONS]; - u32 key_instance; + struct drm_i915_private *i915; + bool enabled; + bool active; + struct mutex session_mutex; + int device_idx; + int device_vfid; + int max_sessions; + int avail_sessions; + struct virtio_pxp *vpxp; + spinlock_t irq_lock; + struct intel_pxp_session hwdrm_sessions[INTEL_PXP_MAX_HWDRM_SESSIONS]; + u32 key_instance; struct work_struct session_work; u32 session_events; }; diff --git a/drivers/gpu/drm/i915/pxp/virt/intel_pxp_fe.c b/drivers/gpu/drm/i915/pxp/virt/intel_pxp_fe.c index 60b9ef2b4a48..4f0f8dfa8b3b 100644 --- a/drivers/gpu/drm/i915/pxp/virt/intel_pxp_fe.c +++ b/drivers/gpu/drm/i915/pxp/virt/intel_pxp_fe.c @@ -74,7 +74,7 @@ static void event_cb(int event, void *priv) unsigned long flags; if (!pxp) return; - DRM_DEBUG("PXP FE: event receive: %d\n", event); + printk("PXP FE: event receive: %d\n", event); spin_lock_irqsave(&pxp->fe.irq_lock, flags); pxp->session_events |= event; spin_unlock_irqrestore(&pxp->fe.irq_lock, flags); @@ -88,7 +88,7 @@ void intel_pxp_fe_terminate(struct intel_pxp *pxp) mutex_lock(&pxp->fe.session_mutex); for(int index = 0; index < INTEL_PXP_MAX_HWDRM_SESSIONS; index++) { if (pxp->fe.hwdrm_sessions[index].index > 0) { - DRM_DEBUG("%s, PXP FE: session terminate:%d\n",__FUNCTION__, index); + printk("%s, PXP FE: session terminate:%d\n",__FUNCTION__, index); intel_pxp_fe_sm_ioctl_terminate_session(pxp, pxp->fe.hwdrm_sessions[index].drmfile, index); } } @@ -116,7 +116,7 @@ static void pxp_fe_session_work(struct work_struct *work) if (!events) return; - DRM_DEBUG("PXP FE: processing event-flags 0x%08x", events); + printk("PXP FE: processing event-flags 0x%08x", events); if (events & PXP_INVAL_REQUIRED) { intel_pxp_invalidate(pxp_fe->i915->pxp); @@ -172,7 +172,7 @@ int intel_pxp_fe_init(struct drm_i915_private *i915) INIT_WORK(&i915->pxp->fe.session_work, pxp_fe_session_work); vpxp = get_virtio_pxp(device_idx, device_vfid, event_cb, i915->pxp); if (vpxp) { - DRM_INFO("PXP FE: succeed to bind virtio device\n"); + DRM_INFO("PXP FE: succeed to bind virtio device, vpxp:%p\n", vpxp); i915->pxp->fe.vpxp = vpxp; i915->pxp->fe.enabled = true; i915->pxp->fe.max_sessions = vpxp->sessions; @@ -180,7 +180,7 @@ int intel_pxp_fe_init(struct drm_i915_private *i915) } mutex_init(&i915->pxp->fe.session_mutex); spin_lock_init(&i915->pxp->fe.irq_lock); - DRM_INFO("PXP FE: protected content support initialized\n"); + DRM_INFO("PXP FE: protected content support initialized\n"); return 0; } @@ -231,7 +231,7 @@ int intel_pxp_fe_start(struct intel_pxp *pxp) return 0; if (intel_pxp_is_active(pxp)) return 0; - DRM_DEBUG("%s\n",__FUNCTION__); + printk("%s\n",__FUNCTION__); pxp_key_instance_update(pxp); pxp->fe.active = true; @@ -245,7 +245,7 @@ void intel_pxp_fe_end(struct intel_pxp *pxp) return; if (!intel_pxp_is_active(pxp)) return ; - DRM_DEBUG("%s\n",__FUNCTION__); + printk("%s\n",__FUNCTION__); flush_work(&pxp->fe.session_work); pxp->fe.active = false; } @@ -295,7 +295,7 @@ int intel_pxp_fe_sm_ioctl_reserve_session(struct intel_pxp *pxp, struct drm_file ret = virtio_set_session(pxp->fe.vpxp, ¶ms); *pxp_tag = params.pxp_tag; session_id = *pxp_tag & PRELIM_DRM_I915_PXP_TAG_SESSION_ID_MASK; - DRM_DEBUG("%s, session_id:%d, ret:%d\n",__FUNCTION__, session_id, ret); + printk("%s, session_id:%d, ret:%d\n",__FUNCTION__, session_id, ret); if (session_id >= INTEL_PXP_MAX_HWDRM_SESSIONS || session_id <= 0) { DRM_ERROR("PXP FE: invalid session id:%d", session_id); return -1; @@ -324,7 +324,7 @@ int intel_pxp_fe_sm_ioctl_mark_session_in_play(struct intel_pxp *pxp, params.pxp_tag = session_id; params.req_session_state = PRELIM_DRM_I915_PXP_REQ_SESSION_IN_PLAY; ret = virtio_set_session(pxp->fe.vpxp, ¶ms); - DRM_DEBUG("%s, session_id:%d, ret:%d\n",__FUNCTION__, session_id, ret); + printk("%s, session_id:%d, ret:%d\n",__FUNCTION__, session_id, ret); if (ret < 0) return ret; pxp->fe.hwdrm_sessions[session_id].is_valid = true; @@ -348,7 +348,7 @@ int intel_pxp_fe_sm_ioctl_terminate_session(struct intel_pxp *pxp, params.pxp_tag = session_id; params.req_session_state = PRELIM_DRM_I915_PXP_REQ_SESSION_TERMINATE; ret = virtio_set_session(pxp->fe.vpxp, ¶ms); - DRM_DEBUG("%s, session_id:%d, ret:%d\n",__FUNCTION__, session_id, ret); + printk("%s, session_id:%d, ret:%d\n",__FUNCTION__, session_id, ret); return ret; } @@ -368,7 +368,7 @@ int intel_pxp_fe_io_message(struct intel_pxp *pxp, params.msg_out = (u64)msg_out; params.msg_out_buf_size = msg_out_max_size; ret = virtio_io_msg(pxp->fe.vpxp, ¶ms); - DRM_DEBUG("%s, ret:%d, ret size:%d\n",__FUNCTION__, ret, params.msg_out_ret_size); + printk("%s, ret:%d, ret size:%d\n",__FUNCTION__, ret, params.msg_out_ret_size); *msg_out_rcv_size = params.msg_out_ret_size; return ret; } @@ -390,7 +390,7 @@ int intel_pxp_fe_sm_ioctl_query_pxp_tag(struct intel_pxp *pxp, ret = virtio_query_tag(pxp->fe.vpxp, ¶ms); *pxp_tag = params.pxp_tag; *session_is_alive = params.session_is_alive; - DRM_DEBUG("%s, ret:%d\n",__FUNCTION__, ret); + printk("%s, ret:%d\n",__FUNCTION__, ret); return ret; } @@ -459,7 +459,7 @@ static bool ioctl_buffer_size_valid(u32 size) return size > 0 && size <= SZ_64K; } - static int +static int intel_pxp_fe_ioctl_io_message(struct intel_pxp *pxp, struct drm_file *drmfile, struct prelim_drm_i915_pxp_tee_io_message_params *params) { @@ -665,7 +665,7 @@ void intel_pxp_fe_close(struct intel_pxp *pxp, struct drm_file *drmfile) mutex_lock(&pxp->fe.session_mutex); for(index = 0; index < INTEL_PXP_MAX_HWDRM_SESSIONS; index++) { if (pxp->fe.hwdrm_sessions[index].index > 0 && (pxp->fe.hwdrm_sessions[index].drmfile == drmfile)) { - DRM_DEBUG("%s, PXP FE: session terminate:%d\n",__FUNCTION__, index); + printk("%s, PXP FE: session terminate:%d\n",__FUNCTION__, index); intel_pxp_fe_sm_ioctl_terminate_session(pxp, pxp->fe.hwdrm_sessions[index].drmfile, index); } } diff --git a/drivers/gpu/drm/i915/pxp/virt/virtio_pxp.c b/drivers/gpu/drm/i915/pxp/virt/virtio_pxp.c index 8e17c18a382f..e26f105afd12 100644 --- a/drivers/gpu/drm/i915/pxp/virt/virtio_pxp.c +++ b/drivers/gpu/drm/i915/pxp/virt/virtio_pxp.c @@ -13,8 +13,6 @@ #include #include "virtpxp_drv.h" -#define MAX_PXP_NUM 64 -static int active_pxp_num = 0; static DEFINE_SPINLOCK(pxp_lock); static LIST_HEAD(pxp_devices); @@ -32,17 +30,17 @@ static void virtpxp_recv_events(struct virtqueue *vq) unsigned int *event; unsigned long flags; unsigned int len; + printk("bosheng virtpxp_recv_events\n"); spin_lock_irqsave(&vpxp->event_lock, flags); - if (vpxp->ready) { - while ((event = virtqueue_get_buf(vq, &len)) != NULL) { - spin_unlock_irqrestore(&vpxp->event_lock, flags); - vpxp->irq_recv(*event, vpxp->cb_priv); - virtpxp_queue_evtbuf(vpxp); - spin_lock_irqsave(&vpxp->event_lock, flags); - } - virtqueue_kick(vq); + while ((event = virtqueue_get_buf(vq, &len)) != NULL) { + spin_unlock_irqrestore(&vpxp->event_lock, flags); + printk("bosheng virtpxp_recv_events 1\n"); + vpxp->irq_recv(*event, vpxp->cb_priv); + virtpxp_queue_evtbuf(vpxp); + spin_lock_irqsave(&vpxp->event_lock, flags); } + virtqueue_kick(vq); spin_unlock_irqrestore(&vpxp->event_lock, flags); } @@ -53,14 +51,14 @@ static void virtpxp_control(struct virtqueue *vq) unsigned long flags; unsigned int len; + printk("bosheng virtpxp_control\n"); spin_lock_irqsave(&vpxp->control_lock, flags); - if (vpxp->ready) { - while ((request = virtqueue_get_buf(vq, &len)) != NULL) { - spin_unlock_irqrestore(&vpxp->control_lock, flags); - request->rxlen = len; - complete(&request->completion); - spin_lock_irqsave(&vpxp->control_lock, flags); - } + while ((request = virtqueue_get_buf(vq, &len)) != NULL) { + spin_unlock_irqrestore(&vpxp->control_lock, flags); + request->rxlen = len; + printk("bosheng virtpxp_control completion\n"); + complete(&request->completion); + spin_lock_irqsave(&vpxp->control_lock, flags); } spin_unlock_irqrestore(&vpxp->control_lock, flags); } @@ -105,6 +103,7 @@ EXPORT_SYMBOL(get_virtio_pxp); static void vpxp_free(struct kref *kref) { struct virtio_pxp *vpxp; + printk("bosheng vpxp_free\n"); vpxp = container_of(kref, typeof(*vpxp), ref); kfree(vpxp); vpxp = NULL; @@ -123,6 +122,7 @@ int virtio_set_session(struct virtio_pxp *vpxp, struct prelim_drm_i915_pxp_set_s struct virtio_pxp_set_session_request *request; struct scatterlist *sgs[2], req_sg, res_sg; int ret = 0; + printk("bosheng virtio_set_session\n"); if (!vpxp) return -1; request = kzalloc(sizeof(*request), GFP_KERNEL); @@ -140,28 +140,28 @@ int virtio_set_session(struct virtio_pxp *vpxp, struct prelim_drm_i915_pxp_set_s sg_init_one(&res_sg, &request->resp, sizeof(request->resp)); sgs[0] = &req_sg; sgs[1] = &res_sg; - down_read(&vpxp->lock); + mutex_lock(&vpxp->dev_mutex); if (!vpxp->ready) { - up_read(&vpxp->lock); + mutex_unlock(&vpxp->dev_mutex); kfree(request); return -1; } + printk("bosheng virtio_set_session 1\n"); virtqueue_add_sgs(vpxp->control_vq, sgs, 1, 1, &request->base, GFP_KERNEL); if (ret) { printk("%s, failed to add request to vq:%d\n", __FUNCTION__, ret); - up_read(&vpxp->lock); + mutex_unlock(&vpxp->dev_mutex); kfree(request); return -1; } virtqueue_kick(vpxp->control_vq); + mutex_unlock(&vpxp->dev_mutex); ret = wait_for_completion_interruptible_timeout(&request->base.completion, msecs_to_jiffies(2000)); if (ret < 0) { printk("failed to set session status:%d, ret:%d\n", request->resp.status, ret); - up_read(&vpxp->lock); kfree(request); return -ETIME; } - up_read(&vpxp->lock); params->pxp_tag = request->resp.pxp_tag; ret = request->resp.status; kfree(request); @@ -174,6 +174,7 @@ int virtio_io_msg(struct virtio_pxp *vpxp, struct prelim_drm_i915_pxp_tee_io_mes struct virtio_pxp_io_message_request *request; struct scatterlist *sgs[4], req_sg, req_data_sg, res_data_sg, res_sg; int ret = 0; + printk("bosheng virtio_io_msg, vpxp:%p\n", vpxp); if (!vpxp) return -1; request = kzalloc(sizeof(*request), GFP_KERNEL); @@ -193,28 +194,28 @@ int virtio_io_msg(struct virtio_pxp *vpxp, struct prelim_drm_i915_pxp_tee_io_mes sgs[1] = &req_data_sg; sgs[2] = &res_data_sg; sgs[3] = &res_sg; - down_read(&vpxp->lock); + mutex_lock(&vpxp->dev_mutex); if (!vpxp->ready) { - up_read(&vpxp->lock); + mutex_unlock(&vpxp->dev_mutex); kfree(request); return -1; } + printk("bosheng virtio_io_msg 1\n"); virtqueue_add_sgs(vpxp->control_vq, sgs, 2, 2, &request->base, GFP_KERNEL); if (ret) { printk("%s, failed to add request to vq:%d\n", __FUNCTION__, ret); - up_read(&vpxp->lock); + mutex_unlock(&vpxp->dev_mutex); kfree(request); return -1; } virtqueue_kick(vpxp->control_vq); + mutex_unlock(&vpxp->dev_mutex); ret = wait_for_completion_interruptible_timeout(&request->base.completion, msecs_to_jiffies(2000)); if (ret < 0) { printk("failed to io message status:%d, ret:%d\n", request->resp.status, ret); - up_read(&vpxp->lock); kfree(request); return -ETIME; } - up_read(&vpxp->lock); params->msg_out_ret_size = request->resp.msg_out_ret_size; ret = request->resp.status; kfree(request); @@ -227,6 +228,7 @@ int virtio_query_tag(struct virtio_pxp *vpxp, struct prelim_drm_i915_pxp_query_t struct virtio_pxp_query_tag_request *request ; struct scatterlist *sgs[2], req_sg, res_sg; int ret = 0; + printk("bosheng virtio_query_tag\n"); if (!vpxp) return -1; request = kzalloc(sizeof(*request), GFP_KERNEL); @@ -242,28 +244,28 @@ int virtio_query_tag(struct virtio_pxp *vpxp, struct prelim_drm_i915_pxp_query_t sg_init_one(&res_sg, &request->resp, sizeof(request->resp)); sgs[0] = &req_sg; sgs[1] = &res_sg; - down_read(&vpxp->lock); + mutex_lock(&vpxp->dev_mutex); if (!vpxp->ready) { - up_read(&vpxp->lock); + mutex_unlock(&vpxp->dev_mutex); kfree(request); return -1; } + printk("bosheng virtio_query_tag 1\n"); virtqueue_add_sgs(vpxp->control_vq, sgs, 1, 1, &request->base, GFP_KERNEL); if (ret) { printk("%s, failed to add request to vq:%d\n", __FUNCTION__, ret); - up_read(&vpxp->lock); + mutex_unlock(&vpxp->dev_mutex); kfree(request); return -1; } virtqueue_kick(vpxp->control_vq); + mutex_unlock(&vpxp->dev_mutex); ret = wait_for_completion_interruptible_timeout(&request->base.completion, msecs_to_jiffies(2000)); if (ret < 0) { printk("failed to query tag status:%d, ret:%d\n", request->resp.status, ret); - up_read(&vpxp->lock); kfree(request); return -ETIME; } - up_read(&vpxp->lock); params->pxp_tag = request->resp.pxp_tag; params->session_is_alive = request->resp.session_is_alive; ret = request->resp.status; @@ -277,6 +279,7 @@ int virtio_host_session_handle_request(struct virtio_pxp *vpxp, struct prelim_dr struct virtio_pxp_host_session_handle_request_request *request; struct scatterlist *sgs[2], req_sg, res_sg; int ret = 0; + printk("bosheng virtio_host_session_handle_request\n"); if (!vpxp) return -1; request = kzalloc(sizeof(*request), GFP_KERNEL); @@ -292,28 +295,28 @@ int virtio_host_session_handle_request(struct virtio_pxp *vpxp, struct prelim_dr sg_init_one(&res_sg, &request->resp, sizeof(request->resp)); sgs[0] = &req_sg; sgs[1] = &res_sg; - down_read(&vpxp->lock); + mutex_lock(&vpxp->dev_mutex); if (!vpxp->ready) { - up_read(&vpxp->lock); + mutex_unlock(&vpxp->dev_mutex); kfree(request); return -1; } + printk("bosheng virtio_host_session_handle_request 1\n"); virtqueue_add_sgs(vpxp->control_vq, sgs, 1, 1, &request->base, GFP_KERNEL); if (ret) { printk("%s, failed to add request to vq:%d\n", __FUNCTION__, ret); - up_read(&vpxp->lock); + mutex_unlock(&vpxp->dev_mutex); kfree(request); return -1; } virtqueue_kick(vpxp->control_vq); + mutex_unlock(&vpxp->dev_mutex); ret = wait_for_completion_interruptible_timeout(&request->base.completion, msecs_to_jiffies(2000)); if ( ret < 0) { printk("failed to host session handle status:%d, ret:%d\n", request->resp.status, ret); - up_read(&vpxp->lock); kfree(request); return -ETIME; } - up_read(&vpxp->lock); params->host_session_handle = request->resp.host_session_handle; ret = request->resp.status; kfree(request); @@ -340,7 +343,7 @@ static int virtpxp_probe(struct virtio_device *vdev) spin_lock_init(&vpxp->event_lock); kref_init(&vpxp->ref); INIT_LIST_HEAD(&vpxp->node); - init_rwsem(&vpxp->lock); + mutex_init(&vpxp->dev_mutex); err = virtpxp_init_vqs(vpxp); if (err) goto err_init_vq; @@ -354,20 +357,19 @@ static int virtpxp_probe(struct virtio_device *vdev) virtio_cread_le(vdev, struct virtio_pxp_config, sessions, &sessions); vpxp->sessions = sessions; - printk("virtio_pxp: device idx:%d, vfid:%d, sessions:%d\n", device_idx, device_vfid, sessions); virtio_device_ready(vdev); virtpxp_queue_evtbuf(vpxp); - down_write(&vpxp->lock); + mutex_lock(&vpxp->dev_mutex); vpxp->ready = true; - up_write(&vpxp->lock); + mutex_unlock(&vpxp->dev_mutex); spin_lock_irqsave(&pxp_lock, flags); list_add_tail(&vpxp->node, &pxp_devices); - active_pxp_num++; spin_unlock_irqrestore(&pxp_lock, flags); + printk("virtio_pxp:vpxp:%p device idx:%d, vfid:%d, sessions:%d\n",vpxp, device_idx, device_vfid, sessions); return 0; @@ -383,9 +385,9 @@ static void virtpxp_remove(struct virtio_device *vdev) if (!vpxp) return; printk("%s\n", __FUNCTION__); - down_write(&vpxp->lock); + mutex_lock(&vpxp->dev_mutex); vpxp->ready = false; - up_write(&vpxp->lock); + mutex_unlock(&vpxp->dev_mutex); //vdev->config->reset(vdev); virtio_reset_device(vdev); @@ -393,7 +395,6 @@ static void virtpxp_remove(struct virtio_device *vdev) vdev->config->del_vqs(vdev); spin_lock_irqsave(&pxp_lock, flags); list_del(&vpxp->node); - active_pxp_num--; spin_unlock_irqrestore(&pxp_lock, flags); put_virtio_pxp(vpxp); } @@ -405,9 +406,9 @@ static int virtpxp_freeze(struct virtio_device *vdev) if (!vpxp) return 0; printk("%s\n", __FUNCTION__); - down_write(&vpxp->lock); + mutex_lock(&vpxp->dev_mutex); vpxp->ready = false; - up_write(&vpxp->lock); + mutex_unlock(&vpxp->dev_mutex); //vdev->config->reset(vdev); virtio_reset_device(vdev); @@ -426,12 +427,11 @@ static int virtpxp_restore(struct virtio_device *vdev) err = virtpxp_init_vqs(vpxp); if (err) return err; - virtio_device_ready(vdev); virtpxp_queue_evtbuf(vpxp); - down_write(&vpxp->lock); + mutex_lock(&vpxp->dev_mutex); vpxp->ready = true; - up_write(&vpxp->lock); + mutex_unlock(&vpxp->dev_mutex); return 0; } #endif diff --git a/drivers/gpu/drm/i915/pxp/virt/virtpxp_drv.h b/drivers/gpu/drm/i915/pxp/virt/virtpxp_drv.h index c1ad2b27aff0..449361d85dec 100644 --- a/drivers/gpu/drm/i915/pxp/virt/virtpxp_drv.h +++ b/drivers/gpu/drm/i915/pxp/virt/virtpxp_drv.h @@ -47,13 +47,13 @@ struct virtio_pxp_host_session_handle_request_request { }; struct virtio_pxp { - struct virtio_device *vdev; - struct kref ref; - bool ready; - spinlock_t control_lock; - spinlock_t event_lock; - struct virtqueue *control_vq; - struct virtqueue *event_vq; + struct virtio_device *vdev; + struct kref ref; + bool ready; + spinlock_t control_lock; + spinlock_t event_lock; + struct virtqueue *control_vq; + struct virtqueue *event_vq; int device_idx; int device_vfid; int sessions; @@ -61,7 +61,7 @@ struct virtio_pxp { void *cb_priv; unsigned int evtbuf; struct list_head node; - struct rw_semaphore lock; + struct mutex dev_mutex; }; struct virtio_pxp *get_virtio_pxp(int device_idx, int device_vfid, void (*cb)(int event, void *priv), void *cb_priv);