|
| 1 | +#ifndef __SLRT_H__ |
| 2 | +#define __SLRT_H__ |
| 3 | + |
| 4 | +#include <defs.h> |
| 5 | +#include <types.h> |
| 6 | + |
| 7 | +struct slr_entry_hdr { |
| 8 | + u16 tag; |
| 9 | + u16 size; |
| 10 | +} __packed; |
| 11 | + |
| 12 | +#define SLR_ENTRY_INVALID 0x0000 |
| 13 | +#define SLR_ENTRY_DL_INFO 0x0001 |
| 14 | +#define SLR_ENTRY_LOG_INFO 0x0002 |
| 15 | +#define SLR_ENTRY_DRTM_POLICY 0x0003 |
| 16 | +#define SLR_ENTRY_INTEL_INFO 0x0004 |
| 17 | +#define SLR_ENTRY_AMD_INFO 0x0005 |
| 18 | +#define SLR_ENTRY_ARM_INFO 0x0006 |
| 19 | +#define SLR_ENTRY_UEFI_INFO 0x0007 |
| 20 | +#define SLR_ENTRY_UEFI_CONFIG 0x0008 |
| 21 | +#define SLR_ENTRY_END 0xffff |
| 22 | + |
| 23 | +struct slr_table { |
| 24 | + u32 magic; |
| 25 | + u16 revision; |
| 26 | + u16 architecture; |
| 27 | + u32 size; |
| 28 | + u32 max_size; |
| 29 | + /* Not really a flex array, don't use it that way! */ |
| 30 | + struct slr_entry_hdr entries[]; |
| 31 | +} __packed; |
| 32 | + |
| 33 | +struct slr_bl_context { |
| 34 | + u16 bootloader; |
| 35 | + u16 reserved; |
| 36 | + u64 context; |
| 37 | +} __packed; |
| 38 | + |
| 39 | +#define SLR_BOOTLOADER_GRUB 1 |
| 40 | + |
| 41 | +struct slr_entry_dl_info { |
| 42 | + struct slr_entry_hdr hdr; |
| 43 | + struct slr_bl_context bl_context; |
| 44 | + u64 dl_handler; |
| 45 | + u64 dce_base; |
| 46 | + u32 dce_size; |
| 47 | + u64 dlme_base; |
| 48 | + u32 dlme_size; |
| 49 | + u32 dlme_entry; /* Offset from dlme_base */ |
| 50 | +} __packed; |
| 51 | + |
| 52 | +struct slr_entry_log_info { |
| 53 | + struct slr_entry_hdr hdr; |
| 54 | + u16 format; |
| 55 | + u16 reserved; |
| 56 | + u64 addr; |
| 57 | + u32 size; |
| 58 | +} __packed; |
| 59 | + |
| 60 | +#define SLR_LOG_FORMAT_TPM12_TXT 1 |
| 61 | +#define SLR_LOG_FORMAT_TPM20_TCG 2 |
| 62 | + |
| 63 | +#define TPM_EVENT_INFO_LENGTH 20 |
| 64 | + |
| 65 | +struct slr_policy_entry { |
| 66 | + u16 pcr; |
| 67 | + u16 entity_type; |
| 68 | + u16 flags; |
| 69 | + u16 reserved; |
| 70 | + u64 entity; |
| 71 | + u64 size; |
| 72 | + char evt_info[TPM_EVENT_INFO_LENGTH]; |
| 73 | +} __packed; |
| 74 | + |
| 75 | +/* Constants for entity_type */ |
| 76 | +#define SLR_ET_UNSPECIFIED 0x0000 |
| 77 | +#define SLR_ET_SLRT 0x0001 |
| 78 | +#define SLR_ET_LINUX_BOOT_PARAMS 0x0002 |
| 79 | +#define SLR_ET_LINUX_SETUP_DATA 0x0003 |
| 80 | +#define SLR_ET_CMDLINE 0x0004 |
| 81 | +#define SLR_ET_UEFI_MEMMAP 0x0005 |
| 82 | +#define SLR_ET_RAMDISK 0x0006 |
| 83 | +#define SLR_ET_MULTIBOOT2_INFO 0x0007 |
| 84 | +#define SLR_ET_MULTIBOOT2_MODULE 0x0008 |
| 85 | +// values 0x0009-0x000f reserved for future use |
| 86 | +// TXT-specific: |
| 87 | +#define SLR_ET_TXT_OS2MLE 0x0010 |
| 88 | +#define SLR_ET_UNUSED 0xffff |
| 89 | + |
| 90 | +/* Constants for flags */ |
| 91 | +#define SLR_POLICY_FLAG_MEASURED 0x1 |
| 92 | +#define SLR_POLICY_IMPLICIT_SIZE 0x2 |
| 93 | + |
| 94 | +struct slr_entry_policy { |
| 95 | + struct slr_entry_hdr hdr; |
| 96 | + u16 revision; |
| 97 | + u16 nr_entries; |
| 98 | + struct slr_policy_entry policy_entries[]; |
| 99 | +} __packed; |
| 100 | + |
| 101 | +extern struct slr_table bootloader_data; |
| 102 | + |
| 103 | +static inline void *end_of_slrt(void) |
| 104 | +{ |
| 105 | + return _p(_u(&bootloader_data) + bootloader_data.size); |
| 106 | +} |
| 107 | + |
| 108 | +static inline void *next_entry(void* t) |
| 109 | +{ |
| 110 | + void *x = t + ((struct slr_entry_hdr*)t)->size; |
| 111 | + return x < end_of_slrt() ? x : NULL; |
| 112 | +} |
| 113 | + |
| 114 | +static inline void *next_entry_with_tag(void* _t, u16 tag) |
| 115 | +{ |
| 116 | + struct slr_entry_hdr *t = _t; |
| 117 | + if (t == NULL) { |
| 118 | + t = &bootloader_data.entries[0]; |
| 119 | + if ( t->tag == tag ) |
| 120 | + return (void*)t < end_of_slrt() ? t : NULL; |
| 121 | + } |
| 122 | + |
| 123 | + while ( t->tag != SLR_ENTRY_END ) |
| 124 | + { |
| 125 | + t = next_entry(t); |
| 126 | + if ( t->tag == tag ) |
| 127 | + return (void*)t < end_of_slrt() ? t : NULL; |
| 128 | + } |
| 129 | + return NULL; |
| 130 | +} |
| 131 | + |
| 132 | +#endif /* __SLRT_H__ */ |
0 commit comments