]> git.ozlabs.org Git - petitboot/blob - lib/efi/efivar.h
lib/efi: Add new struct efi_mount
[petitboot] / lib / efi / efivar.h
1 /*
2  *  This program is free software; you can redistribute it and/or modify
3  *  it under the terms of the GNU General Public License as published by
4  *  the Free Software Foundation; version 2 of the License.
5  *
6  *  This program is distributed in the hope that it will be useful,
7  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
8  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9  *  GNU General Public License for more details.
10  *
11  *  You should have received a copy of the GNU General Public License
12  *  along with this program; if not, write to the Free Software
13  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
14  *
15  *  Copyright (C) 2018 Huaxintong Semiconductor Technology Co.,Ltd. All rights
16  *  reserved.
17  *  Author: Ge Song <ge.song@hxt-semitech.com>
18  */
19 #ifndef EFIVAR_H
20 #define EFIVAR_H
21
22 #include <stdbool.h>
23 #include <stdint.h>
24
25 #include <linux/magic.h>
26
27 #define EFI_VARIABLE_NON_VOLATILE                           0x00000001
28 #define EFI_VARIABLE_BOOTSERVICE_ACCESS                     0x00000002
29 #define EFI_VARIABLE_RUNTIME_ACCESS                         0x00000004
30 #define EFI_VARIABLE_HARDWARE_ERROR_RECORD                  0x00000008
31 #define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS             0x00000010
32 #define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS  0x00000020
33 #define EFI_VARIABLE_APPEND_WRITE                           0x00000040
34
35 #define EFI_DEFALT_ATTRIBUTES ( \
36         EFI_VARIABLE_NON_VOLATILE | \
37         EFI_VARIABLE_RUNTIME_ACCESS | \
38         EFI_VARIABLE_BOOTSERVICE_ACCESS \
39 )
40
41 #ifndef EFIVARFS_MAGIC
42 #define EFIVARFS_MAGIC 0xde5e81e4
43 #endif
44
45 struct efi_data {
46         uint32_t attributes;
47         size_t data_size;
48         void *data;
49         uint8_t fill[0];
50 };
51
52 struct efi_mount {
53         const char *path;
54         const char *guid;
55 };
56
57 void efi_init_mount(struct efi_mount *efi_mount, const char *path,
58         const char *guid);
59 bool efi_check_mount_magic(const struct efi_mount *efi_mount, bool check_magic);
60 static inline bool efi_check_mount(const struct efi_mount *efi_mount)
61 {
62         return efi_check_mount_magic(efi_mount, true);
63 }
64
65 int efi_get_variable(void *ctx, const struct efi_mount *efi_mount,
66         const char *name, struct efi_data **efi_data);
67 int efi_set_variable(const struct efi_mount *efi_mount, const char *name,
68         const struct efi_data *efi_data);
69 int efi_del_variable(const struct efi_mount *efi_mount, const char *name);
70
71 #endif /* EFIVAR_H */