From patchwork Tue Mar 7 16:58:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jordan Crouse X-Patchwork-Id: 9609445 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4AF6660414 for ; Tue, 7 Mar 2017 16:58:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E6699277D9 for ; Tue, 7 Mar 2017 16:58:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D9F5328502; Tue, 7 Mar 2017 16:58:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 69686277D9 for ; Tue, 7 Mar 2017 16:58:34 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 222196E77F; Tue, 7 Mar 2017 16:58:28 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from smtp.codeaurora.org (smtp.codeaurora.org [198.145.29.96]) by gabe.freedesktop.org (Postfix) with ESMTPS id C42D06E777; Tue, 7 Mar 2017 16:58:26 +0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1000) id ABEE460739; Tue, 7 Mar 2017 16:58:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1488905906; bh=OLh7wEMko0sVnrdvRwCUz4IQC1qxj0sc0xM9jgVSm5g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R91izbd6LDjeHHM9MIyZk9FHNBd8/3nFEHNoKPJ1xQru9RDfdctNRuIrA/zgvO3cI Vv75kY7ROm7itBhaaT86DEGXLTd5EQrZbOH19PNPYKAeL7GqyQvkjcgLSoblfJk6Ko NoPGGwT+9pyxBOHcbM/pmbmxBcSHerG39s8+8qRU= Received: from jcrouse-lnx.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: jcrouse@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 3B03B60739; Tue, 7 Mar 2017 16:58:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1488905905; bh=OLh7wEMko0sVnrdvRwCUz4IQC1qxj0sc0xM9jgVSm5g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jhxTx/i1wRVEFTBcWRM2hxmQctYDVkZ1B/jibiW9H1t/BvP8VvncPfJ+hmSS+8jjo tmY2NUFVXmKhmscne++xa1SnoJUbMbM0wCPMzTD31rEoSpJ+NXXU32QKkeAwfd74N5 6/fTIAhNZmOjq3b4BhAYD+GbzK4xUF+lCMlYkTsI= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 3B03B60739 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=jcrouse@codeaurora.org From: Jordan Crouse To: freedreno@lists.freedesktop.org Subject: [PATCH 02/11] drm/msm: Improve the zap shader Date: Tue, 7 Mar 2017 09:58:11 -0700 Message-Id: <1488905900-6603-3-git-send-email-jcrouse@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1488905900-6603-1-git-send-email-jcrouse@codeaurora.org> References: <1486402779-9024-1-git-send-email-jcrouse@codeaurora.org> <1488905900-6603-1-git-send-email-jcrouse@codeaurora.org> Cc: linux-arm-msm@vger.kernel.org, dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Simply the code, use snprintf correct 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 --- arch/arm64/boot/dts/qcom/msm8996.dtsi | 4 +- drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 70 +++++++++++++++++------------------ 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/arch/arm64/boot/dts/qcom/msm8996.dtsi b/arch/arm64/boot/dts/qcom/msm8996.dtsi index b004275..2903020 100644 --- a/arch/arm64/boot/dts/qcom/msm8996.dtsi +++ b/arch/arm64/boot/dts/qcom/msm8996.dtsi @@ -915,8 +915,8 @@ }; }; - qcom,zap-shader { - compatible = "qcom,zap-shader"; + zap-shader { + compatible = "zap-shader"; memory-region = <&peripheral_reserved>; qcom,firmware = "a530_zap"; diff --git a/drivers/gpu/drm/msm/adreno/a5xx_gpu.c b/drivers/gpu/drm/msm/adreno/a5xx_gpu.c index dfc9734..9d754a7 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);