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 struct simplebus_softc simplebus_sc; 65 device_t dev; 66 struct mtx mtx; 67 struct scmi_transport_desc trs_desc; 68 struct scmi_transport *trs; 69 struct sysctl_oid *sysctl_root; 70 }; 71 72 struct scmi_msg { 73 bool polling; 74 int poll_done; 75 uint32_t tx_len; 76 uint32_t rx_len; 77 #define SCMI_MSG_HDR_SIZE (sizeof(uint32_t)) 78 uint32_t hdr; 79 uint8_t payld[]; 80 }; 81 #define hdr_to_msg(h) __containerof((h), struct scmi_msg, hdr) 82 83 void *scmi_buf_get(device_t dev, uint8_t protocol_id, uint8_t message_id, 84 int tx_payd_sz, int rx_payld_sz); 85 void scmi_buf_put(device_t dev, void *buf); 86 struct scmi_msg *scmi_msg_get(device_t dev, int tx_payld_sz, int rx_payld_sz); 87 void scmi_msg_put(device_t dev, struct scmi_msg *msg); 88 int scmi_request(device_t dev, void *in, void **); 89 int scmi_request_tx(device_t dev, void *in); 90 int scmi_msg_async_enqueue(struct scmi_msg *msg); 91 void scmi_rx_irq_callback(device_t dev, void *chan, uint32_t hdr, uint32_t rx_len); 92 93 DECLARE_CLASS(scmi_driver); 94 95 int scmi_attach(device_t dev); 96 97 #endif /* !_ARM64_SCMI_SCMI_H_ */ 98