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*80c797c0SSharath M Srinivasan  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate #ifndef	_SYS_EFI_PARTITION_H
267c478bd9Sstevel@tonic-gate #define	_SYS_EFI_PARTITION_H
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include <sys/uuid.h>
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
317c478bd9Sstevel@tonic-gate extern "C" {
327c478bd9Sstevel@tonic-gate #endif
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate /*
357c478bd9Sstevel@tonic-gate  * GUID Partition Table Header
367c478bd9Sstevel@tonic-gate  */
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #define	EFI_LABEL_SIZE	512
397c478bd9Sstevel@tonic-gate #define	LEN_EFI_PAD	(EFI_LABEL_SIZE - \
407c478bd9Sstevel@tonic-gate 			    ((5 * sizeof (diskaddr_t)) + \
417c478bd9Sstevel@tonic-gate 			    (7 * sizeof (uint_t)) + \
427c478bd9Sstevel@tonic-gate 			    (8 * sizeof (char)) + \
437c478bd9Sstevel@tonic-gate 			    (1 * (sizeof (struct uuid)))))
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #define	EFI_SIGNATURE	0x5452415020494645ULL
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /* EFI Guid Partition Table Header -- little endian on-disk format */
487c478bd9Sstevel@tonic-gate typedef struct efi_gpt {
497c478bd9Sstevel@tonic-gate 	uint64_t	efi_gpt_Signature;
507c478bd9Sstevel@tonic-gate 	uint_t		efi_gpt_Revision;
517c478bd9Sstevel@tonic-gate 	uint_t		efi_gpt_HeaderSize;
527c478bd9Sstevel@tonic-gate 	uint_t		efi_gpt_HeaderCRC32;
537c478bd9Sstevel@tonic-gate 	uint_t		efi_gpt_Reserved1;
547c478bd9Sstevel@tonic-gate 	diskaddr_t	efi_gpt_MyLBA;
557c478bd9Sstevel@tonic-gate 	diskaddr_t	efi_gpt_AlternateLBA;
567c478bd9Sstevel@tonic-gate 	diskaddr_t	efi_gpt_FirstUsableLBA;
577c478bd9Sstevel@tonic-gate 	diskaddr_t	efi_gpt_LastUsableLBA;
587c478bd9Sstevel@tonic-gate 	struct uuid	efi_gpt_DiskGUID;
597c478bd9Sstevel@tonic-gate 	diskaddr_t	efi_gpt_PartitionEntryLBA;
607c478bd9Sstevel@tonic-gate 	uint_t		efi_gpt_NumberOfPartitionEntries;
617c478bd9Sstevel@tonic-gate 	uint_t		efi_gpt_SizeOfPartitionEntry;
627c478bd9Sstevel@tonic-gate 	uint_t		efi_gpt_PartitionEntryArrayCRC32;
637c478bd9Sstevel@tonic-gate 	char		efi_gpt_Reserved2[LEN_EFI_PAD];
647c478bd9Sstevel@tonic-gate } efi_gpt_t;
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate /* EFI Guid Partition Entry Attributes -- little endian format */
677c478bd9Sstevel@tonic-gate typedef struct efi_gpe_Attrs {
687c478bd9Sstevel@tonic-gate 	uint32_t	PartitionAttrs		:16,
697c478bd9Sstevel@tonic-gate 			Reserved2		:16;
707c478bd9Sstevel@tonic-gate 	uint32_t	Reserved1		:31,
717c478bd9Sstevel@tonic-gate 			RequiredPartition	:1;
727c478bd9Sstevel@tonic-gate } efi_gpe_Attrs_t;
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate /*
757c478bd9Sstevel@tonic-gate  * 6a96237f-1dd2-11b2-99a6-080020736631	V_UNASSIGNED (not used as such)
767c478bd9Sstevel@tonic-gate  * 6a82cb45-1dd2-11b2-99a6-080020736631	V_BOOT
777c478bd9Sstevel@tonic-gate  * 6a85cf4d-1dd2-11b2-99a6-080020736631	V_ROOT
787c478bd9Sstevel@tonic-gate  * 6a87c46f-1dd2-11b2-99a6-080020736631	V_SWAP
797c478bd9Sstevel@tonic-gate  * 6a898cc3-1dd2-11b2-99a6-080020736631	V_USR
807c478bd9Sstevel@tonic-gate  * 6a8b642b-1dd2-11b2-99a6-080020736631	V_BACKUP
817c478bd9Sstevel@tonic-gate  * 6a8d2ac7-1dd2-11b2-99a6-080020736631	V_STAND (not used)
827c478bd9Sstevel@tonic-gate  * 6a8ef2e9-1dd2-11b2-99a6-080020736631	V_VAR
837c478bd9Sstevel@tonic-gate  * 6a90ba39-1dd2-11b2-99a6-080020736631	V_HOME
847c478bd9Sstevel@tonic-gate  * 6a9283a5-1dd2-11b2-99a6-080020736631	V_ALTSCTR
857c478bd9Sstevel@tonic-gate  * 6a945a3b-1dd2-11b2-99a6-080020736631	V_CACHE
867c478bd9Sstevel@tonic-gate  */
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate #define	EFI_UNUSED	{ 0x00000000, 0x0000, 0x0000, 0x00, 0x00, \
897c478bd9Sstevel@tonic-gate 			    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }
907c478bd9Sstevel@tonic-gate #define	EFI_RESV1	{ 0x6a96237f, 0x1dd2, 0x11b2, 0x99, 0xa6, \
917c478bd9Sstevel@tonic-gate 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
927c478bd9Sstevel@tonic-gate #define	EFI_BOOT	{ 0x6a82cb45, 0x1dd2, 0x11b2, 0x99, 0xa6, \
937c478bd9Sstevel@tonic-gate 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
947c478bd9Sstevel@tonic-gate #define	EFI_ROOT	{ 0x6a85cf4d, 0x1dd2, 0x11b2, 0x99, 0xa6, \
957c478bd9Sstevel@tonic-gate 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
967c478bd9Sstevel@tonic-gate #define	EFI_SWAP	{ 0x6a87c46f, 0x1dd2, 0x11b2, 0x99, 0xa6, \
977c478bd9Sstevel@tonic-gate 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
987c478bd9Sstevel@tonic-gate #define	EFI_USR		{ 0x6a898cc3, 0x1dd2, 0x11b2, 0x99, 0xa6, \
997c478bd9Sstevel@tonic-gate 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
1007c478bd9Sstevel@tonic-gate #define	EFI_BACKUP	{ 0x6a8b642b, 0x1dd2, 0x11b2, 0x99, 0xa6, \
1017c478bd9Sstevel@tonic-gate 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
1027c478bd9Sstevel@tonic-gate #define	EFI_RESV2	{ 0x6a8d2ac7, 0x1dd2, 0x11b2, 0x99, 0xa6, \
1037c478bd9Sstevel@tonic-gate 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
1047c478bd9Sstevel@tonic-gate #define	EFI_VAR		{ 0x6a8ef2e9, 0x1dd2, 0x11b2, 0x99, 0xa6, \
1057c478bd9Sstevel@tonic-gate 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
1067c478bd9Sstevel@tonic-gate #define	EFI_HOME	{ 0x6a90ba39, 0x1dd2, 0x11b2, 0x99, 0xa6, \
1077c478bd9Sstevel@tonic-gate 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
1087c478bd9Sstevel@tonic-gate #define	EFI_ALTSCTR	{ 0x6a9283a5, 0x1dd2, 0x11b2, 0x99, 0xa6, \
1097c478bd9Sstevel@tonic-gate 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
1107c478bd9Sstevel@tonic-gate #define	EFI_RESERVED	{ 0x6a945a3b, 0x1dd2, 0x11b2, 0x99, 0xa6, \
1117c478bd9Sstevel@tonic-gate 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
1127c478bd9Sstevel@tonic-gate #define	EFI_SYSTEM	{ 0xC12A7328, 0xF81F, 0x11d2, 0xBA, 0x4B, \
1137c478bd9Sstevel@tonic-gate 			    { 0x00, 0xA0, 0xC9, 0x3E, 0xC9, 0x3B } }
1147c478bd9Sstevel@tonic-gate #define	EFI_LEGACY_MBR	{ 0x024DEE41, 0x33E7, 0x11d3, 0x9D, 0x69, \
1157c478bd9Sstevel@tonic-gate 			    { 0x00, 0x08, 0xC7, 0x81, 0xF3, 0x9F } }
116*80c797c0SSharath M Srinivasan #define	EFI_SYMC_PUB	{ 0x6a9630d1, 0x1dd2, 0x11b2, 0x99, 0xa6, \
1177c478bd9Sstevel@tonic-gate 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
118*80c797c0SSharath M Srinivasan #define	EFI_SYMC_CDS	{ 0x6a980767, 0x1dd2, 0x11b2, 0x99, 0xa6, \
1197c478bd9Sstevel@tonic-gate 			    { 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }
1207c478bd9Sstevel@tonic-gate #define	EFI_MSFT_RESV	{ 0xE3C9E316, 0x0B5C, 0x4DB8, 0x81, 0x7D, \
1217c478bd9Sstevel@tonic-gate 			    { 0xF9, 0x2D, 0xF0, 0x02, 0x15, 0xAE } }
1227c478bd9Sstevel@tonic-gate #define	EFI_DELL_BASIC	{ 0xebd0a0a2, 0xb9e5, 0x4433, 0x87, 0xc0, \
1237c478bd9Sstevel@tonic-gate 			    { 0x68, 0xb6, 0xb7, 0x26, 0x99, 0xc7 } }
1247c478bd9Sstevel@tonic-gate #define	EFI_DELL_RAID	{ 0xa19d880f, 0x05fc, 0x4d3b, 0xa0, 0x06, \
1257c478bd9Sstevel@tonic-gate 			    { 0x74, 0x3f, 0x0f, 0x84, 0x91, 0x1e } }
1267c478bd9Sstevel@tonic-gate #define	EFI_DELL_SWAP	{ 0x0657fd6d, 0xa4ab, 0x43c4, 0x84, 0xe5, \
1277c478bd9Sstevel@tonic-gate 			    { 0x09, 0x33, 0xc8, 0x4b, 0x4f, 0x4f } }
1287c478bd9Sstevel@tonic-gate #define	EFI_DELL_LVM	{ 0xe6d6d379, 0xf507, 0x44c2, 0xa2, 0x3c, \
1297c478bd9Sstevel@tonic-gate 			    { 0x23, 0x8f, 0x2a, 0x3d, 0xf9, 0x28 } }
1307c478bd9Sstevel@tonic-gate #define	EFI_DELL_RESV	{ 0x8da63339, 0x0007, 0x60c0, 0xc4, 0x36, \
1317c478bd9Sstevel@tonic-gate 			    { 0x08, 0x3a, 0xc8, 0x23, 0x09, 0x08 } }
132f2be5148Sszhou #define	EFI_AAPL_HFS	{ 0x48465300, 0x0000, 0x11aa, 0xaa, 0x11, \
133f2be5148Sszhou 			    { 0x00, 0x30, 0x65, 0x43, 0xec, 0xac } }
134f2be5148Sszhou #define	EFI_AAPL_UFS	{ 0x55465300, 0x0000, 0x11aa, 0xaa, 0x11, \
135f2be5148Sszhou 			    { 0x00, 0x30, 0x65, 0x43, 0xec, 0xac } }
1367c478bd9Sstevel@tonic-gate 
1378488aeb5Staylor /* minimum # of bytes for partition table entires, per EFI spec */
1387c478bd9Sstevel@tonic-gate #define	EFI_MIN_ARRAY_SIZE	(16 * 1024)
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate #define	EFI_PART_NAME_LEN	36
1417c478bd9Sstevel@tonic-gate 
1428488aeb5Staylor /* size of the "reserved" partition, in blocks */
1438488aeb5Staylor #define	EFI_MIN_RESV_SIZE	(16 * 1024)
1448488aeb5Staylor 
1457c478bd9Sstevel@tonic-gate /* EFI Guid Partition Entry */
1467c478bd9Sstevel@tonic-gate typedef struct efi_gpe {
1477c478bd9Sstevel@tonic-gate 	struct uuid	efi_gpe_PartitionTypeGUID;
1487c478bd9Sstevel@tonic-gate 	struct uuid	efi_gpe_UniquePartitionGUID;
1497c478bd9Sstevel@tonic-gate 	diskaddr_t	efi_gpe_StartingLBA;
1507c478bd9Sstevel@tonic-gate 	diskaddr_t	efi_gpe_EndingLBA;
1517c478bd9Sstevel@tonic-gate 	efi_gpe_Attrs_t	efi_gpe_Attributes;
1527c478bd9Sstevel@tonic-gate 	ushort_t	efi_gpe_PartitionName[EFI_PART_NAME_LEN];
1537c478bd9Sstevel@tonic-gate } efi_gpe_t;
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate /*
1567c478bd9Sstevel@tonic-gate  * passed to the useful (we hope) routines (efi_alloc_and_read and
1577c478bd9Sstevel@tonic-gate  * efi_write) that take this VTOC-like struct.  These routines handle
1587c478bd9Sstevel@tonic-gate  * converting this struct into the EFI struct, generate UUIDs and
1597c478bd9Sstevel@tonic-gate  * checksums, and perform any necessary byte-swapping to the on-disk
1607c478bd9Sstevel@tonic-gate  * format.
1617c478bd9Sstevel@tonic-gate  */
1627c478bd9Sstevel@tonic-gate /* Solaris library abstraction for EFI partitons */
1637c478bd9Sstevel@tonic-gate typedef struct dk_part	{
1647c478bd9Sstevel@tonic-gate 	diskaddr_t	p_start;	/* starting LBA */
1657c478bd9Sstevel@tonic-gate 	diskaddr_t	p_size;		/* size in blocks */
1667c478bd9Sstevel@tonic-gate 	struct uuid	p_guid;		/* partion type GUID */
1677c478bd9Sstevel@tonic-gate 	ushort_t	p_tag;		/* converted to part'n type GUID */
1687c478bd9Sstevel@tonic-gate 	ushort_t	p_flag;		/* attributes */
1697c478bd9Sstevel@tonic-gate 	char		p_name[EFI_PART_NAME_LEN]; /* partition name */
1707c478bd9Sstevel@tonic-gate 	struct uuid	p_uguid;	/* unique partition GUID */
1717c478bd9Sstevel@tonic-gate 	uint_t		p_resv[8];	/* future use - set to zero */
1727c478bd9Sstevel@tonic-gate } dk_part_t;
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate /* Solaris library abstraction for an EFI GPT */
1757c478bd9Sstevel@tonic-gate #define	EFI_VERSION102		0x00010002
1767c478bd9Sstevel@tonic-gate #define	EFI_VERSION100		0x00010000
1777c478bd9Sstevel@tonic-gate #define	EFI_VERSION_CURRENT	EFI_VERSION100
1787c478bd9Sstevel@tonic-gate typedef struct dk_gpt {
1797c478bd9Sstevel@tonic-gate 	uint_t		efi_version;	/* set to EFI_VERSION_CURRENT */
1807c478bd9Sstevel@tonic-gate 	uint_t		efi_nparts;	/* number of partitions below */
1817c478bd9Sstevel@tonic-gate 	uint_t		efi_part_size;	/* size of each partition entry */
1827c478bd9Sstevel@tonic-gate 					/* efi_part_size is unused */
1837c478bd9Sstevel@tonic-gate 	uint_t		efi_lbasize;	/* size of block in bytes */
1847c478bd9Sstevel@tonic-gate 	diskaddr_t	efi_last_lba;	/* last block on the disk */
1857c478bd9Sstevel@tonic-gate 	diskaddr_t	efi_first_u_lba; /* first block after labels */
1867c478bd9Sstevel@tonic-gate 	diskaddr_t	efi_last_u_lba;	/* last block before backup labels */
1877c478bd9Sstevel@tonic-gate 	struct uuid	efi_disk_uguid;	/* unique disk GUID */
1887c478bd9Sstevel@tonic-gate 	uint_t		efi_flags;
189af007057Syl 	uint_t		efi_reserved1;	/* future use - set to zero */
190af007057Syl 	diskaddr_t	efi_altern_lba;	/* lba of alternate GPT header */
191af007057Syl 	uint_t		efi_reserved[12]; /* future use - set to zero */
1927c478bd9Sstevel@tonic-gate 	struct dk_part	efi_parts[1];	/* array of partitions */
1937c478bd9Sstevel@tonic-gate } dk_gpt_t;
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate /* possible values for "efi_flags" */
1967c478bd9Sstevel@tonic-gate #define	EFI_GPT_PRIMARY_CORRUPT	0x1	/* primary label corrupt */
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate /* the private ioctl between libefi and the driver */
1997c478bd9Sstevel@tonic-gate typedef struct dk_efi {
2007c478bd9Sstevel@tonic-gate 	diskaddr_t	 dki_lba;	/* starting block */
2017c478bd9Sstevel@tonic-gate 	len_t		 dki_length;	/* length in bytes */
2027c478bd9Sstevel@tonic-gate 	union {
2037c478bd9Sstevel@tonic-gate 		efi_gpt_t 	*_dki_data;
2047c478bd9Sstevel@tonic-gate 		uint64_t	_dki_data_64;
2057c478bd9Sstevel@tonic-gate 	} dki_un;
2067c478bd9Sstevel@tonic-gate #define	dki_data	dki_un._dki_data
2077c478bd9Sstevel@tonic-gate #define	dki_data_64	dki_un._dki_data_64
2087c478bd9Sstevel@tonic-gate } dk_efi_t;
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate struct partition64 {
2117c478bd9Sstevel@tonic-gate 	struct uuid	p_type;
2127c478bd9Sstevel@tonic-gate 	uint_t		p_partno;
2137c478bd9Sstevel@tonic-gate 	uint_t		p_resv1;
2147c478bd9Sstevel@tonic-gate 	diskaddr_t	p_start;
2157c478bd9Sstevel@tonic-gate 	diskaddr_t	p_size;
2167c478bd9Sstevel@tonic-gate };
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate /*
2197c478bd9Sstevel@tonic-gate  * Number of EFI partitions
2207c478bd9Sstevel@tonic-gate  */
2217c478bd9Sstevel@tonic-gate #define	EFI_NUMPAR	9
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate #ifndef _KERNEL
2247c478bd9Sstevel@tonic-gate extern	int	efi_alloc_and_init(int, uint32_t, struct dk_gpt **);
2257c478bd9Sstevel@tonic-gate extern	int	efi_alloc_and_read(int, struct dk_gpt **);
2267c478bd9Sstevel@tonic-gate extern	int	efi_write(int, struct dk_gpt *);
2277c478bd9Sstevel@tonic-gate extern	void	efi_free(struct dk_gpt *);
2287c478bd9Sstevel@tonic-gate extern	int	efi_type(int);
2297c478bd9Sstevel@tonic-gate extern	void	efi_err_check(struct dk_gpt *);
2307c478bd9Sstevel@tonic-gate extern	int	efi_auto_sense(int fd, struct dk_gpt **);
231af007057Syl extern	int	efi_use_whole_disk(int fd);
2327c478bd9Sstevel@tonic-gate #endif
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate #ifdef __cplusplus
2357c478bd9Sstevel@tonic-gate }
2367c478bd9Sstevel@tonic-gate #endif
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate #endif /* _SYS_EFI_PARTITION_H */
239