diff --git a/src/userland/usb/include/usb.h b/src/userland/usb/include/usb.h index a565a40..b9595da 100644 --- a/src/userland/usb/include/usb.h +++ b/src/userland/usb/include/usb.h @@ -62,6 +62,7 @@ void (*getDeviceDescriptor)(void *, uint32_t, uint32_t, void *); void (*setupEndpoints)(void *, ListElement *, uint32_t); void (*setupHID)(void *, uint32_t, void *); + void (*doNormal)(void *, void *); } UsbHostControllerInterface; typedef struct { diff --git a/src/userland/usb/include/usb.h b/src/userland/usb/include/usb.h index a565a40..b9595da 100644 --- a/src/userland/usb/include/usb.h +++ b/src/userland/usb/include/usb.h @@ -62,6 +62,7 @@ void (*getDeviceDescriptor)(void *, uint32_t, uint32_t, void *); void (*setupEndpoints)(void *, ListElement *, uint32_t); void (*setupHID)(void *, uint32_t, void *); + void (*doNormal)(void *, void *); } UsbHostControllerInterface; typedef struct { diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index 3667260..e355d29 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -140,24 +140,9 @@ bool initialized = false; -void hid_normal(uint32_t slotId, void *bufferPhysical) { +void hidNormal(uint32_t slotId, void *bufferPhysical) { UsbSlot *usbSlot = listGet(usbSlots, slotId); - SlotXHCI *slot = usbSlot->data; - uint32_t endpointIndex = 2; // TODO - XHCINormalTRB normal = {0}; - normal.type = 1; - normal.inDirection = 1; - normal.interrupterTarget = 0; - normal.interruptOnCompletion = 1; - normal.interruptOnShortPacket = 1; - normal.dataBuffer[0] = U32(bufferPhysical); - normal.dataBuffer[1] = 0; - normal.transferSize = 4; - uint32_t commandAddress = U32(enqueueCommand( - slot->endpointRings[endpointIndex], (void *)&normal)); - slot->controller->doorbells[slot->slotIndex] = endpointIndex + 1; - printf("xhci normal %i, %x, %x", slotId, bufferPhysical, commandAddress); - awaitCode(serviceId, xhciEvent, commandAddress); + usbSlot->interface->doNormal(usbSlot->data, bufferPhysical); // data is returned to buffer } @@ -165,7 +150,7 @@ serviceId = getServiceId(); xhciEvent = createEvent("xhciEvent"); loadFromInitrd("hid"); - createFunction("hid_normal", (void *)hid_normal); + createFunction("hid_normal", (void *)hidNormal); // xhciEvent will carry data corresponding to the data in the xhci event // code will be used to identify an event for (uint32_t i = 0; i < 100; i++) { diff --git a/src/userland/usb/include/usb.h b/src/userland/usb/include/usb.h index a565a40..b9595da 100644 --- a/src/userland/usb/include/usb.h +++ b/src/userland/usb/include/usb.h @@ -62,6 +62,7 @@ void (*getDeviceDescriptor)(void *, uint32_t, uint32_t, void *); void (*setupEndpoints)(void *, ListElement *, uint32_t); void (*setupHID)(void *, uint32_t, void *); + void (*doNormal)(void *, void *); } UsbHostControllerInterface; typedef struct { diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index 3667260..e355d29 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -140,24 +140,9 @@ bool initialized = false; -void hid_normal(uint32_t slotId, void *bufferPhysical) { +void hidNormal(uint32_t slotId, void *bufferPhysical) { UsbSlot *usbSlot = listGet(usbSlots, slotId); - SlotXHCI *slot = usbSlot->data; - uint32_t endpointIndex = 2; // TODO - XHCINormalTRB normal = {0}; - normal.type = 1; - normal.inDirection = 1; - normal.interrupterTarget = 0; - normal.interruptOnCompletion = 1; - normal.interruptOnShortPacket = 1; - normal.dataBuffer[0] = U32(bufferPhysical); - normal.dataBuffer[1] = 0; - normal.transferSize = 4; - uint32_t commandAddress = U32(enqueueCommand( - slot->endpointRings[endpointIndex], (void *)&normal)); - slot->controller->doorbells[slot->slotIndex] = endpointIndex + 1; - printf("xhci normal %i, %x, %x", slotId, bufferPhysical, commandAddress); - awaitCode(serviceId, xhciEvent, commandAddress); + usbSlot->interface->doNormal(usbSlot->data, bufferPhysical); // data is returned to buffer } @@ -165,7 +150,7 @@ serviceId = getServiceId(); xhciEvent = createEvent("xhciEvent"); loadFromInitrd("hid"); - createFunction("hid_normal", (void *)hid_normal); + createFunction("hid_normal", (void *)hidNormal); // xhciEvent will carry data corresponding to the data in the xhci event // code will be used to identify an event for (uint32_t i = 0; i < 100; i++) { diff --git a/src/userland/usb/xhci/controller.c b/src/userland/usb/xhci/controller.c index 247fd01..14c9a0a 100644 --- a/src/userland/usb/xhci/controller.c +++ b/src/userland/usb/xhci/controller.c @@ -142,10 +142,10 @@ U32(&globalController->events .physical[globalController->events.dequeue]) | (1 << 3); - printf("event %i [%x %x %x %x]: %i\n", - globalController->events.dequeue, trb->dataLow, - trb->dataHigh, trb->status, trb->control, - trb->control >> 10 & 0x3F); + // printf("event %i [%x %x %x %x]: %i\n", + // globalController->events.dequeue, trb->dataLow, + // trb->dataHigh, trb->status, trb->control, + // trb->control >> 10 & 0x3F); fireEventCode(xhciEvent, U32(trb), trb->dataLow); } } diff --git a/src/userland/usb/include/usb.h b/src/userland/usb/include/usb.h index a565a40..b9595da 100644 --- a/src/userland/usb/include/usb.h +++ b/src/userland/usb/include/usb.h @@ -62,6 +62,7 @@ void (*getDeviceDescriptor)(void *, uint32_t, uint32_t, void *); void (*setupEndpoints)(void *, ListElement *, uint32_t); void (*setupHID)(void *, uint32_t, void *); + void (*doNormal)(void *, void *); } UsbHostControllerInterface; typedef struct { diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index 3667260..e355d29 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -140,24 +140,9 @@ bool initialized = false; -void hid_normal(uint32_t slotId, void *bufferPhysical) { +void hidNormal(uint32_t slotId, void *bufferPhysical) { UsbSlot *usbSlot = listGet(usbSlots, slotId); - SlotXHCI *slot = usbSlot->data; - uint32_t endpointIndex = 2; // TODO - XHCINormalTRB normal = {0}; - normal.type = 1; - normal.inDirection = 1; - normal.interrupterTarget = 0; - normal.interruptOnCompletion = 1; - normal.interruptOnShortPacket = 1; - normal.dataBuffer[0] = U32(bufferPhysical); - normal.dataBuffer[1] = 0; - normal.transferSize = 4; - uint32_t commandAddress = U32(enqueueCommand( - slot->endpointRings[endpointIndex], (void *)&normal)); - slot->controller->doorbells[slot->slotIndex] = endpointIndex + 1; - printf("xhci normal %i, %x, %x", slotId, bufferPhysical, commandAddress); - awaitCode(serviceId, xhciEvent, commandAddress); + usbSlot->interface->doNormal(usbSlot->data, bufferPhysical); // data is returned to buffer } @@ -165,7 +150,7 @@ serviceId = getServiceId(); xhciEvent = createEvent("xhciEvent"); loadFromInitrd("hid"); - createFunction("hid_normal", (void *)hid_normal); + createFunction("hid_normal", (void *)hidNormal); // xhciEvent will carry data corresponding to the data in the xhci event // code will be used to identify an event for (uint32_t i = 0; i < 100; i++) { diff --git a/src/userland/usb/xhci/controller.c b/src/userland/usb/xhci/controller.c index 247fd01..14c9a0a 100644 --- a/src/userland/usb/xhci/controller.c +++ b/src/userland/usb/xhci/controller.c @@ -142,10 +142,10 @@ U32(&globalController->events .physical[globalController->events.dequeue]) | (1 << 3); - printf("event %i [%x %x %x %x]: %i\n", - globalController->events.dequeue, trb->dataLow, - trb->dataHigh, trb->status, trb->control, - trb->control >> 10 & 0x3F); + // printf("event %i [%x %x %x %x]: %i\n", + // globalController->events.dequeue, trb->dataLow, + // trb->dataHigh, trb->status, trb->control, + // trb->control >> 10 & 0x3F); fireEventCode(xhciEvent, U32(trb), trb->dataLow); } } diff --git a/src/userland/usb/xhci/xhci.c b/src/userland/usb/xhci/xhci.c index 5ab5167..a697220 100644 --- a/src/userland/usb/xhci/xhci.c +++ b/src/userland/usb/xhci/xhci.c @@ -159,7 +159,7 @@ awaitCode(serviceId, xhciEvent, commandAddress); } -void setIdle(SlotXHCI *slot) { +void setIdle(SlotXHCI *slot, void *bufferPhysical) { XHCISetupStageTRB setup = {0}; setup.requestType = 0x21; setup.request = 0x0A; @@ -184,11 +184,28 @@ slot->controller->doorbells[slot->slotIndex] = 1; awaitCode(serviceId, xhciEvent, commandAddress); } + +void xhciNormal(SlotXHCI *slot, void *bufferPhysical) { + uint32_t endpointIndex = 2; // TODO + XHCINormalTRB normal = {0}; + normal.type = 1; + normal.inDirection = 1; + normal.interrupterTarget = 0; + normal.interruptOnCompletion = 1; + normal.interruptOnShortPacket = 1; + normal.dataBuffer[0] = U32(bufferPhysical); + normal.dataBuffer[1] = 0; + normal.transferSize = 4; + uint32_t commandAddress = U32(enqueueCommand( + slot->endpointRings[endpointIndex], (void *)&normal)); + slot->controller->doorbells[slot->slotIndex] = endpointIndex + 1; + awaitCode(serviceId, xhciEvent, commandAddress); +} UsbHostControllerInterface xhci = { .initialize = init, .getDeviceDescriptor = (void *)usbGetDeviceDescriptor, .setupEndpoints = (void *)xhciSetupEndpoints, - //.setupHID = (void *)setupHID, .pciClass = 0x0C0330, + .doNormal = (void *)xhciNormal, };