From nobody Thu Apr 25 04:22:43 2024 Delivered-To: importer2@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+importer2=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 1675193954664253.8010473617146; Tue, 31 Jan 2023 11:39:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pMwSq-0006ra-HQ; Tue, 31 Jan 2023 14:38:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pMwSp-0006p4-Eo for qemu-devel@nongnu.org; Tue, 31 Jan 2023 14:38:43 -0500 Received: from zero.eik.bme.hu ([2001:738:2001:2001::2001]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pMwSn-0003Ib-9m for qemu-devel@nongnu.org; Tue, 31 Jan 2023 14:38:43 -0500 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id 2DD8D74632B; Tue, 31 Jan 2023 20:36:12 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id E71D6745712; Tue, 31 Jan 2023 20:36:11 +0100 (CET) Message-Id: <12159564d95e6cdfc78611234f4c478184be425c.1675193329.git.balaton@eik.bme.hu> In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH 1/6] usb/ohci: Code style fix comments MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Howard Spoelstra Date: Tue, 31 Jan 2023 20:36:11 +0100 (CET) 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+importer2=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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZM-MESSAGEID: 1675193956221100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: BALATON Zoltan Reviewed-by: Peter Maydell --- hw/usb/hcd-ohci.c | 99 +++++++++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 50 deletions(-) diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c index 9d68036d23..9f138e7f25 100644 --- a/hw/usb/hcd-ohci.c +++ b/hw/usb/hcd-ohci.c @@ -23,7 +23,7 @@ * o Disable timers when nothing needs to be done, or remove timer usage * all together. * o BIOS work to boot from USB storage -*/ + */ =20 #include "qemu/osdep.h" #include "hw/irq.h" @@ -39,7 +39,7 @@ #include "hcd-ohci.h" =20 /* This causes frames to occur 1000x slower */ -//#define OHCI_TIME_WARP 1 +/*#define OHCI_TIME_WARP 1*/ =20 #define ED_LINK_LIMIT 32 =20 @@ -58,7 +58,7 @@ struct ohci_hcca { #define ED_WBACK_OFFSET offsetof(struct ohci_ed, head) #define ED_WBACK_SIZE 4 =20 -/* Bitfields for the first word of an Endpoint Desciptor. */ +/* Bitfields for the first word of an Endpoint Desciptor. */ #define OHCI_ED_FA_SHIFT 0 #define OHCI_ED_FA_MASK (0x7f<per_cur =3D 0; ohci->done =3D 0; ohci->done_count =3D 7; - - /* FSMPS is marked TBD in OCHI 1.0, what gives ffs? + /* + * FSMPS is marked TBD in OCHI 1.0, what gives ffs? * I took the value linux sets ... */ ohci->fsmps =3D 0x2778; @@ -460,10 +460,10 @@ static inline int ohci_read_hcca(OHCIState *ohci, static inline int ohci_put_ed(OHCIState *ohci, dma_addr_t addr, struct ohci_ed *ed) { - /* ed->tail is under control of the HCD. + /* + * ed->tail is under control of the HCD. * Since just ed->head is changed by HC, just write back this */ - return put_dwords(ohci, addr + ED_WBACK_OFFSET, (uint32_t *)((char *)ed + ED_WBACK_OFFSET), ED_WBACK_SIZE >> 2); @@ -601,8 +601,10 @@ static int ohci_service_iso_td(OHCIState *ohci, struct= ohci_ed *ed) trace_usb_ohci_iso_td_relative_frame_number_neg(relative_frame_num= ber); return 1; } else if (relative_frame_number > frame_count) { - /* ISO TD expired - retire the TD to the Done Queue and continue w= ith - the next ISO TD of the same ED */ + /* + * ISO TD expired - retire the TD to the Done Queue and continue w= ith + * the next ISO TD of the same ED + */ trace_usb_ohci_iso_td_relative_frame_number_big(relative_frame_num= ber, frame_count); if (OHCI_CC_DATAOVERRUN =3D=3D OHCI_BM(iso_td.flags, TD_CC)) { @@ -845,9 +847,10 @@ static void ohci_td_pkt(const char *msg, const uint8_t= *buf, size_t len) } } =20 -/* Service a transport descriptor. - Returns nonzero to terminate processing of this endpoint. */ - +/* + * Service a transport descriptor. + * Returns nonzero to terminate processing of this endpoint. + */ static int ohci_service_td(OHCIState *ohci, struct ohci_ed *ed) { int dir; @@ -869,7 +872,7 @@ static int ohci_service_td(OHCIState *ohci, struct ohci= _ed *ed) return 1; } =20 - /* See if this TD has already been submitted to the device. */ + /* See if this TD has already been submitted to the device. */ completion =3D (addr =3D=3D ohci->async_td); if (completion && !ohci->async_complete) { trace_usb_ohci_td_skip_async(); @@ -885,7 +888,7 @@ static int ohci_service_td(OHCIState *ohci, struct ohci= _ed *ed) switch (dir) { case OHCI_TD_DIR_OUT: case OHCI_TD_DIR_IN: - /* Same value. */ + /* Same value. */ break; default: dir =3D OHCI_BM(td.flags, TD_DP); @@ -956,11 +959,12 @@ static int ohci_service_td(OHCIState *ohci, struct oh= ci_ed *ed) } ep =3D usb_ep_get(dev, pid, OHCI_BM(ed->flags, ED_EN)); if (ohci->async_td) { - /* ??? The hardware should allow one active packet per - endpoint. We only allow one active packet per controller. - This should be sufficient as long as devices respond in a - timely manner. - */ + /* + * ??? The hardware should allow one active packet per + * endpoint. We only allow one active packet per controller. + * This should be sufficient as long as devices respond in a + * timely manner. + */ trace_usb_ohci_td_too_many_pending(ep->nr); return 1; } @@ -996,7 +1000,7 @@ static int ohci_service_td(OHCIState *ohci, struct ohc= i_ed *ed) =20 /* Writeback */ if (ret =3D=3D pktlen || (dir =3D=3D OHCI_TD_DIR_IN && ret >=3D 0 && f= lag_r)) { - /* Transmission succeeded. */ + /* Transmission succeeded. */ if (ret =3D=3D len) { td.cbp =3D 0; } else { @@ -1048,8 +1052,10 @@ static int ohci_service_td(OHCIState *ohci, struct o= hci_ed *ed) OHCI_SET_BM(td.flags, TD_EC, 3); break; } - /* An error occurred so we have to clear the interrupt counter= . See - * spec at 6.4.4 on page 104 */ + /* + * An error occurred so we have to clear the interrupt counter. + * See spec at 6.4.4 on page 104 + */ ohci->done_count =3D 0; } ed->head |=3D OHCI_ED_H; @@ -1071,7 +1077,7 @@ exit_no_retire: return OHCI_BM(td.flags, TD_CC) !=3D OHCI_CC_NOERROR; } =20 -/* Service an endpoint list. Returns nonzero if active TD were found. */ +/* Service an endpoint list. Returns nonzero if active TD were found. */ static int ohci_service_ed_list(OHCIState *ohci, uint32_t head) { struct ohci_ed ed; @@ -1095,7 +1101,7 @@ static int ohci_service_ed_list(OHCIState *ohci, uint= 32_t head) =20 if ((ed.head & OHCI_ED_H) || (ed.flags & OHCI_ED_K)) { uint32_t addr; - /* Cancel pending packets for ED that have been paused. */ + /* Cancel pending packets for ED that have been paused. */ addr =3D ed.head & OHCI_DPTR_MASK; if (ohci->async_td && addr =3D=3D ohci->async_td) { usb_cancel_packet(&ohci->usb_packet); @@ -1151,7 +1157,7 @@ static void ohci_sof(OHCIState *ohci) ohci_set_interrupt(ohci, OHCI_INTR_SF); } =20 -/* Process Control and Bulk lists. */ +/* Process Control and Bulk lists. */ static void ohci_process_lists(OHCIState *ohci) { if ((ohci->ctl & OHCI_CTL_CLE) && (ohci->status & OHCI_STATUS_CLF)) { @@ -1192,7 +1198,7 @@ static void ohci_frame_boundary(void *opaque) ohci_service_ed_list(ohci, le32_to_cpu(hcca.intr[n])); } =20 - /* Cancel all pending packets if either of the lists has been disabled= . */ + /* Cancel all pending packets if either of the lists has been disabled= . */ if (ohci->old_ctl & (~ohci->ctl) & (OHCI_CTL_BLE | OHCI_CTL_CLE)) { ohci_stop_endpoints(ohci); } @@ -1234,18 +1240,17 @@ static void ohci_frame_boundary(void *opaque) } } =20 -/* Start sending SOF tokens across the USB bus, lists are processed in +/* + * Start sending SOF tokens across the USB bus, lists are processed in * next frame */ static int ohci_bus_start(OHCIState *ohci) { trace_usb_ohci_start(ohci->name); - - /* Delay the first SOF event by one frame time as - * linux driver is not ready to receive it and - * can meet some race conditions + /* + * Delay the first SOF event by one frame time as linux driver is + * not ready to receive it and can meet some race conditions */ - ohci->sof_time =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); ohci_eof_timer(ohci); =20 @@ -1259,9 +1264,9 @@ void ohci_bus_stop(OHCIState *ohci) timer_del(ohci->eof_timer); } =20 -/* Sets a flag in a port status register but only set it if the port is - * connected, if not set ConnectStatusChange flag. If flag is enabled - * return 1. +/* + * Sets a flag in a port status reg but only set it if the port is connect= ed. + * If not set ConnectStatusChange flag. If flag is enabled return 1. */ static int ohci_port_set_if_connected(OHCIState *ohci, int i, uint32_t val) { @@ -1271,9 +1276,7 @@ static int ohci_port_set_if_connected(OHCIState *ohci= , int i, uint32_t val) if (val =3D=3D 0) return 0; =20 - /* If CurrentConnectStatus is cleared we set - * ConnectStatusChange - */ + /* If CurrentConnectStatus is cleared we set ConnectStatusChange */ if (!(ohci->rhport[i].ctrl & OHCI_PORT_CCS)) { ohci->rhport[i].ctrl |=3D OHCI_PORT_CSC; if (ohci->rhstatus & OHCI_RHS_DRWE) { @@ -1291,7 +1294,7 @@ static int ohci_port_set_if_connected(OHCIState *ohci= , int i, uint32_t val) return ret; } =20 -/* Set the frame interval - frame interval toggle is manipulated by the hc= d only */ +/* Frame interval toggle is manipulated by the hcd only */ static void ohci_set_frame_interval(OHCIState *ohci, uint16_t val) { val &=3D OHCI_FMI_FI; @@ -1357,9 +1360,7 @@ static uint32_t ohci_get_frame_remaining(OHCIState *o= hci) if ((ohci->ctl & OHCI_CTL_HCFS) !=3D OHCI_USB_OPERATIONAL) return (ohci->frt << 31); =20 - /* Being in USB operational state guarnatees sof_time was - * set already. - */ + /* Being in USB operational state guarnatees sof_time was set already.= */ tks =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - ohci->sof_time; if (tks < 0) { tks =3D 0; @@ -1439,13 +1440,11 @@ static void ohci_port_set_status(OHCIState *ohci, i= nt portnum, uint32_t val) trace_usb_ohci_port_reset(portnum); usb_device_reset(port->port.dev); port->ctrl &=3D ~OHCI_PORT_PRS; - /* ??? Should this also set OHCI_PORT_PESC. */ + /* ??? Should this also set OHCI_PORT_PESC. */ port->ctrl |=3D OHCI_PORT_PES | OHCI_PORT_PRSC; } =20 - /* Invert order here to ensure in ambiguous case, device is - * powered up... - */ + /* Invert order here to ensure in ambiguous case, device is powered up= . */ if (val & OHCI_PORT_LSDA) ohci_port_power(ohci, portnum, 0); if (val & OHCI_PORT_PPS) @@ -1892,7 +1891,7 @@ void usb_ohci_init(OHCIState *ohci, DeviceState *dev,= uint32_t num_ports, ohci_frame_boundary, ohci); } =20 -/** +/* * A typical OHCI will stop operating and set itself into error state * (which can be queried by MMIO) to signal that it got an error. */ --=20 2.30.6 From nobody Thu Apr 25 04:22:43 2024 Delivered-To: importer2@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+importer2=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 1675193957502991.7288332826151; Tue, 31 Jan 2023 11:39:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pMwSs-0006sl-Ad; Tue, 31 Jan 2023 14:38:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pMwSq-0006rb-H8 for qemu-devel@nongnu.org; Tue, 31 Jan 2023 14:38:44 -0500 Received: from zero.eik.bme.hu ([152.66.115.2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pMwSn-0003Ih-Rb for qemu-devel@nongnu.org; Tue, 31 Jan 2023 14:38:44 -0500 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id 38400746335; Tue, 31 Jan 2023 20:36:13 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id F2A67745712; Tue, 31 Jan 2023 20:36:12 +0100 (CET) Message-Id: <42bcdf2e60211557ec44f11a45d6b465654693b4.1675193329.git.balaton@eik.bme.hu> In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH 2/6] usb/ohci: Code style fix white space errors MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Howard Spoelstra Date: Tue, 31 Jan 2023 20:36:12 +0100 (CET) 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=152.66.115.2; envelope-from=balaton@eik.bme.hu; helo=zero.eik.bme.hu X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZM-MESSAGEID: 1675193958113100004 Content-Type: text/plain; charset="utf-8" Signed-off-by: BALATON Zoltan Reviewed-by: Peter Maydell --- hw/usb/hcd-ohci.c | 162 +++++++++++++++++++++++----------------------- 1 file changed, 80 insertions(+), 82 deletions(-) diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c index 9f138e7f25..b2a2de7964 100644 --- a/hw/usb/hcd-ohci.c +++ b/hw/usb/hcd-ohci.c @@ -60,46 +60,46 @@ struct ohci_hcca { =20 /* Bitfields for the first word of an Endpoint Desciptor. */ #define OHCI_ED_FA_SHIFT 0 -#define OHCI_ED_FA_MASK (0x7f<frame_number, starting_frame);=20 + relative_frame_number =3D USUB(ohci->frame_number, starting_frame); =20 trace_usb_ohci_iso_td_head( ed->head & OHCI_DPTR_MASK, ed->tail & OHCI_DPTR_MASK, @@ -657,8 +657,8 @@ static int ohci_service_iso_td(OHCIState *ohci, struct = ohci_ed *ed) next_offset =3D iso_td.be; } =20 - if (!(OHCI_BM(start_offset, TD_PSW_CC) & 0xe) ||=20 - ((relative_frame_number < frame_count) &&=20 + if (!(OHCI_BM(start_offset, TD_PSW_CC) & 0xe) || + ((relative_frame_number < frame_count) && !(OHCI_BM(next_offset, TD_PSW_CC) & 0xe))) { trace_usb_ohci_iso_td_bad_cc_not_accessed(start_offset, next_offse= t); return 1; @@ -1118,7 +1118,7 @@ static int ohci_service_ed_list(OHCIState *ohci, uint= 32_t head) ed.tail & OHCI_DPTR_MASK, ed.next & OHCI_DPTR_MASK); trace_usb_ohci_ed_pkt_flags( OHCI_BM(ed.flags, ED_FA), OHCI_BM(ed.flags, ED_EN), - OHCI_BM(ed.flags, ED_D), (ed.flags & OHCI_ED_S)!=3D 0, + OHCI_BM(ed.flags, ED_D), (ed.flags & OHCI_ED_S) !=3D 0, (ed.flags & OHCI_ED_K) !=3D 0, (ed.flags & OHCI_ED_F) = !=3D 0, OHCI_BM(ed.flags, ED_MPS)); =20 @@ -1311,10 +1311,8 @@ static void ohci_port_power(OHCIState *ohci, int i, = int p) if (p) { ohci->rhport[i].ctrl |=3D OHCI_PORT_PPS; } else { - ohci->rhport[i].ctrl &=3D ~(OHCI_PORT_PPS| - OHCI_PORT_CCS| - OHCI_PORT_PSS| - OHCI_PORT_PRS); + ohci->rhport[i].ctrl &=3D ~(OHCI_PORT_PPS | OHCI_PORT_CCS | + OHCI_PORT_PSS | OHCI_PORT_PRS); } } =20 @@ -1858,7 +1856,7 @@ void usb_ohci_init(OHCIState *ohci, DeviceState *dev,= uint32_t num_ports, ohci->num_ports =3D num_ports; if (masterbus) { USBPort *ports[OHCI_MAX_PORTS]; - for(i =3D 0; i < num_ports; i++) { + for (i =3D 0; i < num_ports; i++) { ports[i] =3D &ohci->rhport[i].port; } usb_register_companion(masterbus, ports, num_ports, @@ -1997,7 +1995,7 @@ const VMStateDescription vmstate_ohci_state =3D { VMSTATE_BOOL(async_complete, OHCIState), VMSTATE_END_OF_LIST() }, - .subsections =3D (const VMStateDescription*[]) { + .subsections =3D (const VMStateDescription * []) { &vmstate_ohci_eof_timer, NULL } --=20 2.30.6 From nobody Thu Apr 25 04:22:43 2024 Delivered-To: importer2@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+importer2=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 1675193938944736.149508484139; Tue, 31 Jan 2023 11:38:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pMwSs-0006sj-B0; Tue, 31 Jan 2023 14:38:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pMwSq-0006rc-JS for qemu-devel@nongnu.org; Tue, 31 Jan 2023 14:38:44 -0500 Received: from zero.eik.bme.hu ([152.66.115.2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pMwSo-0003Im-Dw for qemu-devel@nongnu.org; Tue, 31 Jan 2023 14:38:44 -0500 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id 44C53746346; Tue, 31 Jan 2023 20:36:14 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 0EFD9745712; Tue, 31 Jan 2023 20:36:14 +0100 (CET) Message-Id: <150f19f5299dd2c2261fd189f1d477ee9c0690a2.1675193329.git.balaton@eik.bme.hu> In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH 3/6] usb/ohci: Code style fix missing braces and extra parenthesis MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Howard Spoelstra Date: Tue, 31 Jan 2023 20:36:14 +0100 (CET) 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=152.66.115.2; envelope-from=balaton@eik.bme.hu; helo=zero.eik.bme.hu X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZM-MESSAGEID: 1675193941229100004 Content-Type: text/plain; charset="utf-8" Signed-off-by: BALATON Zoltan Reviewed-by: Peter Maydell --- hw/usb/hcd-ohci.c | 106 ++++++++++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 46 deletions(-) diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c index b2a2de7964..c262418181 100644 --- a/hw/usb/hcd-ohci.c +++ b/hw/usb/hcd-ohci.c @@ -499,9 +499,9 @@ static int ohci_copy_td(OHCIState *ohci, struct ohci_td= *td, =20 ptr =3D td->cbp; n =3D 0x1000 - (ptr & 0xfff); - if (n > len) + if (n > len) { n =3D len; - + } if (dma_memory_rw(ohci->as, ptr + ohci->localmem_base, buf, n, dir, MEMTXATTRS_UNSPECIFIED)) { return -1; @@ -527,9 +527,9 @@ static int ohci_copy_iso_td(OHCIState *ohci, =20 ptr =3D start_addr; n =3D 0x1000 - (ptr & 0xfff); - if (n > len) + if (n > len) { n =3D len; - + } if (dma_memory_rw(ohci->as, ptr + ohci->localmem_base, buf, n, dir, MEMTXATTRS_UNSPECIFIED)) { return -1; @@ -617,8 +617,9 @@ static int ohci_service_iso_td(OHCIState *ohci, struct = ohci_ed *ed) iso_td.next =3D ohci->done; ohci->done =3D addr; i =3D OHCI_BM(iso_td.flags, TD_DI); - if (i < ohci->done_count) + if (i < ohci->done_count) { ohci->done_count =3D i; + } if (ohci_put_iso_td(ohci, addr, &iso_td)) { ohci_die(ohci); return 1; @@ -803,8 +804,9 @@ static int ohci_service_iso_td(OHCIState *ohci, struct = ohci_ed *ed) iso_td.next =3D ohci->done; ohci->done =3D addr; i =3D OHCI_BM(iso_td.flags, TD_DI); - if (i < ohci->done_count) + if (i < ohci->done_count) { ohci->done_count =3D i; + } } if (ohci_put_iso_td(ohci, addr, &iso_td)) { ohci_die(ohci); @@ -1022,8 +1024,9 @@ static int ohci_service_td(OHCIState *ohci, struct oh= ci_ed *ed) =20 /* Setting ED_C is part of the TD retirement process */ ed->head &=3D ~OHCI_ED_C; - if (td.flags & OHCI_TD_T0) + if (td.flags & OHCI_TD_T0) { ed->head |=3D OHCI_ED_C; + } } else { if (ret >=3D 0) { trace_usb_ohci_td_underrun(); @@ -1067,8 +1070,9 @@ static int ohci_service_td(OHCIState *ohci, struct oh= ci_ed *ed) td.next =3D ohci->done; ohci->done =3D addr; i =3D OHCI_BM(td.flags, TD_DI); - if (i < ohci->done_count) + if (i < ohci->done_count) { ohci->done_count =3D i; + } exit_no_retire: if (ohci_put_td(ohci, addr, &td)) { ohci_die(ohci); @@ -1087,9 +1091,9 @@ static int ohci_service_ed_list(OHCIState *ohci, uint= 32_t head) uint32_t link_cnt =3D 0; active =3D 0; =20 - if (head =3D=3D 0) + if (head =3D=3D 0) { return 0; - + } for (cur =3D head; cur && link_cnt++ < ED_LINK_LIMIT; cur =3D next_ed)= { if (ohci_read_ed(ohci, cur, &ed)) { trace_usb_ohci_ed_read_error(cur); @@ -1125,8 +1129,9 @@ static int ohci_service_ed_list(OHCIState *ohci, uint= 32_t head) active =3D 1; =20 if ((ed.flags & OHCI_ED_F) =3D=3D 0) { - if (ohci_service_td(ohci, &ed)) + if (ohci_service_td(ohci, &ed)) { break; + } } else { /* Handle isochronous endpoints */ if (ohci_service_iso_td(ohci, &ed)) { @@ -1218,19 +1223,21 @@ static void ohci_frame_boundary(void *opaque) hcca.frame =3D cpu_to_le16(ohci->frame_number); =20 if (ohci->done_count =3D=3D 0 && !(ohci->intr_status & OHCI_INTR_WD)) { - if (!ohci->done) + if (!ohci->done) { abort(); - if (ohci->intr & ohci->intr_status) + } + if (ohci->intr & ohci->intr_status) { ohci->done |=3D 1; + } hcca.done =3D cpu_to_le32(ohci->done); ohci->done =3D 0; ohci->done_count =3D 7; ohci_set_interrupt(ohci, OHCI_INTR_WD); } =20 - if (ohci->done_count !=3D 7 && ohci->done_count !=3D 0) + if (ohci->done_count !=3D 7 && ohci->done_count !=3D 0) { ohci->done_count--; - + } /* Do SOF stuff here */ ohci_sof(ohci); =20 @@ -1273,9 +1280,9 @@ static int ohci_port_set_if_connected(OHCIState *ohci= , int i, uint32_t val) int ret =3D 1; =20 /* writing a 0 has no effect */ - if (val =3D=3D 0) + if (val =3D=3D 0) { return 0; - + } /* If CurrentConnectStatus is cleared we set ConnectStatusChange */ if (!(ohci->rhport[i].ctrl & OHCI_PORT_CCS)) { ohci->rhport[i].ctrl |=3D OHCI_PORT_CSC; @@ -1285,9 +1292,9 @@ static int ohci_port_set_if_connected(OHCIState *ohci= , int i, uint32_t val) return 0; } =20 - if (ohci->rhport[i].ctrl & val) + if (ohci->rhport[i].ctrl & val) { ret =3D 0; - + } /* set the bit */ ohci->rhport[i].ctrl |=3D val; =20 @@ -1327,9 +1334,9 @@ static void ohci_set_ctl(OHCIState *ohci, uint32_t va= l) new_state =3D ohci->ctl & OHCI_CTL_HCFS; =20 /* no state change */ - if (old_state =3D=3D new_state) + if (old_state =3D=3D new_state) { return; - + } trace_usb_ohci_set_ctl(ohci->name, new_state); switch (new_state) { case OHCI_USB_OPERATIONAL: @@ -1355,9 +1362,9 @@ static uint32_t ohci_get_frame_remaining(OHCIState *o= hci) uint16_t fr; int64_t tks; =20 - if ((ohci->ctl & OHCI_CTL_HCFS) !=3D OHCI_USB_OPERATIONAL) - return (ohci->frt << 31); - + if ((ohci->ctl & OHCI_CTL_HCFS) !=3D OHCI_USB_OPERATIONAL) { + return ohci->frt << 31; + } /* Being in USB operational state guarnatees sof_time was set already.= */ tks =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - ohci->sof_time; if (tks < 0) { @@ -1365,9 +1372,9 @@ static uint32_t ohci_get_frame_remaining(OHCIState *o= hci) } =20 /* avoid muldiv if possible */ - if (tks >=3D usb_frame_time) - return (ohci->frt << 31); - + if (tks >=3D usb_frame_time) { + return ohci->frt << 31; + } tks =3D tks / usb_bit_time; fr =3D (uint16_t)(ohci->fi - tks); =20 @@ -1383,33 +1390,36 @@ static void ohci_set_hub_status(OHCIState *ohci, ui= nt32_t val) old_state =3D ohci->rhstatus; =20 /* write 1 to clear OCIC */ - if (val & OHCI_RHS_OCIC) + if (val & OHCI_RHS_OCIC) { ohci->rhstatus &=3D ~OHCI_RHS_OCIC; - + } if (val & OHCI_RHS_LPS) { int i; =20 - for (i =3D 0; i < ohci->num_ports; i++) + for (i =3D 0; i < ohci->num_ports; i++) { ohci_port_power(ohci, i, 0); + } trace_usb_ohci_hub_power_down(); } =20 if (val & OHCI_RHS_LPSC) { int i; =20 - for (i =3D 0; i < ohci->num_ports; i++) + for (i =3D 0; i < ohci->num_ports; i++) { ohci_port_power(ohci, i, 1); + } trace_usb_ohci_hub_power_up(); } =20 - if (val & OHCI_RHS_DRWE) + if (val & OHCI_RHS_DRWE) { ohci->rhstatus |=3D OHCI_RHS_DRWE; - - if (val & OHCI_RHS_CRWE) + } + if (val & OHCI_RHS_CRWE) { ohci->rhstatus &=3D ~OHCI_RHS_DRWE; - - if (old_state !=3D ohci->rhstatus) + } + if (old_state !=3D ohci->rhstatus) { ohci_set_interrupt(ohci, OHCI_INTR_RHSC); + } } =20 /* Set root hub port status */ @@ -1422,12 +1432,12 @@ static void ohci_port_set_status(OHCIState *ohci, i= nt portnum, uint32_t val) old_state =3D port->ctrl; =20 /* Write to clear CSC, PESC, PSSC, OCIC, PRSC */ - if (val & OHCI_PORT_WTC) + if (val & OHCI_PORT_WTC) { port->ctrl &=3D ~(val & OHCI_PORT_WTC); - - if (val & OHCI_PORT_CCS) + } + if (val & OHCI_PORT_CCS) { port->ctrl &=3D ~OHCI_PORT_PES; - + } ohci_port_set_if_connected(ohci, portnum, val & OHCI_PORT_PES); =20 if (ohci_port_set_if_connected(ohci, portnum, val & OHCI_PORT_PSS)) { @@ -1443,13 +1453,15 @@ static void ohci_port_set_status(OHCIState *ohci, i= nt portnum, uint32_t val) } =20 /* Invert order here to ensure in ambiguous case, device is powered up= . */ - if (val & OHCI_PORT_LSDA) + if (val & OHCI_PORT_LSDA) { ohci_port_power(ohci, portnum, 0); - if (val & OHCI_PORT_PPS) + } + if (val & OHCI_PORT_PPS) { ohci_port_power(ohci, portnum, 1); - - if (old_state !=3D port->ctrl) + } + if (old_state !=3D port->ctrl) { ohci_set_interrupt(ohci, OHCI_INTR_RHSC); + } } =20 static uint64_t ohci_mem_read(void *opaque, @@ -1606,8 +1618,9 @@ static void ohci_mem_write(void *opaque, /* Bits written as '0' remain unchanged in the register */ ohci->status |=3D val; =20 - if (ohci->status & OHCI_STATUS_HCR) + if (ohci->status & OHCI_STATUS_HCR) { ohci_soft_reset(ohci); + } break; =20 case 3: /* HcInterruptStatus */ @@ -1685,8 +1698,9 @@ static void ohci_mem_write(void *opaque, =20 case 25: /* HcHReset */ ohci->hreset =3D val & ~OHCI_HRESET_FSBIR; - if (val & OHCI_HRESET_FSBIR) + if (val & OHCI_HRESET_FSBIR) { ohci_hard_reset(ohci); + } break; =20 case 26: /* HcHInterruptEnable */ --=20 2.30.6 From nobody Thu Apr 25 04:22:43 2024 Delivered-To: importer2@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+importer2=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 1675193962047676.3359048374585; Tue, 31 Jan 2023 11:39:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pMwSt-0006u0-LL; Tue, 31 Jan 2023 14:38:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pMwSr-0006sA-0G for qemu-devel@nongnu.org; Tue, 31 Jan 2023 14:38:45 -0500 Received: from zero.eik.bme.hu ([2001:738:2001:2001::2001]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pMwSp-0003KJ-BY for qemu-devel@nongnu.org; Tue, 31 Jan 2023 14:38:44 -0500 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id 3CE7F74635C; Tue, 31 Jan 2023 20:36:15 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 1A1B8745712; Tue, 31 Jan 2023 20:36:15 +0100 (CET) Message-Id: In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH 4/6] usb/ohci: Move a function next to where it is used MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Howard Spoelstra Date: Tue, 31 Jan 2023 20:36:15 +0100 (CET) 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+importer2=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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZM-MESSAGEID: 1675193964103100002 Content-Type: text/plain; charset="utf-8" The ohci_port_set_if_connected() function is only used by ohci_port_set_status(), move next to it to have them at the same place. Signed-off-by: BALATON Zoltan Reviewed-by: Peter Maydell --- hw/usb/hcd-ohci.c | 60 +++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c index c262418181..c5306378cc 100644 --- a/hw/usb/hcd-ohci.c +++ b/hw/usb/hcd-ohci.c @@ -1271,36 +1271,6 @@ void ohci_bus_stop(OHCIState *ohci) timer_del(ohci->eof_timer); } =20 -/* - * Sets a flag in a port status reg but only set it if the port is connect= ed. - * If not set ConnectStatusChange flag. If flag is enabled return 1. - */ -static int ohci_port_set_if_connected(OHCIState *ohci, int i, uint32_t val) -{ - int ret =3D 1; - - /* writing a 0 has no effect */ - if (val =3D=3D 0) { - return 0; - } - /* If CurrentConnectStatus is cleared we set ConnectStatusChange */ - if (!(ohci->rhport[i].ctrl & OHCI_PORT_CCS)) { - ohci->rhport[i].ctrl |=3D OHCI_PORT_CSC; - if (ohci->rhstatus & OHCI_RHS_DRWE) { - /* TODO: CSC is a wakeup event */ - } - return 0; - } - - if (ohci->rhport[i].ctrl & val) { - ret =3D 0; - } - /* set the bit */ - ohci->rhport[i].ctrl |=3D val; - - return ret; -} - /* Frame interval toggle is manipulated by the hcd only */ static void ohci_set_frame_interval(OHCIState *ohci, uint16_t val) { @@ -1422,6 +1392,36 @@ static void ohci_set_hub_status(OHCIState *ohci, uin= t32_t val) } } =20 +/* + * Sets a flag in a port status reg but only set it if the port is connect= ed. + * If not set ConnectStatusChange flag. If flag is enabled return 1. + */ +static int ohci_port_set_if_connected(OHCIState *ohci, int i, uint32_t val) +{ + int ret =3D 1; + + /* writing a 0 has no effect */ + if (val =3D=3D 0) { + return 0; + } + /* If CurrentConnectStatus is cleared we set ConnectStatusChange */ + if (!(ohci->rhport[i].ctrl & OHCI_PORT_CCS)) { + ohci->rhport[i].ctrl |=3D OHCI_PORT_CSC; + if (ohci->rhstatus & OHCI_RHS_DRWE) { + /* TODO: CSC is a wakeup event */ + } + return 0; + } + + if (ohci->rhport[i].ctrl & val) { + ret =3D 0; + } + /* set the bit */ + ohci->rhport[i].ctrl |=3D val; + + return ret; +} + /* Set root hub port status */ static void ohci_port_set_status(OHCIState *ohci, int portnum, uint32_t va= l) { --=20 2.30.6 From nobody Thu Apr 25 04:22:43 2024 Delivered-To: importer2@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+importer2=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 1675193983868846.04181510624; Tue, 31 Jan 2023 11:39:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pMwSv-0006vR-Ku; Tue, 31 Jan 2023 14:38:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pMwSs-0006sV-1s for qemu-devel@nongnu.org; Tue, 31 Jan 2023 14:38:46 -0500 Received: from zero.eik.bme.hu ([2001:738:2001:2001::2001]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pMwSq-0003Kc-EV for qemu-devel@nongnu.org; Tue, 31 Jan 2023 14:38:45 -0500 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id 4C534745712; Tue, 31 Jan 2023 20:36:16 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 2684C746376; Tue, 31 Jan 2023 20:36:16 +0100 (CET) Message-Id: <6c788d629e8caef69041f8fbb18bfe169285b58e.1675193329.git.balaton@eik.bme.hu> In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH 5/6] usb/ohci: Add trace points for register access MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Howard Spoelstra Date: Tue, 31 Jan 2023 20:36:16 +0100 (CET) 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+importer2=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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZM-MESSAGEID: 1675193984527100003 Content-Type: text/plain; charset="utf-8" To help debugging add trace points that print values read from or written to the device's registers. Signed-off-by: BALATON Zoltan --- hw/usb/hcd-ohci.c | 19 +++++++++++++++++++ hw/usb/trace-events | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c index c5306378cc..c5bec4e4d7 100644 --- a/hw/usb/hcd-ohci.c +++ b/hw/usb/hcd-ohci.c @@ -235,6 +235,15 @@ struct ohci_iso_td { =20 #define OHCI_HRESET_FSBIR (1 << 0) =20 +static const char *ohci_reg_names[] =3D { + "HcRevision", "HcControl", "HcCommandStatus", "HcInterruptStatus", + "HcInterruptEnable", "HcInterruptDisable", "HcHCCA", "HcPeriodCurrentE= D", + "HcControlHeadED", "HcControlCurrentED", "HcBulkHeadED", "HcBulkCurren= tED", + "HcDoneHead", "HcFmInterval", "HcFmRemaining", "HcFmNumber", + "HcPeriodicStart", "HcLSThreshold", "HcRhDescriptorA", "HcRhDescriptor= B", + "HcRhStatus" +}; + static void ohci_die(OHCIState *ohci) { ohci->ohci_die(ohci); @@ -1478,6 +1487,8 @@ static uint64_t ohci_mem_read(void *opaque, } else if (addr >=3D 0x54 && addr < 0x54 + ohci->num_ports * 4) { /* HcRhPortStatus */ retval =3D ohci->rhport[(addr - 0x54) >> 2].ctrl | OHCI_PORT_PPS; + trace_usb_ohci_mem_port_read(size, "HcRhPortStatus", (addr - 0x50)= >> 2, + addr, addr >> 2, retval); } else { switch (addr >> 2) { case 0: /* HcRevision */ @@ -1582,6 +1593,10 @@ static uint64_t ohci_mem_read(void *opaque, trace_usb_ohci_mem_read_bad_offset(addr); retval =3D 0xffffffff; } + if (addr !=3D 0xc || retval) { + trace_usb_ohci_mem_read(size, ohci_reg_names[addr >> 2], + addr, addr >> 2, retval); + } } =20 return retval; @@ -1602,10 +1617,14 @@ static void ohci_mem_write(void *opaque, =20 if (addr >=3D 0x54 && addr < 0x54 + ohci->num_ports * 4) { /* HcRhPortStatus */ + trace_usb_ohci_mem_port_write(size, "HcRhPortStatus", (addr - 0x50= ) >> 2, + addr, addr >> 2, val); ohci_port_set_status(ohci, (addr - 0x54) >> 2, val); return; } =20 + trace_usb_ohci_mem_write(size, ohci_reg_names[addr >> 2], + addr, addr >> 2, val); switch (addr >> 2) { case 1: /* HcControl */ ohci_set_ctl(ohci, val); diff --git a/hw/usb/trace-events b/hw/usb/trace-events index b65269892c..6bb9655c8d 100644 --- a/hw/usb/trace-events +++ b/hw/usb/trace-events @@ -57,8 +57,12 @@ usb_ohci_ed_read_error(uint32_t addr) "ED read error at = 0x%x" usb_ohci_ed_pkt(uint32_t cur, int h, int c, uint32_t head, uint32_t tail, = uint32_t next) "ED @ 0x%.8x h=3D%u c=3D%u\n head=3D0x%.8x tailp=3D0x%.8x n= ext=3D0x%.8x" usb_ohci_ed_pkt_flags(uint32_t fa, uint32_t en, uint32_t d, int s, int k, = int f, uint32_t mps) "fa=3D%u en=3D%u d=3D%u s=3D%u k=3D%u f=3D%u mps=3D%u" usb_ohci_hcca_read_error(uint32_t addr) "HCCA read error at 0x%x" +usb_ohci_mem_read(uint32_t size, const char *name, uint32_t addr, uint32_t= offs, uint32_t val) "%d %s 0x%x %d -> 0x%x" +usb_ohci_mem_port_read(uint32_t size, const char *name, uint32_t port, uin= t32_t addr, uint32_t offs, uint32_t val) "%d %s[%d] 0x%x %d -> 0x%x" usb_ohci_mem_read_unaligned(uint32_t addr) "at 0x%x" usb_ohci_mem_read_bad_offset(uint32_t addr) "0x%x" +usb_ohci_mem_write(uint32_t size, const char *name, uint32_t addr, uint32_= t offs, uint32_t val) "%d %s 0x%x %d <- 0x%x" +usb_ohci_mem_port_write(uint32_t size, const char *name, uint32_t port, ui= nt32_t addr, uint32_t offs, uint32_t val) "%d %s[%d] 0x%x %d <- 0x%x" usb_ohci_mem_write_unaligned(uint32_t addr) "at 0x%x" usb_ohci_mem_write_bad_offset(uint32_t addr) "0x%x" usb_ohci_process_lists(uint32_t head, uint32_t cur) "head 0x%x, cur 0x%x" --=20 2.30.6 From nobody Thu Apr 25 04:22:43 2024 Delivered-To: importer2@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+importer2=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 1675193988857214.41457811790883; Tue, 31 Jan 2023 11:39:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pMwSu-0006uB-GM; Tue, 31 Jan 2023 14:38:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pMwSt-0006tQ-1i for qemu-devel@nongnu.org; Tue, 31 Jan 2023 14:38:47 -0500 Received: from zero.eik.bme.hu ([2001:738:2001:2001::2001]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pMwSr-0003Kx-FT for qemu-devel@nongnu.org; Tue, 31 Jan 2023 14:38:46 -0500 Received: from zero.eik.bme.hu (blah.eik.bme.hu [152.66.115.182]) by localhost (Postfix) with SMTP id 61ED974632B; Tue, 31 Jan 2023 20:36:17 +0100 (CET) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 41310746324; Tue, 31 Jan 2023 20:36:17 +0100 (CET) Message-Id: In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH 6/6] usb/ohci: Implement resume on connection status change MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Howard Spoelstra Date: Tue, 31 Jan 2023 20:36:17 +0100 (CET) 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+importer2=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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZM-MESSAGEID: 1675193990545100003 Content-Type: text/plain; charset="utf-8" If certain bit is set remote wake up should change state from suspended to resume and generate interrupt. There was a todo comment for this, implement that by moving existing resume logic to a function and call that. Signed-off-by: BALATON Zoltan --- hw/usb/hcd-ohci.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c index c5bec4e4d7..7f98ab8924 100644 --- a/hw/usb/hcd-ohci.c +++ b/hw/usb/hcd-ohci.c @@ -1401,6 +1401,18 @@ static void ohci_set_hub_status(OHCIState *ohci, uin= t32_t val) } } =20 +/* This is the one state transition the controller can do by itself */ +static int ohci_resume(OHCIState *s) +{ + if ((s->ctl & OHCI_CTL_HCFS) =3D=3D OHCI_USB_SUSPEND) { + trace_usb_ohci_remote_wakeup(s->name); + s->ctl &=3D ~OHCI_CTL_HCFS; + s->ctl |=3D OHCI_USB_RESUME; + return 1; + } + return 0; +} + /* * Sets a flag in a port status reg but only set it if the port is connect= ed. * If not set ConnectStatusChange flag. If flag is enabled return 1. @@ -1417,7 +1429,10 @@ static int ohci_port_set_if_connected(OHCIState *ohc= i, int i, uint32_t val) if (!(ohci->rhport[i].ctrl & OHCI_PORT_CCS)) { ohci->rhport[i].ctrl |=3D OHCI_PORT_CSC; if (ohci->rhstatus & OHCI_RHS_DRWE) { - /* TODO: CSC is a wakeup event */ + /* CSC is a wakeup event */ + if (ohci_resume(ohci)) { + ohci_set_interrupt(ohci, OHCI_INTR_RD); + } } return 0; } @@ -1820,11 +1835,7 @@ static void ohci_wakeup(USBPort *port1) 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; + if (ohci_resume(s)) { /* * In suspend mode only ResumeDetected is possible, not RHSC: * see the OHCI spec 5.1.2.3. --=20 2.30.6