11da177e4SLinus Torvalds #ifndef _LINUX_EFI_H 21da177e4SLinus Torvalds #define _LINUX_EFI_H 31da177e4SLinus Torvalds 41da177e4SLinus Torvalds /* 51da177e4SLinus Torvalds * Extensible Firmware Interface 61da177e4SLinus Torvalds * Based on 'Extensible Firmware Interface Specification' version 0.9, April 30, 1999 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * Copyright (C) 1999 VA Linux Systems 91da177e4SLinus Torvalds * Copyright (C) 1999 Walt Drummond <drummond@valinux.com> 101da177e4SLinus Torvalds * Copyright (C) 1999, 2002-2003 Hewlett-Packard Co. 111da177e4SLinus Torvalds * David Mosberger-Tang <davidm@hpl.hp.com> 121da177e4SLinus Torvalds * Stephane Eranian <eranian@hpl.hp.com> 131da177e4SLinus Torvalds */ 141da177e4SLinus Torvalds #include <linux/init.h> 151da177e4SLinus Torvalds #include <linux/string.h> 161da177e4SLinus Torvalds #include <linux/time.h> 171da177e4SLinus Torvalds #include <linux/types.h> 181da177e4SLinus Torvalds #include <linux/proc_fs.h> 191da177e4SLinus Torvalds #include <linux/rtc.h> 201da177e4SLinus Torvalds #include <linux/ioport.h> 214a3575fdSHuang, Ying #include <linux/pfn.h> 225ee9c198SMatthew Garrett #include <linux/pstore.h> 231da177e4SLinus Torvalds 241da177e4SLinus Torvalds #include <asm/page.h> 251da177e4SLinus Torvalds #include <asm/system.h> 261da177e4SLinus Torvalds 271da177e4SLinus Torvalds #define EFI_SUCCESS 0 281da177e4SLinus Torvalds #define EFI_LOAD_ERROR ( 1 | (1UL << (BITS_PER_LONG-1))) 291da177e4SLinus Torvalds #define EFI_INVALID_PARAMETER ( 2 | (1UL << (BITS_PER_LONG-1))) 301da177e4SLinus Torvalds #define EFI_UNSUPPORTED ( 3 | (1UL << (BITS_PER_LONG-1))) 311da177e4SLinus Torvalds #define EFI_BAD_BUFFER_SIZE ( 4 | (1UL << (BITS_PER_LONG-1))) 321da177e4SLinus Torvalds #define EFI_BUFFER_TOO_SMALL ( 5 | (1UL << (BITS_PER_LONG-1))) 331da177e4SLinus Torvalds #define EFI_NOT_FOUND (14 | (1UL << (BITS_PER_LONG-1))) 341da177e4SLinus Torvalds 351da177e4SLinus Torvalds typedef unsigned long efi_status_t; 361da177e4SLinus Torvalds typedef u8 efi_bool_t; 371da177e4SLinus Torvalds typedef u16 efi_char16_t; /* UNICODE character */ 381da177e4SLinus Torvalds 391da177e4SLinus Torvalds 401da177e4SLinus Torvalds typedef struct { 411da177e4SLinus Torvalds u8 b[16]; 421da177e4SLinus Torvalds } efi_guid_t; 431da177e4SLinus Torvalds 441da177e4SLinus Torvalds #define EFI_GUID(a,b,c,d0,d1,d2,d3,d4,d5,d6,d7) \ 451da177e4SLinus Torvalds ((efi_guid_t) \ 461da177e4SLinus Torvalds {{ (a) & 0xff, ((a) >> 8) & 0xff, ((a) >> 16) & 0xff, ((a) >> 24) & 0xff, \ 471da177e4SLinus Torvalds (b) & 0xff, ((b) >> 8) & 0xff, \ 481da177e4SLinus Torvalds (c) & 0xff, ((c) >> 8) & 0xff, \ 491da177e4SLinus Torvalds (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }}) 501da177e4SLinus Torvalds 511da177e4SLinus Torvalds /* 521da177e4SLinus Torvalds * Generic EFI table header 531da177e4SLinus Torvalds */ 541da177e4SLinus Torvalds typedef struct { 551da177e4SLinus Torvalds u64 signature; 561da177e4SLinus Torvalds u32 revision; 571da177e4SLinus Torvalds u32 headersize; 581da177e4SLinus Torvalds u32 crc32; 591da177e4SLinus Torvalds u32 reserved; 601da177e4SLinus Torvalds } efi_table_hdr_t; 611da177e4SLinus Torvalds 621da177e4SLinus Torvalds /* 631da177e4SLinus Torvalds * Memory map descriptor: 641da177e4SLinus Torvalds */ 651da177e4SLinus Torvalds 661da177e4SLinus Torvalds /* Memory types: */ 671da177e4SLinus Torvalds #define EFI_RESERVED_TYPE 0 681da177e4SLinus Torvalds #define EFI_LOADER_CODE 1 691da177e4SLinus Torvalds #define EFI_LOADER_DATA 2 701da177e4SLinus Torvalds #define EFI_BOOT_SERVICES_CODE 3 711da177e4SLinus Torvalds #define EFI_BOOT_SERVICES_DATA 4 721da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_CODE 5 731da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_DATA 6 741da177e4SLinus Torvalds #define EFI_CONVENTIONAL_MEMORY 7 751da177e4SLinus Torvalds #define EFI_UNUSABLE_MEMORY 8 761da177e4SLinus Torvalds #define EFI_ACPI_RECLAIM_MEMORY 9 771da177e4SLinus Torvalds #define EFI_ACPI_MEMORY_NVS 10 781da177e4SLinus Torvalds #define EFI_MEMORY_MAPPED_IO 11 791da177e4SLinus Torvalds #define EFI_MEMORY_MAPPED_IO_PORT_SPACE 12 801da177e4SLinus Torvalds #define EFI_PAL_CODE 13 811da177e4SLinus Torvalds #define EFI_MAX_MEMORY_TYPE 14 821da177e4SLinus Torvalds 831da177e4SLinus Torvalds /* Attribute values: */ 841da177e4SLinus Torvalds #define EFI_MEMORY_UC ((u64)0x0000000000000001ULL) /* uncached */ 851da177e4SLinus Torvalds #define EFI_MEMORY_WC ((u64)0x0000000000000002ULL) /* write-coalescing */ 861da177e4SLinus Torvalds #define EFI_MEMORY_WT ((u64)0x0000000000000004ULL) /* write-through */ 871da177e4SLinus Torvalds #define EFI_MEMORY_WB ((u64)0x0000000000000008ULL) /* write-back */ 881da177e4SLinus Torvalds #define EFI_MEMORY_WP ((u64)0x0000000000001000ULL) /* write-protect */ 891da177e4SLinus Torvalds #define EFI_MEMORY_RP ((u64)0x0000000000002000ULL) /* read-protect */ 901da177e4SLinus Torvalds #define EFI_MEMORY_XP ((u64)0x0000000000004000ULL) /* execute-protect */ 911da177e4SLinus Torvalds #define EFI_MEMORY_RUNTIME ((u64)0x8000000000000000ULL) /* range requires runtime mapping */ 921da177e4SLinus Torvalds #define EFI_MEMORY_DESCRIPTOR_VERSION 1 931da177e4SLinus Torvalds 941da177e4SLinus Torvalds #define EFI_PAGE_SHIFT 12 951da177e4SLinus Torvalds 961da177e4SLinus Torvalds typedef struct { 971da177e4SLinus Torvalds u32 type; 981da177e4SLinus Torvalds u32 pad; 991da177e4SLinus Torvalds u64 phys_addr; 1001da177e4SLinus Torvalds u64 virt_addr; 1011da177e4SLinus Torvalds u64 num_pages; 1021da177e4SLinus Torvalds u64 attribute; 1031da177e4SLinus Torvalds } efi_memory_desc_t; 1041da177e4SLinus Torvalds 1053b370237SMatthew Garrett typedef struct { 1063b370237SMatthew Garrett efi_guid_t guid; 1073b370237SMatthew Garrett u32 headersize; 1083b370237SMatthew Garrett u32 flags; 1093b370237SMatthew Garrett u32 imagesize; 1103b370237SMatthew Garrett } efi_capsule_header_t; 1113b370237SMatthew Garrett 112bb05e4baSMatt Fleming /* 113bb05e4baSMatt Fleming * Allocation types for calls to boottime->allocate_pages. 114bb05e4baSMatt Fleming */ 115bb05e4baSMatt Fleming #define EFI_ALLOCATE_ANY_PAGES 0 116bb05e4baSMatt Fleming #define EFI_ALLOCATE_MAX_ADDRESS 1 117bb05e4baSMatt Fleming #define EFI_ALLOCATE_ADDRESS 2 118bb05e4baSMatt Fleming #define EFI_MAX_ALLOCATE_TYPE 3 119bb05e4baSMatt Fleming 120e088a4adSMatthew Wilcox typedef int (*efi_freemem_callback_t) (u64 start, u64 end, void *arg); 1211da177e4SLinus Torvalds 1221da177e4SLinus Torvalds /* 1231da177e4SLinus Torvalds * Types and defines for Time Services 1241da177e4SLinus Torvalds */ 1251da177e4SLinus Torvalds #define EFI_TIME_ADJUST_DAYLIGHT 0x1 1261da177e4SLinus Torvalds #define EFI_TIME_IN_DAYLIGHT 0x2 1271da177e4SLinus Torvalds #define EFI_UNSPECIFIED_TIMEZONE 0x07ff 1281da177e4SLinus Torvalds 1291da177e4SLinus Torvalds typedef struct { 1301da177e4SLinus Torvalds u16 year; 1311da177e4SLinus Torvalds u8 month; 1321da177e4SLinus Torvalds u8 day; 1331da177e4SLinus Torvalds u8 hour; 1341da177e4SLinus Torvalds u8 minute; 1351da177e4SLinus Torvalds u8 second; 1361da177e4SLinus Torvalds u8 pad1; 1371da177e4SLinus Torvalds u32 nanosecond; 1381da177e4SLinus Torvalds s16 timezone; 1391da177e4SLinus Torvalds u8 daylight; 1401da177e4SLinus Torvalds u8 pad2; 1411da177e4SLinus Torvalds } efi_time_t; 1421da177e4SLinus Torvalds 1431da177e4SLinus Torvalds typedef struct { 1441da177e4SLinus Torvalds u32 resolution; 1451da177e4SLinus Torvalds u32 accuracy; 1461da177e4SLinus Torvalds u8 sets_to_zero; 1471da177e4SLinus Torvalds } efi_time_cap_t; 1481da177e4SLinus Torvalds 1491da177e4SLinus Torvalds /* 150f30ca6baSMatt Fleming * EFI Boot Services table 151f30ca6baSMatt Fleming */ 152f30ca6baSMatt Fleming typedef struct { 153f30ca6baSMatt Fleming efi_table_hdr_t hdr; 154f30ca6baSMatt Fleming void *raise_tpl; 155f30ca6baSMatt Fleming void *restore_tpl; 156f30ca6baSMatt Fleming void *allocate_pages; 157f30ca6baSMatt Fleming void *free_pages; 158f30ca6baSMatt Fleming void *get_memory_map; 159f30ca6baSMatt Fleming void *allocate_pool; 160f30ca6baSMatt Fleming void *free_pool; 161f30ca6baSMatt Fleming void *create_event; 162f30ca6baSMatt Fleming void *set_timer; 163f30ca6baSMatt Fleming void *wait_for_event; 164f30ca6baSMatt Fleming void *signal_event; 165f30ca6baSMatt Fleming void *close_event; 166f30ca6baSMatt Fleming void *check_event; 167f30ca6baSMatt Fleming void *install_protocol_interface; 168f30ca6baSMatt Fleming void *reinstall_protocol_interface; 169f30ca6baSMatt Fleming void *uninstall_protocol_interface; 170f30ca6baSMatt Fleming void *handle_protocol; 171f30ca6baSMatt Fleming void *__reserved; 172f30ca6baSMatt Fleming void *register_protocol_notify; 173f30ca6baSMatt Fleming void *locate_handle; 174f30ca6baSMatt Fleming void *locate_device_path; 175f30ca6baSMatt Fleming void *install_configuration_table; 176f30ca6baSMatt Fleming void *load_image; 177f30ca6baSMatt Fleming void *start_image; 178f30ca6baSMatt Fleming void *exit; 179f30ca6baSMatt Fleming void *unload_image; 180f30ca6baSMatt Fleming void *exit_boot_services; 181f30ca6baSMatt Fleming void *get_next_monotonic_count; 182f30ca6baSMatt Fleming void *stall; 183f30ca6baSMatt Fleming void *set_watchdog_timer; 184f30ca6baSMatt Fleming void *connect_controller; 185f30ca6baSMatt Fleming void *disconnect_controller; 186f30ca6baSMatt Fleming void *open_protocol; 187f30ca6baSMatt Fleming void *close_protocol; 188f30ca6baSMatt Fleming void *open_protocol_information; 189f30ca6baSMatt Fleming void *protocols_per_handle; 190f30ca6baSMatt Fleming void *locate_handle_buffer; 191f30ca6baSMatt Fleming void *locate_protocol; 192f30ca6baSMatt Fleming void *install_multiple_protocol_interfaces; 193f30ca6baSMatt Fleming void *uninstall_multiple_protocol_interfaces; 194f30ca6baSMatt Fleming void *calculate_crc32; 195f30ca6baSMatt Fleming void *copy_mem; 196f30ca6baSMatt Fleming void *set_mem; 197f30ca6baSMatt Fleming void *create_event_ex; 198f30ca6baSMatt Fleming } efi_boot_services_t; 199f30ca6baSMatt Fleming 200f30ca6baSMatt Fleming /* 2011da177e4SLinus Torvalds * Types and defines for EFI ResetSystem 2021da177e4SLinus Torvalds */ 2031da177e4SLinus Torvalds #define EFI_RESET_COLD 0 2041da177e4SLinus Torvalds #define EFI_RESET_WARM 1 2051da177e4SLinus Torvalds #define EFI_RESET_SHUTDOWN 2 2061da177e4SLinus Torvalds 2071da177e4SLinus Torvalds /* 2081da177e4SLinus Torvalds * EFI Runtime Services table 2091da177e4SLinus Torvalds */ 2101da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_SIGNATURE ((u64)0x5652453544e5552ULL) 2111da177e4SLinus Torvalds #define EFI_RUNTIME_SERVICES_REVISION 0x00010000 2121da177e4SLinus Torvalds 2131da177e4SLinus Torvalds typedef struct { 2141da177e4SLinus Torvalds efi_table_hdr_t hdr; 2151da177e4SLinus Torvalds unsigned long get_time; 2161da177e4SLinus Torvalds unsigned long set_time; 2171da177e4SLinus Torvalds unsigned long get_wakeup_time; 2181da177e4SLinus Torvalds unsigned long set_wakeup_time; 2191da177e4SLinus Torvalds unsigned long set_virtual_address_map; 2201da177e4SLinus Torvalds unsigned long convert_pointer; 2211da177e4SLinus Torvalds unsigned long get_variable; 2221da177e4SLinus Torvalds unsigned long get_next_variable; 2231da177e4SLinus Torvalds unsigned long set_variable; 2241da177e4SLinus Torvalds unsigned long get_next_high_mono_count; 2251da177e4SLinus Torvalds unsigned long reset_system; 2263b370237SMatthew Garrett unsigned long update_capsule; 2273b370237SMatthew Garrett unsigned long query_capsule_caps; 2283b370237SMatthew Garrett unsigned long query_variable_info; 2291da177e4SLinus Torvalds } efi_runtime_services_t; 2301da177e4SLinus Torvalds 2311da177e4SLinus Torvalds typedef efi_status_t efi_get_time_t (efi_time_t *tm, efi_time_cap_t *tc); 2321da177e4SLinus Torvalds typedef efi_status_t efi_set_time_t (efi_time_t *tm); 2331da177e4SLinus Torvalds typedef efi_status_t efi_get_wakeup_time_t (efi_bool_t *enabled, efi_bool_t *pending, 2341da177e4SLinus Torvalds efi_time_t *tm); 2351da177e4SLinus Torvalds typedef efi_status_t efi_set_wakeup_time_t (efi_bool_t enabled, efi_time_t *tm); 2361da177e4SLinus Torvalds typedef efi_status_t efi_get_variable_t (efi_char16_t *name, efi_guid_t *vendor, u32 *attr, 2371da177e4SLinus Torvalds unsigned long *data_size, void *data); 2381da177e4SLinus Torvalds typedef efi_status_t efi_get_next_variable_t (unsigned long *name_size, efi_char16_t *name, 2391da177e4SLinus Torvalds efi_guid_t *vendor); 2401da177e4SLinus Torvalds typedef efi_status_t efi_set_variable_t (efi_char16_t *name, efi_guid_t *vendor, 241f7a2d73fSMatthew Garrett u32 attr, unsigned long data_size, 2421da177e4SLinus Torvalds void *data); 2431da177e4SLinus Torvalds typedef efi_status_t efi_get_next_high_mono_count_t (u32 *count); 2441da177e4SLinus Torvalds typedef void efi_reset_system_t (int reset_type, efi_status_t status, 2451da177e4SLinus Torvalds unsigned long data_size, efi_char16_t *data); 2461da177e4SLinus Torvalds typedef efi_status_t efi_set_virtual_address_map_t (unsigned long memory_map_size, 2471da177e4SLinus Torvalds unsigned long descriptor_size, 2481da177e4SLinus Torvalds u32 descriptor_version, 2491da177e4SLinus Torvalds efi_memory_desc_t *virtual_map); 2503b370237SMatthew Garrett typedef efi_status_t efi_query_variable_info_t(u32 attr, 2513b370237SMatthew Garrett u64 *storage_space, 2523b370237SMatthew Garrett u64 *remaining_space, 2533b370237SMatthew Garrett u64 *max_variable_size); 2543b370237SMatthew Garrett typedef efi_status_t efi_update_capsule_t(efi_capsule_header_t **capsules, 2553b370237SMatthew Garrett unsigned long count, 2563b370237SMatthew Garrett unsigned long sg_list); 2573b370237SMatthew Garrett typedef efi_status_t efi_query_capsule_caps_t(efi_capsule_header_t **capsules, 2583b370237SMatthew Garrett unsigned long count, 2593b370237SMatthew Garrett u64 *max_size, 2603b370237SMatthew Garrett int *reset_type); 2611da177e4SLinus Torvalds 2621da177e4SLinus Torvalds /* 2631da177e4SLinus Torvalds * EFI Configuration Table and GUID definitions 2641da177e4SLinus Torvalds */ 2651da177e4SLinus Torvalds #define NULL_GUID \ 2661da177e4SLinus Torvalds EFI_GUID( 0x00000000, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ) 2671da177e4SLinus Torvalds 2681da177e4SLinus Torvalds #define MPS_TABLE_GUID \ 2691da177e4SLinus Torvalds EFI_GUID( 0xeb9d2d2f, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d ) 2701da177e4SLinus Torvalds 2711da177e4SLinus Torvalds #define ACPI_TABLE_GUID \ 2721da177e4SLinus Torvalds EFI_GUID( 0xeb9d2d30, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d ) 2731da177e4SLinus Torvalds 2741da177e4SLinus Torvalds #define ACPI_20_TABLE_GUID \ 2751da177e4SLinus Torvalds EFI_GUID( 0x8868e871, 0xe4f1, 0x11d3, 0xbc, 0x22, 0x0, 0x80, 0xc7, 0x3c, 0x88, 0x81 ) 2761da177e4SLinus Torvalds 2771da177e4SLinus Torvalds #define SMBIOS_TABLE_GUID \ 2781da177e4SLinus Torvalds EFI_GUID( 0xeb9d2d31, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d ) 2791da177e4SLinus Torvalds 2801da177e4SLinus Torvalds #define SAL_SYSTEM_TABLE_GUID \ 2811da177e4SLinus Torvalds EFI_GUID( 0xeb9d2d32, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d ) 2821da177e4SLinus Torvalds 2831da177e4SLinus Torvalds #define HCDP_TABLE_GUID \ 2841da177e4SLinus Torvalds EFI_GUID( 0xf951938d, 0x620b, 0x42ef, 0x82, 0x79, 0xa8, 0x4b, 0x79, 0x61, 0x78, 0x98 ) 2851da177e4SLinus Torvalds 2861da177e4SLinus Torvalds #define UGA_IO_PROTOCOL_GUID \ 2871da177e4SLinus Torvalds EFI_GUID( 0x61a4d49e, 0x6f68, 0x4f1b, 0xb9, 0x22, 0xa8, 0x6e, 0xed, 0xb, 0x7, 0xa2 ) 2881da177e4SLinus Torvalds 2891da177e4SLinus Torvalds #define EFI_GLOBAL_VARIABLE_GUID \ 2901da177e4SLinus Torvalds EFI_GUID( 0x8be4df61, 0x93ca, 0x11d2, 0xaa, 0x0d, 0x00, 0xe0, 0x98, 0x03, 0x2b, 0x8c ) 2911da177e4SLinus Torvalds 292a50f70b1SRuss Anderson #define UV_SYSTEM_TABLE_GUID \ 293a50f70b1SRuss Anderson EFI_GUID( 0x3b13a7d4, 0x633e, 0x11dd, 0x93, 0xec, 0xda, 0x25, 0x56, 0xd8, 0x95, 0x93 ) 294a50f70b1SRuss Anderson 2955ee9c198SMatthew Garrett #define LINUX_EFI_CRASH_GUID \ 2965ee9c198SMatthew Garrett EFI_GUID( 0xcfc8fc79, 0xbe2e, 0x4ddc, 0x97, 0xf0, 0x9f, 0x98, 0xbf, 0xe2, 0x98, 0xa0 ) 2975ee9c198SMatthew Garrett 2988e84f345SMatt Fleming #define LOADED_IMAGE_PROTOCOL_GUID \ 2998e84f345SMatt Fleming EFI_GUID( 0x5b1b31a1, 0x9562, 0x11d2, 0x8e, 0x3f, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b ) 3008e84f345SMatt Fleming 301*0f7c5d47SMatt Fleming #define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \ 302*0f7c5d47SMatt Fleming EFI_GUID( 0x9042a9de, 0x23dc, 0x4a38, 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a ) 303*0f7c5d47SMatt Fleming 304*0f7c5d47SMatt Fleming #define EFI_UGA_PROTOCOL_GUID \ 305*0f7c5d47SMatt Fleming EFI_GUID( 0x982c298b, 0xf4fa, 0x41cb, 0xb8, 0x38, 0x77, 0xaa, 0x68, 0x8f, 0xb8, 0x39 ) 306*0f7c5d47SMatt Fleming 307*0f7c5d47SMatt Fleming #define EFI_PCI_IO_PROTOCOL_GUID \ 308*0f7c5d47SMatt Fleming EFI_GUID( 0x4cf5b200, 0x68b8, 0x4ca5, 0x9e, 0xec, 0xb2, 0x3e, 0x3f, 0x50, 0x2, 0x9a ) 309*0f7c5d47SMatt Fleming 3101da177e4SLinus Torvalds typedef struct { 3111da177e4SLinus Torvalds efi_guid_t guid; 3121da177e4SLinus Torvalds unsigned long table; 3131da177e4SLinus Torvalds } efi_config_table_t; 3141da177e4SLinus Torvalds 3151da177e4SLinus Torvalds #define EFI_SYSTEM_TABLE_SIGNATURE ((u64)0x5453595320494249ULL) 3161da177e4SLinus Torvalds 3173b370237SMatthew Garrett #define EFI_2_30_SYSTEM_TABLE_REVISION ((2 << 16) | (30)) 3183b370237SMatthew Garrett #define EFI_2_20_SYSTEM_TABLE_REVISION ((2 << 16) | (20)) 3193b370237SMatthew Garrett #define EFI_2_10_SYSTEM_TABLE_REVISION ((2 << 16) | (10)) 3203b370237SMatthew Garrett #define EFI_2_00_SYSTEM_TABLE_REVISION ((2 << 16) | (00)) 3213b370237SMatthew Garrett #define EFI_1_10_SYSTEM_TABLE_REVISION ((1 << 16) | (10)) 3223b370237SMatthew Garrett #define EFI_1_02_SYSTEM_TABLE_REVISION ((1 << 16) | (02)) 3233b370237SMatthew Garrett 3241da177e4SLinus Torvalds typedef struct { 3251da177e4SLinus Torvalds efi_table_hdr_t hdr; 3261da177e4SLinus Torvalds unsigned long fw_vendor; /* physical addr of CHAR16 vendor string */ 3271da177e4SLinus Torvalds u32 fw_revision; 3281da177e4SLinus Torvalds unsigned long con_in_handle; 3291da177e4SLinus Torvalds unsigned long con_in; 3301da177e4SLinus Torvalds unsigned long con_out_handle; 3311da177e4SLinus Torvalds unsigned long con_out; 3321da177e4SLinus Torvalds unsigned long stderr_handle; 3331da177e4SLinus Torvalds unsigned long stderr; 3341da177e4SLinus Torvalds efi_runtime_services_t *runtime; 335f30ca6baSMatt Fleming efi_boot_services_t *boottime; 3361da177e4SLinus Torvalds unsigned long nr_tables; 3371da177e4SLinus Torvalds unsigned long tables; 3381da177e4SLinus Torvalds } efi_system_table_t; 3391da177e4SLinus Torvalds 3401da177e4SLinus Torvalds struct efi_memory_map { 3417ae65fd3SMatt Tolentino void *phys_map; 3427ae65fd3SMatt Tolentino void *map; 3437ae65fd3SMatt Tolentino void *map_end; 3441da177e4SLinus Torvalds int nr_map; 3451da177e4SLinus Torvalds unsigned long desc_version; 3467ae65fd3SMatt Tolentino unsigned long desc_size; 3471da177e4SLinus Torvalds }; 3481da177e4SLinus Torvalds 3498e84f345SMatt Fleming typedef struct { 3508e84f345SMatt Fleming u32 revision; 3518e84f345SMatt Fleming void *parent_handle; 3528e84f345SMatt Fleming efi_system_table_t *system_table; 3538e84f345SMatt Fleming void *device_handle; 3548e84f345SMatt Fleming void *file_path; 3558e84f345SMatt Fleming void *reserved; 3568e84f345SMatt Fleming u32 load_options_size; 3578e84f345SMatt Fleming void *load_options; 3588e84f345SMatt Fleming void *image_base; 3598e84f345SMatt Fleming __aligned_u64 image_size; 3608e84f345SMatt Fleming unsigned int image_code_type; 3618e84f345SMatt Fleming unsigned int image_data_type; 3628e84f345SMatt Fleming unsigned long unload; 3638e84f345SMatt Fleming } efi_loaded_image_t; 3648e84f345SMatt Fleming 365b2c99e3cSBjorn Helgaas #define EFI_INVALID_TABLE_ADDR (~0UL) 366b2c99e3cSBjorn Helgaas 3671da177e4SLinus Torvalds /* 3681da177e4SLinus Torvalds * All runtime access to EFI goes through this structure: 3691da177e4SLinus Torvalds */ 3701da177e4SLinus Torvalds extern struct efi { 3711da177e4SLinus Torvalds efi_system_table_t *systab; /* EFI system table */ 3723b370237SMatthew Garrett unsigned int runtime_version; /* Runtime services version */ 373b2c99e3cSBjorn Helgaas unsigned long mps; /* MPS table */ 374b2c99e3cSBjorn Helgaas unsigned long acpi; /* ACPI table (IA64 ext 0.71) */ 375b2c99e3cSBjorn Helgaas unsigned long acpi20; /* ACPI table (ACPI 2.0) */ 376b2c99e3cSBjorn Helgaas unsigned long smbios; /* SM BIOS table */ 377b2c99e3cSBjorn Helgaas unsigned long sal_systab; /* SAL system table */ 378b2c99e3cSBjorn Helgaas unsigned long boot_info; /* boot info table */ 379b2c99e3cSBjorn Helgaas unsigned long hcdp; /* HCDP table */ 380b2c99e3cSBjorn Helgaas unsigned long uga; /* UGA table */ 381a50f70b1SRuss Anderson unsigned long uv_systab; /* UV system table */ 3821da177e4SLinus Torvalds efi_get_time_t *get_time; 3831da177e4SLinus Torvalds efi_set_time_t *set_time; 3841da177e4SLinus Torvalds efi_get_wakeup_time_t *get_wakeup_time; 3851da177e4SLinus Torvalds efi_set_wakeup_time_t *set_wakeup_time; 3861da177e4SLinus Torvalds efi_get_variable_t *get_variable; 3871da177e4SLinus Torvalds efi_get_next_variable_t *get_next_variable; 3881da177e4SLinus Torvalds efi_set_variable_t *set_variable; 3893b370237SMatthew Garrett efi_query_variable_info_t *query_variable_info; 3903b370237SMatthew Garrett efi_update_capsule_t *update_capsule; 3913b370237SMatthew Garrett efi_query_capsule_caps_t *query_capsule_caps; 3921da177e4SLinus Torvalds efi_get_next_high_mono_count_t *get_next_high_mono_count; 3931da177e4SLinus Torvalds efi_reset_system_t *reset_system; 3941da177e4SLinus Torvalds efi_set_virtual_address_map_t *set_virtual_address_map; 3951da177e4SLinus Torvalds } efi; 3961da177e4SLinus Torvalds 3971da177e4SLinus Torvalds static inline int 3981da177e4SLinus Torvalds efi_guidcmp (efi_guid_t left, efi_guid_t right) 3991da177e4SLinus Torvalds { 4001da177e4SLinus Torvalds return memcmp(&left, &right, sizeof (efi_guid_t)); 4011da177e4SLinus Torvalds } 4021da177e4SLinus Torvalds 4031da177e4SLinus Torvalds static inline char * 4041da177e4SLinus Torvalds efi_guid_unparse(efi_guid_t *guid, char *out) 4051da177e4SLinus Torvalds { 406925ede0bSJoe Perches sprintf(out, "%pUl", guid->b); 4071da177e4SLinus Torvalds return out; 4081da177e4SLinus Torvalds } 4091da177e4SLinus Torvalds 4101da177e4SLinus Torvalds extern void efi_init (void); 4111da177e4SLinus Torvalds extern void *efi_get_pal_addr (void); 4121da177e4SLinus Torvalds extern void efi_map_pal_code (void); 4131da177e4SLinus Torvalds extern void efi_memmap_walk (efi_freemem_callback_t callback, void *arg); 4141da177e4SLinus Torvalds extern void efi_gettimeofday (struct timespec *ts); 4151da177e4SLinus Torvalds extern void efi_enter_virtual_mode (void); /* switch EFI to virtual mode, if possible */ 4161da177e4SLinus Torvalds extern u64 efi_get_iobase (void); 4171da177e4SLinus Torvalds extern u32 efi_mem_type (unsigned long phys_addr); 4181da177e4SLinus Torvalds extern u64 efi_mem_attributes (unsigned long phys_addr); 41932e62c63SBjorn Helgaas extern u64 efi_mem_attribute (unsigned long phys_addr, unsigned long size); 4201da177e4SLinus Torvalds extern int __init efi_uart_console_only (void); 4211da177e4SLinus Torvalds extern void efi_initialize_iomem_resources(struct resource *code_resource, 42200bf4098SBernhard Walle struct resource *data_resource, struct resource *bss_resource); 423e1cccf48SArtiom Myaskouvskey extern unsigned long efi_get_time(void); 424472ba91dSAl Viro extern int efi_set_rtc_mmss(unsigned long nowtime); 425916f676fSMatthew Garrett extern void efi_reserve_boot_services(void); 4261da177e4SLinus Torvalds extern struct efi_memory_map memmap; 4271da177e4SLinus Torvalds 4281da177e4SLinus Torvalds /** 4291da177e4SLinus Torvalds * efi_range_is_wc - check the WC bit on an address range 4301da177e4SLinus Torvalds * @start: starting kvirt address 4311da177e4SLinus Torvalds * @len: length of range 4321da177e4SLinus Torvalds * 4331da177e4SLinus Torvalds * Consult the EFI memory map and make sure it's ok to set this range WC. 4341da177e4SLinus Torvalds * Returns true or false. 4351da177e4SLinus Torvalds */ 4361da177e4SLinus Torvalds static inline int efi_range_is_wc(unsigned long start, unsigned long len) 4371da177e4SLinus Torvalds { 438986a80d5SJesper Juhl unsigned long i; 4391da177e4SLinus Torvalds 4401da177e4SLinus Torvalds for (i = 0; i < len; i += (1UL << EFI_PAGE_SHIFT)) { 4411da177e4SLinus Torvalds unsigned long paddr = __pa(start + i); 4421da177e4SLinus Torvalds if (!(efi_mem_attributes(paddr) & EFI_MEMORY_WC)) 4431da177e4SLinus Torvalds return 0; 4441da177e4SLinus Torvalds } 4451da177e4SLinus Torvalds /* The range checked out */ 4461da177e4SLinus Torvalds return 1; 4471da177e4SLinus Torvalds } 4481da177e4SLinus Torvalds 4491da177e4SLinus Torvalds #ifdef CONFIG_EFI_PCDP 4501da177e4SLinus Torvalds extern int __init efi_setup_pcdp_console(char *); 4511da177e4SLinus Torvalds #endif 4521da177e4SLinus Torvalds 4531da177e4SLinus Torvalds /* 4541da177e4SLinus Torvalds * We play games with efi_enabled so that the compiler will, if possible, remove 4551da177e4SLinus Torvalds * EFI-related code altogether. 4561da177e4SLinus Torvalds */ 4571da177e4SLinus Torvalds #ifdef CONFIG_EFI 4581da177e4SLinus Torvalds # ifdef CONFIG_X86 4591da177e4SLinus Torvalds extern int efi_enabled; 4601da177e4SLinus Torvalds # else 4611da177e4SLinus Torvalds # define efi_enabled 1 4621da177e4SLinus Torvalds # endif 4631da177e4SLinus Torvalds #else 4641da177e4SLinus Torvalds # define efi_enabled 0 4651da177e4SLinus Torvalds #endif 4661da177e4SLinus Torvalds 4671da177e4SLinus Torvalds /* 4681da177e4SLinus Torvalds * Variable Attributes 4691da177e4SLinus Torvalds */ 4701da177e4SLinus Torvalds #define EFI_VARIABLE_NON_VOLATILE 0x0000000000000001 4711da177e4SLinus Torvalds #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002 4721da177e4SLinus Torvalds #define EFI_VARIABLE_RUNTIME_ACCESS 0x0000000000000004 4731da177e4SLinus Torvalds 4741da177e4SLinus Torvalds /* 4751da177e4SLinus Torvalds * EFI Device Path information 4761da177e4SLinus Torvalds */ 4771da177e4SLinus Torvalds #define EFI_DEV_HW 0x01 4781da177e4SLinus Torvalds #define EFI_DEV_PCI 1 4791da177e4SLinus Torvalds #define EFI_DEV_PCCARD 2 4801da177e4SLinus Torvalds #define EFI_DEV_MEM_MAPPED 3 4811da177e4SLinus Torvalds #define EFI_DEV_VENDOR 4 4821da177e4SLinus Torvalds #define EFI_DEV_CONTROLLER 5 4831da177e4SLinus Torvalds #define EFI_DEV_ACPI 0x02 4841da177e4SLinus Torvalds #define EFI_DEV_BASIC_ACPI 1 4851da177e4SLinus Torvalds #define EFI_DEV_EXPANDED_ACPI 2 4861da177e4SLinus Torvalds #define EFI_DEV_MSG 0x03 4871da177e4SLinus Torvalds #define EFI_DEV_MSG_ATAPI 1 4881da177e4SLinus Torvalds #define EFI_DEV_MSG_SCSI 2 4891da177e4SLinus Torvalds #define EFI_DEV_MSG_FC 3 4901da177e4SLinus Torvalds #define EFI_DEV_MSG_1394 4 4911da177e4SLinus Torvalds #define EFI_DEV_MSG_USB 5 4921da177e4SLinus Torvalds #define EFI_DEV_MSG_USB_CLASS 15 4931da177e4SLinus Torvalds #define EFI_DEV_MSG_I20 6 4941da177e4SLinus Torvalds #define EFI_DEV_MSG_MAC 11 4951da177e4SLinus Torvalds #define EFI_DEV_MSG_IPV4 12 4961da177e4SLinus Torvalds #define EFI_DEV_MSG_IPV6 13 4971da177e4SLinus Torvalds #define EFI_DEV_MSG_INFINIBAND 9 4981da177e4SLinus Torvalds #define EFI_DEV_MSG_UART 14 4991da177e4SLinus Torvalds #define EFI_DEV_MSG_VENDOR 10 5001da177e4SLinus Torvalds #define EFI_DEV_MEDIA 0x04 5011da177e4SLinus Torvalds #define EFI_DEV_MEDIA_HARD_DRIVE 1 5021da177e4SLinus Torvalds #define EFI_DEV_MEDIA_CDROM 2 5031da177e4SLinus Torvalds #define EFI_DEV_MEDIA_VENDOR 3 5041da177e4SLinus Torvalds #define EFI_DEV_MEDIA_FILE 4 5051da177e4SLinus Torvalds #define EFI_DEV_MEDIA_PROTOCOL 5 5061da177e4SLinus Torvalds #define EFI_DEV_BIOS_BOOT 0x05 5071da177e4SLinus Torvalds #define EFI_DEV_END_PATH 0x7F 5081da177e4SLinus Torvalds #define EFI_DEV_END_PATH2 0xFF 5091da177e4SLinus Torvalds #define EFI_DEV_END_INSTANCE 0x01 5101da177e4SLinus Torvalds #define EFI_DEV_END_ENTIRE 0xFF 5111da177e4SLinus Torvalds 5121da177e4SLinus Torvalds struct efi_generic_dev_path { 5131da177e4SLinus Torvalds u8 type; 5141da177e4SLinus Torvalds u8 sub_type; 5151da177e4SLinus Torvalds u16 length; 5161da177e4SLinus Torvalds } __attribute ((packed)); 5171da177e4SLinus Torvalds 5184a3575fdSHuang, Ying static inline void memrange_efi_to_native(u64 *addr, u64 *npages) 5194a3575fdSHuang, Ying { 5204a3575fdSHuang, Ying *npages = PFN_UP(*addr + (*npages<<EFI_PAGE_SHIFT)) - PFN_DOWN(*addr); 5214a3575fdSHuang, Ying *addr &= PAGE_MASK; 5224a3575fdSHuang, Ying } 5234a3575fdSHuang, Ying 5244fc756bdSMike Waychison #if defined(CONFIG_EFI_VARS) || defined(CONFIG_EFI_VARS_MODULE) 5254fc756bdSMike Waychison /* 5264fc756bdSMike Waychison * EFI Variable support. 5274fc756bdSMike Waychison * 5284fc756bdSMike Waychison * Different firmware drivers can expose their EFI-like variables using 5294fc756bdSMike Waychison * the following. 5304fc756bdSMike Waychison */ 5314fc756bdSMike Waychison 5324fc756bdSMike Waychison struct efivar_operations { 5334fc756bdSMike Waychison efi_get_variable_t *get_variable; 5344fc756bdSMike Waychison efi_get_next_variable_t *get_next_variable; 5354fc756bdSMike Waychison efi_set_variable_t *set_variable; 5364fc756bdSMike Waychison }; 5374fc756bdSMike Waychison 5384fc756bdSMike Waychison struct efivars { 5394fc756bdSMike Waychison /* 5404fc756bdSMike Waychison * ->lock protects two things: 5414fc756bdSMike Waychison * 1) ->list - adds, removals, reads, writes 5424fc756bdSMike Waychison * 2) ops.[gs]et_variable() calls. 5434fc756bdSMike Waychison * It must not be held when creating sysfs entries or calling kmalloc. 5444fc756bdSMike Waychison * ops.get_next_variable() is only called from register_efivars(), 5454fc756bdSMike Waychison * which is protected by the BKL, so that path is safe. 5464fc756bdSMike Waychison */ 5474fc756bdSMike Waychison spinlock_t lock; 5484fc756bdSMike Waychison struct list_head list; 5494fc756bdSMike Waychison struct kset *kset; 5504fc756bdSMike Waychison struct bin_attribute *new_var, *del_var; 5514fc756bdSMike Waychison const struct efivar_operations *ops; 5525ee9c198SMatthew Garrett struct efivar_entry *walk_entry; 5535ee9c198SMatthew Garrett struct pstore_info efi_pstore_info; 5544fc756bdSMike Waychison }; 5554fc756bdSMike Waychison 5564fc756bdSMike Waychison int register_efivars(struct efivars *efivars, 5574fc756bdSMike Waychison const struct efivar_operations *ops, 5584fc756bdSMike Waychison struct kobject *parent_kobj); 5594fc756bdSMike Waychison void unregister_efivars(struct efivars *efivars); 5604fc756bdSMike Waychison 5614fc756bdSMike Waychison #endif /* CONFIG_EFI_VARS */ 5624fc756bdSMike Waychison 5631da177e4SLinus Torvalds #endif /* _LINUX_EFI_H */ 564