* [PATCH] hw/mips: Improve the default USB settings in the loongson3-virt machine
@ 2023-05-25 6:47 Thomas Huth
2023-06-07 10:26 ` Thomas Huth
0 siblings, 1 reply; 4+ messages in thread
From: Thomas Huth @ 2023-05-25 6:47 UTC (permalink / raw)
To: qemu-devel, Huacai Chen, Philippe Mathieu-Daudé; +Cc: Jiaxun Yang
It's possible to compile QEMU without the USB devices (e.g. when using
"--without-default-devices" as option for the "configure" script).
To be still able to run the loongson3-virt machine in default mode with
such a QEMU binary, we have to check here for the availability of the
devices first before instantiating them.
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
The alternative would be to use a "#ifdef CONFIG_USB_OHCI_PCI" etc.
... not sure what is nicer ... what do you think?
hw/mips/loongson3_virt.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c
index 216812f660..a0afb17030 100644
--- a/hw/mips/loongson3_virt.c
+++ b/hw/mips/loongson3_virt.c
@@ -447,10 +447,14 @@ static inline void loongson3_virt_devices_init(MachineState *machine,
pci_vga_init(pci_bus);
- if (defaults_enabled()) {
+ if (defaults_enabled() && module_object_class_by_name("pci-ohci")) {
pci_create_simple(pci_bus, -1, "pci-ohci");
- usb_create_simple(usb_bus_find(-1), "usb-kbd");
- usb_create_simple(usb_bus_find(-1), "usb-tablet");
+ if (module_object_class_by_name("usb-kbd")) {
+ usb_create_simple(usb_bus_find(-1), "usb-kbd");
+ }
+ if (module_object_class_by_name("usb-tablet")) {
+ usb_create_simple(usb_bus_find(-1), "usb-tablet");
+ }
}
for (i = 0; i < nb_nics; i++) {
--
2.31.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] hw/mips: Improve the default USB settings in the loongson3-virt machine
2023-05-25 6:47 [PATCH] hw/mips: Improve the default USB settings in the loongson3-virt machine Thomas Huth
@ 2023-06-07 10:26 ` Thomas Huth
2023-06-08 18:31 ` Michael Tokarev
0 siblings, 1 reply; 4+ messages in thread
From: Thomas Huth @ 2023-06-07 10:26 UTC (permalink / raw)
To: qemu-devel, Huacai Chen, Philippe Mathieu-Daudé
Cc: Jiaxun Yang, QEMU Trivial
On 25/05/2023 08.47, Thomas Huth wrote:
> It's possible to compile QEMU without the USB devices (e.g. when using
> "--without-default-devices" as option for the "configure" script).
> To be still able to run the loongson3-virt machine in default mode with
> such a QEMU binary, we have to check here for the availability of the
> devices first before instantiating them.
>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
> The alternative would be to use a "#ifdef CONFIG_USB_OHCI_PCI" etc.
> ... not sure what is nicer ... what do you think?
>
> hw/mips/loongson3_virt.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c
> index 216812f660..a0afb17030 100644
> --- a/hw/mips/loongson3_virt.c
> +++ b/hw/mips/loongson3_virt.c
> @@ -447,10 +447,14 @@ static inline void loongson3_virt_devices_init(MachineState *machine,
>
> pci_vga_init(pci_bus);
>
> - if (defaults_enabled()) {
> + if (defaults_enabled() && module_object_class_by_name("pci-ohci")) {
> pci_create_simple(pci_bus, -1, "pci-ohci");
> - usb_create_simple(usb_bus_find(-1), "usb-kbd");
> - usb_create_simple(usb_bus_find(-1), "usb-tablet");
> + if (module_object_class_by_name("usb-kbd")) {
> + usb_create_simple(usb_bus_find(-1), "usb-kbd");
> + }
> + if (module_object_class_by_name("usb-tablet")) {
> + usb_create_simple(usb_bus_find(-1), "usb-tablet");
> + }
> }
>
> for (i = 0; i < nb_nics; i++) {
Friendly ping!
Thomas
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] hw/mips: Improve the default USB settings in the loongson3-virt machine
2023-06-07 10:26 ` Thomas Huth
@ 2023-06-08 18:31 ` Michael Tokarev
2023-06-21 7:24 ` Thomas Huth
0 siblings, 1 reply; 4+ messages in thread
From: Michael Tokarev @ 2023-06-08 18:31 UTC (permalink / raw)
To: Thomas Huth, qemu-devel, Huacai Chen, Philippe Mathieu-Daudé
Cc: Jiaxun Yang, QEMU Trivial
07.06.2023 13:26, Thomas Huth wrote:
> On 25/05/2023 08.47, Thomas Huth wrote:
>> It's possible to compile QEMU without the USB devices (e.g. when using
>> "--without-default-devices" as option for the "configure" script).
>> To be still able to run the loongson3-virt machine in default mode with
>> such a QEMU binary, we have to check here for the availability of the
>> devices first before instantiating them.
>>
>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>> ---
>> The alternative would be to use a "#ifdef CONFIG_USB_OHCI_PCI" etc.
>> ... not sure what is nicer ... what do you think?
>>
>> hw/mips/loongson3_virt.c | 10 +++++++---
>> 1 file changed, 7 insertions(+), 3 deletions(-)
>>
>> diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c
>> index 216812f660..a0afb17030 100644
>> --- a/hw/mips/loongson3_virt.c
>> +++ b/hw/mips/loongson3_virt.c
>> @@ -447,10 +447,14 @@ static inline void loongson3_virt_devices_init(MachineState *machine,
>> pci_vga_init(pci_bus);
>> - if (defaults_enabled()) {
>> + if (defaults_enabled() && module_object_class_by_name("pci-ohci")) {
>> pci_create_simple(pci_bus, -1, "pci-ohci");
>> - usb_create_simple(usb_bus_find(-1), "usb-kbd");
>> - usb_create_simple(usb_bus_find(-1), "usb-tablet");
>> + if (module_object_class_by_name("usb-kbd")) {
>> + usb_create_simple(usb_bus_find(-1), "usb-kbd");
>> + }
>> + if (module_object_class_by_name("usb-tablet")) {
>> + usb_create_simple(usb_bus_find(-1), "usb-tablet");
>> + }
It looks like kbd/tablet don't need to have an if around, because
hw/usb/usb-hid.c is always compiled when CONFIG_USB is enabled,
and enabling CONFIG_USB_OHCI automatically selects CONFIG_USB.
I guess this whole code can be guarded by #if CONFIG_USB_OHCI..#endif,
instead of using runtime checking of device availability.
Notes:
Other places don't check if ohci or other usb controllers are available.
We have TYPE_PCI_OHCI #define which isn't used in places where pci-ohci
is requested, - probably need to move it to a common header (it is
defined in hw/usb/hcd-ohci-pci.c now).
roms/config.seabios-128k turns USB_OHCI off.
/mjt
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] hw/mips: Improve the default USB settings in the loongson3-virt machine
2023-06-08 18:31 ` Michael Tokarev
@ 2023-06-21 7:24 ` Thomas Huth
0 siblings, 0 replies; 4+ messages in thread
From: Thomas Huth @ 2023-06-21 7:24 UTC (permalink / raw)
To: Michael Tokarev, qemu-devel, Huacai Chen,
Philippe Mathieu-Daudé
Cc: Jiaxun Yang, QEMU Trivial
On 08/06/2023 20.31, Michael Tokarev wrote:
> 07.06.2023 13:26, Thomas Huth wrote:
>> On 25/05/2023 08.47, Thomas Huth wrote:
>>> It's possible to compile QEMU without the USB devices (e.g. when using
>>> "--without-default-devices" as option for the "configure" script).
>>> To be still able to run the loongson3-virt machine in default mode with
>>> such a QEMU binary, we have to check here for the availability of the
>>> devices first before instantiating them.
>>>
>>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>>> ---
>>> The alternative would be to use a "#ifdef CONFIG_USB_OHCI_PCI" etc.
>>> ... not sure what is nicer ... what do you think?
>>>
>>> hw/mips/loongson3_virt.c | 10 +++++++---
>>> 1 file changed, 7 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/hw/mips/loongson3_virt.c b/hw/mips/loongson3_virt.c
>>> index 216812f660..a0afb17030 100644
>>> --- a/hw/mips/loongson3_virt.c
>>> +++ b/hw/mips/loongson3_virt.c
>>> @@ -447,10 +447,14 @@ static inline void
>>> loongson3_virt_devices_init(MachineState *machine,
>>> pci_vga_init(pci_bus);
>>> - if (defaults_enabled()) {
>>> + if (defaults_enabled() && module_object_class_by_name("pci-ohci")) {
>>> pci_create_simple(pci_bus, -1, "pci-ohci");
>>> - usb_create_simple(usb_bus_find(-1), "usb-kbd");
>>> - usb_create_simple(usb_bus_find(-1), "usb-tablet");
>>> + if (module_object_class_by_name("usb-kbd")) {
>>> + usb_create_simple(usb_bus_find(-1), "usb-kbd");
>>> + }
>>> + if (module_object_class_by_name("usb-tablet")) {
>>> + usb_create_simple(usb_bus_find(-1), "usb-tablet");
>>> + }
>
> It looks like kbd/tablet don't need to have an if around, because
> hw/usb/usb-hid.c is always compiled when CONFIG_USB is enabled,
> and enabling CONFIG_USB_OHCI automatically selects CONFIG_USB.
Oh, right! So this can be simplified, indeed.
> I guess this whole code can be guarded by #if CONFIG_USB_OHCI..#endif,
> instead of using runtime checking of device availability.
Yes, that's the alternative ... I'll respin the patch with that to see how
it looks like.
> Notes:
>
> Other places don't check if ohci or other usb controllers are available.
Those likely use "select" instead of "imply" in their Kconfig, so the OHCI
controller is always included.
> We have TYPE_PCI_OHCI #define which isn't used in places where pci-ohci
> is requested, - probably need to move it to a common header (it is
> defined in hw/usb/hcd-ohci-pci.c now).
Yes, sounds like a cleanup that could be done in an additional patch.
> roms/config.seabios-128k turns USB_OHCI off.
That's the config of the seabios ROM - not (directly) related to the config
of the QEMU binaries.
Thomas
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-06-21 7:25 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-25 6:47 [PATCH] hw/mips: Improve the default USB settings in the loongson3-virt machine Thomas Huth
2023-06-07 10:26 ` Thomas Huth
2023-06-08 18:31 ` Michael Tokarev
2023-06-21 7:24 ` Thomas Huth
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).