Module Name:    src
Committed By:   skrll
Date:           Mon Jun  1 10:25:01 UTC 2020

Modified Files:
        src/sys/dev/usb: xhci.c xhcireg.h

Log Message:
Remove some unnecessary bit shifts by using appropriate read size


To generate a diff of this commit:
cvs rdiff -u -r1.129 -r1.130 src/sys/dev/usb/xhci.c
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/usb/xhcireg.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/usb/xhci.c
diff -u src/sys/dev/usb/xhci.c:1.129 src/sys/dev/usb/xhci.c:1.130
--- src/sys/dev/usb/xhci.c:1.129	Thu May 21 15:28:35 2020
+++ src/sys/dev/usb/xhci.c	Mon Jun  1 10:25:00 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: xhci.c,v 1.129 2020/05/21 15:28:35 jakllsch Exp $	*/
+/*	$NetBSD: xhci.c,v 1.130 2020/06/01 10:25:00 skrll Exp $	*/
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.129 2020/05/21 15:28:35 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.130 2020/06/01 10:25:00 skrll Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -272,6 +272,12 @@ xhci_read_1(const struct xhci_softc * co
 }
 
 static inline uint32_t
+xhci_read_2(const struct xhci_softc * const sc, bus_size_t offset)
+{
+	return bus_space_read_2(sc->sc_iot, sc->sc_ioh, offset);
+}
+
+static inline uint32_t
 xhci_read_4(const struct xhci_softc * const sc, bus_size_t offset)
 {
 	return bus_space_read_4(sc->sc_iot, sc->sc_ioh, offset);
@@ -938,7 +944,7 @@ int
 xhci_init(struct xhci_softc *sc)
 {
 	bus_size_t bsz;
-	uint32_t cap, hcs1, hcs2, hcs3, hcc, dboff, rtsoff, hcc2;
+	uint32_t hcs1, hcs2, hcs3, hcc, dboff, rtsoff, hcc2;
 	uint32_t pagesize, config;
 	int i = 0;
 	uint16_t hciversion;
@@ -959,9 +965,8 @@ xhci_init(struct xhci_softc *sc)
 	sc->sc_bus2.ub_hcpriv = sc;
 	sc->sc_bus2.ub_dmatag = sc->sc_bus.ub_dmatag;
 
-	cap = xhci_read_4(sc, XHCI_CAPLENGTH);
-	caplength = XHCI_CAP_CAPLENGTH(cap);
-	hciversion = XHCI_CAP_HCIVERSION(cap);
+	caplength = xhci_read_1(sc, XHCI_CAPLENGTH);
+	hciversion = xhci_read_2(sc, XHCI_HCIVERSION);
 
 	if (hciversion < XHCI_HCIVERSION_0_96 ||
 	    hciversion >= 0x0200) {

Index: src/sys/dev/usb/xhcireg.h
diff -u src/sys/dev/usb/xhcireg.h:1.14 src/sys/dev/usb/xhcireg.h:1.15
--- src/sys/dev/usb/xhcireg.h:1.14	Fri May 29 06:53:40 2020
+++ src/sys/dev/usb/xhcireg.h	Mon Jun  1 10:25:00 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: xhcireg.h,v 1.14 2020/05/29 06:53:40 skrll Exp $ */
+/* $NetBSD: xhcireg.h,v 1.15 2020/06/01 10:25:00 skrll Exp $ */
 
 /*-
  * Copyright (c) 2010 Hans Petter Selasky. All rights reserved.
@@ -45,9 +45,8 @@
 #define	PCI_XHCI_INTEL_USB3PRM	0xdc    /* Intel USB3 Port Routing Mask */
 
 /* XHCI capability registers */
-#define	XHCI_CAPLENGTH		0x00	/* RO capability */
-#define	 XHCI_CAP_CAPLENGTH(x)	((x) & 0xFF)
-#define	 XHCI_CAP_HCIVERSION(x)	(((x) >> 16) & 0xFFFF)	/* RO Interface version number */
+#define	XHCI_CAPLENGTH		0x00	/* RO capability - 1 byte */
+#define	XHCI_HCIVERSION		0x02	/* RO version - 2 bytes */
 #define	 XHCI_HCIVERSION_0_9	0x0090	/* xHCI version 0.9 */
 #define	 XHCI_HCIVERSION_0_96	0x0096	/* xHCI version 0.96 */
 #define	 XHCI_HCIVERSION_1_0	0x0100	/* xHCI version 1.0 */

Reply via email to