1 /* 2 * Copyright 2024 NXP 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 /** 8 * @file 9 * @brief SCMI SHMEM API 10 */ 11 12 #ifndef _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_SHMEM_H_ 13 #define _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_SHMEM_H_ 14 15 #include <zephyr/device.h> 16 #include <zephyr/arch/cpu.h> 17 #include <errno.h> 18 19 #define SCMI_SHMEM_CHAN_STATUS_BUSY_BIT BIT(0) 20 #define SCMI_SHMEM_CHAN_FLAG_IRQ_BIT BIT(0) 21 22 struct scmi_shmem_layout { 23 volatile uint32_t res0; 24 volatile uint32_t chan_status; 25 volatile uint32_t res1[2]; 26 volatile uint32_t chan_flags; 27 volatile uint32_t len; 28 volatile uint32_t msg_hdr; 29 }; 30 31 struct scmi_message; 32 33 /** 34 * @brief Write a message in the SHMEM area 35 * 36 * @param shmem pointer to shmem device 37 * @param msg message to write 38 * 39 * @retval 0 if successful 40 * @retval negative errno if failure 41 */ 42 int scmi_shmem_write_message(const struct device *shmem, 43 struct scmi_message *msg); 44 45 /** 46 * @brief Read a message from a SHMEM area 47 * 48 * @param shmem pointer to shmem device 49 * @param msg message to write the data into 50 * 51 * @retval 0 if successful 52 * @retval negative errno if failure 53 */ 54 int scmi_shmem_read_message(const struct device *shmem, 55 struct scmi_message *msg); 56 57 /** 58 * @brief Update the channel flags 59 * 60 * @param shmem pointer to shmem device 61 * @param mask value to negate and bitwise-and the old 62 * channel flags value 63 * @param val value to bitwise and with the mask and 64 * bitwise-or with the masked old value 65 */ 66 void scmi_shmem_update_flags(const struct device *shmem, 67 uint32_t mask, uint32_t val); 68 69 /** 70 * @brief Read a channel's status 71 * 72 * @param shmem pointer to shmem device 73 */ 74 uint32_t scmi_shmem_channel_status(const struct device *shmem); 75 76 /** 77 * @brief Process vendor specific features when writing message 78 * 79 * @param layout layout of the message 80 * 81 * @retval 0 if successful 82 * @retval negative errno if failure 83 */ 84 int scmi_shmem_vendor_write_message(struct scmi_shmem_layout *layout); 85 86 /** 87 * @brief Process vendor specific features when reading message 88 * 89 * @param layout layout of the message 90 * 91 * @retval 0 if successful 92 * @retval negative errno if failure 93 */ 94 int scmi_shmem_vendor_read_message(const struct scmi_shmem_layout *layout); 95 96 #endif /* _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_SHMEM_H_ */ 97