1 /* 2 * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef SDS_PRIVATE_H 8 #define SDS_PRIVATE_H 9 10 /* SDS Header defines */ 11 #define SDS_HEADER_ID_SHIFT 0 12 #define SDS_HEADER_ID_WIDTH 16 13 #define SDS_HEADER_ID_MASK ((1 << SDS_HEADER_ID_WIDTH) - 1) 14 15 #define SDS_HEADER_MINOR_VERSION_WIDTH 8 16 #define SDS_HEADER_MINOR_VERSION_SHIFT 16 17 #define SDS_HEADER_MAJOR_VERSION_WIDTH 8 18 19 #define MAKE_SDS_HEADER_VERSION(major, minor) \ 20 (((((major) & 0xff) << SDS_HEADER_MINOR_VERSION_WIDTH) | ((minor) & 0xff))) 21 #define SDS_HEADER_VERSION_MASK \ 22 ((1 << (SDS_HEADER_MINOR_VERSION_WIDTH + SDS_HEADER_MAJOR_VERSION_WIDTH)) - 1) 23 24 #define SDS_HEADER_VERSION MAKE_SDS_HEADER_VERSION(1, 0) 25 #define SDS_HEADER_STRUCT_SIZE_WIDTH 23 26 #define SDS_HEADER_STRUCT_SIZE_SHIFT 1 27 #define SDS_HEADER_STRUCT_SIZE_MASK ((1 << SDS_HEADER_STRUCT_SIZE_WIDTH) - 1) 28 #define SDS_HEADER_VALID_MASK 0x1 29 #define SDS_HEADER_VALID_SHIFT 0 30 #define SDS_HEADER_SIZE 0x8 31 32 /* Arbitrary, 16 bit value that indicates a valid SDS Memory Region */ 33 #define SDS_REGION_SIGNATURE 0xAA7A 34 #define SDS_REGION_SIGNATURE_WIDTH 16 35 #define SDS_REGION_SIGNATURE_SHIFT 0 36 #define SDS_REGION_SIGNATURE_MASK ((1 << SDS_REGION_SIGNATURE_WIDTH) - 1) 37 38 #define SDS_REGION_STRUCT_COUNT_SHIFT 16 39 #define SDS_REGION_STRUCT_COUNT_WIDTH 8 40 #define SDS_REGION_STRUCT_COUNT_MASK ((1 << SDS_REGION_STRUCT_COUNT_WIDTH) - 1) 41 42 #define SDS_REGION_SCH_MINOR_SHIFT 24 43 #define SDS_REGION_SCH_MINOR_WIDTH 4 44 #define SDS_REGION_SCH_MINOR_MASK ((1 << SDS_REGION_SCH_MINOR_WIDTH) - 1) 45 46 #define SDS_REGION_SCH_MAJOR_SHIFT 28 47 #define SDS_REGION_SCH_MAJOR_WIDTH 4 48 #define SDS_REGION_SCH_MAJOR_MASK ((1 << SDS_REGION_SCH_MAJOR_WIDTH) - 1) 49 50 #define SDS_REGION_SCH_VERSION_MASK \ 51 ((1 << (SDS_REGION_SCH_MINOR_WIDTH + SDS_REGION_SCH_MAJOR_WIDTH)) - 1) 52 53 #define MAKE_SDS_REGION_SCH_VERSION(maj, min) \ 54 ((((maj) & SDS_REGION_SCH_MAJOR_MASK) << SDS_REGION_SCH_MINOR_WIDTH) | \ 55 ((min) & SDS_REGION_SCH_MINOR_MASK)) 56 57 #define SDS_REGION_SCH_VERSION MAKE_SDS_REGION_SCH_VERSION(1, 0) 58 #define SDS_REGION_REGIONSIZE_OFFSET 0x4 59 #define SDS_REGION_DESC_SIZE 0x8 60 61 #ifndef __ASSEMBLER__ 62 #include <stddef.h> 63 #include <stdint.h> 64 65 /* Header containing Shared Data Structure metadata */ 66 typedef struct structure_header { 67 uint32_t reg[2]; 68 } struct_header_t; 69 70 #define GET_SDS_HEADER_ID(_header) \ 71 ((((struct_header_t *)(_header))->reg[0]) & SDS_HEADER_ID_MASK) 72 #define GET_SDS_HEADER_VERSION(_header) \ 73 (((((struct_header_t *)(_header))->reg[0]) >> SDS_HEADER_MINOR_VERSION_SHIFT)\ 74 & SDS_HEADER_VERSION_MASK) 75 #define GET_SDS_HEADER_STRUCT_SIZE(_header) \ 76 (((((struct_header_t *)(_header))->reg[1]) >> SDS_HEADER_STRUCT_SIZE_SHIFT)\ 77 & SDS_HEADER_STRUCT_SIZE_MASK) 78 #define IS_SDS_HEADER_VALID(_header) \ 79 ((((struct_header_t *)(_header))->reg[1]) & SDS_HEADER_VALID_MASK) 80 #define GET_SDS_STRUCT_FIELD(_header, _field_offset) \ 81 ((((uint8_t *)(_header)) + sizeof(struct_header_t)) + (_field_offset)) 82 83 /* Region Descriptor describing the SDS Memory Region */ 84 typedef struct region_descriptor { 85 uint32_t reg[2]; 86 } region_desc_t; 87 88 #define IS_SDS_REGION_VALID(region) \ 89 (((((region_desc_t *)(region))->reg[0]) & SDS_REGION_SIGNATURE_MASK) == SDS_REGION_SIGNATURE) 90 #define GET_SDS_REGION_STRUCTURE_COUNT(region) \ 91 (((((region_desc_t *)(region))->reg[0]) >> SDS_REGION_STRUCT_COUNT_SHIFT)\ 92 & SDS_REGION_STRUCT_COUNT_MASK) 93 #define GET_SDS_REGION_SCHEMA_VERSION(region) \ 94 (((((region_desc_t *)(region))->reg[0]) >> SDS_REGION_SCH_MINOR_SHIFT)\ 95 & SDS_REGION_SCH_VERSION_MASK) 96 #define GET_SDS_REGION_SIZE(region) ((((region_desc_t *)(region))->reg[1])) 97 98 #endif /* __ASSEMBLER__ */ 99 100 #endif /* SDS_PRIVATE_H */ 101