Commit 90a2186b authored by Ingo Molnar's avatar Ingo Molnar

efi/x86: Clean up the eboot code

Various small cleanups:

 - Standardize printk messages:

     'alloc' => 'allocate'
     'mem'   => 'memory'

   also put variable names in printk messages between quotes.

 - Align mass-assignments vertically for better readability

 - Break multi-line function prototypes at the name where possible,
   not in the middle of the parameter list

 - Use a newline before return statements consistently.

 - Use curly braces in a balanced fashion.

 - Remove stray newlines.

No change in functionality.
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
Signed-off-by: default avatarArd Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-efi@vger.kernel.org
Link: http://lkml.kernel.org/r/20180711094040.12506-2-ard.biesheuvel@linaro.orgSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 9d3cce1e
...@@ -64,6 +64,7 @@ static inline efi_status_t __open_volume32(void *__image, void **__fh) ...@@ -64,6 +64,7 @@ static inline efi_status_t __open_volume32(void *__image, void **__fh)
efi_printk(sys_table, "Failed to open volume\n"); efi_printk(sys_table, "Failed to open volume\n");
*__fh = fh; *__fh = fh;
return status; return status;
} }
...@@ -90,6 +91,7 @@ static inline efi_status_t __open_volume64(void *__image, void **__fh) ...@@ -90,6 +91,7 @@ static inline efi_status_t __open_volume64(void *__image, void **__fh)
efi_printk(sys_table, "Failed to open volume\n"); efi_printk(sys_table, "Failed to open volume\n");
*__fh = fh; *__fh = fh;
return status; return status;
} }
...@@ -134,7 +136,7 @@ __setup_efi_pci(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom) ...@@ -134,7 +136,7 @@ __setup_efi_pci(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom)
status = efi_call_early(allocate_pool, EFI_LOADER_DATA, size, &rom); status = efi_call_early(allocate_pool, EFI_LOADER_DATA, size, &rom);
if (status != EFI_SUCCESS) { if (status != EFI_SUCCESS) {
efi_printk(sys_table, "Failed to alloc mem for rom\n"); efi_printk(sys_table, "Failed to allocate memory for 'rom'\n");
return status; return status;
} }
...@@ -180,8 +182,7 @@ __setup_efi_pci(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom) ...@@ -180,8 +182,7 @@ __setup_efi_pci(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom)
} }
static void static void
setup_efi_pci32(struct boot_params *params, void **pci_handle, setup_efi_pci32(struct boot_params *params, void **pci_handle, unsigned long size)
unsigned long size)
{ {
efi_pci_io_protocol_t *pci = NULL; efi_pci_io_protocol_t *pci = NULL;
efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID; efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID;
...@@ -220,13 +221,11 @@ setup_efi_pci32(struct boot_params *params, void **pci_handle, ...@@ -220,13 +221,11 @@ setup_efi_pci32(struct boot_params *params, void **pci_handle,
params->hdr.setup_data = (unsigned long)rom; params->hdr.setup_data = (unsigned long)rom;
data = (struct setup_data *)rom; data = (struct setup_data *)rom;
} }
} }
static void static void
setup_efi_pci64(struct boot_params *params, void **pci_handle, setup_efi_pci64(struct boot_params *params, void **pci_handle, unsigned long size)
unsigned long size)
{ {
efi_pci_io_protocol_t *pci = NULL; efi_pci_io_protocol_t *pci = NULL;
efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID; efi_guid_t pci_proto = EFI_PCI_IO_PROTOCOL_GUID;
...@@ -265,7 +264,6 @@ setup_efi_pci64(struct boot_params *params, void **pci_handle, ...@@ -265,7 +264,6 @@ setup_efi_pci64(struct boot_params *params, void **pci_handle,
params->hdr.setup_data = (unsigned long)rom; params->hdr.setup_data = (unsigned long)rom;
data = (struct setup_data *)rom; data = (struct setup_data *)rom;
} }
} }
...@@ -295,7 +293,7 @@ static void setup_efi_pci(struct boot_params *params) ...@@ -295,7 +293,7 @@ static void setup_efi_pci(struct boot_params *params)
size, (void **)&pci_handle); size, (void **)&pci_handle);
if (status != EFI_SUCCESS) { if (status != EFI_SUCCESS) {
efi_printk(sys_table, "Failed to alloc mem for pci_handle\n"); efi_printk(sys_table, "Failed to allocate memory for 'pci_handle'\n");
return; return;
} }
...@@ -341,8 +339,7 @@ static void retrieve_apple_device_properties(struct boot_params *boot_params) ...@@ -341,8 +339,7 @@ static void retrieve_apple_device_properties(struct boot_params *boot_params)
status = efi_call_early(allocate_pool, EFI_LOADER_DATA, status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
size + sizeof(struct setup_data), &new); size + sizeof(struct setup_data), &new);
if (status != EFI_SUCCESS) { if (status != EFI_SUCCESS) {
efi_printk(sys_table, efi_printk(sys_table, "Failed to allocate memory for 'properties'\n");
"Failed to alloc mem for properties\n");
return; return;
} }
...@@ -358,9 +355,9 @@ static void retrieve_apple_device_properties(struct boot_params *boot_params) ...@@ -358,9 +355,9 @@ static void retrieve_apple_device_properties(struct boot_params *boot_params)
new->next = 0; new->next = 0;
data = (struct setup_data *)(unsigned long)boot_params->hdr.setup_data; data = (struct setup_data *)(unsigned long)boot_params->hdr.setup_data;
if (!data) if (!data) {
boot_params->hdr.setup_data = (unsigned long)new; boot_params->hdr.setup_data = (unsigned long)new;
else { } else {
while (data->next) while (data->next)
data = (struct setup_data *)(unsigned long)data->next; data = (struct setup_data *)(unsigned long)data->next;
data->next = (unsigned long)new; data->next = (unsigned long)new;
...@@ -473,8 +470,8 @@ setup_uga64(void **uga_handle, unsigned long size, u32 *width, u32 *height) ...@@ -473,8 +470,8 @@ setup_uga64(void **uga_handle, unsigned long size, u32 *width, u32 *height)
/* /*
* See if we have Universal Graphics Adapter (UGA) protocol * See if we have Universal Graphics Adapter (UGA) protocol
*/ */
static efi_status_t setup_uga(struct screen_info *si, efi_guid_t *uga_proto, static efi_status_t
unsigned long size) setup_uga(struct screen_info *si, efi_guid_t *uga_proto, unsigned long size)
{ {
efi_status_t status; efi_status_t status;
u32 width, height; u32 width, height;
...@@ -520,6 +517,7 @@ static efi_status_t setup_uga(struct screen_info *si, efi_guid_t *uga_proto, ...@@ -520,6 +517,7 @@ static efi_status_t setup_uga(struct screen_info *si, efi_guid_t *uga_proto,
free_handle: free_handle:
efi_call_early(free_pool, uga_handle); efi_call_early(free_pool, uga_handle);
return status; return status;
} }
...@@ -601,7 +599,7 @@ struct boot_params *make_boot_params(struct efi_config *c) ...@@ -601,7 +599,7 @@ struct boot_params *make_boot_params(struct efi_config *c)
status = efi_low_alloc(sys_table, 0x4000, 1, status = efi_low_alloc(sys_table, 0x4000, 1,
(unsigned long *)&boot_params); (unsigned long *)&boot_params);
if (status != EFI_SUCCESS) { if (status != EFI_SUCCESS) {
efi_printk(sys_table, "Failed to alloc lowmem for boot params\n"); efi_printk(sys_table, "Failed to allocate lowmem for boot params\n");
return NULL; return NULL;
} }
...@@ -627,6 +625,7 @@ struct boot_params *make_boot_params(struct efi_config *c) ...@@ -627,6 +625,7 @@ struct boot_params *make_boot_params(struct efi_config *c)
cmdline_ptr = efi_convert_cmdline(sys_table, image, &options_size); cmdline_ptr = efi_convert_cmdline(sys_table, image, &options_size);
if (!cmdline_ptr) if (!cmdline_ptr)
goto fail; goto fail;
hdr->cmd_line_ptr = (unsigned long)cmdline_ptr; hdr->cmd_line_ptr = (unsigned long)cmdline_ptr;
/* Fill in upper bits of command line address, NOP on 32 bit */ /* Fill in upper bits of command line address, NOP on 32 bit */
boot_params->ext_cmd_line_ptr = (u64)(unsigned long)cmdline_ptr >> 32; boot_params->ext_cmd_line_ptr = (u64)(unsigned long)cmdline_ptr >> 32;
...@@ -663,10 +662,12 @@ struct boot_params *make_boot_params(struct efi_config *c) ...@@ -663,10 +662,12 @@ struct boot_params *make_boot_params(struct efi_config *c)
boot_params->ext_ramdisk_size = (u64)ramdisk_size >> 32; boot_params->ext_ramdisk_size = (u64)ramdisk_size >> 32;
return boot_params; return boot_params;
fail2: fail2:
efi_free(sys_table, options_size, hdr->cmd_line_ptr); efi_free(sys_table, options_size, hdr->cmd_line_ptr);
fail: fail:
efi_free(sys_table, 0x4000, (unsigned long)boot_params); efi_free(sys_table, 0x4000, (unsigned long)boot_params);
return NULL; return NULL;
} }
...@@ -692,8 +693,8 @@ static void add_e820ext(struct boot_params *params, ...@@ -692,8 +693,8 @@ static void add_e820ext(struct boot_params *params,
params->hdr.setup_data = (unsigned long)e820ext; params->hdr.setup_data = (unsigned long)e820ext;
} }
static efi_status_t setup_e820(struct boot_params *params, static efi_status_t
struct setup_data *e820ext, u32 e820ext_size) setup_e820(struct boot_params *params, struct setup_data *e820ext, u32 e820ext_size)
{ {
struct boot_e820_entry *entry = params->e820_table; struct boot_e820_entry *entry = params->e820_table;
struct efi_info *efi = &params->efi_info; struct efi_info *efi = &params->efi_info;
...@@ -894,6 +895,7 @@ static efi_status_t exit_boot(struct boot_params *boot_params, ...@@ -894,6 +895,7 @@ static efi_status_t exit_boot(struct boot_params *boot_params,
e820ext = priv.e820ext; e820ext = priv.e820ext;
e820ext_size = priv.e820ext_size; e820ext_size = priv.e820ext_size;
/* Historic? */ /* Historic? */
boot_params->alt_mem_k = 32 * 1024; boot_params->alt_mem_k = 32 * 1024;
...@@ -908,8 +910,8 @@ static efi_status_t exit_boot(struct boot_params *boot_params, ...@@ -908,8 +910,8 @@ static efi_status_t exit_boot(struct boot_params *boot_params,
* On success we return a pointer to a boot_params structure, and NULL * On success we return a pointer to a boot_params structure, and NULL
* on failure. * on failure.
*/ */
struct boot_params *efi_main(struct efi_config *c, struct boot_params *
struct boot_params *boot_params) efi_main(struct efi_config *c, struct boot_params *boot_params)
{ {
struct desc_ptr *gdt = NULL; struct desc_ptr *gdt = NULL;
efi_loaded_image_t *image; efi_loaded_image_t *image;
...@@ -957,7 +959,7 @@ struct boot_params *efi_main(struct efi_config *c, ...@@ -957,7 +959,7 @@ struct boot_params *efi_main(struct efi_config *c,
status = efi_call_early(allocate_pool, EFI_LOADER_DATA, status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
sizeof(*gdt), (void **)&gdt); sizeof(*gdt), (void **)&gdt);
if (status != EFI_SUCCESS) { if (status != EFI_SUCCESS) {
efi_printk(sys_table, "Failed to alloc mem for gdt structure\n"); efi_printk(sys_table, "Failed to allocate memory for 'gdt' structure\n");
goto fail; goto fail;
} }
...@@ -965,7 +967,7 @@ struct boot_params *efi_main(struct efi_config *c, ...@@ -965,7 +967,7 @@ struct boot_params *efi_main(struct efi_config *c,
status = efi_low_alloc(sys_table, gdt->size, 8, status = efi_low_alloc(sys_table, gdt->size, 8,
(unsigned long *)&gdt->address); (unsigned long *)&gdt->address);
if (status != EFI_SUCCESS) { if (status != EFI_SUCCESS) {
efi_printk(sys_table, "Failed to alloc mem for gdt\n"); efi_printk(sys_table, "Failed to allocate memory for 'gdt'\n");
goto fail; goto fail;
} }
...@@ -1015,6 +1017,7 @@ struct boot_params *efi_main(struct efi_config *c, ...@@ -1015,6 +1017,7 @@ struct boot_params *efi_main(struct efi_config *c,
desc->d = SEG_OP_SIZE_32BIT; desc->d = SEG_OP_SIZE_32BIT;
desc->g = SEG_GRANULARITY_4KB; desc->g = SEG_GRANULARITY_4KB;
desc->base2 = 0x00; desc->base2 = 0x00;
desc++; desc++;
} else { } else {
/* Second entry is unused on 32-bit */ /* Second entry is unused on 32-bit */
...@@ -1031,6 +1034,7 @@ struct boot_params *efi_main(struct efi_config *c, ...@@ -1031,6 +1034,7 @@ struct boot_params *efi_main(struct efi_config *c,
desc->p = 1; desc->p = 1;
desc->limit1 = 0xf; desc->limit1 = 0xf;
desc->avl = 0; desc->avl = 0;
if (IS_ENABLED(CONFIG_X86_64)) { if (IS_ENABLED(CONFIG_X86_64)) {
desc->l = 1; desc->l = 1;
desc->d = 0; desc->d = 0;
...@@ -1082,5 +1086,6 @@ struct boot_params *efi_main(struct efi_config *c, ...@@ -1082,5 +1086,6 @@ struct boot_params *efi_main(struct efi_config *c,
return boot_params; return boot_params;
fail: fail:
efi_printk(sys_table, "efi_main() failed!\n"); efi_printk(sys_table, "efi_main() failed!\n");
return NULL; return NULL;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment