| Duy Truong | e833aca | 2013-02-12 13:35:08 -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> | 
|  | 16 | #include <linux/elf.h> | 
|  | 17 | #include <linux/err.h> | 
|  | 18 |  | 
|  | 19 | #include "peripheral-loader.h" | 
|  | 20 | #include "scm-pas.h" | 
|  | 21 |  | 
| Stephen Boyd | d89eebe | 2011-09-28 23:28:11 -0700 | [diff] [blame] | 22 | static int pil_tzapps_init_image(struct pil_desc *pil, const u8 *metadata, | 
|  | 23 | size_t size) | 
|  | 24 | { | 
|  | 25 | return pas_init_image(PAS_TZAPPS, metadata, size); | 
|  | 26 | } | 
|  | 27 |  | 
|  | 28 | static int pil_tzapps_reset(struct pil_desc *pil) | 
|  | 29 | { | 
|  | 30 | return pas_auth_and_reset(PAS_TZAPPS); | 
|  | 31 | } | 
|  | 32 |  | 
|  | 33 | static int pil_tzapps_shutdown(struct pil_desc *pil) | 
|  | 34 | { | 
|  | 35 | return pas_shutdown(PAS_TZAPPS); | 
|  | 36 | } | 
|  | 37 |  | 
|  | 38 | static struct pil_reset_ops pil_tzapps_ops = { | 
|  | 39 | .init_image = pil_tzapps_init_image, | 
| Stephen Boyd | d89eebe | 2011-09-28 23:28:11 -0700 | [diff] [blame] | 40 | .auth_and_reset = pil_tzapps_reset, | 
|  | 41 | .shutdown = pil_tzapps_shutdown, | 
|  | 42 | }; | 
|  | 43 |  | 
|  | 44 | static int __devinit pil_tzapps_driver_probe(struct platform_device *pdev) | 
|  | 45 | { | 
|  | 46 | struct pil_desc *desc; | 
| Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 47 | struct pil_device *pil; | 
| Stephen Boyd | d89eebe | 2011-09-28 23:28:11 -0700 | [diff] [blame] | 48 |  | 
|  | 49 | if (pas_supported(PAS_TZAPPS) < 0) | 
|  | 50 | return -ENOSYS; | 
|  | 51 |  | 
|  | 52 | desc = devm_kzalloc(&pdev->dev, sizeof(*desc), GFP_KERNEL); | 
|  | 53 | if (!desc) | 
|  | 54 | return -ENOMEM; | 
|  | 55 |  | 
|  | 56 | desc->name = "tzapps"; | 
|  | 57 | desc->dev = &pdev->dev; | 
|  | 58 | desc->ops = &pil_tzapps_ops; | 
| Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 59 | desc->owner = THIS_MODULE; | 
|  | 60 | pil = msm_pil_register(desc); | 
|  | 61 | if (IS_ERR(pil)) | 
|  | 62 | return PTR_ERR(pil); | 
|  | 63 | platform_set_drvdata(pdev, pil); | 
| Stephen Boyd | d89eebe | 2011-09-28 23:28:11 -0700 | [diff] [blame] | 64 | return 0; | 
|  | 65 | } | 
|  | 66 |  | 
|  | 67 | static int __devexit pil_tzapps_driver_exit(struct platform_device *pdev) | 
|  | 68 | { | 
| Stephen Boyd | 6d67d25 | 2011-09-27 11:50:05 -0700 | [diff] [blame] | 69 | struct pil_device *pil = platform_get_drvdata(pdev); | 
|  | 70 | msm_pil_unregister(pil); | 
| Stephen Boyd | d89eebe | 2011-09-28 23:28:11 -0700 | [diff] [blame] | 71 | return 0; | 
|  | 72 | } | 
|  | 73 |  | 
|  | 74 | static struct platform_driver pil_tzapps_driver = { | 
|  | 75 | .probe = pil_tzapps_driver_probe, | 
|  | 76 | .remove = __devexit_p(pil_tzapps_driver_exit), | 
|  | 77 | .driver = { | 
|  | 78 | .name = "pil_tzapps", | 
|  | 79 | .owner = THIS_MODULE, | 
|  | 80 | }, | 
|  | 81 | }; | 
|  | 82 |  | 
|  | 83 | static int __init pil_tzapps_init(void) | 
|  | 84 | { | 
|  | 85 | return platform_driver_register(&pil_tzapps_driver); | 
|  | 86 | } | 
|  | 87 | module_init(pil_tzapps_init); | 
|  | 88 |  | 
|  | 89 | static void __exit pil_tzapps_exit(void) | 
|  | 90 | { | 
|  | 91 | platform_driver_unregister(&pil_tzapps_driver); | 
|  | 92 | } | 
|  | 93 | module_exit(pil_tzapps_exit); | 
|  | 94 |  | 
|  | 95 | MODULE_DESCRIPTION("Support for booting TZApps images"); | 
|  | 96 | MODULE_LICENSE("GPL v2"); |