msm: pil: Add pil driver for video core
Add support to boot a securely signed image on the video core.
Change-Id: Ideb010dc7b0cad9fac6aef10e3f5256372887ee3
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
diff --git a/arch/arm/mach-msm/Kconfig b/arch/arm/mach-msm/Kconfig
index 27db4a5..ae69ad4 100644
--- a/arch/arm/mach-msm/Kconfig
+++ b/arch/arm/mach-msm/Kconfig
@@ -1788,6 +1788,12 @@
DSPS is a sensors offloading processor used for applications such
as rotation detection, temperature, etc.
+config MSM_PIL_VIDC
+ tristate "Video Core Secure Boot Support"
+ depends on MSM_PIL
+ help
+ Support for authenticating the video core image.
+
config MSM_PIL_GSS
tristate "GSS (Coretx A5) Boot Support"
depends on MSM_PIL
diff --git a/arch/arm/mach-msm/Makefile b/arch/arm/mach-msm/Makefile
index b465da5..253a238 100644
--- a/arch/arm/mach-msm/Makefile
+++ b/arch/arm/mach-msm/Makefile
@@ -71,6 +71,7 @@
obj-$(CONFIG_MSM_PIL_QDSP6V4) += pil-q6v4.o
obj-$(CONFIG_MSM_PIL_RIVA) += pil-riva.o
obj-$(CONFIG_MSM_PIL_TZAPPS) += pil-tzapps.o
+obj-$(CONFIG_MSM_PIL_VIDC) += pil-vidc.o
obj-$(CONFIG_MSM_PIL_MODEM) += pil-modem.o
obj-$(CONFIG_MSM_PIL_DSPS) += pil-dsps.o
obj-$(CONFIG_MSM_PIL_GSS) += pil-gss.o
diff --git a/arch/arm/mach-msm/board-8064.c b/arch/arm/mach-msm/board-8064.c
index 3f4266f..df20d60 100644
--- a/arch/arm/mach-msm/board-8064.c
+++ b/arch/arm/mach-msm/board-8064.c
@@ -1871,6 +1871,7 @@
&msm_pil_dsps,
&msm_8960_riva,
&msm_8960_q6_lpass,
+ &msm_pil_vidc,
&msm_gss,
#ifdef CONFIG_MSM_RTB
&msm_rtb_device,
diff --git a/arch/arm/mach-msm/board-8930.c b/arch/arm/mach-msm/board-8930.c
index 5493628..98f1228 100644
--- a/arch/arm/mach-msm/board-8930.c
+++ b/arch/arm/mach-msm/board-8930.c
@@ -1637,6 +1637,7 @@
&msm_8960_q6_mss_sw,
&msm_8960_riva,
&msm_pil_tzapps,
+ &msm_pil_vidc,
&msm8960_device_qup_spi_gsbi1,
&msm8960_device_qup_i2c_gsbi3,
&msm8960_device_qup_i2c_gsbi4,
diff --git a/arch/arm/mach-msm/board-8960.c b/arch/arm/mach-msm/board-8960.c
index f462c7a..29fc200 100644
--- a/arch/arm/mach-msm/board-8960.c
+++ b/arch/arm/mach-msm/board-8960.c
@@ -2336,6 +2336,7 @@
&msm_8960_riva,
&msm_pil_tzapps,
&msm_pil_dsps,
+ &msm_pil_vidc,
&msm8960_device_otg,
&msm8960_device_gadget_peripheral,
&msm_device_hsusb_host,
diff --git a/arch/arm/mach-msm/clock-8960.c b/arch/arm/mach-msm/clock-8960.c
index 7d1bcf3..0561a18 100644
--- a/arch/arm/mach-msm/clock-8960.c
+++ b/arch/arm/mach-msm/clock-8960.c
@@ -5178,6 +5178,9 @@
CLK_LOOKUP("core_clk", gfx3d_axi_clk_8064.c, "msm_iommu.10"),
CLK_LOOKUP("core_clk", vcap_axi_clk.c, "msm_iommu.11"),
+ CLK_LOOKUP("core_clk", vcodec_axi_clk.c, "pil_vidc"),
+ CLK_LOOKUP("smmu_iface_clk", smmu_p_clk.c, "pil_vidc"),
+
CLK_LOOKUP("mem_clk", ebi1_adm_clk.c, "msm_dmov"),
CLK_LOOKUP("l2_mclk", l2_m_clk, ""),
@@ -5456,6 +5459,8 @@
CLK_LOOKUP("vcodec_iommu0_clk", vcodec_axi_a_clk.c, "msm_vidc.0"),
CLK_LOOKUP("vcodec_iommu1_clk", vcodec_axi_b_clk.c, "msm_vidc.0"),
CLK_LOOKUP("smmu_iface_clk", smmu_p_clk.c, "msm_vidc.0"),
+ CLK_LOOKUP("core_clk", vcodec_axi_clk.c, "pil_vidc"),
+ CLK_LOOKUP("smmu_iface_clk", smmu_p_clk.c, "pil_vidc"),
CLK_LOOKUP("dfab_dsps_clk", dfab_dsps_clk.c, NULL),
CLK_LOOKUP("core_clk", dfab_usb_hs_clk.c, "msm_otg"),
@@ -5728,6 +5733,8 @@
CLK_LOOKUP("vcodec_iommu0_clk", vcodec_axi_a_clk.c, "msm_vidc.0"),
CLK_LOOKUP("vcodec_iommu1_clk", vcodec_axi_b_clk.c, "msm_vidc.0"),
CLK_LOOKUP("smmu_iface_clk", smmu_p_clk.c, "msm_vidc.0"),
+ CLK_LOOKUP("core_clk", vcodec_axi_clk.c, "pil_vidc"),
+ CLK_LOOKUP("smmu_iface_clk", smmu_p_clk.c, "pil_vidc"),
CLK_LOOKUP("dfab_dsps_clk", dfab_dsps_clk.c, NULL),
CLK_LOOKUP("core_clk", dfab_usb_hs_clk.c, "msm_otg"),
diff --git a/arch/arm/mach-msm/devices-8960.c b/arch/arm/mach-msm/devices-8960.c
index 3255248..818deaf 100644
--- a/arch/arm/mach-msm/devices-8960.c
+++ b/arch/arm/mach-msm/devices-8960.c
@@ -996,6 +996,11 @@
.dev.platform_data = "dsps",
};
+struct platform_device msm_pil_vidc = {
+ .name = "pil_vidc",
+ .id = -1,
+};
+
static struct resource smd_resource[] = {
{
.name = "a9_m2a_0",
diff --git a/arch/arm/mach-msm/devices.h b/arch/arm/mach-msm/devices.h
index 078e931..29e4dd0 100644
--- a/arch/arm/mach-msm/devices.h
+++ b/arch/arm/mach-msm/devices.h
@@ -221,6 +221,7 @@
extern struct platform_device msm_pil_modem;
extern struct platform_device msm_pil_tzapps;
extern struct platform_device msm_pil_dsps;
+extern struct platform_device msm_pil_vidc;
extern struct platform_device msm_8960_q6_lpass;
extern struct platform_device msm_8960_q6_mss_fw;
extern struct platform_device msm_8960_q6_mss_sw;
diff --git a/arch/arm/mach-msm/pil-vidc.c b/arch/arm/mach-msm/pil-vidc.c
new file mode 100644
index 0000000..ceb9bcd
--- /dev/null
+++ b/arch/arm/mach-msm/pil-vidc.c
@@ -0,0 +1,146 @@
+/* Copyright (c) 2012, Code Aurora Forum. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 and
+ * only version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/elf.h>
+#include <linux/err.h>
+#include <linux/clk.h>
+
+#include "peripheral-loader.h"
+#include "scm-pas.h"
+
+struct vidc_data {
+ struct clk *smmu_iface;
+ struct clk *core;
+ struct pil_device *pil;
+};
+
+static int pil_vidc_init_image(struct pil_desc *pil, const u8 *metadata,
+ size_t size)
+{
+ return pas_init_image(PAS_VIDC, metadata, size);
+}
+
+static int pil_vidc_reset(struct pil_desc *pil)
+{
+ int ret;
+ struct vidc_data *drv = dev_get_drvdata(pil->dev);
+
+ ret = clk_prepare_enable(drv->smmu_iface);
+ if (ret)
+ goto err_smmu;
+ ret = clk_prepare_enable(drv->core);
+ if (ret)
+ goto err_core;
+ ret = pas_auth_and_reset(PAS_VIDC);
+
+ clk_disable_unprepare(drv->core);
+err_core:
+ clk_disable_unprepare(drv->smmu_iface);
+err_smmu:
+ return ret;
+}
+
+static int pil_vidc_shutdown(struct pil_desc *pil)
+{
+ return pas_shutdown(PAS_VIDC);
+}
+
+static struct pil_reset_ops pil_vidc_ops = {
+ .init_image = pil_vidc_init_image,
+ .auth_and_reset = pil_vidc_reset,
+ .shutdown = pil_vidc_shutdown,
+};
+
+static int __devinit pil_vidc_driver_probe(struct platform_device *pdev)
+{
+ struct pil_desc *desc;
+ struct vidc_data *drv;
+ int ret;
+
+ if (pas_supported(PAS_VIDC) < 0)
+ return -ENOSYS;
+
+ desc = devm_kzalloc(&pdev->dev, sizeof(*desc), GFP_KERNEL);
+ if (!desc)
+ return -ENOMEM;
+
+ drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL);
+ if (!drv)
+ return -ENOMEM;
+ platform_set_drvdata(pdev, drv);
+ drv->smmu_iface = clk_get(&pdev->dev, "smmu_iface_clk");
+ if (IS_ERR(drv->smmu_iface)) {
+ dev_err(&pdev->dev, "failed to get smmu interface clock\n");
+ ret = PTR_ERR(drv->smmu_iface);
+ goto err_smmu;
+ }
+ drv->core = clk_get(&pdev->dev, "core_clk");
+ if (IS_ERR(drv->core)) {
+ dev_err(&pdev->dev, "failed to get core clock\n");
+ ret = PTR_ERR(drv->core);
+ goto err_core;
+ }
+
+ desc->name = "vidc";
+ desc->dev = &pdev->dev;
+ desc->ops = &pil_vidc_ops;
+ desc->owner = THIS_MODULE;
+ drv->pil = msm_pil_register(desc);
+ if (IS_ERR(drv->pil)) {
+ ret = PTR_ERR(drv->pil);
+ goto err_register;
+ }
+ return 0;
+
+err_register:
+ clk_put(drv->core);
+err_core:
+ clk_put(drv->smmu_iface);
+err_smmu:
+ return ret;
+}
+
+static int __devexit pil_vidc_driver_exit(struct platform_device *pdev)
+{
+ struct vidc_data *drv = platform_get_drvdata(pdev);
+ msm_pil_unregister(drv->pil);
+ clk_put(drv->smmu_iface);
+ clk_put(drv->core);
+ return 0;
+}
+
+static struct platform_driver pil_vidc_driver = {
+ .probe = pil_vidc_driver_probe,
+ .remove = __devexit_p(pil_vidc_driver_exit),
+ .driver = {
+ .name = "pil_vidc",
+ .owner = THIS_MODULE,
+ },
+};
+
+static int __init pil_vidc_init(void)
+{
+ return platform_driver_register(&pil_vidc_driver);
+}
+module_init(pil_vidc_init);
+
+static void __exit pil_vidc_exit(void)
+{
+ platform_driver_unregister(&pil_vidc_driver);
+}
+module_exit(pil_vidc_exit);
+
+MODULE_DESCRIPTION("Support for secure booting vidc images");
+MODULE_LICENSE("GPL v2");
diff --git a/arch/arm/mach-msm/scm-pas.h b/arch/arm/mach-msm/scm-pas.h
index 3651ee1..2fe71a9 100644
--- a/arch/arm/mach-msm/scm-pas.h
+++ b/arch/arm/mach-msm/scm-pas.h
@@ -22,6 +22,7 @@
PAS_RIVA,
PAS_SECAPP,
PAS_GSS,
+ PAS_VIDC,
};
extern int pas_init_image(enum pas_id id, const u8 *metadata, size_t size);