Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 10 Aug 2009 19:21:37 GMT
From:      Sylvestre Gallon <syl@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 167185 for review
Message-ID:  <200908101921.n7AJLbUb077185@repoman.freebsd.org>

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

Change 167185 by syl@syl_atuin on 2009/08/10 19:21:01

	Add usb_roothub_exec.c in usb module Makefile.
	Add usb_generic_roothub prototypes in usb_controller.h.
	Add structure definition need by usb_generic_roothub in usb_controller.h.
	First shot for the usb_generic_roothub.
	2 functions implementation are still missing.
	clock and pull-{up|down} code are still missing.

Affected files ...

.. //depot/projects/soc2009/syl_usb/src/sys/dev/usb/usb_controller.h#8 edit
.. //depot/projects/soc2009/syl_usb/src/sys/dev/usb/usb_roothub_exec.c#5 edit
.. //depot/projects/soc2009/syl_usb/src/sys/modules/usb/usb/Makefile#2 edit

Differences ...

==== //depot/projects/soc2009/syl_usb/src/sys/dev/usb/usb_controller.h#8 (text+ko) ====

@@ -39,6 +39,7 @@
 struct usb_page_cache;
 struct usb_setup_params;
 struct usb_hw_ep_profile;
+struct usb_generic_softc;
 struct usb_fs_isoc_schedule;
 struct usb_config_descriptor;
 struct usb_endpoint_descriptor;
@@ -184,6 +185,53 @@
 	usb_error_t err;
 };
 
+/* 
+ * usb_generic_roothub_exec structures
+ */
+
+struct usb_generic_flags {
+	uint8_t change_connect:1;
+	uint8_t change_suspend:1;
+	uint8_t status_suspend:1;
+	uint8_t status_vbus:1;
+	uint8_t status_bus_reset:1;
+	uint8_t remote_wakeup:1;
+	uint8_t self_powered:1;
+	uint8_t clocks_off:1;
+	uint8_t port_powered:1;
+	uint8_t port_enabled:1;
+	uint8_t d_pulled_up:1;
+};
+
+struct usb_generic_hub_temp {
+	uWord wValue;
+	struct usb_port_status ps;
+};
+
+typedef usb_error_t (*usb_roothub_fops_t)(struct usb_generic_softc *sc, uint16_t *len, uint16_t *value, uint16_t *index);
+
+struct usb_roothub_fops {
+	usb_roothub_fops_t handle_get_descriptor;
+	usb_roothub_fops_t handle_get_config;
+	usb_roothub_fops_t handle_get_status;
+	usb_roothub_fops_t handle_set_address;
+	usb_roothub_fops_t handle_set_config;
+	usb_roothub_fops_t handle_clear_halt;
+	usb_roothub_fops_t handle_clear_wakeup;
+	usb_roothub_fops_t handle_set_halt;
+	usb_roothub_fops_t handle_set_wakeup;
+	usb_roothub_fops_t handle_get_ep_status;
+	usb_roothub_fops_t handle_set_interface;
+	usb_roothub_fops_t handle_get_interface;
+	usb_roothub_fops_t handle_get_iface_status;
+	usb_roothub_fops_t handle_clear_port_feature;
+	usb_roothub_fops_t handle_set_port_feature;
+	usb_roothub_fops_t handle_get_tt_state;
+	usb_roothub_fops_t handle_get_port_status;
+	usb_roothub_fops_t handle_get_class_descriptor;
+	usb_roothub_fops_t handle_get_class_status;
+};
+
 /* prototypes */
 
 void	usb_bus_mem_flush_all(struct usb_bus *bus, usb_bus_mem_cb_t *cb);
@@ -192,5 +240,6 @@
 uint16_t usb_isoc_time_expand(struct usb_bus *bus, uint16_t isoc_time_curr);
 uint16_t usbd_fs_isoc_schedule_isoc_time_expand(struct usb_device *udev, struct usb_fs_isoc_schedule **pp_start, struct usb_fs_isoc_schedule **pp_end, uint16_t isoc_time);
 uint8_t	usbd_fs_isoc_schedule_alloc(struct usb_fs_isoc_schedule *fss, uint8_t *pstart, uint16_t len);
+usb_error_t generic_roothub_exec(struct usb_generic_softc *sc, struct usb_roothub_fops *fops, struct usb_device_request *req, const void **pptr, uint16_t *plength);
 
 #endif					/* _USB_CONTROLLER_H_ */

==== //depot/projects/soc2009/syl_usb/src/sys/dev/usb/usb_roothub_exec.c#5 (text+ko) ====

@@ -46,7 +46,7 @@
 #include <dev/usb/usb.h>
 #include <dev/usb/usbdi.h>
 
-#define	USB_DEBUG_VAR s3c24dcidebug
+#define	USB_DEBUG_VAR usb_debug
 
 #include <dev/usb/usb_core.h>
 #include <dev/usb/usb_debug.h>
@@ -60,25 +60,6 @@
 #include <dev/usb/usb_controller.h>
 #include <dev/usb/usb_bus.h>
 
-struct usb_generic_flags {
-	uint8_t change_connect:1;
-	uint8_t change_suspend:1;
-	uint8_t status_suspend:1;
-	uint8_t status_vbus:1;
-	uint8_t status_bus_reset:1;
-	uint8_t remote_wakeup:1;
-	uint8_t self_powered:1;
-	uint8_t clocks_off:1;
-	uint8_t port_powered:1;
-	uint8_t port_enabled:1;
-	uint8_t d_pulled_up:1;
-};
-
-struct usb_generic_hub_temp {
-	uWord wValue;
-	struct usb_port_status ps;
-};
-
 struct usb_generic_softc {
 	struct usb_bus sc_bus;
 	struct usb_generic_hub_temp sc_hub_temp;
@@ -89,8 +70,219 @@
 	struct usb_generic_flags sc_flags;
 };
 
+static struct usb_roothub_fops generic_roothub_fops; 
+
+static usb_error_t 
+generic_get_descriptor(struct usb_generic_softc *sc, uint16_t *len, uint16_t *value, uint16_t *index)
+{
+	switch ((*value) >> 8) {
+	case UDESC_DEVICE:
+		if ((*value) & 0xff) {
+			return (USB_ERR_STALLED);
+		}
+		/* XXX Descriptor's devd stuff */
+		break;
+	case UDESC_CONFIG:
+		if ((*value) & 0xff) {
+			return (USB_ERR_STALLED);
+		}
+		/* XXX Descriptor's confd stuff */
+		break;
+	case UDESC_STRING:
+		switch ((*value) & 0xff) {
+		case 0:
+			/* XXX Descriptor's lantab stuff */
+			break;
+		case 1:
+			/* XXX Descriptor's vendor stuff */
+			break;
+		case 2:
+			/* XXX Descriptor's product stuff */
+			break;
+		default:
+			return (USB_ERR_STALLED);
+		}
+	default:
+		return (USB_ERR_STALLED);
+	}
+	return (0);
+}
+
+static usb_error_t
+generic_get_config(struct usb_generic_softc *sc, uint16_t *len, uint16_t *value, uint16_t *index)
+{
+	*len = 1;
+	sc->sc_hub_temp.wValue[0] = sc->sc_conf;
+	return (0);
+}
+
+static usb_error_t
+generic_get_status(struct usb_generic_softc *sc, uint16_t *len, uint16_t *value, uint16_t *index)
+{
+	*len = 2;
+	USETW(sc->sc_hub_temp.wValue, UDS_SELF_POWERED);
+	return (0);
+}
+
+static usb_error_t
+generic_set_address(struct usb_generic_softc *sc, uint16_t *len, uint16_t *value, uint16_t *index)
+{
+	if ((*value) & 0xff00) {
+		return (USB_ERR_STALLED);
+	}
+	sc->sc_rt_addr = *value;
+	return (0);
+}
+
+static usb_error_t
+generic_set_config(struct usb_generic_softc *sc, uint16_t *len, uint16_t *value, uint16_t *index)
+{
+	if ((*value) >= 2) {
+		return (USB_ERR_STALLED);
+	}
+	sc->sc_conf = *value;
+	return (0);
+}
+
+static usb_error_t
+generic_clear_halt(struct usb_generic_softc *sc, uint16_t *len, uint16_t *value, uint16_t *index)
+{
+	return (0);
+}
+
+static usb_error_t
+generic_clear_wakeup(struct usb_generic_softc *sc, uint16_t *len, uint16_t *value, uint16_t *index)
+{
+	return (0);
+}
+
+static usb_error_t
+generic_set_halt(struct usb_generic_softc *sc, uint16_t *len, uint16_t *value, uint16_t *index)
+{
+	return (0);
+}
+
+static usb_error_t
+generic_set_wakeup(struct usb_generic_softc *sc, uint16_t *len, uint16_t *value, uint16_t *index)
+{
+	return (0);
+}
+
+static usb_error_t
+generic_get_ep_status(struct usb_generic_softc *sc, uint16_t *len, uint16_t *value, uint16_t *index)
+{
+	*len = 2;
+	USETW(sc->sc_hub_temp.wValue, 0);
+	return (0);
+}
+
+static usb_error_t
+generic_set_interface(struct usb_generic_softc *sc, uint16_t *len, uint16_t *value, uint16_t *index)
+{
+	return (0);
+}
+
+static usb_error_t
+generic_get_interface(struct usb_generic_softc *sc, uint16_t *len, uint16_t *value, uint16_t *index)
+{
+	*len = 1;
+	sc->sc_hub_temp.wValue[0] = 0;
+	return (0);
+}
+
+static usb_error_t
+generic_get_iface_status(struct usb_generic_softc *sc, uint16_t *len, uint16_t *value, uint16_t *index)
+{
+	*len = 2;
+	USETW(sc->sc_hub_temp.wValue, 0);
+	return (0);
+}
+
+static usb_error_t
+generic_clear_port_feature(struct usb_generic_softc *sc, uint16_t *len, uint16_t *value, uint16_t *index)
+{
+	if ((*index) != 1) {
+		return (USB_ERR_STALLED);
+	}
+	DPRINTFN(9, "UR_CLEAR_PORT_FEATURE on port %d\n", *index);
+
+	switch (*value) {
+	case UHF_PORT_SUSPEND:
+		/* XXX xxxdci_wakeup_peer */
+		break;	
+
+	case UHF_PORT_ENABLE:
+		sc->sc_flags.port_enabled = 0;
+		break;
+	
+	case UHF_PORT_TEST:
+	case UHF_PORT_INDICATOR:
+	case UHF_C_PORT_ENABLE:
+	case UHF_C_PORT_OVER_CURRENT:
+	case UHF_C_PORT_RESET:
+		break;
+	case UHF_PORT_POWER:
+		sc->sc_flags.port_powered = 0;
+		/* XXX Pull down clock off */
+		break;
+	case UHF_C_PORT_CONNECTION:
+		sc->sc_flags.change_connect = 0;
+		break;
+	case UHF_C_PORT_SUSPEND:
+		sc->sc_flags.change_suspend = 0;
+		break;
+	default:
+		return (USB_ERR_IOERROR);
+	}
+	return (0);
+}
+
+static usb_error_t
+generic_set_port_feature(struct usb_generic_softc *sc, uint16_t *len, uint16_t *value, uint16_t *index)
+{
+	return (0);
+}
+
+static usb_error_t
+generic_get_tt_state(struct usb_generic_softc *sc, uint16_t *len, uint16_t *value, uint16_t *index)
+{
+	*len = 2;
+	USETW(sc->sc_hub_temp.wValue, 0);
+	return (0);
+}
+
+static usb_error_t
+generic_get_port_status(struct usb_generic_softc *sc, uint16_t *len, uint16_t *value, uint16_t *index)
+{
+	return (0);
+}
+
+static usb_error_t
+generic_get_class_descriptor(struct usb_generic_softc *sc, uint16_t *len, uint16_t *value, uint16_t *index)
+{
+	if ((*value) & 0xff) {
+		return (USB_ERR_STALLED);
+	}
+	/* XXX HUB Descriptor stuff */
+	return (0);
+}
+
 static usb_error_t
-genric_roothub_exec(struct usb_device *udev, struct usb_generic_softc *sc,
+generic_get_class_status(struct usb_generic_softc *sc, uint16_t *len, uint16_t *value, uint16_t *index)
+{
+	*len = 2;
+	USETW(sc->sc_hub_temp.wValue, 0);
+	return (0);
+}
+
+#define SAFE_OPS(fops, field, err) 			\
+	if (fops->field == NULL) 			\
+		err = generic_roothub_fops.field(sc, &len, &value, &index); 	\
+	else 						\
+		err = fops->field(sc, &len, &value, &index)
+
+usb_error_t
+generic_roothub_exec(struct usb_generic_softc *sc, struct usb_roothub_fops *fops,
     struct usb_device_request *req, const void **pptr, uint16_t *plength)
 {
 	const void *ptr;
@@ -105,6 +297,9 @@
 	ptr = (const void*)&sc->sc_hub_temp;
 	len = 0;
 	err = 0;
+	
+	if (fops == NULL)
+		fops = &generic_roothub_fops;
 
 	value = UGETW(req->wValue);
 	index = UGETW(req->wIndex);
@@ -114,11 +309,14 @@
 	case UT_READ_DEVICE:
 		switch (req->bRequest) {
 		case UR_GET_DESCRIPTOR:
-			/* handle_get_descriptor */
+			SAFE_OPS(fops, handle_get_descriptor, err);
+			break;
 		case UR_GET_CONFIG:
-			/* handle_get_config */
+			SAFE_OPS(fops, handle_get_config, err);
+			break;
 		case UR_GET_STATUS:
-			/* handle_get_status */
+			SAFE_OPS(fops, handle_get_status, err);
+			break;
 		default:
 			err = USB_ERR_STALLED;
 			break;
@@ -128,9 +326,11 @@
 	case UT_WRITE_DEVICE:
 		switch (req->bRequest) {
 		case UR_SET_ADDRESS:
-			/* handle_set_address */
+			SAFE_OPS(fops, handle_set_address, err);
+			break;
 		case UR_SET_CONFIG:
-			/* handle_set_config */
+			SAFE_OPS(fops, handle_set_config, err);
+			break;
 		case UR_CLEAR_FEATURE:
 			break;
 		case UR_SET_DESCRIPTOR:
@@ -147,9 +347,11 @@
 		case UR_CLEAR_FEATURE:
 			switch (UGETW(req->wValue)) {
 			case UF_ENDPOINT_HALT:
-				/* handle_clear_halt */
+				SAFE_OPS(fops, handle_clear_halt, err);
+				break;
 			case UF_DEVICE_REMOTE_WAKEUP:
-				/* handle_clear_wakeup */
+				SAFE_OPS(fops, handle_clear_wakeup, err);
+				break;
 			default:
 				err = USB_ERR_STALLED;
 				break;
@@ -158,9 +360,11 @@
 		case UR_SET_FEATURE:
 			switch (UGETW(req->wValue)) {
 			case UF_ENDPOINT_HALT:
-				/* handle_set_halt */
+				SAFE_OPS(fops, handle_set_halt, err);
+				break;
 			case UF_DEVICE_REMOTE_WAKEUP:
-				/* handle_set_wakeup */
+				SAFE_OPS(fops, handle_set_wakeup, err);
+				break;
 			default:
 				err = USB_ERR_STALLED;
 				break;
@@ -177,7 +381,8 @@
 	case UT_READ_ENDPOINT:
 		switch (req->bRequest) {
 		case UR_GET_STATUS:
-			/* handle_get_ep_status */
+			SAFE_OPS(fops, handle_get_ep_status, err);
+			break;
 		default:
 			err = USB_ERR_STALLED;
 			break;
@@ -187,7 +392,8 @@
 	case UT_WRITE_INTERFACE:
 		switch (req->bRequest) {
 		case UR_SET_INTERFACE:
-			/* handle_set_interface */
+			SAFE_OPS(fops, handle_set_interface, err);
+			break;
 		case UR_CLEAR_FEATURE:
 			break;
 		case UR_SET_FEATURE:
@@ -200,9 +406,11 @@
 	case UT_READ_INTERFACE:
 		switch (req->bRequest) {
 		case UR_GET_INTERFACE:
-			/* handle_get_interfac */
+			SAFE_OPS(fops, handle_get_interface, err);
+			break;
 		case UR_GET_STATUS:
-			/* handle_get_iface_status */
+			SAFE_OPS(fops, handle_get_iface_status, err);
+			break;
 		default:
 			err = USB_ERR_STALLED;
 			break;
@@ -235,9 +443,11 @@
 	case UT_WRITE_CLASS_OTHER:
 		switch (req->bRequest) {
 		case UR_CLEAR_FEATURE:
-			/* handle_clear_port_feature */
+			SAFE_OPS(fops, handle_clear_port_feature, err);
+			break;
 		case UR_SET_FEATURE:
-			/* handle_set_port_feature */
+			SAFE_OPS(fops, handle_set_port_feature, err);
+			break;
 		case UR_CLEAR_TT_BUFFER:
 		case UR_RESET_TT:
 		case UR_STOP_TT:
@@ -251,9 +461,11 @@
 	case UT_READ_CLASS_OTHER:
 		switch (req->bRequest) {
 		case UR_GET_TT_STATE:
-			/* handle_get_tt_state */
+			SAFE_OPS(fops, handle_get_tt_state, err);
+			break;
 		case UR_GET_STATUS:
-			/* handle_get_port_status */
+			SAFE_OPS(fops, handle_get_port_status, err);
+			break;
 		default:
 			err = USB_ERR_STALLED;
 			break;
@@ -263,20 +475,44 @@
 	case UT_READ_CLASS_DEVICE:
 		switch (req->bRequest) {
 		case UR_GET_DESCRIPTOR:
-			/* handle_get_class_descriptor */
+			SAFE_OPS(fops, handle_get_class_descriptor, err);
+			break;
 		case UR_GET_STATUS:
-			/* handle_get_class_status */
-
+			SAFE_OPS(fops, handle_get_class_status, err);
+			break;
 		default:
 			err = USB_ERR_STALLED;
 			break ;
 		}
 		break;
 	default:
-		goto tr_stalled;
+		err = USB_ERR_STALLED;
 	}
 
 	*plength = len;
 	*pptr = ptr;
 	return (err);
 }
+
+static struct usb_roothub_fops generic_roothub_fops = {
+	&generic_get_descriptor,
+	&generic_get_config,
+	&generic_get_status,
+	&generic_set_address,
+	&generic_set_config,
+	&generic_clear_halt,
+        &generic_clear_wakeup,
+        &generic_set_halt,
+        &generic_set_wakeup,
+        &generic_get_ep_status,
+        &generic_set_interface,
+        &generic_get_interface,
+        &generic_get_iface_status,
+        &generic_clear_port_feature,
+        &generic_set_port_feature,
+        &generic_get_tt_state,
+	&generic_get_port_status,
+        &generic_get_class_descriptor,
+	&generic_get_class_status,
+};
+

==== //depot/projects/soc2009/syl_usb/src/sys/modules/usb/usb/Makefile#2 (text+ko) ====

@@ -37,6 +37,6 @@
 	usb_dev.c usb_device.c usb_dynamic.c usb_error.c usb_generic.c \
 	usb_handle_request.c usb_hid.c usb_hub.c usb_lookup.c usb_mbuf.c \
 	usb_msctest.c usb_parse.c usb_process.c usb_request.c \
-	usb_transfer.c usb_util.c 
+	usb_roothub_exec.c usb_transfer.c usb_util.c 
 
 .include <bsd.kmod.mk>



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