From nobody Mon Feb 9 17:07:19 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=eik.bme.hu Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1633123206237697.4095174004447; Fri, 1 Oct 2021 14:20:06 -0700 (PDT) Received: from localhost ([::1]:35072 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mWPwq-0004bN-Mw for importer@patchew.org; Fri, 01 Oct 2021 17:20:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48880) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mWPtq-0001mB-Ly for qemu-devel@nongnu.org; Fri, 01 Oct 2021 17:16:58 -0400 Received: from zero.eik.bme.hu ([2001:738:2001:2001::2001]:46263) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mWPti-000844-Kj for qemu-devel@nongnu.org; Fri, 01 Oct 2021 17:16:58 -0400 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id 77CB0748F5E; Fri, 1 Oct 2021 23:16:49 +0200 (CEST) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 8B17A748F56; Fri, 1 Oct 2021 23:16:42 +0200 (CEST) Message-Id: In-Reply-To: References: From: BALATON Zoltan Subject: [RFC PATCH 2/4] usb/ohci: Move USBPortOps related functions together Date: Fri, 01 Oct 2021 23:11:10 +0200 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org X-Spam-Probability: 8% Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2001:738:2001:2001::2001; envelope-from=balaton@eik.bme.hu; helo=zero.eik.bme.hu X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Cave-Ayland , Gerd Hoffmann , Howard Spoelstra Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1633123208483100001 Content-Type: text/plain; charset="utf-8" This also allows removing two forward declarations Signed-off-by: BALATON Zoltan --- hw/usb/hcd-ohci.c | 204 +++++++++++++++++++++++----------------------- 1 file changed, 100 insertions(+), 104 deletions(-) diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c index 405abbb62d..f8761370e3 100644 --- a/hw/usb/hcd-ohci.c +++ b/hw/usb/hcd-ohci.c @@ -58,8 +58,6 @@ struct ohci_hcca { #define ED_WBACK_OFFSET offsetof(struct ohci_ed, head) #define ED_WBACK_SIZE 4 =20 -static void ohci_async_cancel_device(OHCIState *ohci, USBDevice *dev); - /* Bitfields for the first word of an Endpoint Desciptor. */ #define OHCI_ED_FA_SHIFT 0 #define OHCI_ED_FA_MASK (0x7f<opaque; - OHCIPort *port =3D &s->rhport[port1->index]; - uint32_t old_state =3D port->ctrl; - - /* set connect status */ - port->ctrl |=3D OHCI_PORT_CCS | OHCI_PORT_CSC; - - /* update speed */ - if (port->port.dev->speed =3D=3D USB_SPEED_LOW) { - port->ctrl |=3D OHCI_PORT_LSDA; - } else { - port->ctrl &=3D ~OHCI_PORT_LSDA; - } - - /* notify of remote-wakeup */ - if ((s->ctl & OHCI_CTL_HCFS) =3D=3D OHCI_USB_SUSPEND) { - ohci_set_interrupt(s, OHCI_INTR_RD); - } - - trace_usb_ohci_port_attach(port1->index); - - if (old_state !=3D port->ctrl) { - ohci_set_interrupt(s, OHCI_INTR_RHSC); - } -} - -static void ohci_detach(USBPort *port1) -{ - OHCIState *s =3D port1->opaque; - OHCIPort *port =3D &s->rhport[port1->index]; - uint32_t old_state =3D port->ctrl; - - ohci_async_cancel_device(s, port1->dev); - - /* set connect status */ - if (port->ctrl & OHCI_PORT_CCS) { - port->ctrl &=3D ~OHCI_PORT_CCS; - port->ctrl |=3D OHCI_PORT_CSC; - } - /* disable port */ - if (port->ctrl & OHCI_PORT_PES) { - port->ctrl &=3D ~OHCI_PORT_PES; - port->ctrl |=3D OHCI_PORT_PESC; - } - trace_usb_ohci_port_detach(port1->index); - - if (old_state !=3D port->ctrl) { - ohci_set_interrupt(s, OHCI_INTR_RHSC); - } -} - -static void ohci_wakeup(USBPort *port1) -{ - OHCIState *s =3D port1->opaque; - OHCIPort *port =3D &s->rhport[port1->index]; - uint32_t intr =3D 0; - if (port->ctrl & OHCI_PORT_PSS) { - trace_usb_ohci_port_wakeup(port1->index); - port->ctrl |=3D OHCI_PORT_PSSC; - port->ctrl &=3D ~OHCI_PORT_PSS; - intr =3D OHCI_INTR_RHSC; - } - /* Note that the controller can be suspended even if this port is not = */ - if ((s->ctl & OHCI_CTL_HCFS) =3D=3D OHCI_USB_SUSPEND) { - trace_usb_ohci_remote_wakeup(s->name); - /* This is the one state transition the controller can do by itsel= f */ - s->ctl &=3D ~OHCI_CTL_HCFS; - s->ctl |=3D OHCI_USB_RESUME; - /* In suspend mode only ResumeDetected is possible, not RHSC: - * see the OHCI spec 5.1.2.3. - */ - intr =3D OHCI_INTR_RD; - } - ohci_set_interrupt(s, intr); -} - -static void ohci_child_detach(USBPort *port1, USBDevice *child) -{ - OHCIState *s =3D port1->opaque; - - ohci_async_cancel_device(s, child); -} - static USBDevice *ohci_find_device(OHCIState *ohci, uint8_t addr) { USBDevice *dev; @@ -628,17 +540,6 @@ static int ohci_copy_iso_td(OHCIState *ohci, return 0; } =20 -static void ohci_process_lists(OHCIState *ohci, int completion); - -static void ohci_async_complete_packet(USBPort *port, USBPacket *packet) -{ - OHCIState *ohci =3D container_of(packet, OHCIState, usb_packet); - - trace_usb_ohci_async_complete(); - ohci->async_complete =3D true; - ohci_process_lists(ohci, 1); -} - #define USUB(a, b) ((int16_t)((uint16_t)(a) - (uint16_t)(b))) =20 static int ohci_service_iso_td(OHCIState *ohci, struct ohci_ed *ed, @@ -1783,6 +1684,41 @@ static void ohci_mem_write(void *opaque, } } =20 +static const MemoryRegionOps ohci_mem_ops =3D { + .read =3D ohci_mem_read, + .write =3D ohci_mem_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, +}; + +/* USBPortOps */ +static void ohci_attach(USBPort *port1) +{ + OHCIState *s =3D port1->opaque; + OHCIPort *port =3D &s->rhport[port1->index]; + uint32_t old_state =3D port->ctrl; + + /* set connect status */ + port->ctrl |=3D OHCI_PORT_CCS | OHCI_PORT_CSC; + + /* update speed */ + if (port->port.dev->speed =3D=3D USB_SPEED_LOW) { + port->ctrl |=3D OHCI_PORT_LSDA; + } else { + port->ctrl &=3D ~OHCI_PORT_LSDA; + } + + /* notify of remote-wakeup */ + if ((s->ctl & OHCI_CTL_HCFS) =3D=3D OHCI_USB_SUSPEND) { + ohci_set_interrupt(s, OHCI_INTR_RD); + } + + trace_usb_ohci_port_attach(port1->index); + + if (old_state !=3D port->ctrl) { + ohci_set_interrupt(s, OHCI_INTR_RHSC); + } +} + static void ohci_async_cancel_device(OHCIState *ohci, USBDevice *dev) { if (ohci->async_td && @@ -1793,11 +1729,71 @@ static void ohci_async_cancel_device(OHCIState *ohc= i, USBDevice *dev) } } =20 -static const MemoryRegionOps ohci_mem_ops =3D { - .read =3D ohci_mem_read, - .write =3D ohci_mem_write, - .endianness =3D DEVICE_LITTLE_ENDIAN, -}; +static void ohci_child_detach(USBPort *port1, USBDevice *child) +{ + OHCIState *s =3D port1->opaque; + + ohci_async_cancel_device(s, child); +} + +static void ohci_detach(USBPort *port1) +{ + OHCIState *s =3D port1->opaque; + OHCIPort *port =3D &s->rhport[port1->index]; + uint32_t old_state =3D port->ctrl; + + ohci_async_cancel_device(s, port1->dev); + + /* set connect status */ + if (port->ctrl & OHCI_PORT_CCS) { + port->ctrl &=3D ~OHCI_PORT_CCS; + port->ctrl |=3D OHCI_PORT_CSC; + } + /* disable port */ + if (port->ctrl & OHCI_PORT_PES) { + port->ctrl &=3D ~OHCI_PORT_PES; + port->ctrl |=3D OHCI_PORT_PESC; + } + trace_usb_ohci_port_detach(port1->index); + + if (old_state !=3D port->ctrl) { + ohci_set_interrupt(s, OHCI_INTR_RHSC); + } +} + +static void ohci_wakeup(USBPort *port1) +{ + OHCIState *s =3D port1->opaque; + OHCIPort *port =3D &s->rhport[port1->index]; + uint32_t intr =3D 0; + if (port->ctrl & OHCI_PORT_PSS) { + trace_usb_ohci_port_wakeup(port1->index); + port->ctrl |=3D OHCI_PORT_PSSC; + port->ctrl &=3D ~OHCI_PORT_PSS; + intr =3D OHCI_INTR_RHSC; + } + /* Note that the controller can be suspended even if this port is not = */ + if ((s->ctl & OHCI_CTL_HCFS) =3D=3D OHCI_USB_SUSPEND) { + trace_usb_ohci_remote_wakeup(s->name); + /* This is the one state transition the controller can do by itsel= f */ + s->ctl &=3D ~OHCI_CTL_HCFS; + s->ctl |=3D OHCI_USB_RESUME; + /* In suspend mode only ResumeDetected is possible, not RHSC: + * see the OHCI spec 5.1.2.3. + */ + intr =3D OHCI_INTR_RD; + } + ohci_set_interrupt(s, intr); +} + +static void ohci_async_complete_packet(USBPort *port, USBPacket *packet) +{ + OHCIState *ohci =3D container_of(packet, OHCIState, usb_packet); + + trace_usb_ohci_async_complete(); + ohci->async_complete =3D true; + ohci_process_lists(ohci, 1); +} =20 static USBPortOps ohci_port_ops =3D { .attach =3D ohci_attach, --=20 2.21.4