Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

efi: Add esrt support

Add sysfs files for the EFI System Resource Table (ESRT) under
/sys/firmware/efi/esrt and for each EFI System Resource Entry under
entries/ as a subdir.

The EFI System Resource Table (ESRT) provides a read-only catalog of
system components for which the system accepts firmware upgrades via
UEFI's "Capsule Update" feature. This module allows userland utilities
to evaluate what firmware updates can be applied to this system, and
potentially arrange for those updates to occur.

The ESRT is described as part of the UEFI specification, in version 2.5
which should be available from http://uefi.org/specifications in early
2015. If you're a member of the UEFI Forum, information about its
addition to the standard is available as UEFI Mantis 1090.

For some hardware platforms, additional restrictions may be found at
http://msdn.microsoft.com/en-us/library/windows/hardware/jj128256.aspx ,
and additional documentation may be found at
http://download.microsoft.com/download/5/F/5/5F5D16CD-2530-4289-8019-94C6A20BED3C/windows-uefi-firmware-update-platform.docx
.

Signed-off-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Matt Fleming <matt.fleming@intel.com>

authored by

Peter Jones and committed by
Matt Fleming
0bb54905 f7ef7e3e

+637 -2
+81
Documentation/ABI/testing/sysfs-firmware-efi-esrt
··· 1 + What: /sys/firmware/efi/esrt/ 2 + Date: February 2015 3 + Contact: Peter Jones <pjones@redhat.com> 4 + Description: Provides userland access to read the EFI System Resource Table 5 + (ESRT), a catalog of firmware for which can be updated with 6 + the UEFI UpdateCapsule mechanism described in section 7.5 of 7 + the UEFI Standard. 8 + Users: fwupdate - https://github.com/rhinstaller/fwupdate 9 + 10 + What: /sys/firmware/efi/esrt/fw_resource_count 11 + Date: February 2015 12 + Contact: Peter Jones <pjones@redhat.com> 13 + Description: The number of entries in the ESRT 14 + 15 + What: /sys/firmware/efi/esrt/fw_resource_count_max 16 + Date: February 2015 17 + Contact: Peter Jones <pjones@redhat.com> 18 + Description: The maximum number of entries that /could/ be registered 19 + in the allocation the table is currently in. This is 20 + really only useful to the system firmware itself. 21 + 22 + What: /sys/firmware/efi/esrt/fw_resource_version 23 + Date: February 2015 24 + Contact: Peter Jones <pjones@redhat.com> 25 + Description: The version of the ESRT structure provided by the firmware. 26 + 27 + What: /sys/firmware/efi/esrt/entries/entry$N/ 28 + Date: February 2015 29 + Contact: Peter Jones <pjones@redhat.com> 30 + Description: Each ESRT entry is identified by a GUID, and each gets a 31 + subdirectory under entries/ . 32 + example: /sys/firmware/efi/esrt/entries/entry0/ 33 + 34 + What: /sys/firmware/efi/esrt/entries/entry$N/fw_type 35 + Date: February 2015 36 + Contact: Peter Jones <pjones@redhat.com> 37 + Description: What kind of firmware entry this is: 38 + 0 - Unknown 39 + 1 - System Firmware 40 + 2 - Device Firmware 41 + 3 - UEFI Driver 42 + 43 + What: /sys/firmware/efi/esrt/entries/entry$N/fw_class 44 + Date: February 2015 45 + Contact: Peter Jones <pjones@redhat.com> 46 + Description: This is the entry's guid, and will match the directory name. 47 + 48 + What: /sys/firmware/efi/esrt/entries/entry$N/fw_version 49 + Date: February 2015 50 + Contact: Peter Jones <pjones@redhat.com> 51 + Description: The version of the firmware currently installed. This is a 52 + 32-bit unsigned integer. 53 + 54 + What: /sys/firmware/efi/esrt/entries/entry$N/lowest_supported_fw_version 55 + Date: February 2015 56 + Contact: Peter Jones <pjones@redhat.com> 57 + Description: The lowest version of the firmware that can be installed. 58 + 59 + What: /sys/firmware/efi/esrt/entries/entry$N/capsule_flags 60 + Date: February 2015 61 + Contact: Peter Jones <pjones@redhat.com> 62 + Description: Flags that must be passed to UpdateCapsule() 63 + 64 + What: /sys/firmware/efi/esrt/entries/entry$N/last_attempt_version 65 + Date: February 2015 66 + Contact: Peter Jones <pjones@redhat.com> 67 + Description: The last firmware version for which an update was attempted. 68 + 69 + What: /sys/firmware/efi/esrt/entries/entry$N/last_attempt_status 70 + Date: February 2015 71 + Contact: Peter Jones <pjones@redhat.com> 72 + Description: The result of the last firmware update attempt for the 73 + firmware resource entry. 74 + 0 - Success 75 + 1 - Insufficient resources 76 + 2 - Incorrect version 77 + 3 - Invalid format 78 + 4 - Authentication error 79 + 5 - AC power event 80 + 6 - Battery power event 81 +
+2
arch/x86/platform/efi/efi.c
··· 501 501 502 502 if (efi_enabled(EFI_DBG)) 503 503 print_efi_memmap(); 504 + 505 + efi_esrt_init(); 504 506 } 505 507 506 508 void __init efi_late_init(void)
+1 -1
drivers/firmware/efi/Makefile
··· 1 1 # 2 2 # Makefile for linux kernel 3 3 # 4 - obj-$(CONFIG_EFI) += efi.o vars.o reboot.o 4 + obj-$(CONFIG_EFI) += efi.o esrt.o vars.o reboot.o 5 5 obj-$(CONFIG_EFI_VARS) += efivars.o 6 6 obj-$(CONFIG_EFI_VARS_PSTORE) += efi-pstore.o 7 7 obj-$(CONFIG_UEFI_CPER) += cper.o
+81 -1
drivers/firmware/efi/efi.c
··· 39 39 .fw_vendor = EFI_INVALID_TABLE_ADDR, 40 40 .runtime = EFI_INVALID_TABLE_ADDR, 41 41 .config_table = EFI_INVALID_TABLE_ADDR, 42 + .esrt = EFI_INVALID_TABLE_ADDR, 42 43 }; 43 44 EXPORT_SYMBOL(efi); 44 45 ··· 65 64 } 66 65 early_param("efi", parse_efi_cmdline); 67 66 68 - static struct kobject *efi_kobj; 67 + struct kobject *efi_kobj; 69 68 static struct kobject *efivars_kobj; 70 69 71 70 /* ··· 233 232 234 233 subsys_initcall(efisubsys_init); 235 234 235 + /* 236 + * Find the efi memory descriptor for a given physical address. Given a 237 + * physicall address, determine if it exists within an EFI Memory Map entry, 238 + * and if so, populate the supplied memory descriptor with the appropriate 239 + * data. 240 + */ 241 + int __init efi_mem_desc_lookup(u64 phys_addr, efi_memory_desc_t *out_md) 242 + { 243 + struct efi_memory_map *map = efi.memmap; 244 + void *p, *e; 245 + 246 + if (!efi_enabled(EFI_MEMMAP)) { 247 + pr_err_once("EFI_MEMMAP is not enabled.\n"); 248 + return -EINVAL; 249 + } 250 + 251 + if (!map) { 252 + pr_err_once("efi.memmap is not set.\n"); 253 + return -EINVAL; 254 + } 255 + if (!out_md) { 256 + pr_err_once("out_md is null.\n"); 257 + return -EINVAL; 258 + } 259 + if (WARN_ON_ONCE(!map->phys_map)) 260 + return -EINVAL; 261 + if (WARN_ON_ONCE(map->nr_map == 0) || WARN_ON_ONCE(map->desc_size == 0)) 262 + return -EINVAL; 263 + 264 + e = map->phys_map + map->nr_map * map->desc_size; 265 + for (p = map->phys_map; p < e; p += map->desc_size) { 266 + efi_memory_desc_t *md; 267 + u64 size; 268 + u64 end; 269 + 270 + /* 271 + * If a driver calls this after efi_free_boot_services, 272 + * ->map will be NULL, and the target may also not be mapped. 273 + * So just always get our own virtual map on the CPU. 274 + * 275 + */ 276 + md = early_memremap((phys_addr_t)p, sizeof (*md)); 277 + if (!md) { 278 + pr_err_once("early_memremap(%p, %zu) failed.\n", 279 + p, sizeof (*md)); 280 + return -ENOMEM; 281 + } 282 + 283 + if (!(md->attribute & EFI_MEMORY_RUNTIME) && 284 + md->type != EFI_BOOT_SERVICES_DATA && 285 + md->type != EFI_RUNTIME_SERVICES_DATA) { 286 + early_memunmap(md, sizeof (*md)); 287 + continue; 288 + } 289 + 290 + size = md->num_pages << EFI_PAGE_SHIFT; 291 + end = md->phys_addr + size; 292 + if (phys_addr >= md->phys_addr && phys_addr < end) { 293 + memcpy(out_md, md, sizeof(*out_md)); 294 + early_memunmap(md, sizeof (*md)); 295 + return 0; 296 + } 297 + 298 + early_memunmap(md, sizeof (*md)); 299 + } 300 + pr_err_once("requested map not found.\n"); 301 + return -ENOENT; 302 + } 303 + 304 + /* 305 + * Calculate the highest address of an efi memory descriptor. 306 + */ 307 + u64 __init efi_mem_desc_end(efi_memory_desc_t *md) 308 + { 309 + u64 size = md->num_pages << EFI_PAGE_SHIFT; 310 + u64 end = md->phys_addr + size; 311 + return end; 312 + } 236 313 237 314 /* 238 315 * We can't ioremap data in EFI boot services RAM, because we've already mapped ··· 353 274 {SMBIOS_TABLE_GUID, "SMBIOS", &efi.smbios}, 354 275 {SMBIOS3_TABLE_GUID, "SMBIOS 3.0", &efi.smbios3}, 355 276 {UGA_IO_PROTOCOL_GUID, "UGA", &efi.uga}, 277 + {EFI_SYSTEM_RESOURCE_TABLE_GUID, "ESRT", &efi.esrt}, 356 278 {NULL_GUID, NULL, NULL}, 357 279 }; 358 280
+464
drivers/firmware/efi/esrt.c
··· 1 + /* 2 + * esrt.c 3 + * 4 + * This module exports EFI System Resource Table (ESRT) entries into userspace 5 + * through the sysfs file system. The ESRT provides a read-only catalog of 6 + * system components for which the system accepts firmware upgrades via UEFI's 7 + * "Capsule Update" feature. This module allows userland utilities to evaluate 8 + * what firmware updates can be applied to this system, and potentially arrange 9 + * for those updates to occur. 10 + * 11 + * Data is currently found below /sys/firmware/efi/esrt/... 12 + */ 13 + #define pr_fmt(fmt) "esrt: " fmt 14 + 15 + #include <linux/capability.h> 16 + #include <linux/device.h> 17 + #include <linux/efi.h> 18 + #include <linux/init.h> 19 + #include <linux/kernel.h> 20 + #include <linux/kobject.h> 21 + #include <linux/list.h> 22 + #include <linux/memblock.h> 23 + #include <linux/module.h> 24 + #include <linux/slab.h> 25 + #include <linux/types.h> 26 + 27 + #include <asm/io.h> 28 + #include <asm/early_ioremap.h> 29 + 30 + struct efi_system_resource_entry_v1 { 31 + efi_guid_t fw_class; 32 + u32 fw_type; 33 + u32 fw_version; 34 + u32 lowest_supported_fw_version; 35 + u32 capsule_flags; 36 + u32 last_attempt_version; 37 + u32 last_attempt_status; 38 + }; 39 + 40 + /* 41 + * _count and _version are what they seem like. _max is actually just 42 + * accounting info for the firmware when creating the table; it should never 43 + * have been exposed to us. To wit, the spec says: 44 + * The maximum number of resource array entries that can be within the 45 + * table without reallocating the table, must not be zero. 46 + * Since there's no guidance about what that means in terms of memory layout, 47 + * it means nothing to us. 48 + */ 49 + struct efi_system_resource_table { 50 + u32 fw_resource_count; 51 + u32 fw_resource_count_max; 52 + u64 fw_resource_version; 53 + u8 entries[]; 54 + }; 55 + 56 + static phys_addr_t esrt_data; 57 + static size_t esrt_data_size; 58 + 59 + static struct efi_system_resource_table *esrt; 60 + 61 + struct esre_entry { 62 + union { 63 + struct efi_system_resource_entry_v1 *esre1; 64 + } esre; 65 + 66 + struct kobject kobj; 67 + struct list_head list; 68 + }; 69 + 70 + /* global list of esre_entry. */ 71 + static LIST_HEAD(entry_list); 72 + 73 + /* entry attribute */ 74 + struct esre_attribute { 75 + struct attribute attr; 76 + ssize_t (*show)(struct esre_entry *entry, char *buf); 77 + ssize_t (*store)(struct esre_entry *entry, 78 + const char *buf, size_t count); 79 + }; 80 + 81 + static struct esre_entry *to_entry(struct kobject *kobj) 82 + { 83 + return container_of(kobj, struct esre_entry, kobj); 84 + } 85 + 86 + static struct esre_attribute *to_attr(struct attribute *attr) 87 + { 88 + return container_of(attr, struct esre_attribute, attr); 89 + } 90 + 91 + static ssize_t esre_attr_show(struct kobject *kobj, 92 + struct attribute *_attr, char *buf) 93 + { 94 + struct esre_entry *entry = to_entry(kobj); 95 + struct esre_attribute *attr = to_attr(_attr); 96 + 97 + /* Don't tell normal users what firmware versions we've got... */ 98 + if (!capable(CAP_SYS_ADMIN)) 99 + return -EACCES; 100 + 101 + return attr->show(entry, buf); 102 + } 103 + 104 + static const struct sysfs_ops esre_attr_ops = { 105 + .show = esre_attr_show, 106 + }; 107 + 108 + /* Generic ESRT Entry ("ESRE") support. */ 109 + static ssize_t esre_fw_class_show(struct esre_entry *entry, char *buf) 110 + { 111 + char *str = buf; 112 + 113 + efi_guid_to_str(&entry->esre.esre1->fw_class, str); 114 + str += strlen(str); 115 + str += sprintf(str, "\n"); 116 + 117 + return str - buf; 118 + } 119 + 120 + static struct esre_attribute esre_fw_class = __ATTR(fw_class, 0400, 121 + esre_fw_class_show, NULL); 122 + 123 + #define esre_attr_decl(name, size, fmt) \ 124 + static ssize_t esre_##name##_show(struct esre_entry *entry, char *buf) \ 125 + { \ 126 + return sprintf(buf, fmt "\n", \ 127 + le##size##_to_cpu(entry->esre.esre1->name)); \ 128 + } \ 129 + \ 130 + static struct esre_attribute esre_##name = __ATTR(name, 0400, \ 131 + esre_##name##_show, NULL) 132 + 133 + esre_attr_decl(fw_type, 32, "%u"); 134 + esre_attr_decl(fw_version, 32, "%u"); 135 + esre_attr_decl(lowest_supported_fw_version, 32, "%u"); 136 + esre_attr_decl(capsule_flags, 32, "0x%x"); 137 + esre_attr_decl(last_attempt_version, 32, "%u"); 138 + esre_attr_decl(last_attempt_status, 32, "%u"); 139 + 140 + static struct attribute *esre1_attrs[] = { 141 + &esre_fw_class.attr, 142 + &esre_fw_type.attr, 143 + &esre_fw_version.attr, 144 + &esre_lowest_supported_fw_version.attr, 145 + &esre_capsule_flags.attr, 146 + &esre_last_attempt_version.attr, 147 + &esre_last_attempt_status.attr, 148 + NULL 149 + }; 150 + static void esre_release(struct kobject *kobj) 151 + { 152 + struct esre_entry *entry = to_entry(kobj); 153 + 154 + list_del(&entry->list); 155 + kfree(entry); 156 + } 157 + 158 + static struct kobj_type esre1_ktype = { 159 + .release = esre_release, 160 + .sysfs_ops = &esre_attr_ops, 161 + .default_attrs = esre1_attrs, 162 + }; 163 + 164 + 165 + static struct kobject *esrt_kobj; 166 + static struct kset *esrt_kset; 167 + 168 + static int esre_create_sysfs_entry(void *esre, int entry_num) 169 + { 170 + int rc = 0; 171 + struct esre_entry *entry; 172 + char name[20]; 173 + 174 + entry = kzalloc(sizeof(*entry), GFP_KERNEL); 175 + if (!entry) 176 + return -ENOMEM; 177 + 178 + sprintf(name, "entry%d", entry_num); 179 + 180 + entry->kobj.kset = esrt_kset; 181 + 182 + if (esrt->fw_resource_version == 1) { 183 + entry->esre.esre1 = esre; 184 + rc = kobject_init_and_add(&entry->kobj, &esre1_ktype, NULL, 185 + "%s", name); 186 + } 187 + if (rc) { 188 + kfree(entry); 189 + return rc; 190 + } 191 + 192 + list_add_tail(&entry->list, &entry_list); 193 + return 0; 194 + } 195 + 196 + /* support for displaying ESRT fields at the top level */ 197 + #define esrt_attr_decl(name, size, fmt) \ 198 + static ssize_t esrt_##name##_show(struct kobject *kobj, \ 199 + struct kobj_attribute *attr, char *buf)\ 200 + { \ 201 + return sprintf(buf, fmt "\n", le##size##_to_cpu(esrt->name)); \ 202 + } \ 203 + \ 204 + static struct kobj_attribute esrt_##name = __ATTR(name, 0400, \ 205 + esrt_##name##_show, NULL) 206 + 207 + esrt_attr_decl(fw_resource_count, 32, "%u"); 208 + esrt_attr_decl(fw_resource_count_max, 32, "%u"); 209 + esrt_attr_decl(fw_resource_version, 64, "%llu"); 210 + 211 + static struct attribute *esrt_attrs[] = { 212 + &esrt_fw_resource_count.attr, 213 + &esrt_fw_resource_count_max.attr, 214 + &esrt_fw_resource_version.attr, 215 + NULL, 216 + }; 217 + 218 + static inline int esrt_table_exists(void) 219 + { 220 + if (!efi_enabled(EFI_CONFIG_TABLES)) 221 + return 0; 222 + if (efi.esrt == EFI_INVALID_TABLE_ADDR) 223 + return 0; 224 + return 1; 225 + } 226 + 227 + static umode_t esrt_attr_is_visible(struct kobject *kobj, 228 + struct attribute *attr, int n) 229 + { 230 + if (!esrt_table_exists()) 231 + return 0; 232 + return attr->mode; 233 + } 234 + 235 + static struct attribute_group esrt_attr_group = { 236 + .attrs = esrt_attrs, 237 + .is_visible = esrt_attr_is_visible, 238 + }; 239 + 240 + /* 241 + * remap the table, copy it to kmalloced pages, and unmap it. 242 + */ 243 + void __init efi_esrt_init(void) 244 + { 245 + void *va; 246 + struct efi_system_resource_table tmpesrt; 247 + struct efi_system_resource_entry_v1 *v1_entries; 248 + size_t size, max, entry_size, entries_size; 249 + efi_memory_desc_t md; 250 + int rc; 251 + 252 + pr_debug("esrt-init: loading.\n"); 253 + if (!esrt_table_exists()) 254 + return; 255 + 256 + rc = efi_mem_desc_lookup(efi.esrt, &md); 257 + if (rc < 0) { 258 + pr_err("ESRT header is not in the memory map.\n"); 259 + return; 260 + } 261 + 262 + max = efi_mem_desc_end(&md); 263 + if (max < efi.esrt) { 264 + pr_err("EFI memory descriptor is invalid. (esrt: %p max: %p)\n", 265 + (void *)efi.esrt, (void *)max); 266 + return; 267 + } 268 + 269 + size = sizeof(*esrt); 270 + max -= efi.esrt; 271 + 272 + if (max < size) { 273 + pr_err("ESRT header doen't fit on single memory map entry. (size: %zu max: %zu)\n", 274 + size, max); 275 + return; 276 + } 277 + 278 + va = early_memremap(efi.esrt, size); 279 + if (!va) { 280 + pr_err("early_memremap(%p, %zu) failed.\n", (void *)efi.esrt, 281 + size); 282 + return; 283 + } 284 + 285 + memcpy(&tmpesrt, va, sizeof(tmpesrt)); 286 + 287 + if (tmpesrt.fw_resource_version == 1) { 288 + entry_size = sizeof (*v1_entries); 289 + } else { 290 + pr_err("Unsupported ESRT version %lld.\n", 291 + tmpesrt.fw_resource_version); 292 + return; 293 + } 294 + 295 + if (tmpesrt.fw_resource_count > 0 && max - size < entry_size) { 296 + pr_err("ESRT memory map entry can only hold the header. (max: %zu size: %zu)\n", 297 + max - size, entry_size); 298 + goto err_memunmap; 299 + } 300 + 301 + /* 302 + * The format doesn't really give us any boundary to test here, 303 + * so I'm making up 128 as the max number of individually updatable 304 + * components we support. 305 + * 128 should be pretty excessive, but there's still some chance 306 + * somebody will do that someday and we'll need to raise this. 307 + */ 308 + if (tmpesrt.fw_resource_count > 128) { 309 + pr_err("ESRT says fw_resource_count has very large value %d.\n", 310 + tmpesrt.fw_resource_count); 311 + goto err_memunmap; 312 + } 313 + 314 + /* 315 + * We know it can't be larger than N * sizeof() here, and N is limited 316 + * by the previous test to a small number, so there's no overflow. 317 + */ 318 + entries_size = tmpesrt.fw_resource_count * entry_size; 319 + if (max < size + entries_size) { 320 + pr_err("ESRT does not fit on single memory map entry (size: %zu max: %zu)\n", 321 + size, max); 322 + goto err_memunmap; 323 + } 324 + 325 + /* remap it with our (plausible) new pages */ 326 + early_memunmap(va, size); 327 + size += entries_size; 328 + va = early_memremap(efi.esrt, size); 329 + if (!va) { 330 + pr_err("early_memremap(%p, %zu) failed.\n", (void *)efi.esrt, 331 + size); 332 + return; 333 + } 334 + 335 + esrt_data = (phys_addr_t)efi.esrt; 336 + esrt_data_size = size; 337 + 338 + pr_info("Reserving ESRT space from %p to %p.\n", (void *)esrt_data, 339 + (char *)esrt_data + size); 340 + memblock_reserve(esrt_data, esrt_data_size); 341 + 342 + pr_debug("esrt-init: loaded.\n"); 343 + err_memunmap: 344 + early_memunmap(va, size); 345 + } 346 + 347 + static int __init register_entries(void) 348 + { 349 + struct efi_system_resource_entry_v1 *v1_entries = (void *)esrt->entries; 350 + int i, rc; 351 + 352 + if (!esrt_table_exists()) 353 + return 0; 354 + 355 + for (i = 0; i < le32_to_cpu(esrt->fw_resource_count); i++) { 356 + void *entry; 357 + if (esrt->fw_resource_version == 1) { 358 + entry = &v1_entries[i]; 359 + } 360 + rc = esre_create_sysfs_entry(entry, i); 361 + if (rc < 0) { 362 + pr_err("ESRT entry creation failed with error %d.\n", 363 + rc); 364 + return rc; 365 + } 366 + } 367 + return 0; 368 + } 369 + 370 + static void cleanup_entry_list(void) 371 + { 372 + struct esre_entry *entry, *next; 373 + 374 + list_for_each_entry_safe(entry, next, &entry_list, list) { 375 + kobject_put(&entry->kobj); 376 + } 377 + } 378 + 379 + static int __init esrt_sysfs_init(void) 380 + { 381 + int error; 382 + struct efi_system_resource_table __iomem *ioesrt; 383 + 384 + pr_debug("esrt-sysfs: loading.\n"); 385 + if (!esrt_data || !esrt_data_size) 386 + return -ENOSYS; 387 + 388 + ioesrt = ioremap(esrt_data, esrt_data_size); 389 + if (!ioesrt) { 390 + pr_err("ioremap(%p, %zu) failed.\n", (void *)esrt_data, 391 + esrt_data_size); 392 + return -ENOMEM; 393 + } 394 + 395 + esrt = kmalloc(esrt_data_size, GFP_KERNEL); 396 + if (!esrt) { 397 + pr_err("kmalloc failed. (wanted %zu bytes)\n", esrt_data_size); 398 + iounmap(ioesrt); 399 + return -ENOMEM; 400 + } 401 + 402 + memcpy_fromio(esrt, ioesrt, esrt_data_size); 403 + 404 + esrt_kobj = kobject_create_and_add("esrt", efi_kobj); 405 + if (!esrt_kobj) { 406 + pr_err("Firmware table registration failed.\n"); 407 + error = -ENOMEM; 408 + goto err; 409 + } 410 + 411 + error = sysfs_create_group(esrt_kobj, &esrt_attr_group); 412 + if (error) { 413 + pr_err("Sysfs attribute export failed with error %d.\n", 414 + error); 415 + goto err_remove_esrt; 416 + } 417 + 418 + esrt_kset = kset_create_and_add("entries", NULL, esrt_kobj); 419 + if (!esrt_kset) { 420 + pr_err("kset creation failed.\n"); 421 + error = -ENOMEM; 422 + goto err_remove_group; 423 + } 424 + 425 + error = register_entries(); 426 + if (error) 427 + goto err_cleanup_list; 428 + 429 + memblock_remove(esrt_data, esrt_data_size); 430 + 431 + pr_debug("esrt-sysfs: loaded.\n"); 432 + 433 + return 0; 434 + err_cleanup_list: 435 + cleanup_entry_list(); 436 + kset_unregister(esrt_kset); 437 + err_remove_group: 438 + sysfs_remove_group(esrt_kobj, &esrt_attr_group); 439 + err_remove_esrt: 440 + kobject_put(esrt_kobj); 441 + err: 442 + kfree(esrt); 443 + esrt = NULL; 444 + return error; 445 + } 446 + 447 + static void __exit esrt_sysfs_exit(void) 448 + { 449 + pr_debug("esrt-sysfs: unloading.\n"); 450 + cleanup_entry_list(); 451 + kset_unregister(esrt_kset); 452 + sysfs_remove_group(esrt_kobj, &esrt_attr_group); 453 + kfree(esrt); 454 + esrt = NULL; 455 + kobject_del(esrt_kobj); 456 + kobject_put(esrt_kobj); 457 + } 458 + 459 + module_init(esrt_sysfs_init); 460 + module_exit(esrt_sysfs_exit); 461 + 462 + MODULE_AUTHOR("Peter Jones <pjones@redhat.com>"); 463 + MODULE_DESCRIPTION("EFI System Resource Table support"); 464 + MODULE_LICENSE("GPL");
+8
include/linux/efi.h
··· 583 583 #define EFI_FILE_INFO_ID \ 584 584 EFI_GUID( 0x9576e92, 0x6d3f, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b ) 585 585 586 + #define EFI_SYSTEM_RESOURCE_TABLE_GUID \ 587 + EFI_GUID( 0xb122a263, 0x3661, 0x4f68, 0x99, 0x29, 0x78, 0xf8, 0xb0, 0xd6, 0x21, 0x80 ) 588 + 586 589 #define EFI_FILE_SYSTEM_GUID \ 587 590 EFI_GUID( 0x964e5b22, 0x6459, 0x11d2, 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b ) 588 591 ··· 826 823 unsigned long fw_vendor; /* fw_vendor */ 827 824 unsigned long runtime; /* runtime table */ 828 825 unsigned long config_table; /* config tables */ 826 + unsigned long esrt; /* ESRT table */ 829 827 efi_get_time_t *get_time; 830 828 efi_set_time_t *set_time; 831 829 efi_get_wakeup_time_t *get_wakeup_time; ··· 879 875 #endif 880 876 extern void __iomem *efi_lookup_mapped_addr(u64 phys_addr); 881 877 extern int efi_config_init(efi_config_table_type_t *arch_tables); 878 + extern void __init efi_esrt_init(void); 882 879 extern int efi_config_parse_tables(void *config_tables, int count, int sz, 883 880 efi_config_table_type_t *arch_tables); 884 881 extern u64 efi_get_iobase (void); ··· 887 882 extern u64 efi_mem_attributes (unsigned long phys_addr); 888 883 extern u64 efi_mem_attribute (unsigned long phys_addr, unsigned long size); 889 884 extern int __init efi_uart_console_only (void); 885 + extern u64 efi_mem_desc_end(efi_memory_desc_t *md); 886 + extern int efi_mem_desc_lookup(u64 phys_addr, efi_memory_desc_t *out_md); 890 887 extern void efi_initialize_iomem_resources(struct resource *code_resource, 891 888 struct resource *data_resource, struct resource *bss_resource); 892 889 extern void efi_get_time(struct timespec *now); 893 890 extern void efi_reserve_boot_services(void); 894 891 extern int efi_get_fdt_params(struct efi_fdt_params *params, int verbose); 895 892 extern struct efi_memory_map memmap; 893 + extern struct kobject *efi_kobj; 896 894 897 895 extern int efi_reboot_quirk_mode; 898 896 extern bool efi_poweroff_required(void);