diff --git a/src/userland/usb/include/usb.h b/src/userland/usb/include/usb.h index 7bb9f21..1a8d96f 100644 --- a/src/userland/usb/include/usb.h +++ b/src/userland/usb/include/usb.h @@ -60,10 +60,12 @@ uint32_t pciClass; void *(*initialize)(uint32_t, uint32_t, uint32_t); void (*getDeviceDescriptor)(void *, uint32_t, uint32_t, void *); - void (*setupEndpoints)(void *, ListElement *, uint32_t); + void (*setupEndpointsStart)(void *, uint32_t); + void (*setupEndpointsEnd)(void *, uint32_t); void (*setupHID)(void *, uint32_t, void *); void (*doNormal)(void *, void *, uint32_t); void (*command)(void *, uint8_t, uint8_t, uint16_t, uint8_t); + void (*configureEndpoint)(void *, UsbEndpointDescriptor *); } UsbHostControllerInterface; typedef struct { diff --git a/src/userland/usb/include/usb.h b/src/userland/usb/include/usb.h index 7bb9f21..1a8d96f 100644 --- a/src/userland/usb/include/usb.h +++ b/src/userland/usb/include/usb.h @@ -60,10 +60,12 @@ uint32_t pciClass; void *(*initialize)(uint32_t, uint32_t, uint32_t); void (*getDeviceDescriptor)(void *, uint32_t, uint32_t, void *); - void (*setupEndpoints)(void *, ListElement *, uint32_t); + void (*setupEndpointsStart)(void *, uint32_t); + void (*setupEndpointsEnd)(void *, uint32_t); void (*setupHID)(void *, uint32_t, void *); void (*doNormal)(void *, void *, uint32_t); void (*command)(void *, uint8_t, uint8_t, uint16_t, uint8_t); + void (*configureEndpoint)(void *, UsbEndpointDescriptor *); } UsbHostControllerInterface; typedef struct { diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index 0d1c6d0..b7eef42 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -30,8 +30,8 @@ UsbInterfaceDescriptor *interface = start; // only doing blank interface descriptors for now, there are // also interface assosciations... - ListElement *endpointConfigurations = NULL; ListElement *hidInterfaces = NULL; + slot->interface->setupEndpointsStart(slot->data, configurationValue); while (interface->descriptorType == 4) { printf("interface %i: %i endpoint(s), class %i, subclass %i\n", interface->interfaceNumber, interface->endpointCount, @@ -40,7 +40,7 @@ for (uint32_t i = 0; i < interface->endpointCount;) { UsbEndpointDescriptor *endpoint = nextInterface; if (endpoint->descriptorType == 5) { - listAdd(&endpointConfigurations, endpoint); + slot->interface->configureEndpoint(slot->data, endpoint); printf("endpoint %i (%i): address: %x, attributes: %x\n", i, endpoint->descriptorType, endpoint->address, endpoint->attributes); @@ -53,8 +53,7 @@ } interface = nextInterface; } - slot->interface->setupEndpoints(slot->data, endpointConfigurations, - configurationValue); + slot->interface->setupEndpointsEnd(slot->data, configurationValue); foreach (hidInterfaces, UsbInterfaceDescriptor *, interface, { UsbEndpointDescriptor *endpoint = (void *)interface + interface->size; while (endpoint->descriptorType != 5) { diff --git a/src/userland/usb/include/usb.h b/src/userland/usb/include/usb.h index 7bb9f21..1a8d96f 100644 --- a/src/userland/usb/include/usb.h +++ b/src/userland/usb/include/usb.h @@ -60,10 +60,12 @@ uint32_t pciClass; void *(*initialize)(uint32_t, uint32_t, uint32_t); void (*getDeviceDescriptor)(void *, uint32_t, uint32_t, void *); - void (*setupEndpoints)(void *, ListElement *, uint32_t); + void (*setupEndpointsStart)(void *, uint32_t); + void (*setupEndpointsEnd)(void *, uint32_t); void (*setupHID)(void *, uint32_t, void *); void (*doNormal)(void *, void *, uint32_t); void (*command)(void *, uint8_t, uint8_t, uint16_t, uint8_t); + void (*configureEndpoint)(void *, UsbEndpointDescriptor *); } UsbHostControllerInterface; typedef struct { diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index 0d1c6d0..b7eef42 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -30,8 +30,8 @@ UsbInterfaceDescriptor *interface = start; // only doing blank interface descriptors for now, there are // also interface assosciations... - ListElement *endpointConfigurations = NULL; ListElement *hidInterfaces = NULL; + slot->interface->setupEndpointsStart(slot->data, configurationValue); while (interface->descriptorType == 4) { printf("interface %i: %i endpoint(s), class %i, subclass %i\n", interface->interfaceNumber, interface->endpointCount, @@ -40,7 +40,7 @@ for (uint32_t i = 0; i < interface->endpointCount;) { UsbEndpointDescriptor *endpoint = nextInterface; if (endpoint->descriptorType == 5) { - listAdd(&endpointConfigurations, endpoint); + slot->interface->configureEndpoint(slot->data, endpoint); printf("endpoint %i (%i): address: %x, attributes: %x\n", i, endpoint->descriptorType, endpoint->address, endpoint->attributes); @@ -53,8 +53,7 @@ } interface = nextInterface; } - slot->interface->setupEndpoints(slot->data, endpointConfigurations, - configurationValue); + slot->interface->setupEndpointsEnd(slot->data, configurationValue); foreach (hidInterfaces, UsbInterfaceDescriptor *, interface, { UsbEndpointDescriptor *endpoint = (void *)interface + interface->size; while (endpoint->descriptorType != 5) { diff --git a/src/userland/usb/xhci/xhci.c b/src/userland/usb/xhci/xhci.c index eee0f0a..c8dd23a 100644 --- a/src/userland/usb/xhci/xhci.c +++ b/src/userland/usb/xhci/xhci.c @@ -113,8 +113,7 @@ awaitCode(serviceId, xhciEvent, commandAddress); } -void xhciSetupEndpoints(SlotXHCI *slot, ListElement *endpoints, - uint32_t configValue) { +void xhciSetupEndpointsStart(SlotXHCI *slot, uint32_t configValue) { XHCIController *controller = slot->controller; XHCIInputContext *inputContext = slot->inputContext; memcpy((void *)controller->deviceContexts[slot->slotIndex], @@ -123,41 +122,47 @@ printf("slot context state: %x, address: %x\n", inputContext->deviceContext.slot.slotState, inputContext->deviceContext.slot.deviceAddress); - foreach (endpoints, UsbEndpointDescriptor *, endpoint, { - uint8_t endpointNumber = endpoint->address & 0xF; // never 0 - uint8_t direction = endpoint->address >> 7; - uint8_t endpointIndex = (endpointNumber)*2 - 1 + direction; - XHCIEndpointContext *endpointContext = - &inputContext->deviceContext.endpoints[endpointIndex]; - endpointContext->maxPrimaryStreams = 0; - endpointContext->interval = endpoint->interval; - endpointContext->errorCount = 3; - endpointContext->endpointType = - direction << 2 | endpoint->attributes & 3; - endpointContext->maxPacketSize = endpoint->maxPacketSize; - slot->endpointRings[endpointIndex] = malloc(sizeof(TrbRing)); - setupTrbRing(slot->endpointRings[endpointIndex], 256); - endpointContext->transferDequeuePointerLow = - U32(slot->endpointRings[endpointIndex]->physical) | 1; - endpointContext->transferDequeuePointerHigh = 0; - endpointContext->averageTRBLength = 2048; - inputContext->inputControl.addContextFlags |= 1 << (endpointIndex + 1); - inputContext->deviceContext.slot.contextEntryCount = MAX( - inputContext->deviceContext.slot.contextEntryCount, endpointIndex); - }) - ; - +} + +void xhciSetupEndpointsEnd(SlotXHCI *slot, uint32_t configValue) { + XHCIController *controller = slot->controller; + XHCIInputContext *inputContext = slot->inputContext; uint32_t control = COMMAND_TYPE(12) | COMMAND_SLOT_ID(slot->slotIndex); xhciCommand(controller, U32(getPhysicalAddress((void *)inputContext)), 0, 0, control); - doXhciCommand(slot, 0x00, 9, configValue, 0); } +void xhciConfigureEndpoint(SlotXHCI *slot, UsbEndpointDescriptor *endpoint) { + uint8_t endpointNumber = endpoint->address & 0xF; // never 0 + uint8_t direction = endpoint->address >> 7; + uint8_t endpointIndex = (endpointNumber)*2 - 1 + direction; + XHCIInputContext *inputContext = slot->inputContext; + XHCIEndpointContext *endpointContext = + &inputContext->deviceContext.endpoints[endpointIndex]; + endpointContext->maxPrimaryStreams = 0; + endpointContext->interval = endpoint->interval; + endpointContext->errorCount = 3; + endpointContext->endpointType = + direction << 2 | endpoint->attributes & 3; + endpointContext->maxPacketSize = endpoint->maxPacketSize; + slot->endpointRings[endpointIndex] = malloc(sizeof(TrbRing)); + setupTrbRing(slot->endpointRings[endpointIndex], 256); + endpointContext->transferDequeuePointerLow = + U32(slot->endpointRings[endpointIndex]->physical) | 1; + endpointContext->transferDequeuePointerHigh = 0; + endpointContext->averageTRBLength = 2048; + inputContext->inputControl.addContextFlags |= 1 << (endpointIndex + 1); + inputContext->deviceContext.slot.contextEntryCount = MAX( + inputContext->deviceContext.slot.contextEntryCount, endpointIndex); +} + UsbHostControllerInterface xhci = { .initialize = init, .getDeviceDescriptor = (void *)usbGetDeviceDescriptor, - .setupEndpoints = (void *)xhciSetupEndpoints, + .setupEndpointsStart = (void *)xhciSetupEndpointsStart, + .setupEndpointsEnd = (void *)xhciSetupEndpointsEnd, + .configureEndpoint = (void *)xhciConfigureEndpoint, .pciClass = 0x0C0330, .doNormal = (void *)xhciNormal, .command = (void *)doXhciCommand,