[PATCH 18/18] riscv: qemu: Enable usb keyboard as an input device

Mark Kettenis mark.kettenis at xs4all.nl
Sun Jul 23 10:38:00 CEST 2023


> From: Bin Meng <bmeng at tinylab.org>
> Date: Sun, 23 Jul 2023 12:40:41 +0800
> 
> This brings PCI xHCI support to QEMU RISC-V and uses a usb keyboard
> as one of the input devices.
> 
> Signed-off-by: Bin Meng <bmeng at tinylab.org>
> 
> ---
> 
>  board/emulation/qemu-riscv/Kconfig      | 5 +++++
>  board/emulation/qemu-riscv/qemu-riscv.c | 5 +++++
>  doc/board/emulation/qemu-riscv.rst      | 5 +++++
>  include/configs/qemu-riscv.h            | 2 +-
>  4 files changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/board/emulation/qemu-riscv/Kconfig b/board/emulation/qemu-riscv/Kconfig
> index 7220c55350..b503578d27 100644
> --- a/board/emulation/qemu-riscv/Kconfig
> +++ b/board/emulation/qemu-riscv/Kconfig
> @@ -76,5 +76,10 @@ config BOARD_SPECIFIC_OPTIONS # dummy
>  	imply VIDEO_BOCHS
>  	imply SYS_WHITE_ON_BLACK
>  	imply PRE_CONSOLE_BUFFER
> +	imply USB
> +	imply USB_XHCI_HCD
> +	imply USB_XHCI_PCI
> +	imply USB_KEYBOARD
> +	imply CMD_USB
>  
>  endif
> diff --git a/board/emulation/qemu-riscv/qemu-riscv.c b/board/emulation/qemu-riscv/qemu-riscv.c
> index f39f3be366..181abbbf97 100644
> --- a/board/emulation/qemu-riscv/qemu-riscv.c
> +++ b/board/emulation/qemu-riscv/qemu-riscv.c
> @@ -12,6 +12,7 @@
>  #include <log.h>
>  #include <spl.h>
>  #include <init.h>
> +#include <usb.h>
>  #include <virtio_types.h>
>  #include <virtio.h>
>  
> @@ -41,6 +42,10 @@ int board_init(void)
>  
>  int board_late_init(void)
>  {
> +	/* start usb so that usb keyboard can be used as input device */
> +	if (CONFIG_IS_ENABLED(USB_KEYBOARD))
> +		usb_init();
> +

This is typically handled by including "usb start" in CONFIG_PREBOOT,
which is done by boot/Kconfig.  Any reason why that doesn't work for
you?

>  	return 0;
>  }
>  
> diff --git a/doc/board/emulation/qemu-riscv.rst b/doc/board/emulation/qemu-riscv.rst
> index 9d21f3270c..61137bcbf1 100644
> --- a/doc/board/emulation/qemu-riscv.rst
> +++ b/doc/board/emulation/qemu-riscv.rst
> @@ -138,6 +138,11 @@ and adding::
>  
>      -serial stdio -device VGA
>  
> +In addition, a usb keyboard can be attached to an emulated xHCI controller in
> +RISC-V virt machine as an option of input devices by adding::
> +
> +    -device qemu-xhci,id=xhci -device usb-kbd,bus=xhci.0
> +
>  Running with KVM
>  ----------------
>  
> diff --git a/include/configs/qemu-riscv.h b/include/configs/qemu-riscv.h
> index d5146e70f7..584559cfa3 100644
> --- a/include/configs/qemu-riscv.h
> +++ b/include/configs/qemu-riscv.h
> @@ -17,7 +17,7 @@
>  
>  /* Environment options */
>  
> -#define CFG_STD_DEVICES_SETTINGS	"stdin=serial\0" \
> +#define CFG_STD_DEVICES_SETTINGS	"stdin=serial,usbkbd\0" \
>  					"stdout=serial,vidconsole\0" \
>  					"stderr=serial,vidconsole\0"
>  
> -- 
> 2.34.1
> 
> 


More information about the U-Boot mailing list