From 66d55b09c560003edd61d52fbd347170dbe9c32d Mon Sep 17 00:00:00 2001 From: kettenis Date: Mon, 11 Jul 2022 19:45:02 +0000 Subject: [PATCH] Switch bootloaders to the extended BOOTARG_CONSDEV struct. Make the EFI bootloader provide the extra parameters that are necessary for using the non-standard UART on the AMD Ryzen Embedded V1000 SoCs. ok anton@ --- sys/arch/amd64/stand/boot/conf.c | 4 +- sys/arch/amd64/stand/cdboot/conf.c | 4 +- sys/arch/amd64/stand/efiboot/conf.c | 4 +- sys/arch/amd64/stand/efiboot/efiboot.c | 66 +++++++++++++++++++++++- sys/arch/amd64/stand/efiboot/efiboot.h | 3 +- sys/arch/amd64/stand/efiboot/exec_i386.c | 12 +---- sys/arch/amd64/stand/libsa/exec_i386.c | 6 +-- sys/arch/amd64/stand/pxeboot/conf.c | 4 +- 8 files changed, 80 insertions(+), 23 deletions(-) diff --git a/sys/arch/amd64/stand/boot/conf.c b/sys/arch/amd64/stand/boot/conf.c index a40bd230fb2..543d9b404ed 100644 --- a/sys/arch/amd64/stand/boot/conf.c +++ b/sys/arch/amd64/stand/boot/conf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.c,v 1.53 2020/12/09 18:10:17 krw Exp $ */ +/* $OpenBSD: conf.c,v 1.54 2022/07/11 19:45:02 kettenis Exp $ */ /* * Copyright (c) 1996 Michael Shalayeff @@ -41,7 +41,7 @@ #include #include -const char version[] = "3.53"; +const char version[] = "3.54"; int debug = 1; diff --git a/sys/arch/amd64/stand/cdboot/conf.c b/sys/arch/amd64/stand/cdboot/conf.c index 9875e59fe0f..5b4e78c86c4 100644 --- a/sys/arch/amd64/stand/cdboot/conf.c +++ b/sys/arch/amd64/stand/cdboot/conf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.c,v 1.47 2020/12/09 18:10:18 krw Exp $ */ +/* $OpenBSD: conf.c,v 1.48 2022/07/11 19:45:02 kettenis Exp $ */ /* * Copyright (c) 2004 Tom Cosgrove @@ -42,7 +42,7 @@ #include #include -const char version[] = "3.53"; +const char version[] = "3.54"; int debug = 1; diff --git a/sys/arch/amd64/stand/efiboot/conf.c b/sys/arch/amd64/stand/efiboot/conf.c index dfbc2f451f5..2096ee66f3d 100644 --- a/sys/arch/amd64/stand/efiboot/conf.c +++ b/sys/arch/amd64/stand/efiboot/conf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.c,v 1.37 2022/06/20 02:22:05 yasuoka Exp $ */ +/* $OpenBSD: conf.c,v 1.38 2022/07/11 19:45:02 kettenis Exp $ */ /* * Copyright (c) 1996 Michael Shalayeff @@ -40,7 +40,7 @@ #include "efidev.h" #include "efipxe.h" -const char version[] = "3.60"; +const char version[] = "3.61"; #ifdef EFI_DEBUG int debug = 0; diff --git a/sys/arch/amd64/stand/efiboot/efiboot.c b/sys/arch/amd64/stand/efiboot/efiboot.c index 33dad302e02..3115508d6c7 100644 --- a/sys/arch/amd64/stand/efiboot/efiboot.c +++ b/sys/arch/amd64/stand/efiboot/efiboot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: efiboot.c,v 1.39 2022/06/20 02:22:05 yasuoka Exp $ */ +/* $OpenBSD: efiboot.c,v 1.40 2022/07/11 19:45:02 kettenis Exp $ */ /* * Copyright (c) 2015 YASUOKA Masahiko @@ -938,6 +938,70 @@ efi_makebootargs(void) addbootarg(BOOTARG_EFIINFO, sizeof(bios_efiinfo), &bios_efiinfo); } +/* Vendor device path used to indicate the mmio UART on AMD SoCs. */ +#define AMDSOC_DEVPATH \ + { 0xe76fd4e9, 0x0a30, 0x4ca9, \ + { 0x95, 0x40, 0xd7, 0x99, 0x53, 0x4c, 0xc4, 0xff } } + +void +efi_setconsdev(void) +{ + bios_consdev_t cd; + EFI_STATUS status; + UINT8 data[128]; + UINTN size = sizeof(data); + EFI_DEVICE_PATH *dp = (void *)data; + VENDOR_DEVICE_PATH *vdp; + UART_DEVICE_PATH *udp; + EFI_GUID global = EFI_GLOBAL_VARIABLE; + EFI_GUID amdsoc = AMDSOC_DEVPATH; + + memset(&cd, 0, sizeof(cd)); + cd.consdev = cn_tab->cn_dev; + cd.conspeed = com_speed; + cd.consaddr = com_addr; + + /* + * If the ConOut variable indicates we're using a serial + * console, use it to determine the baud rate. + */ + status = RS->GetVariable(L"ConOut", &global, NULL, &size, &data); + if (status == EFI_SUCCESS) { + for (dp = (void *)data; !IsDevicePathEnd(dp); + dp = NextDevicePathNode(dp)) { + /* + * AMD Ryzen Embedded V1000 SoCs integrate a + * Synopsys DesignWare UART that is not + * compatible with the traditional 8250 UART + * found on the IBM PC. Pass the magic + * parameters to the kernel to make this UART + * work. + */ + if (DevicePathType(dp) == HARDWARE_DEVICE_PATH && + DevicePathSubType(dp) == HW_VENDOR_DP) { + vdp = (VENDOR_DEVICE_PATH *)dp; + if (efi_guidcmp(&vdp->Guid, &amdsoc) == 0) { + cd.consdev = makedev(8, 4); + cd.consaddr = *(uint64_t *)(vdp + 1); + cd.consfreq = 48000000; + cd.flags = BCD_MMIO; + cd.reg_width = 4; + cd.reg_shift = 2; + } + } + + if (DevicePathType(dp) == MESSAGING_DEVICE_PATH && + DevicePathSubType(dp) == MSG_UART_DP) { + udp = (UART_DEVICE_PATH *)dp; + if (cd.conspeed == -1) + cd.conspeed = udp->BaudRate; + } + } + } + + addbootarg(BOOTARG_CONSDEV, sizeof(cd), &cd); +} + void _rtt(void) { diff --git a/sys/arch/amd64/stand/efiboot/efiboot.h b/sys/arch/amd64/stand/efiboot/efiboot.h index 5f5052587fa..725aebcccbd 100644 --- a/sys/arch/amd64/stand/efiboot/efiboot.h +++ b/sys/arch/amd64/stand/efiboot/efiboot.h @@ -1,4 +1,4 @@ -/* $OpenBSD: efiboot.h,v 1.4 2017/11/25 19:02:07 patrick Exp $ */ +/* $OpenBSD: efiboot.h,v 1.5 2022/07/11 19:45:02 kettenis Exp $ */ /* * Copyright (c) 2015 YASUOKA Masahiko @@ -34,6 +34,7 @@ int Xvideo_efi(void); int Xgop_efi(void); int Xexit_efi(void); void efi_makebootargs(void); +void efi_setconsdev(void); int Xpoweroff_efi(void); diff --git a/sys/arch/amd64/stand/efiboot/exec_i386.c b/sys/arch/amd64/stand/efiboot/exec_i386.c index 08f68c32dcb..d6957c638b9 100644 --- a/sys/arch/amd64/stand/efiboot/exec_i386.c +++ b/sys/arch/amd64/stand/efiboot/exec_i386.c @@ -1,4 +1,4 @@ -/* $OpenBSD: exec_i386.c,v 1.8 2022/06/30 15:46:57 anton Exp $ */ +/* $OpenBSD: exec_i386.c,v 1.9 2022/07/11 19:45:02 kettenis Exp $ */ /* * Copyright (c) 1997-1998 Michael Shalayeff @@ -72,9 +72,6 @@ run_loadfile(uint64_t *marks, int howto) dev_t bootdev = bootdev_dip->bootdev; size_t ac = BOOTARG_LEN; caddr_t av = (caddr_t)BOOTARG_OFF; - bios_oconsdev_t cd; - extern int com_speed; /* from bioscons.c */ - extern int com_addr; bios_ddb_t ddb; extern int db_console; bios_bootduid_t bootduid; @@ -89,16 +86,11 @@ run_loadfile(uint64_t *marks, int howto) if ((av = alloc(ac)) == NULL) panic("alloc for bootarg"); efi_makebootargs(); + efi_setconsdev(); delta = DEFAULT_KERNEL_ADDRESS - efi_loadaddr; if (sa_cleanup != NULL) (*sa_cleanup)(); - cd.consdev = cn_tab->cn_dev; - cd.conspeed = com_speed; - cd.consaddr = com_addr; - cd.consfreq = 0; - addbootarg(BOOTARG_CONSDEV, sizeof(cd), &cd); - if (bootmac != NULL) addbootarg(BOOTARG_BOOTMAC, sizeof(bios_bootmac_t), bootmac); diff --git a/sys/arch/amd64/stand/libsa/exec_i386.c b/sys/arch/amd64/stand/libsa/exec_i386.c index f5900bcdc37..1d2e14bf929 100644 --- a/sys/arch/amd64/stand/libsa/exec_i386.c +++ b/sys/arch/amd64/stand/libsa/exec_i386.c @@ -1,4 +1,4 @@ -/* $OpenBSD: exec_i386.c,v 1.36 2022/06/30 15:46:57 anton Exp $ */ +/* $OpenBSD: exec_i386.c,v 1.37 2022/07/11 19:45:02 kettenis Exp $ */ /* * Copyright (c) 1997-1998 Michael Shalayeff @@ -91,7 +91,7 @@ run_loadfile(uint64_t *marks, int howto) dev_t bootdev = bootdev_dip->bootdev; size_t ac = BOOTARG_LEN; caddr_t av = (caddr_t)BOOTARG_OFF; - bios_oconsdev_t cd; + bios_consdev_t cd; extern int com_speed; /* from bioscons.c */ extern int com_addr; bios_ddb_t ddb; @@ -105,10 +105,10 @@ run_loadfile(uint64_t *marks, int howto) if (sa_cleanup != NULL) (*sa_cleanup)(); + memset(&cd, 0, sizeof(cd)); cd.consdev = cn_tab->cn_dev; cd.conspeed = com_speed; cd.consaddr = com_addr; - cd.consfreq = 0; addbootarg(BOOTARG_CONSDEV, sizeof(cd), &cd); if (bootmac != NULL) diff --git a/sys/arch/amd64/stand/pxeboot/conf.c b/sys/arch/amd64/stand/pxeboot/conf.c index 4d40cc17e88..f80304065d7 100644 --- a/sys/arch/amd64/stand/pxeboot/conf.c +++ b/sys/arch/amd64/stand/pxeboot/conf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.c,v 1.52 2020/12/09 18:10:18 krw Exp $ */ +/* $OpenBSD: conf.c,v 1.53 2022/07/11 19:45:02 kettenis Exp $ */ /* * Copyright (c) 2004 Tom Cosgrove @@ -44,7 +44,7 @@ #include "pxeboot.h" #include "pxe_net.h" -const char version[] = "3.53"; +const char version[] = "3.54"; int debug = 0; void (*sa_cleanup)(void) = pxe_shutdown; -- 2.20.1