xref: /freebsd/sys/dev/firmware/arm/scmi.h (revision 9768746b)
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  * $FreeBSD$
31  */
32 
33 #ifndef	_ARM64_SCMI_SCMI_H_
34 #define	_ARM64_SCMI_SCMI_H_
35 
36 #define	SCMI_LOCK(sc)		mtx_lock(&(sc)->mtx)
37 #define	SCMI_UNLOCK(sc)		mtx_unlock(&(sc)->mtx)
38 #define	SCMI_ASSERT_LOCKED(sc)	mtx_assert(&(sc)->mtx, MA_OWNED)
39 
40 #define dprintf(fmt, ...)
41 
42 /* Shared Memory Transfer. */
43 struct scmi_smt_header {
44 	uint32_t reserved;
45 	uint32_t channel_status;
46 #define	SCMI_SHMEM_CHAN_STAT_CHANNEL_ERROR	(1 << 1)
47 #define	SCMI_SHMEM_CHAN_STAT_CHANNEL_FREE	(1 << 0)
48 	uint32_t reserved1[2];
49 	uint32_t flags;
50 #define	SCMI_SHMEM_FLAG_INTR_ENABLED		(1 << 0)
51 	uint32_t length;
52 	uint32_t msg_header;
53 	uint8_t msg_payload[0];
54 };
55 
56 #define	SMT_HEADER_SIZE			sizeof(struct scmi_smt_header)
57 
58 #define	SMT_HEADER_TOKEN_S		18
59 #define	SMT_HEADER_TOKEN_M		(0x3fff << SMT_HEADER_TOKEN_S)
60 #define	SMT_HEADER_PROTOCOL_ID_S	10
61 #define	SMT_HEADER_PROTOCOL_ID_M	(0xff << SMT_HEADER_PROTOCOL_ID_S)
62 #define	SMT_HEADER_MESSAGE_TYPE_S	8
63 #define	SMT_HEADER_MESSAGE_TYPE_M	(0x3 << SMT_HEADER_MESSAGE_TYPE_S)
64 #define	SMT_HEADER_MESSAGE_ID_S		0
65 #define	SMT_HEADER_MESSAGE_ID_M		(0xff << SMT_HEADER_MESSAGE_ID_S)
66 
67 struct scmi_req {
68 	int protocol_id;
69 	int message_id;
70 	const void *in_buf;
71 	uint32_t in_size;
72 	void *out_buf;
73 	uint32_t out_size;
74 };
75 
76 int scmi_request(device_t dev, struct scmi_req *req);
77 void scmi_shmem_read(device_t dev, bus_size_t offset, void *buf,
78     bus_size_t len);
79 void scmi_shmem_write(device_t dev, bus_size_t offset, const void *buf,
80     bus_size_t len);
81 
82 #endif /* !_ARM64_SCMI_SCMI_H_ */
83