1*a31d8983SYatharth Kochar /* 2*a31d8983SYatharth Kochar * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved. 3*a31d8983SYatharth Kochar * 4*a31d8983SYatharth Kochar * Redistribution and use in source and binary forms, with or without 5*a31d8983SYatharth Kochar * modification, are permitted provided that the following conditions are met: 6*a31d8983SYatharth Kochar * 7*a31d8983SYatharth Kochar * Redistributions of source code must retain the above copyright notice, this 8*a31d8983SYatharth Kochar * list of conditions and the following disclaimer. 9*a31d8983SYatharth Kochar * 10*a31d8983SYatharth Kochar * Redistributions in binary form must reproduce the above copyright notice, 11*a31d8983SYatharth Kochar * this list of conditions and the following disclaimer in the documentation 12*a31d8983SYatharth Kochar * and/or other materials provided with the distribution. 13*a31d8983SYatharth Kochar * 14*a31d8983SYatharth Kochar * Neither the name of ARM nor the names of its contributors may be used 15*a31d8983SYatharth Kochar * to endorse or promote products derived from this software without specific 16*a31d8983SYatharth Kochar * prior written permission. 17*a31d8983SYatharth Kochar * 18*a31d8983SYatharth Kochar * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19*a31d8983SYatharth Kochar * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20*a31d8983SYatharth Kochar * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21*a31d8983SYatharth Kochar * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22*a31d8983SYatharth Kochar * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23*a31d8983SYatharth Kochar * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24*a31d8983SYatharth Kochar * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25*a31d8983SYatharth Kochar * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26*a31d8983SYatharth Kochar * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27*a31d8983SYatharth Kochar * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28*a31d8983SYatharth Kochar * POSSIBILITY OF SUCH DAMAGE. 29*a31d8983SYatharth Kochar */ 30*a31d8983SYatharth Kochar #include <assert.h> 31*a31d8983SYatharth Kochar #include <debug.h> 32*a31d8983SYatharth Kochar #include <platform.h> 33*a31d8983SYatharth Kochar #include <pmf.h> 34*a31d8983SYatharth Kochar #include <smcc_helpers.h> 35*a31d8983SYatharth Kochar 36*a31d8983SYatharth Kochar /* 37*a31d8983SYatharth Kochar * This function is responsible for handling all PMF SMC calls. 38*a31d8983SYatharth Kochar */ 39*a31d8983SYatharth Kochar uintptr_t pmf_smc_handler(unsigned int smc_fid, 40*a31d8983SYatharth Kochar u_register_t x1, 41*a31d8983SYatharth Kochar u_register_t x2, 42*a31d8983SYatharth Kochar u_register_t x3, 43*a31d8983SYatharth Kochar u_register_t x4, 44*a31d8983SYatharth Kochar void *cookie, 45*a31d8983SYatharth Kochar void *handle, 46*a31d8983SYatharth Kochar u_register_t flags) 47*a31d8983SYatharth Kochar { 48*a31d8983SYatharth Kochar int rc; 49*a31d8983SYatharth Kochar unsigned long long ts_value; 50*a31d8983SYatharth Kochar 51*a31d8983SYatharth Kochar if (((smc_fid >> FUNCID_CC_SHIFT) & FUNCID_CC_MASK) == SMC_32) { 52*a31d8983SYatharth Kochar 53*a31d8983SYatharth Kochar x1 = (uint32_t)x1; 54*a31d8983SYatharth Kochar x2 = (uint32_t)x2; 55*a31d8983SYatharth Kochar x3 = (uint32_t)x3; 56*a31d8983SYatharth Kochar 57*a31d8983SYatharth Kochar switch (smc_fid) { 58*a31d8983SYatharth Kochar case PMF_SMC_GET_TIMESTAMP_32: 59*a31d8983SYatharth Kochar /* 60*a31d8983SYatharth Kochar * Return error code and the captured 61*a31d8983SYatharth Kochar * time-stamp to the caller. 62*a31d8983SYatharth Kochar * x0 --> error code. 63*a31d8983SYatharth Kochar * x1 - x2 --> time-stamp value. 64*a31d8983SYatharth Kochar */ 65*a31d8983SYatharth Kochar rc = pmf_get_timestamp_smc(x1, x2, x3, &ts_value); 66*a31d8983SYatharth Kochar SMC_RET3(handle, rc, (uint32_t)ts_value, 67*a31d8983SYatharth Kochar (uint32_t)(ts_value >> 32)); 68*a31d8983SYatharth Kochar 69*a31d8983SYatharth Kochar default: 70*a31d8983SYatharth Kochar break; 71*a31d8983SYatharth Kochar } 72*a31d8983SYatharth Kochar } else { 73*a31d8983SYatharth Kochar switch (smc_fid) { 74*a31d8983SYatharth Kochar case PMF_SMC_GET_TIMESTAMP_64: 75*a31d8983SYatharth Kochar /* 76*a31d8983SYatharth Kochar * Return error code and the captured 77*a31d8983SYatharth Kochar * time-stamp to the caller. 78*a31d8983SYatharth Kochar * x0 --> error code. 79*a31d8983SYatharth Kochar * x1 --> time-stamp value. 80*a31d8983SYatharth Kochar */ 81*a31d8983SYatharth Kochar rc = pmf_get_timestamp_smc(x1, x2, x3, &ts_value); 82*a31d8983SYatharth Kochar SMC_RET2(handle, rc, ts_value); 83*a31d8983SYatharth Kochar 84*a31d8983SYatharth Kochar default: 85*a31d8983SYatharth Kochar break; 86*a31d8983SYatharth Kochar } 87*a31d8983SYatharth Kochar } 88*a31d8983SYatharth Kochar 89*a31d8983SYatharth Kochar WARN("Unimplemented PMF Call: 0x%x \n", smc_fid); 90*a31d8983SYatharth Kochar SMC_RET1(handle, SMC_UNK); 91*a31d8983SYatharth Kochar } 92