17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5f2be5148Sszhou  * Common Development and Distribution License (the "License").
6f2be5148Sszhou  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*af007057Syl  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_SYS_EFI_PARTITION_H
277c478bd9Sstevel@tonic-gate #define	_SYS_EFI_PARTITION_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <sys/uuid.h>
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
347c478bd9Sstevel@tonic-gate extern "C" {
357c478bd9Sstevel@tonic-gate #endif
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate /*
387c478bd9Sstevel@tonic-gate  * GUID Partition Table Header
397c478bd9Sstevel@tonic-gate  */
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #define	EFI_LABEL_SIZE	512
427c478bd9Sstevel@tonic-gate #define	LEN_EFI_PAD	(EFI_LABEL_SIZE - \
437c478bd9Sstevel@tonic-gate 			    ((5 * sizeof (diskaddr_t)) + \
447c478bd9Sstevel@tonic-gate 			    (7 * sizeof (uint_t)) + \
457c478bd9Sstevel@tonic-gate 			    (8 * sizeof (char)) + \
467c478bd9Sstevel@tonic-gate 			    (1 * (sizeof (struct uuid)))))
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate #define	EFI_SIGNATURE	0x5452415020494645ULL
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate /* EFI Guid Partition Table Header -- little endian on-disk format */
517c478bd9Sstevel@tonic-gate typedef struct efi_gpt {
527c478bd9Sstevel@tonic-gate 	uint64_t	efi_gpt_Signature;
537c478bd9Sstevel@tonic-gate 	uint_t		efi_gpt_Revision;
547c478bd9Sstevel@tonic-gate 	uint_t		efi_gpt_HeaderSize;
557c478bd9Sstevel@tonic-gate 	uint_t		efi_gpt_HeaderCRC32;
567c478bd9Sstevel@tonic-gate 	uint_t		efi_gpt_Reserved1;
577c478bd9Sstevel@tonic-gate 	diskaddr_t	efi_gpt_MyLBA;
587c478bd9Sstevel@tonic-gate 	diskaddr_t	efi_gpt_AlternateLBA;
597c478bd9Sstevel@tonic-gate 	diskaddr_t	efi_gpt_FirstUsableLBA;
607c478bd9Sstevel@tonic-gate 	diskaddr_t	efi_gpt_LastUsableLBA;
617c478bd9Sstevel@tonic-gate 	struct uuid	efi_gpt_DiskGUID;
627c478bd9Sstevel@tonic-gate 	diskaddr_t	efi_gpt_PartitionEntryLBA;
637c478bd9Sstevel@tonic-gate 	uint_t		efi_gpt_NumberOfPartitionEntries;
647c478bd9Sstevel@tonic-gate 	uint_t		efi_gpt_SizeOfPartitionEntry;
657c478bd9Sstevel@tonic-gate 	uint_t		efi_gpt_PartitionEntryArrayCRC32;
667c478bd9Sstevel@tonic-gate 	char		efi_gpt_Reserved2[LEN_EFI_PAD];
677c478bd9Sstevel@tonic-gate } efi_gpt_t;
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate /* EFI Guid Partition Entry Attributes -- little endian format */
707c478bd9Sstevel@tonic-gate typedef struct efi_gpe_Attrs {
717c478bd9Sstevel@tonic-gate 	uint32_t	PartitionAttrs		:16,
727c478bd9Sstevel@tonic-gate 			Reserved2		:16;
737c478bd9Sstevel@tonic-gate 	uint32_t	Reserved1		:31,
747c478bd9Sstevel@tonic-gate 			RequiredPartition	:1;
757c478bd9Sstevel@tonic-gate } efi_gpe_Attrs_t;
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate  * 6a96237f-1dd2-11b2-99a6-080020736631	V_UNASSIGNED (not used as such)
797c478bd9Sstevel@tonic-gate  * 6a82cb45-1dd2-11b2-99a6-080020736631	V_BOOT
807c478bd9Sstevel@tonic-gate  * 6a85cf4d-1dd2-11b2-99a6-080020736631	V_ROOT
817c478bd9Sstevel@tonic-gate  * 6a87c46f-1dd2-11b2-99a6-080020736631	V_SWAP
827c478bd9Sstevel@tonic-gate  * 6a898cc3-1dd2-11b2-99a6-080020736631	V_USR
837c478bd9Sstevel@tonic-gate  * 6a8b642b-1dd2-11b2-99a6-080020736631	V_BACKUP
847c478bd9Sstevel@tonic-gate  * 6a8d2ac7-1dd2-11b2-99a6-080020736631	V_STAND (not used)
857c478bd9Sstevel@tonic-gate  * 6a8ef2e9-1dd2-11b2-99a6-080020736631	V_VAR
867c478bd9Sstevel@tonic-gate  * 6a90ba39-1dd2-11b2-99a6-080020736631	V_HOME
877c478bd9Sstevel@tonic-gate  * 6a9283a5-1dd2-11b2-99a6-080020736631	V_ALTSCTR
887c478bd9Sstevel@tonic-gate  * 6a945a3b-1dd2-11b2-99a6-080020736631	V_CACHE
897c478bd9Sstevel@tonic-gate  */
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate #define	EFI_UNUSED	{ 0x00000000, 0x0000, 0x0000, 0x00, 0x00, \
927c478bd9Sstevel@tonic-gate 			    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }
937c478bd9Sstevel@tonic-gate #define	EFI_RESV1	{ 0x6a96237f, 0x1dd2, 0x11b2, 0x99, 0xa6, \
947c478bd9Sstevel@tonic-gate 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
957c478bd9Sstevel@tonic-gate #define	EFI_BOOT	{ 0x6a82cb45, 0x1dd2, 0x11b2, 0x99, 0xa6, \
967c478bd9Sstevel@tonic-gate 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
977c478bd9Sstevel@tonic-gate #define	EFI_ROOT	{ 0x6a85cf4d, 0x1dd2, 0x11b2, 0x99, 0xa6, \
987c478bd9Sstevel@tonic-gate 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
997c478bd9Sstevel@tonic-gate #define	EFI_SWAP	{ 0x6a87c46f, 0x1dd2, 0x11b2, 0x99, 0xa6, \
1007c478bd9Sstevel@tonic-gate 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
1017c478bd9Sstevel@tonic-gate #define	EFI_USR		{ 0x6a898cc3, 0x1dd2, 0x11b2, 0x99, 0xa6, \
1027c478bd9Sstevel@tonic-gate 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
1037c478bd9Sstevel@tonic-gate #define	EFI_BACKUP	{ 0x6a8b642b, 0x1dd2, 0x11b2, 0x99, 0xa6, \
1047c478bd9Sstevel@tonic-gate 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
1057c478bd9Sstevel@tonic-gate #define	EFI_RESV2	{ 0x6a8d2ac7, 0x1dd2, 0x11b2, 0x99, 0xa6, \
1067c478bd9Sstevel@tonic-gate 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
1077c478bd9Sstevel@tonic-gate #define	EFI_VAR		{ 0x6a8ef2e9, 0x1dd2, 0x11b2, 0x99, 0xa6, \
1087c478bd9Sstevel@tonic-gate 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
1097c478bd9Sstevel@tonic-gate #define	EFI_HOME	{ 0x6a90ba39, 0x1dd2, 0x11b2, 0x99, 0xa6, \
1107c478bd9Sstevel@tonic-gate 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
1117c478bd9Sstevel@tonic-gate #define	EFI_ALTSCTR	{ 0x6a9283a5, 0x1dd2, 0x11b2, 0x99, 0xa6, \
1127c478bd9Sstevel@tonic-gate 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
1137c478bd9Sstevel@tonic-gate #define	EFI_RESERVED	{ 0x6a945a3b, 0x1dd2, 0x11b2, 0x99, 0xa6, \
1147c478bd9Sstevel@tonic-gate 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
1157c478bd9Sstevel@tonic-gate #define	EFI_SYSTEM	{ 0xC12A7328, 0xF81F, 0x11d2, 0xBA, 0x4B, \
1167c478bd9Sstevel@tonic-gate 			    { 0x00, 0xA0, 0xC9, 0x3E, 0xC9, 0x3B } }
1177c478bd9Sstevel@tonic-gate #define	EFI_LEGACY_MBR	{ 0x024DEE41, 0x33E7, 0x11d3, 0x9D, 0x69, \
1187c478bd9Sstevel@tonic-gate 			    { 0x00, 0x08, 0xC7, 0x81, 0xF3, 0x9F } }
1197c478bd9Sstevel@tonic-gate #define	EFI_RESV3	{ 0x6a9630d1, 0x1dd2, 0x11b2, 0x99, 0xa6, \
1207c478bd9Sstevel@tonic-gate 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
1217c478bd9Sstevel@tonic-gate #define	EFI_RESV4	{ 0x6a980767, 0x1dd2, 0x11b2, 0x99, 0xa6, \
1227c478bd9Sstevel@tonic-gate 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
1237c478bd9Sstevel@tonic-gate #define	EFI_MSFT_RESV	{ 0xE3C9E316, 0x0B5C, 0x4DB8, 0x81, 0x7D, \
1247c478bd9Sstevel@tonic-gate 			    { 0xF9, 0x2D, 0xF0, 0x02, 0x15, 0xAE } }
1257c478bd9Sstevel@tonic-gate #define	EFI_DELL_BASIC	{ 0xebd0a0a2, 0xb9e5, 0x4433, 0x87, 0xc0, \
1267c478bd9Sstevel@tonic-gate 			    { 0x68, 0xb6, 0xb7, 0x26, 0x99, 0xc7 } }
1277c478bd9Sstevel@tonic-gate #define	EFI_DELL_RAID	{ 0xa19d880f, 0x05fc, 0x4d3b, 0xa0, 0x06, \
1287c478bd9Sstevel@tonic-gate 			    { 0x74, 0x3f, 0x0f, 0x84, 0x91, 0x1e } }
1297c478bd9Sstevel@tonic-gate #define	EFI_DELL_SWAP	{ 0x0657fd6d, 0xa4ab, 0x43c4, 0x84, 0xe5, \
1307c478bd9Sstevel@tonic-gate 			    { 0x09, 0x33, 0xc8, 0x4b, 0x4f, 0x4f } }
1317c478bd9Sstevel@tonic-gate #define	EFI_DELL_LVM	{ 0xe6d6d379, 0xf507, 0x44c2, 0xa2, 0x3c, \
1327c478bd9Sstevel@tonic-gate 			    { 0x23, 0x8f, 0x2a, 0x3d, 0xf9, 0x28 } }
1337c478bd9Sstevel@tonic-gate #define	EFI_DELL_RESV	{ 0x8da63339, 0x0007, 0x60c0, 0xc4, 0x36, \
1347c478bd9Sstevel@tonic-gate 			    { 0x08, 0x3a, 0xc8, 0x23, 0x09, 0x08 } }
135f2be5148Sszhou #define	EFI_AAPL_HFS	{ 0x48465300, 0x0000, 0x11aa, 0xaa, 0x11, \
136f2be5148Sszhou 			    { 0x00, 0x30, 0x65, 0x43, 0xec, 0xac } }
137f2be5148Sszhou #define	EFI_AAPL_UFS	{ 0x55465300, 0x0000, 0x11aa, 0xaa, 0x11, \
138f2be5148Sszhou 			    { 0x00, 0x30, 0x65, 0x43, 0xec, 0xac } }
1397c478bd9Sstevel@tonic-gate 
1408488aeb5Staylor /* minimum # of bytes for partition table entires, per EFI spec */
1417c478bd9Sstevel@tonic-gate #define	EFI_MIN_ARRAY_SIZE	(16 * 1024)
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate #define	EFI_PART_NAME_LEN	36
1447c478bd9Sstevel@tonic-gate 
1458488aeb5Staylor /* size of the "reserved" partition, in blocks */
1468488aeb5Staylor #define	EFI_MIN_RESV_SIZE	(16 * 1024)
1478488aeb5Staylor 
1487c478bd9Sstevel@tonic-gate /* EFI Guid Partition Entry */
1497c478bd9Sstevel@tonic-gate typedef struct efi_gpe {
1507c478bd9Sstevel@tonic-gate 	struct uuid	efi_gpe_PartitionTypeGUID;
1517c478bd9Sstevel@tonic-gate 	struct uuid	efi_gpe_UniquePartitionGUID;
1527c478bd9Sstevel@tonic-gate 	diskaddr_t	efi_gpe_StartingLBA;
1537c478bd9Sstevel@tonic-gate 	diskaddr_t	efi_gpe_EndingLBA;
1547c478bd9Sstevel@tonic-gate 	efi_gpe_Attrs_t	efi_gpe_Attributes;
1557c478bd9Sstevel@tonic-gate 	ushort_t	efi_gpe_PartitionName[EFI_PART_NAME_LEN];
1567c478bd9Sstevel@tonic-gate } efi_gpe_t;
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate /*
1597c478bd9Sstevel@tonic-gate  * passed to the useful (we hope) routines (efi_alloc_and_read and
1607c478bd9Sstevel@tonic-gate  * efi_write) that take this VTOC-like struct.  These routines handle
1617c478bd9Sstevel@tonic-gate  * converting this struct into the EFI struct, generate UUIDs and
1627c478bd9Sstevel@tonic-gate  * checksums, and perform any necessary byte-swapping to the on-disk
1637c478bd9Sstevel@tonic-gate  * format.
1647c478bd9Sstevel@tonic-gate  */
1657c478bd9Sstevel@tonic-gate /* Solaris library abstraction for EFI partitons */
1667c478bd9Sstevel@tonic-gate typedef struct dk_part	{
1677c478bd9Sstevel@tonic-gate 	diskaddr_t	p_start;	/* starting LBA */
1687c478bd9Sstevel@tonic-gate 	diskaddr_t	p_size;		/* size in blocks */
1697c478bd9Sstevel@tonic-gate 	struct uuid	p_guid;		/* partion type GUID */
1707c478bd9Sstevel@tonic-gate 	ushort_t	p_tag;		/* converted to part'n type GUID */
1717c478bd9Sstevel@tonic-gate 	ushort_t	p_flag;		/* attributes */
1727c478bd9Sstevel@tonic-gate 	char		p_name[EFI_PART_NAME_LEN]; /* partition name */
1737c478bd9Sstevel@tonic-gate 	struct uuid	p_uguid;	/* unique partition GUID */
1747c478bd9Sstevel@tonic-gate 	uint_t		p_resv[8];	/* future use - set to zero */
1757c478bd9Sstevel@tonic-gate } dk_part_t;
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate /* Solaris library abstraction for an EFI GPT */
1787c478bd9Sstevel@tonic-gate #define	EFI_VERSION102		0x00010002
1797c478bd9Sstevel@tonic-gate #define	EFI_VERSION100		0x00010000
1807c478bd9Sstevel@tonic-gate #define	EFI_VERSION_CURRENT	EFI_VERSION100
1817c478bd9Sstevel@tonic-gate typedef struct dk_gpt {
1827c478bd9Sstevel@tonic-gate 	uint_t		efi_version;	/* set to EFI_VERSION_CURRENT */
1837c478bd9Sstevel@tonic-gate 	uint_t		efi_nparts;	/* number of partitions below */
1847c478bd9Sstevel@tonic-gate 	uint_t		efi_part_size;	/* size of each partition entry */
1857c478bd9Sstevel@tonic-gate 					/* efi_part_size is unused */
1867c478bd9Sstevel@tonic-gate 	uint_t		efi_lbasize;	/* size of block in bytes */
1877c478bd9Sstevel@tonic-gate 	diskaddr_t	efi_last_lba;	/* last block on the disk */
1887c478bd9Sstevel@tonic-gate 	diskaddr_t	efi_first_u_lba; /* first block after labels */
1897c478bd9Sstevel@tonic-gate 	diskaddr_t	efi_last_u_lba;	/* last block before backup labels */
1907c478bd9Sstevel@tonic-gate 	struct uuid	efi_disk_uguid;	/* unique disk GUID */
1917c478bd9Sstevel@tonic-gate 	uint_t		efi_flags;
192*af007057Syl 	uint_t		efi_reserved1;	/* future use - set to zero */
193*af007057Syl 	diskaddr_t	efi_altern_lba;	/* lba of alternate GPT header */
194*af007057Syl 	uint_t		efi_reserved[12]; /* future use - set to zero */
1957c478bd9Sstevel@tonic-gate 	struct dk_part	efi_parts[1];	/* array of partitions */
1967c478bd9Sstevel@tonic-gate } dk_gpt_t;
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate /* possible values for "efi_flags" */
1997c478bd9Sstevel@tonic-gate #define	EFI_GPT_PRIMARY_CORRUPT	0x1	/* primary label corrupt */
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate /* the private ioctl between libefi and the driver */
2027c478bd9Sstevel@tonic-gate typedef struct dk_efi {
2037c478bd9Sstevel@tonic-gate 	diskaddr_t	 dki_lba;	/* starting block */
2047c478bd9Sstevel@tonic-gate 	len_t		 dki_length;	/* length in bytes */
2057c478bd9Sstevel@tonic-gate 	union {
2067c478bd9Sstevel@tonic-gate 		efi_gpt_t 	*_dki_data;
2077c478bd9Sstevel@tonic-gate 		uint64_t	_dki_data_64;
2087c478bd9Sstevel@tonic-gate 	} dki_un;
2097c478bd9Sstevel@tonic-gate #define	dki_data	dki_un._dki_data
2107c478bd9Sstevel@tonic-gate #define	dki_data_64	dki_un._dki_data_64
2117c478bd9Sstevel@tonic-gate } dk_efi_t;
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate struct partition64 {
2147c478bd9Sstevel@tonic-gate 	struct uuid	p_type;
2157c478bd9Sstevel@tonic-gate 	uint_t		p_partno;
2167c478bd9Sstevel@tonic-gate 	uint_t		p_resv1;
2177c478bd9Sstevel@tonic-gate 	diskaddr_t	p_start;
2187c478bd9Sstevel@tonic-gate 	diskaddr_t	p_size;
2197c478bd9Sstevel@tonic-gate };
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate /*
2227c478bd9Sstevel@tonic-gate  * Number of EFI partitions
2237c478bd9Sstevel@tonic-gate  */
2247c478bd9Sstevel@tonic-gate #define	EFI_NUMPAR	9
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate #ifndef _KERNEL
2277c478bd9Sstevel@tonic-gate extern	int	efi_alloc_and_init(int, uint32_t, struct dk_gpt **);
2287c478bd9Sstevel@tonic-gate extern	int	efi_alloc_and_read(int, struct dk_gpt **);
2297c478bd9Sstevel@tonic-gate extern	int	efi_write(int, struct dk_gpt *);
2307c478bd9Sstevel@tonic-gate extern	void	efi_free(struct dk_gpt *);
2317c478bd9Sstevel@tonic-gate extern	int	efi_type(int);
2327c478bd9Sstevel@tonic-gate extern	void	efi_err_check(struct dk_gpt *);
2337c478bd9Sstevel@tonic-gate extern	int	efi_auto_sense(int fd, struct dk_gpt **);
234*af007057Syl extern	int	efi_use_whole_disk(int fd);
2357c478bd9Sstevel@tonic-gate #endif
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate #ifdef __cplusplus
2387c478bd9Sstevel@tonic-gate }
2397c478bd9Sstevel@tonic-gate #endif
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate #endif /* _SYS_EFI_PARTITION_H */
242