On Sun, Apr 10, 2022 at 03:28:41PM +0200, Christian Weisgerber wrote:

> Marcus Glocker:
> 
> > > This constifies the bus method and pipe method tables in our USB
> > > host controller drivers.
> > 
> > dwctwo(4) also exists on arm64.
> 
> Oops, right.  That arch I have.
> 
> The USB host controller drivers also have another set of tables to
> emulate the root hub.  I have extended the diff to constify those
> as well.  xhci(4) and dwctwo(4) were already (partially) done.
> 
> The *_devd descriptor template poses a problem, because its idVendor
> member is modified before the descriptor is memcpy()'ed into a
> transmit buffer.  The copy can be truncated, so reordering the
> operations would lead to much ugliness.  I have introduced a temporary
> variable at the cost of another copy.  The code already does this
> for the *_hubd descriptor.
> 
> The NetBSD author of dwctwo(4) also ran into this problem, but
> didn't solve it, simply never setting idVendor, for which there is
> also no ready source absent a PCI bus attachment.  I _think_ the
> FreeBSD code for all host controllers doesn't bother setting idVendor
> either, so that may be another solution.

I was also initially tempted to suggest removal of sc_id_vendor.
But since we already take the effort to read it, I think lets keep it
there for now.
 
> Comments, okays?

ok mglocker@
 
> diff refs/heads/master refs/heads/usb
> blob - 9b9d1635f902afef00a4111dfba8f86d13f74b4e
> blob + 64dea91909ed4f77f7f24c61dd1c09809d27d031
> --- sys/dev/usb/dwc2/dwc2.c
> +++ sys/dev/usb/dwc2/dwc2.c
> @@ -146,7 +146,7 @@ dwc2_free_bus_bandwidth(struct dwc2_hsotg *hsotg, u16 
>  
>  #define DWC2_INTR_ENDPT 1
>  
> -STATIC struct usbd_bus_methods dwc2_bus_methods = {
> +STATIC const struct usbd_bus_methods dwc2_bus_methods = {
>       .open_pipe =    dwc2_open,
>       .dev_setaddr =  dwc2_setaddr,
>       .soft_intr =    dwc2_softintr,
> @@ -155,7 +155,7 @@ STATIC struct usbd_bus_methods dwc2_bus_methods = {
>       .freex =        dwc2_freex,
>  };
>  
> -STATIC struct usbd_pipe_methods dwc2_root_ctrl_methods = {
> +STATIC const struct usbd_pipe_methods dwc2_root_ctrl_methods = {
>       .transfer =     dwc2_root_ctrl_transfer,
>       .start =        dwc2_root_ctrl_start,
>       .abort =        dwc2_root_ctrl_abort,
> @@ -164,7 +164,7 @@ STATIC struct usbd_pipe_methods dwc2_root_ctrl_methods
>       .done =         dwc2_root_ctrl_done,
>  };
>  
> -STATIC struct usbd_pipe_methods dwc2_root_intr_methods = {
> +STATIC const struct usbd_pipe_methods dwc2_root_intr_methods = {
>       .transfer =     dwc2_root_intr_transfer,
>       .start =        dwc2_root_intr_start,
>       .abort =        dwc2_root_intr_abort,
> @@ -173,7 +173,7 @@ STATIC struct usbd_pipe_methods dwc2_root_intr_methods
>       .done =         dwc2_root_intr_done,
>  };
>  
> -STATIC struct usbd_pipe_methods dwc2_device_ctrl_methods = {
> +STATIC const struct usbd_pipe_methods dwc2_device_ctrl_methods = {
>       .transfer =     dwc2_device_ctrl_transfer,
>       .start =        dwc2_device_ctrl_start,
>       .abort =        dwc2_device_ctrl_abort,
> @@ -182,7 +182,7 @@ STATIC struct usbd_pipe_methods dwc2_device_ctrl_metho
>       .done =         dwc2_device_ctrl_done,
>  };
>  
> -STATIC struct usbd_pipe_methods dwc2_device_intr_methods = {
> +STATIC const struct usbd_pipe_methods dwc2_device_intr_methods = {
>       .transfer =     dwc2_device_intr_transfer,
>       .start =        dwc2_device_intr_start,
>       .abort =        dwc2_device_intr_abort,
> @@ -191,7 +191,7 @@ STATIC struct usbd_pipe_methods dwc2_device_intr_metho
>       .done =         dwc2_device_intr_done,
>  };
>  
> -STATIC struct usbd_pipe_methods dwc2_device_bulk_methods = {
> +STATIC const struct usbd_pipe_methods dwc2_device_bulk_methods = {
>       .transfer =     dwc2_device_bulk_transfer,
>       .start =        dwc2_device_bulk_start,
>       .abort =        dwc2_device_bulk_abort,
> @@ -200,7 +200,7 @@ STATIC struct usbd_pipe_methods dwc2_device_bulk_metho
>       .done =         dwc2_device_bulk_done,
>  };
>  
> -STATIC struct usbd_pipe_methods dwc2_device_isoc_methods = {
> +STATIC const struct usbd_pipe_methods dwc2_device_isoc_methods = {
>       .transfer =     dwc2_device_isoc_transfer,
>       .start =        dwc2_device_isoc_start,
>       .abort =        dwc2_device_isoc_abort,
> @@ -681,7 +681,6 @@ dwc2_root_ctrl_start(struct usbd_xfer *xfer)
>               switch (value) {
>               case C(0, UDESC_DEVICE):
>                       l = min(len, USB_DEVICE_DESCRIPTOR_SIZE);
> -//                   USETW(dwc2_devd.idVendor, sc->sc_id_vendor);
>                       memcpy(buf, &dwc2_devd, l);
>                       buf += l;
>                       len -= l;
> blob - 350580c00b30f8edcfd5edf8ad8d1734624462c6
> blob + 834e97310fb06a73bc569a943e4b0e7906c136d5
> --- sys/dev/usb/ehci.c
> +++ sys/dev/usb/ehci.c
> @@ -218,7 +218,7 @@ void              ehci_dump_exfer(struct ehci_xfer *);
>  
>  #define EHCI_INTR_ENDPT 1
>  
> -struct usbd_bus_methods ehci_bus_methods = {
> +const struct usbd_bus_methods ehci_bus_methods = {
>       .open_pipe = ehci_open,
>       .dev_setaddr = ehci_setaddr,
>       .soft_intr = ehci_softintr,
> @@ -227,7 +227,7 @@ struct usbd_bus_methods ehci_bus_methods = {
>       .freex = ehci_freex,
>  };
>  
> -struct usbd_pipe_methods ehci_root_ctrl_methods = {
> +const struct usbd_pipe_methods ehci_root_ctrl_methods = {
>       .transfer = ehci_root_ctrl_transfer,
>       .start = ehci_root_ctrl_start,
>       .abort = ehci_root_ctrl_abort,
> @@ -235,7 +235,7 @@ struct usbd_pipe_methods ehci_root_ctrl_methods = {
>       .done = ehci_root_ctrl_done,
>  };
>  
> -struct usbd_pipe_methods ehci_root_intr_methods = {
> +const struct usbd_pipe_methods ehci_root_intr_methods = {
>       .transfer = ehci_root_intr_transfer,
>       .start = ehci_root_intr_start,
>       .abort = ehci_root_intr_abort,
> @@ -243,7 +243,7 @@ struct usbd_pipe_methods ehci_root_intr_methods = {
>       .done = ehci_root_intr_done,
>  };
>  
> -struct usbd_pipe_methods ehci_device_ctrl_methods = {
> +const struct usbd_pipe_methods ehci_device_ctrl_methods = {
>       .transfer = ehci_device_ctrl_transfer,
>       .start = ehci_device_ctrl_start,
>       .abort = ehci_device_ctrl_abort,
> @@ -251,7 +251,7 @@ struct usbd_pipe_methods ehci_device_ctrl_methods = {
>       .done = ehci_device_ctrl_done,
>  };
>  
> -struct usbd_pipe_methods ehci_device_intr_methods = {
> +const struct usbd_pipe_methods ehci_device_intr_methods = {
>       .transfer = ehci_device_intr_transfer,
>       .start = ehci_device_intr_start,
>       .abort = ehci_device_intr_abort,
> @@ -260,7 +260,7 @@ struct usbd_pipe_methods ehci_device_intr_methods = {
>       .done = ehci_device_intr_done,
>  };
>  
> -struct usbd_pipe_methods ehci_device_bulk_methods = {
> +const struct usbd_pipe_methods ehci_device_bulk_methods = {
>       .transfer = ehci_device_bulk_transfer,
>       .start = ehci_device_bulk_start,
>       .abort = ehci_device_bulk_abort,
> @@ -269,7 +269,7 @@ struct usbd_pipe_methods ehci_device_bulk_methods = {
>       .done = ehci_device_bulk_done,
>  };
>  
> -struct usbd_pipe_methods ehci_device_isoc_methods = {
> +const struct usbd_pipe_methods ehci_device_isoc_methods = {
>       .transfer = ehci_device_isoc_transfer,
>       .start = ehci_device_isoc_start,
>       .abort = ehci_device_isoc_abort,
> @@ -1705,7 +1705,7 @@ ehci_free_itd_chain(struct ehci_softc *sc, struct ehci
>  /*
>   * Data structures and routines to emulate the root hub.
>   */
> -usb_device_descriptor_t ehci_devd = {
> +const usb_device_descriptor_t ehci_devd = {
>       USB_DEVICE_DESCRIPTOR_SIZE,
>       UDESC_DEVICE,           /* type */
>       {0x00, 0x02},           /* USB version */
> @@ -1718,7 +1718,7 @@ usb_device_descriptor_t ehci_devd = {
>       1                       /* # of configurations */
>  };
>  
> -usb_device_qualifier_t ehci_odevd = {
> +const usb_device_qualifier_t ehci_odevd = {
>       USB_DEVICE_DESCRIPTOR_SIZE,
>       UDESC_DEVICE_QUALIFIER, /* type */
>       {0x00, 0x02},           /* USB version */
> @@ -1730,7 +1730,7 @@ usb_device_qualifier_t ehci_odevd = {
>       0
>  };
>  
> -usb_config_descriptor_t ehci_confd = {
> +const usb_config_descriptor_t ehci_confd = {
>       USB_CONFIG_DESCRIPTOR_SIZE,
>       UDESC_CONFIG,
>       {USB_CONFIG_DESCRIPTOR_SIZE +
> @@ -1743,7 +1743,7 @@ usb_config_descriptor_t ehci_confd = {
>       0                       /* max power */
>  };
>  
> -usb_interface_descriptor_t ehci_ifcd = {
> +const usb_interface_descriptor_t ehci_ifcd = {
>       USB_INTERFACE_DESCRIPTOR_SIZE,
>       UDESC_INTERFACE,
>       0,
> @@ -1755,7 +1755,7 @@ usb_interface_descriptor_t ehci_ifcd = {
>       0
>  };
>  
> -usb_endpoint_descriptor_t ehci_endpd = {
> +const usb_endpoint_descriptor_t ehci_endpd = {
>       USB_ENDPOINT_DESCRIPTOR_SIZE,
>       UDESC_ENDPOINT,
>       UE_DIR_IN | EHCI_INTR_ENDPT,
> @@ -1764,7 +1764,7 @@ usb_endpoint_descriptor_t ehci_endpd = {
>       12
>  };
>  
> -usb_hub_descriptor_t ehci_hubd = {
> +const usb_hub_descriptor_t ehci_hubd = {
>       USB_HUB_DESCRIPTOR_SIZE,
>       UDESC_HUB,
>       0,
> @@ -1800,6 +1800,7 @@ ehci_root_ctrl_start(struct usbd_xfer *xfer)
>       int port, i;
>       int s, len, value, index, l, totlen = 0;
>       usb_port_status_t ps;
> +     usb_device_descriptor_t devd;
>       usb_hub_descriptor_t hubd;
>       usbd_status err;
>       u_int32_t v;
> @@ -1848,9 +1849,10 @@ ehci_root_ctrl_start(struct usbd_xfer *xfer)
>                               err = USBD_IOERROR;
>                               goto ret;
>                       }
> +                     devd = ehci_devd;
> +                     USETW(devd.idVendor, sc->sc_id_vendor);
>                       totlen = l = min(len, USB_DEVICE_DESCRIPTOR_SIZE);
> -                     USETW(ehci_devd.idVendor, sc->sc_id_vendor);
> -                     memcpy(buf, &ehci_devd, l);
> +                     memcpy(buf, &devd, l);
>                       break;
>               case UDESC_DEVICE_QUALIFIER:
>                       if ((value & 0xff) != 0) {
> blob - 041e8328e9a0cd0a644eb45e50bc6ed478656640
> blob + 9805c9596a2ab92bb4d13b018ffc4c6f49f2ecae
> --- sys/dev/usb/ohci.c
> +++ sys/dev/usb/ohci.c
> @@ -197,7 +197,7 @@ OREAD4(struct ohci_softc *sc, bus_size_t r)
>  }
>  
>  /* Reverse the bits in a value 0 .. 31 */
> -u_int8_t revbits[OHCI_NO_INTRS] =
> +const u_int8_t revbits[OHCI_NO_INTRS] =
>    { 0x00, 0x10, 0x08, 0x18, 0x04, 0x14, 0x0c, 0x1c,
>      0x02, 0x12, 0x0a, 0x1a, 0x06, 0x16, 0x0e, 0x1e,
>      0x01, 0x11, 0x09, 0x19, 0x05, 0x15, 0x0d, 0x1d,
> @@ -229,7 +229,7 @@ struct ohci_pipe {
>  
>  #define OHCI_INTR_ENDPT 1
>  
> -struct usbd_bus_methods ohci_bus_methods = {
> +const struct usbd_bus_methods ohci_bus_methods = {
>       .open_pipe = ohci_open,
>       .dev_setaddr = ohci_setaddr,
>       .soft_intr = ohci_softintr,
> @@ -238,7 +238,7 @@ struct usbd_bus_methods ohci_bus_methods = {
>       .freex = ohci_freex,
>  };
>  
> -struct usbd_pipe_methods ohci_root_ctrl_methods = {
> +const struct usbd_pipe_methods ohci_root_ctrl_methods = {
>       .transfer = ohci_root_ctrl_transfer,
>       .start = ohci_root_ctrl_start,
>       .abort = ohci_root_ctrl_abort,
> @@ -246,7 +246,7 @@ struct usbd_pipe_methods ohci_root_ctrl_methods = {
>       .done = ohci_root_ctrl_done,
>  };
>  
> -struct usbd_pipe_methods ohci_root_intr_methods = {
> +const struct usbd_pipe_methods ohci_root_intr_methods = {
>       .transfer = ohci_root_intr_transfer,
>       .start = ohci_root_intr_start,
>       .abort = ohci_root_intr_abort,
> @@ -254,7 +254,7 @@ struct usbd_pipe_methods ohci_root_intr_methods = {
>       .done = ohci_root_intr_done,
>  };
>  
> -struct usbd_pipe_methods ohci_device_ctrl_methods = {
> +const struct usbd_pipe_methods ohci_device_ctrl_methods = {
>       .transfer = ohci_device_ctrl_transfer,
>       .start = ohci_device_ctrl_start,
>       .abort = ohci_device_ctrl_abort,
> @@ -262,7 +262,7 @@ struct usbd_pipe_methods ohci_device_ctrl_methods = {
>       .done = ohci_device_ctrl_done,
>  };
>  
> -struct usbd_pipe_methods ohci_device_intr_methods = {
> +const struct usbd_pipe_methods ohci_device_intr_methods = {
>       .transfer = ohci_device_intr_transfer,
>       .start = ohci_device_intr_start,
>       .abort = ohci_device_intr_abort,
> @@ -271,7 +271,7 @@ struct usbd_pipe_methods ohci_device_intr_methods = {
>       .done = ohci_device_intr_done,
>  };
>  
> -struct usbd_pipe_methods ohci_device_bulk_methods = {
> +const struct usbd_pipe_methods ohci_device_bulk_methods = {
>       .transfer = ohci_device_bulk_transfer,
>       .start = ohci_device_bulk_start,
>       .abort = ohci_device_bulk_abort,
> @@ -280,7 +280,7 @@ struct usbd_pipe_methods ohci_device_bulk_methods = {
>       .done = ohci_device_bulk_done,
>  };
>  
> -struct usbd_pipe_methods ohci_device_isoc_methods = {
> +const struct usbd_pipe_methods ohci_device_isoc_methods = {
>       .transfer = ohci_device_isoc_transfer,
>       .start = ohci_device_isoc_start,
>       .abort = ohci_device_isoc_abort,
> @@ -1153,7 +1153,7 @@ ohci_rhsc_enable(void *v_sc)
>  }
>  
>  #ifdef OHCI_DEBUG
> -char *ohci_cc_strs[] = {
> +const char *ohci_cc_strs[] = {
>       "NO_ERROR",
>       "CRC",
>       "BIT_STUFFING",
> @@ -2189,7 +2189,7 @@ ohci_abort_xfer(struct usbd_xfer *xfer, usbd_status st
>  /*
>   * Data structures and routines to emulate the root hub.
>   */
> -usb_device_descriptor_t ohci_devd = {
> +const usb_device_descriptor_t ohci_devd = {
>       USB_DEVICE_DESCRIPTOR_SIZE,
>       UDESC_DEVICE,           /* type */
>       {0x00, 0x01},           /* USB version */
> @@ -2202,7 +2202,7 @@ usb_device_descriptor_t ohci_devd = {
>       1                       /* # of configurations */
>  };
>  
> -usb_config_descriptor_t ohci_confd = {
> +const usb_config_descriptor_t ohci_confd = {
>       USB_CONFIG_DESCRIPTOR_SIZE,
>       UDESC_CONFIG,
>       {USB_CONFIG_DESCRIPTOR_SIZE +
> @@ -2215,7 +2215,7 @@ usb_config_descriptor_t ohci_confd = {
>       0                       /* max power */
>  };
>  
> -usb_interface_descriptor_t ohci_ifcd = {
> +const usb_interface_descriptor_t ohci_ifcd = {
>       USB_INTERFACE_DESCRIPTOR_SIZE,
>       UDESC_INTERFACE,
>       0,
> @@ -2227,7 +2227,7 @@ usb_interface_descriptor_t ohci_ifcd = {
>       0
>  };
>  
> -usb_endpoint_descriptor_t ohci_endpd = {
> +const usb_endpoint_descriptor_t ohci_endpd = {
>       USB_ENDPOINT_DESCRIPTOR_SIZE,
>       UDESC_ENDPOINT,
>       UE_DIR_IN | OHCI_INTR_ENDPT,
> @@ -2236,7 +2236,7 @@ usb_endpoint_descriptor_t ohci_endpd = {
>       255
>  };
>  
> -usb_hub_descriptor_t ohci_hubd = {
> +const usb_hub_descriptor_t ohci_hubd = {
>       USB_HUB_DESCRIPTOR_SIZE,
>       UDESC_HUB,
>       0,
> @@ -2272,6 +2272,7 @@ ohci_root_ctrl_start(struct usbd_xfer *xfer)
>       int port, i;
>       int s, len, value, index, l, totlen = 0;
>       usb_port_status_t ps;
> +     usb_device_descriptor_t devd;
>       usb_hub_descriptor_t hubd;
>       usbd_status err;
>       u_int32_t v;
> @@ -2320,9 +2321,10 @@ ohci_root_ctrl_start(struct usbd_xfer *xfer)
>                               err = USBD_IOERROR;
>                               goto ret;
>                       }
> +                     devd = ohci_devd;
> +                     USETW(devd.idVendor, sc->sc_id_vendor);
>                       totlen = l = min(len, USB_DEVICE_DESCRIPTOR_SIZE);
> -                     USETW(ohci_devd.idVendor, sc->sc_id_vendor);
> -                     memcpy(buf, &ohci_devd, l);
> +                     memcpy(buf, &devd, l);
>                       break;
>               case UDESC_CONFIG:
>                       if ((value & 0xff) != 0) {
> blob - 51fed2c96833b7b67f045db0b2cd938b99e7bec7
> blob + 9bbd243cf425f85155a48e2e7e139ea2f5b2c4aa
> --- sys/dev/usb/uhci.c
> +++ sys/dev/usb/uhci.c
> @@ -246,7 +246,7 @@ UREAD4(struct uhci_softc *sc, bus_size_t r)
>  
>  #define UHCI_INTR_ENDPT 1
>  
> -struct usbd_bus_methods uhci_bus_methods = {
> +const struct usbd_bus_methods uhci_bus_methods = {
>       .open_pipe = uhci_open,
>       .dev_setaddr = usbd_set_address,
>       .soft_intr = uhci_softintr,
> @@ -255,7 +255,7 @@ struct usbd_bus_methods uhci_bus_methods = {
>       .freex = uhci_freex,
>  };
>  
> -struct usbd_pipe_methods uhci_root_ctrl_methods = {
> +const struct usbd_pipe_methods uhci_root_ctrl_methods = {
>       .transfer = uhci_root_ctrl_transfer,
>       .start = uhci_root_ctrl_start,
>       .abort = uhci_root_ctrl_abort,
> @@ -263,7 +263,7 @@ struct usbd_pipe_methods uhci_root_ctrl_methods = {
>       .done = uhci_root_ctrl_done,
>  };
>  
> -struct usbd_pipe_methods uhci_root_intr_methods = {
> +const struct usbd_pipe_methods uhci_root_intr_methods = {
>       .transfer = uhci_root_intr_transfer,
>       .start = uhci_root_intr_start,
>       .abort = uhci_root_intr_abort,
> @@ -271,7 +271,7 @@ struct usbd_pipe_methods uhci_root_intr_methods = {
>       .done = uhci_root_intr_done,
>  };
>  
> -struct usbd_pipe_methods uhci_device_ctrl_methods = {
> +const struct usbd_pipe_methods uhci_device_ctrl_methods = {
>       .transfer = uhci_device_ctrl_transfer,
>       .start = uhci_device_ctrl_start,
>       .abort = uhci_device_ctrl_abort,
> @@ -279,7 +279,7 @@ struct usbd_pipe_methods uhci_device_ctrl_methods = {
>       .done = uhci_device_ctrl_done,
>  };
>  
> -struct usbd_pipe_methods uhci_device_intr_methods = {
> +const struct usbd_pipe_methods uhci_device_intr_methods = {
>       .transfer = uhci_device_intr_transfer,
>       .start = uhci_device_intr_start,
>       .abort = uhci_device_intr_abort,
> @@ -288,7 +288,7 @@ struct usbd_pipe_methods uhci_device_intr_methods = {
>       .done = uhci_device_intr_done,
>  };
>  
> -struct usbd_pipe_methods uhci_device_bulk_methods = {
> +const struct usbd_pipe_methods uhci_device_bulk_methods = {
>       .transfer = uhci_device_bulk_transfer,
>       .start = uhci_device_bulk_start,
>       .abort = uhci_device_bulk_abort,
> @@ -297,7 +297,7 @@ struct usbd_pipe_methods uhci_device_bulk_methods = {
>       .done = uhci_device_bulk_done,
>  };
>  
> -struct usbd_pipe_methods uhci_device_isoc_methods = {
> +const struct usbd_pipe_methods uhci_device_isoc_methods = {
>       .transfer = uhci_device_isoc_transfer,
>       .start = uhci_device_isoc_start,
>       .abort = uhci_device_isoc_abort,
> @@ -2702,7 +2702,7 @@ uhci_open(struct usbd_pipe *pipe)
>  /*
>   * Data structures and routines to emulate the root hub.
>   */
> -usb_device_descriptor_t uhci_devd = {
> +const usb_device_descriptor_t uhci_devd = {
>       USB_DEVICE_DESCRIPTOR_SIZE,
>       UDESC_DEVICE,           /* type */
>       {0x00, 0x01},           /* USB version */
> @@ -2715,7 +2715,7 @@ usb_device_descriptor_t uhci_devd = {
>       1                       /* # of configurations */
>  };
>  
> -usb_config_descriptor_t uhci_confd = {
> +const usb_config_descriptor_t uhci_confd = {
>       USB_CONFIG_DESCRIPTOR_SIZE,
>       UDESC_CONFIG,
>       {USB_CONFIG_DESCRIPTOR_SIZE +
> @@ -2728,7 +2728,7 @@ usb_config_descriptor_t uhci_confd = {
>       0                       /* max power */
>  };
>  
> -usb_interface_descriptor_t uhci_ifcd = {
> +const usb_interface_descriptor_t uhci_ifcd = {
>       USB_INTERFACE_DESCRIPTOR_SIZE,
>       UDESC_INTERFACE,
>       0,
> @@ -2740,7 +2740,7 @@ usb_interface_descriptor_t uhci_ifcd = {
>       0
>  };
>  
> -usb_endpoint_descriptor_t uhci_endpd = {
> +const usb_endpoint_descriptor_t uhci_endpd = {
>       USB_ENDPOINT_DESCRIPTOR_SIZE,
>       UDESC_ENDPOINT,
>       UE_DIR_IN | UHCI_INTR_ENDPT,
> @@ -2749,7 +2749,7 @@ usb_endpoint_descriptor_t uhci_endpd = {
>       255
>  };
>  
> -usb_hub_descriptor_t uhci_hubd_piix = {
> +const usb_hub_descriptor_t uhci_hubd_piix = {
>       USB_HUB_DESCRIPTOR_SIZE,
>       UDESC_HUB,
>       2,
> @@ -2883,6 +2883,7 @@ uhci_root_ctrl_start(struct usbd_xfer *xfer)
>       int port, x;
>       int s, len, value, index, status, change, l, totlen = 0;
>       usb_port_status_t ps;
> +     usb_device_descriptor_t devd;
>       usbd_status err;
>  
>       if (sc->sc_bus.dying)
> @@ -2928,9 +2929,10 @@ uhci_root_ctrl_start(struct usbd_xfer *xfer)
>                               err = USBD_IOERROR;
>                               goto ret;
>                       }
> +                     devd = uhci_devd;
> +                     USETW(devd.idVendor, sc->sc_id_vendor);
>                       totlen = l = min(len, USB_DEVICE_DESCRIPTOR_SIZE);
> -                     USETW(uhci_devd.idVendor, sc->sc_id_vendor);
> -                     memcpy(buf, &uhci_devd, l);
> +                     memcpy(buf, &devd, l);
>                       break;
>               case UDESC_CONFIG:
>                       if ((value & 0xff) != 0) {
> blob - 5aa207818f7c956e06d63eaef50ec6d582b68b4f
> blob + 7e197ff71c69bab5269d9cf91854b642be3692dd
> --- sys/dev/usb/usbdivar.h
> +++ sys/dev/usb/usbdivar.h
> @@ -105,7 +105,7 @@ struct usbd_hub {
>  struct usbd_bus {
>       /* Filled by HC driver */
>       struct device           bdev; /* base device, host adapter */
> -     struct usbd_bus_methods *methods;
> +     const struct usbd_bus_methods *methods;
>  #if NBPFILTER > 0
>       void                    *bpfif;
>       caddr_t                 bpf;
> @@ -194,7 +194,7 @@ struct usbd_pipe {
>       int                     interval;
>  
>       /* Filled by HC driver. */
> -     struct usbd_pipe_methods *methods;
> +     const struct usbd_pipe_methods *methods;
>  };
>  
>  struct usbd_xfer {
> blob - 71958b064a11d366a1f462b4a30fc2e61bba10e6
> blob + a1b017eaa6cca045a0c67b97d5bf03e6ac3276e4
> --- sys/dev/usb/xhci.c
> +++ sys/dev/usb/xhci.c
> @@ -157,7 +157,7 @@ usbd_status         xhci_device_isoc_start(struct 
> usbd_xfer 
>  
>  #define XHCI_INTR_ENDPT 1
>  
> -struct usbd_bus_methods xhci_bus_methods = {
> +const struct usbd_bus_methods xhci_bus_methods = {
>       .open_pipe = xhci_pipe_open,
>       .dev_setaddr = xhci_setaddr,
>       .soft_intr = xhci_softintr,
> @@ -166,7 +166,7 @@ struct usbd_bus_methods xhci_bus_methods = {
>       .freex = xhci_freex,
>  };
>  
> -struct usbd_pipe_methods xhci_root_ctrl_methods = {
> +const struct usbd_pipe_methods xhci_root_ctrl_methods = {
>       .transfer = xhci_root_ctrl_transfer,
>       .start = xhci_root_ctrl_start,
>       .abort = xhci_noop,
> @@ -174,7 +174,7 @@ struct usbd_pipe_methods xhci_root_ctrl_methods = {
>       .done = xhci_noop,
>  };
>  
> -struct usbd_pipe_methods xhci_root_intr_methods = {
> +const struct usbd_pipe_methods xhci_root_intr_methods = {
>       .transfer = xhci_root_intr_transfer,
>       .start = xhci_root_intr_start,
>       .abort = xhci_root_intr_abort,
> @@ -182,7 +182,7 @@ struct usbd_pipe_methods xhci_root_intr_methods = {
>       .done = xhci_root_intr_done,
>  };
>  
> -struct usbd_pipe_methods xhci_device_ctrl_methods = {
> +const struct usbd_pipe_methods xhci_device_ctrl_methods = {
>       .transfer = xhci_device_ctrl_transfer,
>       .start = xhci_device_ctrl_start,
>       .abort = xhci_device_ctrl_abort,
> @@ -190,7 +190,7 @@ struct usbd_pipe_methods xhci_device_ctrl_methods = {
>       .done = xhci_noop,
>  };
>  
> -struct usbd_pipe_methods xhci_device_intr_methods = {
> +const struct usbd_pipe_methods xhci_device_intr_methods = {
>       .transfer = xhci_device_generic_transfer,
>       .start = xhci_device_generic_start,
>       .abort = xhci_device_generic_abort,
> @@ -198,7 +198,7 @@ struct usbd_pipe_methods xhci_device_intr_methods = {
>       .done = xhci_device_generic_done,
>  };
>  
> -struct usbd_pipe_methods xhci_device_bulk_methods = {
> +const struct usbd_pipe_methods xhci_device_bulk_methods = {
>       .transfer = xhci_device_generic_transfer,
>       .start = xhci_device_generic_start,
>       .abort = xhci_device_generic_abort,
> @@ -206,7 +206,7 @@ struct usbd_pipe_methods xhci_device_bulk_methods = {
>       .done = xhci_device_generic_done,
>  };
>  
> -struct usbd_pipe_methods xhci_device_isoc_methods = {
> +const struct usbd_pipe_methods xhci_device_isoc_methods = {
>       .transfer = xhci_device_isoc_transfer,
>       .start = xhci_device_isoc_start,
>       .abort = xhci_device_generic_abort,
> @@ -2165,7 +2165,7 @@ xhci_softdev_free(struct xhci_softc *sc, uint8_t slot)
>  }
>  
>  /* Root hub descriptors. */
> -usb_device_descriptor_t xhci_devd = {
> +const usb_device_descriptor_t xhci_devd = {
>       USB_DEVICE_DESCRIPTOR_SIZE,
>       UDESC_DEVICE,           /* type */
>       {0x00, 0x03},           /* USB version */
> @@ -2348,6 +2348,7 @@ xhci_root_ctrl_start(struct usbd_xfer *xfer)
>       usb_port_status_t ps;
>       usb_device_request_t *req;
>       void *buf = NULL;
> +     usb_device_descriptor_t devd;
>       usb_hub_descriptor_t hubd;
>       usbd_status err;
>       int s, len, value, index;
> @@ -2396,9 +2397,10 @@ xhci_root_ctrl_start(struct usbd_xfer *xfer)
>                               err = USBD_IOERROR;
>                               goto ret;
>                       }
> +                     devd = xhci_devd;
> +                     USETW(devd.idVendor, sc->sc_id_vendor);
>                       totlen = l = min(len, USB_DEVICE_DESCRIPTOR_SIZE);
> -                     USETW(xhci_devd.idVendor, sc->sc_id_vendor);
> -                     memcpy(buf, &xhci_devd, l);
> +                     memcpy(buf, &devd, l);
>                       break;
>               /*
>                * We can't really operate at another speed, but the spec says
> -- 
> Christian "naddy" Weisgerber                          na...@mips.inka.de
> 

-- 

[ -- Marcus Glocker, mar...@nazgul.ch, https://nazgul.ch ------------- ]

Reply via email to