On Tue, Oct 10, 2017 at 02:56:26AM +0000, YASUOKA Masahiko wrote:
> On Sat, 7 Oct 2017 09:24:20 +0200
> Klemens Nanni <[email protected]> wrote:
> > On Sat, Oct 07, 2017 at 01:15:40AM +0000, YASUOKA Masahiko wrote:
> >> > See my updated diff for reusing the gopi struct, please.
> >>
> >> ok, but the diff seems to be against wrong revision. You seems to
> >> have other diffs, moving gop and gopi to global at least.
> >>
> >> Can you send it entirely?
> > My bad, those were applied on top of other (unsubmitted) diffs such as
> > https://marc.info/?l=openbsd-tech&m=150437080106164
>
> Ah, sorry I missed that mail.
>
> On Fri, 6 Oct 2017 20:11:24 +0200
> Klemens Nanni <[email protected]> wrote:
> > Declaring the gop and gopi strucutures globally makes things easier in
> > preparation for the next commit.
> >
> > Both changes also improve consistency with regard to other structures
> > like ei, di and conout as well.
>
> As for gopi, I'd like to keep it be a local since it is used to refer
> various different modes.
That's fine.
> also s/efi_gopmode/gopmode/
I adapted efi_gopmode from your previous patch.
> comments?
>
> Index: sys/arch/amd64/stand/efiboot/efiboot.c
> ===================================================================
> RCS file: /cvs/src/sys/arch/amd64/stand/efiboot/efiboot.c,v
> retrieving revision 1.24
> diff -u -p -r1.24 efiboot.c
> --- sys/arch/amd64/stand/efiboot/efiboot.c 6 Oct 2017 04:52:22 -0000
> 1.24
> +++ sys/arch/amd64/stand/efiboot/efiboot.c 10 Oct 2017 02:52:46 -0000
> @@ -60,7 +60,7 @@ static void efi_memprobe_internal(void)
> static void efi_video_init(void);
> static void efi_video_reset(void);
> static EFI_STATUS
> - efi_gop_setmode(EFI_GRAPHICS_OUTPUT *gop, int mode);
> + efi_gop_setmode(int mode);
> EFI_STATUS efi_main(EFI_HANDLE, EFI_SYSTEM_TABLE *);
>
> void (*run_i386)(u_long, u_long, int, int, int, int, int, int, int, int)
> @@ -696,13 +696,15 @@ efi_com_putc(dev_t dev, int c)
> * {EFI_,}_ACPI_20_TABLE_GUID or EFI_ACPI_TABLE_GUID means
> * ACPI 2.0 or above.
> */
> -static EFI_GUID acpi_guid = ACPI_20_TABLE_GUID;
> -static EFI_GUID smbios_guid = SMBIOS_TABLE_GUID;
> +static EFI_GUID acpi_guid = ACPI_20_TABLE_GUID;
> +static EFI_GUID smbios_guid = SMBIOS_TABLE_GUID;
> +static EFI_GRAPHICS_OUTPUT *gop;
> +static int gopmode = -1;
>
> #define efi_guidcmp(_a, _b) memcmp((_a), (_b), sizeof(EFI_GUID))
>
> static EFI_STATUS
> -efi_gop_setmode(EFI_GRAPHICS_OUTPUT *gop, int mode)
> +efi_gop_setmode(int mode)
> {
> EFI_STATUS status;
>
> @@ -718,14 +720,11 @@ efi_makebootargs(void)
> {
> int i;
> EFI_STATUS status;
> - EFI_GRAPHICS_OUTPUT *gop;
> EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
> *gopi;
> bios_efiinfo_t ei;
> - int curmode, bestmode = -1;
> + int curmode;
> UINTN sz, gopsiz, bestsiz = 0;
> - EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
> - *info;
>
> memset(&ei, 0, sizeof(ei));
> /*
> @@ -748,21 +747,24 @@ efi_makebootargs(void)
> status = EFI_CALL(BS->LocateProtocol, &gop_guid, NULL,
> (void **)&gop);
> if (!EFI_ERROR(status)) {
> - for (i = 0; i < gop->Mode->MaxMode; i++) {
> - status = EFI_CALL(gop->QueryMode, gop, i, &sz, &info);
> - if (EFI_ERROR(status))
> - continue;
> - gopsiz = info->HorizontalResolution *
> - info->VerticalResolution;
> - if (gopsiz > bestsiz) {
> - bestmode = i;
> - bestsiz = gopsiz;
> + if (gopmode < 0) {
> + for (i = 0; i < gop->Mode->MaxMode; i++) {
> + status = EFI_CALL(gop->QueryMode, gop,
> + i, &sz, &gopi);
> + if (EFI_ERROR(status))
> + continue;
> + gopsiz = gopi->HorizontalResolution *
> + gopi->VerticalResolution;
> + if (gopsiz > bestsiz) {
> + gopmode = i;
> + bestsiz = gopsiz;
> + }
> }
> }
> - if (bestmode >= 0) {
> + if (gopmode >= 0 && gopmode != gop->Mode->Mode) {
> curmode = gop->Mode->Mode;
> - if (efi_gop_setmode(gop, bestmode) != EFI_SUCCESS)
> - (void)efi_gop_setmode(gop, curmode);
> + if (efi_gop_setmode(gopmode) != EFI_SUCCESS)
> + (void)efi_gop_setmode(curmode);
> }
>
> gopi = gop->Mode->Info;
> @@ -882,5 +884,46 @@ int
> Xpoweroff_efi(void)
> {
> EFI_CALL(RS->ResetSystem, EfiResetShutdown, EFI_SUCCESS, 0, NULL);
> + return (0);
> +}
> +
> +int
> +Xgop_efi(void)
> +{
> + EFI_STATUS status;
> + int i, mode = -1;
> + UINTN sz;
> + EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
> + *gopi;
> +
> + status = EFI_CALL(BS->LocateProtocol, &gop_guid, NULL,
> + (void **)&gop);
> + if (EFI_ERROR(status))
> + return (0);
> +
> + if (cmd.argc >= 2) {
> + mode = strtol(cmd.argv[1], NULL, 10);
> + if (0 <= mode && mode < gop->Mode->MaxMode) {
> + status = EFI_CALL(gop->QueryMode, gop, mode,
> + &sz, &gopi);
> + if (!EFI_ERROR(status)) {
> + if (efi_gop_setmode(mode) == EFI_SUCCESS)
> + gopmode = mode;
> + }
> + }
> + } else {
> + for (i = 0; i < gop->Mode->MaxMode; i++) {
> + status = EFI_CALL(gop->QueryMode, gop, i, &sz, &gopi);
> + if (EFI_ERROR(status))
> + continue;
> + printf("Mode %d: %d x %d (stride = %d)\n", i,
> + gopi->HorizontalResolution,
> + gopi->VerticalResolution,
> + gopi->PixelsPerScanLine);
> + }
> + printf("\n");
> + }
> + printf("Current Mode = %d\n", gop->Mode->Mode);
> +
> return (0);
> }
> Index: sys/arch/amd64/stand/efiboot/efiboot.h
> ===================================================================
> RCS file: /cvs/src/sys/arch/amd64/stand/efiboot/efiboot.h,v
> retrieving revision 1.2
> diff -u -p -r1.2 efiboot.h
> --- sys/arch/amd64/stand/efiboot/efiboot.h 31 May 2017 08:40:32 -0000
> 1.2
> +++ sys/arch/amd64/stand/efiboot/efiboot.h 10 Oct 2017 02:52:47 -0000
> @@ -30,6 +30,7 @@ void efi_com_init(struct consdev *);
> int efi_com_getc(dev_t);
> void efi_com_putc(dev_t, int);
> int Xvideo_efi(void);
> +int Xgop_efi(void);
> int Xexit_efi(void);
> void efi_makebootargs(void);
>
> Index: sys/arch/amd64/stand/libsa/cmd_i386.c
> ===================================================================
> RCS file: /cvs/src/sys/arch/amd64/stand/libsa/cmd_i386.c,v
> retrieving revision 1.11
> diff -u -p -r1.11 cmd_i386.c
> --- sys/arch/amd64/stand/libsa/cmd_i386.c 31 May 2017 08:23:33 -0000
> 1.11
> +++ sys/arch/amd64/stand/libsa/cmd_i386.c 10 Oct 2017 02:52:47 -0000
> @@ -62,6 +62,7 @@ const struct cmd_table cmd_machine[] = {
> { "memory", CMDT_CMD, Xmemory },
> #ifdef EFIBOOT
> { "video", CMDT_CMD, Xvideo_efi },
> + { "gop", CMDT_CMD, Xgop_efi },
> { "exit", CMDT_CMD, Xexit_efi },
> { "poweroff", CMDT_CMD, Xpoweroff_efi },
> #endif
>
>
>
Good :)