Andrew Jeffery | 7992eb8 | 2023-04-06 16:13:53 +0930 | [diff] [blame] | 1 | #ifndef PLDM_MSGBUF_PLATFORM_H |
| 2 | #define PLDM_MSGBUF_PLATFORM_H |
| 3 | |
| 4 | #include "../msgbuf.h" |
| 5 | #include <libpldm/base.h> |
| 6 | #include <libpldm/platform.h> |
| 7 | |
| 8 | static inline int |
| 9 | pldm_msgbuf_extract_value_pdr_hdr(struct pldm_msgbuf *ctx, |
| 10 | struct pldm_value_pdr_hdr *hdr) |
| 11 | { |
| 12 | pldm_msgbuf_extract(ctx, &hdr->record_handle); |
| 13 | pldm_msgbuf_extract(ctx, &hdr->version); |
| 14 | pldm_msgbuf_extract(ctx, &hdr->type); |
| 15 | pldm_msgbuf_extract(ctx, &hdr->record_change_num); |
| 16 | pldm_msgbuf_extract(ctx, &hdr->length); |
| 17 | |
| 18 | return pldm_msgbuf_validate(ctx); |
| 19 | } |
| 20 | |
| 21 | /* |
| 22 | * We use __attribute__((always_inline)) below so the compiler has visibility of |
| 23 | * the switch() at the call site. It is often the case that the size of multiple |
| 24 | * fields depends on the tag. Inlining thus gives the compiler visibility to |
| 25 | * hoist one tag-based code-path condition to cover all invocations. |
| 26 | */ |
| 27 | |
| 28 | __attribute__((always_inline)) static inline int |
| 29 | pldm_msgbuf_extract_sensor_data(struct pldm_msgbuf *ctx, |
| 30 | enum pldm_sensor_readings_data_type tag, |
| 31 | union_sensor_data_size *dst) |
| 32 | { |
| 33 | switch (tag) { |
| 34 | case PLDM_SENSOR_DATA_SIZE_UINT8: |
| 35 | return pldm_msgbuf_extract(ctx, &dst->value_u8); |
| 36 | case PLDM_SENSOR_DATA_SIZE_SINT8: |
| 37 | return pldm_msgbuf_extract(ctx, &dst->value_s8); |
| 38 | case PLDM_SENSOR_DATA_SIZE_UINT16: |
| 39 | return pldm_msgbuf_extract(ctx, &dst->value_u16); |
| 40 | case PLDM_SENSOR_DATA_SIZE_SINT16: |
| 41 | return pldm_msgbuf_extract(ctx, &dst->value_s16); |
| 42 | case PLDM_SENSOR_DATA_SIZE_UINT32: |
| 43 | return pldm_msgbuf_extract(ctx, &dst->value_u32); |
| 44 | case PLDM_SENSOR_DATA_SIZE_SINT32: |
| 45 | return pldm_msgbuf_extract(ctx, &dst->value_s32); |
| 46 | } |
| 47 | |
| 48 | return -PLDM_ERROR_INVALID_DATA; |
| 49 | } |
| 50 | |
| 51 | __attribute__((always_inline)) static inline int |
| 52 | pldm_msgbuf_extract_range_field_format(struct pldm_msgbuf *ctx, |
| 53 | enum pldm_range_field_format tag, |
| 54 | union_range_field_format *dst) |
| 55 | { |
| 56 | switch (tag) { |
| 57 | case PLDM_RANGE_FIELD_FORMAT_UINT8: |
| 58 | return pldm_msgbuf_extract(ctx, &dst->value_u8); |
| 59 | case PLDM_RANGE_FIELD_FORMAT_SINT8: |
| 60 | return pldm_msgbuf_extract(ctx, &dst->value_s8); |
| 61 | case PLDM_RANGE_FIELD_FORMAT_UINT16: |
| 62 | return pldm_msgbuf_extract(ctx, &dst->value_u16); |
| 63 | case PLDM_RANGE_FIELD_FORMAT_SINT16: |
| 64 | return pldm_msgbuf_extract(ctx, &dst->value_s16); |
| 65 | case PLDM_RANGE_FIELD_FORMAT_UINT32: |
| 66 | return pldm_msgbuf_extract(ctx, &dst->value_u32); |
| 67 | case PLDM_RANGE_FIELD_FORMAT_SINT32: |
| 68 | return pldm_msgbuf_extract(ctx, &dst->value_s32); |
| 69 | case PLDM_RANGE_FIELD_FORMAT_REAL32: |
| 70 | return pldm_msgbuf_extract(ctx, &dst->value_f32); |
| 71 | } |
| 72 | |
| 73 | return -PLDM_ERROR_INVALID_DATA; |
| 74 | } |
| 75 | |
| 76 | #endif |