PERFORCE change 167302 for review
Sylvestre Gallon
syl at FreeBSD.org
Thu Aug 13 19:10:05 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=167302
Change 167302 by syl at syl_atuin on 2009/08/13 19:09:17
On Hans Petter advices :
- Add static const to usb_roothub_fops.
- Use multiple field initialisation.
- Update at91dci to use this mechanisms.
Affected files ...
.. //depot/projects/soc2009/syl_usb/src/sys/dev/usb/controller/at91dci.c#13 edit
.. //depot/projects/soc2009/syl_usb/src/sys/dev/usb/usb_controller.h#11 edit
.. //depot/projects/soc2009/syl_usb/src/sys/dev/usb/usb_roothub_exec.c#8 edit
Differences ...
==== //depot/projects/soc2009/syl_usb/src/sys/dev/usb/controller/at91dci.c#13 (text+ko) ====
@@ -1582,7 +1582,7 @@
static usb_error_t
at91dci_get_port_status(struct usb_generic_softc *gensc,
- struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
+ const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
uint16_t *index)
{
struct at91dci_softc *sc = (struct at91dci_softc *)gensc;
@@ -1640,16 +1640,17 @@
struct usb_device_request *req, const void **pptr, uint16_t *plength)
{
struct at91dci_softc *sc = AT9100_DCI_BUS2SC(udev->bus);
- struct usb_roothub_fops fops;
+ static const struct usb_roothub_fops fops = {
+ DEFAULT_ROOTHUB,
+ .handle_get_port_status = &at91dci_get_port_status,
+ .handle_clocks_on = (usb_clocks_fops_t)&at91dci_clocks_on,
+ .handle_clocks_off = (usb_clocks_fops_t)&at91dci_clocks_off,
+ .handle_pull_up = (usb_clocks_fops_t)&at91dci_pull_up,
+ .handle_pull_down = (usb_clocks_fops_t)&at91dci_pull_down,
+ .handle_wakeup_peer = (usb_clocks_fops_t)&at91dci_wakeup_peer,
+ };
- bzero(&fops, sizeof(struct usb_roothub_fops));
- fops.handle_get_port_status = &at91dci_get_port_status;
- fops.handle_clocks_on = (usb_clocks_fops_t)&at91dci_clocks_on;
- fops.handle_clocks_off = (usb_clocks_fops_t)&at91dci_clocks_off;
- fops.handle_pull_up = (usb_clocks_fops_t)&at91dci_pull_up;
- fops.handle_pull_down = (usb_clocks_fops_t)&at91dci_pull_down;
- fops.handle_wakeup_peer = (usb_clocks_fops_t)&at91dci_wakeup_peer;
- return generic_roothub_exec((struct usb_generic_softc *)sc, &fops, req,
+ return generic_roothub_exec((struct usb_generic_softc *)sc, &fops, req,
pptr, plength);
}
==== //depot/projects/soc2009/syl_usb/src/sys/dev/usb/usb_controller.h#11 (text+ko) ====
@@ -209,7 +209,7 @@
struct usb_port_status ps;
};
-typedef usb_error_t (*usb_roothub_fops_t)(struct usb_generic_softc *sc, struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value, uint16_t *index);
+typedef usb_error_t (*usb_roothub_fops_t)(struct usb_generic_softc *sc, const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value, uint16_t *index);
typedef usb_error_t (*usb_clocks_fops_t)(struct usb_generic_softc *sc);
struct usb_roothub_fops {
@@ -247,6 +247,50 @@
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);
+usb_error_t generic_roothub_exec(struct usb_generic_softc *sc, const struct usb_roothub_fops *fops, struct usb_device_request *req, const void **pptr, uint16_t *plength);
+
+/* prototypes needed by generic_roothub_exec */
+
+
+usb_error_t generic_get_descriptor(struct usb_generic_softc *sc, const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value, uint16_t *index);
+usb_error_t generic_get_config(struct usb_generic_softc *sc, const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value, uint16_t *index);
+usb_error_t generic_get_status(struct usb_generic_softc *sc, const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value, uint16_t *index);
+usb_error_t generic_set_address(struct usb_generic_softc *sc, const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value, uint16_t *index);
+usb_error_t generic_set_config(struct usb_generic_softc *sc, const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value, uint16_t *index);
+usb_error_t generic_clear_halt(struct usb_generic_softc *sc, const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value, uint16_t *index);
+usb_error_t generic_clear_wakeup(struct usb_generic_softc *sc, const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value, uint16_t *index);
+usb_error_t generic_set_halt(struct usb_generic_softc *sc, const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value, uint16_t *index);
+usb_error_t generic_set_wakeup(struct usb_generic_softc *sc, const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value, uint16_t *index);
+usb_error_t generic_get_ep_status(struct usb_generic_softc *sc, const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value, uint16_t *index);
+usb_error_t generic_set_interface(struct usb_generic_softc *sc, const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value, uint16_t *index);
+usb_error_t generic_get_interface(struct usb_generic_softc *sc, const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value, uint16_t *index);
+usb_error_t generic_get_iface_status(struct usb_generic_softc *sc, const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value, uint16_t *index);
+usb_error_t generic_clear_port_feature(struct usb_generic_softc *sc, const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value, uint16_t *index);
+usb_error_t generic_set_port_feature(struct usb_generic_softc *sc, const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value, uint16_t *index);
+usb_error_t generic_get_tt_state(struct usb_generic_softc *sc, const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value, uint16_t *index);
+usb_error_t generic_get_port_status(struct usb_generic_softc *sc, const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value, uint16_t *index);
+usb_error_t generic_get_class_descriptor(struct usb_generic_softc *sc, const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value, uint16_t *index);
+usb_error_t generic_get_class_status(struct usb_generic_softc *sc, const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value, uint16_t *index);
+
+#define DEFAULT_ROOTHUB \
+.handle_get_descriptor = &generic_get_descriptor, \
+.handle_get_config = &generic_get_config, \
+.handle_get_status = &generic_get_status, \
+.handle_set_address = &generic_set_address, \
+.handle_set_config = &generic_set_config, \
+.handle_clear_halt = &generic_clear_halt, \
+.handle_clear_wakeup = &generic_clear_wakeup, \
+.handle_set_halt = &generic_set_halt, \
+.handle_set_wakeup = &generic_set_wakeup, \
+.handle_get_ep_status = &generic_get_ep_status, \
+.handle_set_interface = &generic_set_interface, \
+.handle_get_interface = &generic_get_interface, \
+.handle_get_iface_status = &generic_get_iface_status, \
+.handle_clear_port_feature = &generic_clear_port_feature, \
+.handle_set_port_feature = &generic_set_port_feature, \
+.handle_get_tt_state = &generic_get_tt_state, \
+.handle_get_port_status = &generic_get_port_status, \
+.handle_get_class_descriptor = &generic_get_class_descriptor, \
+.handle_get_class_status = &generic_get_class_status
#endif /* _USB_CONTROLLER_H_ */
==== //depot/projects/soc2009/syl_usb/src/sys/dev/usb/usb_roothub_exec.c#8 (text+ko) ====
@@ -70,17 +70,9 @@
struct usb_generic_flags sc_flags;
};
-#define SAFE_OPS(fops, field, err) \
- if (fops->field == NULL) \
- err = generic_roothub_fops.field(sc, fops, &len, &value, &index); \
- else \
- err = fops->field(sc, fops, &len, &value, &index)
-
-static struct usb_roothub_fops generic_roothub_fops;
-
-static usb_error_t
+usb_error_t
generic_get_descriptor(struct usb_generic_softc *sc,
- struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
+ const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
uint16_t *index)
{
switch ((*value) >> 8) {
@@ -116,9 +108,9 @@
return (0);
}
-static usb_error_t
+usb_error_t
generic_get_config(struct usb_generic_softc *sc,
- struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
+ const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
uint16_t *index)
{
*len = 1;
@@ -126,18 +118,19 @@
return (0);
}
-static usb_error_t
-generic_get_status(struct usb_generic_softc *sc, struct usb_roothub_fops *fops,
- uint16_t *len, uint16_t *value, uint16_t *index)
+usb_error_t
+generic_get_status(struct usb_generic_softc *sc,
+ const struct usb_roothub_fops *fops, 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
+usb_error_t
generic_set_address(struct usb_generic_softc *sc,
- struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
+ const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
uint16_t *index)
{
if ((*value) & 0xff00) {
@@ -147,9 +140,10 @@
return (0);
}
-static usb_error_t
-generic_set_config(struct usb_generic_softc *sc, struct usb_roothub_fops *fops,
- uint16_t *len, uint16_t *value, uint16_t *index)
+usb_error_t
+generic_set_config(struct usb_generic_softc *sc,
+ const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
+ uint16_t *index)
{
if ((*value) >= 2) {
return (USB_ERR_STALLED);
@@ -158,38 +152,41 @@
return (0);
}
-static usb_error_t
-generic_clear_halt(struct usb_generic_softc *sc, struct usb_roothub_fops *fops,
- uint16_t *len, uint16_t *value, uint16_t *index)
+usb_error_t
+generic_clear_halt(struct usb_generic_softc *sc,
+ const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
+ uint16_t *index)
{
return (0);
}
-static usb_error_t
+usb_error_t
generic_clear_wakeup(struct usb_generic_softc *sc,
- struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
+ const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
uint16_t *index)
{
return (0);
}
-static usb_error_t
-generic_set_halt(struct usb_generic_softc *sc, struct usb_roothub_fops *fops,
- uint16_t *len, uint16_t *value, uint16_t *index)
+usb_error_t
+generic_set_halt(struct usb_generic_softc *sc,
+ const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
+ uint16_t *index)
{
return (0);
}
-static usb_error_t
-generic_set_wakeup(struct usb_generic_softc *sc, struct usb_roothub_fops *fops,
- uint16_t *len, uint16_t *value, uint16_t *index)
+usb_error_t
+generic_set_wakeup(struct usb_generic_softc *sc,
+ const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
+ uint16_t *index)
{
return (0);
}
-static usb_error_t
+usb_error_t
generic_get_ep_status(struct usb_generic_softc *sc,
- struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
+ const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
uint16_t *index)
{
*len = 2;
@@ -197,17 +194,17 @@
return (0);
}
-static usb_error_t
+usb_error_t
generic_set_interface(struct usb_generic_softc *sc,
- struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
+ const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
uint16_t *index)
{
return (0);
}
-static usb_error_t
+usb_error_t
generic_get_interface(struct usb_generic_softc *sc,
- struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
+ const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
uint16_t *index)
{
*len = 1;
@@ -215,9 +212,9 @@
return (0);
}
-static usb_error_t
+usb_error_t
generic_get_iface_status(struct usb_generic_softc *sc,
- struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
+ const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
uint16_t *index)
{
*len = 2;
@@ -226,9 +223,9 @@
}
/* XXX Atmega need another function here */
-static usb_error_t
+usb_error_t
generic_clear_port_feature(struct usb_generic_softc *sc,
- struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
+ const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
uint16_t *index)
{
if ((*index) != 1) {
@@ -272,9 +269,9 @@
return (0);
}
-static usb_error_t
+usb_error_t
generic_set_port_feature(struct usb_generic_softc *sc,
- struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
+ const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
uint16_t *index)
{
if ((*index) != 1) {
@@ -301,9 +298,9 @@
return (0);
}
-static usb_error_t
+usb_error_t
generic_get_tt_state(struct usb_generic_softc *sc,
- struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
+ const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
uint16_t *index)
{
*len = 2;
@@ -311,9 +308,10 @@
return (0);
}
-static usb_error_t
+/* XXX Need to recheck with atmega */
+usb_error_t
generic_get_port_status(struct usb_generic_softc *sc,
- struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
+ const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
uint16_t *index)
{
DPRINTFN(9, "UR_GET_PORT_STATUS");
@@ -366,9 +364,9 @@
return (0);
}
-static usb_error_t
+usb_error_t
generic_get_class_descriptor(struct usb_generic_softc *sc,
- struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
+ const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
uint16_t *index)
{
if ((*value) & 0xff) {
@@ -378,9 +376,9 @@
return (0);
}
-static usb_error_t
+usb_error_t
generic_get_class_status(struct usb_generic_softc *sc,
- struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
+ const struct usb_roothub_fops *fops, uint16_t *len, uint16_t *value,
uint16_t *index)
{
*len = 2;
@@ -390,7 +388,7 @@
usb_error_t
generic_roothub_exec(struct usb_generic_softc *sc,
- struct usb_roothub_fops *fops, struct usb_device_request *req,
+ const struct usb_roothub_fops *fops, struct usb_device_request *req,
const void **pptr, uint16_t *plength)
{
const void *ptr;
@@ -406,9 +404,6 @@
len = 0;
err = 0;
- if (fops == NULL)
- fops = &generic_roothub_fops;
-
value = UGETW(req->wValue);
index = UGETW(req->wIndex);
@@ -417,13 +412,13 @@
case UT_READ_DEVICE:
switch (req->bRequest) {
case UR_GET_DESCRIPTOR:
- SAFE_OPS(fops, handle_get_descriptor, err);
+ err = fops->handle_get_descriptor(sc, fops, &len, &value, &index);
break;
case UR_GET_CONFIG:
- SAFE_OPS(fops, handle_get_config, err);
+ err = fops->handle_get_config(sc, fops, &len, &value, &index);
break;
case UR_GET_STATUS:
- SAFE_OPS(fops, handle_get_status, err);
+ err = fops->handle_get_status(sc, fops, &len, &value, &index);
break;
default:
err = USB_ERR_STALLED;
@@ -434,10 +429,10 @@
case UT_WRITE_DEVICE:
switch (req->bRequest) {
case UR_SET_ADDRESS:
- SAFE_OPS(fops, handle_set_address, err);
+ err = fops->handle_set_address(sc, fops, &len, &value, &index);
break;
case UR_SET_CONFIG:
- SAFE_OPS(fops, handle_set_config, err);
+ err = fops->handle_set_config(sc, fops, &len, &value, &index);
break;
case UR_CLEAR_FEATURE:
break;
@@ -455,10 +450,10 @@
case UR_CLEAR_FEATURE:
switch (UGETW(req->wValue)) {
case UF_ENDPOINT_HALT:
- SAFE_OPS(fops, handle_clear_halt, err);
+ err = fops->handle_clear_halt(sc, fops, &len, &value, &index);
break;
case UF_DEVICE_REMOTE_WAKEUP:
- SAFE_OPS(fops, handle_clear_wakeup, err);
+ err = fops->handle_clear_wakeup(sc, fops, &len, &value, &index);
break;
default:
err = USB_ERR_STALLED;
@@ -468,10 +463,10 @@
case UR_SET_FEATURE:
switch (UGETW(req->wValue)) {
case UF_ENDPOINT_HALT:
- SAFE_OPS(fops, handle_set_halt, err);
+ err = fops->handle_set_halt(sc, fops, &len, &value, &index);
break;
case UF_DEVICE_REMOTE_WAKEUP:
- SAFE_OPS(fops, handle_set_wakeup, err);
+ err = fops->handle_set_wakeup(sc, fops, &len, &value, &index);
break;
default:
err = USB_ERR_STALLED;
@@ -489,7 +484,7 @@
case UT_READ_ENDPOINT:
switch (req->bRequest) {
case UR_GET_STATUS:
- SAFE_OPS(fops, handle_get_ep_status, err);
+ err = fops->handle_get_ep_status(sc, fops, &len, &value, &index);
break;
default:
err = USB_ERR_STALLED;
@@ -500,7 +495,7 @@
case UT_WRITE_INTERFACE:
switch (req->bRequest) {
case UR_SET_INTERFACE:
- SAFE_OPS(fops, handle_set_interface, err);
+ err = fops->handle_set_interface(sc, fops, &len, &value, &index);
break;
case UR_CLEAR_FEATURE:
break;
@@ -514,10 +509,10 @@
case UT_READ_INTERFACE:
switch (req->bRequest) {
case UR_GET_INTERFACE:
- SAFE_OPS(fops, handle_get_interface, err);
+ err = fops->handle_get_interface(sc, fops, &len, &value, &index);
break;
case UR_GET_STATUS:
- SAFE_OPS(fops, handle_get_iface_status, err);
+ err = fops->handle_get_iface_status(sc, fops, &len, &value, &index);
break;
default:
err = USB_ERR_STALLED;
@@ -551,10 +546,10 @@
case UT_WRITE_CLASS_OTHER:
switch (req->bRequest) {
case UR_CLEAR_FEATURE:
- SAFE_OPS(fops, handle_clear_port_feature, err);
+ err = fops->handle_clear_port_feature(sc, fops, &len, &value, &index);
break;
case UR_SET_FEATURE:
- SAFE_OPS(fops, handle_set_port_feature, err);
+ err = fops->handle_set_port_feature(sc, fops, &len, &value, &index);
break;
case UR_CLEAR_TT_BUFFER:
case UR_RESET_TT:
@@ -569,10 +564,10 @@
case UT_READ_CLASS_OTHER:
switch (req->bRequest) {
case UR_GET_TT_STATE:
- SAFE_OPS(fops, handle_get_tt_state, err);
+ err = fops->handle_get_tt_state(sc, fops, &len, &value, &index);
break;
case UR_GET_STATUS:
- SAFE_OPS(fops, handle_get_port_status, err);
+ err = fops->handle_get_port_status(sc, fops, &len, &value, &index);
break;
default:
err = USB_ERR_STALLED;
@@ -583,10 +578,10 @@
case UT_READ_CLASS_DEVICE:
switch (req->bRequest) {
case UR_GET_DESCRIPTOR:
- SAFE_OPS(fops, handle_get_class_descriptor, err);
+ err = fops->handle_get_class_descriptor(sc, fops, &len, &value, &index);
break;
case UR_GET_STATUS:
- SAFE_OPS(fops, handle_get_class_status, err);
+ err = fops->handle_get_class_status(sc, fops, &len, &value, &index);
break;
default:
err = USB_ERR_STALLED;
@@ -603,31 +598,3 @@
*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,
- NULL,
- NULL,
- NULL,
- NULL,
- NULL,
-};
-
More information about the p4-projects
mailing list