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