mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dikshita Agarwal <quic_dikshita@quicinc.com>
To: Konrad Dybcio <konrad.dybcio@linaro.org>,
	Vikash Garodia <quic_vgarodia@quicinc.com>,
	<stanimir.k.varbanov@gmail.com>, <agross@kernel.org>,
	<andersson@kernel.org>, <mchehab@kernel.org>,
	<hans.verkuil@cisco.com>, <linux-kernel@vger.kernel.org>,
	<linux-media@vger.kernel.org>, <linux-arm-msm@vger.kernel.org>
Subject: Re: [PATCH 02/33] iris: vidc: add core functions
Date: Tue, 15 Aug 2023 00:19:59 +0530	[thread overview]
Message-ID: <1c8f7cb2-9536-39f7-05ba-a568b3d3be5f@quicinc.com> (raw)
In-Reply-To: <c6a094bc-3032-cfe7-d24b-6e83f53e1771@linaro.org>



On 7/28/2023 7:15 PM, Konrad Dybcio wrote:
> On 28.07.2023 15:23, Vikash Garodia wrote:
>> From: Dikshita Agarwal <quic_dikshita@quicinc.com>
>>
>> This implements the platform driver methods, file
>> operations and v4l2 registration.
>>
>> Signed-off-by: Dikshita Agarwal <quic_dikshita@quicinc.com>
>> Signed-off-by: Vikash Garodia <quic_vgarodia@quicinc.com>
>> ---
> [...]
> 
>> +struct msm_vidc_core *g_core;
>> +
>> +static inline bool is_video_device(struct device *dev)
>> +{
>> +	return !!(of_device_is_compatible(dev->of_node, "qcom,sm8550-vidc"));
>> +}
> Are you expecting this to be expanded each time support for new SoC is added?
> 
I understand the concern here.
Will remove this API in next version.
>> +
>> +static inline bool is_video_context_bank_device(struct device *dev)
>> +{
>> +	return !!(of_device_is_compatible(dev->of_node, "qcom,vidc,cb-ns"));
>> +}
>> +
>> +static int msm_vidc_init_resources(struct msm_vidc_core *core)
>> +{
>> +	struct msm_vidc_resource *res = NULL;
> No need to initialize, you use it right after defining.
Agree, will remove.
> 
>> +	int rc = 0;
> I think 'ret' is more common for a return-value-holding variable.
> 
Agree, will replace 'rc' with 'ret' in all APIs in next version
>> +
>> +	res = devm_kzalloc(&core->pdev->dev, sizeof(*res), GFP_KERNEL);
>> +	if (!res) {
>> +		d_vpr_e("%s: failed to alloc memory for resource\n", __func__);
>> +		return -ENOMEM;
>> +	}
>> +	core->resource = res;
> I don't think the 'res' variable makes sense.
> 
Sure, Will update, res->resource
>> +
>> +	rc = call_res_op(core, init, core);
>> +	if (rc) {
>> +		d_vpr_e("%s: Failed to init resources: %d\n", __func__, rc);
>> +		return rc;
> you can omit this line and return rc/ret at the last line of this func.
> 
The abstraction layer for resource is not required so this API will be
changed in next version, will take care of return values as well.
>> +	}
>> +
>> +	return 0;
>> +}
>> +
>> +static const struct of_device_id msm_vidc_dt_match[] = {
>> +	{.compatible = "qcom,sm8550-vidc"},
> { .compatible = .... " },
> 
>> +	{.compatible = "qcom,vidc,cb-ns"},
>> +	MSM_VIDC_EMPTY_BRACE
> why?
> 
Right, it's not needed, Will replace with {}
>> +};
>> +MODULE_DEVICE_TABLE(of, msm_vidc_dt_match);
>> +
>> +static void msm_vidc_release_video_device(struct video_device *vdev)
>> +{
>> +	d_vpr_e("%s: video device released\n", __func__);
>> +}
> Doesn't sound too useful? And definitely not with an error print?
> 
The device structure is embedded in the core structure, so driver needs to
set the release() callback. hence this API is required.
This API doesn't free anything here because the core struture will be freed
when device is removed.
Will remove error print in next version.
>> +
>> +static void msm_vidc_unregister_video_device(struct msm_vidc_core *core,
>> +					     enum msm_vidc_domain_type type)
>> +{
>> +	int index;
>> +
>> +	if (type == MSM_VIDC_DECODER)
> I'm not sure this is defined.
> 
>> +		index = 0;
>> +	else if (type == MSM_VIDC_ENCODER)
> Or this.
> 
These macros are defined in [1]

[1]:
https://patchwork.linuxtv.org/project/linux-media/patch/1690550624-14642-18-git-send-email-quic_vgarodia@quicinc.com/

> Can't we just assign index = MSM_VIDC_EN/DECODER?
> these are bitmasks hence can not be used as array index and the bitmask
values are being used in driver at multiple places.
>> +		index = 1;
>> +	else
>> +		return;
>> +
>> +	v4l2_m2m_release(core->vdev[index].m2m_dev);
>> +
>> +	video_set_drvdata(&core->vdev[index].vdev, NULL);
>> +	video_unregister_device(&core->vdev[index].vdev);
>> +}
>> +
>> +static int msm_vidc_register_video_device(struct msm_vidc_core *core,
>> +					  enum msm_vidc_domain_type type, int nr)
>> +{
>> +	int rc = 0;
>> +	int index;
>> +
>> +	d_vpr_h("%s: domain %d\n", __func__, type);
>> +
>> +	if (type == MSM_VIDC_DECODER)
>> +		index = 0;
>> +	else if (type == MSM_VIDC_ENCODER)
>> +		index = 1;
>> +	else
>> +		return -EINVAL;
>> +
>> +	core->vdev[index].vdev.release =
>> +		msm_vidc_release_video_device;
>> +	core->vdev[index].vdev.fops = core->v4l2_file_ops;
>> +	if (type == MSM_VIDC_DECODER)
>> +		core->vdev[index].vdev.ioctl_ops = core->v4l2_ioctl_ops_dec;
>> +	else
>> +		core->vdev[index].vdev.ioctl_ops = core->v4l2_ioctl_ops_enc;
>> +	core->vdev[index].vdev.vfl_dir = VFL_DIR_M2M;
>> +	core->vdev[index].type = type;
>> +	core->vdev[index].vdev.v4l2_dev = &core->v4l2_dev;
>> +	core->vdev[index].vdev.device_caps = core->capabilities[DEVICE_CAPS].value;
>> +	rc = video_register_device(&core->vdev[index].vdev,
>> +				   VFL_TYPE_VIDEO, nr);
>> +	if (rc) {
>> +		d_vpr_e("Failed to register the video device\n");
>> +		return rc;
>> +	}
>> +	video_set_drvdata(&core->vdev[index].vdev, core);
>> +
>> +	core->vdev[index].m2m_dev = v4l2_m2m_init(core->v4l2_m2m_ops);
>> +	if (IS_ERR(core->vdev[index].m2m_dev)) {
>> +		d_vpr_e("Failed to initialize V4L2 M2M device\n");
>> +		rc = PTR_ERR(core->vdev[index].m2m_dev);
>> +		goto m2m_init_failed;
>> +	}
>> +
>> +	return 0;
>> +
>> +m2m_init_failed:
>> +	video_unregister_device(&core->vdev[index].vdev);
>> +	return rc;
>> +}
>> +
>> +static int msm_vidc_deinitialize_core(struct msm_vidc_core *core)
>> +{
>> +	int rc = 0;
>> +
>> +	if (!core) {
> Are we expecting to ever hit this?
> 
True, it's highly unlikely that we hit this, will remove the check.
>> +		d_vpr_e("%s: invalid params\n", __func__);
>> +		return -EINVAL;
>> +	}
>> +
>> +	mutex_destroy(&core->lock);
>> +	msm_vidc_update_core_state(core, MSM_VIDC_CORE_DEINIT, __func__);
> Not defined.
> 
it is defined in [2]

>> +
>> +	if (core->batch_workq)
>> +		destroy_workqueue(core->batch_workq);
>> +
>> +	if (core->pm_workq)
>> +		destroy_workqueue(core->pm_workq);
>> +
>> +	core->batch_workq = NULL;
>> +	core->pm_workq = NULL;
>> +
>> +	return rc;
>> +}
>> +
>> +static int msm_vidc_initialize_core(struct msm_vidc_core *core)
>> +{
>> +	int rc = 0;
>> +
>> +	msm_vidc_update_core_state(core, MSM_VIDC_CORE_DEINIT, __func__);
> Not defined.
> 
it is defined in [2]

[2]:
https://patchwork.linuxtv.org/project/linux-media/patch/1690550624-14642-15-git-send-email-quic_vgarodia@quicinc.com/
>> +
>> +	core->pm_workq = create_singlethread_workqueue("pm_workq");
>> +	if (!core->pm_workq) {
>> +		d_vpr_e("%s: create pm workq failed\n", __func__);
>> +		rc = -EINVAL;
>> +		goto exit;
>> +	}
>> +
>> +	core->batch_workq = create_singlethread_workqueue("batch_workq");
>> +	if (!core->batch_workq) {
>> +		d_vpr_e("%s: create batch workq failed\n", __func__);
>> +		rc = -EINVAL;
>> +		goto exit;
>> +	}
>> +
>> +	core->packet_size = VIDC_IFACEQ_VAR_HUGE_PKT_SIZE;
>> +	core->packet = devm_kzalloc(&core->pdev->dev, core->packet_size, GFP_KERNEL);
>> +	if (!core->packet) {
>> +		d_vpr_e("%s: failed to alloc core packet\n", __func__);
>> +		rc = -ENOMEM;
>> +		goto exit;
>> +	}
>> +
>> +	core->response_packet = devm_kzalloc(&core->pdev->dev, core->packet_size, GFP_KERNEL);
>> +	if (!core->packet) {
>> +		d_vpr_e("%s: failed to alloc core response packet\n", __func__);
>> +		rc = -ENOMEM;
>> +		goto exit;
>> +	}
>> +
>> +	mutex_init(&core->lock);
>> +	INIT_LIST_HEAD(&core->instances);
>> +	INIT_LIST_HEAD(&core->dangling_instances);
>> +
>> +	INIT_DELAYED_WORK(&core->pm_work, venus_hfi_pm_work_handler);
>> +	INIT_DELAYED_WORK(&core->fw_unload_work, msm_vidc_fw_unload_handler);
>> +
>> +	return 0;
> Either return rc/ret here or don't initialize it at definition.
> 
Sure, Will fix it.
>> +exit:
>> +	if (core->batch_workq)
>> +		destroy_workqueue(core->batch_workq);
>> +	if (core->pm_workq)
>> +		destroy_workqueue(core->pm_workq);
>> +	core->batch_workq = NULL;
>> +	core->pm_workq = NULL;
>> +
>> +	return rc;
>> +}
> [...]
> 
>> +
>> +static int msm_vidc_pm_suspend(struct device *dev)
>> +{
>> +	int rc = 0;
>> +	struct msm_vidc_core *core;
>> +	enum msm_vidc_allow allow = MSM_VIDC_DISALLOW;
>> +
>> +	/*
>> +	 * Bail out if
>> +	 * - driver possibly not probed yet
> Would the pm callbacks be registered by then?
> 
>> +	 * - not the main device. We don't support power management on
>> +	 *   subdevices (e.g. context banks)
> I'm not sure registering context banks as different kinds of devices
> within the same driver is a good idea, this seems rather convoluted.
> 
Sure, will remove the separate probe for context bank in next version.
>> +	 */
>> +	if (!dev || !dev->driver || !is_video_device(dev))
>> +		return 0;
>> +
>> +	core = dev_get_drvdata(dev);
>> +	if (!core) {
>> +		d_vpr_e("%s: invalid core\n", __func__);
>> +		return -EINVAL;
>> +	}
>> +
>> +	core_lock(core, __func__);
>> +	allow = msm_vidc_allow_pm_suspend(core);
>> +
>> +	if (allow == MSM_VIDC_IGNORE) {
>> +		d_vpr_h("%s: pm already suspended\n", __func__);
>> +		msm_vidc_change_core_sub_state(core, 0, CORE_SUBSTATE_PM_SUSPEND, __func__);
>> +		rc = 0;
>> +		goto unlock;
>> +	} else if (allow != MSM_VIDC_ALLOW) {
>> +		d_vpr_h("%s: pm suspend not allowed\n", __func__);
>> +		rc = 0;
>> +		goto unlock;
>> +	}
>> +
>> +	rc = msm_vidc_suspend(core);
>> +	if (rc == -EOPNOTSUPP)
>> +		rc = 0;
>> +	else if (rc)
>> +		d_vpr_e("Failed to suspend: %d\n", rc);
>> +	else
>> +		msm_vidc_change_core_sub_state(core, 0, CORE_SUBSTATE_PM_SUSPEND, __func__);
>> +
>> +unlock:
>> +	core_unlock(core, __func__);
>> +	return rc;
>> +}
>> +
>> +static int msm_vidc_pm_resume(struct device *dev)
> Same comments as in _suspend
> 
> Konrad

  reply	other threads:[~2023-08-14 18:50 UTC|newest]

Thread overview: 108+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-28 13:23 [PATCH 00/33] Qualcomm video decoder/encoder driver Vikash Garodia
2023-07-28 13:23 ` [PATCH 01/33] MAINTAINERS: Add Qualcomm Iris video accelerator driver Vikash Garodia
2023-07-28 22:48   ` Randy Dunlap
2023-08-14 18:44     ` Dikshita Agarwal
2023-08-16 12:00       ` Bryan O'Donoghue
2023-08-16 13:14         ` Dmitry Baryshkov
2023-07-28 13:23 ` [PATCH 02/33] iris: vidc: add core functions Vikash Garodia
2023-07-28 13:45   ` Konrad Dybcio
2023-08-14 18:49     ` Dikshita Agarwal [this message]
2023-07-28 13:47   ` Konrad Dybcio
2023-07-28 13:49   ` Dmitry Baryshkov
2023-08-14 18:58     ` Dikshita Agarwal
2023-08-14 21:03       ` Dmitry Baryshkov
2023-08-24 15:32         ` Vikash Garodia
2023-07-31 21:16   ` Krzysztof Kozlowski
2023-08-14 18:54     ` Dikshita Agarwal
2023-08-14 20:04       ` Krzysztof Kozlowski
2023-07-31 21:23   ` Krzysztof Kozlowski
2023-08-14 18:51     ` Dikshita Agarwal
2023-07-28 13:23 ` [PATCH 03/33] iris: vidc: add v4l2 wrapper file Vikash Garodia
2023-07-28 13:34   ` Dmitry Baryshkov
2023-08-14 18:59     ` Dikshita Agarwal
2023-08-14 21:19       ` Dmitry Baryshkov
2023-07-28 16:23   ` Bjorn Andersson
2023-07-28 17:50   ` Nicolas Dufresne
2023-08-14 19:14     ` Dikshita Agarwal
2023-07-31 21:23   ` Krzysztof Kozlowski
2023-08-14 19:00     ` Dikshita Agarwal
2023-07-28 13:23 ` [PATCH 04/33] iris: add vidc " Vikash Garodia
2023-07-28 13:23 ` [PATCH 05/33] iris: vidc: add vb2 ops Vikash Garodia
2023-07-28 18:03   ` Nicolas Dufresne
2023-08-14 19:03     ` Dikshita Agarwal
2023-07-28 13:23 ` [PATCH 06/33] iris: vidc: define video core and instance context Vikash Garodia
2023-07-28 15:47   ` Bryan O'Donoghue
2023-08-14 19:04     ` Dikshita Agarwal
2023-07-28 13:23 ` [PATCH 07/33] iris: iris: add video encoder files Vikash Garodia
2023-07-28 13:23 ` [PATCH 08/33] iris: vidc: add video decoder files Vikash Garodia
2023-07-28 17:21   ` Konrad Dybcio
2023-08-14 19:13     ` Dikshita Agarwal
2023-07-28 13:23 ` [PATCH 09/33] iris: vidc: add control files Vikash Garodia
2023-07-28 13:23 ` [PATCH 10/33] iris: vidc: add helper functions Vikash Garodia
2023-07-28 17:41   ` Konrad Dybcio
2023-08-14 19:15     ` Dikshita Agarwal
2023-08-16 11:46       ` Konrad Dybcio
2023-07-28 13:23 ` [PATCH 11/33] iris: vidc: add helpers for memory management Vikash Garodia
2023-07-28 16:28   ` Bjorn Andersson
2023-07-28 17:22     ` Konrad Dybcio
2023-08-14 19:06       ` Dikshita Agarwal
2023-08-25 18:38         ` Konrad Dybcio
2023-08-14 19:05     ` Dikshita Agarwal
2023-07-28 13:23 ` [PATCH 12/33] iris: vidc: add helper functions for resource management Vikash Garodia
2023-07-28 17:30   ` Konrad Dybcio
2023-08-14 19:07     ` Dikshita Agarwal
2023-07-28 13:23 ` [PATCH 13/33] iris: vidc: add helper functions for power management Vikash Garodia
2023-07-28 17:46   ` Konrad Dybcio
2023-08-14 19:10     ` Dikshita Agarwal
2023-07-28 13:23 ` [PATCH 14/33] iris: vidc: add helpers for state management Vikash Garodia
2023-07-28 17:52   ` Konrad Dybcio
2023-08-14 19:17     ` Dikshita Agarwal
2023-07-28 13:23 ` [PATCH 15/33] iris: add vidc buffer files Vikash Garodia
2023-07-28 13:23 ` [PATCH 16/33] iris: add helpers for media format Vikash Garodia
2023-07-28 17:55   ` Konrad Dybcio
2023-08-14 19:18     ` Dikshita Agarwal
2023-07-28 13:23 ` [PATCH 17/33] iris: vidc: define various structures and enum Vikash Garodia
2023-07-28 13:23 ` [PATCH 18/33] iris: vidc: hfi: add Host Firmware Interface (HFI) Vikash Garodia
2023-07-28 15:58   ` Bryan O'Donoghue
2023-08-14 19:11     ` Dikshita Agarwal
2023-07-31  9:02   ` Bryan O'Donoghue
2023-08-14 19:11     ` Dikshita Agarwal
2023-07-28 13:23 ` [PATCH 19/33] iris: vidc: hfi: add Host Firmware Interface (HFI) response handling Vikash Garodia
2023-07-28 13:23 ` [PATCH 20/33] iris: vidc: hfi: add helpers for handling shared queues Vikash Garodia
2023-07-28 17:58   ` Konrad Dybcio
2023-08-14 19:19     ` Dikshita Agarwal
2023-07-28 13:23 ` [PATCH 21/33] iris: vidc: hfi: Add packetization layer Vikash Garodia
2023-07-28 13:23 ` [PATCH 22/33] iris: vidc: hfi: defines HFI properties and enums Vikash Garodia
2023-07-28 13:23 ` [PATCH 23/33] iris: vidc: add PIL functionality for video firmware Vikash Garodia
2023-07-28 13:23 ` [PATCH 24/33] iris: vidc: add debug files Vikash Garodia
2023-07-31 21:31   ` Krzysztof Kozlowski
2023-08-14 19:12     ` Dikshita Agarwal
2023-07-28 13:23 ` [PATCH 25/33] iris: platform: add platform files Vikash Garodia
2023-07-28 13:23 ` [PATCH 26/33] iris: platform: sm8550: add capability file for sm8550 Vikash Garodia
2023-07-28 14:13   ` Dmitry Baryshkov
2023-08-14 19:35     ` Dikshita Agarwal
2023-08-14 21:17       ` Dmitry Baryshkov
2023-07-28 13:23 ` [PATCH 27/33] iris: variant: add helper functions for register handling Vikash Garodia
2023-07-28 13:23 ` [PATCH 28/33] iris: variant: iris3: add iris3 specific ops Vikash Garodia
2023-07-28 13:23 ` [PATCH 29/33] iris: variant: iris3: add helpers for buffer size calculations Vikash Garodia
2023-07-28 14:19   ` Dmitry Baryshkov
2023-08-14 20:00     ` Dikshita Agarwal
2023-08-14 20:59       ` Dmitry Baryshkov
2023-07-28 13:23 ` [PATCH 30/33] iris: variant: iris3: add helper for bus and clock calculation Vikash Garodia
2023-07-28 13:23 ` [PATCH 31/33] iris: variant: iris: implement the logic to compute bus bandwidth Vikash Garodia
2023-07-28 18:09   ` Konrad Dybcio
2023-08-14 19:21     ` Dikshita Agarwal
2023-07-28 13:23 ` [PATCH 32/33] iris: variant: iris3: implement logic to compute clock frequency Vikash Garodia
2023-07-28 18:13   ` Konrad Dybcio
2023-08-14 19:25     ` Dikshita Agarwal
2023-07-28 13:23 ` [PATCH 33/33] iris: enable building of iris video driver Vikash Garodia
2023-07-28 14:40   ` Dmitry Baryshkov
2023-07-28 15:25   ` Bryan O'Donoghue
2023-07-28 15:51     ` Dmitry Baryshkov
2023-07-28 13:32 ` [PATCH 00/33] Qualcomm video decoder/encoder driver Dmitry Baryshkov
2023-07-28 17:38   ` Nicolas Dufresne
2023-07-28 14:01 ` Dmitry Baryshkov
2023-08-14 12:58   ` Stanimir Varbanov
2023-08-14 15:00     ` Dmitry Baryshkov
2023-08-24 15:23       ` Vikash Garodia
2023-07-28 14:34 ` Bryan O'Donoghue

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1c8f7cb2-9536-39f7-05ba-a568b3d3be5f@quicinc.com \
    --to=quic_dikshita@quicinc.com \
    --cc=agross@kernel.org \
    --cc=andersson@kernel.org \
    --cc=hans.verkuil@cisco.com \
    --cc=konrad.dybcio@linaro.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=quic_vgarodia@quicinc.com \
    --cc=stanimir.k.varbanov@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®