2020-02-18 16:54:05 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
|
|
|
|
#define pr_fmt(fmt) "efi: " fmt
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/efi.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_fdt.h>
|
|
|
|
|
|
|
|
#include <asm/early_ioremap.h>
|
|
|
|
|
|
|
|
#define UEFI_PARAM(name, prop, field) \
|
|
|
|
{ \
|
|
|
|
{ name }, \
|
|
|
|
{ prop }, \
|
|
|
|
offsetof(struct efi_fdt_params, field), \
|
|
|
|
sizeof_field(struct efi_fdt_params, field) \
|
|
|
|
}
|
|
|
|
|
2020-02-18 17:19:34 +08:00
|
|
|
struct efi_fdt_params {
|
|
|
|
u64 system_table;
|
|
|
|
u64 mmap;
|
|
|
|
u32 mmap_size;
|
|
|
|
u32 desc_size;
|
|
|
|
u32 desc_ver;
|
|
|
|
};
|
|
|
|
|
2020-02-18 16:54:05 +08:00
|
|
|
struct params {
|
|
|
|
const char name[32];
|
|
|
|
const char propname[32];
|
|
|
|
int offset;
|
|
|
|
int size;
|
|
|
|
};
|
|
|
|
|
|
|
|
static __initdata struct params fdt_params[] = {
|
|
|
|
UEFI_PARAM("System Table", "linux,uefi-system-table", system_table),
|
|
|
|
UEFI_PARAM("MemMap Address", "linux,uefi-mmap-start", mmap),
|
|
|
|
UEFI_PARAM("MemMap Size", "linux,uefi-mmap-size", mmap_size),
|
|
|
|
UEFI_PARAM("MemMap Desc. Size", "linux,uefi-mmap-desc-size", desc_size),
|
|
|
|
UEFI_PARAM("MemMap Desc. Version", "linux,uefi-mmap-desc-ver", desc_ver)
|
|
|
|
};
|
|
|
|
|
|
|
|
static __initdata struct params xen_fdt_params[] = {
|
|
|
|
UEFI_PARAM("System Table", "xen,uefi-system-table", system_table),
|
|
|
|
UEFI_PARAM("MemMap Address", "xen,uefi-mmap-start", mmap),
|
|
|
|
UEFI_PARAM("MemMap Size", "xen,uefi-mmap-size", mmap_size),
|
|
|
|
UEFI_PARAM("MemMap Desc. Size", "xen,uefi-mmap-desc-size", desc_size),
|
|
|
|
UEFI_PARAM("MemMap Desc. Version", "xen,uefi-mmap-desc-ver", desc_ver)
|
|
|
|
};
|
|
|
|
|
|
|
|
#define EFI_FDT_PARAMS_SIZE ARRAY_SIZE(fdt_params)
|
|
|
|
|
|
|
|
static __initdata struct {
|
|
|
|
const char *uname;
|
|
|
|
const char *subnode;
|
|
|
|
struct params *params;
|
|
|
|
} dt_params[] = {
|
|
|
|
{ "hypervisor", "uefi", xen_fdt_params },
|
|
|
|
{ "chosen", NULL, fdt_params },
|
|
|
|
};
|
|
|
|
|
|
|
|
struct param_info {
|
|
|
|
int found;
|
|
|
|
void *params;
|
|
|
|
const char *missing;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init __find_uefi_params(unsigned long node,
|
|
|
|
struct param_info *info,
|
|
|
|
struct params *params)
|
|
|
|
{
|
|
|
|
const void *prop;
|
|
|
|
void *dest;
|
|
|
|
u64 val;
|
|
|
|
int i, len;
|
|
|
|
|
|
|
|
for (i = 0; i < EFI_FDT_PARAMS_SIZE; i++) {
|
|
|
|
prop = of_get_flat_dt_prop(node, params[i].propname, &len);
|
|
|
|
if (!prop) {
|
|
|
|
info->missing = params[i].name;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
dest = info->params + params[i].offset;
|
|
|
|
info->found++;
|
|
|
|
|
|
|
|
val = of_read_number(prop, len / sizeof(u32));
|
|
|
|
|
|
|
|
if (params[i].size == sizeof(u32))
|
|
|
|
*(u32 *)dest = val;
|
|
|
|
else
|
|
|
|
*(u64 *)dest = val;
|
|
|
|
|
|
|
|
if (efi_enabled(EFI_DBG))
|
|
|
|
pr_info(" %s: 0x%0*llx\n", params[i].name,
|
|
|
|
params[i].size * 2, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init fdt_find_uefi_params(unsigned long node, const char *uname,
|
|
|
|
int depth, void *data)
|
|
|
|
{
|
|
|
|
struct param_info *info = data;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(dt_params); i++) {
|
|
|
|
const char *subnode = dt_params[i].subnode;
|
|
|
|
|
|
|
|
if (depth != 1 || strcmp(uname, dt_params[i].uname) != 0) {
|
|
|
|
info->missing = dt_params[i].params[0].name;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (subnode) {
|
|
|
|
int err = of_get_flat_dt_subnode_by_name(node, subnode);
|
|
|
|
|
|
|
|
if (err < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
node = err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return __find_uefi_params(node, info, dt_params[i].params);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-02-18 17:19:34 +08:00
|
|
|
u64 __init efi_get_fdt_params(struct efi_memory_map_data *memmap)
|
2020-02-18 16:54:05 +08:00
|
|
|
{
|
2020-02-18 17:19:34 +08:00
|
|
|
struct efi_fdt_params params;
|
2020-02-18 16:54:05 +08:00
|
|
|
struct param_info info;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
pr_info("Getting EFI parameters from FDT:\n");
|
|
|
|
|
|
|
|
info.found = 0;
|
2020-02-18 17:19:34 +08:00
|
|
|
info.params = ¶ms;
|
2020-02-18 16:54:05 +08:00
|
|
|
|
|
|
|
ret = of_scan_flat_dt(fdt_find_uefi_params, &info);
|
2020-02-18 17:19:34 +08:00
|
|
|
if (!info.found) {
|
2020-02-18 16:54:05 +08:00
|
|
|
pr_info("UEFI not found.\n");
|
2020-02-18 17:19:34 +08:00
|
|
|
return 0;
|
|
|
|
} else if (!ret) {
|
|
|
|
pr_err("Can't find '%s' in device tree!\n", info.missing);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
memmap->desc_version = params.desc_ver;
|
|
|
|
memmap->desc_size = params.desc_size;
|
|
|
|
memmap->size = params.mmap_size;
|
|
|
|
memmap->phys_map = params.mmap;
|
2020-02-18 16:54:05 +08:00
|
|
|
|
2020-02-18 17:19:34 +08:00
|
|
|
return params.system_table;
|
2020-02-18 16:54:05 +08:00
|
|
|
}
|