Jeenu Viswambharan | 1814a3e | 2014-02-28 10:08:33 +0000 | [diff] [blame] | 1 | /* |
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 2 | * Copyright (c) 2014-2016, ARM Limited and Contributors. All rights reserved. |
Jeenu Viswambharan | 1814a3e | 2014-02-28 10:08:33 +0000 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of ARM nor the names of its contributors may be used |
| 15 | * to endorse or promote products derived from this software without specific |
| 16 | * prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
Soby Mathew | 8da8966 | 2016-09-19 17:21:15 +0100 | [diff] [blame] | 31 | #include <assert.h> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 32 | #include <debug.h> |
| 33 | #include <psci.h> |
Jeenu Viswambharan | 1814a3e | 2014-02-28 10:08:33 +0000 | [diff] [blame] | 34 | #include <runtime_svc.h> |
Soby Mathew | d019487 | 2016-04-29 19:01:30 +0100 | [diff] [blame] | 35 | #include <smcc_helpers.h> |
Jeenu Viswambharan | 1814a3e | 2014-02-28 10:08:33 +0000 | [diff] [blame] | 36 | #include <std_svc.h> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 37 | #include <stdint.h> |
| 38 | #include <uuid.h> |
Jeenu Viswambharan | 1814a3e | 2014-02-28 10:08:33 +0000 | [diff] [blame] | 39 | |
| 40 | /* Standard Service UUID */ |
| 41 | DEFINE_SVC_UUID(arm_svc_uid, |
| 42 | 0x108d905b, 0xf863, 0x47e8, 0xae, 0x2d, |
| 43 | 0xc0, 0xfb, 0x56, 0x41, 0xf6, 0xe2); |
| 44 | |
Soby Mathew | 8da8966 | 2016-09-19 17:21:15 +0100 | [diff] [blame] | 45 | /* Setup Standard Services */ |
| 46 | static int32_t std_svc_setup(void) |
| 47 | { |
| 48 | uintptr_t svc_arg; |
| 49 | |
| 50 | svc_arg = get_arm_std_svc_args(PSCI_FID_MASK); |
| 51 | assert(svc_arg); |
| 52 | |
| 53 | /* |
| 54 | * PSCI is the only specification implemented as a Standard Service. |
| 55 | * The `psci_setup()` also does EL3 architectural setup. |
| 56 | */ |
| 57 | return psci_setup((const psci_lib_args_t *)svc_arg); |
| 58 | } |
| 59 | |
Jeenu Viswambharan | 1814a3e | 2014-02-28 10:08:33 +0000 | [diff] [blame] | 60 | /* |
| 61 | * Top-level Standard Service SMC handler. This handler will in turn dispatch |
| 62 | * calls to PSCI SMC handler |
| 63 | */ |
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 64 | uintptr_t std_svc_smc_handler(uint32_t smc_fid, |
| 65 | u_register_t x1, |
| 66 | u_register_t x2, |
| 67 | u_register_t x3, |
| 68 | u_register_t x4, |
Jeenu Viswambharan | 1814a3e | 2014-02-28 10:08:33 +0000 | [diff] [blame] | 69 | void *cookie, |
| 70 | void *handle, |
Soby Mathew | a0fedc4 | 2016-06-16 14:52:04 +0100 | [diff] [blame] | 71 | u_register_t flags) |
Jeenu Viswambharan | 1814a3e | 2014-02-28 10:08:33 +0000 | [diff] [blame] | 72 | { |
| 73 | /* |
| 74 | * Dispatch PSCI calls to PSCI SMC handler and return its return |
| 75 | * value |
| 76 | */ |
| 77 | if (is_psci_fid(smc_fid)) { |
Soby Mathew | d019487 | 2016-04-29 19:01:30 +0100 | [diff] [blame] | 78 | SMC_RET1(handle, |
| 79 | psci_smc_handler(smc_fid, x1, x2, x3, x4, |
| 80 | cookie, handle, flags)); |
Jeenu Viswambharan | 1814a3e | 2014-02-28 10:08:33 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | switch (smc_fid) { |
| 84 | case ARM_STD_SVC_CALL_COUNT: |
| 85 | /* |
| 86 | * Return the number of Standard Service Calls. PSCI is the only |
| 87 | * standard service implemented; so return number of PSCI calls |
| 88 | */ |
| 89 | SMC_RET1(handle, PSCI_NUM_CALLS); |
| 90 | |
| 91 | case ARM_STD_SVC_UID: |
| 92 | /* Return UID to the caller */ |
| 93 | SMC_UUID_RET(handle, arm_svc_uid); |
| 94 | |
| 95 | case ARM_STD_SVC_VERSION: |
| 96 | /* Return the version of current implementation */ |
| 97 | SMC_RET2(handle, STD_SVC_VERSION_MAJOR, STD_SVC_VERSION_MINOR); |
| 98 | |
| 99 | default: |
| 100 | WARN("Unimplemented Standard Service Call: 0x%x \n", smc_fid); |
| 101 | SMC_RET1(handle, SMC_UNK); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | /* Register Standard Service Calls as runtime service */ |
| 106 | DECLARE_RT_SVC( |
| 107 | std_svc, |
| 108 | |
| 109 | OEN_STD_START, |
| 110 | OEN_STD_END, |
| 111 | SMC_TYPE_FAST, |
Soby Mathew | 8da8966 | 2016-09-19 17:21:15 +0100 | [diff] [blame] | 112 | std_svc_setup, |
Jeenu Viswambharan | 1814a3e | 2014-02-28 10:08:33 +0000 | [diff] [blame] | 113 | std_svc_smc_handler |
| 114 | ); |