1 /*
2  * Copyright (c) 2016-2022, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef PARTITION_H
8 #define PARTITION_H
9 
10 #include <stdint.h>
11 
12 #include <lib/cassert.h>
13 #include <drivers/partition/efi.h>
14 #include <tools_share/uuid.h>
15 
16 #if !PLAT_PARTITION_MAX_ENTRIES
17 # define PLAT_PARTITION_MAX_ENTRIES	128
18 #endif	/* PLAT_PARTITION_MAX_ENTRIES */
19 
20 CASSERT(PLAT_PARTITION_MAX_ENTRIES <= 128, assert_plat_partition_max_entries);
21 
22 #if !PLAT_PARTITION_BLOCK_SIZE
23 # define PLAT_PARTITION_BLOCK_SIZE	512
24 #endif /* PLAT_PARTITION_BLOCK_SIZE */
25 
26 CASSERT((PLAT_PARTITION_BLOCK_SIZE == 512) ||
27 	(PLAT_PARTITION_BLOCK_SIZE == 4096),
28 	assert_plat_partition_block_size);
29 
30 #define LEGACY_PARTITION_BLOCK_SIZE	512
31 
32 #define DEFAULT_GPT_HEADER_SIZE 	92
33 
34 typedef struct partition_entry {
35 	uint64_t		start;
36 	uint64_t		length;
37 	char			name[EFI_NAMELEN];
38 	struct efi_guid		part_guid;
39 	struct efi_guid		type_guid;
40 } partition_entry_t;
41 
42 typedef struct partition_entry_list {
43 	partition_entry_t	list[PLAT_PARTITION_MAX_ENTRIES];
44 	int			entry_count;
45 } partition_entry_list_t;
46 
47 int load_partition_table(unsigned int image_id);
48 const partition_entry_t *get_partition_entry(const char *name);
49 const partition_entry_t *get_partition_entry_by_type(const uuid_t *type_guid);
50 const partition_entry_t *get_partition_entry_by_uuid(const uuid_t *part_uuid);
51 const partition_entry_list_t *get_partition_entry_list(void);
52 void partition_init(unsigned int image_id);
53 
54 #endif /* PARTITION_H */
55