1 /* 2 * Copyright (c) 2024, Arm Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef MHU_V3_X_H 8 #define MHU_V3_X_H 9 10 #include <stdbool.h> 11 #include <stdint.h> 12 13 /* MHU Architecture Major Revision 3 */ 14 #define MHU_MAJOR_REV_V3 U(0x2) 15 /* MHU Architecture Minor Revision 0 */ 16 #define MHU_MINOR_REV_3_0 U(0x0) 17 18 /* MHU Architecture Major Revision offset */ 19 #define MHU_ARCH_MAJOR_REV_OFF U(0x4) 20 /* MHU Architecture Major Revision mask */ 21 #define MHU_ARCH_MAJOR_REV_MASK (U(0xf) << MHU_ARCH_MAJOR_REV_OFF) 22 23 /* MHU Architecture Minor Revision offset */ 24 #define MHU_ARCH_MINOR_REV_OFF U(0x0) 25 /* MHU Architecture Minor Revision mask */ 26 #define MHU_ARCH_MINOR_REV_MASK (U(0xf) << MHU_ARCH_MINOR_REV_OFF) 27 28 /* MHUv3 PBX/MBX Operational Request offset */ 29 #define MHU_V3_OP_REQ_OFF U(0) 30 /* MHUv3 PBX/MBX Operational Request */ 31 #define MHU_V3_OP_REQ (U(1) << MHU_V3_OP_REQ_OFF) 32 33 /** 34 * MHUv3 error enumeration types 35 */ 36 enum mhu_v3_x_error_t { 37 /* No error */ 38 MHU_V_3_X_ERR_NONE, 39 /* MHU driver not initialized */ 40 MHU_V_3_X_ERR_NOT_INIT, 41 /* MHU driver alreary initialized */ 42 MHU_V_3_X_ERR_ALREADY_INIT, 43 /* MHU Revision not supported error */ 44 MHU_V_3_X_ERR_UNSUPPORTED_VERSION, 45 /* Operation not supported */ 46 MHU_V_3_X_ERR_UNSUPPORTED, 47 /* Invalid parameter */ 48 MHU_V_3_X_ERR_INVALID_PARAM, 49 /* General MHU driver error */ 50 MHU_V_3_X_ERR_GENERAL, 51 }; 52 53 /** 54 * MHUv3 channel types 55 */ 56 enum mhu_v3_x_channel_type_t { 57 /* Doorbell channel */ 58 MHU_V3_X_CHANNEL_TYPE_DBCH, 59 /* Channel type count */ 60 MHU_V3_X_CHANNEL_TYPE_COUNT, 61 }; 62 63 /** 64 * MHUv3 frame types 65 */ 66 enum mhu_v3_x_frame_t { 67 /* MHUv3 postbox frame */ 68 MHU_V3_X_PBX_FRAME, 69 /* MHUv3 mailbox frame */ 70 MHU_V3_X_MBX_FRAME, 71 }; 72 73 /** 74 * MHUv3 device structure 75 */ 76 struct mhu_v3_x_dev_t { 77 /* Base address of the MHUv3 frame */ 78 uintptr_t base; 79 /* Type of the MHUv3 frame */ 80 enum mhu_v3_x_frame_t frame; 81 /* Minor revision of the MHUv3 */ 82 uint32_t subversion; 83 /* Flag to indicate if the MHUv3 is initialized */ 84 bool is_initialized; 85 }; 86 87 /** 88 * Initializes the MHUv3 89 * 90 * dev MHU device struct mhu_v3_x_dev_t 91 * 92 * Returns mhu_v3_x_error_t error code 93 */ 94 enum mhu_v3_x_error_t mhu_v3_x_driver_init(struct mhu_v3_x_dev_t *dev); 95 96 /** 97 * Returns the number of channels implemented 98 * 99 * dev MHU device struct mhu_v3_x_dev_t 100 * ch_type MHU channel type mhu_v3_x_channel_type_t 101 * num_ch Pointer to the variable that will store the value 102 * 103 * Returns mhu_v3_x_error_t error code 104 */ 105 enum mhu_v3_x_error_t mhu_v3_x_get_num_channel_implemented( 106 const struct mhu_v3_x_dev_t *dev, enum mhu_v3_x_channel_type_t ch_type, 107 uint8_t *num_ch); 108 109 /** 110 * Clear flags from a doorbell channel 111 * 112 * dev MHU device struct mhu_v3_x_dev_t 113 * channel Doorbell channel number 114 * flags Flags to be cleared from the channel 115 * 116 * Returns mhu_v3_x_error_t error code 117 */ 118 enum mhu_v3_x_error_t mhu_v3_x_doorbell_clear(const struct mhu_v3_x_dev_t *dev, 119 const uint32_t channel, uint32_t flags); 120 121 /** 122 * Write flags to a doorbell channel 123 * 124 * dev MHU device struct mhu_v3_x_dev_t 125 * channel Doorbell channel number 126 * flags Flags to be written to the channel 127 * 128 * Returns mhu_v3_x_error_t error code 129 */ 130 enum mhu_v3_x_error_t mhu_v3_x_doorbell_write(const struct mhu_v3_x_dev_t *dev, 131 const uint32_t channel, uint32_t flags); 132 133 /** 134 * Read value from a doorbell channel 135 * 136 * dev MHU device struct mhu_v3_x_dev_t 137 * channel Doorbell channel number 138 * flags Pointer to the variable that will store the flags read from the 139 * channel 140 * 141 * Returns mhu_v3_x_error_t error code 142 */ 143 enum mhu_v3_x_error_t mhu_v3_x_doorbell_read(const struct mhu_v3_x_dev_t *dev, 144 const uint32_t channel, uint32_t *flags); 145 146 /** 147 * Set bits in a doorbell channel mask which is used to disable interrupts for 148 * received flags corresponding to the mask 149 * 150 * dev MHU device struct mhu_v3_x_dev_t 151 * channel Doorbell channel number 152 * flags Flags to set mask bits in this doorbell channel 153 * 154 * Returns mhu_v3_x_error_t error code 155 */ 156 enum mhu_v3_x_error_t mhu_v3_x_doorbell_mask_set( 157 const struct mhu_v3_x_dev_t *dev, const uint32_t channel, 158 uint32_t flags); 159 160 /** 161 * Clear bits in a doorbell channel mask which is used to disable interrupts 162 * for received flags corresponding to the mask 163 * 164 * dev MHU device struct mhu_v3_x_dev_t 165 * channel Doorbell channel number 166 * flags Flags to clear mask bits in this doorbell channel 167 * 168 * Returns mhu_v3_x_error_t error code 169 */ 170 enum mhu_v3_x_error_t mhu_v3_x_doorbell_mask_clear( 171 const struct mhu_v3_x_dev_t *dev, const uint32_t channel, uint32_t flags); 172 173 /** 174 * Get the mask of a doorbell channel which is used to disable interrupts for 175 * received flags corresponding to the mask 176 * 177 * dev MHU device struct mhu_v3_x_dev_t 178 * channel Doorbell channel number 179 * flags Pointer to the variable that will store the flags read from the 180 * mask value 181 * 182 * Returns mhu_v3_x_error_t error code 183 */ 184 enum mhu_v3_x_error_t mhu_v3_x_doorbell_mask_get( 185 const struct mhu_v3_x_dev_t *dev, const uint32_t channel, uint32_t *flags); 186 187 /** 188 * Enable the channel interrupt 189 * 190 * dev MHU device struct mhu_v3_x_dev_t 191 * channel Doorbell channel number 192 * ch_type MHU channel type mhu_v3_x_channel_type_t 193 * 194 * Returns mhu_v3_x_error_t error code 195 */ 196 enum mhu_v3_x_error_t mhu_v3_x_channel_interrupt_enable( 197 const struct mhu_v3_x_dev_t *dev, const uint32_t channel, 198 enum mhu_v3_x_channel_type_t ch_type); 199 200 /** 201 * Disable the channel interrupt 202 * 203 * dev MHU device struct mhu_v3_x_dev_t 204 * channel Doorbell channel number 205 * ch_type MHU channel type mhu_v3_x_channel_type_t 206 * 207 * Returns mhu_v3_x_error_t error code 208 */ 209 enum mhu_v3_x_error_t mhu_v3_x_channel_interrupt_disable( 210 const struct mhu_v3_x_dev_t *dev, const uint32_t channel, 211 enum mhu_v3_x_channel_type_t ch_type); 212 213 /** 214 * Clear the channel interrupt 215 * 216 * dev MHU device struct mhu_v3_x_dev_t 217 * channel Doorbell channel number 218 * ch_type MHU channel type mhu_v3_x_channel_type_t 219 * 220 * Returns mhu_v3_x_error_t error code 221 */ 222 enum mhu_v3_x_error_t mhu_v3_x_channel_interrupt_clear( 223 const struct mhu_v3_x_dev_t *dev, const uint32_t channel, 224 enum mhu_v3_x_channel_type_t ch_type); 225 226 #endif /* MHU_V3_X_H */ 227