static void handle_port_owner_write(EHCIState *s, int port, uint32_t owner)

{

    USBDevice *dev = s->ports[port].dev;

    uint32_t *portsc = &s->portsc[port];

    uint32_t orig;



    if (s->companion_ports[port] == NULL)

        return;



    owner = owner & PORTSC_POWNER;

    orig  = *portsc & PORTSC_POWNER;



    if (!(owner ^ orig)) {

        return;

    }



    if (dev) {

        usb_attach(&s->ports[port], NULL);

    }



    *portsc &= ~PORTSC_POWNER;

    *portsc |= owner;



    if (dev) {

        usb_attach(&s->ports[port], dev);

    }

}

static void handle_port_owner_write(EHCIState *s, int port, uint32_t owner)

{

    USBDevice *dev = s->ports[port].dev;

    uint32_t *portsc = &s->portsc[port];

    uint32_t orig;



    if (s->companion_ports[port] == NULL)

        return;



    owner = owner & PORTSC_POWNER;

    orig  = *portsc & PORTSC_POWNER;



    if (!(owner ^ orig)) {

        return;

    }



    if (dev) {

        usb_attach(&s->ports[port], NULL);

    }



    *portsc &= ~PORTSC_POWNER;

    *portsc |= owner;



    if (dev) {

        usb_attach(&s->ports[port], dev);

    }

}

static void FUNC_0(EHCIState *VAR_0, int VAR_1, uint32_t VAR_2)

{

    USBDevice *dev = VAR_0->ports[VAR_1].dev;

    uint32_t *portsc = &VAR_0->portsc[VAR_1];

    uint32_t orig;



    if (VAR_0->companion_ports[VAR_1] == NULL)

        return;



    VAR_2 = VAR_2 & PORTSC_POWNER;

    orig  = *portsc & PORTSC_POWNER;



    if (!(VAR_2 ^ orig)) {

        return;

    }



    if (dev) {

        usb_attach(&VAR_0->ports[VAR_1], NULL);

    }



    *portsc &= ~PORTSC_POWNER;

    *portsc |= VAR_2;



    if (dev) {

        usb_attach(&VAR_0->ports[VAR_1], dev);

    }

}

static void FUNC_0(EHCIState *VAR_0, int VAR_1, uint32_t VAR_2)
{ USBDevice *dev = VAR_0->ports[VAR_1].dev; uint32_t *portsc = &VAR_0->portsc[VAR_1]; uint32_t orig; if (VAR_0->companion_ports[VAR_1] == NULL)
return; VAR_2 = VAR_2 & PORTSC_POWNER; orig  = *portsc & PORTSC_POWNER; if (!(VAR_2 ^ orig)) { return; } if (dev) { usb_attach(&VAR_0->ports[VAR_1], NULL); } *portsc &= ~PORTSC_POWNER; *portsc |= VAR_2; if (dev) { usb_attach(&VAR_0->ports[VAR_1], dev); } }