1960e65d2SAdrian Chadd /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3960e65d2SAdrian Chadd * 4960e65d2SAdrian Chadd * Copyright (c) 2021 Adrian Chadd <adrian@FreeBSD.org> 5960e65d2SAdrian Chadd * 6960e65d2SAdrian Chadd * Redistribution and use in source and binary forms, with or without 7960e65d2SAdrian Chadd * modification, are permitted provided that the following conditions 8960e65d2SAdrian Chadd * are met: 9960e65d2SAdrian Chadd * 1. Redistributions of source code must retain the above copyright 10960e65d2SAdrian Chadd * notice, this list of conditions and the following disclaimer. 11960e65d2SAdrian Chadd * 2. Redistributions in binary form must reproduce the above copyright 12960e65d2SAdrian Chadd * notice, this list of conditions and the following disclaimer in the 13960e65d2SAdrian Chadd * documentation and/or other materials provided with the distribution. 14960e65d2SAdrian Chadd * 15960e65d2SAdrian Chadd * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16960e65d2SAdrian Chadd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17960e65d2SAdrian Chadd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18960e65d2SAdrian Chadd * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19960e65d2SAdrian Chadd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20960e65d2SAdrian Chadd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21960e65d2SAdrian Chadd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22960e65d2SAdrian Chadd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23960e65d2SAdrian Chadd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24960e65d2SAdrian Chadd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25960e65d2SAdrian Chadd * SUCH DAMAGE. 26960e65d2SAdrian Chadd */ 27960e65d2SAdrian Chadd 28960e65d2SAdrian Chadd #ifndef __QCOM_SCM_LEGACY_DEFS_H__ 29960e65d2SAdrian Chadd #define __QCOM_SCM_LEGACY_DEFS_H__ 30960e65d2SAdrian Chadd 31960e65d2SAdrian Chadd /* 32960e65d2SAdrian Chadd * These definitions are specific to the 32 bit legacy SCM interface 33960e65d2SAdrian Chadd * used by the IPQ806x and IPQ401x SoCs. 34960e65d2SAdrian Chadd */ 35960e65d2SAdrian Chadd 36960e65d2SAdrian Chadd /* 37960e65d2SAdrian Chadd * Mapping of the SCM service/command fields into the a0 argument 38960e65d2SAdrian Chadd * in an SMC instruction call. 39960e65d2SAdrian Chadd * 40960e65d2SAdrian Chadd * This is particular to the legacy SCM interface, and is not the 41960e65d2SAdrian Chadd * same as the non-legacy 32/64 bit FNID mapping layout. 42960e65d2SAdrian Chadd */ 43960e65d2SAdrian Chadd #define QCOM_SCM_LEGACY_SMC_FNID(s, c) (((s) << 10) | ((c) & 0x3ff)) 44960e65d2SAdrian Chadd 45960e65d2SAdrian Chadd /* 46960e65d2SAdrian Chadd * There are two kinds of SCM calls in this legacy path. 47960e65d2SAdrian Chadd * 48960e65d2SAdrian Chadd * The first kind are the normal ones - up to a defined max of arguments, 49960e65d2SAdrian Chadd * a defined max of responses and some identifiers for all of it. 50960e65d2SAdrian Chadd * They can be issues in parallel on different cores, can be interrupted, 51960e65d2SAdrian Chadd * etc. 52960e65d2SAdrian Chadd * 53960e65d2SAdrian Chadd * The second kind are what are termed "atomic" SCM calls - 54960e65d2SAdrian Chadd * up to 5 argument DWORDs, up to 3 response DWORDs, done atomically, 55960e65d2SAdrian Chadd * not interruptable/parallel. 56960e65d2SAdrian Chadd * 57960e65d2SAdrian Chadd * The former use the structures below to represent the request and response 58960e65d2SAdrian Chadd * in memory. The latter use defines and a direct SMC call with the 59960e65d2SAdrian Chadd * arguments in registers. 60960e65d2SAdrian Chadd */ 61960e65d2SAdrian Chadd 62960e65d2SAdrian Chadd struct qcom_scm_legacy_smc_args { 63960e65d2SAdrian Chadd uint32_t args[8]; 64960e65d2SAdrian Chadd }; 65960e65d2SAdrian Chadd 66960e65d2SAdrian Chadd /* 67960e65d2SAdrian Chadd * Atomic SCM call command/response buffer definitions. 68960e65d2SAdrian Chadd */ 69960e65d2SAdrian Chadd #define QCOM_SCM_LEGACY_ATOMIC_MAX_ARGCOUNT 5 70960e65d2SAdrian Chadd #define QCOM_SCM_LEGACY_CLASS_REGISTER (0x2 << 8) 71960e65d2SAdrian Chadd #define QCOM_SCM_LEGACY_MASK_IRQS (1U << 5) 72960e65d2SAdrian Chadd 73960e65d2SAdrian Chadd /* 74960e65d2SAdrian Chadd * Mapping an SCM service/command/argcount into the a0 register 75960e65d2SAdrian Chadd * for an SMC instruction call. 76960e65d2SAdrian Chadd */ 77960e65d2SAdrian Chadd #define QCOM_SCM_LEGACY_ATOMIC_ID(svc, cmd, n) \ 78960e65d2SAdrian Chadd ((QCOM_SCM_LEGACY_SMC_FNID((svc), cmd) << 12) | \ 79960e65d2SAdrian Chadd QCOM_SCM_LEGACY_CLASS_REGISTER | \ 80960e65d2SAdrian Chadd QCOM_SCM_LEGACY_MASK_IRQS | \ 81960e65d2SAdrian Chadd ((n) & 0xf)) 82960e65d2SAdrian Chadd 83960e65d2SAdrian Chadd /* 84960e65d2SAdrian Chadd * Legacy command/response buffer definitions. 85960e65d2SAdrian Chadd * 86960e65d2SAdrian Chadd * The legacy path contains up to the defined maximum arguments 87960e65d2SAdrian Chadd * but only a single command/response pair per call. 88960e65d2SAdrian Chadd * 89960e65d2SAdrian Chadd * A command and response buffer is laid out in memory as such: 90960e65d2SAdrian Chadd * 91960e65d2SAdrian Chadd * | command header | 92960e65d2SAdrian Chadd * | (buffer payload) | 93960e65d2SAdrian Chadd * | response header | 94960e65d2SAdrian Chadd * | (response payload) | 95960e65d2SAdrian Chadd */ 96960e65d2SAdrian Chadd 97960e65d2SAdrian Chadd /* 98960e65d2SAdrian Chadd * The command header. 99960e65d2SAdrian Chadd * 100960e65d2SAdrian Chadd * len - the length of the total command and response, including 101960e65d2SAdrian Chadd * the headers. 102960e65d2SAdrian Chadd * 103960e65d2SAdrian Chadd * buf_offset - the offset inside the buffer, starting at the 104960e65d2SAdrian Chadd * beginning of this command header, where the command buffer 105960e65d2SAdrian Chadd * is found. The end is the byte before the response_header_offset. 106960e65d2SAdrian Chadd * 107960e65d2SAdrian Chadd * response_header_offset - the offset inside the buffer where 108960e65d2SAdrian Chadd * the response header is found. 109960e65d2SAdrian Chadd * 110960e65d2SAdrian Chadd * id - the QCOM_SCM_LEGACY_SMC_FNID() - service/command ids 111960e65d2SAdrian Chadd */ 112960e65d2SAdrian Chadd struct qcom_scm_legacy_command_header { 113960e65d2SAdrian Chadd uint32_t len; 114960e65d2SAdrian Chadd uint32_t buf_offset; 115960e65d2SAdrian Chadd uint32_t response_header_offset; 116960e65d2SAdrian Chadd uint32_t id; 117960e65d2SAdrian Chadd }; 118960e65d2SAdrian Chadd 119960e65d2SAdrian Chadd /* 120960e65d2SAdrian Chadd * The response header. 121960e65d2SAdrian Chadd * 122960e65d2SAdrian Chadd * This is found immediately after the command header and command 123960e65d2SAdrian Chadd * buffer payload. 124960e65d2SAdrian Chadd * 125960e65d2SAdrian Chadd * len - the total amount of memory available for the response. 126960e65d2SAdrian Chadd * Linux doesn't set this; it always passes in a response 127960e65d2SAdrian Chadd * buffer large enough to store MAX_QCOM_SCM_RETS * DWORD 128960e65d2SAdrian Chadd * bytes. 129960e65d2SAdrian Chadd * 130960e65d2SAdrian Chadd * It's also possible this is set by the firmware. 131960e65d2SAdrian Chadd * 132960e65d2SAdrian Chadd * buf_offset - start of response buffer, relative to the beginning 133960e65d2SAdrian Chadd * of the command header. This also isn't set in Linux before 134960e65d2SAdrian Chadd * calling the SMC instruction, but it is checked afterwards 135960e65d2SAdrian Chadd * to assemble a pointer to the response data. The firmware 136960e65d2SAdrian Chadd * likely sets this. 137960e65d2SAdrian Chadd * 138960e65d2SAdrian Chadd * is_complete - true if complete. Linux loops over DMA sync to 139960e65d2SAdrian Chadd * check if this is complete even after the SMC call returns. 140960e65d2SAdrian Chadd */ 141960e65d2SAdrian Chadd struct qcom_scm_legacy_response_header { 142960e65d2SAdrian Chadd uint32_t len; 143960e65d2SAdrian Chadd uint32_t buf_offset; 144960e65d2SAdrian Chadd uint32_t is_complete; 145960e65d2SAdrian Chadd }; 146960e65d2SAdrian Chadd 147960e65d2SAdrian Chadd #endif /* __QCOM_SCM_LEGACY_DEFS_H__ */ 148