Fixed Interface.

svn path=/trunk/; revision=15798
This commit is contained in:
James Tabor 2005-06-05 00:40:40 +00:00
parent 355593bafa
commit a104816de4
8 changed files with 73 additions and 72 deletions

View file

@ -101,56 +101,56 @@ static int usb_parse_endpoint(struct usb_host_endpoint *endpoint, unsigned char
return parsed; return parsed;
} }
static int usb_parse_interface(struct usb_interface *pinterface, unsigned char *buffer, int size) static int usb_parse_interface(struct usb_interface *interface, unsigned char *buffer, int size)
{ {
int i, len, numskipped, retval, parsed = 0; int i, len, numskipped, retval, parsed = 0;
struct usb_descriptor_header *header; struct usb_descriptor_header *header;
struct usb_host_interface *ifp; struct usb_host_interface *ifp;
unsigned char *begin; unsigned char *begin;
pinterface->act_altsetting = 0; interface->act_altsetting = 0;
pinterface->num_altsetting = 0; interface->num_altsetting = 0;
pinterface->max_altsetting = USB_ALTSETTINGALLOC; interface->max_altsetting = USB_ALTSETTINGALLOC;
device_initialize(&pinterface->dev); device_initialize(&interface->dev);
pinterface->altsetting = kmalloc(sizeof(*pinterface->altsetting) * pinterface->max_altsetting, interface->altsetting = kmalloc(sizeof(*interface->altsetting) * interface->max_altsetting,
GFP_KERNEL); GFP_KERNEL);
if (!pinterface->altsetting) { if (!interface->altsetting) {
err("couldn't kmalloc pinterface->altsetting"); err("couldn't kmalloc interface->altsetting");
return -1; return -1;
} }
while (size > 0) { while (size > 0) {
struct usb_interface_descriptor *d; struct usb_interface_descriptor *d;
if (pinterface->num_altsetting >= pinterface->max_altsetting) { if (interface->num_altsetting >= interface->max_altsetting) {
struct usb_host_interface *ptr; struct usb_host_interface *ptr;
int oldmas; int oldmas;
oldmas = pinterface->max_altsetting; oldmas = interface->max_altsetting;
pinterface->max_altsetting += USB_ALTSETTINGALLOC; interface->max_altsetting += USB_ALTSETTINGALLOC;
if (pinterface->max_altsetting > USB_MAXALTSETTING) { if (interface->max_altsetting > USB_MAXALTSETTING) {
warn("too many alternate settings (incr %d max %d)\n", warn("too many alternate settings (incr %d max %d)\n",
USB_ALTSETTINGALLOC, USB_MAXALTSETTING); USB_ALTSETTINGALLOC, USB_MAXALTSETTING);
return -1; return -1;
} }
ptr = kmalloc(sizeof(*ptr) * pinterface->max_altsetting, GFP_KERNEL); ptr = kmalloc(sizeof(*ptr) * interface->max_altsetting, GFP_KERNEL);
if (ptr == NULL) { if (ptr == NULL) {
err("couldn't kmalloc pinterface->altsetting"); err("couldn't kmalloc interface->altsetting");
return -1; return -1;
} }
memcpy(ptr, pinterface->altsetting, sizeof(*pinterface->altsetting) * oldmas); memcpy(ptr, interface->altsetting, sizeof(*interface->altsetting) * oldmas);
kfree(pinterface->altsetting); kfree(interface->altsetting);
pinterface->altsetting = ptr; interface->altsetting = ptr;
} }
ifp = pinterface->altsetting + pinterface->num_altsetting; ifp = interface->altsetting + interface->num_altsetting;
ifp->endpoint = NULL; ifp->endpoint = NULL;
ifp->extra = NULL; ifp->extra = NULL;
ifp->extralen = 0; ifp->extralen = 0;
pinterface->num_altsetting++; interface->num_altsetting++;
memcpy(ifp, buffer, USB_DT_INTERFACE_SIZE); memcpy(ifp, buffer, USB_DT_INTERFACE_SIZE);
@ -268,16 +268,16 @@ int usb_parse_configuration(struct usb_host_config *config, char *buffer)
return -1; return -1;
} }
config->pinterface = (struct usb_interface *) config->interface = (struct usb_interface *)
kmalloc(config->desc.bNumInterfaces * kmalloc(config->desc.bNumInterfaces *
sizeof(struct usb_interface), GFP_KERNEL); sizeof(struct usb_interface), GFP_KERNEL);
dbg("kmalloc IF %p, numif %i", config->pinterface, config->desc.bNumInterfaces); dbg("kmalloc IF %p, numif %i", config->interface, config->desc.bNumInterfaces);
if (!config->pinterface) { if (!config->interface) {
err("out of memory"); err("out of memory");
return -1; return -1;
} }
memset(config->pinterface, 0, memset(config->interface, 0,
config->desc.bNumInterfaces * sizeof(struct usb_interface)); config->desc.bNumInterfaces * sizeof(struct usb_interface));
buffer += config->desc.bLength; buffer += config->desc.bLength;
@ -337,7 +337,7 @@ int usb_parse_configuration(struct usb_host_config *config, char *buffer)
} }
} }
retval = usb_parse_interface(config->pinterface + i, buffer, size); retval = usb_parse_interface(config->interface + i, buffer, size);
if (retval < 0) if (retval < 0)
return retval; return retval;
@ -367,12 +367,12 @@ void usb_destroy_configuration(struct usb_device *dev)
for (c = 0; c < dev->descriptor.bNumConfigurations; c++) { for (c = 0; c < dev->descriptor.bNumConfigurations; c++) {
struct usb_host_config *cf = &dev->config[c]; struct usb_host_config *cf = &dev->config[c];
if (!cf->pinterface) if (!cf->interface)
break; break;
for (i = 0; i < cf->desc.bNumInterfaces; i++) { for (i = 0; i < cf->desc.bNumInterfaces; i++) {
struct usb_interface *ifp = struct usb_interface *ifp =
&cf->pinterface[i]; &cf->interface[i];
if (!ifp->altsetting) if (!ifp->altsetting)
break; break;
@ -398,7 +398,7 @@ void usb_destroy_configuration(struct usb_device *dev)
kfree(ifp->altsetting); kfree(ifp->altsetting);
} }
kfree(cf->pinterface); kfree(cf->interface);
} }
kfree(dev->config); kfree(dev->config);
} }

View file

@ -424,7 +424,7 @@ extern void usb_bus_get (struct usb_bus *bus);
extern void usb_bus_put (struct usb_bus *bus); extern void usb_bus_put (struct usb_bus *bus);
extern int usb_find_interface_driver (struct usb_device *dev, extern int usb_find_interface_driver (struct usb_device *dev,
struct usb_interface *pinterface); struct usb_interface *interface);
#define usb_endpoint_halt(dev, ep, out) ((dev)->halted[out] |= (1 << (ep))) #define usb_endpoint_halt(dev, ep, out) ((dev)->halted[out] |= (1 << (ep)))

View file

@ -67,7 +67,7 @@ static inline char *portspeed (int portstatus)
/* for dev_info, dev_dbg, etc */ /* for dev_info, dev_dbg, etc */
static inline struct device *hubdev (struct usb_device *dev) static inline struct device *hubdev (struct usb_device *dev)
{ {
return &dev->actconfig->pinterface [0].dev; return &dev->actconfig->interface [0].dev;
} }
/* USB 2.0 spec Section 11.24.4.5 */ /* USB 2.0 spec Section 11.24.4.5 */
@ -700,7 +700,7 @@ static void hub_start_disconnect(struct usb_device *dev)
static int hub_port_status(struct usb_device *dev, int port, static int hub_port_status(struct usb_device *dev, int port,
u16 *status, u16 *change) u16 *status, u16 *change)
{ {
struct usb_hub *hub = usb_get_intfdata (dev->actconfig->pinterface); struct usb_hub *hub = usb_get_intfdata (dev->actconfig->interface);
int ret; int ret;
ret = get_port_status(dev, port + 1, &hub->status->port); ret = get_port_status(dev, port + 1, &hub->status->port);
@ -1377,7 +1377,7 @@ int usb_physical_reset_device(struct usb_device *dev)
} }
for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) { for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) {
struct usb_interface *intf = &dev->actconfig->pinterface[i]; struct usb_interface *intf = &dev->actconfig->interface[i];
struct usb_interface_descriptor *as; struct usb_interface_descriptor *as;
as = &intf->altsetting[intf->act_altsetting].desc; as = &intf->altsetting[intf->act_altsetting].desc;

View file

@ -683,7 +683,7 @@ void usb_set_maxpacket(struct usb_device *dev)
/* NOTE: affects all endpoints _except_ ep0 */ /* NOTE: affects all endpoints _except_ ep0 */
for (i=0; i<dev->actconfig->desc.bNumInterfaces; i++) { for (i=0; i<dev->actconfig->desc.bNumInterfaces; i++) {
struct usb_interface *ifp = dev->actconfig->pinterface + i; struct usb_interface *ifp = dev->actconfig->interface + i;
struct usb_host_interface *as = ifp->altsetting + ifp->act_altsetting; struct usb_host_interface *as = ifp->altsetting + ifp->act_altsetting;
struct usb_host_endpoint *ep = as->endpoint; struct usb_host_endpoint *ep = as->endpoint;
int e; int e;
@ -800,16 +800,16 @@ int usb_clear_halt(struct usb_device *dev, int pipe)
* Returns zero on success, or else the status code returned by the * Returns zero on success, or else the status code returned by the
* underlying usb_control_msg() call. * underlying usb_control_msg() call.
*/ */
int usb_set_interface(struct usb_device *dev, int pinterface, int alternate) int usb_set_interface(struct usb_device *dev, int interface, int alternate)
{ {
struct usb_interface *iface; struct usb_interface *iface;
struct usb_host_interface *iface_as; struct usb_host_interface *iface_as;
int i, ret; int i, ret;
void (*disable)(struct usb_device *, int) = dev->bus->op->disable; void (*disable)(struct usb_device *, int) = dev->bus->op->disable;
iface = usb_ifnum_to_if(dev, pinterface); iface = usb_ifnum_to_if(dev, interface);
if (!iface) { if (!iface) {
warn("selecting invalid interface %d", pinterface); warn("selecting invalid interface %d", interface);
return -EINVAL; return -EINVAL;
} }
@ -817,7 +817,7 @@ int usb_set_interface(struct usb_device *dev, int pinterface, int alternate)
only has one alternate setting */ only has one alternate setting */
if (iface->num_altsetting == 1) { if (iface->num_altsetting == 1) {
dbg("ignoring set_interface for dev %d, iface %d, alt %d", dbg("ignoring set_interface for dev %d, iface %d, alt %d",
dev->devnum, pinterface, alternate); dev->devnum, interface, alternate);
return 0; return 0;
} }
@ -828,7 +828,7 @@ int usb_set_interface(struct usb_device *dev, int pinterface, int alternate)
USB_REQ_SET_INTERFACE, USB_RECIP_INTERFACE, USB_REQ_SET_INTERFACE, USB_RECIP_INTERFACE,
iface->altsetting[alternate] iface->altsetting[alternate]
.desc.bAlternateSetting, .desc.bAlternateSetting,
pinterface, NULL, 0, HZ * 5)) < 0) interface, NULL, 0, HZ * 5)) < 0)
return ret; return ret;
/* FIXME drivers shouldn't need to replicate/bugfix the logic here /* FIXME drivers shouldn't need to replicate/bugfix the logic here

View file

@ -42,7 +42,7 @@ static void usb_show_config(struct usb_host_config *config)
usb_show_config_descriptor(&config->desc); usb_show_config_descriptor(&config->desc);
for (i = 0; i < config->desc.bNumInterfaces; i++) { for (i = 0; i < config->desc.bNumInterfaces; i++) {
ifp = config->pinterface + i; ifp = config->interface + i;
if (!ifp) if (!ifp)
break; break;

View file

@ -212,9 +212,9 @@ struct usb_interface *usb_ifnum_to_if(struct usb_device *dev, unsigned ifnum)
int i; int i;
for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++)
if (dev->actconfig->pinterface[i].altsetting[0] if (dev->actconfig->interface[i].altsetting[0]
.desc.bInterfaceNumber == ifnum) .desc.bInterfaceNumber == ifnum)
return &dev->actconfig->pinterface[i]; return &dev->actconfig->interface[i];
return NULL; return NULL;
} }
@ -239,13 +239,13 @@ usb_epnum_to_ep_desc(struct usb_device *dev, unsigned epnum)
int i, j, k; int i, j, k;
for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++)
for (j = 0; j < dev->actconfig->pinterface[i].num_altsetting; j++) for (j = 0; j < dev->actconfig->interface[i].num_altsetting; j++)
for (k = 0; k < dev->actconfig->pinterface[i] for (k = 0; k < dev->actconfig->interface[i]
.altsetting[j].desc.bNumEndpoints; k++) .altsetting[j].desc.bNumEndpoints; k++)
if (epnum == dev->actconfig->pinterface[i] if (epnum == dev->actconfig->interface[i]
.altsetting[j].endpoint[k] .altsetting[j].endpoint[k]
.desc.bEndpointAddress) .desc.bEndpointAddress)
return &dev->actconfig->pinterface[i] return &dev->actconfig->interface[i]
.altsetting[j].endpoint[k] .altsetting[j].endpoint[k]
.desc; .desc;
@ -392,7 +392,7 @@ void usb_driver_release_interface(struct usb_driver *driver, struct usb_interfac
* its associated class and subclass. * its associated class and subclass.
*/ */
const struct usb_device_id * const struct usb_device_id *
usb_match_id(struct usb_interface *pinterface, const struct usb_device_id *id) usb_match_id(struct usb_interface *interface, const struct usb_device_id *id)
{ {
struct usb_host_interface *intf; struct usb_host_interface *intf;
struct usb_device *dev; struct usb_device *dev;
@ -401,8 +401,8 @@ usb_match_id(struct usb_interface *pinterface, const struct usb_device_id *id)
if (id == NULL) if (id == NULL)
return NULL; return NULL;
intf = &pinterface->altsetting [pinterface->act_altsetting]; intf = &interface->altsetting [interface->act_altsetting];
dev = interface_to_usbdev(pinterface); dev = interface_to_usbdev(interface);
/* It is important to check that id->driver_info is nonzero, /* It is important to check that id->driver_info is nonzero,
since an entry that is all zeroes except for a nonzero since an entry that is all zeroes except for a nonzero
@ -902,11 +902,11 @@ void usb_disconnect(struct usb_device **pdev)
dev_dbg (&dev->dev, "unregistering interfaces\n"); dev_dbg (&dev->dev, "unregistering interfaces\n");
if (dev->actconfig) { if (dev->actconfig) {
for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) { for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) {
struct usb_interface *pinterface; struct usb_interface *interface;
/* remove this interface */ /* remove this interface */
pinterface = &dev->actconfig->pinterface[i]; interface = &dev->actconfig->interface[i];
device_unregister(&pinterface->dev); device_unregister(&interface->dev);
} }
} }
@ -1210,35 +1210,35 @@ int usb_new_device(struct usb_device *dev, struct device *parent)
/* Register all of the interfaces for this device with the driver core. /* Register all of the interfaces for this device with the driver core.
* Remember, interfaces get bound to drivers, not devices. */ * Remember, interfaces get bound to drivers, not devices. */
for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) { for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) {
struct usb_interface *pinterface = &dev->actconfig->pinterface[i]; struct usb_interface *interface = &dev->actconfig->interface[i];
struct usb_interface_descriptor *desc; struct usb_interface_descriptor *desc;
desc = &pinterface->altsetting [pinterface->act_altsetting].desc; desc = &interface->altsetting [interface->act_altsetting].desc;
pinterface->dev.parent = &dev->dev; interface->dev.parent = &dev->dev;
pinterface->dev.driver = NULL; interface->dev.driver = NULL;
pinterface->dev.bus = &usb_bus_type; interface->dev.bus = &usb_bus_type;
pinterface->dev.dma_mask = parent->dma_mask; interface->dev.dma_mask = parent->dma_mask;
sprintf (&pinterface->dev.bus_id[0], "%d-%s:%d", sprintf (&interface->dev.bus_id[0], "%d-%s:%d",
dev->bus->busnum, dev->devpath, dev->bus->busnum, dev->devpath,
desc->bInterfaceNumber); desc->bInterfaceNumber);
if (!desc->iInterface if (!desc->iInterface
|| usb_string (dev, desc->iInterface, || usb_string (dev, desc->iInterface,
pinterface->dev.name, interface->dev.name,
sizeof pinterface->dev.name) <= 0) { sizeof interface->dev.name) <= 0) {
/* typically devices won't bother with interface /* typically devices won't bother with interface
* descriptions; this is the normal case. an * descriptions; this is the normal case. an
* interface's driver might describe it better. * interface's driver might describe it better.
* (also: iInterface is per-altsetting ...) * (also: iInterface is per-altsetting ...)
*/ */
sprintf (&pinterface->dev.name[0], sprintf (&interface->dev.name[0],
"usb-%s-%s interface %d", "usb-%s-%s interface %d",
dev->bus->bus_name, dev->devpath, dev->bus->bus_name, dev->devpath,
desc->bInterfaceNumber); desc->bInterfaceNumber);
DPRINT1("usb_new_device: %s\n", pinterface->dev.name); DPRINT1("usb_new_device: %s\n", interface->dev.name);
} }
dev_dbg (&dev->dev, "%s - registering interface %s\n", __FUNCTION__, pinterface->dev.bus_id); dev_dbg (&dev->dev, "%s - registering interface %s\n", __FUNCTION__, interface->dev.bus_id);
device_add (&pinterface->dev); device_add (&interface->dev);
usb_create_driverfs_intf_files (pinterface); usb_create_driverfs_intf_files (interface);
} }
/* add a /proc/bus/usb entry */ /* add a /proc/bus/usb entry */
usbfs_add_device(dev); usbfs_add_device(dev);

View file

@ -150,12 +150,12 @@ static inline void usb_set_intfdata (struct usb_interface *intf, void *data)
*/ */
struct usb_host_config { struct usb_host_config {
struct usb_config_descriptor desc; struct usb_config_descriptor desc;
//
// /* the interfaces associated with this configuration /* the interfaces associated with this configuration
// * these will be in numeric order, 0..desc.bNumInterfaces * these will be in numeric order, 0..desc.bNumInterfaces
// */ */
//
struct usb_interface *pinterface; struct usb_interface *interface;
unsigned char *extra; /* Extra descriptors */ unsigned char *extra; /* Extra descriptors */
int extralen; int extralen;
@ -292,7 +292,7 @@ extern void usb_driver_claim_interface(struct usb_driver *driver,
extern int usb_interface_claimed(struct usb_interface *iface); extern int usb_interface_claimed(struct usb_interface *iface);
extern void usb_driver_release_interface(struct usb_driver *driver, extern void usb_driver_release_interface(struct usb_driver *driver,
struct usb_interface *iface); struct usb_interface *iface);
const struct usb_device_id *usb_match_id(struct usb_interface *pinterface, const struct usb_device_id *usb_match_id(struct usb_interface *interface,
const struct usb_device_id *id); const struct usb_device_id *id);
extern struct usb_interface *usb_find_interface(struct usb_driver *drv, int minor); extern struct usb_interface *usb_find_interface(struct usb_driver *drv, int minor);

View file

@ -2,7 +2,6 @@
//#include <ntos/types.h> //#include <ntos/types.h>
//#include <ddk/extypes.h> //#include <ddk/extypes.h>
#include <ddk/ntddk.h> #include <ddk/ntddk.h>
#define NDEBUG
#include <debug.h> #include <debug.h>
void wait_ms(int mils); void wait_ms(int mils);
@ -17,6 +16,8 @@ int sprintf(char * buf, const char *fmt, ...);
int swprintf(wchar_t *buf, const wchar_t *fmt, ...); int swprintf(wchar_t *buf, const wchar_t *fmt, ...);
#endif #endif
#undef interface
#include "linux/linux_wrapper.h" #include "linux/linux_wrapper.h"
#define __KERNEL__ #define __KERNEL__
#undef CONFIG_PCI #undef CONFIG_PCI