remove get_endpoint_descriptor and change all functions needing

descriptor to just receive it as argument rather than endpoint
	address.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2013-03-19 11:19:36 +01:00
parent 5dd6f58789
commit e5a2dd7b55
11 changed files with 51 additions and 70 deletions

View file

@ -1,3 +1,9 @@
2013-03-19 Vladimir Serbinenko <phcoder@gmail.com>
remove get_endpoint_descriptor and change all functions needing
descriptor to just receive it as argument rather than endpoint
address.
2013-03-19 Aleš Nesrsta <starous@volny.cz> 2013-03-19 Aleš Nesrsta <starous@volny.cz>
Better estimate the maximum USB transfer size. Better estimate the maximum USB transfer size.

View file

@ -124,7 +124,7 @@ grub_usbserial_fetch (struct grub_serial_port *port, grub_size_t header_size)
if (port->bufstart < port->bufend) if (port->bufstart < port->bufend)
return port->buf[port->bufstart++]; return port->buf[port->bufstart++];
err = grub_usb_bulk_read_extended (port->usbdev, port->in_endp->endp_addr, err = grub_usb_bulk_read_extended (port->usbdev, port->in_endp,
sizeof (port->buf), port->buf, 10, sizeof (port->buf), port->buf, 10,
&actual); &actual);
if (err != GRUB_USB_ERR_NONE) if (err != GRUB_USB_ERR_NONE)

View file

@ -128,7 +128,7 @@ ftdi_hw_put (struct grub_serial_port *port, const int c)
real_config (port); real_config (port);
grub_usb_bulk_write (port->usbdev, port->out_endp->endp_addr, 1, &cc); grub_usb_bulk_write (port->usbdev, port->out_endp, 1, &cc);
} }
static grub_err_t static grub_err_t

View file

@ -146,7 +146,7 @@ pl2303_hw_put (struct grub_serial_port *port, const int c)
real_config (port); real_config (port);
grub_usb_bulk_write (port->usbdev, port->out_endp->endp_addr, 1, &cc); grub_usb_bulk_write (port->usbdev, port->out_endp, 1, &cc);
} }
static grub_err_t static grub_err_t

View file

@ -41,7 +41,7 @@ usbdebug_late_hw_put (struct grub_serial_port *port, const int c)
{ {
char cc = c; char cc = c;
grub_usb_bulk_write (port->usbdev, port->out_endp->endp_addr, 1, &cc); grub_usb_bulk_write (port->usbdev, port->out_endp, 1, &cc);
} }
static grub_err_t static grub_err_t

View file

@ -147,31 +147,6 @@ grub_usb_get_descriptor (grub_usb_device_t dev,
0, size, data); 0, size, data);
} }
struct grub_usb_desc_endp *
grub_usb_get_endpdescriptor (grub_usb_device_t usbdev, int addr)
{
int i;
for (i = 0; i < usbdev->config[0].descconf->numif; i++)
{
struct grub_usb_desc_if *interf;
int j;
interf = usbdev->config[0].interf[i].descif;
for (j = 0; j < interf->endpointcnt; j++)
{
struct grub_usb_desc_endp *endp;
endp = &usbdev->config[0].interf[i].descendp[j];
if (endp->endp_addr == addr)
return endp;
}
}
return NULL;
}
grub_usb_err_t grub_usb_err_t
grub_usb_device_initialize (grub_usb_device_t dev) grub_usb_device_initialize (grub_usb_device_t dev)
{ {

View file

@ -173,7 +173,7 @@ grub_usb_add_hub (grub_usb_device_t dev)
if (len > sizeof (dev->statuschange)) if (len > sizeof (dev->statuschange))
len = sizeof (dev->statuschange); len = sizeof (dev->statuschange);
dev->hub_transfer dev->hub_transfer
= grub_usb_bulk_read_background (dev, endp->endp_addr, len, = grub_usb_bulk_read_background (dev, endp, len,
(char *) &dev->statuschange); (char *) &dev->statuschange);
break; break;
} }
@ -342,7 +342,7 @@ poll_nonroot_hub (grub_usb_device_t dev)
if (len > sizeof (dev->statuschange)) if (len > sizeof (dev->statuschange))
len = sizeof (dev->statuschange); len = sizeof (dev->statuschange);
dev->hub_transfer dev->hub_transfer
= grub_usb_bulk_read_background (dev, dev->hub_endpoint->endp_addr, len, = grub_usb_bulk_read_background (dev, dev->hub_endpoint, len,
(char *) &dev->statuschange); (char *) &dev->statuschange);
if (err || actual == 0 || changed == 0) if (err || actual == 0 || changed == 0)

View file

@ -27,21 +27,14 @@
static inline unsigned int static inline unsigned int
grub_usb_bulk_maxpacket (grub_usb_device_t dev, int endpoint) grub_usb_bulk_maxpacket (grub_usb_device_t dev,
struct grub_usb_desc_endp *endpoint)
{ {
unsigned int max = 64;
/* Use the maximum packet size given in the endpoint descriptor. */ /* Use the maximum packet size given in the endpoint descriptor. */
if (dev->initialized) if (dev->initialized && endpoint)
{ return endpoint->maxpacket;
struct grub_usb_desc_endp *endpdesc;
endpdesc = grub_usb_get_endpdescriptor (dev, endpoint);
if (endpdesc) return 64;
max = endpdesc->maxpacket;
}
return max;
} }
@ -219,7 +212,8 @@ grub_usb_control_msg (grub_usb_device_t dev,
static grub_usb_transfer_t static grub_usb_transfer_t
grub_usb_bulk_setup_readwrite (grub_usb_device_t dev, grub_usb_bulk_setup_readwrite (grub_usb_device_t dev,
int endpoint, grub_size_t size0, char *data_in, struct grub_usb_desc_endp *endpoint,
grub_size_t size0, char *data_in,
grub_transfer_type_t type) grub_transfer_type_t type)
{ {
int i; int i;
@ -230,7 +224,7 @@ grub_usb_bulk_setup_readwrite (grub_usb_device_t dev,
grub_uint32_t data_addr; grub_uint32_t data_addr;
struct grub_pci_dma_chunk *data_chunk; struct grub_pci_dma_chunk *data_chunk;
grub_size_t size = size0; grub_size_t size = size0;
int toggle = dev->toggle[endpoint]; int toggle = dev->toggle[endpoint->endp_addr];
grub_dprintf ("usb", "bulk: size=0x%02lx type=%d\n", (unsigned long) size, grub_dprintf ("usb", "bulk: size=0x%02lx type=%d\n", (unsigned long) size,
type); type);
@ -257,7 +251,7 @@ grub_usb_bulk_setup_readwrite (grub_usb_device_t dev,
datablocks = ((size + max - 1) / max); datablocks = ((size + max - 1) / max);
transfer->transcnt = datablocks; transfer->transcnt = datablocks;
transfer->size = size - 1; transfer->size = size - 1;
transfer->endpoint = endpoint; transfer->endpoint = endpoint->endp_addr;
transfer->devaddr = dev->addr; transfer->devaddr = dev->addr;
transfer->type = GRUB_USB_TRANSACTION_TYPE_BULK; transfer->type = GRUB_USB_TRANSACTION_TYPE_BULK;
transfer->dir = type; transfer->dir = type;
@ -323,7 +317,8 @@ grub_usb_bulk_finish_readwrite (grub_usb_transfer_t transfer)
static grub_usb_err_t static grub_usb_err_t
grub_usb_bulk_readwrite (grub_usb_device_t dev, grub_usb_bulk_readwrite (grub_usb_device_t dev,
int endpoint, grub_size_t size0, char *data_in, struct grub_usb_desc_endp *endpoint,
grub_size_t size0, char *data_in,
grub_transfer_type_t type, int timeout, grub_transfer_type_t type, int timeout,
grub_size_t *actual) grub_size_t *actual)
{ {
@ -343,7 +338,7 @@ grub_usb_bulk_readwrite (grub_usb_device_t dev,
static grub_usb_err_t static grub_usb_err_t
grub_usb_bulk_readwrite_packetize (grub_usb_device_t dev, grub_usb_bulk_readwrite_packetize (grub_usb_device_t dev,
int endpoint, struct grub_usb_desc_endp *endpoint,
grub_transfer_type_t type, grub_transfer_type_t type,
grub_size_t size, char *data) grub_size_t size, char *data)
{ {
@ -380,7 +375,8 @@ grub_usb_bulk_readwrite_packetize (grub_usb_device_t dev,
grub_usb_err_t grub_usb_err_t
grub_usb_bulk_write (grub_usb_device_t dev, grub_usb_bulk_write (grub_usb_device_t dev,
int endpoint, grub_size_t size, char *data) struct grub_usb_desc_endp *endpoint,
grub_size_t size, char *data)
{ {
return grub_usb_bulk_readwrite_packetize (dev, endpoint, return grub_usb_bulk_readwrite_packetize (dev, endpoint,
GRUB_USB_TRANSFER_TYPE_OUT, GRUB_USB_TRANSFER_TYPE_OUT,
@ -389,7 +385,8 @@ grub_usb_bulk_write (grub_usb_device_t dev,
grub_usb_err_t grub_usb_err_t
grub_usb_bulk_read (grub_usb_device_t dev, grub_usb_bulk_read (grub_usb_device_t dev,
int endpoint, grub_size_t size, char *data) struct grub_usb_desc_endp *endpoint,
grub_size_t size, char *data)
{ {
return grub_usb_bulk_readwrite_packetize (dev, endpoint, return grub_usb_bulk_readwrite_packetize (dev, endpoint,
GRUB_USB_TRANSFER_TYPE_IN, GRUB_USB_TRANSFER_TYPE_IN,
@ -414,7 +411,8 @@ grub_usb_check_transfer (grub_usb_transfer_t transfer, grub_size_t *actual)
grub_usb_transfer_t grub_usb_transfer_t
grub_usb_bulk_read_background (grub_usb_device_t dev, grub_usb_bulk_read_background (grub_usb_device_t dev,
int endpoint, grub_size_t size, void *data) struct grub_usb_desc_endp *endpoint,
grub_size_t size, void *data)
{ {
grub_usb_err_t err; grub_usb_err_t err;
grub_usb_transfer_t transfer; grub_usb_transfer_t transfer;
@ -441,7 +439,8 @@ grub_usb_cancel_transfer (grub_usb_transfer_t transfer)
grub_usb_err_t grub_usb_err_t
grub_usb_bulk_read_extended (grub_usb_device_t dev, grub_usb_bulk_read_extended (grub_usb_device_t dev,
int endpoint, grub_size_t size, char *data, struct grub_usb_desc_endp *endpoint,
grub_size_t size, char *data,
int timeout, grub_size_t *actual) int timeout, grub_size_t *actual)
{ {
return grub_usb_bulk_readwrite (dev, endpoint, size, data, return grub_usb_bulk_readwrite (dev, endpoint, size, data,

View file

@ -326,7 +326,7 @@ grub_usbms_transfer_bo (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
/* Write the request. /* Write the request.
* XXX: Error recovery is maybe still not fully correct. */ * XXX: Error recovery is maybe still not fully correct. */
err = grub_usb_bulk_write (dev->dev, dev->out->endp_addr, err = grub_usb_bulk_write (dev->dev, dev->out,
sizeof (cbw), (char *) &cbw); sizeof (cbw), (char *) &cbw);
if (err) if (err)
{ {
@ -341,7 +341,7 @@ grub_usbms_transfer_bo (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
/* Read/write the data, (maybe) according to specification. */ /* Read/write the data, (maybe) according to specification. */
if (size && (read_write == 0)) if (size && (read_write == 0))
{ {
err = grub_usb_bulk_read (dev->dev, dev->in->endp_addr, size, buf); err = grub_usb_bulk_read (dev->dev, dev->in, size, buf);
grub_dprintf ("usb", "read: %d %d\n", err, GRUB_USB_ERR_STALL); grub_dprintf ("usb", "read: %d %d\n", err, GRUB_USB_ERR_STALL);
if (err) if (err)
{ {
@ -362,7 +362,7 @@ grub_usbms_transfer_bo (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
} }
else if (size) else if (size)
{ {
err = grub_usb_bulk_write (dev->dev, dev->out->endp_addr, size, buf); err = grub_usb_bulk_write (dev->dev, dev->out, size, buf);
grub_dprintf ("usb", "write: %d %d\n", err, GRUB_USB_ERR_STALL); grub_dprintf ("usb", "write: %d %d\n", err, GRUB_USB_ERR_STALL);
grub_dprintf ("usb", "First 16 bytes of sent data:\n %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", grub_dprintf ("usb", "First 16 bytes of sent data:\n %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
buf[ 0], buf[ 1], buf[ 2], buf[ 3], buf[ 0], buf[ 1], buf[ 2], buf[ 3],
@ -388,12 +388,12 @@ grub_usbms_transfer_bo (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
/* Read the status - (maybe) according to specification. */ /* Read the status - (maybe) according to specification. */
CheckCSW: CheckCSW:
errCSW = grub_usb_bulk_read (dev->dev, dev->in->endp_addr, errCSW = grub_usb_bulk_read (dev->dev, dev->in,
sizeof (status), (char *) &status); sizeof (status), (char *) &status);
if (errCSW) if (errCSW)
{ {
grub_usb_clear_halt (dev->dev, dev->in->endp_addr); grub_usb_clear_halt (dev->dev, dev->in->endp_addr);
errCSW = grub_usb_bulk_read (dev->dev, dev->in->endp_addr, errCSW = grub_usb_bulk_read (dev->dev, dev->in,
sizeof (status), (char *) &status); sizeof (status), (char *) &status);
if (errCSW) if (errCSW)
{ /* Bulk-only reset device. */ { /* Bulk-only reset device. */
@ -476,7 +476,7 @@ grub_usbms_transfer_cbi (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
else if (dev->protocol == GRUB_USBMS_PROTOCOL_CBI) else if (dev->protocol == GRUB_USBMS_PROTOCOL_CBI)
{ {
/* Try to get status from interrupt pipe */ /* Try to get status from interrupt pipe */
err = grub_usb_bulk_read (dev->dev, dev->intrpt->endp_addr, err = grub_usb_bulk_read (dev->dev, dev->intrpt,
2, (char*)&status); 2, (char*)&status);
grub_dprintf ("usb", "CBI cmdcb setup status: err=%d, status=0x%x\n", err, status); grub_dprintf ("usb", "CBI cmdcb setup status: err=%d, status=0x%x\n", err, status);
} }
@ -487,7 +487,7 @@ grub_usbms_transfer_cbi (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
/* Read/write the data, (maybe) according to specification. */ /* Read/write the data, (maybe) according to specification. */
if (size && (read_write == 0)) if (size && (read_write == 0))
{ {
err = grub_usb_bulk_read (dev->dev, dev->in->endp_addr, size, buf); err = grub_usb_bulk_read (dev->dev, dev->in, size, buf);
grub_dprintf ("usb", "read: %d\n", err); grub_dprintf ("usb", "read: %d\n", err);
if (err) if (err)
{ {
@ -498,7 +498,7 @@ grub_usbms_transfer_cbi (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
} }
else if (size) else if (size)
{ {
err = grub_usb_bulk_write (dev->dev, dev->out->endp_addr, size, buf); err = grub_usb_bulk_write (dev->dev, dev->out, size, buf);
grub_dprintf ("usb", "write: %d\n", err); grub_dprintf ("usb", "write: %d\n", err);
if (err) if (err)
{ {
@ -517,7 +517,7 @@ grub_usbms_transfer_cbi (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
* (we do not it yet) - ? */ * (we do not it yet) - ? */
if (dev->protocol == GRUB_USBMS_PROTOCOL_CBI) if (dev->protocol == GRUB_USBMS_PROTOCOL_CBI)
{ /* Check status in interrupt pipe */ { /* Check status in interrupt pipe */
err = grub_usb_bulk_read (dev->dev, dev->intrpt->endp_addr, err = grub_usb_bulk_read (dev->dev, dev->intrpt,
2, (char*)&status); 2, (char*)&status);
grub_dprintf ("usb", "read status: %d\n", err); grub_dprintf ("usb", "read status: %d\n", err);
if (err) if (err)

View file

@ -244,7 +244,7 @@ grub_usb_keyboard_attach (grub_usb_device_t usbdev, int configno, int interfno)
#endif #endif
data->transfer = grub_usb_bulk_read_background (usbdev, data->transfer = grub_usb_bulk_read_background (usbdev,
data->endp->endp_addr, data->endp,
sizeof (data->report), sizeof (data->report),
(char *) data->report); (char *) data->report);
if (!data->transfer) if (!data->transfer)
@ -394,7 +394,7 @@ grub_usb_keyboard_getkey (struct grub_term_input *term)
sizeof (termdata->report)); sizeof (termdata->report));
termdata->transfer = grub_usb_bulk_read_background (termdata->usbdev, termdata->transfer = grub_usb_bulk_read_background (termdata->usbdev,
termdata->endp->endp_addr, termdata->endp,
sizeof (termdata->report), sizeof (termdata->report),
(char *) termdata->report); (char *) termdata->report);
if (!termdata->transfer) if (!termdata->transfer)

View file

@ -63,9 +63,6 @@ grub_usb_err_t grub_usb_get_descriptor (grub_usb_device_t dev,
grub_uint8_t type, grub_uint8_t index, grub_uint8_t type, grub_uint8_t index,
grub_size_t size, char *data); grub_size_t size, char *data);
struct grub_usb_desc_endp *
grub_usb_get_endpdescriptor (grub_usb_device_t usbdev, int addr);
grub_usb_err_t grub_usb_clear_halt (grub_usb_device_t dev, int endpoint); grub_usb_err_t grub_usb_clear_halt (grub_usb_device_t dev, int endpoint);
@ -87,10 +84,12 @@ grub_usb_err_t grub_usb_control_msg (grub_usb_device_t dev, grub_uint8_t reqtype
grub_usb_err_t grub_usb_err_t
grub_usb_bulk_read (grub_usb_device_t dev, grub_usb_bulk_read (grub_usb_device_t dev,
int endpoint, grub_size_t size, char *data); struct grub_usb_desc_endp *endpoint,
grub_size_t size, char *data);
grub_usb_err_t grub_usb_err_t
grub_usb_bulk_write (grub_usb_device_t dev, grub_usb_bulk_write (grub_usb_device_t dev,
int endpoint, grub_size_t size, char *data); struct grub_usb_desc_endp *endpoint,
grub_size_t size, char *data);
grub_usb_err_t grub_usb_err_t
grub_usb_root_hub (grub_usb_controller_t controller); grub_usb_root_hub (grub_usb_controller_t controller);
@ -297,11 +296,13 @@ void grub_usb_poll_devices (void);
void grub_usb_device_attach (grub_usb_device_t dev); void grub_usb_device_attach (grub_usb_device_t dev);
grub_usb_err_t grub_usb_err_t
grub_usb_bulk_read_extended (grub_usb_device_t dev, grub_usb_bulk_read_extended (grub_usb_device_t dev,
int endpoint, grub_size_t size, char *data, struct grub_usb_desc_endp *endpoint,
grub_size_t size, char *data,
int timeout, grub_size_t *actual); int timeout, grub_size_t *actual);
grub_usb_transfer_t grub_usb_transfer_t
grub_usb_bulk_read_background (grub_usb_device_t dev, grub_usb_bulk_read_background (grub_usb_device_t dev,
int endpoint, grub_size_t size, void *data); struct grub_usb_desc_endp *endpoint,
grub_size_t size, void *data);
grub_usb_err_t grub_usb_err_t
grub_usb_check_transfer (grub_usb_transfer_t trans, grub_size_t *actual); grub_usb_check_transfer (grub_usb_transfer_t trans, grub_size_t *actual);
void void