xref: /freebsd/sys/arm/qualcomm/qcom_scm_legacy_defs.h (revision 4d846d260e2b9a3d4d0a701462568268cbfe7a5b)
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  * $FreeBSD$
28960e65d2SAdrian Chadd  */
29960e65d2SAdrian Chadd 
30960e65d2SAdrian Chadd #ifndef	__QCOM_SCM_LEGACY_DEFS_H__
31960e65d2SAdrian Chadd #define	__QCOM_SCM_LEGACY_DEFS_H__
32960e65d2SAdrian Chadd 
33960e65d2SAdrian Chadd /*
34960e65d2SAdrian Chadd  * These definitions are specific to the 32 bit legacy SCM interface
35960e65d2SAdrian Chadd  * used by the IPQ806x and IPQ401x SoCs.
36960e65d2SAdrian Chadd  */
37960e65d2SAdrian Chadd 
38960e65d2SAdrian Chadd /*
39960e65d2SAdrian Chadd  * Mapping of the SCM service/command fields into the a0 argument
40960e65d2SAdrian Chadd  * in an SMC instruction call.
41960e65d2SAdrian Chadd  *
42960e65d2SAdrian Chadd  * This is particular to the legacy SCM interface, and is not the
43960e65d2SAdrian Chadd  * same as the non-legacy 32/64 bit FNID mapping layout.
44960e65d2SAdrian Chadd  */
45960e65d2SAdrian Chadd #define	QCOM_SCM_LEGACY_SMC_FNID(s, c)		(((s) << 10) | ((c) & 0x3ff))
46960e65d2SAdrian Chadd 
47960e65d2SAdrian Chadd /*
48960e65d2SAdrian Chadd  * There are two kinds of SCM calls in this legacy path.
49960e65d2SAdrian Chadd  *
50960e65d2SAdrian Chadd  * The first kind are the normal ones - up to a defined max of arguments,
51960e65d2SAdrian Chadd  * a defined max of responses and some identifiers for all of it.
52960e65d2SAdrian Chadd  * They can be issues in parallel on different cores, can be interrupted,
53960e65d2SAdrian Chadd  * etc.
54960e65d2SAdrian Chadd  *
55960e65d2SAdrian Chadd  * The second kind are what are termed "atomic" SCM calls -
56960e65d2SAdrian Chadd  * up to 5 argument DWORDs, up to 3 response DWORDs, done atomically,
57960e65d2SAdrian Chadd  * not interruptable/parallel.
58960e65d2SAdrian Chadd  *
59960e65d2SAdrian Chadd  * The former use the structures below to represent the request and response
60960e65d2SAdrian Chadd  * in memory.  The latter use defines and a direct SMC call with the
61960e65d2SAdrian Chadd  * arguments in registers.
62960e65d2SAdrian Chadd  */
63960e65d2SAdrian Chadd 
64960e65d2SAdrian Chadd struct qcom_scm_legacy_smc_args {
65960e65d2SAdrian Chadd 	uint32_t args[8];
66960e65d2SAdrian Chadd };
67960e65d2SAdrian Chadd 
68960e65d2SAdrian Chadd /*
69960e65d2SAdrian Chadd  * Atomic SCM call command/response buffer definitions.
70960e65d2SAdrian Chadd  */
71960e65d2SAdrian Chadd #define	QCOM_SCM_LEGACY_ATOMIC_MAX_ARGCOUNT		5
72960e65d2SAdrian Chadd #define	QCOM_SCM_LEGACY_CLASS_REGISTER			(0x2 << 8)
73960e65d2SAdrian Chadd #define	QCOM_SCM_LEGACY_MASK_IRQS			(1U << 5)
74960e65d2SAdrian Chadd 
75960e65d2SAdrian Chadd /*
76960e65d2SAdrian Chadd  * Mapping an SCM service/command/argcount into the a0 register
77960e65d2SAdrian Chadd  * for an SMC instruction call.
78960e65d2SAdrian Chadd  */
79960e65d2SAdrian Chadd #define	QCOM_SCM_LEGACY_ATOMIC_ID(svc, cmd, n) \
80960e65d2SAdrian Chadd 	    ((QCOM_SCM_LEGACY_SMC_FNID((svc), cmd) << 12) | \
81960e65d2SAdrian Chadd 	    QCOM_SCM_LEGACY_CLASS_REGISTER | \
82960e65d2SAdrian Chadd 	    QCOM_SCM_LEGACY_MASK_IRQS | \
83960e65d2SAdrian Chadd 	    ((n) & 0xf))
84960e65d2SAdrian Chadd 
85960e65d2SAdrian Chadd /*
86960e65d2SAdrian Chadd  * Legacy command/response buffer definitions.
87960e65d2SAdrian Chadd  *
88960e65d2SAdrian Chadd  * The legacy path contains up to the defined maximum arguments
89960e65d2SAdrian Chadd  * but only a single command/response pair per call.
90960e65d2SAdrian Chadd  *
91960e65d2SAdrian Chadd  * A command and response buffer is laid out in memory as such:
92960e65d2SAdrian Chadd  *
93960e65d2SAdrian Chadd  * | command header     |
94960e65d2SAdrian Chadd  * | (buffer payload)   |
95960e65d2SAdrian Chadd  * | response header    |
96960e65d2SAdrian Chadd  * | (response payload) |
97960e65d2SAdrian Chadd  */
98960e65d2SAdrian Chadd 
99960e65d2SAdrian Chadd /*
100960e65d2SAdrian Chadd  * The command header.
101960e65d2SAdrian Chadd  *
102960e65d2SAdrian Chadd  * len - the length of the total command and response, including
103960e65d2SAdrian Chadd  *       the headers.
104960e65d2SAdrian Chadd  *
105960e65d2SAdrian Chadd  * buf_offset - the offset inside the buffer, starting at the
106960e65d2SAdrian Chadd  *       beginning of this command header, where the command buffer
107960e65d2SAdrian Chadd  *       is found.  The end is the byte before the response_header_offset.
108960e65d2SAdrian Chadd  *
109960e65d2SAdrian Chadd  * response_header_offset - the offset inside the buffer where
110960e65d2SAdrian Chadd  *       the response header is found.
111960e65d2SAdrian Chadd  *
112960e65d2SAdrian Chadd  * id - the QCOM_SCM_LEGACY_SMC_FNID() - service/command ids
113960e65d2SAdrian Chadd  */
114960e65d2SAdrian Chadd struct qcom_scm_legacy_command_header {
115960e65d2SAdrian Chadd 	uint32_t len;
116960e65d2SAdrian Chadd 	uint32_t buf_offset;
117960e65d2SAdrian Chadd 	uint32_t response_header_offset;
118960e65d2SAdrian Chadd 	uint32_t id;
119960e65d2SAdrian Chadd };
120960e65d2SAdrian Chadd 
121960e65d2SAdrian Chadd /*
122960e65d2SAdrian Chadd  * The response header.
123960e65d2SAdrian Chadd  *
124960e65d2SAdrian Chadd  * This is found immediately after the command header and command
125960e65d2SAdrian Chadd  * buffer payload.
126960e65d2SAdrian Chadd  *
127960e65d2SAdrian Chadd  * len - the total amount of memory available for the response.
128960e65d2SAdrian Chadd  *       Linux doesn't set this; it always passes in a response
129960e65d2SAdrian Chadd  *       buffer large enough to store MAX_QCOM_SCM_RETS * DWORD
130960e65d2SAdrian Chadd  *       bytes.
131960e65d2SAdrian Chadd  *
132960e65d2SAdrian Chadd  *       It's also possible this is set by the firmware.
133960e65d2SAdrian Chadd  *
134960e65d2SAdrian Chadd  * buf_offset - start of response buffer, relative to the beginning
135960e65d2SAdrian Chadd  *       of the command header.  This also isn't set in Linux before
136960e65d2SAdrian Chadd  *       calling the SMC instruction, but it is checked afterwards
137960e65d2SAdrian Chadd  *       to assemble a pointer to the response data.  The firmware
138960e65d2SAdrian Chadd  *       likely sets this.
139960e65d2SAdrian Chadd  *
140960e65d2SAdrian Chadd  * is_complete - true if complete.  Linux loops over DMA sync to
141960e65d2SAdrian Chadd  *       check if this is complete even after the SMC call returns.
142960e65d2SAdrian Chadd  */
143960e65d2SAdrian Chadd struct qcom_scm_legacy_response_header {
144960e65d2SAdrian Chadd 	uint32_t len;
145960e65d2SAdrian Chadd 	uint32_t buf_offset;
146960e65d2SAdrian Chadd 	uint32_t is_complete;
147960e65d2SAdrian Chadd };
148960e65d2SAdrian Chadd 
149960e65d2SAdrian Chadd #endif	/* __QCOM_SCM_LEGACY_DEFS_H__ */
150