Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/usb xhci(4): dynamically allocate xhci_xfer->xx_trb ...



details:   https://anonhg.NetBSD.org/src/rev/b4ff16338ad3
branches:  trunk
changeset: 1010289:b4ff16338ad3
user:      jakllsch <jakllsch%NetBSD.org@localhost>
date:      Thu May 21 13:47:10 2020 +0000

description:
xhci(4): dynamically allocate xhci_xfer->xx_trb buffer

Allocation size remains the same for now.

diffstat:

 sys/dev/usb/xhci.c    |  21 +++++++++++++++++----
 sys/dev/usb/xhcivar.h |   5 +++--
 2 files changed, 20 insertions(+), 6 deletions(-)

diffs (88 lines):

diff -r 89065a0c4c04 -r b4ff16338ad3 sys/dev/usb/xhci.c
--- a/sys/dev/usb/xhci.c        Thu May 21 13:23:38 2020 +0000
+++ b/sys/dev/usb/xhci.c        Thu May 21 13:47:10 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: xhci.c,v 1.127 2020/05/21 13:23:38 jakllsch Exp $      */
+/*     $NetBSD: xhci.c,v 1.128 2020/05/21 13:47:10 jakllsch Exp $      */
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.127 2020/05/21 13:23:38 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.128 2020/05/21 13:47:10 jakllsch Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -520,7 +520,7 @@
 xhci_xfer_put_trb(struct xhci_xfer * const xx, u_int idx,
     uint64_t parameter, uint32_t status, uint32_t control)
 {
-       KASSERTMSG(idx < XHCI_XFER_NTRB, "idx=%u", idx);
+       KASSERTMSG(idx < xx->xx_ntrb, "idx=%u xx_ntrb=%u", idx, xx->xx_ntrb);
        xx->xx_trb[idx].trb_0 = parameter;
        xx->xx_trb[idx].trb_2 = status;
        xx->xx_trb[idx].trb_3 = control;
@@ -2241,12 +2241,20 @@
 {
        struct xhci_softc * const sc = XHCI_BUS2SC(bus);
        struct xhci_xfer *xx;
+       u_int ntrbs;
 
        XHCIHIST_FUNC(); XHCIHIST_CALLED();
 
+       ntrbs = XHCI_XFER_NTRB;
+       const size_t trbsz = sizeof(*xx->xx_trb) * ntrbs;
+
        xx = pool_cache_get(sc->sc_xferpool, PR_WAITOK);
        if (xx != NULL) {
                memset(xx, 0, sizeof(*xx));
+               if (ntrbs > 0) {
+                       xx->xx_trb = kmem_alloc(trbsz, KM_SLEEP);
+                       xx->xx_ntrb = ntrbs;
+               }
 #ifdef DIAGNOSTIC
                xx->xx_xfer.ux_state = XFER_BUSY;
 #endif
@@ -2271,6 +2279,11 @@
        }
        xfer->ux_state = XFER_FREE;
 #endif
+       if (xx->xx_ntrb > 0) {
+               kmem_free(xx->xx_trb, xx->xx_ntrb * sizeof(*xx->xx_trb));
+               xx->xx_trb = NULL;
+               xx->xx_ntrb = 0;
+       }
        pool_cache_put(sc->sc_xferpool, xx);
 }
 
@@ -2675,7 +2688,7 @@
 xhci_ring_put_xfer(struct xhci_softc * const sc, struct xhci_ring * const tr,
     struct xhci_xfer *xx, u_int ntrb)
 {
-       KASSERT(ntrb <= XHCI_XFER_NTRB);
+       KASSERT(ntrb <= xx->xx_ntrb);
        xhci_ring_put(sc, tr, xx, xx->xx_trb, ntrb);
 }
 
diff -r 89065a0c4c04 -r b4ff16338ad3 sys/dev/usb/xhcivar.h
--- a/sys/dev/usb/xhcivar.h     Thu May 21 13:23:38 2020 +0000
+++ b/sys/dev/usb/xhcivar.h     Thu May 21 13:47:10 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: xhcivar.h,v 1.14 2020/05/19 18:18:33 jakllsch Exp $    */
+/*     $NetBSD: xhcivar.h,v 1.15 2020/05/21 13:47:10 jakllsch Exp $    */
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -42,7 +42,8 @@
 
 struct xhci_xfer {
        struct usbd_xfer xx_xfer;
-       struct xhci_soft_trb xx_trb[XHCI_XFER_NTRB];
+       struct xhci_soft_trb *xx_trb;
+       u_int xx_ntrb;
 };
 
 #define XHCI_BUS2SC(bus)       ((bus)->ub_hcpriv)



Home | Main Index | Thread Index | Old Index