xref: /openbmc/linux/block/partitions/efi.h (revision cbdf59ad)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /************************************************************
3  * EFI GUID Partition Table
4  * Per Intel EFI Specification v1.02
5  * http://developer.intel.com/technology/efi/efi.htm
6  *
7  * By Matt Domsch <Matt_Domsch@dell.com>  Fri Sep 22 22:15:56 CDT 2000
8  *   Copyright 2000,2001 Dell Inc.
9  ************************************************************/
10 
11 #ifndef FS_PART_EFI_H_INCLUDED
12 #define FS_PART_EFI_H_INCLUDED
13 
14 #include <linux/types.h>
15 #include <linux/fs.h>
16 #include <linux/genhd.h>
17 #include <linux/kernel.h>
18 #include <linux/major.h>
19 #include <linux/string.h>
20 #include <linux/efi.h>
21 #include <linux/compiler.h>
22 
23 #define MSDOS_MBR_SIGNATURE 0xaa55
24 #define EFI_PMBR_OSTYPE_EFI 0xEF
25 #define EFI_PMBR_OSTYPE_EFI_GPT 0xEE
26 
27 #define GPT_MBR_PROTECTIVE  1
28 #define GPT_MBR_HYBRID      2
29 
30 #define GPT_HEADER_SIGNATURE 0x5452415020494645ULL
31 #define GPT_HEADER_REVISION_V1 0x00010000
32 #define GPT_PRIMARY_PARTITION_TABLE_LBA 1
33 
34 #define PARTITION_SYSTEM_GUID \
35     EFI_GUID( 0xC12A7328, 0xF81F, 0x11d2, \
36               0xBA, 0x4B, 0x00, 0xA0, 0xC9, 0x3E, 0xC9, 0x3B)
37 #define LEGACY_MBR_PARTITION_GUID \
38     EFI_GUID( 0x024DEE41, 0x33E7, 0x11d3, \
39               0x9D, 0x69, 0x00, 0x08, 0xC7, 0x81, 0xF3, 0x9F)
40 #define PARTITION_MSFT_RESERVED_GUID \
41     EFI_GUID( 0xE3C9E316, 0x0B5C, 0x4DB8, \
42               0x81, 0x7D, 0xF9, 0x2D, 0xF0, 0x02, 0x15, 0xAE)
43 #define PARTITION_BASIC_DATA_GUID \
44     EFI_GUID( 0xEBD0A0A2, 0xB9E5, 0x4433, \
45               0x87, 0xC0, 0x68, 0xB6, 0xB7, 0x26, 0x99, 0xC7)
46 #define PARTITION_LINUX_RAID_GUID \
47     EFI_GUID( 0xa19d880f, 0x05fc, 0x4d3b, \
48               0xa0, 0x06, 0x74, 0x3f, 0x0f, 0x84, 0x91, 0x1e)
49 #define PARTITION_LINUX_SWAP_GUID \
50     EFI_GUID( 0x0657fd6d, 0xa4ab, 0x43c4, \
51               0x84, 0xe5, 0x09, 0x33, 0xc8, 0x4b, 0x4f, 0x4f)
52 #define PARTITION_LINUX_LVM_GUID \
53     EFI_GUID( 0xe6d6d379, 0xf507, 0x44c2, \
54               0xa2, 0x3c, 0x23, 0x8f, 0x2a, 0x3d, 0xf9, 0x28)
55 
56 typedef struct _gpt_header {
57 	__le64 signature;
58 	__le32 revision;
59 	__le32 header_size;
60 	__le32 header_crc32;
61 	__le32 reserved1;
62 	__le64 my_lba;
63 	__le64 alternate_lba;
64 	__le64 first_usable_lba;
65 	__le64 last_usable_lba;
66 	efi_guid_t disk_guid;
67 	__le64 partition_entry_lba;
68 	__le32 num_partition_entries;
69 	__le32 sizeof_partition_entry;
70 	__le32 partition_entry_array_crc32;
71 
72 	/* The rest of the logical block is reserved by UEFI and must be zero.
73 	 * EFI standard handles this by:
74 	 *
75 	 * uint8_t		reserved2[ BlockSize - 92 ];
76 	 */
77 } __packed gpt_header;
78 
79 typedef struct _gpt_entry_attributes {
80 	u64 required_to_function:1;
81 	u64 reserved:47;
82         u64 type_guid_specific:16;
83 } __packed gpt_entry_attributes;
84 
85 typedef struct _gpt_entry {
86 	efi_guid_t partition_type_guid;
87 	efi_guid_t unique_partition_guid;
88 	__le64 starting_lba;
89 	__le64 ending_lba;
90 	gpt_entry_attributes attributes;
91 	efi_char16_t partition_name[72 / sizeof (efi_char16_t)];
92 } __packed gpt_entry;
93 
94 typedef struct _gpt_mbr_record {
95 	u8	boot_indicator; /* unused by EFI, set to 0x80 for bootable */
96 	u8	start_head;     /* unused by EFI, pt start in CHS */
97 	u8	start_sector;   /* unused by EFI, pt start in CHS */
98 	u8	start_track;
99 	u8	os_type;        /* EFI and legacy non-EFI OS types */
100 	u8	end_head;       /* unused by EFI, pt end in CHS */
101 	u8	end_sector;     /* unused by EFI, pt end in CHS */
102 	u8	end_track;      /* unused by EFI, pt end in CHS */
103 	__le32	starting_lba;   /* used by EFI - start addr of the on disk pt */
104 	__le32	size_in_lba;    /* used by EFI - size of pt in LBA */
105 } __packed gpt_mbr_record;
106 
107 
108 typedef struct _legacy_mbr {
109 	u8 boot_code[440];
110 	__le32 unique_mbr_signature;
111 	__le16 unknown;
112 	gpt_mbr_record partition_record[4];
113 	__le16 signature;
114 } __packed legacy_mbr;
115 
116 /* Functions */
117 extern int efi_partition(struct parsed_partitions *state);
118 
119 #endif
120