From: Jordan Crouse <jcrouse@codeaurora.org>
To: freedreno@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
bjorn.andersson@linaro.org
Cc: linux-arm-msm@vger.kernel.org
Subject: [PATCH 3/6] drm/msm: Improve the zap shader
Date: Wed, 12 Apr 2017 15:15:15 -0600 [thread overview]
Message-ID: <1492031718-28477-4-git-send-email-jcrouse@codeaurora.org> (raw)
In-Reply-To: <1492031718-28477-1-git-send-email-jcrouse@codeaurora.org>
Simply the code use snprintf correctly and make sure that we memset
the rest of the segment if the memory size in the ELF file is larger
than the file size.
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
---
drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 70 +++++++++++++++++------------------
1 file changed, 35 insertions(+), 35 deletions(-)
diff --git a/drivers/gpu/drm/msm/adreno/a5xx_gpu.c b/drivers/gpu/drm/msm/adreno/a5xx_gpu.c
index 0e2b00a..0a096f8 100644
--- a/drivers/gpu/drm/msm/adreno/a5xx_gpu.c
+++ b/drivers/gpu/drm/msm/adreno/a5xx_gpu.c
@@ -31,11 +31,11 @@ static inline bool _check_segment(const struct elf32_phdr *phdr)
phdr->p_memsz);
}
-static int __pil_tz_load_image(struct platform_device *pdev,
+static int zap_load_segments(struct platform_device *pdev,
const struct firmware *mdt, const char *fwname,
void *fwptr, size_t fw_size, unsigned long fw_min_addr)
{
- char str[64] = { 0 };
+ char filename[64];
const struct elf32_hdr *ehdr = (struct elf32_hdr *) mdt->data;
const struct elf32_phdr *phdrs = (struct elf32_phdr *) (ehdr + 1);
const struct firmware *fw;
@@ -53,16 +53,18 @@ static int __pil_tz_load_image(struct platform_device *pdev,
offset = (phdr->p_paddr - fw_min_addr);
/* Request the file containing the segment */
- snprintf(str, sizeof(str) - 1, "%s.b%02d", fwname, i);
+ snprintf(filename, sizeof(filename), "%s.b%02d", fwname, i);
- ret = request_firmware(&fw, str, &pdev->dev);
+ ret = request_firmware(&fw, filename, &pdev->dev);
if (ret) {
- dev_err(&pdev->dev, "Failed to load segment %s\n", str);
+ DRM_DEV_ERROR(&pdev->dev, "Failed to load segment %s\n",
+ filename);
break;
}
if (offset + fw->size > fw_size) {
- dev_err(&pdev->dev, "Segment %s is too big\n", str);
+ DRM_DEV_ERROR(&pdev->dev, "Segment %s is too big\n",
+ filename);
ret = -EINVAL;
release_firmware(fw);
break;
@@ -70,15 +72,19 @@ static int __pil_tz_load_image(struct platform_device *pdev,
/* Copy the segment into place */
memcpy(fwptr + offset, fw->data, fw->size);
+
+ if (phdr->p_memsz > phdr->p_filesz)
+ memset(fwptr + fw->size, 0,
+ phdr->p_memsz - phdr->p_filesz);
release_firmware(fw);
}
return ret;
}
-static int _pil_tz_load_image(struct platform_device *pdev)
+static int zap_load_mdt(struct platform_device *pdev)
{
- char str[64] = { 0 };
+ char filename[64];
const char *fwname;
const struct elf32_hdr *ehdr;
const struct elf32_phdr *phdrs;
@@ -86,7 +92,6 @@ static int _pil_tz_load_image(struct platform_device *pdev)
phys_addr_t fw_min_addr, fw_max_addr;
dma_addr_t fw_phys;
size_t fw_size;
- u32 pas_id;
void *ptr;
int i, ret;
@@ -94,35 +99,29 @@ static int _pil_tz_load_image(struct platform_device *pdev)
return -ENODEV;
if (!qcom_scm_is_available()) {
- dev_err(&pdev->dev, "SCM is not available\n");
- return -EINVAL;
+ DRM_DEV_ERROR(&pdev->dev, "SCM is not available\n");
+ return -EPROBE_DEFER;
}
ret = of_reserved_mem_device_init(&pdev->dev);
-
if (ret) {
- dev_err(&pdev->dev, "Unable to set up the reserved memory\n");
+ DRM_DEV_ERROR(&pdev->dev, "Unable to set up the reserved memory\n");
return ret;
}
/* Get the firmware and PAS id from the device node */
if (of_property_read_string(pdev->dev.of_node, "qcom,firmware",
&fwname)) {
- dev_err(&pdev->dev, "Could not read a firmware name\n");
- return -EINVAL;
- }
-
- if (of_property_read_u32(pdev->dev.of_node, "qcom,pas-id", &pas_id)) {
- dev_err(&pdev->dev, "Could not read the pas ID\n");
+ DRM_DEV_ERROR(&pdev->dev, "Could not read a firmware name\n");
return -EINVAL;
}
- snprintf(str, sizeof(str) - 1, "%s.mdt", fwname);
+ snprintf(filename, sizeof(filename), "%s.mdt", fwname);
/* Request the MDT file for the firmware */
- ret = request_firmware(&mdt, str, &pdev->dev);
+ ret = request_firmware(&mdt, filename, &pdev->dev);
if (ret) {
- dev_err(&pdev->dev, "Unable to load %s\n", str);
+ DRM_DEV_ERROR(&pdev->dev, "Unable to load %s\n", filename);
return ret;
}
@@ -151,9 +150,9 @@ static int _pil_tz_load_image(struct platform_device *pdev)
fw_size = (size_t) (fw_max_addr - fw_min_addr);
/* Verify the MDT header */
- ret = qcom_scm_pas_init_image(pas_id, mdt->data, mdt->size);
+ ret = qcom_scm_pas_init_image(13, mdt->data, mdt->size);
if (ret) {
- dev_err(&pdev->dev, "Invalid firmware metadata\n");
+ DRM_DEV_ERROR(&pdev->dev, "Invalid firmware metadata\n");
goto out;
}
@@ -163,18 +162,19 @@ static int _pil_tz_load_image(struct platform_device *pdev)
goto out;
/* Set up the newly allocated memory region */
- ret = qcom_scm_pas_mem_setup(pas_id, fw_phys, fw_size);
+ ret = qcom_scm_pas_mem_setup(13, fw_phys, fw_size);
if (ret) {
- dev_err(&pdev->dev, "Unable to set up firmware memory\n");
+ DRM_DEV_ERROR(&pdev->dev, "Unable to set up firmware memory\n");
goto out;
}
- ret = __pil_tz_load_image(pdev, mdt, fwname, ptr, fw_size, fw_min_addr);
- if (!ret) {
- ret = qcom_scm_pas_auth_and_reset(pas_id);
- if (ret)
- dev_err(&pdev->dev, "Unable to authorize the image\n");
- }
+ ret = zap_load_segments(pdev, mdt, fwname, ptr, fw_size, fw_min_addr);
+ if (ret)
+ goto out;
+
+ ret = qcom_scm_pas_auth_and_reset(13);
+ if (ret)
+ DRM_DEV_ERROR(&pdev->dev, "Unable to authorize the image\n");
out:
if (ret && ptr)
@@ -502,14 +502,14 @@ static int a5xx_zap_shader_init(struct msm_gpu *gpu)
of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev);
/* Find the sub-node for the zap shader */
- node = of_find_node_by_name(pdev->dev.of_node, "qcom,zap-shader");
+ node = of_get_child_by_name(pdev->dev.of_node, "zap-shader");
if (!node) {
- DRM_ERROR("%s: qcom,zap-shader not found in device tree\n",
+ DRM_ERROR("%s: zap-shader not found in device tree\n",
gpu->name);
return -ENODEV;
}
- ret = _pil_tz_load_image(of_find_device_by_node(node));
+ ret = zap_load_mdt(of_find_device_by_node(node));
if (ret)
DRM_ERROR("%s: Unable to load the zap shader\n",
gpu->name);
--
1.9.1
next prev parent reply other threads:[~2017-04-12 21:15 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-12 21:15 [PATCH 0/6] drm: msm: A5XX zap shader Jordan Crouse
2017-04-12 21:15 ` [PATCH 1/6] drm/msm: Add a quick and dirty PIL loader Jordan Crouse
[not found] ` <1492031718-28477-2-git-send-email-jcrouse-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2017-04-17 19:57 ` Bjorn Andersson
2017-04-12 21:15 ` Jordan Crouse [this message]
2017-04-17 19:58 ` [PATCH 3/6] drm/msm: Improve the zap shader Bjorn Andersson
2017-04-12 21:15 ` [PATCH 4/6] drm/msm: Create a child device for " Jordan Crouse
2017-04-12 21:15 ` [PATCH 5/6] drm/msm: Move zap shader firmware name to the device table Jordan Crouse
2017-04-17 19:58 ` Bjorn Andersson
[not found] ` <1492031718-28477-1-git-send-email-jcrouse-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2017-04-12 21:15 ` [PATCH 2/6] drm/msm: gpu: Use the zap shader on 5XX if we can Jordan Crouse
[not found] ` <1492031718-28477-3-git-send-email-jcrouse-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2017-04-17 19:58 ` Bjorn Andersson
[not found] ` <20170417195807.GB12022-iTMlPVAvTYNoL7IsjepNBwq4bfNCki47rNQQ6b5fDX0@public.gmane.org>
2017-04-17 21:51 ` Jordan Crouse
[not found] ` <20170417215124.GA415-9PYrDHPZ2Orvke4nUoYGnHL1okKdlPRT@public.gmane.org>
2017-04-17 23:53 ` Bjorn Andersson
2017-04-12 21:15 ` [PATCH 6/6] drm/msm: Document the zap-shader subnode for the GPU Jordan Crouse
2017-04-17 19:57 ` Bjorn Andersson
2017-04-17 19:57 ` [PATCH 0/6] drm: msm: A5XX zap shader Bjorn Andersson
2017-04-20 3:46 ` Archit Taneja
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=1492031718-28477-4-git-send-email-jcrouse@codeaurora.org \
--to=jcrouse@codeaurora.org \
--cc=bjorn.andersson@linaro.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=freedreno@lists.freedesktop.org \
--cc=linux-arm-msm@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).