Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 4 Aug 2008 15:49:37 GMT
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 146633 for review
Message-ID:  <200808041549.m74FnbVH069661@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=146633

Change 146633 by hselasky@hselasky_laptop001 on 2008/08/04 15:49:33

	
	Various changes to support more compilers and
	to allow easier porting of the code to other
	platforms.

Affected files ...

.. //depot/projects/usb/src/sys/dev/usb2/controller/musb2_otg.c#2 edit
.. //depot/projects/usb/src/sys/dev/usb2/controller/ohci2.c#6 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_compat_linux.h#4 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_config_td.c#5 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_core.h#13 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_dev.c#19 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_device.c#16 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_device.h#6 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_handle_request.c#5 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_hid.c#4 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_hid.h#5 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_hub.c#13 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_process.h#2 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_request.c#11 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_transfer.c#15 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_util.c#3 edit
.. //depot/projects/usb/src/sys/dev/usb2/core/usb2_util.h#3 edit

Differences ...

==== //depot/projects/usb/src/sys/dev/usb2/controller/musb2_otg.c#2 (text+ko) ====

@@ -1305,7 +1305,7 @@
 static void
 musbotg_device_done(struct usb2_xfer *xfer, usb2_error_t error)
 {
-	mtx_assert(&sc->sc_bus.mtx, MA_OWNED);
+	mtx_assert(xfer->usb2_mtx, MA_OWNED);
 
 	DPRINTFN(2, "xfer=%p, pipe=%p, error=%d\n",
 	    xfer, xfer->pipe, error);

==== //depot/projects/usb/src/sys/dev/usb2/controller/ohci2.c#6 (text+ko) ====

@@ -629,7 +629,7 @@
 	    le32toh(sitd->itd_be));
 	for (i = 0; i < OHCI_ITD_NOFFSET; i++) {
 		printf("offs[%d]=0x%04x ", i,
-		    (u_int)le16toh(sitd->itd_offset[i]));
+		    (uint32_t)le16toh(sitd->itd_offset[i]));
 	}
 	printf("\n");
 

==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_compat_linux.h#4 (text+ko) ====

@@ -429,7 +429,7 @@
 	uint8_t	transfer_dma;		/* (in) not used on FreeBSD */
 	uint8_t	bsd_isread;
 
-	struct usb_iso_packet_descriptor iso_frame_desc[0];	/* (in) ISO ONLY */
+	struct usb_iso_packet_descriptor iso_frame_desc[];	/* (in) ISO ONLY */
 };
 
 /* various prototypes */

==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_config_td.c#5 (text+ko) ====

@@ -261,15 +261,19 @@
 	}
 	if (timeout == 0) {
 		/*
-		 * zero means no timeout, so avoid that by setting
+		 * Zero means no timeout, so avoid that by setting
 		 * timeout to one:
 		 */
 		timeout = 1;
 	}
-	if (mtx_sleep(ctd, ctd->usb2_proc.up_mtx, 0,
-	    "DELAY", timeout)) {
+	mtx_unlock(ctd->usb2_proc.up_mtx);
+
+	if (pause("USBWAIT", timeout)) {
 		/* ignore */
 	}
+	mtx_lock(ctd->usb2_proc.up_mtx);
+
+	is_gone = usb2_config_td_is_gone(ctd);
 done:
 	return (is_gone);
 }

==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_core.h#13 (text+ko) ====

@@ -31,6 +31,18 @@
 #ifndef _USB2_CORE_H_
 #define	_USB2_CORE_H_
 
+/* Default USB configuration */
+
+#ifndef USB_NO_POLL
+#define	USB_NO_POLL 0
+#endif
+
+#ifndef USB_USE_CONDVAR
+#define	USB_USE_CONDVAR 0
+#endif
+
+/* Include files */
+
 #include <sys/stdint.h>
 #include <sys/stddef.h>
 #include <sys/param.h>
@@ -55,9 +67,7 @@
 #include <dev/usb2/include/usb2_revision.h>
 
 #include "usb2_if.h"
-
 #include "opt_usb.h"
-
 #include "opt_bus.h"
 
 #define	USB_STACK_VERSION 2000		/* 2.0 */

==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_dev.c#19 (text+ko) ====

@@ -1552,7 +1552,7 @@
 			tr_data = 1;
 		}
 
-		io_len = min(m->cur_data_len, uio->uio_resid);
+		io_len = MIN(m->cur_data_len, uio->uio_resid);
 
 		DPRINTFN(2, "transfer %d bytes from %p\n",
 		    io_len, m->cur_data_ptr);
@@ -1684,7 +1684,7 @@
 
 		USB_MBUF_RESET(m);
 
-		io_len = min(m->cur_data_len, uio->uio_resid);
+		io_len = MIN(m->cur_data_len, uio->uio_resid);
 
 		m->cur_data_len = io_len;
 
@@ -2103,7 +2103,7 @@
 		if (m) {
 			USB_MBUF_RESET(m);
 
-			io_len = min(len, m->cur_data_len);
+			io_len = MIN(len, m->cur_data_len);
 
 			usb2_copy_out(pc, offset, m->cur_data_ptr, io_len);
 
@@ -2142,7 +2142,7 @@
 		if (m) {
 			USB_MBUF_RESET(m);
 
-			io_len = min(len, m->cur_data_len);
+			io_len = MIN(len, m->cur_data_len);
 
 			bcopy(ptr, m->cur_data_ptr, io_len);
 
@@ -2205,7 +2205,7 @@
 
 			tr_data = 1;
 
-			io_len = min(len, m->cur_data_len);
+			io_len = MIN(len, m->cur_data_len);
 
 			usb2_copy_in(pc, offset, m->cur_data_ptr, io_len);
 
@@ -2263,7 +2263,7 @@
 
 			tr_data = 1;
 
-			io_len = min(len, m->cur_data_len);
+			io_len = MIN(len, m->cur_data_len);
 
 			bcopy(m->cur_data_ptr, ptr, io_len);
 

==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_device.c#16 (text+ko) ====

@@ -96,7 +96,7 @@
 usb2_get_pipe_by_addr(struct usb2_device *udev, uint8_t ea_val)
 {
 	struct usb2_pipe *pipe = udev->pipes;
-	struct usb2_pipe *pipe_end = udev->pipes_end;
+	struct usb2_pipe *pipe_end = udev->pipes + USB_EP_MAX;
 	enum {
 		EA_MASK = (UE_DIR_IN | UE_DIR_OUT | UE_ADDR),
 	};
@@ -151,7 +151,7 @@
     const struct usb2_config *setup)
 {
 	struct usb2_pipe *pipe = udev->pipes;
-	struct usb2_pipe *pipe_end = udev->pipes_end;
+	struct usb2_pipe *pipe_end = udev->pipes + USB_EP_MAX;
 	uint8_t index = setup->ep_index;
 	uint8_t ea_mask;
 	uint8_t ea_val;
@@ -311,7 +311,7 @@
     uint8_t iface_index, uint8_t iface_mask)
 {
 	struct usb2_pipe *pipe = udev->pipes;
-	struct usb2_pipe *pipe_end = udev->pipes_end;
+	struct usb2_pipe *pipe_end = udev->pipes + USB_EP_MAX;
 
 	while (pipe != pipe_end) {
 		if ((pipe->iface_index & iface_mask) == iface_index) {
@@ -337,7 +337,7 @@
 {
 	struct usb2_interface *iface = usb2_get_iface(udev, iface_index);
 	struct usb2_pipe *pipe = udev->pipes;
-	struct usb2_pipe *pipe_end = udev->pipes_end;
+	struct usb2_pipe *pipe_end = udev->pipes + USB_EP_MAX;
 	struct usb2_interface_descriptor *id;
 	struct usb2_endpoint_descriptor *ed = NULL;
 	struct usb2_descriptor *desc;
@@ -446,7 +446,7 @@
 usb2_free_iface_data(struct usb2_device *udev)
 {
 	struct usb2_interface *iface = udev->ifaces;
-	struct usb2_interface *iface_end = udev->ifaces_end;
+	struct usb2_interface *iface_end = udev->ifaces + USB_IFACE_MAX;
 	uint8_t n;
 
 	/* mtx_assert() */
@@ -786,7 +786,7 @@
 	usb2_error_t err;
 
 	pipe = udev->pipes;
-	pipe_end = udev->pipes_end;
+	pipe_end = udev->pipes + USB_EP_MAX;
 
 	for (; pipe != pipe_end; pipe++) {
 
@@ -1491,7 +1491,7 @@
 	    udev->ddesc.iSerialNumber) {
 		/* read out the language ID string */
 		err = usb2_req_get_string_desc(udev, &Giant,
-		    scratch_ptr, 4, scratch_size,
+		    (char *)scratch_ptr, 4, scratch_size,
 		    USB_LANGUAGE_TABLE);
 	} else {
 		err = USB_ERR_INVAL;
@@ -1509,24 +1509,24 @@
 
 	/* get serial number string */
 	err = usb2_req_get_string_any
-	    (udev, &Giant, scratch_ptr,
+	    (udev, &Giant, (char *)scratch_ptr,
 	    scratch_size, udev->ddesc.iSerialNumber);
 
-	strlcpy(udev->serial, scratch_ptr, sizeof(udev->serial));
+	strlcpy(udev->serial, (char *)scratch_ptr, sizeof(udev->serial));
 
 	/* get manufacturer string */
 	err = usb2_req_get_string_any
-	    (udev, &Giant, scratch_ptr,
+	    (udev, &Giant, (char *)scratch_ptr,
 	    scratch_size, udev->ddesc.iManufacturer);
 
-	strlcpy(udev->manufacturer, scratch_ptr, sizeof(udev->manufacturer));
+	strlcpy(udev->manufacturer, (char *)scratch_ptr, sizeof(udev->manufacturer));
 
 	/* get product string */
 	err = usb2_req_get_string_any
-	    (udev, &Giant, scratch_ptr,
+	    (udev, &Giant, (char *)scratch_ptr,
 	    scratch_size, udev->ddesc.iProduct);
 
-	strlcpy(udev->product, scratch_ptr, sizeof(udev->product));
+	strlcpy(udev->product, (char *)scratch_ptr, sizeof(udev->product));
 
 	/* finish up all the strings */
 	usb2_check_strings(udev);
@@ -1608,14 +1608,14 @@
 	    parent_hub->hub->ports + port_index : NULL, udev, device_index);
 
 	/* make a symlink for UGEN */
-	if (snprintf(scratch_ptr, scratch_size,
+	if (snprintf((char *)scratch_ptr, scratch_size,
 	    USB_DEVICE_NAME "%u.%u.0.0",
 	    device_get_unit(udev->bus->bdev),
 	    udev->device_index)) {
 		/* ignore */
 	}
 	udev->ugen_symlink =
-	    usb2_alloc_symlink(scratch_ptr, "ugen%u.%u",
+	    usb2_alloc_symlink((char *)scratch_ptr, "ugen%u.%u",
 	    device_get_unit(udev->bus->bdev),
 	    udev->device_index);
 
@@ -1720,7 +1720,7 @@
 	struct usb2_interface *iface = udev->ifaces + iface_index;
 
 	if ((iface < udev->ifaces) ||
-	    (iface >= udev->ifaces_end) ||
+	    (iface_index >= USB_IFACE_MAX) ||
 	    (udev->cdesc == NULL) ||
 	    (iface_index >= udev->cdesc->bNumInterface)) {
 		return (NULL);

==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_device.h#6 (text+ko) ====

@@ -92,13 +92,9 @@
 	struct sx default_sx[2];
 	struct mtx default_mtx[1];
 	struct cv default_cv[2];
-
 	struct usb2_interface ifaces[USB_IFACE_MAX];
-	struct usb2_interface ifaces_end[0];
-
 	struct usb2_pipe default_pipe;	/* Control Endpoint 0 */
 	struct usb2_pipe pipes[USB_EP_MAX];
-	struct usb2_pipe pipes_end[0];
 
 	struct usb2_bus *bus;		/* our USB BUS */
 	device_t parent_dev;		/* parent device */

==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_handle_request.c#5 (text+ko) ====

@@ -207,6 +207,9 @@
 	    (error != ENOTTY) &&
 	    (iface->subdev != NULL) &&
 	    device_is_attached(iface->subdev)) {
+#if 0
+		DEVMETHOD(usb2_handle_request, NULL);	/* dummy */
+#endif
 		error = USB2_HANDLE_REQUEST(iface->subdev,
 		    &req, ppdata, plen,
 		    off, (state == ST_POST_STATUS));

==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_hid.c#4 (text+ko) ====

@@ -60,9 +60,9 @@
 
 #define	MAXUSAGE 100
 struct hid_data {
-	const u_char *start;
-	const u_char *end;
-	const u_char *p;
+	const uint8_t *start;
+	const uint8_t *end;
+	const uint8_t *p;
 	struct hid_item cur;
 	int32_t	usages[MAXUSAGE];
 	int	nu;
@@ -101,7 +101,7 @@
 
 	s = malloc(sizeof *s, M_TEMP, M_WAITOK | M_ZERO);
 	s->start = s->p = d;
-	s->end = ((const char *)d) + len;
+	s->end = ((const uint8_t *)d) + len;
 	s->kindset = kindset;
 	return (s);
 }
@@ -131,16 +131,16 @@
 	struct hid_item *c = &s->cur;
 	unsigned int bTag, bType, bSize;
 	uint32_t oldpos;
-	const u_char *data;
+	const uint8_t *data;
 	int32_t dval;
-	const u_char *p;
+	const uint8_t *p;
 	struct hid_item *hi;
 	int i;
 
 top:
 	if (s->multimax != 0) {
 		if (s->multi < s->multimax) {
-			c->usage = s->usages[min(s->multi, s->nu - 1)];
+			c->usage = s->usages[MIN(s->multi, s->nu - 1)];
 			s->multi++;
 			*h = *c;
 			c->loc.pos += c->loc.size;
@@ -435,11 +435,11 @@
 /*------------------------------------------------------------------------*
  *	hid_get_data
  *------------------------------------------------------------------------*/
-u_long
-hid_get_data(const u_char *buf, uint32_t len, struct hid_location *loc)
+uint32_t
+hid_get_data(const uint8_t *buf, uint32_t len, struct hid_location *loc)
 {
-	u_int hpos = loc->pos;
-	u_int hsize = loc->size;
+	uint32_t hpos = loc->pos;
+	uint32_t hsize = loc->size;
 	uint32_t data;
 	int i, s, t;
 

==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_hid.h#5 (text+ko) ====

@@ -80,7 +80,7 @@
 int	hid_get_item(struct hid_data *s, struct hid_item *h);
 int	hid_report_size(const void *buf, int len, enum hid_kind k, uint8_t *id);
 int	hid_locate(const void *desc, int size, uint32_t usage, enum hid_kind kind, struct hid_location *loc, uint32_t *flags);
-u_long	hid_get_data(const u_char *buf, uint32_t len, struct hid_location *loc);
+uint32_t hid_get_data(const uint8_t *buf, uint32_t len, struct hid_location *loc);
 int	hid_is_collection(const void *desc, int size, uint32_t usage);
 struct usb2_hid_descriptor *hid_get_descriptor_from_usb(struct usb2_config_descriptor *cd, struct usb2_interface_descriptor *id);
 usb2_error_t usb2_req_get_hid_desc(struct usb2_device *udev, struct mtx *mtx, void **descp, uint16_t *sizep, usb2_malloc_type mem, uint8_t iface_index);

==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_hub.c#13 (text+ko) ====

@@ -72,7 +72,7 @@
 	struct usb2_xfer *sc_xfer[2];	/* interrupt xfer */
 	uint8_t	sc_flags;
 #define	UHUB_FLAG_INTR_STALL 0x02
-	uint8_t	sc_name[32];
+	char	sc_name[32];
 };
 
 #define	UHUB_PROTO(sc) ((sc)->sc_udev->ddesc.bDeviceProtocol)

==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_process.h#2 (text+ko) ====

@@ -1,4 +1,4 @@
-/*
+/*-
  * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without

==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_request.c#11 (text+ko) ====

@@ -102,7 +102,7 @@
 	/* round robin pipe clear stall */
 
 	pipe = xfer->udev->pipe_curr;
-	pipe_end = xfer->udev->pipes_end;
+	pipe_end = xfer->udev->pipes + USB_EP_MAX;
 	pipe_first = xfer->udev->pipes;
 	if (pipe == NULL) {
 		pipe = pipe_first;
@@ -665,7 +665,7 @@
 	if (err) {
 		return (err);
 	}
-	temp = buf;
+	temp = (uint8_t *)buf;
 
 	if (temp[0] < 2) {
 		/* string length is too short */

==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_transfer.c#15 (text+ko) ====

@@ -72,14 +72,14 @@
 	},
 
 	[UE_BULK] = {
-		[USB_SPEED_LOW] = {},	/* invalid (all zero) */
+		[USB_SPEED_LOW] = {.fixed = {0, 0, 0, 0}},	/* invalid */
 		[USB_SPEED_FULL] = {.fixed = {8, 16, 32, 64}},
 		[USB_SPEED_HIGH] = {.fixed = {512, 512, 512, 512}},
 		[USB_SPEED_VARIABLE] = {.fixed = {512, 512, 1024, 1536}},
 	},
 
 	[UE_ISOCHRONOUS] = {
-		[USB_SPEED_LOW] = {},	/* invalid (all zero) */
+		[USB_SPEED_LOW] = {.fixed = {0, 0, 0, 0}},	/* invalid */
 		[USB_SPEED_FULL] = {.range = {0, 1023}},
 		[USB_SPEED_HIGH] = {.range = {0, 1024}},
 		[USB_SPEED_VARIABLE] = {.range = {0, 3584}},
@@ -2585,6 +2585,8 @@
 	return (1);			/* Clear Stall Finished */
 }
 
+#if (USB_NO_POLL == 0)
+
 /*------------------------------------------------------------------------*
  *	usb2_callout_poll
  *------------------------------------------------------------------------*/
@@ -2693,3 +2695,14 @@
 	}
 	return;
 }
+
+#else
+
+void
+usb2_do_poll(struct usb2_xfer **ppxfer, uint16_t max)
+{
+	/* polling not supported */
+	return;
+}
+
+#endif

==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_util.c#3 (text+ko) ====

@@ -39,8 +39,11 @@
 #include <dev/usb2/controller/usb2_bus.h>
 
 /* function prototypes */
+#if (USB_USE_CONDVAR == 0)
 static int usb2_msleep(void *chan, struct mtx *mtx, int priority, const char *wmesg, int timo);
 
+#endif
+
 /*------------------------------------------------------------------------*
  * device_delete_all_children - delete all children of a device
  *------------------------------------------------------------------------*/
@@ -99,7 +102,7 @@
 		err = 0;
 	}
 
-	temp_p = udev->bus->scratch[0].data;
+	temp_p = (char *)udev->bus->scratch[0].data;
 
 	if (!err) {
 		/* try to get the interface string ! */
@@ -136,12 +139,18 @@
 	} else {
 
 		ms = USB_MS_TO_TICKS(ms);
-		ms++;			/* be sure that we don't return too
-					 * early */
+		/*
+		 * Add one to the number of ticks so that we don't return
+		 * too early!
+		 */
+		ms++;
+
+		mtx_unlock(mtx);
 
-		if (mtx_sleep(&ms, mtx, 0, "pause_mtx", ms)) {
-			/* should not happen */
+		if (pause("USBWAIT", ms)) {
+			/* ignore */
 		}
+		mtx_lock(mtx);
 	}
 	return;
 }
@@ -238,6 +247,8 @@
 	return (totlen);
 }
 
+#if (USB_USE_CONDVAR == 0)
+
 /*------------------------------------------------------------------------*
  *	usb2_cv_init - wrapper function
  *------------------------------------------------------------------------*/
@@ -336,3 +347,5 @@
 	}
 	return (err);
 }
+
+#endif

==== //depot/projects/usb/src/sys/dev/usb2/core/usb2_util.h#3 (text+ko) ====

@@ -33,6 +33,8 @@
 void	usb2_pause_mtx(struct mtx *mtx, uint32_t ms);
 void	usb2_printBCD(char *p, uint16_t p_len, uint16_t bcd);
 void	usb2_trim_spaces(char *p);
+
+#if (USB_USE_CONDVAR == 0)
 void	usb2_cv_init(struct cv *cv, const char *desc);
 void	usb2_cv_destroy(struct cv *cv);
 void	usb2_cv_wait(struct cv *cv, struct mtx *mtx);
@@ -41,4 +43,14 @@
 void	usb2_cv_signal(struct cv *cv);
 void	usb2_cv_broadcast(struct cv *cv);
 
+#else
+#define	usb2_cv_init cv_init
+#define	usb2_cv_destroy cv_destroy
+#define	usb2_cv_wait cv_wait
+#define	usb2_cv_wait_sig cv_wait_sig
+#define	usb2_cv_timedwait cv_timedwait
+#define	usb2_cv_signal cv_signal
+#define	usb2_cv_broadcast cv_broadcast
+#endif
+
 #endif					/* _USB2_UTIL_H_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200808041549.m74FnbVH069661>