[haiku-commits] haiku: hrev52919 - src/add-ons/kernel/busses/usb

  • From: waddlesplash <waddlesplash@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 22 Feb 2019 17:18:00 -0500 (EST)

hrev52919 adds 4 changesets to branch 'master'
old head: da8c1a9a403aed0fa06beeeb100c3c0c50b8362c
new head: 88180e2f8008bc1af73e2dcdb8d18e8cbfc6e935
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=88180e2f8008+%5Eda8c1a9a403a

----------------------------------------------------------------------------

1464b156f70c: XHCI: Minor non-functional cleanups.

c4db8aba7bb8: XHCI: Delete the device in FreeDevice() before tearing down 
internal state.
  
  We don't properly tear down endpoints, etc. yet, but when we do, this will
  be important as the device destructors are what tells us to do that.

358dd70e161e: XHCI: Initialize all fields during endpoint setup.
  
  As we reuse memory on a device for endpoints, this is potentially a
  functional change.

88180e2f8008: XHCI: Allow commands to time out after 1s instead of stalling 
forever.
  
  This seems to occur when trying to stop endpoints in certain scenarios,
  at least.

                              [ Augustin Cavalier <waddlesplash@xxxxxxxxx> ]

----------------------------------------------------------------------------

1 file changed, 18 insertions(+), 9 deletions(-)
src/add-ons/kernel/busses/usb/xhci.cpp | 27 ++++++++++++++++++---------

############################################################################

Commit:      1464b156f70ce53feb704ad0ea63780205125db1
URL:         https://git.haiku-os.org/haiku/commit/?id=1464b156f70c
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Fri Feb 22 22:08:10 2019 UTC

XHCI: Minor non-functional cleanups.

----------------------------------------------------------------------------

diff --git a/src/add-ons/kernel/busses/usb/xhci.cpp 
b/src/add-ons/kernel/busses/usb/xhci.cpp
index efbd063dcb..033fd68234 100644
--- a/src/add-ons/kernel/busses/usb/xhci.cpp
+++ b/src/add-ons/kernel/busses/usb/xhci.cpp
@@ -160,7 +160,7 @@ XHCI::XHCI(pci_info *info, Stack *stack)
 
        size_t mapSize = fPCIInfo->u.h0.base_register_sizes[0];
 
-       TRACE("map physical memory %08" B_PRIxPHYSADDR ", size: %" B_PRId32 
"\n",
+       TRACE("map physical memory %08" B_PRIxPHYSADDR ", size: %" B_PRIuSIZE 
"\n",
                physicalAddress, mapSize);
 
        fRegisterArea = map_physical_memory("XHCI memory mapped registers",
@@ -1238,7 +1238,7 @@ XHCI::AllocateDevice(Hub *parent, int8 hubAddress, uint8 
hubPort,
        memset(device->device_ctx, 0, sizeof(*device->device_ctx) << 
fContextSizeShift);
 
        device->trb_area = fStack->AllocateArea((void **)&device->trbs,
-               &device->trb_addr, sizeof(*device->trbs) * (XHCI_MAX_ENDPOINTS 
- 1)
+               &device->trb_addr, sizeof(xhci_trb) * (XHCI_MAX_ENDPOINTS - 1)
                        * XHCI_MAX_TRANSFERS, "XHCI endpoint trbs");
        if (device->trb_area < B_OK) {
                TRACE_ERROR("unable to create a device trbs area\n");

############################################################################

Commit:      c4db8aba7bb80c8a287acfe6007fe0037cfade64
URL:         https://git.haiku-os.org/haiku/commit/?id=c4db8aba7bb8
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Fri Feb 22 22:09:09 2019 UTC

XHCI: Delete the device in FreeDevice() before tearing down internal state.

We don't properly tear down endpoints, etc. yet, but when we do, this will
be important as the device destructors are what tells us to do that.

----------------------------------------------------------------------------

diff --git a/src/add-ons/kernel/busses/usb/xhci.cpp 
b/src/add-ons/kernel/busses/usb/xhci.cpp
index 033fd68234..a76e7e2301 100644
--- a/src/add-ons/kernel/busses/usb/xhci.cpp
+++ b/src/add-ons/kernel/busses/usb/xhci.cpp
@@ -1425,6 +1425,11 @@ XHCI::FreeDevice(Device *device)
 {
        uint8 slot = fPortSlots[device->HubPort()];
        TRACE("FreeDevice() port %d slot %d\n", device->HubPort(), slot);
+
+       // Delete the device first, so it cleans up its pipes and tells us
+       // what we need to destroy before we tear down our internal state.
+       delete device;
+
        DisableSlot(slot);
        fDcba->baseAddress[slot] = 0;
        fPortSlots[device->HubPort()] = 0;
@@ -1432,7 +1437,6 @@ XHCI::FreeDevice(Device *device)
        delete_area(fDevices[slot].input_ctx_area);
        delete_area(fDevices[slot].device_ctx_area);
        fDevices[slot].state = XHCI_STATE_DISABLED;
-       delete device;
 }
 
 

############################################################################

Commit:      358dd70e161e0faf8159ff178f3ebd7dd07ba7f4
URL:         https://git.haiku-os.org/haiku/commit/?id=358dd70e161e
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Fri Feb 22 22:12:03 2019 UTC

XHCI: Initialize all fields during endpoint setup.

As we reuse memory on a device for endpoints, this is potentially a
functional change.

----------------------------------------------------------------------------

diff --git a/src/add-ons/kernel/busses/usb/xhci.cpp 
b/src/add-ons/kernel/busses/usb/xhci.cpp
index a76e7e2301..fb8a9173be 100644
--- a/src/add-ons/kernel/busses/usb/xhci.cpp
+++ b/src/add-ons/kernel/busses/usb/xhci.cpp
@@ -1478,11 +1478,17 @@ XHCI::_InsertEndpointForPipe(Pipe *pipe)
                device->endpoints[id].device = device;
                device->endpoints[id].trbs = device->trbs
                        + id * XHCI_MAX_TRANSFERS;
-               device->endpoints[id].td_head = NULL;
-               device->endpoints[id].used = 0;
                device->endpoints[id].trb_addr = device->trb_addr
                        + id * XHCI_MAX_TRANSFERS * sizeof(xhci_trb);
+               device->endpoints[id].td_head = NULL;
+               device->endpoints[id].used = 0;
+               device->endpoints[id].current = 0;
+
+               memset(device->endpoints[id].trbs, 0,
+                       sizeof(xhci_trb) * XHCI_MAX_TRANSFERS);
+
                mutex_init(&device->endpoints[id].lock, "xhci endpoint lock");
+               MutexLocker endpointLocker(device->endpoints[id].lock);
 
                TRACE("_InsertEndpointForPipe trbs device %p endpoint %p\n",
                        device->trbs, device->endpoints[id].trbs);
@@ -2059,7 +2065,6 @@ XHCI::HandleCmdComplete(xhci_trb* trb)
                fCmdResult[1] = B_LENDIAN_TO_HOST_INT32(trb->dwtrb3);
                release_sem_etc(fCmdCompSem, 1, B_DO_NOT_RESCHEDULE);
        }
-
 }
 
 

############################################################################

Revision:    hrev52919
Commit:      88180e2f8008bc1af73e2dcdb8d18e8cbfc6e935
URL:         https://git.haiku-os.org/haiku/commit/?id=88180e2f8008
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Fri Feb 22 22:14:23 2019 UTC

XHCI: Allow commands to time out after 1s instead of stalling forever.

This seems to occur when trying to stop endpoints in certain scenarios,
at least.

----------------------------------------------------------------------------

diff --git a/src/add-ons/kernel/busses/usb/xhci.cpp 
b/src/add-ons/kernel/busses/usb/xhci.cpp
index fb8a9173be..fec831b6d9 100644
--- a/src/add-ons/kernel/busses/usb/xhci.cpp
+++ b/src/add-ons/kernel/busses/usb/xhci.cpp
@@ -2147,10 +2147,10 @@ XHCI::DoCommand(xhci_trb* trb)
        QueueCommand(trb);
        Ring(0, 0);
 
-       if (acquire_sem(fCmdCompSem) < B_OK) {
-               TRACE("Unable to obtain fCmdCompSem semaphore!\n");
+       if (acquire_sem_etc(fCmdCompSem, 1, B_RELATIVE_TIMEOUT, 1 * 1000 * 
1000) < B_OK) {
+               TRACE("Unable to obtain fCmdCompSem!\n");
                Unlock();
-               return B_ERROR;
+               return B_TIMED_OUT;
        }
        // eat up sems that have been released by multiple interrupts
        int32 semCount = 0;


Other related posts:

  • » [haiku-commits] haiku: hrev52919 - src/add-ons/kernel/busses/usb - waddlesplash