On 2016/5/2 18:45, Matt Fleming wrote:
> On Sun, 01 May, at 10:36:51PM, Shannon Zhao wrote:
>> So is there any other way you suggest?
> 
> Would this work (compile tested but not runtime tested)?
> 
> ---
> 
> diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
> index 3a69ed5ecfcb..13d8be16447a 100644
> --- a/drivers/firmware/efi/efi.c
> +++ b/drivers/firmware/efi/efi.c
> @@ -469,12 +469,14 @@ device_initcall(efi_load_efivars);
>               FIELD_SIZEOF(struct efi_fdt_params, field) \
>       }
>  
> -static __initdata struct {
> +struct params {
>       const char name[32];
>       const char propname[32];
>       int offset;
>       int size;
> -} dt_params[] = {
> +};
> +
> +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),
> @@ -482,44 +484,83 @@ static __initdata struct {
>       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;
> +     struct params *params;
> +} dt_params[] = {
> +     { "hypervisor", xen_fdt_params },
While the uefi params are located under /hypervisor/uefi node not
/hypervisor node.

> +     { "chosen", fdt_params },
> +};
> +
>  struct param_info {
>       int found;
>       void *params;
> +     const char *missing;
>  };
>  
> -static int __init fdt_find_uefi_params(unsigned long node, const char *uname,
> -                                    int depth, void *data)
> +static int __init __find_uefi_params(unsigned long node,
> +                                  struct param_info *info,
> +                                  struct params *params)
>  {
> -     struct param_info *info = data;
>       const void *prop;
>       void *dest;
>       u64 val;
>       int i, len;
>  
> -     if (depth != 1 || strcmp(uname, "chosen") != 0)
> -             return 0;
> -
> -     for (i = 0; i < ARRAY_SIZE(dt_params); i++) {
> -             prop = of_get_flat_dt_prop(node, dt_params[i].propname, &len);
> -             if (!prop)
> +     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 + dt_params[i].offset;
> +             }
> +
> +             dest = info->params + params[i].offset;
>               info->found++;
>  
>               val = of_read_number(prop, len / sizeof(u32));
>  
> -             if (dt_params[i].size == 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", dt_params[i].name,
> -                             dt_params[i].size * 2, val);
> +                     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++) {
> +
> +             if (depth != 1 || strcmp(uname, dt_params[i].uname) != 0) {
> +                     info->missing = dt_params[i].params[0].name;
> +                     continue;
> +             }
> +
So here it needs to check whether the node is /hypervisor. If so, get
the subnode "uefi". Like below:
if (strcmp(uname, "hypervisor") == 0) {
        offset = of_get_flat_dt_subnode_by_name(node, "uefi");
        if (offset < 0)
                return 0;
        node = offset;
}

> +             return __find_uefi_params(node, info, dt_params[i].params);
> +     }
> +
> +     return 0;
> +}
> +
>  int __init efi_get_fdt_params(struct efi_fdt_params *params)
>  {
>       struct param_info info;
> @@ -535,7 +576,7 @@ int __init efi_get_fdt_params(struct efi_fdt_params 
> *params)
>               pr_info("UEFI not found.\n");
>       else if (!ret)
>               pr_err("Can't find '%s' in device tree!\n",
> -                    dt_params[info.found].name);
> +                    info.missing);
>  
>       return ret;
>  }
> 

-- 
Shannon

Reply via email to