global: Migrate CONFIG_STACKBASE to CFG
[platform/kernel/u-boot.git] / include / efi.h
index e12697a..42f4e58 100644 (file)
 #include <linux/string.h>
 #include <linux/types.h>
 
+/* Type INTN in UEFI specification */
+#define efi_intn_t ssize_t
+/* Type UINTN in UEFI specification*/
+#define efi_uintn_t size_t
+
 /*
  * EFI on x86_64 uses the Microsoft ABI which is not the default for GCC.
  *
 #define EFIAPI __attribute__((ms_abi))
 #define efi_va_list __builtin_ms_va_list
 #define efi_va_start __builtin_ms_va_start
+#define efi_va_copy __builtin_ms_va_copy
 #define efi_va_arg __builtin_va_arg
 #define efi_va_end __builtin_ms_va_end
 #else
 #define EFIAPI asmlinkage
 #define efi_va_list va_list
 #define efi_va_start va_start
+#define efi_va_copy va_copy
 #define efi_va_arg va_arg
 #define efi_va_end va_end
 #endif /* __x86_64__ */
@@ -120,8 +127,36 @@ struct efi_table_hdr {
        u32 reserved;
 };
 
+/* Allocation types for calls to boottime->allocate_pages*/
+/**
+ * enum efi_allocate_type - address restriction for memory allocation
+ */
+enum efi_allocate_type {
+       /**
+        * @EFI_ALLOCATE_ANY_PAGES:
+        * Allocate any block of sufficient size. Ignore memory address.
+        */
+       EFI_ALLOCATE_ANY_PAGES,
+       /**
+        * @EFI_ALLOCATE_MAX_ADDRESS:
+        * Allocate a memory block with an uppermost address less or equal
+        * to the indicated address.
+        */
+       EFI_ALLOCATE_MAX_ADDRESS,
+       /**
+        * @EFI_ALLOCATE_ADDRESS:
+        * Allocate a memory block starting at the indicatged adress.
+        */
+       EFI_ALLOCATE_ADDRESS,
+       /**
+        * @EFI_MAX_ALLOCATE_TYPE:
+        * Value use for range checking.
+        */
+       EFI_MAX_ALLOCATE_TYPE,
+};
+
 /* Enumeration of memory types introduced in UEFI */
-enum efi_mem_type {
+enum efi_memory_type {
        EFI_RESERVED_MEMORY_TYPE,
        /*
         * The code portions of a loaded application.
@@ -175,12 +210,15 @@ enum efi_mem_type {
         */
        EFI_PAL_CODE,
        /*
-        * Non-volatile memory.
+        * Byte addressable non-volatile memory.
         */
        EFI_PERSISTENT_MEMORY_TYPE,
+       /*
+        * Unaccepted memory must be accepted by boot target before usage.
+        */
+       EFI_UNACCEPTED_MEMORY_TYPE,
 
        EFI_MAX_MEMORY_TYPE,
-       EFI_TABLE_END,  /* For efi_build_mem_table() */
 };
 
 /* Attribute values */
@@ -196,6 +234,8 @@ enum efi_mem_type {
 #define EFI_MEMORY_MORE_RELIABLE \
                                ((u64)0x0000000000010000ULL)    /* higher reliability */
 #define EFI_MEMORY_RO          ((u64)0x0000000000020000ULL)    /* read-only */
+#define EFI_MEMORY_SP          ((u64)0x0000000000040000ULL)    /* specific-purpose memory (SPM) */
+#define EFI_MEMORY_CPU_CRYPTO  ((u64)0x0000000000080000ULL)    /* cryptographically protectable */
 #define EFI_MEMORY_RUNTIME     ((u64)0x8000000000000000ULL)    /* range requires runtime mapping */
 #define EFI_MEM_DESC_VERSION   1
 
@@ -214,12 +254,6 @@ struct efi_mem_desc {
 
 #define EFI_MEMORY_DESCRIPTOR_VERSION 1
 
-/* Allocation types for calls to boottime->allocate_pages*/
-#define EFI_ALLOCATE_ANY_PAGES         0
-#define EFI_ALLOCATE_MAX_ADDRESS       1
-#define EFI_ALLOCATE_ADDRESS           2
-#define EFI_MAX_ALLOCATE_TYPE          3
-
 /* Types and defines for Time Services */
 #define EFI_TIME_ADJUST_DAYLIGHT 0x1
 #define EFI_TIME_IN_DAYLIGHT     0x2
@@ -289,7 +323,7 @@ struct efi_info_hdr {
  * struct efi_entry_hdr - Header for a table entry
  *
  * @type:      enum eft_entry_t
- * @size       size of entry bytes excluding header and padding
+ * @size:      size of entry bytes excluding header and padding
  * @addr:      address of this entry (0 if it follows the header )
  * @link:      size of entry including header and padding
  * @spare1:    Spare space for expansion
@@ -363,25 +397,72 @@ struct efi_entry_systable {
 };
 
 static inline struct efi_mem_desc *efi_get_next_mem_desc(
-               struct efi_entry_memmap *map, struct efi_mem_desc *desc)
+               struct efi_mem_desc *desc, int desc_size)
 {
-       return (struct efi_mem_desc *)((ulong)desc + map->desc_size);
+       return (struct efi_mem_desc *)((ulong)desc + desc_size);
 }
 
+/**
+ * struct efi_priv - Information about the environment provided by EFI
+ *
+ * @parent_image: image passed into the EFI app or stub
+ * @sys_table: Pointer to system table
+ * @boot: Pointer to boot-services table
+ * @run: Pointer to runtime-services table
+ * @memmap_key: Key returned from get_memory_map()
+ * @memmap_desc: List of memory-map records
+ * @memmap_alloc: Amount of memory allocated for memory map list
+ * @memmap_size Size of memory-map list in bytes
+ * @memmap_desc_size: Size of an individual memory-map record, in bytes
+ * @memmap_version: Memory-map version
+ *
+ * @use_pool_for_malloc: true if all allocation should go through the EFI 'pool'
+ *     methods allocate_pool() and free_pool(); false to use 'pages' methods
+ *     allocate_pages() and free_pages()
+ * @ram_base: Base address of RAM (size CONFIG_EFI_RAM_SIZE)
+ * @image_data_type: Type of the loaded image (e.g. EFI_LOADER_CODE)
+ *
+ * @info: Header of the info list, holding info collected by the stub and passed
+ *     to U-Boot
+ * @info_size: Size of the info list @info in bytes
+ * @next_hdr: Pointer to where to put the next header when adding to the list
+ */
 struct efi_priv {
        efi_handle_t parent_image;
-       struct efi_device_path *device_path;
        struct efi_system_table *sys_table;
        struct efi_boot_services *boot;
        struct efi_runtime_services *run;
+       efi_uintn_t memmap_key;
+       struct efi_mem_desc *memmap_desc;
+       efi_uintn_t memmap_alloc;
+       efi_uintn_t memmap_size;
+       efi_uintn_t memmap_desc_size;
+       u32 memmap_version;
+
+       /* app: */
        bool use_pool_for_malloc;
        unsigned long ram_base;
        unsigned int image_data_type;
+
+       /* stub: */
        struct efi_info_hdr *info;
        unsigned int info_size;
        void *next_hdr;
 };
 
+/*
+ * EFI attributes of the udevice handled by efi_media driver
+ *
+ * @handle: handle of the controller on which this driver is installed
+ * @blkio: block io protocol proxied by this driver
+ * @device_path: EFI path to the device
+ */
+struct efi_media_plat {
+       efi_handle_t handle;
+       struct efi_block_io *blkio;
+       struct efi_device_path *device_path;
+};
+
 /* Base address of the EFI image */
 extern char image_base[];
 
@@ -408,19 +489,46 @@ extern char _binary_u_boot_bin_start[], _binary_u_boot_bin_end[];
                                EFI_VARIABLE_APPEND_WRITE)
 
 /**
- * efi_get_sys_table() - Get access to the main EFI system table
+ * efi_get_priv() - Get access to the EFI-private information
  *
- * @return pointer to EFI system table
+ * This struct it used by both the stub and the app to record things about the
+ * EFI environment. It is not available in U-Boot proper after the stub has
+ * jumped there. Use efi_info_get() to obtain info in that case.
+ *
+ * Return: pointer to private info
  */
+struct efi_priv *efi_get_priv(void);
 
+/**
+ * efi_set_priv() - Set up a pointer to the EFI-private information
+ *
+ * This is called in the stub and app to record the location of this
+ * information.
+ *
+ * @priv: New location of private data
+ */
+void efi_set_priv(struct efi_priv *priv);
+
+/**
+ * efi_get_sys_table() - Get access to the main EFI system table
+ *
+ * Returns: pointer to EFI system table
+ */
 struct efi_system_table *efi_get_sys_table(void);
 
 /**
+ * efi_get_boot() - Get access to the EFI boot services table
+ *
+ * Returns: pointer to EFI boot services table
+ */
+struct efi_boot_services *efi_get_boot(void);
+
+/**
  * efi_get_ram_base() - Find the base of RAM
  *
  * This is used when U-Boot is built as an EFI application.
  *
- * @return the base of RAM as known to U-Boot
+ * Returns: the base of RAM as known to U-Boot
  */
 unsigned long efi_get_ram_base(void);
 
@@ -431,6 +539,7 @@ unsigned long efi_get_ram_base(void);
  * @banner:    Banner to display when starting
  * @image:     The image handle passed to efi_main()
  * @sys_table: The EFI system table pointer passed to efi_main()
+ * Return: 0 on succcess, EFI error code on failure
  */
 int efi_init(struct efi_priv *priv, const char *banner, efi_handle_t image,
             struct efi_system_table *sys_table);
@@ -441,7 +550,7 @@ int efi_init(struct efi_priv *priv, const char *banner, efi_handle_t image,
  * @priv:      Pointer to private EFI structure
  * @size:      Number of bytes to allocate
  * @retp:      Return EFI status result
- * @return pointer to memory allocated, or NULL on error
+ * Returns: pointer to memory allocated, or NULL on error
  */
 void *efi_malloc(struct efi_priv *priv, int size, efi_status_t *retp);
 
@@ -472,25 +581,51 @@ void efi_putc(struct efi_priv *priv, const char ch);
 /**
  * efi_info_get() - get an entry from an EFI table
  *
+ * This function is called from U-Boot proper to read information set up by the
+ * EFI stub. It can only be used when running from the EFI stub, not when U-Boot
+ * is running as an app.
+ *
  * @type:      Entry type to search for
  * @datap:     Returns pointer to entry data
- * @sizep:     Returns pointer to entry size
- * @return 0 if OK, -ENODATA if there is no table, -ENOENT if there is no entry
+ * @sizep:     Returns entry size
+ * Return: 0 if OK, -ENODATA if there is no table, -ENOENT if there is no entry
  * of the requested type, -EPROTONOSUPPORT if the table has the wrong version
  */
 int efi_info_get(enum efi_entry_t type, void **datap, int *sizep);
 
 /**
- * efi_build_mem_table() - make a sorted copy of the memory table
- *
- * @map:       Pointer to EFI memory map table
- * @size:      Size of table in bytes
- * @skip_bs:   True to skip boot-time memory and merge it with conventional
- *             memory. This will significantly reduce the number of table
- *             entries.
- * @return pointer to the new table. It should be freed with free() by the
- *        caller
+ * efi_store_memory_map() - Collect the memory-map info from EFI
+ *
+ * Collect the memory info and store it for later use, e.g. in calling
+ * exit_boot_services()
+ *
+ * @priv:      Pointer to private EFI structure
+ * Returns: 0 if OK, non-zero on error
+ */
+int efi_store_memory_map(struct efi_priv *priv);
+
+/**
+ * efi_call_exit_boot_services() - Handle the exit-boot-service procedure
+ *
+ * Tell EFI we don't want their boot services anymore
+ *
+ * Return: 0 if OK, non-zero on error
+ */
+int efi_call_exit_boot_services(void);
+
+/**
+ * efi_get_mmap() - Get the memory map from EFI
+ *
+ * This is used in the app. The caller must free *@descp when done
+ *
+ * @descp:     Returns allocated pointer to EFI memory map table
+ * @sizep:     Returns size of table in bytes
+ * @keyp:      Returns memory-map key
+ * @desc_sizep:        Returns size of each @desc_base record
+ * @versionp:  Returns version number of memory map
+ * Returns: 0 on success, -ve on error
  */
-void *efi_build_mem_table(struct efi_entry_memmap *map, int size, bool skip_bs);
+int efi_get_mmap(struct efi_mem_desc **descp, int *sizep, uint *keyp,
+                int *desc_sizep, uint *versionp);
 
 #endif /* _LINUX_EFI_H */