FSP (CONFIG_HAVE_FSP) and Slim Bootloader (CONFIG_SYS_SLIMBOOTLOADER)
consume HOB (CONFIG_USE_HOB) data from the each HOB list pointer.
Add a common HOB library in lib/hob.c and include/asm/hob.h.

Signed-off-by: Aiden Park <aiden.p...@intel.com>
Reviewed-by: Andy Shevchenko <andy.shevche...@gmail.com>
Reviewed-by: Bin Meng <bmeng...@gmail.com>
Tested-by: Bin Meng <bmeng...@gmail.com>
---
Changes in v8:
  * Add a space between acronym and (definition)

Changes in v7:
  * Split HOB library into EFI_GUID pre-work and making a common lirary

Changes in v6:
  * Use CONFIG_USE_HOB
  * Change struct efi_guid to efi_guid_t
  * Use EFI_GUID to define GUIDs

Changes in v3:
  * Create a common HOB libary from fsp_hob and fsp_support

 arch/x86/include/asm/fsp/fsp_hob.h            | 184 +---------------
 arch/x86/include/asm/fsp/fsp_support.h        |  37 +---
 arch/x86/include/asm/{fsp/fsp_hob.h => hob.h} | 196 +++++++-----------
 arch/x86/lib/Makefile                         |   1 +
 arch/x86/lib/fsp/fsp_support.c                |  57 +----
 arch/x86/lib/hob.c                            |  84 ++++++++
 cmd/x86/Makefile                              |   1 +
 cmd/x86/fsp.c                                 |  65 +-----
 cmd/x86/hob.c                                 |  77 +++++++
 9 files changed, 242 insertions(+), 460 deletions(-)
 copy arch/x86/include/asm/{fsp/fsp_hob.h => hob.h} (67%)
 create mode 100644 arch/x86/lib/hob.c
 create mode 100644 cmd/x86/hob.c

diff --git a/arch/x86/include/asm/fsp/fsp_hob.h 
b/arch/x86/include/asm/fsp/fsp_hob.h
index 843d7b513b..3bb79c4b67 100644
--- a/arch/x86/include/asm/fsp/fsp_hob.h
+++ b/arch/x86/include/asm/fsp/fsp_hob.h
@@ -7,125 +7,7 @@
 #ifndef __FSP_HOB_H__
 #define __FSP_HOB_H__
 
-#include <efi.h>
-#include <efi_loader.h>
-
-/* Type of HOB Header */
-#define HOB_TYPE_MEM_ALLOC     0x0002
-#define HOB_TYPE_RES_DESC      0x0003
-#define HOB_TYPE_GUID_EXT      0x0004
-#define HOB_TYPE_UNUSED                0xFFFE
-#define HOB_TYPE_EOH           0xFFFF
-
-/*
- * Describes the format and size of the data inside the HOB.
- * All HOBs must contain this generic HOB header.
- */
-struct hob_header {
-       u16     type;           /* HOB type */
-       u16     len;            /* HOB length */
-       u32     reserved;       /* always zero */
-};
-
-/*
- * Describes all memory ranges used during the HOB producer phase that
- * exist outside the HOB list. This HOB type describes how memory is used,
- * not the physical attributes of memory.
- */
-struct hob_mem_alloc {
-       struct hob_header       hdr;
-       /*
-        * A GUID that defines the memory allocation region's type and purpose,
-        * as well as other fields within the memory allocation HOB. This GUID
-        * is used to define the additional data within the HOB that may be
-        * present for the memory allocation HOB. Type efi_guid is defined in
-        * InstallProtocolInterface() in the UEFI 2.0 specification.
-        */
-       efi_guid_t              name;
-       /*
-        * The base address of memory allocated by this HOB.
-        * Type phys_addr_t is defined in AllocatePages() in the UEFI 2.0
-        * specification.
-        */
-       phys_addr_t             mem_base;
-       /* The length in bytes of memory allocated by this HOB */
-       phys_size_t             mem_len;
-       /*
-        * Defines the type of memory allocated by this HOB.
-        * The memory type definition follows the EFI_MEMORY_TYPE definition.
-        * Type EFI_MEMORY_TYPE is defined in AllocatePages() in the UEFI 2.0
-        * specification.
-        */
-       enum efi_mem_type       mem_type;
-       /* padding */
-       u8                      reserved[4];
-};
-
-/* Value of ResourceType in HOB_RES_DESC */
-#define RES_SYS_MEM            0x00000000
-#define RES_MMAP_IO            0x00000001
-#define RES_IO                 0x00000002
-#define RES_FW_DEVICE          0x00000003
-#define RES_MMAP_IO_PORT       0x00000004
-#define RES_MEM_RESERVED       0x00000005
-#define RES_IO_RESERVED                0x00000006
-#define RES_MAX_MEM_TYPE       0x00000007
-
-/*
- * These types can be ORed together as needed.
- *
- * The first three enumerations describe settings
- * The rest of the settings describe capabilities
- */
-#define RES_ATTR_PRESENT                       0x00000001
-#define RES_ATTR_INITIALIZED                   0x00000002
-#define RES_ATTR_TESTED                                0x00000004
-#define RES_ATTR_SINGLE_BIT_ECC                        0x00000008
-#define RES_ATTR_MULTIPLE_BIT_ECC              0x00000010
-#define RES_ATTR_ECC_RESERVED_1                        0x00000020
-#define RES_ATTR_ECC_RESERVED_2                        0x00000040
-#define RES_ATTR_READ_PROTECTED                        0x00000080
-#define RES_ATTR_WRITE_PROTECTED               0x00000100
-#define RES_ATTR_EXECUTION_PROTECTED           0x00000200
-#define RES_ATTR_UNCACHEABLE                   0x00000400
-#define RES_ATTR_WRITE_COMBINEABLE             0x00000800
-#define RES_ATTR_WRITE_THROUGH_CACHEABLE       0x00001000
-#define RES_ATTR_WRITE_BACK_CACHEABLE          0x00002000
-#define RES_ATTR_16_BIT_IO                     0x00004000
-#define RES_ATTR_32_BIT_IO                     0x00008000
-#define RES_ATTR_64_BIT_IO                     0x00010000
-#define RES_ATTR_UNCACHED_EXPORTED             0x00020000
-
-/*
- * Describes the resource properties of all fixed, nonrelocatable resource
- * ranges found on the processor host bus during the HOB producer phase.
- */
-struct hob_res_desc {
-       struct hob_header       hdr;
-       /*
-        * A GUID representing the owner of the resource. This GUID is
-        * used by HOB consumer phase components to correlate device
-        * ownership of a resource.
-        */
-       efi_guid_t              owner;
-       u32                     type;
-       u32                     attr;
-       /* The physical start address of the resource region */
-       phys_addr_t             phys_start;
-       /* The number of bytes of the resource region */
-       phys_size_t             len;
-};
-
-/*
- * Allows writers of executable content in the HOB producer phase to
- * maintain and manage HOBs with specific GUID.
- */
-struct hob_guid {
-       struct hob_header       hdr;
-       /* A GUID that defines the contents of this HOB */
-       efi_guid_t              name;
-       /* GUID specific data goes here */
-};
+#include <asm/hob.h>
 
 enum pixel_format {
        pixel_rgbx_8bpc,        /* RGB 8 bit per color */
@@ -147,70 +29,6 @@ struct __packed hob_graphics_info {
        u32 pixels_per_scanline;
 };
 
-/**
- * get_next_hob() - return a pointer to the next HOB in the HOB list
- *
- * This macro returns a pointer to HOB that follows the HOB specified by hob
- * in the HOB List.
- *
- * @hdr:    A pointer to a HOB.
- *
- * @return: A pointer to the next HOB in the HOB list.
- */
-static inline const struct hob_header *get_next_hob(const struct hob_header 
*hdr)
-{
-       return (const struct hob_header *)((uintptr_t)hdr + hdr->len);
-}
-
-/**
- * end_of_hob() - determine if a HOB is the last HOB in the HOB list
- *
- * This macro determine if the HOB specified by hob is the last HOB in the
- * HOB list.  If hob is last HOB in the HOB list, then true is returned.
- * Otherwise, false is returned.
- *
- * @hdr:          A pointer to a HOB.
- *
- * @retval true:  The HOB specified by hdr is the last HOB in the HOB list.
- * @retval false: The HOB specified by hdr is not the last HOB in the HOB list.
- */
-static inline bool end_of_hob(const struct hob_header *hdr)
-{
-       return hdr->type == HOB_TYPE_EOH;
-}
-
-/**
- * get_guid_hob_data() - return a pointer to data buffer from a HOB of
- *                       type HOB_TYPE_GUID_EXT
- *
- * This macro returns a pointer to the data buffer in a HOB specified by hob.
- * hob is assumed to be a HOB of type HOB_TYPE_GUID_EXT.
- *
- * @hdr:    A pointer to a HOB.
- *
- * @return: A pointer to the data buffer in a HOB.
- */
-static inline void *get_guid_hob_data(const struct hob_header *hdr)
-{
-       return (void *)((uintptr_t)hdr + sizeof(struct hob_guid));
-}
-
-/**
- * get_guid_hob_data_size() - return the size of the data buffer from a HOB
- *                            of type HOB_TYPE_GUID_EXT
- *
- * This macro returns the size, in bytes, of the data buffer in a HOB
- * specified by hob. hob is assumed to be a HOB of type HOB_TYPE_GUID_EXT.
- *
- * @hdr:    A pointer to a HOB.
- *
- * @return: The size of the data buffer.
- */
-static inline u16 get_guid_hob_data_size(const struct hob_header *hdr)
-{
-       return hdr->len - sizeof(struct hob_guid);
-}
-
 /* FSP specific GUID HOB definitions */
 #define FSP_GUID_DATA1         0x912740be
 #define FSP_GUID_DATA2         0x2284
diff --git a/arch/x86/include/asm/fsp/fsp_support.h 
b/arch/x86/include/asm/fsp/fsp_support.h
index 0cca948184..7b92392a27 100644
--- a/arch/x86/include/asm/fsp/fsp_support.h
+++ b/arch/x86/include/asm/fsp/fsp_support.h
@@ -8,10 +8,10 @@
 #define __FSP_SUPPORT_H__
 
 #include "fsp_types.h"
+#include "fsp_hob.h"
 #include "fsp_fv.h"
 #include "fsp_ffs.h"
 #include "fsp_api.h"
-#include "fsp_hob.h"
 #include "fsp_infoheader.h"
 #include "fsp_bootmode.h"
 #include "fsp_azalia.h"
@@ -131,41 +131,6 @@ u32 fsp_get_fsp_reserved_mem(const void *hob_list, u32 
*len);
  */
 u32 fsp_get_tseg_reserved_mem(const void *hob_list, u32 *len);
 
-/**
- * Returns the next instance of a HOB type from the starting HOB.
- *
- * @type:     HOB type to search
- * @hob_list: A pointer to the HOB list
- *
- * @retval:   A HOB object with matching type; Otherwise NULL.
- */
-const struct hob_header *fsp_get_next_hob(uint type, const void *hob_list);
-
-/**
- * Returns the next instance of the matched GUID HOB from the starting HOB.
- *
- * @guid:     GUID to search
- * @hob_list: A pointer to the HOB list
- *
- * @retval:   A HOB object with matching GUID; Otherwise NULL.
- */
-const struct hob_header *fsp_get_next_guid_hob(const efi_guid_t *guid,
-                                              const void *hob_list);
-
-/**
- * This function retrieves a GUID HOB data buffer and size.
- *
- * @hob_list:      A HOB list pointer.
- * @len:           A pointer to the GUID HOB data buffer length.
- *                 If the GUID HOB is located, the length will be updated.
- * @guid           A pointer to HOB GUID.
- *
- * @retval NULL:   Failed to find the GUID HOB.
- * @retval others: GUID HOB data buffer pointer.
- */
-void *fsp_get_guid_hob_data(const void *hob_list, u32 *len,
-                           const efi_guid_t *guid);
-
 /**
  * This function retrieves FSP Non-volatile Storage HOB buffer and size.
  *
diff --git a/arch/x86/include/asm/fsp/fsp_hob.h b/arch/x86/include/asm/hob.h
similarity index 67%
copy from arch/x86/include/asm/fsp/fsp_hob.h
copy to arch/x86/include/asm/hob.h
index 843d7b513b..b4239821aa 100644
--- a/arch/x86/include/asm/fsp/fsp_hob.h
+++ b/arch/x86/include/asm/hob.h
@@ -4,8 +4,8 @@
  * Copyright (C) 2014, Bin Meng <bmeng...@gmail.com>
  */
 
-#ifndef __FSP_HOB_H__
-#define __FSP_HOB_H__
+#ifndef __HOB_H__
+#define __HOB_H__
 
 #include <efi.h>
 #include <efi_loader.h>
@@ -17,6 +17,41 @@
 #define HOB_TYPE_UNUSED                0xFFFE
 #define HOB_TYPE_EOH           0xFFFF
 
+/* Value of ResourceType in HOB_RES_DESC */
+#define RES_SYS_MEM            0x00000000
+#define RES_MMAP_IO            0x00000001
+#define RES_IO                 0x00000002
+#define RES_FW_DEVICE          0x00000003
+#define RES_MMAP_IO_PORT       0x00000004
+#define RES_MEM_RESERVED       0x00000005
+#define RES_IO_RESERVED                0x00000006
+#define RES_MAX_MEM_TYPE       0x00000007
+
+/*
+ * These types can be ORed together as needed.
+ *
+ * The first three enumerations describe settings
+ * The rest of the settings describe capabilities
+ */
+#define RES_ATTR_PRESENT                       0x00000001
+#define RES_ATTR_INITIALIZED                   0x00000002
+#define RES_ATTR_TESTED                                0x00000004
+#define RES_ATTR_SINGLE_BIT_ECC                        0x00000008
+#define RES_ATTR_MULTIPLE_BIT_ECC              0x00000010
+#define RES_ATTR_ECC_RESERVED_1                        0x00000020
+#define RES_ATTR_ECC_RESERVED_2                        0x00000040
+#define RES_ATTR_READ_PROTECTED                        0x00000080
+#define RES_ATTR_WRITE_PROTECTED               0x00000100
+#define RES_ATTR_EXECUTION_PROTECTED           0x00000200
+#define RES_ATTR_UNCACHEABLE                   0x00000400
+#define RES_ATTR_WRITE_COMBINEABLE             0x00000800
+#define RES_ATTR_WRITE_THROUGH_CACHEABLE       0x00001000
+#define RES_ATTR_WRITE_BACK_CACHEABLE          0x00002000
+#define RES_ATTR_16_BIT_IO                     0x00004000
+#define RES_ATTR_32_BIT_IO                     0x00008000
+#define RES_ATTR_64_BIT_IO                     0x00010000
+#define RES_ATTR_UNCACHED_EXPORTED             0x00020000
+
 /*
  * Describes the format and size of the data inside the HOB.
  * All HOBs must contain this generic HOB header.
@@ -38,7 +73,7 @@ struct hob_mem_alloc {
         * A GUID that defines the memory allocation region's type and purpose,
         * as well as other fields within the memory allocation HOB. This GUID
         * is used to define the additional data within the HOB that may be
-        * present for the memory allocation HOB. Type efi_guid is defined in
+        * present for the memory allocation HOB. Type efi_guid_t is defined in
         * InstallProtocolInterface() in the UEFI 2.0 specification.
         */
        efi_guid_t              name;
@@ -61,41 +96,6 @@ struct hob_mem_alloc {
        u8                      reserved[4];
 };
 
-/* Value of ResourceType in HOB_RES_DESC */
-#define RES_SYS_MEM            0x00000000
-#define RES_MMAP_IO            0x00000001
-#define RES_IO                 0x00000002
-#define RES_FW_DEVICE          0x00000003
-#define RES_MMAP_IO_PORT       0x00000004
-#define RES_MEM_RESERVED       0x00000005
-#define RES_IO_RESERVED                0x00000006
-#define RES_MAX_MEM_TYPE       0x00000007
-
-/*
- * These types can be ORed together as needed.
- *
- * The first three enumerations describe settings
- * The rest of the settings describe capabilities
- */
-#define RES_ATTR_PRESENT                       0x00000001
-#define RES_ATTR_INITIALIZED                   0x00000002
-#define RES_ATTR_TESTED                                0x00000004
-#define RES_ATTR_SINGLE_BIT_ECC                        0x00000008
-#define RES_ATTR_MULTIPLE_BIT_ECC              0x00000010
-#define RES_ATTR_ECC_RESERVED_1                        0x00000020
-#define RES_ATTR_ECC_RESERVED_2                        0x00000040
-#define RES_ATTR_READ_PROTECTED                        0x00000080
-#define RES_ATTR_WRITE_PROTECTED               0x00000100
-#define RES_ATTR_EXECUTION_PROTECTED           0x00000200
-#define RES_ATTR_UNCACHEABLE                   0x00000400
-#define RES_ATTR_WRITE_COMBINEABLE             0x00000800
-#define RES_ATTR_WRITE_THROUGH_CACHEABLE       0x00001000
-#define RES_ATTR_WRITE_BACK_CACHEABLE          0x00002000
-#define RES_ATTR_16_BIT_IO                     0x00004000
-#define RES_ATTR_32_BIT_IO                     0x00008000
-#define RES_ATTR_64_BIT_IO                     0x00010000
-#define RES_ATTR_UNCACHED_EXPORTED             0x00020000
-
 /*
  * Describes the resource properties of all fixed, nonrelocatable resource
  * ranges found on the processor host bus during the HOB producer phase.
@@ -127,26 +127,6 @@ struct hob_guid {
        /* GUID specific data goes here */
 };
 
-enum pixel_format {
-       pixel_rgbx_8bpc,        /* RGB 8 bit per color */
-       pixel_bgrx_8bpc,        /* BGR 8 bit per color */
-       pixel_bitmask,
-};
-
-struct __packed hob_graphics_info {
-       phys_addr_t fb_base;    /* framebuffer base address */
-       u32 fb_size;            /* framebuffer size */
-       u32 version;
-       u32 width;
-       u32 height;
-       enum pixel_format pixel_format;
-       u32 red_mask;
-       u32 green_mask;
-       u32 blue_mask;
-       u32 reserved_mask;
-       u32 pixels_per_scanline;
-};
-
 /**
  * get_next_hob() - return a pointer to the next HOB in the HOB list
  *
@@ -157,7 +137,8 @@ struct __packed hob_graphics_info {
  *
  * @return: A pointer to the next HOB in the HOB list.
  */
-static inline const struct hob_header *get_next_hob(const struct hob_header 
*hdr)
+static inline const struct hob_header *get_next_hob(const struct hob_header
+                                                   *hdr)
 {
        return (const struct hob_header *)((uintptr_t)hdr + hdr->len);
 }
@@ -211,70 +192,39 @@ static inline u16 get_guid_hob_data_size(const struct 
hob_header *hdr)
        return hdr->len - sizeof(struct hob_guid);
 }
 
-/* FSP specific GUID HOB definitions */
-#define FSP_GUID_DATA1         0x912740be
-#define FSP_GUID_DATA2         0x2284
-#define FSP_GUID_DATA3         0x4734
-#define FSP_GUID_DATA4_0       0xb9
-#define FSP_GUID_DATA4_1       0x71
-#define FSP_GUID_DATA4_2       0x84
-#define FSP_GUID_DATA4_3       0xb0
-#define FSP_GUID_DATA4_4       0x27
-#define FSP_GUID_DATA4_5       0x35
-#define FSP_GUID_DATA4_6       0x3f
-#define FSP_GUID_DATA4_7       0x0c
-
-#define FSP_GUID_BYTE0         0xbe
-#define FSP_GUID_BYTE1         0x40
-#define FSP_GUID_BYTE2         0x27
-#define FSP_GUID_BYTE3         0x91
-#define FSP_GUID_BYTE4         0x84
-#define FSP_GUID_BYTE5         0x22
-#define FSP_GUID_BYTE6         0x34
-#define FSP_GUID_BYTE7         0x47
-#define FSP_GUID_BYTE8         FSP_GUID_DATA4_0
-#define FSP_GUID_BYTE9         FSP_GUID_DATA4_1
-#define FSP_GUID_BYTE10                FSP_GUID_DATA4_2
-#define FSP_GUID_BYTE11                FSP_GUID_DATA4_3
-#define FSP_GUID_BYTE12                FSP_GUID_DATA4_4
-#define FSP_GUID_BYTE13                FSP_GUID_DATA4_5
-#define FSP_GUID_BYTE14                FSP_GUID_DATA4_6
-#define FSP_GUID_BYTE15                FSP_GUID_DATA4_7
-
-#define FSP_HEADER_GUID \
-       EFI_GUID(FSP_GUID_DATA1, FSP_GUID_DATA2, FSP_GUID_DATA3, \
-               FSP_GUID_DATA4_0, FSP_GUID_DATA4_1, FSP_GUID_DATA4_2, \
-               FSP_GUID_DATA4_3, FSP_GUID_DATA4_4, FSP_GUID_DATA4_5, \
-               FSP_GUID_DATA4_6, FSP_GUID_DATA4_7)
-
-#define FSP_NON_VOLATILE_STORAGE_HOB_GUID \
-       EFI_GUID(0x721acf02, 0x4d77, 0x4c2a, \
-               0xb3, 0xdc, 0x27, 0x0b, 0x7b, 0xa9, 0xe4, 0xb0)
-
-#define FSP_BOOTLOADER_TEMP_MEM_HOB_GUID \
-       EFI_GUID(0xbbcff46c, 0xc8d3, 0x4113, \
-               0x89, 0x85, 0xb9, 0xd4, 0xf3, 0xb3, 0xf6, 0x4e)
-
-#define FSP_HOB_RESOURCE_OWNER_FSP_GUID \
-       EFI_GUID(0x69a79759, 0x1373, 0x4367, \
-               0xa6, 0xc4, 0xc7, 0xf5, 0x9e, 0xfd, 0x98, 0x6e)
-
-#define FSP_HOB_RESOURCE_OWNER_TSEG_GUID \
-       EFI_GUID(0xd038747c, 0xd00c, 0x4980, \
-               0xb3, 0x19, 0x49, 0x01, 0x99, 0xa4, 0x7d, 0x55)
-
-#define FSP_HOB_RESOURCE_OWNER_GRAPHICS_GUID \
-       EFI_GUID(0x9c7c3aa7, 0x5332, 0x4917, \
-               0x82, 0xb9, 0x56, 0xa5, 0xf3, 0xe6, 0x2a, 0x07)
-
-/* The following GUIDs are newly introduced in FSP spec 1.1 */
+/**
+ * Returns the next instance of a HOB type from the starting HOB.
+ *
+ * @type:     HOB type to search
+ * @hob_list: A pointer to the HOB list
+ *
+ * @retval:   A HOB object with matching type; Otherwise NULL.
+ */
+const struct hob_header *hob_get_next_hob(uint type, const void *hob_list);
 
-#define FSP_HOB_RESOURCE_OWNER_BOOTLOADER_TOLUM_GUID \
-       EFI_GUID(0x73ff4f56, 0xaa8e, 0x4451, \
-               0xb3, 0x16, 0x36, 0x35, 0x36, 0x67, 0xad, 0x44)
+/**
+ * Returns the next instance of the matched GUID HOB from the starting HOB.
+ *
+ * @guid:     GUID to search
+ * @hob_list: A pointer to the HOB list
+ *
+ * @retval:   A HOB object with matching GUID; Otherwise NULL.
+ */
+const struct hob_header *hob_get_next_guid_hob(const efi_guid_t *guid,
+                                              const void *hob_list);
 
-#define FSP_GRAPHICS_INFO_HOB_GUID \
-       EFI_GUID(0x39f62cce, 0x6825, 0x4669, \
-               0xbb, 0x56, 0x54, 0x1a, 0xba, 0x75, 0x3a, 0x07)
+/**
+ * This function retrieves a GUID HOB data buffer and size.
+ *
+ * @hob_list:      A HOB list pointer.
+ * @len:           A pointer to the GUID HOB data buffer length.
+ *                 If the GUID HOB is located, the length will be updated.
+ * @guid           A pointer to HOB GUID.
+ *
+ * @retval NULL:   Failed to find the GUID HOB.
+ * @retval others: GUID HOB data buffer pointer.
+ */
+void *hob_get_guid_hob_data(const void *hob_list, u32 *len,
+                           const efi_guid_t *guid);
 
-#endif
+#endif /* __HOB_H__ */
diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile
index 436252dd83..906be5eab9 100644
--- a/arch/x86/lib/Makefile
+++ b/arch/x86/lib/Makefile
@@ -42,6 +42,7 @@ obj-y += tables.o
 ifndef CONFIG_SPL_BUILD
 obj-$(CONFIG_CMD_ZBOOT)        += zimage.o
 endif
+obj-$(CONFIG_USE_HOB) += hob.o
 obj-$(CONFIG_HAVE_FSP) += fsp/
 
 ifdef CONFIG_SPL_BUILD
diff --git a/arch/x86/lib/fsp/fsp_support.c b/arch/x86/lib/fsp/fsp_support.c
index 353fa82de5..0eaa9b232b 100644
--- a/arch/x86/lib/fsp/fsp_support.c
+++ b/arch/x86/lib/fsp/fsp_support.c
@@ -344,74 +344,23 @@ u32 fsp_get_tseg_reserved_mem(const void *hob_list, u32 
*len)
        return base;
 }
 
-const struct hob_header *fsp_get_next_hob(uint type, const void *hob_list)
-{
-       const struct hob_header *hdr;
-
-       hdr = hob_list;
-
-       /* Parse the HOB list until end of list or matching type is found */
-       while (!end_of_hob(hdr)) {
-               if (hdr->type == type)
-                       return hdr;
-
-               hdr = get_next_hob(hdr);
-       }
-
-       return NULL;
-}
-
-const struct hob_header *fsp_get_next_guid_hob(const efi_guid_t *guid,
-                                              const void *hob_list)
-{
-       const struct hob_header *hdr;
-       struct hob_guid *guid_hob;
-
-       hdr = hob_list;
-       while ((hdr = fsp_get_next_hob(HOB_TYPE_GUID_EXT,
-                       hdr)) != NULL) {
-               guid_hob = (struct hob_guid *)hdr;
-               if (!guidcmp(guid, &guid_hob->name))
-                       break;
-               hdr = get_next_hob(hdr);
-       }
-
-       return hdr;
-}
-
-void *fsp_get_guid_hob_data(const void *hob_list, u32 *len,
-                           const efi_guid_t *guid)
-{
-       const struct hob_header *guid_hob;
-
-       guid_hob = fsp_get_next_guid_hob(guid, hob_list);
-       if (guid_hob == NULL) {
-               return NULL;
-       } else {
-               if (len)
-                       *len = get_guid_hob_data_size(guid_hob);
-
-               return get_guid_hob_data(guid_hob);
-       }
-}
-
 void *fsp_get_nvs_data(const void *hob_list, u32 *len)
 {
        const efi_guid_t guid = FSP_NON_VOLATILE_STORAGE_HOB_GUID;
 
-       return fsp_get_guid_hob_data(hob_list, len, &guid);
+       return hob_get_guid_hob_data(hob_list, len, &guid);
 }
 
 void *fsp_get_bootloader_tmp_mem(const void *hob_list, u32 *len)
 {
        const efi_guid_t guid = FSP_BOOTLOADER_TEMP_MEM_HOB_GUID;
 
-       return fsp_get_guid_hob_data(hob_list, len, &guid);
+       return hob_get_guid_hob_data(hob_list, len, &guid);
 }
 
 void *fsp_get_graphics_info(const void *hob_list, u32 *len)
 {
        const efi_guid_t guid = FSP_GRAPHICS_INFO_HOB_GUID;
 
-       return fsp_get_guid_hob_data(hob_list, len, &guid);
+       return hob_get_guid_hob_data(hob_list, len, &guid);
 }
diff --git a/arch/x86/lib/hob.c b/arch/x86/lib/hob.c
new file mode 100644
index 0000000000..dcee29b04c
--- /dev/null
+++ b/arch/x86/lib/hob.c
@@ -0,0 +1,84 @@
+// SPDX-License-Identifier: Intel
+/*
+ * Copyright (C) 2013, Intel Corporation
+ * Copyright (C) 2014, Bin Meng <bmeng...@gmail.com>
+ */
+
+#include <common.h>
+#include <asm/hob.h>
+
+/**
+ * Returns the next instance of a HOB type from the starting HOB.
+ *
+ * @type:     HOB type to search
+ * @hob_list: A pointer to the HOB list
+ *
+ * @retval:   A HOB object with matching type; Otherwise NULL.
+ */
+const struct hob_header *hob_get_next_hob(uint type, const void *hob_list)
+{
+       const struct hob_header *hdr;
+
+       hdr = hob_list;
+
+       /* Parse the HOB list until end of list or matching type is found */
+       while (!end_of_hob(hdr)) {
+               if (hdr->type == type)
+                       return hdr;
+
+               hdr = get_next_hob(hdr);
+       }
+
+       return NULL;
+}
+
+/**
+ * Returns the next instance of the matched GUID HOB from the starting HOB.
+ *
+ * @guid:     GUID to search
+ * @hob_list: A pointer to the HOB list
+ *
+ * @retval:   A HOB object with matching GUID; Otherwise NULL.
+ */
+const struct hob_header *hob_get_next_guid_hob(const efi_guid_t *guid,
+                                              const void *hob_list)
+{
+       const struct hob_header *hdr;
+       struct hob_guid *guid_hob;
+
+       hdr = hob_list;
+       while ((hdr = hob_get_next_hob(HOB_TYPE_GUID_EXT, hdr))) {
+               guid_hob = (struct hob_guid *)hdr;
+               if (!guidcmp(guid, &guid_hob->name))
+                       break;
+               hdr = get_next_hob(hdr);
+       }
+
+       return hdr;
+}
+
+/**
+ * This function retrieves a GUID HOB data buffer and size.
+ *
+ * @hob_list:      A HOB list pointer.
+ * @len:           A pointer to the GUID HOB data buffer length.
+ *                 If the GUID HOB is located, the length will be updated.
+ * @guid           A pointer to HOB GUID.
+ *
+ * @retval NULL:   Failed to find the GUID HOB.
+ * @retval others: GUID HOB data buffer pointer.
+ */
+void *hob_get_guid_hob_data(const void *hob_list, u32 *len,
+                           const efi_guid_t *guid)
+{
+       const struct hob_header *guid_hob;
+
+       guid_hob = hob_get_next_guid_hob(guid, hob_list);
+       if (!guid_hob)
+               return NULL;
+
+       if (len)
+               *len = get_guid_hob_data_size(guid_hob);
+
+       return get_guid_hob_data(guid_hob);
+}
diff --git a/cmd/x86/Makefile b/cmd/x86/Makefile
index 707161440d..144b1cf5ab 100644
--- a/cmd/x86/Makefile
+++ b/cmd/x86/Makefile
@@ -2,4 +2,5 @@
 
 obj-y += mtrr.o
 obj-$(CONFIG_CMD_EXCEPTION) += exception.o
+obj-$(CONFIG_USE_HOB) += hob.o
 obj-$(CONFIG_HAVE_FSP) += fsp.o
diff --git a/cmd/x86/fsp.c b/cmd/x86/fsp.c
index 1b4c0207ce..efa183854b 100644
--- a/cmd/x86/fsp.c
+++ b/cmd/x86/fsp.c
@@ -9,21 +9,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-static char *hob_type[] = {
-       "reserved",
-       "Hand-off",
-       "Mem Alloc",
-       "Res Desc",
-       "GUID Ext",
-       "FV",
-       "CPU",
-       "Mem Pool",
-       "reserved",
-       "FV2",
-       "Load PEIM",
-       "Capsule",
-};
-
 static int do_hdr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
        struct fsp_header *hdr = find_fsp_header();
@@ -72,55 +57,8 @@ static int do_hdr(cmd_tbl_t *cmdtp, int flag, int argc, char 
* const argv[])
        return 0;
 }
 
-static int do_hob(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
-       const struct hob_header *hdr;
-       uint type;
-       char *desc;
-       int i = 0;
-       char uuid[UUID_STR_LEN + 1];
-
-       hdr = gd->arch.hob_list;
-
-       printf("HOB list address: 0x%08x\n\n", (unsigned int)hdr);
-
-       printf("#  | Address  | Type      | Len  | ");
-       printf("%42s\n", "GUID");
-       printf("---|----------|-----------|------|-");
-       printf("------------------------------------------\n");
-       while (!end_of_hob(hdr)) {
-               printf("%02x | %08x | ", i, (unsigned int)hdr);
-               type = hdr->type;
-               if (type == HOB_TYPE_UNUSED)
-                       desc = "*Unused*";
-               else if (type == HOB_TYPE_EOH)
-                       desc = "*EOH*";
-               else if (type >= 0 && type <= ARRAY_SIZE(hob_type))
-                       desc = hob_type[type];
-               else
-                       desc = "*Invalid*";
-               printf("%-9s | %04x | ", desc, hdr->len);
-
-               if (type == HOB_TYPE_MEM_ALLOC || type == HOB_TYPE_RES_DESC ||
-                   type == HOB_TYPE_GUID_EXT) {
-                       efi_guid_t *guid = (efi_guid_t *)(hdr + 1);
-
-                       uuid_bin_to_str(guid->b, uuid, UUID_STR_FORMAT_GUID);
-                       printf("%s", uuid);
-               } else {
-                       printf("%42s", "Not Available");
-               }
-               printf("\n");
-               hdr = get_next_hob(hdr);
-               i++;
-       }
-
-       return 0;
-}
-
 static cmd_tbl_t fsp_commands[] = {
        U_BOOT_CMD_MKENT(hdr, 0, 1, do_hdr, "", ""),
-       U_BOOT_CMD_MKENT(hob, 0, 1, do_hob, "", ""),
 };
 
 static int do_fsp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
@@ -144,6 +82,5 @@ static int do_fsp(cmd_tbl_t *cmdtp, int flag, int argc, char 
* const argv[])
 U_BOOT_CMD(
        fsp,    2,      1,      do_fsp,
        "Show Intel Firmware Support Package (FSP) related information",
-       "hdr - Print FSP header information\n"
-       "fsp hob - Print FSP Hand-Off Block (HOB) information"
+       "hdr - Print FSP header information"
 );
diff --git a/cmd/x86/hob.c b/cmd/x86/hob.c
new file mode 100644
index 0000000000..3967a7ca5a
--- /dev/null
+++ b/cmd/x86/hob.c
@@ -0,0 +1,77 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2014-2015, Bin Meng <bmeng...@gmail.com>
+ */
+
+#include <common.h>
+#include <command.h>
+#include <efi.h>
+#include <asm/hob.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static char *hob_type[] = {
+       "reserved",
+       "Hand-off",
+       "Mem Alloc",
+       "Res Desc",
+       "GUID Ext",
+       "FV",
+       "CPU",
+       "Mem Pool",
+       "reserved",
+       "FV2",
+       "Load PEIM",
+       "Capsule",
+};
+
+static int do_hob(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       const struct hob_header *hdr;
+       uint type;
+       char *desc;
+       int i = 0;
+       efi_guid_t *guid;
+       char uuid[UUID_STR_LEN + 1];
+
+       hdr = gd->arch.hob_list;
+
+       printf("HOB list address: 0x%08x\n\n", (unsigned int)hdr);
+
+       printf("#  | Address  | Type      | Len  | ");
+       printf("%36s\n", "GUID");
+       printf("---|----------|-----------|------|-");
+       printf("------------------------------------\n");
+       while (!end_of_hob(hdr)) {
+               printf("%02x | %08x | ", i, (unsigned int)hdr);
+               type = hdr->type;
+               if (type == HOB_TYPE_UNUSED)
+                       desc = "*Unused*";
+               else if (type == HOB_TYPE_EOH)
+                       desc = "*EOH*";
+               else if (type >= 0 && type <= ARRAY_SIZE(hob_type))
+                       desc = hob_type[type];
+               else
+                       desc = "*Invalid*";
+               printf("%-9s | %04x | ", desc, hdr->len);
+
+               if (type == HOB_TYPE_MEM_ALLOC || type == HOB_TYPE_RES_DESC ||
+                   type == HOB_TYPE_GUID_EXT) {
+                       guid = (efi_guid_t *)(hdr + 1);
+                       uuid_bin_to_str(guid->b, uuid, UUID_STR_FORMAT_GUID);
+                       printf("%s", uuid);
+               } else {
+                       printf("%36s", "Not Available");
+               }
+               printf("\n");
+               hdr = get_next_hob(hdr);
+               i++;
+       }
+
+       return 0;
+}
+
+U_BOOT_CMD(hob, 1, 1, do_hob,
+          "Print Hand-Off Block (HOB) information",
+          ""
+);
-- 
2.20.1

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot

Reply via email to