diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index ed9eb1a..01fcb99 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -240,6 +240,7 @@ command.slotID = slotNumber; command.BSR = BSR; enqueueCommand(&controller->commands, (void *)&command); + await(serviceId, events[controller->events.dequeue]); } void configureEndpoint(void *inputContext, uint32_t slotNumber, @@ -251,6 +252,7 @@ command.slotID = slotNumber; command.BSR = deconfigure; enqueueCommand(&controller->commands, (void *)&command); + await(serviceId, events[controller->events.dequeue]); } void evaluateContext(void *inputContext, uint32_t slotNumber) { @@ -262,10 +264,41 @@ enqueueCommand(&controller->commands, (void *)&command); } +void getDeviceInformation(XHCIInputContext *inputContext, TrbRing *ring, + uint32_t slotIndex) { + XHCISetupStageTRB setup = {0}; + setup.requestType = 0x80; + setup.request = 6; + setup.value = 0x100; + setup.index = 0; + setup.length = 8; + setup.transferLegnth = 8; + setup.interruptOnCompletion = 0; + setup.interrupterTarget = 0; + setup.type = 2; + setup.transferType = 3; + setup.immediateData = 1; + enqueueCommand(ring, (void *)&setup); + XHCIDataStageTRB data = {0}; + data.dataBuffer[0] = U32(getPhysicalAddress(requestMemory(1, 0, 0))); + data.inDirection = 1; + data.transferSize = 8; + data.type = 3; + data.interrupterTarget = 0; + enqueueCommand(ring, (void *)&data); + XHCIStatusStageTRB status = {0}; + status.inDirection = 1; + status.evaluateNext = 0; + status.interruptOnCompletion = 1; + status.type = 4; + enqueueCommand(ring, (void *)&status); + controller->doorbells[slotIndex] = 1; +} + void setupPort(XHCITRB *trb) { XHCIPort *port = &controller->operational->ports[(trb->dataLow >> 24) - 1]; if (!(port->status & 1 << 1)) { - // return; + return; } XHCITRB *enableSlotResult = xhciCommandAsync(controller, 0, 0, 0, 9); uint32_t slotIndex = enableSlotResult->control.reserved1 >> 8; @@ -273,14 +306,12 @@ slotIndex); XHCIInputContext *inputContext = requestMemory(1, 0, 0); inputContext->inputControl.addContextFlags = 3; - // inputContext->inputControl.dropContextFlags = - // ~inputContext->inputControl.addContextFlags; inputContext->deviceContext.slot.rootHubPort = trb->dataLow >> 24; inputContext->deviceContext.slot.interrupterTarget = 0; inputContext->deviceContext.slot.multiTT = 0; inputContext->deviceContext.slot.deviceAddress = 0; - inputContext->deviceContext.slot.portCount = 1; inputContext->deviceContext.slot.contextEntryCount = 1; + inputContext->deviceContext.slot.speed = (port->status >> 10) & 3; inputContext->deviceContext.endpoints[0].endpointType = 4; inputContext->deviceContext.endpoints[0].maxPacketSize = 8; // TODO inputContext->deviceContext.endpoints[0].maxBurstSize = 0; @@ -294,30 +325,16 @@ inputContext->deviceContext.endpoints[0].transferDequeuePointerLow = U32(ring->physical) | 1; inputContext->deviceContext.endpoints[0].transferDequeuePointerHigh = 0; + XHCIDevice *device = malloc(sizeof(XHCIDevice)); controller->deviceContextBaseAddressArray[slotIndex] = - U32(getPhysicalAddress((void *)&inputContext->deviceContext)); - addressDevice(getPhysicalAddress((void *)&inputContext->inputControl), - slotIndex, false); + U32(getPhysicalAddress((void *)device)); addressDevice(getPhysicalAddress((void *)&inputContext->inputControl), slotIndex, true); - printf("address: %x / %x, isHub: %i, speed: %i, state: %x\n", - inputContext->deviceContext.slot.routeString, - inputContext->deviceContext.slot.deviceAddress, - inputContext->deviceContext.slot.isHub, - inputContext->deviceContext.slot.speed, port->status); - inputContext->inputControl.addContextFlags = 1; - // inputContext->inputControl.dropContextFlags = - // ~inputContext->inputControl.addContextFlags; - configureEndpoint(getPhysicalAddress((void *)&inputContext->inputControl), - slotIndex, true); - configureEndpoint(getPhysicalAddress((void *)&inputContext->inputControl), - slotIndex, false); - printf("address: %x / %x, isHub: %i, speed: %i, state: %x, root hub: %i\n", - inputContext->deviceContext.slot.routeString, - inputContext->deviceContext.slot.deviceAddress, - inputContext->deviceContext.slot.isHub, - inputContext->deviceContext.slot.speed, port->status, - inputContext->deviceContext.slot.rootHubPort); + getDeviceInformation(inputContext, ring, slotIndex); + // configure endpoint gives a trb error as of now ... + // configureEndpoint(getPhysicalAddress((void + // *)&inputContext->inputControl), + // slotIndex, false); } void xhciInterrupt() { diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index ed9eb1a..01fcb99 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -240,6 +240,7 @@ command.slotID = slotNumber; command.BSR = BSR; enqueueCommand(&controller->commands, (void *)&command); + await(serviceId, events[controller->events.dequeue]); } void configureEndpoint(void *inputContext, uint32_t slotNumber, @@ -251,6 +252,7 @@ command.slotID = slotNumber; command.BSR = deconfigure; enqueueCommand(&controller->commands, (void *)&command); + await(serviceId, events[controller->events.dequeue]); } void evaluateContext(void *inputContext, uint32_t slotNumber) { @@ -262,10 +264,41 @@ enqueueCommand(&controller->commands, (void *)&command); } +void getDeviceInformation(XHCIInputContext *inputContext, TrbRing *ring, + uint32_t slotIndex) { + XHCISetupStageTRB setup = {0}; + setup.requestType = 0x80; + setup.request = 6; + setup.value = 0x100; + setup.index = 0; + setup.length = 8; + setup.transferLegnth = 8; + setup.interruptOnCompletion = 0; + setup.interrupterTarget = 0; + setup.type = 2; + setup.transferType = 3; + setup.immediateData = 1; + enqueueCommand(ring, (void *)&setup); + XHCIDataStageTRB data = {0}; + data.dataBuffer[0] = U32(getPhysicalAddress(requestMemory(1, 0, 0))); + data.inDirection = 1; + data.transferSize = 8; + data.type = 3; + data.interrupterTarget = 0; + enqueueCommand(ring, (void *)&data); + XHCIStatusStageTRB status = {0}; + status.inDirection = 1; + status.evaluateNext = 0; + status.interruptOnCompletion = 1; + status.type = 4; + enqueueCommand(ring, (void *)&status); + controller->doorbells[slotIndex] = 1; +} + void setupPort(XHCITRB *trb) { XHCIPort *port = &controller->operational->ports[(trb->dataLow >> 24) - 1]; if (!(port->status & 1 << 1)) { - // return; + return; } XHCITRB *enableSlotResult = xhciCommandAsync(controller, 0, 0, 0, 9); uint32_t slotIndex = enableSlotResult->control.reserved1 >> 8; @@ -273,14 +306,12 @@ slotIndex); XHCIInputContext *inputContext = requestMemory(1, 0, 0); inputContext->inputControl.addContextFlags = 3; - // inputContext->inputControl.dropContextFlags = - // ~inputContext->inputControl.addContextFlags; inputContext->deviceContext.slot.rootHubPort = trb->dataLow >> 24; inputContext->deviceContext.slot.interrupterTarget = 0; inputContext->deviceContext.slot.multiTT = 0; inputContext->deviceContext.slot.deviceAddress = 0; - inputContext->deviceContext.slot.portCount = 1; inputContext->deviceContext.slot.contextEntryCount = 1; + inputContext->deviceContext.slot.speed = (port->status >> 10) & 3; inputContext->deviceContext.endpoints[0].endpointType = 4; inputContext->deviceContext.endpoints[0].maxPacketSize = 8; // TODO inputContext->deviceContext.endpoints[0].maxBurstSize = 0; @@ -294,30 +325,16 @@ inputContext->deviceContext.endpoints[0].transferDequeuePointerLow = U32(ring->physical) | 1; inputContext->deviceContext.endpoints[0].transferDequeuePointerHigh = 0; + XHCIDevice *device = malloc(sizeof(XHCIDevice)); controller->deviceContextBaseAddressArray[slotIndex] = - U32(getPhysicalAddress((void *)&inputContext->deviceContext)); - addressDevice(getPhysicalAddress((void *)&inputContext->inputControl), - slotIndex, false); + U32(getPhysicalAddress((void *)device)); addressDevice(getPhysicalAddress((void *)&inputContext->inputControl), slotIndex, true); - printf("address: %x / %x, isHub: %i, speed: %i, state: %x\n", - inputContext->deviceContext.slot.routeString, - inputContext->deviceContext.slot.deviceAddress, - inputContext->deviceContext.slot.isHub, - inputContext->deviceContext.slot.speed, port->status); - inputContext->inputControl.addContextFlags = 1; - // inputContext->inputControl.dropContextFlags = - // ~inputContext->inputControl.addContextFlags; - configureEndpoint(getPhysicalAddress((void *)&inputContext->inputControl), - slotIndex, true); - configureEndpoint(getPhysicalAddress((void *)&inputContext->inputControl), - slotIndex, false); - printf("address: %x / %x, isHub: %i, speed: %i, state: %x, root hub: %i\n", - inputContext->deviceContext.slot.routeString, - inputContext->deviceContext.slot.deviceAddress, - inputContext->deviceContext.slot.isHub, - inputContext->deviceContext.slot.speed, port->status, - inputContext->deviceContext.slot.rootHubPort); + getDeviceInformation(inputContext, ring, slotIndex); + // configure endpoint gives a trb error as of now ... + // configureEndpoint(getPhysicalAddress((void + // *)&inputContext->inputControl), + // slotIndex, false); } void xhciInterrupt() { diff --git a/src/userland/usb/usb.h b/src/userland/usb/usb.h index 934f66c..568bbc2 100644 --- a/src/userland/usb/usb.h +++ b/src/userland/usb/usb.h @@ -84,6 +84,37 @@ } __attribute__((packed)) XHCIDeviceTRB; typedef volatile struct { + uint32_t requestType : 8, request : 8, value : 16; + uint32_t index : 16, length : 16; + + uint32_t transferLegnth : 17, // always 8 + reserved : 5, interrupterTarget : 10; + + uint32_t cycle : 1, reserved1 : 4, interruptOnCompletion : 1, + immediateData : 1, // here 1 + reserved2 : 3, type : 6, transferType : 2; +} __attribute__((packed)) XHCISetupStageTRB; + +typedef volatile struct { + uint32_t reserved[2]; + + uint32_t reserved1 : 22, interrupterTarget : 10; + + uint32_t cycle : 1, evaluateNext : 1, reserved2 : 2, chain : 1, + interruptOnCompletion : 1, reserved3 : 4, type : 6, inDirection : 1; +} __attribute__((packed)) XHCIStatusStageTRB; + +typedef volatile struct { + uint32_t dataBuffer[2]; + + uint32_t transferSize : 17, tdSize : 5, interrupterTarget : 10; + + uint32_t cycle : 1, evaluateNext : 1, interruptOnShortPacket : 1, + noSnoop : 1, chain : 1, interruptOnCompletion : 1, immediateData : 1, + reserved : 3, type : 6, inDirection : 1; +} __attribute__((packed)) XHCIDataStageTRB; + +typedef volatile struct { uint32_t routeString : 20, speed : 4, reserved : 1, multiTT : 1, isHub : 1, contextEntryCount : 5; uint32_t maxLatency : 16, rootHubPort : 8, portCount : 8;