Yatharth Kochar | 9518d02 | 2016-03-11 14:20:19 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved. |
| 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 | #include <assert.h> |
| 31 | #include <debug.h> |
| 32 | #include <platform.h> |
| 33 | #include <pmf.h> |
| 34 | #include <smcc_helpers.h> |
| 35 | |
| 36 | /* |
| 37 | * This function is responsible for handling all PMF SMC calls. |
| 38 | */ |
| 39 | uintptr_t pmf_smc_handler(unsigned int smc_fid, |
| 40 | u_register_t x1, |
| 41 | u_register_t x2, |
| 42 | u_register_t x3, |
| 43 | u_register_t x4, |
| 44 | void *cookie, |
| 45 | void *handle, |
| 46 | u_register_t flags) |
| 47 | { |
| 48 | int rc; |
| 49 | unsigned long long ts_value; |
| 50 | |
| 51 | if (((smc_fid >> FUNCID_CC_SHIFT) & FUNCID_CC_MASK) == SMC_32) { |
| 52 | |
| 53 | x1 = (uint32_t)x1; |
| 54 | x2 = (uint32_t)x2; |
| 55 | x3 = (uint32_t)x3; |
| 56 | |
| 57 | switch (smc_fid) { |
| 58 | case PMF_SMC_GET_TIMESTAMP_32: |
| 59 | /* |
| 60 | * Return error code and the captured |
| 61 | * time-stamp to the caller. |
| 62 | * x0 --> error code. |
| 63 | * x1 - x2 --> time-stamp value. |
| 64 | */ |
| 65 | rc = pmf_get_timestamp_smc(x1, x2, x3, &ts_value); |
| 66 | SMC_RET3(handle, rc, (uint32_t)ts_value, |
| 67 | (uint32_t)(ts_value >> 32)); |
| 68 | |
| 69 | default: |
| 70 | break; |
| 71 | } |
| 72 | } else { |
| 73 | switch (smc_fid) { |
| 74 | case PMF_SMC_GET_TIMESTAMP_64: |
| 75 | /* |
| 76 | * Return error code and the captured |
| 77 | * time-stamp to the caller. |
| 78 | * x0 --> error code. |
| 79 | * x1 --> time-stamp value. |
| 80 | */ |
| 81 | rc = pmf_get_timestamp_smc(x1, x2, x3, &ts_value); |
| 82 | SMC_RET2(handle, rc, ts_value); |
| 83 | |
| 84 | default: |
| 85 | break; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | WARN("Unimplemented PMF Call: 0x%x \n", smc_fid); |
| 90 | SMC_RET1(handle, SMC_UNK); |
| 91 | } |