xref: /freebsd/sys/dev/firmware/arm/scmi.h (revision f700da1c20f1f103d2ab2899d7060d3e331f082e)
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 "scmi_if.h"
36 
37 #define SCMI_DEF_MAX_MSG		32
38 #define SCMI_DEF_MAX_MSG_PAYLD_SIZE	128
39 
40 #define SCMI_MAX_MSG_PAYLD_SIZE(sc)	((sc)->trs_desc.max_payld_sz + sizeof(uint32_t))
41 #define SCMI_MAX_MSG_REPLY_SIZE(sc)	(SCMI_MAX_MSG_PAYLD_SIZE((sc)) + sizeof(uint32_t))
42 #define SCMI_MAX_MSG_SIZE(sc)		(SCMI_MAX_MSG_REPLY_SIZE(sc) + sizeof(uint32_t))
43 #define SCMI_MAX_MSG(sc)		((sc)->trs_desc.max_msg)
44 #define SCMI_MAX_MSG_TIMEOUT_MS(sc)	((sc)->trs_desc.reply_timo_ms)
45 
46 enum scmi_chan {
47 	SCMI_CHAN_A2P,
48 	SCMI_CHAN_P2A,
49 	SCMI_CHAN_MAX
50 };
51 
52 struct scmi_transport_desc {
53 	bool no_completion_irq;
54 	unsigned int max_msg;
55 	unsigned int max_payld_sz;
56 	unsigned int reply_timo_ms;
57 };
58 
59 struct scmi_transport;
60 
61 struct scmi_softc {
62 	struct simplebus_softc		simplebus_sc;
63 	device_t			dev;
64 	struct mtx			mtx;
65 	struct scmi_transport_desc	trs_desc;
66 	struct scmi_transport		*trs;
67 };
68 
69 struct scmi_msg {
70 	bool		polling;
71 	int		poll_done;
72 	uint32_t	tx_len;
73 	uint32_t	rx_len;
74 #define SCMI_MSG_HDR_SIZE	(sizeof(uint32_t))
75 	uint32_t	hdr;
76 	uint8_t		payld[];
77 };
78 #define hdr_to_msg(h)	__containerof((h), struct scmi_msg, hdr)
79 
80 void *scmi_buf_get(device_t dev, uint8_t protocol_id, uint8_t message_id,
81 		   int tx_payd_sz, int rx_payld_sz);
82 void scmi_buf_put(device_t dev, void *buf);
83 struct scmi_msg *scmi_msg_get(device_t dev, int tx_payld_sz, int rx_payld_sz);
84 void scmi_msg_put(device_t dev, struct scmi_msg *msg);
85 int scmi_request(device_t dev, void *in, void **);
86 void scmi_rx_irq_callback(device_t dev, void *chan, uint32_t hdr, uint32_t rx_len);
87 
88 DECLARE_CLASS(scmi_driver);
89 
90 int scmi_attach(device_t dev);
91 
92 #endif /* !_ARM64_SCMI_SCMI_H_ */
93