Message ID | 20241127-media-staging-24-11-25-rb3-hw-compat-string-v2-0-c010fd45f7ff@linaro.org |
---|---|
Headers | show |
Series | media: venus: Provide support for selecting encoder/decoder from in-driver | expand |
On 11/27/24 13:44, Bryan O'Donoghue wrote: > Add resource structure data and probe() logic to support static > declarations of encoder and decoder. > > Right now we rely on video encoder/decoder selection happening in the dtb > but, this goes against the remit of device tree which is supposed to > describe hardware, not select functional logic in Linux drivers. > > Provide two strings in the venus resource structure enc_nodename and > dec_nodename. > > When set the venus driver will create an OF entry in-memory consistent > with: > > dec_nodename { > compat = "video-decoder"; > }; > > and/or > > enc_nodename { > compat = "video-encoder"; > }; > > This will allow us to reuse the existing driver scheme of relying on compat > names maintaining compatibility with old dtb files. > > dec_nodename can be "video-decoder" or "video0" > enc_nodename can be "video-encoder" or "video1" > > Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> > --- > drivers/media/platform/qcom/venus/core.c | 56 ++++++++++++++++++++++++++++++++ > drivers/media/platform/qcom/venus/core.h | 2 ++ > 2 files changed, 58 insertions(+) > > diff --git a/drivers/media/platform/qcom/venus/core.c b/drivers/media/platform/qcom/venus/core.c > index 4e26b18790537885a77d66c1917a4e7a146eaf57..17506d547a6172b89acb77879337750c22f993cf 100644 > --- a/drivers/media/platform/qcom/venus/core.c > +++ b/drivers/media/platform/qcom/venus/core.c > @@ -286,6 +286,36 @@ static irqreturn_t venus_isr_thread(int irq, void *dev_id) > return ret; > } > > +static int venus_add_video_core(struct device *dev, struct of_changeset *ocs, > + const char *node_name, const char *compat) > +{ > + struct device_node *np, *enp; > + int ret; > + > + if (!node_name) > + return 0; > + > + enp = of_find_node_by_name(dev->of_node, node_name); > + if (enp) { > + of_node_put(enp); > + return 0; > + } > + > + np = of_changeset_create_node(ocs, dev->of_node, node_name); > + if (!np) { > + dev_err(dev, "Unable to create new node\n"); > + return -ENODEV; Leaked reference to np. > + } > + > + ret = of_changeset_add_prop_string(ocs, np, "compatible", compat); > + if (ret) > + dev_err(dev, "unable to add %s\n", compat); > + > + of_node_put(np); > + > + return ret; > +} > + > static int venus_probe(struct platform_device *pdev) > { > struct device *dev = &pdev->dev; > @@ -365,6 +395,32 @@ static int venus_probe(struct platform_device *pdev) > if (ret < 0) > goto err_runtime_disable; > > + if (core->res->dec_nodename || core->res->enc_nodename) { > + struct of_changeset *ocs; > + > + ocs = devm_kmalloc(dev, sizeof(*ocs), GFP_KERNEL); > + if (!ocs) { > + ret = -ENOMEM; > + goto err_runtime_disable; > + } > + > + of_changeset_init(ocs); > + > + ret = venus_add_video_core(dev, ocs, core->res->dec_nodename, "venus-decoder"); > + if (ret) > + goto err_runtime_disable; > + > + ret = venus_add_video_core(dev, ocs, core->res->enc_nodename, "venus-encoder"); > + if (ret) > + goto err_runtime_disable; > + > + ret = of_changeset_apply(ocs); > + if (ret) { > + dev_err(dev, "applying changeset fail ret %d\n", ret); > + goto err_runtime_disable; > + } > + } > + > ret = of_platform_populate(dev->of_node, NULL, NULL, dev); > if (ret) > goto err_runtime_disable; > diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h > index 27784fd7082c321222b23ca4b2902a04c49e19ca..4ce98a3ef186823a57ac40e2e8e42b08fafed575 100644 > --- a/drivers/media/platform/qcom/venus/core.h > +++ b/drivers/media/platform/qcom/venus/core.h > @@ -90,6 +90,8 @@ struct venus_resources { > u32 cp_nonpixel_start; > u32 cp_nonpixel_size; > const char *fwname; > + const char *enc_nodename; > + const char *dec_nodename; > }; > > enum venus_fmt { > -- Best wishes, Vladimir
On 28/11/2024 09:02, Vladimir Zapolskiy wrote: >> + np = of_changeset_create_node(ocs, dev->of_node, node_name); >> + if (!np) { >> + dev_err(dev, "Unable to create new node\n"); >> + return -ENODEV; > > Leaked reference to np. I don't believe that's a leak, because you only release np when it is non-NULL. >> + } >> + >> + ret = of_changeset_add_prop_string(ocs, np, "compatible", compat); >> + if (ret) >> + dev_err(dev, "unable to add %s\n", compat); >> + >> + of_node_put(np); Which we do here. However, I think I have missed a of_changeset_destroy(ocs); on the error path. @ref drivers/pci/of.c::of_pci_make_dev_node() --- bod
On 11/28/24 14:54, Bryan O'Donoghue wrote: > On 28/11/2024 09:02, Vladimir Zapolskiy wrote: >>> + np = of_changeset_create_node(ocs, dev->of_node, node_name); >>> + if (!np) { >>> + dev_err(dev, "Unable to create new node\n"); >>> + return -ENODEV; >> >> Leaked reference to np. > > I don't believe that's a leak, because you only release np when it is > non-NULL. > Clearly it's my fault here, I'm very sorry for it. -- Best wishes, Vladimir
v2: - Removes useless dev_info() leftover from debugging - Bryan Link: https://lore.kernel.org/r/ce9ac473-2f73-4c7a-97b1-08be39f3adb4@linaro.org - Trivial newline change @ np = of_changeset_create_node(ocs, dev->of_node, node_name); - Bryan - Fixes a missing goto identified by smatch - Smatch/Bryan - Adds Krzysztof's RB to deprecated - Krzysztof - Link to v1: https://lore.kernel.org/r/20241127-media-staging-24-11-25-rb3-hw-compat-string-v1-0-99c16f266b46@linaro.org v1: Various venus patches have been held up due to the misuse of DT to provide a configuration input to venus as to which mode a given transcoder should be in. Link: https://lore.kernel.org/linux-arm-msm/436145fd-d65f-44ec-b950-c434775187ca@kernel.org Link: https://lore.kernel.org/linux-media/ba40de82-b308-67b1-5751-bb2d95f2b8a5@linaro.org/ This series provides support for static configuration of venus from the resource structure via: 1. Adding two strings to the resource structure. One string for the decoder one for the encoder. 2. The string for each SoC has been matched to the existing in the DT which currently specifies the mode as decoder or encoder. 3. New logic in the driver parses the DTB looking for the node name specified for the decoder and encoder . 4. If the DTB contains the node name, then no new node is added as we assume to be working with an "old" DTB. 5. If the DTB does not contain the specified decoder/encoder string then a new in-memory node is added which contains a compat string consistent with upstream compat strings used to currently select between the decoder and encoder respectively. 6. In this way new venus driver entries may be added which respect the requirement to move mode selection out of DTB and into driver. 7. Simple instances of decoder/encoder nodes in the yaml schema have been marked as deprecated. 8. Since the proposed scheme here always defers to what the DTB says that means it would be possible to remove decoder/encoder entries for the deprecated schema should we choose to do so at a later date but, that step is not taken in this series. 9. Some of the upstream encoder/decoder nodes for example sdm630/sdm660 also contain clock and power-domain information and have not been updated with the static configuration data or had the schema amended to deprecate values. Because these nodes impart hardware specific information and are already upstream this series proposes to leave those as-is. However if this scheme is adopted it should allow for addition of venus for both qcs615[1] and sc8280xp[2]. Other SoCs such as sm8550, sm8650 and beyond are expected to be supported by Iris. The sm8350 and sm8280xp in the second series would then be able to excise the offending compat = "video-encoder" | "video-decoder" in the schema and DT. I considered making this series an all singing all dancing method to select between encoder and decoder for all SoCs but, the objective here is not to add functionality but to provide support for configuration in-driver consistent with current usage and to do so with a minimal code intervention. So far I've tested on RB3 by removing: video-core0 { compatible = "venus-decoder"; }; video-core1 { compatible = "venus-encoder"; }; This works - the code adds the nodes into memory and the video encoder/decoder logic in the plaform code runs. Similarly if the nodes are left in-place then no new nodes are added by the code in this series and still both encoder and decoder probe. Thus proving the code works and will provide support for new platforms while also leaving open the option of dropping nodes from upstream. I've left the dropping step out for now, it can be implemented later. [1] https://lore.kernel.org/linux-arm-msm/20241125-add-venus-for-qcs615-v3-0-5a376b97a68e@quicinc.com [2] https://lore.kernel.org/linux-media/20230731-topic-8280_venus-v1-0-8c8bbe1983a5@linaro.org/ Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org> --- Bryan O'Donoghue (3): media: venus: Add support for static video encoder/decoder declarations media: venus: Populate video encoder/decoder nodename entries media: dt-bindings: qcom-venus: Deprecate video-decoder and video-encoder where applicable .../bindings/media/qcom,msm8916-venus.yaml | 12 +--- .../bindings/media/qcom,sc7180-venus.yaml | 12 +--- .../bindings/media/qcom,sc7280-venus.yaml | 12 +--- .../bindings/media/qcom,sdm845-venus-v2.yaml | 12 +--- .../bindings/media/qcom,sm8250-venus.yaml | 12 +--- drivers/media/platform/qcom/venus/core.c | 66 ++++++++++++++++++++++ drivers/media/platform/qcom/venus/core.h | 2 + 7 files changed, 78 insertions(+), 50 deletions(-) --- base-commit: 72ad4ff638047bbbdf3232178fea4bec1f429319 change-id: 20241127-media-staging-24-11-25-rb3-hw-compat-string-ea3c99938021 Best regards,