From nobody Thu Apr 25 13:41:44 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 80.81.252.135 is neither permitted nor denied by domain of seabios.org) client-ip=80.81.252.135; envelope-from=seabios-bounces@seabios.org; helo=mail.coreboot.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 80.81.252.135 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org Return-Path: Received: from mail.coreboot.org (mail.coreboot.org [80.81.252.135]) by mx.zohomail.com with SMTPS id 1507052553261894.4174706282955; Tue, 3 Oct 2017 10:42:33 -0700 (PDT) Received: from [127.0.0.1] (helo=ra.coreboot.org) by mail.coreboot.org with esmtp (Exim 4.86_2) (envelope-from ) id 1dzRCz-0006nC-VT; Tue, 03 Oct 2017 19:42:18 +0200 Received: from mail-qk0-f193.google.com ([209.85.220.193]) by mail.coreboot.org with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.86_2) (envelope-from ) id 1dzRCm-0006lP-5D for seabios@seabios.org; Tue, 03 Oct 2017 19:42:15 +0200 Received: by mail-qk0-f193.google.com with SMTP id q8so6335024qkl.5 for ; Tue, 03 Oct 2017 10:42:04 -0700 (PDT) Received: from localhost ([64.9.249.2]) by smtp.gmail.com with ESMTPSA id a125sm8550256qkg.13.2017.10.03.10.42.00 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 Oct 2017 10:42:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=koconnor-net.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id; bh=V8kw9vEU8BO6RMinZm4RsqLh0XQ/ujOkuPeEEVB5HvY=; b=zqbf8mfwJkywOqC4gNZ61yygX34VM/uuDu1vSAKG9/bGIN4gYPEc+7mIugmcQgXFlb yg8p87EbYPue2sy5itnLqympVeot3V0VRvs+AtqRx5M4Pyi5VjVgLNGqSatm3SzuyZBL 4idXWGnBPfVdYUUOWl6nmQL7eQ3k2BhkMUF1CZMeiOxhh9zX+jkkLAAYWCC/XxfEpP0h 6zIvV9Lo7VJz75AZy3oo2ITPB4R6/2hLkrsvI3eR+aPXWWMO9cUXuvXYgCHSp3CcRRF4 Fgmw0Ey+Sp7XovREnddo4Ks9F7iVSnGP8Dywr1vjMyfVyjuULSYmhpjJogTCnl9V6Wrd gJEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=V8kw9vEU8BO6RMinZm4RsqLh0XQ/ujOkuPeEEVB5HvY=; b=rH/oflj14Bmnm1+fO5HVC5Al34cUpys3GBXc5GvPxWET/iOdKsssKQ75cxpn+Big9L ZmoKsg+at8t00SGFiuR4YFA2O91L8YfVuA9sK261weBUGYcrz783Ehb9Q/IPh9qDY0ZY O1nPRMzYg7ZeiJqAbelXPF8PJVkmjeCVeA9uQHW6c+0LXRjyox2/UTvSCRb9PHu4FBfS ejA6p4Mrs3sF1iJN5lWpPaW190q2BU2XqxGGaxqHOPc+RXMBG7pCanXCYxChL0e3wvoI fpqwr3h5/Ud+Tb6NRHZHCnABEhbYJETAiWznIAUmzPgspDdN70T7SD8WyMI1dndjeCSK epXw== X-Gm-Message-State: AMCzsaWLHlMPuAVjhIUuMwBll8yC8u/v3/n7/6FFHSx1vnDtj0tOAdDm lsaL/bSF25+mRUaxYriZKGG/KiNNYgA= X-Google-Smtp-Source: AOwi7QBRoXwVxaSm7wiAEGWbYoyNZLmkPSezC5BuXqy5xMg9eyUAzmhE3hPfvL953T3kFM68a6/arw== X-Received: by 10.55.23.131 with SMTP id 3mr19087020qkx.237.1507052521340; Tue, 03 Oct 2017 10:42:01 -0700 (PDT) From: Kevin O'Connor To: seabios@seabios.org Date: Tue, 3 Oct 2017 13:41:57 -0400 Message-Id: <20171003174157.32379-1-kevin@koconnor.net> X-Mailer: git-send-email 2.9.5 X-Spam-Score: -2.5 (--) Subject: [SeaBIOS] [PATCH] xhci: Build TRBs directly in xhci_trb_queue() X-BeenThere: seabios@seabios.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SeaBIOS mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: seabios-bounces@seabios.org Sender: "SeaBIOS" X-Duff: Orig. Duff, Duff Lite, Duff Dry, Duff Dark, Raspberry Duff, Lady Duff, Red Duff, Tartar Control Duff X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Use the logic for building a 'struct xhci_trb' that was in xhci_xfer_queue() up so that command and ring TRBs can also use that functionality. This eliminates the need to manually generate the xhci_trb struct from those code paths. Signed-off-by: Kevin O'Connor --- src/hw/usb-xhci.c | 162 +++++++++++++++++++-------------------------------= ---- 1 file changed, 57 insertions(+), 105 deletions(-) diff --git a/src/hw/usb-xhci.c b/src/hw/usb-xhci.c index 50b3b86..a92a162 100644 --- a/src/hw/usb-xhci.c +++ b/src/hw/usb-xhci.c @@ -641,13 +641,16 @@ xhci_setup(void) * End point communication ****************************************************************/ =20 +// Signal the hardware to process events on a TRB ring static void xhci_doorbell(struct usb_xhci_s *xhci, u32 slotid, u32 value) { + dprintf(5, "%s: slotid %d, epid %d\n", __func__, slotid, value); struct xhci_db *db =3D xhci->db; void *addr =3D &db[slotid].doorbell; writel(addr, value); } =20 +// Dequeue events on the XHCI command ring generated by the hardware static void xhci_process_events(struct usb_xhci_s *xhci) { struct xhci_ring *evts =3D xhci->evts; @@ -712,6 +715,7 @@ static void xhci_process_events(struct usb_xhci_s *xhci) } } =20 +// Check if a ring has any pending TRBs static int xhci_ring_busy(struct xhci_ring *ring) { u32 eidx =3D ring->eidx; @@ -719,6 +723,7 @@ static int xhci_ring_busy(struct xhci_ring *ring) return (eidx !=3D nidx); } =20 +// Wait for a ring to empty (all TRBs processed by hardware) static int xhci_event_wait(struct usb_xhci_s *xhci, struct xhci_ring *ring, u32 timeout) @@ -739,69 +744,54 @@ static int xhci_event_wait(struct usb_xhci_s *xhci, } } =20 -static void xhci_trb_queue(struct xhci_ring *ring, - struct xhci_trb *trb) +// Add a TRB to the given ring +static void xhci_trb_fill(struct xhci_ring *ring + , void *data, u32 xferlen, u32 flags) { - u32 nidx =3D ring->nidx; - u32 cs =3D ring->cs; - struct xhci_trb *dst; - u32 control; - - if (nidx =3D=3D XHCI_RING_ITEMS-1) { - dst =3D ring->ring + nidx; - control =3D (TR_LINK << 10); // trb type - control |=3D TRB_LK_TC; - control |=3D (cs ? TRB_C : 0); - dst->ptr_low =3D (u32)&ring[0]; + struct xhci_trb *dst =3D &ring->ring[ring->nidx]; + if (flags & TRB_TR_IDT) { + memcpy(&dst->ptr_low, data, xferlen); + } else { + dst->ptr_low =3D (u32)data; dst->ptr_high =3D 0; - dst->status =3D 0; - dst->control =3D control; - nidx =3D 0; - cs =3D cs ? 0 : 1; - ring->nidx =3D nidx; - ring->cs =3D cs; + } + dst->status =3D xferlen; + dst->control =3D flags | (ring->cs ? TRB_C : 0); +} =20 +// Queue a TRB onto a ring, wrapping ring as needed +static void xhci_trb_queue(struct xhci_ring *ring, + void *data, u32 xferlen, u32 flags) +{ + if (ring->nidx >=3D ARRAY_SIZE(ring->ring) - 1) { + xhci_trb_fill(ring, ring->ring, 0, (TR_LINK << 10) | TRB_LK_TC); + ring->nidx =3D 0; + ring->cs ^=3D 1; dprintf(5, "%s: ring %p [linked]\n", __func__, ring); } =20 - dst =3D ring->ring + nidx; - control =3D trb->control | (cs ? TRB_C : 0); - - dst->ptr_low =3D trb->ptr_low; - dst->ptr_high =3D trb->ptr_high; - dst->status =3D trb->status; - dst->control =3D control; - nidx++; - ring->nidx =3D nidx; - + xhci_trb_fill(ring, data, xferlen, flags); + ring->nidx++; dprintf(5, "%s: ring %p [nidx %d, len %d]\n", - __func__, ring, nidx, - trb->status & 0xffff); + __func__, ring, ring->nidx, xferlen); } =20 -static int xhci_cmd_submit(struct usb_xhci_s *xhci, - struct xhci_trb *cmd) +// Submit a command to the xhci controller ring +static int xhci_cmd_submit(struct usb_xhci_s *xhci, struct xhci_inctx *inc= tx + , u32 flags) { - int rc; - mutex_lock(&xhci->cmds->lock); - xhci_trb_queue(xhci->cmds, cmd); + xhci_trb_queue(xhci->cmds, inctx, 0, flags); xhci_doorbell(xhci, 0, 0); - rc =3D xhci_event_wait(xhci, xhci->cmds, 1000); + int rc =3D xhci_event_wait(xhci, xhci->cmds, 1000); mutex_unlock(&xhci->cmds->lock); return rc; } =20 static int xhci_cmd_enable_slot(struct usb_xhci_s *xhci) { - struct xhci_trb cmd =3D { - .ptr_low =3D 0, - .ptr_high =3D 0, - .status =3D 0, - .control =3D (CR_ENABLE_SLOT << 10) - }; dprintf(3, "%s:\n", __func__); - int cc =3D xhci_cmd_submit(xhci, &cmd); + int cc =3D xhci_cmd_submit(xhci, NULL, CR_ENABLE_SLOT << 10); if (cc !=3D CC_SUCCESS) return -1; return (xhci->cmds->evt.control >> 24) & 0xff; @@ -809,55 +799,34 @@ static int xhci_cmd_enable_slot(struct usb_xhci_s *xh= ci) =20 static int xhci_cmd_disable_slot(struct usb_xhci_s *xhci, u32 slotid) { - struct xhci_trb cmd =3D { - .ptr_low =3D 0, - .ptr_high =3D 0, - .status =3D 0, - .control =3D (slotid << 24) | (CR_DISABLE_SLOT << 10) - }; dprintf(3, "%s: slotid %d\n", __func__, slotid); - return xhci_cmd_submit(xhci, &cmd); + return xhci_cmd_submit(xhci, NULL, (CR_DISABLE_SLOT << 10) | (slotid <= < 24)); } =20 static int xhci_cmd_address_device(struct usb_xhci_s *xhci, u32 slotid , struct xhci_inctx *inctx) { - struct xhci_trb cmd =3D { - .ptr_low =3D (u32)inctx, - .ptr_high =3D 0, - .status =3D 0, - .control =3D (slotid << 24) | (CR_ADDRESS_DEVICE << 10) - }; dprintf(3, "%s: slotid %d\n", __func__, slotid); - return xhci_cmd_submit(xhci, &cmd); + return xhci_cmd_submit(xhci, inctx + , (CR_ADDRESS_DEVICE << 10) | (slotid << 24)); } =20 static int xhci_cmd_configure_endpoint(struct usb_xhci_s *xhci, u32 slotid , struct xhci_inctx *inctx) { - struct xhci_trb cmd =3D { - .ptr_low =3D (u32)inctx, - .ptr_high =3D 0, - .status =3D 0, - .control =3D (slotid << 24) | (CR_CONFIGURE_ENDPOINT << 10) - }; dprintf(3, "%s: slotid %d, add 0x%x, del 0x%x\n", __func__, slotid, inctx->add, inctx->del); - return xhci_cmd_submit(xhci, &cmd); + return xhci_cmd_submit(xhci, inctx + , (CR_CONFIGURE_ENDPOINT << 10) | (slotid << 24= )); } =20 static int xhci_cmd_evaluate_context(struct usb_xhci_s *xhci, u32 slotid , struct xhci_inctx *inctx) { - struct xhci_trb cmd =3D { - .ptr_low =3D (u32)inctx, - .ptr_high =3D 0, - .status =3D 0, - .control =3D (slotid << 24) | (CR_EVALUATE_CONTEXT << 10) - }; dprintf(3, "%s: slotid %d, add 0x%x, del 0x%x\n", __func__, slotid, inctx->add, inctx->del); - return xhci_cmd_submit(xhci, &cmd); + return xhci_cmd_submit(xhci, inctx + , (CR_EVALUATE_CONTEXT << 10) | (slotid << 24)); } =20 static struct xhci_inctx * @@ -1092,37 +1061,29 @@ xhci_realloc_pipe(struct usbdevice_s *usbdev, struc= t usb_pipe *upipe return upipe; } =20 -static void xhci_xfer_queue(struct xhci_pipe *pipe, - void *data, int datalen, u32 flags) -{ - struct xhci_trb trb; - memset(&trb, 0, sizeof(trb)); - if (flags & TRB_TR_IDT) - memcpy(&trb.ptr_low, data, datalen); - else - trb.ptr_low =3D (u32)data; - trb.status =3D datalen; - trb.control =3D flags; - xhci_trb_queue(&pipe->reqs, &trb); -} - -static void xhci_xfer_kick(struct xhci_pipe *pipe) +static void xhci_xfer_setup(struct xhci_pipe *pipe, int dir, void *cmd + , void *data, int datalen) { struct usb_xhci_s *xhci =3D container_of( pipe->pipe.cntl, struct usb_xhci_s, usb); - u32 slotid =3D pipe->slotid; - u32 epid =3D pipe->epid; - - dprintf(5, "%s: ring %p, slotid %d, epid %d\n", - __func__, &pipe->reqs, slotid, epid); - xhci_doorbell(xhci, slotid, epid); + xhci_trb_queue(&pipe->reqs, cmd, USB_CONTROL_SETUP_SIZE + , (TR_SETUP << 10) | TRB_TR_IDT + | ((datalen ? (dir ? 3 : 2) : 0) << 16)); + if (datalen) + xhci_trb_queue(&pipe->reqs, data, datalen, (TR_DATA << 10) + | ((dir ? 1 : 0) << 16)); + xhci_trb_queue(&pipe->reqs, NULL, 0, (TR_STATUS << 10) | TRB_TR_IOC + | ((dir ? 0 : 1) << 16)); + xhci_doorbell(xhci, pipe->slotid, pipe->epid); } =20 static void xhci_xfer_normal(struct xhci_pipe *pipe, void *data, int datalen) { - xhci_xfer_queue(pipe, data, datalen, (TR_NORMAL << 10) | TRB_TR_IOC); - xhci_xfer_kick(pipe); + struct usb_xhci_s *xhci =3D container_of( + pipe->pipe.cntl, struct usb_xhci_s, usb); + xhci_trb_queue(&pipe->reqs, data, datalen, (TR_NORMAL << 10) | TRB_TR_= IOC); + xhci_doorbell(xhci, pipe->slotid, pipe->epid); } =20 int @@ -1140,16 +1101,7 @@ xhci_send_pipe(struct usb_pipe *p, int dir, const vo= id *cmd if (req->bRequest =3D=3D USB_REQ_SET_ADDRESS) // Set address command sent during xhci_alloc_pipe. return 0; - - xhci_xfer_queue(pipe, (void*)req, USB_CONTROL_SETUP_SIZE - , (TR_SETUP << 10) | TRB_TR_IDT - | ((datalen ? (dir ? 3 : 2) : 0) << 16)); - if (datalen) - xhci_xfer_queue(pipe, data, datalen, (TR_DATA << 10) - | ((dir ? 1 : 0) << 16)); - xhci_xfer_queue(pipe, NULL, 0, (TR_STATUS << 10) | TRB_TR_IOC - | ((dir ? 0 : 1) << 16)); - xhci_xfer_kick(pipe); + xhci_xfer_setup(pipe, dir, (void*)req, data, datalen); } else { xhci_xfer_normal(pipe, data, datalen); } --=20 2.9.5 _______________________________________________ SeaBIOS mailing list SeaBIOS@seabios.org https://mail.coreboot.org/mailman/listinfo/seabios