blob: 5bbffd343661f2cf39e358dd0cdabc9211b2478c [file] [log] [blame]
Stephen Boyde44ec392011-08-29 12:03:24 -07001/* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
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/module.h>
14#include <linux/slab.h>
15#include <linux/string.h>
16
17#include <mach/scm.h>
18#include <mach/socinfo.h>
19#include "scm-pas.h"
20
21#define PAS_INIT_IMAGE_CMD 1
22#define PAS_AUTH_AND_RESET_CMD 5
23#define PAS_SHUTDOWN_CMD 6
24#define PAS_IS_SUPPORTED_CMD 7
25
26int pas_init_image(enum pas_id id, const u8 *metadata, size_t size)
27{
28 int ret;
29 struct pas_init_image_req {
30 u32 proc;
31 u32 image_addr;
32 } request;
33 u32 scm_ret = 0;
34 /* Make memory physically contiguous */
35 void *mdata_buf = kmemdup(metadata, size, GFP_KERNEL);
36
37 if (!mdata_buf)
38 return -ENOMEM;
39
40 request.proc = id;
41 request.image_addr = virt_to_phys(mdata_buf);
42
43 ret = scm_call(SCM_SVC_PIL, PAS_INIT_IMAGE_CMD, &request,
44 sizeof(request), &scm_ret, sizeof(scm_ret));
45 kfree(mdata_buf);
46
47 if (ret)
48 return ret;
49 return scm_ret;
50}
51EXPORT_SYMBOL(pas_init_image);
52
53int pas_auth_and_reset(enum pas_id id)
54{
55 int ret;
56 u32 proc = id, scm_ret = 0;
57
58 ret = scm_call(SCM_SVC_PIL, PAS_AUTH_AND_RESET_CMD, &proc,
59 sizeof(proc), &scm_ret, sizeof(scm_ret));
60 if (ret)
61 return ret;
62
63 return scm_ret;
64}
65EXPORT_SYMBOL(pas_auth_and_reset);
66
67int pas_shutdown(enum pas_id id)
68{
69 int ret;
70 u32 proc = id, scm_ret = 0;
71
72 ret = scm_call(SCM_SVC_PIL, PAS_SHUTDOWN_CMD, &proc, sizeof(proc),
73 &scm_ret, sizeof(scm_ret));
74 if (ret)
75 return ret;
76
77 return scm_ret;
78}
79EXPORT_SYMBOL(pas_shutdown);
80
81static bool secure_pil = true;
82module_param(secure_pil, bool, S_IRUGO);
83MODULE_PARM_DESC(secure_pil, "Use secure PIL");
84
85int pas_supported(enum pas_id id)
86{
87 int ret;
88 u32 periph = id, ret_val = 0;
89
90 if (!secure_pil)
91 return 0;
92
93 /*
94 * 8660 SCM doesn't support querying secure PIL support so just return
95 * true if not overridden on the command line.
96 */
97 if (cpu_is_msm8x60())
98 return 1;
99
100 if (scm_is_call_available(SCM_SVC_PIL, PAS_IS_SUPPORTED_CMD) <= 0)
101 return 0;
102
103 ret = scm_call(SCM_SVC_PIL, PAS_IS_SUPPORTED_CMD, &periph,
104 sizeof(periph), &ret_val, sizeof(ret_val));
105 if (ret)
106 return ret;
107
108 return ret_val;
109}
110EXPORT_SYMBOL(pas_supported);