Skip to content

Commit 2c23b73

Browse files
Ard BiesheuvelIngo Molnar
authored andcommitted
x86/efi: Prepare GOP handling code for reuse as generic code
In preparation of moving this code to drivers/firmware/efi and reusing it on ARM and arm64, apply any changes that will be required to make this code build for other architectures. This should make it easier to track down problems that this move may cause to its operation on x86. Note that the generic version uses slightly different ways of casting the protocol methods and some other variables to the correct types, since such method calls are not loosely typed on ARM and arm64 as they are on x86. Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Signed-off-by: Matt Fleming <matt@codeblueprint.co.uk> Cc: Borislav Petkov <bp@alien8.de> Cc: David Herrmann <dh.herrmann@gmail.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Peter Jones <pjones@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Will Deacon <will.deacon@arm.com> Cc: linux-efi@vger.kernel.org Link: http://lkml.kernel.org/r/1461614832-17633-17-git-send-email-matt@codeblueprint.co.uk Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent c3c1c47 commit 2c23b73

File tree

4 files changed

+49
-23
lines changed

4 files changed

+49
-23
lines changed

arch/x86/boot/compressed/eboot.c

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -622,19 +622,22 @@ setup_pixel_info(struct screen_info *si, u32 pixels_per_scan_line,
622622
}
623623

624624
static efi_status_t
625-
__gop_query32(struct efi_graphics_output_protocol_32 *gop32,
625+
__gop_query32(efi_system_table_t *sys_table_arg,
626+
struct efi_graphics_output_protocol_32 *gop32,
626627
struct efi_graphics_output_mode_info **info,
627628
unsigned long *size, u64 *fb_base)
628629
{
629630
struct efi_graphics_output_protocol_mode_32 *mode;
631+
efi_graphics_output_protocol_query_mode query_mode;
630632
efi_status_t status;
631633
unsigned long m;
632634

633635
m = gop32->mode;
634636
mode = (struct efi_graphics_output_protocol_mode_32 *)m;
637+
query_mode = (void *)(unsigned long)gop32->query_mode;
635638

636-
status = efi_early->call(gop32->query_mode, gop32,
637-
mode->mode, size, info);
639+
status = __efi_call_early(query_mode, (void *)gop32, mode->mode, size,
640+
info);
638641
if (status != EFI_SUCCESS)
639642
return status;
640643

@@ -643,8 +646,8 @@ __gop_query32(struct efi_graphics_output_protocol_32 *gop32,
643646
}
644647

645648
static efi_status_t
646-
setup_gop32(struct screen_info *si, efi_guid_t *proto,
647-
unsigned long size, void **gop_handle)
649+
setup_gop32(efi_system_table_t *sys_table_arg, struct screen_info *si,
650+
efi_guid_t *proto, unsigned long size, void **gop_handle)
648651
{
649652
struct efi_graphics_output_protocol_32 *gop32, *first_gop;
650653
unsigned long nr_gops;
@@ -654,7 +657,7 @@ setup_gop32(struct screen_info *si, efi_guid_t *proto,
654657
u64 fb_base;
655658
struct efi_pixel_bitmask pixel_info;
656659
int pixel_format;
657-
efi_status_t status;
660+
efi_status_t status = EFI_NOT_FOUND;
658661
u32 *handles = (u32 *)(unsigned long)gop_handle;
659662
int i;
660663

@@ -667,7 +670,7 @@ setup_gop32(struct screen_info *si, efi_guid_t *proto,
667670
efi_guid_t conout_proto = EFI_CONSOLE_OUT_DEVICE_GUID;
668671
bool conout_found = false;
669672
void *dummy = NULL;
670-
u32 h = handles[i];
673+
efi_handle_t h = (efi_handle_t)(unsigned long)handles[i];
671674
u64 current_fb_base;
672675

673676
status = efi_call_early(handle_protocol, h,
@@ -680,7 +683,8 @@ setup_gop32(struct screen_info *si, efi_guid_t *proto,
680683
if (status == EFI_SUCCESS)
681684
conout_found = true;
682685

683-
status = __gop_query32(gop32, &info, &size, &current_fb_base);
686+
status = __gop_query32(sys_table_arg, gop32, &info, &size,
687+
&current_fb_base);
684688
if (status == EFI_SUCCESS && (!first_gop || conout_found)) {
685689
/*
686690
* Systems that use the UEFI Console Splitter may
@@ -735,19 +739,22 @@ setup_gop32(struct screen_info *si, efi_guid_t *proto,
735739
}
736740

737741
static efi_status_t
738-
__gop_query64(struct efi_graphics_output_protocol_64 *gop64,
742+
__gop_query64(efi_system_table_t *sys_table_arg,
743+
struct efi_graphics_output_protocol_64 *gop64,
739744
struct efi_graphics_output_mode_info **info,
740745
unsigned long *size, u64 *fb_base)
741746
{
742747
struct efi_graphics_output_protocol_mode_64 *mode;
748+
efi_graphics_output_protocol_query_mode query_mode;
743749
efi_status_t status;
744750
unsigned long m;
745751

746752
m = gop64->mode;
747753
mode = (struct efi_graphics_output_protocol_mode_64 *)m;
754+
query_mode = (void *)(unsigned long)gop64->query_mode;
748755

749-
status = efi_early->call(gop64->query_mode, gop64,
750-
mode->mode, size, info);
756+
status = __efi_call_early(query_mode, (void *)gop64, mode->mode, size,
757+
info);
751758
if (status != EFI_SUCCESS)
752759
return status;
753760

@@ -756,8 +763,8 @@ __gop_query64(struct efi_graphics_output_protocol_64 *gop64,
756763
}
757764

758765
static efi_status_t
759-
setup_gop64(struct screen_info *si, efi_guid_t *proto,
760-
unsigned long size, void **gop_handle)
766+
setup_gop64(efi_system_table_t *sys_table_arg, struct screen_info *si,
767+
efi_guid_t *proto, unsigned long size, void **gop_handle)
761768
{
762769
struct efi_graphics_output_protocol_64 *gop64, *first_gop;
763770
unsigned long nr_gops;
@@ -767,7 +774,7 @@ setup_gop64(struct screen_info *si, efi_guid_t *proto,
767774
u64 fb_base;
768775
struct efi_pixel_bitmask pixel_info;
769776
int pixel_format;
770-
efi_status_t status;
777+
efi_status_t status = EFI_NOT_FOUND;
771778
u64 *handles = (u64 *)(unsigned long)gop_handle;
772779
int i;
773780

@@ -780,7 +787,7 @@ setup_gop64(struct screen_info *si, efi_guid_t *proto,
780787
efi_guid_t conout_proto = EFI_CONSOLE_OUT_DEVICE_GUID;
781788
bool conout_found = false;
782789
void *dummy = NULL;
783-
u64 h = handles[i];
790+
efi_handle_t h = (efi_handle_t)(unsigned long)handles[i];
784791
u64 current_fb_base;
785792

786793
status = efi_call_early(handle_protocol, h,
@@ -793,7 +800,8 @@ setup_gop64(struct screen_info *si, efi_guid_t *proto,
793800
if (status == EFI_SUCCESS)
794801
conout_found = true;
795802

796-
status = __gop_query64(gop64, &info, &size, &current_fb_base);
803+
status = __gop_query64(sys_table_arg, gop64, &info, &size,
804+
&current_fb_base);
797805
if (status == EFI_SUCCESS && (!first_gop || conout_found)) {
798806
/*
799807
* Systems that use the UEFI Console Splitter may
@@ -850,8 +858,9 @@ setup_gop64(struct screen_info *si, efi_guid_t *proto,
850858
/*
851859
* See if we have Graphics Output Protocol
852860
*/
853-
static efi_status_t setup_gop(struct screen_info *si, efi_guid_t *proto,
854-
unsigned long size)
861+
efi_status_t efi_setup_gop(efi_system_table_t *sys_table_arg,
862+
struct screen_info *si, efi_guid_t *proto,
863+
unsigned long size)
855864
{
856865
efi_status_t status;
857866
void **gop_handle = NULL;
@@ -867,10 +876,13 @@ static efi_status_t setup_gop(struct screen_info *si, efi_guid_t *proto,
867876
if (status != EFI_SUCCESS)
868877
goto free_handle;
869878

870-
if (efi_early->is64)
871-
status = setup_gop64(si, proto, size, gop_handle);
872-
else
873-
status = setup_gop32(si, proto, size, gop_handle);
879+
if (efi_is_64bit()) {
880+
status = setup_gop64(sys_table_arg, si, proto, size,
881+
gop_handle);
882+
} else {
883+
status = setup_gop32(sys_table_arg, si, proto, size,
884+
gop_handle);
885+
}
874886

875887
free_handle:
876888
efi_call_early(free_pool, gop_handle);
@@ -1038,7 +1050,7 @@ void setup_graphics(struct boot_params *boot_params)
10381050
EFI_LOCATE_BY_PROTOCOL,
10391051
&graphics_proto, NULL, &size, gop_handle);
10401052
if (status == EFI_BUFFER_TOO_SMALL)
1041-
status = setup_gop(si, &graphics_proto, size);
1053+
status = efi_setup_gop(NULL, si, &graphics_proto, size);
10421054

10431055
if (status != EFI_SUCCESS) {
10441056
size = 0;

arch/x86/boot/compressed/eboot.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ struct efi_graphics_output_protocol {
8585
struct efi_graphics_output_protocol_mode *mode;
8686
};
8787

88+
typedef efi_status_t (*efi_graphics_output_protocol_query_mode)(
89+
struct efi_graphics_output_protocol *, u32, unsigned long *,
90+
struct efi_graphics_output_mode_info **);
91+
8892
struct efi_uga_draw_protocol_32 {
8993
u32 get_mode;
9094
u32 set_mode;

arch/x86/include/asm/efi.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ __pure const struct efi_config *__efi_early(void);
225225
#define efi_call_early(f, ...) \
226226
__efi_early()->call(__efi_early()->f, __VA_ARGS__);
227227

228+
#define __efi_call_early(f, ...) \
229+
__efi_early()->call((unsigned long)f, __VA_ARGS__);
230+
231+
#define efi_is_64bit() __efi_early()->is64
232+
228233
extern bool efi_reboot_required(void);
229234

230235
#else

include/linux/efi.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/pfn.h>
2222
#include <linux/pstore.h>
2323
#include <linux/reboot.h>
24+
#include <linux/screen_info.h>
2425

2526
#include <asm/page.h>
2627

@@ -1352,5 +1353,9 @@ efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
13521353

13531354
efi_status_t efi_parse_options(char *cmdline);
13541355

1356+
efi_status_t efi_setup_gop(efi_system_table_t *sys_table_arg,
1357+
struct screen_info *si, efi_guid_t *proto,
1358+
unsigned long size);
1359+
13551360
bool efi_runtime_disabled(void);
13561361
#endif /* _LINUX_EFI_H */

0 commit comments

Comments
 (0)