Re: [PATCH v8 25/40] x86/compressed/acpi: move EFI config table lookup to helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2021-12-10 09:43:17 -0600, Brijesh Singh wrote:
> From: Michael Roth <michael.roth@xxxxxxx>
> 
> Future patches for SEV-SNP-validated CPUID will also require early
> parsing of the EFI configuration. Incrementally move the related code
> into a set of helpers that can be re-used for that purpose.
> 
> Signed-off-by: Michael Roth <michael.roth@xxxxxxx>
> Signed-off-by: Brijesh Singh <brijesh.singh@xxxxxxx>

Reviewed-by: Venu Busireddy <venu.busireddy@xxxxxxxxxx>

> ---
>  arch/x86/boot/compressed/acpi.c | 25 ++++++--------------
>  arch/x86/boot/compressed/efi.c  | 42 +++++++++++++++++++++++++++++++++
>  arch/x86/boot/compressed/misc.h |  9 +++++++
>  3 files changed, 58 insertions(+), 18 deletions(-)
> 
> diff --git a/arch/x86/boot/compressed/acpi.c b/arch/x86/boot/compressed/acpi.c
> index 9e784bd7b2e6..fea72a1504ff 100644
> --- a/arch/x86/boot/compressed/acpi.c
> +++ b/arch/x86/boot/compressed/acpi.c
> @@ -117,8 +117,9 @@ static acpi_physical_address kexec_get_rsdp_addr(void) { return 0; }
>  static acpi_physical_address efi_get_rsdp_addr(void)
>  {
>  #ifdef CONFIG_EFI
> -	unsigned long systab_tbl_pa, config_tables;
> -	unsigned int nr_tables;
> +	unsigned long cfg_tbl_pa = 0;
> +	unsigned long systab_tbl_pa;
> +	unsigned int cfg_tbl_len;
>  	bool efi_64;
>  	int ret;
>  
> @@ -134,23 +135,11 @@ static acpi_physical_address efi_get_rsdp_addr(void)
>  	if (ret)
>  		error("EFI support advertised, but unable to locate system table.");
>  
> -	/* Handle EFI bitness properly */
> -	if (efi_64) {
> -		efi_system_table_64_t *stbl = (efi_system_table_64_t *)systab_tbl_pa;
> +	ret = efi_get_conf_table(boot_params, &cfg_tbl_pa, &cfg_tbl_len, &efi_64);
> +	if (ret || !cfg_tbl_pa)
> +		error("EFI config table not found.");
>  
> -		config_tables	= stbl->tables;
> -		nr_tables	= stbl->nr_tables;
> -	} else {
> -		efi_system_table_32_t *stbl = (efi_system_table_32_t *)systab_tbl_pa;
> -
> -		config_tables	= stbl->tables;
> -		nr_tables	= stbl->nr_tables;
> -	}
> -
> -	if (!config_tables)
> -		error("EFI config tables not found.");
> -
> -	return __efi_get_rsdp_addr(config_tables, nr_tables, efi_64);
> +	return __efi_get_rsdp_addr(cfg_tbl_pa, cfg_tbl_len, efi_64);
>  #else
>  	return 0;
>  #endif
> diff --git a/arch/x86/boot/compressed/efi.c b/arch/x86/boot/compressed/efi.c
> index 1c626d28f07e..08ad517b0731 100644
> --- a/arch/x86/boot/compressed/efi.c
> +++ b/arch/x86/boot/compressed/efi.c
> @@ -70,3 +70,45 @@ int efi_get_system_table(struct boot_params *boot_params, unsigned long *sys_tbl
>  	*is_efi_64 = efi_64;
>  	return 0;
>  }
> +
> +/**
> + * efi_get_conf_table - Given boot_params, locate EFI system table from it
> + *                        and return the physical address EFI configuration table.
> + *
> + * @boot_params:        pointer to boot_params
> + * @cfg_tbl_pa:         location to store physical address of config table
> + * @cfg_tbl_len:        location to store number of config table entries
> + * @is_efi_64:          location to store whether using 64-bit EFI or not
> + *
> + * Return: 0 on success. On error, return params are left unchanged.
> + */
> +int efi_get_conf_table(struct boot_params *boot_params, unsigned long *cfg_tbl_pa,
> +		       unsigned int *cfg_tbl_len, bool *is_efi_64)
> +{
> +	unsigned long sys_tbl_pa = 0;
> +	int ret;
> +
> +	if (!cfg_tbl_pa || !cfg_tbl_len || !is_efi_64)
> +		return -EINVAL;
> +
> +	ret = efi_get_system_table(boot_params, &sys_tbl_pa, is_efi_64);
> +	if (ret)
> +		return ret;
> +
> +	/* Handle EFI bitness properly */
> +	if (*is_efi_64) {
> +		efi_system_table_64_t *stbl =
> +			(efi_system_table_64_t *)sys_tbl_pa;
> +
> +		*cfg_tbl_pa	= stbl->tables;
> +		*cfg_tbl_len	= stbl->nr_tables;
> +	} else {
> +		efi_system_table_32_t *stbl =
> +			(efi_system_table_32_t *)sys_tbl_pa;
> +
> +		*cfg_tbl_pa	= stbl->tables;
> +		*cfg_tbl_len	= stbl->nr_tables;
> +	}
> +
> +	return 0;
> +}
> diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h
> index 165640f64b71..1c69592e83da 100644
> --- a/arch/x86/boot/compressed/misc.h
> +++ b/arch/x86/boot/compressed/misc.h
> @@ -181,6 +181,8 @@ unsigned long sev_verify_cbit(unsigned long cr3);
>  /* helpers for early EFI config table access */
>  int efi_get_system_table(struct boot_params *boot_params,
>  			 unsigned long *sys_tbl_pa, bool *is_efi_64);
> +int efi_get_conf_table(struct boot_params *boot_params, unsigned long *cfg_tbl_pa,
> +		       unsigned int *cfg_tbl_len, bool *is_efi_64);
>  #else
>  static inline int
>  efi_get_system_table(struct boot_params *boot_params,
> @@ -188,6 +190,13 @@ efi_get_system_table(struct boot_params *boot_params,
>  {
>  	return -ENOENT;
>  }
> +
> +static inline int
> +efi_get_conf_table(struct boot_params *boot_params, unsigned long *cfg_tbl_pa,
> +		   unsigned int *cfg_tbl_len, bool *is_efi_64)
> +{
> +	return -ENOENT;
> +}
>  #endif /* CONFIG_EFI */
>  
>  #endif /* BOOT_COMPRESSED_MISC_H */
> -- 
> 2.25.1
> 



[Index of Archives]     [Linux Kernel Development]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux