Furquan Shaikh | d7fb6a9 | 2021-09-16 22:04:11 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #ifndef __CBFSTOOL_CSE_SERGER_H__ |
| 4 | #define __CBFSTOOL_CSE_SERGER_H__ |
| 5 | |
| 6 | #include <commonlib/endian.h> |
| 7 | #include <commonlib/region.h> |
| 8 | |
| 9 | #include "common.h" |
Furquan Shaikh | 555f040 | 2021-10-08 15:18:33 -0700 | [diff] [blame] | 10 | #include "cse_helpers.h" |
Furquan Shaikh | d7fb6a9 | 2021-09-16 22:04:11 -0700 | [diff] [blame] | 11 | |
| 12 | #define BPDT_SIGNATURE (0x000055AA) |
| 13 | |
| 14 | #define BUFF_SIZE_ALIGN (4 * KiB) |
| 15 | |
Furquan Shaikh | d7fb6a9 | 2021-09-16 22:04:11 -0700 | [diff] [blame] | 16 | enum bpdt_version { |
| 17 | BPDT_VERSION_1_6 = 1, |
| 18 | BPDT_VERSION_1_7 = 2, |
| 19 | }; |
| 20 | |
| 21 | enum subpart_hdr_version { |
| 22 | SUBPART_HDR_VERSION_1 = 1, |
| 23 | SUBPART_HDR_VERSION_2 = 2, |
| 24 | }; |
| 25 | |
| 26 | enum subpart_entry_version { |
| 27 | SUBPART_ENTRY_VERSION_1 = 1, |
| 28 | }; |
| 29 | |
Furquan Shaikh | 8b4ca15 | 2021-10-09 23:06:09 -0700 | [diff] [blame] | 30 | enum { |
| 31 | DP, |
| 32 | BP1, |
| 33 | BP2, |
| 34 | BP3, |
| 35 | BP4, |
| 36 | BP_TOTAL, |
Furquan Shaikh | d7fb6a9 | 2021-09-16 22:04:11 -0700 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | typedef void *cse_layout_ptr; |
| 40 | typedef void *bpdt_hdr_ptr; |
| 41 | typedef void *subpart_hdr_ptr; |
| 42 | |
| 43 | struct bpdt_entry { |
| 44 | uint32_t type; |
| 45 | uint32_t offset; |
| 46 | uint32_t size; |
| 47 | } __packed; |
| 48 | |
| 49 | struct bpdt_ops { |
| 50 | bool (*match_version)(const struct buffer *buff); |
| 51 | |
| 52 | bpdt_hdr_ptr (*create_hdr)(void); |
| 53 | void (*print_hdr)(const bpdt_hdr_ptr ptr); |
| 54 | bpdt_hdr_ptr (*read_hdr)(struct buffer *buff); |
| 55 | int (*write_hdr)(struct buffer *buff, const bpdt_hdr_ptr ptr); |
| 56 | |
| 57 | size_t (*get_entry_count)(const bpdt_hdr_ptr ptr); |
| 58 | void (*inc_entry_count)(bpdt_hdr_ptr ptr); |
| 59 | |
Furquan Shaikh | 8b4ca15 | 2021-10-09 23:06:09 -0700 | [diff] [blame] | 60 | cse_layout_ptr (*create_layout)(const struct region *regions); |
Furquan Shaikh | d7fb6a9 | 2021-09-16 22:04:11 -0700 | [diff] [blame] | 61 | void (*print_layout)(const cse_layout_ptr ptr); |
| 62 | cse_layout_ptr (*read_layout)(struct buffer *buff); |
| 63 | int (*write_layout)(struct buffer *buff, const cse_layout_ptr ptr); |
| 64 | |
| 65 | void (*update_checksum)(bpdt_hdr_ptr ptr, struct bpdt_entry *entry); |
| 66 | bool (*validate_checksum)(bpdt_hdr_ptr ptr, struct bpdt_entry *entry); |
| 67 | |
| 68 | enum subpart_hdr_version subpart_hdr_version; |
| 69 | enum subpart_entry_version subpart_entry_version; |
| 70 | }; |
| 71 | |
| 72 | struct subpart_hdr_ops { |
| 73 | subpart_hdr_ptr (*read)(struct buffer *buffer); |
| 74 | void (*print)(const subpart_hdr_ptr ptr); |
| 75 | size_t (*get_entry_count)(const subpart_hdr_ptr ptr); |
| 76 | void (*free)(subpart_hdr_ptr ptr); |
| 77 | }; |
| 78 | |
| 79 | struct subpart_entry_ops { |
| 80 | void (*print)(struct buffer *buff, size_t size); |
| 81 | }; |
| 82 | |
| 83 | extern const struct bpdt_ops bpdt_1_7_ops; |
| 84 | extern const struct bpdt_ops bpdt_1_6_ops; |
| 85 | |
| 86 | extern const struct subpart_hdr_ops subpart_hdr_1_ops; |
| 87 | extern const struct subpart_hdr_ops subpart_hdr_2_ops; |
| 88 | |
| 89 | extern const struct subpart_entry_ops subpart_entry_1_ops; |
| 90 | |
Furquan Shaikh | d7fb6a9 | 2021-09-16 22:04:11 -0700 | [diff] [blame] | 91 | #endif /* __CBFSTOOL_CSE_SERGER_H__ */ |