I have observed two separate EHCI host bridges that do not tolerate
using C bit-fields to directly manipulate the portsc_t register. The
reason for this is that the EHCI spec says that port_enable must go
to 0 at the time that port_reset goes to 1. Naturally this cannot be
done using direct bit-field manipulation. Instead, we use a temporary
variable, change the bit-fields there, then atomically write the new
value back to the hardware.
Signed-off-by: Steven A. Falco <sfalco@coincident.com>
Change-Id: If138faee43e0293efa203b86f7893fdf1e811269
Reviewed-on: http://review.coreboot.org/101
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <patrick@georgi-clan.de>
ehci_rh_hand_over_port (usbdev_t *dev, int port)
{
volatile portsc_t *p = &(RH_INST(dev)->ports[port]);
ehci_rh_hand_over_port (usbdev_t *dev, int port)
{
volatile portsc_t *p = &(RH_INST(dev)->ports[port]);
printf("giving up port %x, it's USB1\n", port+1);
/* Lowspeed device. Hand over to companion */
printf("giving up port %x, it's USB1\n", port+1);
/* Lowspeed device. Hand over to companion */
+ tmp = *p;
+ tmp.port_owner = 1;
+ *p = tmp;
do {} while (!p->conn_status_change);
/* RW/C register, so clear it by writing 1 */
do {} while (!p->conn_status_change);
/* RW/C register, so clear it by writing 1 */
- p->conn_status_change = 1;
+ tmp = *p;
+ tmp.conn_status_change = 1;
+ *p = tmp;
ehci_rh_scanport (usbdev_t *dev, int port)
{
volatile portsc_t *p = &(RH_INST(dev)->ports[port]);
ehci_rh_scanport (usbdev_t *dev, int port)
{
volatile portsc_t *p = &(RH_INST(dev)->ports[port]);
if (RH_INST(dev)->devices[port]!=-1) {
printf("Unregister device at port %x\n", port+1);
usb_detach_device(dev->controller, RH_INST(dev)->devices[port]);
if (RH_INST(dev)->devices[port]!=-1) {
printf("Unregister device at port %x\n", port+1);
usb_detach_device(dev->controller, RH_INST(dev)->devices[port]);
ehci_rh_hand_over_port(dev, port);
return;
}
ehci_rh_hand_over_port(dev, port);
return;
}
- p->port_enable = 0;
- p->port_reset = 1;
+
+ /* Deassert enable, assert reset. These must change
+ * atomically.
+ */
+ tmp = *p;
+ tmp.port_enable = 0;
+ tmp.port_reset = 1;
+ *p = tmp;
+
+ /* Wait a bit while reset is active. */
+
+ /* Deassert reset. */
+ tmp.port_reset = 0;
+ *p = tmp;
+
/* Wait for flag change to finish. The controller might take a while */
while (p->port_reset) ;
if (!p->port_enable) {
/* Wait for flag change to finish. The controller might take a while */
while (p->port_reset) ;
if (!p->port_enable) {
RH_INST(dev)->devices[port] = usb_attach_device(dev->controller, dev->address, port, 2);
}
/* RW/C register, so clear it by writing 1 */
RH_INST(dev)->devices[port] = usb_attach_device(dev->controller, dev->address, port, 2);
}
/* RW/C register, so clear it by writing 1 */
- p->conn_status_change = 1;
+ tmp = *p;
+ tmp.conn_status_change = 1;
+ *p = tmp;
ehci_rh_init (usbdev_t *dev)
{
int i;
ehci_rh_init (usbdev_t *dev)
{
int i;
+ volatile portsc_t *p;
+ volatile portsc_t tmp;
dev->destroy = ehci_rh_destroy;
dev->poll = ehci_rh_poll;
dev->destroy = ehci_rh_destroy;
dev->poll = ehci_rh_poll;
RH_INST(dev)->devices = malloc(RH_INST(dev)->n_ports * sizeof(int));
for (i=0; i < RH_INST(dev)->n_ports; i++) {
RH_INST(dev)->devices = malloc(RH_INST(dev)->n_ports * sizeof(int));
for (i=0; i < RH_INST(dev)->n_ports; i++) {
+ p = &(RH_INST(dev)->ports[i]);
RH_INST(dev)->devices[i] = -1;
RH_INST(dev)->devices[i] = -1;
- RH_INST(dev)->ports[i].pp = 1;
+ tmp = *p;
+ tmp.pp = 1;
+ *p = tmp;