xref: /freebsd/sys/dev/firmware/arm/scmi.h (revision c4fde87a3236b500246d4fce76dbca2a3d64f73a)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2022 Ruslan Bukin <br@bsdpad.com>
5  * Copyright (c) 2023 Arm Ltd
6  *
7  * This work was supported by Innovate UK project 105694, "Digital Security
8  * by Design (DSbD) Technology Platform Prototype".
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  */
31 
32 #ifndef	_ARM64_SCMI_SCMI_H_
33 #define	_ARM64_SCMI_SCMI_H_
34 
35 #include <sys/sysctl.h>
36 
37 #include "scmi_if.h"
38 
39 #define SCMI_DEF_MAX_MSG		32
40 #define SCMI_DEF_MAX_MSG_PAYLD_SIZE	128
41 
42 #define SCMI_MAX_MSG_PAYLD_SIZE(sc)	((sc)->trs_desc.max_payld_sz + sizeof(uint32_t))
43 #define SCMI_MAX_MSG_REPLY_SIZE(sc)	(SCMI_MAX_MSG_PAYLD_SIZE((sc)) + sizeof(uint32_t))
44 #define SCMI_MAX_MSG_SIZE(sc)		(SCMI_MAX_MSG_REPLY_SIZE(sc) + sizeof(uint32_t))
45 #define SCMI_MAX_MSG(sc)		((sc)->trs_desc.max_msg)
46 #define SCMI_MAX_MSG_TIMEOUT_MS(sc)	((sc)->trs_desc.reply_timo_ms)
47 
48 enum scmi_chan {
49 	SCMI_CHAN_A2P,
50 	SCMI_CHAN_P2A,
51 	SCMI_CHAN_MAX
52 };
53 
54 struct scmi_transport_desc {
55 	bool no_completion_irq;
56 	unsigned int max_msg;
57 	unsigned int max_payld_sz;
58 	unsigned int reply_timo_ms;
59 };
60 
61 struct scmi_transport;
62 
63 struct scmi_softc {
64 	device_t			dev;
65 	struct mtx			mtx;
66 	struct scmi_transport_desc	trs_desc;
67 	struct scmi_transport		*trs;
68 	struct sysctl_oid		*sysctl_root;
69 };
70 
71 struct scmi_msg {
72 	bool		polling;
73 	int		poll_done;
74 	uint32_t	tx_len;
75 	uint32_t	rx_len;
76 #define SCMI_MSG_HDR_SIZE	(sizeof(uint32_t))
77 	uint32_t	hdr;
78 	uint8_t		payld[];
79 };
80 #define hdr_to_msg(h)	__containerof((h), struct scmi_msg, hdr)
81 
82 void *scmi_buf_get(device_t dev, uint8_t protocol_id, uint8_t message_id,
83 		   int tx_payd_sz, int rx_payld_sz);
84 void scmi_buf_put(device_t dev, void *buf);
85 struct scmi_msg *scmi_msg_get(device_t dev, int tx_payld_sz, int rx_payld_sz);
86 void scmi_msg_put(device_t dev, struct scmi_msg *msg);
87 int scmi_request(device_t dev, void *in, void **);
88 int scmi_request_tx(device_t dev, void *in);
89 int scmi_msg_async_enqueue(struct scmi_msg *msg);
90 void scmi_rx_irq_callback(device_t dev, void *chan, uint32_t hdr, uint32_t rx_len);
91 
92 DECLARE_CLASS(scmi_driver);
93 
94 int scmi_attach(device_t dev);
95 
96 #endif /* !_ARM64_SCMI_SCMI_H_ */
97