sds_private.h 3.6 KB

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