// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (C) 2014-2015, Bin Meng <bmeng.cn@gmail.com>
 */

#include <common.h>
#include <command.h>
#include <efi.h>
#include <uuid.h>
#include <asm/hob.h>
#include <asm/fsp/fsp_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 char *res_type[] = {
	"System",
	"Memory-mapped I/O",
	"I/O",
	"Firmware device",
	"Memory-mapped I/O port",
	"Reserved",
	"I/O reserved",
};

static struct guid_name {
	efi_guid_t guid;
	const char *name;
} guid_name[] = {
	{ FSP_HOB_RESOURCE_OWNER_TSEG_GUID, "TSEG" },
	{ FSP_HOB_RESOURCE_OWNER_FSP_GUID, "FSP" },
	{ FSP_HOB_RESOURCE_OWNER_SMM_PEI_SMRAM_GUID, "SMM PEI SMRAM" },
	{ FSP_NON_VOLATILE_STORAGE_HOB_GUID, "NVS" },
	{ FSP_VARIABLE_NV_DATA_HOB_GUID, "Variable NVS" },
	{ FSP_GRAPHICS_INFO_HOB_GUID, "Graphics info" },
	{ FSP_HOB_RESOURCE_OWNER_PCD_DATABASE_GUID1, "PCD database ea" },
	{ FSP_HOB_RESOURCE_OWNER_PCD_DATABASE_GUID2, "PCD database 9b" },
	{ FSP_HOB_RESOURCE_OWNER_PEIM_DXE_GUID, "PEIM Init DXE" },
	{ FSP_HOB_RESOURCE_OWNER_ALLOC_STACK_GUID, "Alloc stack" },
	{ FSP_HOB_RESOURCE_OWNER_SMBIOS_MEMORY_GUID, "SMBIOS memory" },
	{ {}, "zero-guid" },
	{}
};

static const char *guid_to_name(const efi_guid_t *guid)
{
	struct guid_name *entry;

	for (entry = guid_name; entry->name; entry++) {
		if (!guidcmp(guid, &entry->guid))
			return entry->name;
	}

	return NULL;
}

static void show_hob_details(const struct hob_header *hdr)
{
	const void *ptr = hdr;

	switch (hdr->type) {
	case HOB_TYPE_RES_DESC: {
		const struct hob_res_desc *res = ptr;
		const char *typename;

		typename = res->type > 0 && res->type <= RES_MAX_MEM_TYPE ?
			res_type[res->type] : "unknown";

		printf("     base = %08llx, len = %08llx, end = %08llx, type = %d (%s)\n\n",
		       res->phys_start, res->len, res->phys_start + res->len,
		       res->type, typename);
		break;
	}
	}
}

static int do_hob(struct cmd_tbl *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];
	bool verbose = false;
	int seq = -1;	/* Show all by default */

	argc--;
	argv++;
	if (argc) {
		if (!strcmp("-v", *argv)) {
			verbose = true;
			argc--;
			argv++;
		}
		if (argc)
			seq = simple_strtol(*argv, NULL, 16);
	}
	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");
	for (i = 0; !end_of_hob(hdr); i++, hdr = get_next_hob(hdr)) {
		if (seq != -1 && seq != i)
			continue;
		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) {
			const char *name;

			guid = (efi_guid_t *)(hdr + 1);
			name = guid_to_name(guid);
			if (!name) {
				uuid_bin_to_str(guid->b, uuid,
						UUID_STR_FORMAT_GUID);
				name = uuid;
			}
			printf("%36s", name);
		} else {
			printf("%36s", "Not Available");
		}
		printf("\n");
		if (verbose)
			show_hob_details(hdr);
	}

	return 0;
}

U_BOOT_CMD(hob, 3, 1, do_hob,
	   "[-v] [seq]  Print Hand-Off Block (HOB) information"
	   "   -v  - Show detailed HOB information where available"
	   "   seq - Record # to show (all by default)",
	   ""
);
