Duy Truong | 790f06d | 2013-02-13 16:38:12 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2010-2012, The Linux Foundation. All rights reserved. |
Stephen Boyd | d89eebe | 2011-09-28 23:28:11 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/platform_device.h> |
Stephen Boyd | d89eebe | 2011-09-28 23:28:11 -0700 | [diff] [blame] | 16 | #include <linux/err.h> |
| 17 | |
Stephen Boyd | 046013f | 2012-06-28 20:24:17 -0700 | [diff] [blame] | 18 | #include <mach/subsystem_restart.h> |
| 19 | |
Stephen Boyd | d89eebe | 2011-09-28 23:28:11 -0700 | [diff] [blame] | 20 | #include "peripheral-loader.h" |
| 21 | #include "scm-pas.h" |
| 22 | |
Stephen Boyd | 046013f | 2012-06-28 20:24:17 -0700 | [diff] [blame] | 23 | struct tzapps_data { |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 24 | struct pil_desc pil_desc; |
Stephen Boyd | 046013f | 2012-06-28 20:24:17 -0700 | [diff] [blame] | 25 | struct subsys_device *subsys; |
| 26 | struct subsys_desc subsys_desc; |
| 27 | }; |
| 28 | |
Stephen Boyd | d89eebe | 2011-09-28 23:28:11 -0700 | [diff] [blame] | 29 | static int pil_tzapps_init_image(struct pil_desc *pil, const u8 *metadata, |
| 30 | size_t size) |
| 31 | { |
| 32 | return pas_init_image(PAS_TZAPPS, metadata, size); |
| 33 | } |
| 34 | |
| 35 | static int pil_tzapps_reset(struct pil_desc *pil) |
| 36 | { |
| 37 | return pas_auth_and_reset(PAS_TZAPPS); |
| 38 | } |
| 39 | |
| 40 | static int pil_tzapps_shutdown(struct pil_desc *pil) |
| 41 | { |
| 42 | return pas_shutdown(PAS_TZAPPS); |
| 43 | } |
| 44 | |
| 45 | static struct pil_reset_ops pil_tzapps_ops = { |
| 46 | .init_image = pil_tzapps_init_image, |
Stephen Boyd | d89eebe | 2011-09-28 23:28:11 -0700 | [diff] [blame] | 47 | .auth_and_reset = pil_tzapps_reset, |
| 48 | .shutdown = pil_tzapps_shutdown, |
| 49 | }; |
| 50 | |
Stephen Boyd | 046013f | 2012-06-28 20:24:17 -0700 | [diff] [blame] | 51 | #define subsys_to_drv(d) container_of(d, struct tzapps_data, subsys_desc) |
| 52 | |
| 53 | static int tzapps_start(const struct subsys_desc *desc) |
| 54 | { |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 55 | struct tzapps_data *drv = subsys_to_drv(desc); |
Stephen Boyd | 046013f | 2012-06-28 20:24:17 -0700 | [diff] [blame] | 56 | |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 57 | return pil_boot(&drv->pil_desc); |
Stephen Boyd | 046013f | 2012-06-28 20:24:17 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | static void tzapps_stop(const struct subsys_desc *desc) |
| 61 | { |
| 62 | struct tzapps_data *drv = subsys_to_drv(desc); |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 63 | pil_shutdown(&drv->pil_desc); |
Stephen Boyd | 046013f | 2012-06-28 20:24:17 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Stephen Boyd | d89eebe | 2011-09-28 23:28:11 -0700 | [diff] [blame] | 66 | static int __devinit pil_tzapps_driver_probe(struct platform_device *pdev) |
| 67 | { |
| 68 | struct pil_desc *desc; |
Stephen Boyd | 046013f | 2012-06-28 20:24:17 -0700 | [diff] [blame] | 69 | struct tzapps_data *drv; |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 70 | int ret; |
Stephen Boyd | d89eebe | 2011-09-28 23:28:11 -0700 | [diff] [blame] | 71 | |
| 72 | if (pas_supported(PAS_TZAPPS) < 0) |
| 73 | return -ENOSYS; |
| 74 | |
Stephen Boyd | 046013f | 2012-06-28 20:24:17 -0700 | [diff] [blame] | 75 | drv = devm_kzalloc(&pdev->dev, sizeof(*drv), GFP_KERNEL); |
| 76 | if (!drv) |
| 77 | return -ENOMEM; |
| 78 | platform_set_drvdata(pdev, drv); |
| 79 | |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 80 | desc = &drv->pil_desc; |
Stephen Boyd | d89eebe | 2011-09-28 23:28:11 -0700 | [diff] [blame] | 81 | desc->name = "tzapps"; |
| 82 | desc->dev = &pdev->dev; |
| 83 | desc->ops = &pil_tzapps_ops; |
Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 84 | desc->owner = THIS_MODULE; |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 85 | ret = pil_desc_init(desc); |
| 86 | if (ret) |
| 87 | return ret; |
Stephen Boyd | 046013f | 2012-06-28 20:24:17 -0700 | [diff] [blame] | 88 | |
| 89 | drv->subsys_desc.name = "tzapps"; |
| 90 | drv->subsys_desc.dev = &pdev->dev; |
| 91 | drv->subsys_desc.owner = THIS_MODULE; |
| 92 | drv->subsys_desc.start = tzapps_start; |
| 93 | drv->subsys_desc.stop = tzapps_stop; |
| 94 | |
| 95 | drv->subsys = subsys_register(&drv->subsys_desc); |
| 96 | if (IS_ERR(drv->subsys)) { |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 97 | pil_desc_release(desc); |
Stephen Boyd | 046013f | 2012-06-28 20:24:17 -0700 | [diff] [blame] | 98 | return PTR_ERR(drv->subsys); |
| 99 | } |
Stephen Boyd | d89eebe | 2011-09-28 23:28:11 -0700 | [diff] [blame] | 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | static int __devexit pil_tzapps_driver_exit(struct platform_device *pdev) |
| 104 | { |
Stephen Boyd | 046013f | 2012-06-28 20:24:17 -0700 | [diff] [blame] | 105 | struct tzapps_data *drv = platform_get_drvdata(pdev); |
| 106 | subsys_unregister(drv->subsys); |
Stephen Boyd | e83a0a2 | 2012-06-29 13:51:27 -0700 | [diff] [blame] | 107 | pil_desc_release(&drv->pil_desc); |
Stephen Boyd | d89eebe | 2011-09-28 23:28:11 -0700 | [diff] [blame] | 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | static struct platform_driver pil_tzapps_driver = { |
| 112 | .probe = pil_tzapps_driver_probe, |
| 113 | .remove = __devexit_p(pil_tzapps_driver_exit), |
| 114 | .driver = { |
| 115 | .name = "pil_tzapps", |
| 116 | .owner = THIS_MODULE, |
| 117 | }, |
| 118 | }; |
| 119 | |
| 120 | static int __init pil_tzapps_init(void) |
| 121 | { |
| 122 | return platform_driver_register(&pil_tzapps_driver); |
| 123 | } |
| 124 | module_init(pil_tzapps_init); |
| 125 | |
| 126 | static void __exit pil_tzapps_exit(void) |
| 127 | { |
| 128 | platform_driver_unregister(&pil_tzapps_driver); |
| 129 | } |
| 130 | module_exit(pil_tzapps_exit); |
| 131 | |
| 132 | MODULE_DESCRIPTION("Support for booting TZApps images"); |
| 133 | MODULE_LICENSE("GPL v2"); |