Source-Changes-HG archive

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

[src/trunk]: src/sys coalesce the two copies of hexdump into libkern



details:   https://anonhg.NetBSD.org/src/rev/f04f31e41116
branches:  trunk
changeset: 358033:f04f31e41116
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Dec 08 21:51:07 2017 +0000

description:
coalesce the two copies of hexdump into libkern

diffstat:

 sys/dev/pcmcia/if_ray.c          |  111 ++------------------------------------
 sys/dev/usb/xhci.c               |   62 +++++++--------------
 sys/lib/libkern/Makefile.libkern |    4 +-
 sys/lib/libkern/hexdump.c        |   69 ++++++++++++++++++++++++
 sys/lib/libkern/libkern.h        |    3 +-
 5 files changed, 101 insertions(+), 148 deletions(-)

diffs (truncated from 430 to 300 lines):

diff -r 96fce9f8274d -r f04f31e41116 sys/dev/pcmcia/if_ray.c
--- a/sys/dev/pcmcia/if_ray.c   Fri Dec 08 17:49:54 2017 +0000
+++ b/sys/dev/pcmcia/if_ray.c   Fri Dec 08 21:51:07 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_ray.c,v 1.86 2017/01/13 14:48:18 maya Exp $ */
+/*     $NetBSD: if_ray.c,v 1.87 2017/12/08 21:51:07 christos Exp $     */
 
 /*
  * Copyright (c) 2000 Christian E. Hopps
@@ -57,7 +57,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ray.c,v 1.86 2017/01/13 14:48:18 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ray.c,v 1.87 2017/12/08 21:51:07 christos Exp $");
 
 #include "opt_inet.h"
 
@@ -368,10 +368,6 @@
        printf x ;                              \
        } } while (0)
 
-#define        HEXDF_NOCOMPRESS        0x1
-#define        HEXDF_NOOFFSET          0x2
-#define HEXDF_NOASCII          0x4
-void hexdump(const u_int8_t *, int, int, int, int);
 static void ray_dump_mbuf(struct ray_softc *, struct mbuf *);
 
 #else  /* !RAY_DEBUG */
@@ -1295,7 +1291,7 @@
 #ifdef RAY_DEBUG
        /* have a look if you want to see how the card rx works :) */
        if (ray_debug && ray_debug_dump_desc)
-               hexdump((char *)sc->sc_memh + RAY_RCS_BASE, 0x400, 16, 4, 0);
+               hexdump(__func__, (char *)sc->sc_memh + RAY_RCS_BASE, 0x400);
 #endif
 
        m = 0;
@@ -1448,7 +1444,7 @@
                        RAY_DPRINTF(("%s: mgt packet not supported\n",
                            device_xname(sc->sc_dev)));
 #ifdef RAY_DEBUG
-                       hexdump((const u_int8_t*)frame, pktlen, 16, 4, 0);
+                       hexdump(__func__, (const u_int8_t*)frame, pktlen);
 #endif
                        RAY_DPRINTF(("\n"));
                        break;
@@ -1537,7 +1533,7 @@
                RAY_DPRINTF(("%s: recv auth packet:\n",
                    device_xname(sc->sc_dev)));
 #ifdef RAY_DEBUG
-               hexdump((const u_int8_t *)frame, sizeof(*frame) + 6, 16, 4, 0);
+               hexdump(__func__, (const u_int8_t *)frame, sizeof(*frame) + 6);
 #endif
                RAY_DPRINTF(("\n"));
 
@@ -3067,108 +3063,13 @@
 
 #ifdef RAY_DEBUG
 
-#define PRINTABLE(c) ((c) >= 0x20 && (c) <= 0x7f)
-
-void
-hexdump(const u_int8_t *d, int len, int br, int div, int fl)
-{
-       int i, j, offw, first, tlen, ni, nj, sp;
-
-       sp = br / div;
-       offw = 0;
-       if (len && (fl & HEXDF_NOOFFSET) == 0) {
-               tlen = len;
-               do {
-                       offw++;
-               } while (tlen /= br);
-       }
-       if (offw)
-               printf("%0*x: ", offw, 0);
-       for (i = 0; i < len; i++, d++) {
-               if (i && (i % br) == 0) {
-                       if ((fl & HEXDF_NOASCII) == 0) {
-                               printf("   ");
-                               d -= br;
-                               for (j = 0; j < br; d++, j++) {
-                                       if (j && (j % sp) == 0)
-                                               printf(" ");
-                                       if (PRINTABLE(*d))
-                                               printf("%c", (int)*d);
-                                       else
-                                               printf(".");
-                               }
-                       }
-                       if (offw)
-                               printf("\n%0*x: ", offw, i);
-                       else
-                               printf("\n");
-                       if ((fl & HEXDF_NOCOMPRESS) == 0) {
-                               first = 1;
-                               while (len - i >= br) {
-                                       if (memcmp(d, d - br, br))
-                                               break;
-                                       d += br;
-                                       i += br;
-                                       if (first) {
-                                               printf("*");
-                                               first = 0;
-                                       }
-                               }
-                               if (len == i) {
-                                       printf("\n%0*x", offw, i);
-                                       return;
-                               }
-                       }
-               } else if (i && (i % sp) == 0)
-                       printf(" ");
-               printf("%02x ", *d);
-       }
-       if (len && (((i - 1) % br) || i == 1)) {
-               if ((fl & HEXDF_NOASCII) == 0) {
-                       i = i % br ? i % br : br;
-                       ni = (br - i) % br;
-                       j = (i - 1) / sp;
-                       nj = (div - j - 1) % div;
-                       j = 3 * ni + nj + 3;
-                       printf("%*s", j, "");
-                       d -= i;
-                       for (j = 0; j < i; d++, j++) {
-                               if (j && (j % sp) == 0)
-                                       printf(" ");
-                               if (PRINTABLE(*d))
-                                       printf("%c", (int)*d);
-                               else
-                                       printf(".");
-                       }
-               }
-               printf("\n");
-       }
-}
-
-
-
 static void
 ray_dump_mbuf(struct ray_softc *sc, struct mbuf *m)
 {
-       u_int8_t *d, *ed;
-       u_int i;
-
        printf("%s: pkt dump:", device_xname(sc->sc_dev));
-       i = 0;
        for (; m; m = m->m_next) {
-               d = mtod(m, u_int8_t *);
-               ed = d + m->m_len;
-
-               for (; d < ed; i++, d++) {
-                       if ((i % 16) == 0)
-                               printf("\n\t");
-                       else if ((i % 8) == 0)
-                               printf("  ");
-                       printf(" %02x", *d);
-               }
+               hexdump(NULL, mtod(m, void *), m->m_len);
        }
-       if ((i - 1) % 16)
-               printf("\n");
 }
 #endif /* RAY_DEBUG */
 
diff -r 96fce9f8274d -r f04f31e41116 sys/dev/usb/xhci.c
--- a/sys/dev/usb/xhci.c        Fri Dec 08 17:49:54 2017 +0000
+++ b/sys/dev/usb/xhci.c        Fri Dec 08 21:51:07 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: xhci.c,v 1.78 2017/12/07 22:56:23 christos Exp $       */
+/*     $NetBSD: xhci.c,v 1.79 2017/12/08 21:51:07 christos Exp $       */
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.78 2017/12/07 22:56:23 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.79 2017/12/08 21:51:07 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -73,6 +73,11 @@
 #ifndef XHCI_DEBUG
 #define xhcidebug 0
 #else /* !XHCI_DEBUG */
+#define HEXDUMP(a, b, c) \
+    do { \
+           if (xhcidebug > 0) \
+                   hexdump(a, b, c); \
+    } while (/*CONSTCOND*/0)
 static int xhcidebug = 0;
 
 SYSCTL_SETUP(sysctl_hw_xhci_setup, "sysctl hw.xhci setup")
@@ -105,6 +110,10 @@
 #endif /* !XHCI_DEBUG */
 #endif /* USB_DEBUG */
 
+#ifndef HEXDUMP
+#define HEXDUMP(a, b, c)
+#endif
+
 #define DPRINTFN(N,FMT,A,B,C,D) USBHIST_LOGN(xhcidebug,N,FMT,A,B,C,D)
 #define XHCIHIST_FUNC() USBHIST_FUNC()
 #define XHCIHIST_CALLED(name) USBHIST_CALLED(xhcidebug)
@@ -720,35 +729,6 @@
 }
 
 
-static void
-hexdump(const char *msg, const void *base, size_t len)
-{
-#if 0
-       size_t cnt;
-       const uint32_t *p;
-       extern paddr_t vtophys(vaddr_t);
-
-       p = base;
-       cnt = 0;
-
-       printf("*** %s (%zu bytes @ %p %p)\n", msg, len, base,
-           (void *)vtophys((vaddr_t)base));
-
-       while (cnt < len) {
-               if (cnt % 16 == 0)
-                       printf("%p: ", p);
-               else if (cnt % 8 == 0)
-                       printf(" |");
-               printf(" %08x", *p++);
-               cnt += 4;
-               if (cnt % 16 == 0)
-                       printf("\n");
-       }
-       if (cnt % 16 != 0)
-               printf("\n");
-#endif
-}
-
 /* 7.2 xHCI Support Protocol Capability */
 static void
 xhci_id_protocols(struct xhci_softc *sc, bus_size_t ecp)
@@ -1184,10 +1164,8 @@
        xhci_op_write_8(sc, XHCI_CRCR, xhci_ring_trbp(&sc->sc_cr, 0) |
            sc->sc_cr.xr_cs);
 
-#if 0
-       hexdump("eventst", KERNADDR(&sc->sc_eventst_dma, 0),
+       HEXDUMP("eventst", KERNADDR(&sc->sc_eventst_dma, 0),
            XHCI_ERSTE_SIZE * XHCI_EVENT_RING_SEGMENTS);
-#endif
 
        if ((sc->sc_quirks & XHCI_DEFERRED_START) == 0)
                xhci_start(sc);
@@ -1363,7 +1341,9 @@
 {
        struct xhci_softc * const sc = XHCI_PIPE2SC(pipe);
        struct xhci_slot * const xs = pipe->up_dev->ud_hcpriv;
+#ifdef XHCI_DEBUG
        const u_int dci = xhci_ep_get_dci(pipe->up_endpoint->ue_edesc);
+#endif
        struct xhci_trb trb;
        usbd_status err;
 
@@ -1379,9 +1359,9 @@
        /* set up context */
        xhci_setup_ctx(pipe);
 
-       hexdump("input control context", xhci_slot_get_icv(sc, xs, 0),
+       HEXDUMP("input control context", xhci_slot_get_icv(sc, xs, 0),
            sc->sc_ctxsz * 1);
-       hexdump("input endpoint context", xhci_slot_get_icv(sc, xs,
+       HEXDUMP("input endpoint context", xhci_slot_get_icv(sc, xs,
            xhci_dci_to_ici(dci)), sc->sc_ctxsz * 1);
 
        trb.trb_0 = xhci_slot_get_icp(sc, xs, 0);
@@ -1392,7 +1372,7 @@
        err = xhci_do_command(sc, &trb, USBD_DEFAULT_TIMEOUT);
 
        usb_syncmem(&xs->xs_dc_dma, 0, sc->sc_pgsz, BUS_DMASYNC_POSTREAD);
-       hexdump("output context", xhci_slot_get_dcv(sc, xs, dci),
+       HEXDUMP("output context", xhci_slot_get_dcv(sc, xs, dci),
            sc->sc_ctxsz * 1);
 
        return err;
@@ -2363,7 +2343,7 @@
                usbd_delay_ms(dev, USB_SET_ADDRESS_SETTLE);
 
                cp = xhci_slot_get_dcv(sc, xs, XHCI_DCI_SLOT);
-               //hexdump("slot context", cp, sc->sc_ctxsz);
+               HEXDUMP("slot context", cp, sc->sc_ctxsz);
                uint8_t addr = XHCI_SCTX_3_DEV_ADDR_GET(le32toh(cp[3]));
                DPRINTFN(4, "device address %ju", addr, 0, 0, 0);
                /*
@@ -2821,7 +2801,7 @@
 
        /* sync input contexts before they are read from memory */
        usb_syncmem(&xs->xs_ic_dma, 0, sc->sc_pgsz, BUS_DMASYNC_PREWRITE);
-       hexdump("input context", xhci_slot_get_icv(sc, xs, 0),



Home | Main Index | Thread Index | Old Index