1 /* 2 * Copyright (c) 2011 Intel Corporation. All Rights Reserved. 3 * Copyright (c) Imagination Technologies Limited, UK 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the 7 * "Software"), to deal in the Software without restriction, including 8 * without limitation the rights to use, copy, modify, merge, publish, 9 * distribute, sub license, and/or sell copies of the Software, and to 10 * permit persons to whom the Software is furnished to do so, subject to 11 * the following conditions: 12 * 13 * The above copyright notice and this permission notice (including the 14 * next paragraph) shall be included in all copies or substantial portions 15 * of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20 * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR 21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 */ 25 26 27 /*! 28 ****************************************************************************** 29 @file : mem_io.h 30 31 @brief Memory structure access macros. 32 33 @date 12/09/05 34 35 <b>Description:</b>\n 36 37 This file contains a set of memory access macros for accessing packed memory 38 structures. 39 40 <b>Platform:</b>\n 41 Platform Independent 42 43 @Version 1.0 44 45 ******************************************************************************/ 46 47 /* 48 ****************************************************************************** 49 Modifications :- 50 51 $Log: mem_io.h $ 52 53 --- Revision Logs Removed --- 54 55 --- Revision Logs Removed --- 56 57 --- Revision Logs Removed --- 58 59 --- Revision Logs Removed --- 60 61 --- Revision Logs Removed --- 62 63 --- Revision Logs Removed --- 64 65 --- Revision Logs Removed --- 66 67 --- Revision Logs Removed --- 68 69 --- Revision Logs Removed --- 70 71 --- Revision Logs Removed --- 72 73 74 *****************************************************************************/ 75 76 #if !defined (__MEM_IO_H__) 77 #define __MEM_IO_H__ 78 79 #if (__cplusplus) 80 extern "C" { 81 #endif 82 83 #include "img_types.h" 84 85 #ifdef DOXYGEN_WILL_SEE_THIS 86 /*! 87 ****************************************************************************** 88 89 @Function MEMIO_READ_FIELD 90 91 @Description 92 93 This macro is used to extract a field from a packed memory based structure. 94 95 @Input vpMem: A pointer to the memory structure. 96 97 @Input field: The name of the field to be extracted. 98 99 @Return IMG_UINT32: The value of the field - right aligned. 100 101 ******************************************************************************/ 102 IMG_UINT32 MEMIO_READ_FIELD(IMG_VOID * vpMem, field); 103 104 /*! 105 ****************************************************************************** 106 107 @Function MEMIO_READ_TABLE_FIELD 108 109 @Description 110 111 This macro is used to extract the value of a field in a table in a packed 112 memory based structure. 113 114 @Input vpMem: A pointer to the memory structure. 115 116 @Input field: The name of the field to be extracted. 117 118 @Input ui32TabIndex: The table index of the field to be extracted. 119 120 @Return IMG_UINT32: The value of the field - right aligned. 121 122 ******************************************************************************/ 123 IMG_UINT32 MEMIO_READ_TABLE_FIELD(IMG_VOID * vpMem, field, IMG_UINT32 ui32TabIndex); 124 125 /*! 126 ****************************************************************************** 127 128 @Function MEMIO_READ_REPEATED_FIELD 129 130 @Description 131 132 This macro is used to extract the value of a repeated field in a packed 133 memory based structure. 134 135 @Input vpMem: A pointer to the memory structure. 136 137 @Input field: The name of the field to be extracted. 138 139 @Input ui32RepIndex: The repeat index of the field to be extracted. 140 141 @Return IMG_UINT32: The value of the field - right aligned. 142 143 ******************************************************************************/ 144 IMG_UINT32 MEMIO_READ_REPEATED_FIELD(IMG_VOID * vpMem, field, IMG_UINT32 ui32RepIndex); 145 146 /*! 147 ****************************************************************************** 148 149 @Function MEMIO_READ_TABLE_REPEATED_FIELD 150 151 @Description 152 153 This macro is used to extract the value of a repeated field in a table 154 in a packed memory based structure. 155 156 @Input vpMem: A pointer to the memory structure. 157 158 @Input field: The name of the field to be extracted. 159 160 @Input ui32TabIndex: The table index of the field to be extracted. 161 162 @Input ui32RepIndex: The repeat index of the field to be extracted. 163 164 @Return IMG_UINT32: The value of the field - right aligned. 165 166 ******************************************************************************/ 167 IMG_UINT32 MEMIO_READ_TABLE_REPEATED_FIELD(IMG_VOID * vpMem, field, IMG_UINT32 ui32TabIndex, IMG_UINT32 ui32RepIndex); 168 169 /*! 170 ****************************************************************************** 171 172 @Function MEMIO_WRITE_FIELD 173 174 @Description 175 176 This macro is used to update the value of a field in a packed memory based 177 structure. 178 179 @Input vpMem: A pointer to the memory structure. 180 181 @Input field: The name of the field to be updated. 182 183 @Input ui32Value: The value to be writtem to the field - right aligned. 184 185 @Return None. 186 187 ******************************************************************************/ 188 IMG_VOID MEMIO_WRITE_FIELD(IMG_VOID * vpMem, field, IMG_UINT32 ui32Value); 189 190 /*! 191 ****************************************************************************** 192 193 @Function MEMIO_WRITE_TABLE_FIELD 194 195 @Description 196 197 This macro is used to update the field in a table in a packed memory 198 based structure. 199 200 @Input vpMem: A pointer to the memory structure. 201 202 @Input field: The name of the field to be updated. 203 204 @Input ui32TabIndex: The table index of the field to be updated. 205 206 @Input ui32Value: The value to be writtem to the field - right aligned. 207 208 @Return None. 209 210 ******************************************************************************/ 211 IMG_VOID MEMIO_WRITE_TABLE_FIELD(IMG_VOID * vpMem, field, IMG_UINT32 ui32TabIndex, IMG_UINT32 ui32Value); 212 213 /*! 214 ****************************************************************************** 215 216 @Function MEMIO_WRITE_REPEATED_FIELD 217 218 @Description 219 220 This macro is used to update a repeated field in a packed memory 221 based structure. 222 223 @Input vpMem: A pointer to the memory structure. 224 225 @Input field: The name of the field to be updated. 226 227 @Input ui32RepIndex: The repeat index of the field to be updated. 228 229 @Input ui32Value: The value to be writtem to the field - right aligned. 230 231 @Return None. 232 233 ******************************************************************************/ 234 IMG_VOID MEMIO_WRITE_REPEATED_FIELD(IMG_VOID * vpMem, field, IMG_UINT32 ui32RepIndex, IMG_UINT32 ui32Value); 235 236 237 /*! 238 ****************************************************************************** 239 240 @Function MEMIO_WRITE_TABLE_REPEATED_FIELD 241 242 @Description 243 244 This macro is used to update a repeated field in a table in a packed memory 245 based structure. 246 247 @Input vpMem: A pointer to the memory structure. 248 249 @Input field: The name of the field to be updated. 250 251 @Input ui32TabIndex: The table index of the field to be updated. 252 253 @Input ui32RepIndex: The repeat index of the field to be updated. 254 255 @Input ui32Value: The value to be writtem to the field - right aligned. 256 257 @Return None. 258 259 ******************************************************************************/ 260 IMG_VOID MEMIO_WRITE_TABLE_REPEATED_FIELD(IMG_VOID * vpMem, field, IMG_UINT32 ui32TabIndex, IMG_UINT32 ui32RepIndex, IMG_UINT32 ui32Value); 261 262 #else 263 264 #if WIN32 265 #define MEMIO_CHECK_ALIGNMENT(vpMem) 266 267 #else 268 #define MEMIO_CHECK_ALIGNMENT(vpMem) \ 269 IMG_ASSERT(((IMG_UINTPTR_T)vpMem & 0x3) == 0) 270 #endif 271 272 /*! 273 ****************************************************************************** 274 275 @Function MEMIO_READ_FIELD 276 277 ******************************************************************************/ 278 279 280 #if defined __RELEASE_DEBUG__ 281 282 #define MEMIO_READ_FIELD(vpMem, field) \ 283 ( MEMIO_CHECK_ALIGNMENT(vpMem), \ 284 ((IMG_UINT32)(((*((field##_TYPE *)(((IMG_UINTPTR_T)vpMem) + field##_OFFSET))) & field##_MASK) >> field##_SHIFT)) ) 285 286 #else 287 288 #if 1 289 #define MEMIO_READ_FIELD(vpMem, field) \ 290 ((IMG_UINT32)(((*((field##_TYPE *)(((IMG_UINTPTR_T)vpMem) + field##_OFFSET))) & field##_MASK) >> field##_SHIFT)) 291 292 #else 293 294 #define MEMIO_READ_FIELD(vpMem, field) \ 295 ((IMG_UINT32)(((*((field##_TYPE *)(((IMG_UINTPTR_T)vpMem) + field##_OFFSET))) >> field##_SHIFT) & field##_LSBMASK) ) 296 297 #endif 298 299 #endif 300 301 302 303 /*! 304 ****************************************************************************** 305 306 @Function MEMIO_READ_TABLE_FIELD 307 308 ******************************************************************************/ 309 #if defined __RELEASE_DEBUG__ 310 311 #define MEMIO_READ_TABLE_FIELD(vpMem, field, ui32TabIndex) \ 312 ( MEMIO_CHECK_ALIGNMENT(vpMem), IMG_ASSERT((ui32TabIndex < field##_NO_ENTRIES) || (field##_NO_ENTRIES == 0)), \ 313 ((IMG_UINT32)(((*((field##_TYPE *)(((IMG_UINTPTR_T)vpMem) + field##_OFFSET + (field##_STRIDE * ui32TabIndex)))) & field##_MASK) >> field##_SHIFT)) ) \ 314 315 #else 316 317 #define MEMIO_READ_TABLE_FIELD(vpMem, field, ui32TabIndex) \ 318 ((IMG_UINT32)(((*((field##_TYPE *)(((IMG_UINTPTR_T)vpMem) + field##_OFFSET + (field##_STRIDE * ui32TabIndex)))) & field##_MASK) >> field##_SHIFT)) \ 319 320 #endif 321 322 323 /*! 324 ****************************************************************************** 325 326 @Function MEMIO_READ_REPEATED_FIELD 327 328 ******************************************************************************/ 329 #if defined __RELEASE_DEBUG__ 330 331 #define MEMIO_READ_REPEATED_FIELD(vpMem, field, ui32RepIndex) \ 332 ( MEMIO_CHECK_ALIGNMENT(vpMem), IMG_ASSERT(ui32RepIndex < field##_NO_REPS), \ 333 ((IMG_UINT32)(((*((field##_TYPE *)(((IMG_UINTPTR_T)vpMem) + field##_OFFSET))) & (field##_MASK >> (ui32RepIndex * field##_SIZE))) >> (field##_SHIFT - (ui32RepIndex * field##_SIZE)))) ) \ 334 335 #else 336 337 #define MEMIO_READ_REPEATED_FIELD(vpMem, field, ui32RepIndex) \ 338 ( (IMG_UINT32)(((*((field##_TYPE *)(((IMG_UINTPTR_T)vpMem) + field##_OFFSET))) & (field##_MASK >> (ui32RepIndex * field##_SIZE))) >> (field##_SHIFT - (ui32RepIndex * field##_SIZE))) ) \ 339 340 #endif 341 /*! 342 ****************************************************************************** 343 344 @Function MEMIO_READ_TABLE_REPEATED_FIELD 345 346 ******************************************************************************/ 347 #if defined __RELEASE_DEBUG__ 348 349 #define MEMIO_READ_TABLE_REPEATED_FIELD(vpMem, field, ui32TabIndex, ui32RepIndex) \ 350 ( MEMIO_CHECK_ALIGNMENT(vpMem), IMG_ASSERT((ui32TabIndex < field##_NO_ENTRIES) || (field##_NO_ENTRIES == 0)), IMG_ASSERT(ui32RepIndex < field##_NO_REPS), \ 351 ((IMG_UINT32)(((*((field##_TYPE *)(((IMG_UINTPTR_T)vpMem) + field##_OFFSET + (field##_STRIDE * ui32TabIndex)))) & (field##_MASK >> (ui32RepIndex * field##_SIZE))) >> (field##_SHIFT - (ui32RepIndex * field##_SIZE)))) ) \ 352 353 #else 354 355 #define MEMIO_READ_TABLE_REPEATED_FIELD(vpMem, field, ui32TabIndex, ui32RepIndex) \ 356 ((IMG_UINT32)(((*((field##_TYPE *)(((IMG_UINTPTR_T)vpMem) + field##_OFFSET + (field##_STRIDE * ui32TabIndex)))) & (field##_MASK >> (ui32RepIndex * field##_SIZE))) >> (field##_SHIFT - (ui32RepIndex * field##_SIZE)))) \ 357 358 #endif 359 360 /*! 361 ****************************************************************************** 362 363 @Function MEMIO_WRITE_FIELD 364 365 ******************************************************************************/ 366 #define MEMIO_WRITE_FIELD(vpMem, field, ui32Value) \ 367 MEMIO_CHECK_ALIGNMENT(vpMem); \ 368 (*((field##_TYPE *)(((IMG_UINTPTR_T)vpMem) + field##_OFFSET))) = \ 369 ((*((field##_TYPE *)(((IMG_UINTPTR_T)vpMem) + field##_OFFSET))) & (field##_TYPE)~field##_MASK) | \ 370 (field##_TYPE)(( (IMG_UINT32) (ui32Value) << field##_SHIFT) & field##_MASK); 371 372 #define MEMIO_WRITE_FIELD_LITE(vpMem, field, ui32Value) \ 373 MEMIO_CHECK_ALIGNMENT(vpMem); \ 374 (*((field##_TYPE *)(((IMG_UINTPTR_T)vpMem) + field##_OFFSET))) = \ 375 ((*((field##_TYPE *)(((IMG_UINTPTR_T)vpMem) + field##_OFFSET))) | \ 376 (field##_TYPE) (( (IMG_UINT32) (ui32Value) << field##_SHIFT)) ); 377 378 /*! 379 ****************************************************************************** 380 381 @Function MEMIO_WRITE_TABLE_FIELD 382 ******************************************************************************/ 383 #define MEMIO_WRITE_TABLE_FIELD(vpMem, field, ui32TabIndex, ui32Value) \ 384 MEMIO_CHECK_ALIGNMENT(vpMem); IMG_ASSERT(((ui32TabIndex) < field##_NO_ENTRIES) || (field##_NO_ENTRIES == 0)); \ 385 (*((field##_TYPE *)(((IMG_UINTPTR_T)vpMem) + field##_OFFSET + (field##_STRIDE * (ui32TabIndex))))) = \ 386 ((*((field##_TYPE *)(((IMG_UINTPTR_T)vpMem) + field##_OFFSET + (field##_STRIDE * (ui32TabIndex))))) & (field##_TYPE)~field##_MASK) | \ 387 (field##_TYPE)(( (IMG_UINT32) (ui32Value) << field##_SHIFT) & field##_MASK); 388 389 /*! 390 ****************************************************************************** 391 392 @Function MEMIO_WRITE_REPEATED_FIELD 393 394 ******************************************************************************/ 395 #define MEMIO_WRITE_REPEATED_FIELD(vpMem, field, ui32RepIndex, ui32Value) \ 396 MEMIO_CHECK_ALIGNMENT(vpMem); IMG_ASSERT((ui32RepIndex) < field##_NO_REPS); \ 397 (*((field##_TYPE *)(((IMG_UINTPTR_T)vpMem) + field##_OFFSET))) = \ 398 ((*((field##_TYPE *)(((IMG_UINTPTR_T)vpMem) + field##_OFFSET))) & (field##_TYPE)~(field##_MASK >> ((ui32RepIndex) * field##_SIZE)) | \ 399 (field##_TYPE)(( (IMG_UINT32) (ui32Value) << (field##_SHIFT - ((ui32RepIndex) * field##_SIZE))) & (field##_MASK >> ((ui32RepIndex) * field##_SIZE)))); 400 401 /*! 402 ****************************************************************************** 403 404 @Function MEMIO_WRITE_TABLE_REPEATED_FIELD 405 406 ******************************************************************************/ 407 #define MEMIO_WRITE_TABLE_REPEATED_FIELD(vpMem, field, ui32TabIndex, ui32RepIndex, ui32Value) \ 408 MEMIO_CHECK_ALIGNMENT(vpMem); IMG_ASSERT(((ui32TabIndex) < field##_NO_ENTRIES) || (field##_NO_ENTRIES == 0)); IMG_ASSERT((ui32RepIndex) < field##_NO_REPS); \ 409 (*((field##_TYPE *)(((IMG_UINTPTR_T)vpMem) + field##_OFFSET + (field##_STRIDE * (ui32TabIndex))))) = \ 410 ((*((field##_TYPE *)(((IMG_UINTPTR_T)vpMem) + field##_OFFSET + (field##_STRIDE * (ui32TabIndex))))) & (field##_TYPE)~(field##_MASK >> ((ui32RepIndex) * field##_SIZE))) | \ 411 (field##_TYPE)(( (IMG_UINT32) (ui32Value) << (field##_SHIFT - ((ui32RepIndex) * field##_SIZE))) & (field##_MASK >> ((ui32RepIndex) * field##_SIZE))); 412 413 #endif 414 415 416 #if (__cplusplus) 417 } 418 #endif 419 420 #endif 421 422