diff --git a/src/userland/usb/include/usb.h b/src/userland/usb/include/usb.h index 42c3602..c35da42 100644 --- a/src/userland/usb/include/usb.h +++ b/src/userland/usb/include/usb.h @@ -63,8 +63,7 @@ void (*setupEndpoints)(void *, ListElement *, uint32_t); void (*setupHID)(void *, uint32_t, void *); void (*doNormal)(void *, void *); - void (*setProtocol)(void *); - void (*setIdle)(void *); + void (*command)(void *, uint8_t, uint8_t, uint16_t); } UsbHostControllerInterface; typedef struct { diff --git a/src/userland/usb/include/usb.h b/src/userland/usb/include/usb.h index 42c3602..c35da42 100644 --- a/src/userland/usb/include/usb.h +++ b/src/userland/usb/include/usb.h @@ -63,8 +63,7 @@ void (*setupEndpoints)(void *, ListElement *, uint32_t); void (*setupHID)(void *, uint32_t, void *); void (*doNormal)(void *, void *); - void (*setProtocol)(void *); - void (*setIdle)(void *); + void (*command)(void *, uint8_t, uint8_t, uint16_t); } UsbHostControllerInterface; typedef struct { diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index 8085b2b..1f62f5a 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -64,8 +64,10 @@ uint8_t direction = endpoint->address >> 7; uint8_t endpointIndex = (endpointNumber)*2 - 1 + direction; printf("endpoint index: %i\n", endpointIndex); - slot->interface->setProtocol(slot->data); - slot->interface->setIdle(slot->data); + // set protocol + slot->interface->command(slot->data, 0x21, 0x0B, 0); + // set IDLE + slot->interface->command(slot->data, 0x21, 0x0A, 0); registerHID(slot->id, 0); }) // clear list diff --git a/src/userland/usb/include/usb.h b/src/userland/usb/include/usb.h index 42c3602..c35da42 100644 --- a/src/userland/usb/include/usb.h +++ b/src/userland/usb/include/usb.h @@ -63,8 +63,7 @@ void (*setupEndpoints)(void *, ListElement *, uint32_t); void (*setupHID)(void *, uint32_t, void *); void (*doNormal)(void *, void *); - void (*setProtocol)(void *); - void (*setIdle)(void *); + void (*command)(void *, uint8_t, uint8_t, uint16_t); } UsbHostControllerInterface; typedef struct { diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index 8085b2b..1f62f5a 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -64,8 +64,10 @@ uint8_t direction = endpoint->address >> 7; uint8_t endpointIndex = (endpointNumber)*2 - 1 + direction; printf("endpoint index: %i\n", endpointIndex); - slot->interface->setProtocol(slot->data); - slot->interface->setIdle(slot->data); + // set protocol + slot->interface->command(slot->data, 0x21, 0x0B, 0); + // set IDLE + slot->interface->command(slot->data, 0x21, 0x0A, 0); registerHID(slot->id, 0); }) // clear list diff --git a/src/userland/usb/xhci/xhci.c b/src/userland/usb/xhci/xhci.c index 06d37d7..d550ea7 100644 --- a/src/userland/usb/xhci/xhci.c +++ b/src/userland/usb/xhci/xhci.c @@ -133,58 +133,6 @@ awaitCode(serviceId, xhciEvent, commandAddress); } -void setProtocol(SlotXHCI *slot) { - XHCISetupStageTRB setup = {0}; - setup.requestType = 0x21; - setup.request = 0x0B; - setup.value = 0; - setup.index = 0; - setup.length = 0; - setup.transferLength = 8; - setup.interruptOnCompletion = 0; - setup.interrupterTarget = 0; - setup.type = 2; - setup.transferType = 3; - setup.immediateData = 1; - XHCIStatusStageTRB status = {0}; - status.inDirection = 1; - status.evaluateNext = 0; - status.interruptOnCompletion = 1; - status.type = 4; - - enqueueCommand(slot->controlRing, (void *)&setup); - uint32_t commandAddress = - U32(enqueueCommand(slot->controlRing, (void *)&status)); - slot->controller->doorbells[slot->slotIndex] = 1; - awaitCode(serviceId, xhciEvent, commandAddress); -} - -void setIdle(SlotXHCI *slot, void *bufferPhysical) { - XHCISetupStageTRB setup = {0}; - setup.requestType = 0x21; - setup.request = 0x0A; - setup.value = 0; - setup.index = 0; - setup.length = 0; - setup.transferLength = 8; - setup.interruptOnCompletion = 0; - setup.interrupterTarget = 0; - setup.type = 2; - setup.transferType = 3; - setup.immediateData = 1; - XHCIStatusStageTRB status = {0}; - status.inDirection = 1; - status.evaluateNext = 0; - status.interruptOnCompletion = 1; - status.type = 4; - - enqueueCommand(slot->controlRing, (void *)&setup); - uint32_t commandAddress = - U32(enqueueCommand(slot->controlRing, (void *)&status)); - slot->controller->doorbells[slot->slotIndex] = 1; - awaitCode(serviceId, xhciEvent, commandAddress); -} - void xhciNormal(SlotXHCI *slot, void *bufferPhysical) { uint32_t endpointIndex = 2; // TODO XHCINormalTRB normal = {0}; @@ -202,12 +150,38 @@ awaitCode(serviceId, xhciEvent, commandAddress); } +void doXhciCommand(SlotXHCI *slot, uint8_t requestType, uint8_t request, uint16_t value) { + XHCISetupStageTRB setup = {0}; + setup.requestType = requestType; + setup.request = request; + setup.value = value; + setup.index = 0; + setup.length = 0; + setup.transferLength = 8; + setup.interruptOnCompletion = 0; + setup.interrupterTarget = 0; + setup.type = 2; + setup.transferType = 3; + setup.immediateData = 1; + enqueueCommand(slot->controlRing, (void *)&setup); + + XHCIStatusStageTRB status = {0}; + status.inDirection = 1; + status.evaluateNext = 0; + status.interruptOnCompletion = 1; + status.type = 4; + uint32_t commandAddress = + U32(enqueueCommand(slot->controlRing, (void *)&status)); + + slot->controller->doorbells[slot->slotIndex] = 1; + awaitCode(serviceId, xhciEvent, commandAddress); +} + UsbHostControllerInterface xhci = { .initialize = init, .getDeviceDescriptor = (void *)usbGetDeviceDescriptor, .setupEndpoints = (void *)xhciSetupEndpoints, .pciClass = 0x0C0330, .doNormal = (void *)xhciNormal, - .setProtocol = (void *)setProtocol, - .setIdle = (void *)setIdle, + .command = (void *)doXhciCommand, };