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