xref: /titanic_50/usr/src/uts/common/sys/efi_partition.h (revision fa9e4066f08beec538e775443c5be79dd423fcab)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_EFI_PARTITION_H
28 #define	_SYS_EFI_PARTITION_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/uuid.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 /*
39  * GUID Partition Table Header
40  */
41 
42 #define	EFI_LABEL_SIZE	512
43 #define	LEN_EFI_PAD	(EFI_LABEL_SIZE - \
44 			    ((5 * sizeof (diskaddr_t)) + \
45 			    (7 * sizeof (uint_t)) + \
46 			    (8 * sizeof (char)) + \
47 			    (1 * (sizeof (struct uuid)))))
48 
49 #define	EFI_SIGNATURE	0x5452415020494645ULL
50 
51 /* EFI Guid Partition Table Header -- little endian on-disk format */
52 typedef struct efi_gpt {
53 	uint64_t	efi_gpt_Signature;
54 	uint_t		efi_gpt_Revision;
55 	uint_t		efi_gpt_HeaderSize;
56 	uint_t		efi_gpt_HeaderCRC32;
57 	uint_t		efi_gpt_Reserved1;
58 	diskaddr_t	efi_gpt_MyLBA;
59 	diskaddr_t	efi_gpt_AlternateLBA;
60 	diskaddr_t	efi_gpt_FirstUsableLBA;
61 	diskaddr_t	efi_gpt_LastUsableLBA;
62 	struct uuid	efi_gpt_DiskGUID;
63 	diskaddr_t	efi_gpt_PartitionEntryLBA;
64 	uint_t		efi_gpt_NumberOfPartitionEntries;
65 	uint_t		efi_gpt_SizeOfPartitionEntry;
66 	uint_t		efi_gpt_PartitionEntryArrayCRC32;
67 	char		efi_gpt_Reserved2[LEN_EFI_PAD];
68 } efi_gpt_t;
69 
70 /* EFI Guid Partition Entry Attributes -- little endian format */
71 typedef struct efi_gpe_Attrs {
72 	uint32_t	PartitionAttrs		:16,
73 			Reserved2		:16;
74 	uint32_t	Reserved1		:31,
75 			RequiredPartition	:1;
76 } efi_gpe_Attrs_t;
77 
78 /*
79  * 6a96237f-1dd2-11b2-99a6-080020736631	V_UNASSIGNED (not used as such)
80  * 6a82cb45-1dd2-11b2-99a6-080020736631	V_BOOT
81  * 6a85cf4d-1dd2-11b2-99a6-080020736631	V_ROOT
82  * 6a87c46f-1dd2-11b2-99a6-080020736631	V_SWAP
83  * 6a898cc3-1dd2-11b2-99a6-080020736631	V_USR
84  * 6a8b642b-1dd2-11b2-99a6-080020736631	V_BACKUP
85  * 6a8d2ac7-1dd2-11b2-99a6-080020736631	V_STAND (not used)
86  * 6a8ef2e9-1dd2-11b2-99a6-080020736631	V_VAR
87  * 6a90ba39-1dd2-11b2-99a6-080020736631	V_HOME
88  * 6a9283a5-1dd2-11b2-99a6-080020736631	V_ALTSCTR
89  * 6a945a3b-1dd2-11b2-99a6-080020736631	V_CACHE
90  */
91 
92 #define	EFI_UNUSED	{ 0x00000000, 0x0000, 0x0000, 0x00, 0x00, \
93 			    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }
94 #define	EFI_RESV1	{ 0x6a96237f, 0x1dd2, 0x11b2, 0x99, 0xa6, \
95 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
96 #define	EFI_BOOT	{ 0x6a82cb45, 0x1dd2, 0x11b2, 0x99, 0xa6, \
97 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
98 #define	EFI_ROOT	{ 0x6a85cf4d, 0x1dd2, 0x11b2, 0x99, 0xa6, \
99 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
100 #define	EFI_SWAP	{ 0x6a87c46f, 0x1dd2, 0x11b2, 0x99, 0xa6, \
101 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
102 #define	EFI_USR		{ 0x6a898cc3, 0x1dd2, 0x11b2, 0x99, 0xa6, \
103 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
104 #define	EFI_BACKUP	{ 0x6a8b642b, 0x1dd2, 0x11b2, 0x99, 0xa6, \
105 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
106 #define	EFI_RESV2	{ 0x6a8d2ac7, 0x1dd2, 0x11b2, 0x99, 0xa6, \
107 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
108 #define	EFI_VAR		{ 0x6a8ef2e9, 0x1dd2, 0x11b2, 0x99, 0xa6, \
109 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
110 #define	EFI_HOME	{ 0x6a90ba39, 0x1dd2, 0x11b2, 0x99, 0xa6, \
111 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
112 #define	EFI_ALTSCTR	{ 0x6a9283a5, 0x1dd2, 0x11b2, 0x99, 0xa6, \
113 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
114 #define	EFI_RESERVED	{ 0x6a945a3b, 0x1dd2, 0x11b2, 0x99, 0xa6, \
115 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
116 #define	EFI_SYSTEM	{ 0xC12A7328, 0xF81F, 0x11d2, 0xBA, 0x4B, \
117 			    { 0x00, 0xA0, 0xC9, 0x3E, 0xC9, 0x3B } }
118 #define	EFI_LEGACY_MBR	{ 0x024DEE41, 0x33E7, 0x11d3, 0x9D, 0x69, \
119 			    { 0x00, 0x08, 0xC7, 0x81, 0xF3, 0x9F } }
120 #define	EFI_RESV3	{ 0x6a9630d1, 0x1dd2, 0x11b2, 0x99, 0xa6, \
121 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
122 #define	EFI_RESV4	{ 0x6a980767, 0x1dd2, 0x11b2, 0x99, 0xa6, \
123 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
124 #define	EFI_MSFT_RESV	{ 0xE3C9E316, 0x0B5C, 0x4DB8, 0x81, 0x7D, \
125 			    { 0xF9, 0x2D, 0xF0, 0x02, 0x15, 0xAE } }
126 #define	EFI_DELL_BASIC	{ 0xebd0a0a2, 0xb9e5, 0x4433, 0x87, 0xc0, \
127 			    { 0x68, 0xb6, 0xb7, 0x26, 0x99, 0xc7 } }
128 #define	EFI_DELL_RAID	{ 0xa19d880f, 0x05fc, 0x4d3b, 0xa0, 0x06, \
129 			    { 0x74, 0x3f, 0x0f, 0x84, 0x91, 0x1e } }
130 #define	EFI_DELL_SWAP	{ 0x0657fd6d, 0xa4ab, 0x43c4, 0x84, 0xe5, \
131 			    { 0x09, 0x33, 0xc8, 0x4b, 0x4f, 0x4f } }
132 #define	EFI_DELL_LVM	{ 0xe6d6d379, 0xf507, 0x44c2, 0xa2, 0x3c, \
133 			    { 0x23, 0x8f, 0x2a, 0x3d, 0xf9, 0x28 } }
134 #define	EFI_DELL_RESV	{ 0x8da63339, 0x0007, 0x60c0, 0xc4, 0x36, \
135 			    { 0x08, 0x3a, 0xc8, 0x23, 0x09, 0x08 } }
136 
137 #define	EFI_MIN_ARRAY_SIZE	(16 * 1024)
138 
139 #define	EFI_PART_NAME_LEN	36
140 
141 /* EFI Guid Partition Entry */
142 typedef struct efi_gpe {
143 	struct uuid	efi_gpe_PartitionTypeGUID;
144 	struct uuid	efi_gpe_UniquePartitionGUID;
145 	diskaddr_t	efi_gpe_StartingLBA;
146 	diskaddr_t	efi_gpe_EndingLBA;
147 	efi_gpe_Attrs_t	efi_gpe_Attributes;
148 	ushort_t	efi_gpe_PartitionName[EFI_PART_NAME_LEN];
149 } efi_gpe_t;
150 
151 /*
152  * passed to the useful (we hope) routines (efi_alloc_and_read and
153  * efi_write) that take this VTOC-like struct.  These routines handle
154  * converting this struct into the EFI struct, generate UUIDs and
155  * checksums, and perform any necessary byte-swapping to the on-disk
156  * format.
157  */
158 /* Solaris library abstraction for EFI partitons */
159 typedef struct dk_part	{
160 	diskaddr_t	p_start;	/* starting LBA */
161 	diskaddr_t	p_size;		/* size in blocks */
162 	struct uuid	p_guid;		/* partion type GUID */
163 	ushort_t	p_tag;		/* converted to part'n type GUID */
164 	ushort_t	p_flag;		/* attributes */
165 	char		p_name[EFI_PART_NAME_LEN]; /* partition name */
166 	struct uuid	p_uguid;	/* unique partition GUID */
167 	uint_t		p_resv[8];	/* future use - set to zero */
168 } dk_part_t;
169 
170 /* Solaris library abstraction for an EFI GPT */
171 #define	EFI_VERSION102		0x00010002
172 #define	EFI_VERSION100		0x00010000
173 #define	EFI_VERSION_CURRENT	EFI_VERSION100
174 typedef struct dk_gpt {
175 	uint_t		efi_version;	/* set to EFI_VERSION_CURRENT */
176 	uint_t		efi_nparts;	/* number of partitions below */
177 	uint_t		efi_part_size;	/* size of each partition entry */
178 					/* efi_part_size is unused */
179 	uint_t		efi_lbasize;	/* size of block in bytes */
180 	diskaddr_t	efi_last_lba;	/* last block on the disk */
181 	diskaddr_t	efi_first_u_lba; /* first block after labels */
182 	diskaddr_t	efi_last_u_lba;	/* last block before backup labels */
183 	struct uuid	efi_disk_uguid;	/* unique disk GUID */
184 	uint_t		efi_flags;
185 	uint_t		efi_reserved[15]; /* future use - set to zero */
186 	struct dk_part	efi_parts[1];	/* array of partitions */
187 } dk_gpt_t;
188 
189 /* possible values for "efi_flags" */
190 #define	EFI_GPT_PRIMARY_CORRUPT	0x1	/* primary label corrupt */
191 
192 /* the private ioctl between libefi and the driver */
193 typedef struct dk_efi {
194 	diskaddr_t	 dki_lba;	/* starting block */
195 	len_t		 dki_length;	/* length in bytes */
196 	union {
197 		efi_gpt_t 	*_dki_data;
198 		uint64_t	_dki_data_64;
199 	} dki_un;
200 #define	dki_data	dki_un._dki_data
201 #define	dki_data_64	dki_un._dki_data_64
202 } dk_efi_t;
203 
204 struct partition64 {
205 	struct uuid	p_type;
206 	uint_t		p_partno;
207 	uint_t		p_resv1;
208 	diskaddr_t	p_start;
209 	diskaddr_t	p_size;
210 };
211 
212 /*
213  * Number of EFI partitions
214  */
215 #define	EFI_NUMPAR	9
216 
217 #ifndef _KERNEL
218 extern	int	efi_alloc_and_init(int, uint32_t, struct dk_gpt **);
219 extern	int	efi_alloc_and_read(int, struct dk_gpt **);
220 extern	int	efi_write(int, struct dk_gpt *);
221 extern	void	efi_free(struct dk_gpt *);
222 extern	int	efi_type(int);
223 extern	void	efi_err_check(struct dk_gpt *);
224 extern	int	efi_auto_sense(int fd, struct dk_gpt **);
225 #endif
226 
227 #ifdef __cplusplus
228 }
229 #endif
230 
231 #endif /* _SYS_EFI_PARTITION_H */
232