xref: /freebsd/sys/dev/firmware/arm/scmi.h (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2022 Ruslan Bukin <br@bsdpad.com>
5  *
6  * This work was supported by Innovate UK project 105694, "Digital Security
7  * by Design (DSbD) Technology Platform Prototype".
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * 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 AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30 
31 #ifndef	_ARM64_SCMI_SCMI_H_
32 #define	_ARM64_SCMI_SCMI_H_
33 
34 #define	SCMI_LOCK(sc)		mtx_lock(&(sc)->mtx)
35 #define	SCMI_UNLOCK(sc)		mtx_unlock(&(sc)->mtx)
36 #define	SCMI_ASSERT_LOCKED(sc)	mtx_assert(&(sc)->mtx, MA_OWNED)
37 
38 #define dprintf(fmt, ...)
39 
40 /* Shared Memory Transfer. */
41 struct scmi_smt_header {
42 	uint32_t reserved;
43 	uint32_t channel_status;
44 #define	SCMI_SHMEM_CHAN_STAT_CHANNEL_ERROR	(1 << 1)
45 #define	SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE	(1 << 0)
46 	uint32_t reserved1[2];
47 	uint32_t flags;
48 #define	SCMI_SHMEM_FLAG_INTR_ENABLED		(1 << 0)
49 	uint32_t length;
50 	uint32_t msg_header;
51 	uint8_t msg_payload[0];
52 };
53 
54 #define	SMT_HEADER_SIZE			sizeof(struct scmi_smt_header)
55 
56 #define	SMT_HEADER_TOKEN_S		18
57 #define	SMT_HEADER_TOKEN_M		(0x3fff << SMT_HEADER_TOKEN_S)
58 #define	SMT_HEADER_PROTOCOL_ID_S	10
59 #define	SMT_HEADER_PROTOCOL_ID_M	(0xff << SMT_HEADER_PROTOCOL_ID_S)
60 #define	SMT_HEADER_MESSAGE_TYPE_S	8
61 #define	SMT_HEADER_MESSAGE_TYPE_M	(0x3 << SMT_HEADER_MESSAGE_TYPE_S)
62 #define	SMT_HEADER_MESSAGE_ID_S		0
63 #define	SMT_HEADER_MESSAGE_ID_M		(0xff << SMT_HEADER_MESSAGE_ID_S)
64 
65 struct scmi_req {
66 	int protocol_id;
67 	int message_id;
68 	const void *in_buf;
69 	uint32_t in_size;
70 	void *out_buf;
71 	uint32_t out_size;
72 };
73 
74 int scmi_request(device_t dev, struct scmi_req *req);
75 void scmi_shmem_read(device_t dev, bus_size_t offset, void *buf,
76     bus_size_t len);
77 void scmi_shmem_write(device_t dev, bus_size_t offset, const void *buf,
78     bus_size_t len);
79 
80 #endif /* !_ARM64_SCMI_SCMI_H_ */
81