1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright 2025 NXP 4 */ 5 6 #ifndef __SBI_MPXY_H 7 #define __SBI_MPXY_H 8 9 #if defined(CFG_RISCV_SBI_MPXY) 10 11 /* SBI function IDs for MPXY extension */ 12 #define SBI_EXT_MPXY_GET_SHMEM_SIZE 0x0 13 #define SBI_EXT_MPXY_SET_SHMEM 0x1 14 #define SBI_EXT_MPXY_GET_CHANNEL_IDS 0x2 15 #define SBI_EXT_MPXY_READ_ATTRS 0x3 16 #define SBI_EXT_MPXY_WRITE_ATTRS 0x4 17 #define SBI_EXT_MPXY_SEND_MSG_WITH_RESP 0x5 18 #define SBI_EXT_MPXY_SEND_MSG_WITHOUT_RESP 0x6 19 #define SBI_EXT_MPXY_GET_NOTIFICATION_EVENTS 0x7 20 21 /* Capabilities available through CHANNEL_CAPABILITY attribute */ 22 #define SBI_MPXY_CHAN_CAP_MSI BIT(0) 23 #define SBI_MPXY_CHAN_CAP_SSE BIT(1) 24 #define SBI_MPXY_CHAN_CAP_EVENTS_STATE BIT(2) 25 #define SBI_MPXY_CHAN_CAP_SEND_WITH_RESP BIT(3) 26 #define SBI_MPXY_CHAN_CAP_SEND_WITHOUT_RESP BIT(4) 27 #define SBI_MPXY_CHAN_CAP_GET_NOTIFICATIONS BIT(5) 28 29 #ifndef __ASSEMBLER__ 30 31 #include <compiler.h> 32 #include <encoding.h> 33 #include <stdint.h> 34 #include <sys/cdefs.h> 35 #include <types_ext.h> 36 #include <util.h> 37 38 enum sbi_mpxy_attr_id { 39 SBI_MPXY_ATTR_MSG_PROT_ID = 0x00000000, 40 SBI_MPXY_ATTR_MSG_PROT_VER = 0x00000001, 41 SBI_MPXY_ATTR_MSG_MAX_LEN = 0x00000002, 42 SBI_MPXY_ATTR_MSG_SEND_TIMEOUT = 0x00000003, 43 SBI_MPXY_ATTR_MSG_COMPLETION_TIMEOUT = 0x00000004, 44 SBI_MPXY_ATTR_CHANNEL_CAPABILITY = 0x00000005, 45 SBI_MPXY_ATTR_SSE_EVENT_ID = 0x00000006, 46 SBI_MPXY_ATTR_MSI_CONTROL = 0x00000007, 47 SBI_MPXY_ATTR_MSI_ADDR_LO = 0x00000008, 48 SBI_MPXY_ATTR_MSI_ADDR_HI = 0x00000009, 49 SBI_MPXY_ATTR_MSI_DATA = 0x0000000A, 50 SBI_MPXY_ATTR_EVENTS_STATE_CONTROL = 0x0000000B, 51 SBI_MPXY_ATTR_STD_ATTR_MAX_IDX, 52 SBI_MPXY_ATTR_MSGPROTO_ATTR_START = 0x80000000, 53 SBI_MPXY_ATTR_MSGPROTO_ATTR_END = 0xffffffff 54 }; 55 56 enum sbi_mpxy_msgproto_id { 57 SBI_MPXY_MSGPROTO_RPMI_ID = 0x00000000, 58 SBI_MPXY_MSGPROTO_MAX_IDX, 59 SBI_MPXY_MSGPROTO_VENDOR_START = 0x80000000, 60 SBI_MPXY_MSGPROTO_VENDOR_END = 0xffffffff 61 }; 62 63 /* 64 * struct sbi_mpxy_msi_info - MSI-related attributes for an MPXY channel 65 * @msi_addr_lo: Lower 32 bits of the MSI address 66 * @msi_addr_hi: Upper 32 bits of the MSI address 67 * @msi_data: MSI data payload to be written 68 * 69 * Describes the MSI configuration used for sending interrupts from 70 * the SBI implementation to the supervisor software via MPXY channels. 71 */ 72 struct sbi_mpxy_msi_info { 73 uint32_t msi_addr_lo; 74 uint32_t msi_addr_hi; 75 uint32_t msi_data; 76 }; 77 78 /* 79 * struct sbi_mpxy_channel_attrs - Attributes describing an MPXY channel 80 * @msg_proto_id: Protocol identifier used on this channel (e.g., RPMI) 81 * @msg_proto_version: Version of the protocol supported on this channel 82 * @msg_max_len: Maximum length (in bytes) of the message payload 83 * @msg_send_timeout: Timeout (in microseconds) for sending a message 84 * @msg_completion_timeout: Timeout (in microseconds) to wait for a response 85 * @capability: Bitfield indicating supported channel capabilities 86 * @sse_event_id: SSE event ID used for signaling events (if supported) 87 * @msi_control: Bitmask for controlling MSI behavior (e.g., enable) 88 * @msi_info: MSI configuration (address/data) for the channel 89 * @events_state_ctrl: Control register for event state handling 90 * 91 * These attributes are retrieved from the SBI implementation via 92 * SBI_MPXY_ATTR_* queries and describe the static properties of 93 * an MPXY channel. 94 */ 95 struct sbi_mpxy_channel_attrs { 96 uint32_t msg_proto_id; 97 uint32_t msg_proto_version; 98 uint32_t msg_max_len; 99 uint32_t msg_send_timeout; 100 uint32_t msg_completion_timeout; 101 uint32_t capability; 102 uint32_t sse_event_id; 103 uint32_t msi_control; 104 struct sbi_mpxy_msi_info msi_info; 105 uint32_t events_state_ctrl; 106 }; 107 108 /* 109 * struct sbi_mpxy_channel_ids_data - MPXY channel ID list structure 110 * @remaining: Number of channel IDs remaining after this call 111 * @returned: Number of channel IDs returned in this call 112 * @channel_array: Array of channel IDs returned by the SBI call 113 * 114 * This structure is used for retrieving channel IDs from the SBI 115 * implementation via shared memory. It supports partial retrieval 116 * when the number of available IDs exceeds the buffer capacity. 117 */ 118 struct sbi_mpxy_channel_ids_data { 119 uint32_t remaining; 120 uint32_t returned; 121 uint32_t channel_array[]; 122 }; 123 124 /* 125 * struct sbi_mpxy_notification_data - MPXY notification event structure 126 * @remaining: Number of notification events remaining after this call 127 * @returned: Number of notification events returned in this call 128 * @lost: Number of notification events lost due to buffer overflow 129 * @reserved: Reserved for future use (must be zero) 130 * @events_data: Raw event data blob, format defined by the message protocol 131 * 132 * This structure is populated in shared memory by the SBI implementation 133 * to deliver asynchronous notification events to the supervisor software. 134 */ 135 struct sbi_mpxy_notification_data { 136 uint32_t remaining; 137 uint32_t returned; 138 uint32_t lost; 139 uint32_t reserved; 140 uint8_t events_data[]; 141 }; 142 143 /* SBI MPXY */ 144 int sbi_mpxy_get_shmem_size(unsigned long *shmem_size); 145 int sbi_mpxy_set_shmem(void); 146 int sbi_mpxy_get_channel_ids(uint32_t channel_count, uint32_t *channel_ids); 147 int sbi_mpxy_read_attributes(uint32_t channel_id, uint32_t base_attribute_id, 148 uint32_t attribute_count, void *attribute_buf); 149 int sbi_mpxy_write_attributes(uint32_t channel_id, uint32_t base_attribute_id, 150 uint32_t attribute_count, 151 uint32_t *attributes_buf); 152 int sbi_mpxy_send_message_with_response(uint32_t channel_id, 153 uint32_t message_id, void *message, 154 unsigned long message_len, 155 void *response, 156 unsigned long max_response_len, 157 unsigned long *response_len); 158 int sbi_mpxy_send_message_without_response(uint32_t channel_id, 159 uint32_t message_id, void *message, 160 unsigned long message_len); 161 int sbi_mpxy_get_channel_count(uint32_t *channel_count); 162 int 163 sbi_mpxy_get_notification_events(uint32_t channel_id, 164 struct sbi_mpxy_notification_data *notif_data, 165 unsigned long *events_data_len); 166 167 #endif /*__ASSEMBLER__*/ 168 #endif /*defined(CFG_RISCV_SBI_MPXY)*/ 169 #endif /*__SBI_MPXY_H*/ 170