mbox series

[0/3] hw/boards: Remove MachineState::usb_disabled field

Message ID 20250526130006.49817-1-philmd@linaro.org
Headers show
Series hw/boards: Remove MachineState::usb_disabled field | expand

Message

Philippe Mathieu-Daudé May 26, 2025, 1 p.m. UTC
Only add default devices checking defaults_enabled().
Remove the unused usb_disabled field in MachineState.

Based-on: <20250526112346.48744-1-philmd@linaro.org>
          "hw/ppc: Fix --without-default-devices build"

Philippe Mathieu-Daudé (3):
  hw/ppc/spapr: Only create default devices when requested
  hw/ppc/mac_newworld: Only create default devices when requested
  hw/boards: Remove MachineState::usb_disabled field

 include/hw/boards.h   | 1 -
 hw/core/machine.c     | 1 -
 hw/ppc/mac_newworld.c | 3 +--
 hw/ppc/spapr.c        | 3 +--
 4 files changed, 2 insertions(+), 6 deletions(-)

Comments

Philippe Mathieu-Daudé May 26, 2025, 1:01 p.m. UTC | #1
(forgot to Cc Thomas)

On 26/5/25 15:00, Philippe Mathieu-Daudé wrote:
> Only add default devices checking defaults_enabled().
> Remove the unused usb_disabled field in MachineState.
> 
> Based-on: <20250526112346.48744-1-philmd@linaro.org>
>            "hw/ppc: Fix --without-default-devices build"
> 
> Philippe Mathieu-Daudé (3):
>    hw/ppc/spapr: Only create default devices when requested
>    hw/ppc/mac_newworld: Only create default devices when requested
>    hw/boards: Remove MachineState::usb_disabled field
> 
>   include/hw/boards.h   | 1 -
>   hw/core/machine.c     | 1 -
>   hw/ppc/mac_newworld.c | 3 +--
>   hw/ppc/spapr.c        | 3 +--
>   4 files changed, 2 insertions(+), 6 deletions(-)
>
BALATON Zoltan May 26, 2025, 1:18 p.m. UTC | #2
On Mon, 26 May 2025, Philippe Mathieu-Daudé wrote:
> Only add default devices checking defaults_enabled().
> Remove the unused usb_disabled field in MachineState.

At least for Mac machines this may be more complex. I think there is a 
-usb switch to enable/disable USB independently of defaults and due to 
some bugs some MacOS versions may need this to boot so maybe it's used.

Regards,
BALATON Zoltan

> Based-on: <20250526112346.48744-1-philmd@linaro.org>
>          "hw/ppc: Fix --without-default-devices build"
>
> Philippe Mathieu-Daudé (3):
>  hw/ppc/spapr: Only create default devices when requested
>  hw/ppc/mac_newworld: Only create default devices when requested
>  hw/boards: Remove MachineState::usb_disabled field
>
> include/hw/boards.h   | 1 -
> hw/core/machine.c     | 1 -
> hw/ppc/mac_newworld.c | 3 +--
> hw/ppc/spapr.c        | 3 +--
> 4 files changed, 2 insertions(+), 6 deletions(-)
>
>
Philippe Mathieu-Daudé May 26, 2025, 2:20 p.m. UTC | #3
On 26/5/25 15:18, BALATON Zoltan wrote:
> On Mon, 26 May 2025, Philippe Mathieu-Daudé wrote:
>> Only add default devices checking defaults_enabled().
>> Remove the unused usb_disabled field in MachineState.
> 
> At least for Mac machines this may be more complex. I think there is a - 
> usb switch to enable/disable USB independently of defaults and due to 
> some bugs some MacOS versions may need this to boot so maybe it's used.

If the user asks -usb off, we shouldn't re-enable it in the shadow.

If a configuration isn't usable, we have to report a configuration
error, possibly providing hints about what should be fixed.

> 
> Regards,
> BALATON Zoltan
> 
>> Based-on: <20250526112346.48744-1-philmd@linaro.org>
>>          "hw/ppc: Fix --without-default-devices build"
>>
>> Philippe Mathieu-Daudé (3):
>>  hw/ppc/spapr: Only create default devices when requested
>>  hw/ppc/mac_newworld: Only create default devices when requested
>>  hw/boards: Remove MachineState::usb_disabled field
>>
>> include/hw/boards.h   | 1 -
>> hw/core/machine.c     | 1 -
>> hw/ppc/mac_newworld.c | 3 +--
>> hw/ppc/spapr.c        | 3 +--
>> 4 files changed, 2 insertions(+), 6 deletions(-)
>>
>>
Paolo Bonzini May 27, 2025, 5:19 p.m. UTC | #4
On 5/26/25 16:20, Philippe Mathieu-Daudé wrote:
> On 26/5/25 15:18, BALATON Zoltan wrote:
>> On Mon, 26 May 2025, Philippe Mathieu-Daudé wrote:
>>> Only add default devices checking defaults_enabled().
>>> Remove the unused usb_disabled field in MachineState.
>>
>> At least for Mac machines this may be more complex. I think there is a 
>> - usb switch to enable/disable USB independently of defaults and due 
>> to some bugs some MacOS versions may need this to boot so maybe it's 
>> used.
> 
> If the user asks -usb off, we shouldn't re-enable it in the shadow.

And if the user asks -usb on, you shouldn't disable it.  My
understanding is that adding

-        if (!has_adb || machine_arch == ARCH_MAC99_U3) {
+        if ((!has_adb || machine_arch == ARCH_MAC99_U3) && defaults_enabled()) {

disables USB completely when -nodefaults.

If you want to remove usb_disabled, change machine->usb to ON_OFF_AUTO
and query

static inline bool machine_usb_enabled(MachineState *ms)
{
         return (defaults_enabled()
                 ? machine->usb != ON_OFF_AUTO_OFF
                 : machine->usb == ON_OFF_AUTO_ON);
}

instead of machine->usb (even better, change the name of the field so that
it causes a compilation error).

Paolo
Paolo Bonzini May 27, 2025, 5:19 p.m. UTC | #5
On 5/26/25 16:20, Philippe Mathieu-Daudé wrote:
> On 26/5/25 15:18, BALATON Zoltan wrote:
>> On Mon, 26 May 2025, Philippe Mathieu-Daudé wrote:
>>> Only add default devices checking defaults_enabled().
>>> Remove the unused usb_disabled field in MachineState.
>>
>> At least for Mac machines this may be more complex. I think there is a 
>> - usb switch to enable/disable USB independently of defaults and due 
>> to some bugs some MacOS versions may need this to boot so maybe it's 
>> used.
> 
> If the user asks -usb off, we shouldn't re-enable it in the shadow.

And if the user asks -usb on, you shouldn't disable it.  My
understanding is that adding

-        if (!has_adb || machine_arch == ARCH_MAC99_U3) {
+        if ((!has_adb || machine_arch == ARCH_MAC99_U3) && defaults_enabled()) {

disables USB completely when -nodefaults.

If you want to remove usb_disabled, change machine->usb to ON_OFF_AUTO
and query

static inline bool machine_usb_enabled(MachineState *ms)
{
         return (defaults_enabled()
                 ? machine->usb != ON_OFF_AUTO_OFF
                 : machine->usb == ON_OFF_AUTO_ON);
}

instead of machine->usb (even better, change the name of the field so that
it causes a compilation error).

Paolo
Mark Cave-Ayland May 27, 2025, 7:59 p.m. UTC | #6
On 27/05/2025 18:19, Paolo Bonzini wrote:

> On 5/26/25 16:20, Philippe Mathieu-Daudé wrote:
>> On 26/5/25 15:18, BALATON Zoltan wrote:
>>> On Mon, 26 May 2025, Philippe Mathieu-Daudé wrote:
>>>> Only add default devices checking defaults_enabled().
>>>> Remove the unused usb_disabled field in MachineState.
>>>
>>> At least for Mac machines this may be more complex. I think there is a - usb 
>>> switch to enable/disable USB independently of defaults and due to some bugs some 
>>> MacOS versions may need this to boot so maybe it's used.
>>
>> If the user asks -usb off, we shouldn't re-enable it in the shadow.
> 
> And if the user asks -usb on, you shouldn't disable it.  My
> understanding is that adding
> 
> -        if (!has_adb || machine_arch == ARCH_MAC99_U3) {
> +        if ((!has_adb || machine_arch == ARCH_MAC99_U3) && defaults_enabled()) {
> 
> disables USB completely when -nodefaults.
> 
> If you want to remove usb_disabled, change machine->usb to ON_OFF_AUTO
> and query
> 
> static inline bool machine_usb_enabled(MachineState *ms)
> {
>          return (defaults_enabled()
>                  ? machine->usb != ON_OFF_AUTO_OFF
>                  : machine->usb == ON_OFF_AUTO_ON);
> }
> 
> instead of machine->usb (even better, change the name of the field so that
> it causes a compilation error).

I have a feeling that this logic was added a while back to allow a build 
--without-default-devices to work? However disabling USB doesn't actually make sense 
for New World Macs, since the presence of USB ports is one of the ways of 
guaranteeing we have a New World Mac. I'm fairly sure I've seen (BSD?) kernel crashes 
if the USB ports are not present on the mac99 machine.

If MachineState::usb_disabled is removed completely, is it still possible to always 
have the USB ports enabled and the keyboard/mouse plugged into the mac99 machine?


ATB,

Mark.