grub2/0212-remove-get_endpoint_descriptor-and-change-all-functi.patch

416 lines
15 KiB
Diff
Raw Normal View History

2013-06-07 18:03:56 +00:00
From f6ca5450858cedbe0fc18c973fc19e1242f71f45 Mon Sep 17 00:00:00 2001
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Date: Tue, 19 Mar 2013 11:19:36 +0100
2013-06-07 18:03:56 +00:00
Subject: [PATCH 212/471] remove get_endpoint_descriptor and change all
functions needing descriptor to just receive it as argument rather than
endpoint address.
---
ChangeLog | 6 +++++
grub-core/bus/usb/serial/common.c | 2 +-
grub-core/bus/usb/serial/ftdi.c | 2 +-
grub-core/bus/usb/serial/pl2303.c | 2 +-
grub-core/bus/usb/serial/usbdebug_late.c | 2 +-
grub-core/bus/usb/usb.c | 25 -------------------
grub-core/bus/usb/usbhub.c | 4 ++--
grub-core/bus/usb/usbtrans.c | 41 ++++++++++++++++----------------
grub-core/disk/usbms.c | 18 +++++++-------
grub-core/term/usb_keyboard.c | 4 ++--
include/grub/usb.h | 15 ++++++------
11 files changed, 51 insertions(+), 70 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index d331cb4..a544fbf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
Better estimate the maximum USB transfer size.
diff --git a/grub-core/bus/usb/serial/common.c b/grub-core/bus/usb/serial/common.c
index 06f2b0e..8e94c7d 100644
--- a/grub-core/bus/usb/serial/common.c
+++ b/grub-core/bus/usb/serial/common.c
@@ -124,7 +124,7 @@ grub_usbserial_fetch (struct grub_serial_port *port, grub_size_t header_size)
if (port->bufstart < port->bufend)
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,
&actual);
if (err != GRUB_USB_ERR_NONE)
diff --git a/grub-core/bus/usb/serial/ftdi.c b/grub-core/bus/usb/serial/ftdi.c
index e94fd27..25c1d6f 100644
--- a/grub-core/bus/usb/serial/ftdi.c
+++ b/grub-core/bus/usb/serial/ftdi.c
@@ -128,7 +128,7 @@ ftdi_hw_put (struct grub_serial_port *port, const int c)
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
diff --git a/grub-core/bus/usb/serial/pl2303.c b/grub-core/bus/usb/serial/pl2303.c
index f46c6ac..92b00ef 100644
--- a/grub-core/bus/usb/serial/pl2303.c
+++ b/grub-core/bus/usb/serial/pl2303.c
@@ -146,7 +146,7 @@ pl2303_hw_put (struct grub_serial_port *port, const int c)
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
diff --git a/grub-core/bus/usb/serial/usbdebug_late.c b/grub-core/bus/usb/serial/usbdebug_late.c
index 23526e1..e88ba13 100644
--- a/grub-core/bus/usb/serial/usbdebug_late.c
+++ b/grub-core/bus/usb/serial/usbdebug_late.c
@@ -41,7 +41,7 @@ usbdebug_late_hw_put (struct grub_serial_port *port, const int 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
diff --git a/grub-core/bus/usb/usb.c b/grub-core/bus/usb/usb.c
index 41d8010..7a517f8 100644
--- a/grub-core/bus/usb/usb.c
+++ b/grub-core/bus/usb/usb.c
@@ -147,31 +147,6 @@ grub_usb_get_descriptor (grub_usb_device_t dev,
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_device_initialize (grub_usb_device_t dev)
{
diff --git a/grub-core/bus/usb/usbhub.c b/grub-core/bus/usb/usbhub.c
index 3927f51..7e7dc8c 100644
--- a/grub-core/bus/usb/usbhub.c
+++ b/grub-core/bus/usb/usbhub.c
@@ -173,7 +173,7 @@ grub_usb_add_hub (grub_usb_device_t dev)
if (len > sizeof (dev->statuschange))
len = sizeof (dev->statuschange);
dev->hub_transfer
- = grub_usb_bulk_read_background (dev, endp->endp_addr, len,
+ = grub_usb_bulk_read_background (dev, endp, len,
(char *) &dev->statuschange);
break;
}
@@ -342,7 +342,7 @@ poll_nonroot_hub (grub_usb_device_t dev)
if (len > sizeof (dev->statuschange))
len = sizeof (dev->statuschange);
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);
if (err || actual == 0 || changed == 0)
diff --git a/grub-core/bus/usb/usbtrans.c b/grub-core/bus/usb/usbtrans.c
index 4c4d8b4..533c3e7 100644
--- a/grub-core/bus/usb/usbtrans.c
+++ b/grub-core/bus/usb/usbtrans.c
@@ -27,21 +27,14 @@
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. */
- if (dev->initialized)
- {
- struct grub_usb_desc_endp *endpdesc;
- endpdesc = grub_usb_get_endpdescriptor (dev, endpoint);
-
- if (endpdesc)
- max = endpdesc->maxpacket;
- }
+ if (dev->initialized && endpoint)
+ return endpoint->maxpacket;
- return max;
+ return 64;
}
@@ -219,7 +212,8 @@ grub_usb_control_msg (grub_usb_device_t dev,
static grub_usb_transfer_t
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)
{
int i;
@@ -230,7 +224,7 @@ grub_usb_bulk_setup_readwrite (grub_usb_device_t dev,
grub_uint32_t data_addr;
struct grub_pci_dma_chunk *data_chunk;
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,
type);
@@ -257,7 +251,7 @@ grub_usb_bulk_setup_readwrite (grub_usb_device_t dev,
datablocks = ((size + max - 1) / max);
transfer->transcnt = datablocks;
transfer->size = size - 1;
- transfer->endpoint = endpoint;
+ transfer->endpoint = endpoint->endp_addr;
transfer->devaddr = dev->addr;
transfer->type = GRUB_USB_TRANSACTION_TYPE_BULK;
transfer->dir = type;
@@ -323,7 +317,8 @@ grub_usb_bulk_finish_readwrite (grub_usb_transfer_t transfer)
static grub_usb_err_t
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_size_t *actual)
{
@@ -343,7 +338,7 @@ grub_usb_bulk_readwrite (grub_usb_device_t dev,
static grub_usb_err_t
grub_usb_bulk_readwrite_packetize (grub_usb_device_t dev,
- int endpoint,
+ struct grub_usb_desc_endp *endpoint,
grub_transfer_type_t type,
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_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,
GRUB_USB_TRANSFER_TYPE_OUT,
@@ -389,7 +385,8 @@ grub_usb_bulk_write (grub_usb_device_t dev,
grub_usb_err_t
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,
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_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_transfer_t transfer;
@@ -441,7 +439,8 @@ grub_usb_cancel_transfer (grub_usb_transfer_t transfer)
grub_usb_err_t
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)
{
return grub_usb_bulk_readwrite (dev, endpoint, size, data,
diff --git a/grub-core/disk/usbms.c b/grub-core/disk/usbms.c
index 50f0caf..dd35bff 100644
--- a/grub-core/disk/usbms.c
+++ b/grub-core/disk/usbms.c
@@ -326,7 +326,7 @@ grub_usbms_transfer_bo (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
/* Write the request.
* 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);
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. */
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);
if (err)
{
@@ -362,7 +362,7 @@ grub_usbms_transfer_bo (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
}
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", "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],
@@ -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. */
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);
if (errCSW)
{
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);
if (errCSW)
{ /* 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)
{
/* 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);
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. */
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);
if (err)
{
@@ -498,7 +498,7 @@ grub_usbms_transfer_cbi (struct grub_scsi *scsi, grub_size_t cmdsize, char *cmd,
}
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);
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) - ? */
if (dev->protocol == GRUB_USBMS_PROTOCOL_CBI)
{ /* 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);
grub_dprintf ("usb", "read status: %d\n", err);
if (err)
diff --git a/grub-core/term/usb_keyboard.c b/grub-core/term/usb_keyboard.c
index ae00936..3b74846 100644
--- a/grub-core/term/usb_keyboard.c
+++ b/grub-core/term/usb_keyboard.c
@@ -244,7 +244,7 @@ grub_usb_keyboard_attach (grub_usb_device_t usbdev, int configno, int interfno)
#endif
data->transfer = grub_usb_bulk_read_background (usbdev,
- data->endp->endp_addr,
+ data->endp,
sizeof (data->report),
(char *) data->report);
if (!data->transfer)
@@ -394,7 +394,7 @@ grub_usb_keyboard_getkey (struct grub_term_input *term)
sizeof (termdata->report));
termdata->transfer = grub_usb_bulk_read_background (termdata->usbdev,
- termdata->endp->endp_addr,
+ termdata->endp,
sizeof (termdata->report),
(char *) termdata->report);
if (!termdata->transfer)
diff --git a/include/grub/usb.h b/include/grub/usb.h
index 55f65f7..32f0ecd 100644
--- a/include/grub/usb.h
+++ b/include/grub/usb.h
@@ -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_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);
@@ -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_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_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_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);
grub_usb_err_t
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);
grub_usb_transfer_t
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_check_transfer (grub_usb_transfer_t trans, grub_size_t *actual);
void
--
2013-06-07 18:03:56 +00:00
1.8.2.1