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

Heinrich Schuchardt xypron.glpk at gmx.de
Mon Jul 24 20:11:18 CEST 2023


On 23.07.23 12:11, Mark Kettenis wrote:
>> Date: Sun, 23 Jul 2023 11:30:31 +0200
>> From: Heinrich Schuchardt <xypron.glpk at gmx.de>
>>
>> Am 23. Juli 2023 10:38:00 MESZ schrieb Mark Kettenis <mark.kettenis at xs4all.nl>:
>>>> 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?
>>
>> We run pci_init() in board_r.c. Why don't do the same for USB
>> instead of the PREBOOT quirk?
>
> Well, yes, that was going to be my next question.  If using PREBOOT is
> for some reason no longer the preferred way to do this, should there
> be some other generic method to make sure the USB controllers are
> started when a USB keyboard is configured as an input method.  Doing
> something generic like this in board-specific code seems wrong to me.
>
> Cheers,
>
> Mark

+CC Marek

>
>>>
>>>>   	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