diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index 5647c74..3ede05d 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -283,9 +283,8 @@ device->buffer = malloc(0x1000); device->normalFunction = getFunction(serviceId, "hid_normal"); device->inputGroups = NULL; - printf("registered a new HID device, dumping report descriptor here:\n"); + printf("registered a new HID device, dumping report descriptor:\n"); uint32_t totalBits = parseReportDescriptor(report, &device->inputGroups); - printf("start waiting\n"); uint32_t getIntervalFunction = getFunction(serviceId, "hid_interval"); device->interval = request(serviceId, getIntervalFunction, usbDevice, 0); fork(hidListening, device, 0, 0); diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index 5647c74..3ede05d 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -283,9 +283,8 @@ device->buffer = malloc(0x1000); device->normalFunction = getFunction(serviceId, "hid_normal"); device->inputGroups = NULL; - printf("registered a new HID device, dumping report descriptor here:\n"); + printf("registered a new HID device, dumping report descriptor:\n"); uint32_t totalBits = parseReportDescriptor(report, &device->inputGroups); - printf("start waiting\n"); uint32_t getIntervalFunction = getFunction(serviceId, "hid_interval"); device->interval = request(serviceId, getIntervalFunction, usbDevice, 0); fork(hidListening, device, 0, 0); diff --git a/src/userland/usb/xhci/controller.c b/src/userland/usb/xhci/controller.c index 14c9a0a..d272bf5 100644 --- a/src/userland/usb/xhci/controller.c +++ b/src/userland/usb/xhci/controller.c @@ -41,8 +41,7 @@ controller->eventRingSegmentTable[0].ringSegmentBaseAddress[0] = U32(controller->events.physical); - controller->eventRingSegmentTable[0].ringSegmentSize = - controller->events.size; + controller->eventRingSegmentTable[0].ringSegmentSize = controller->events.size - 1; } void readExtendedCapabilities(XHCIController *controller) { @@ -135,17 +134,12 @@ if (globalController->runtime->interrupters[0].management & 1) { globalController->runtime->interrupters[0].management |= 1; XHCITRB *trb; - uint32_t index; - while ((trb = trbRingFetch(&globalController->events, &index))) { + while ((trb = trbRingFetch(&globalController->events, NULL))) { globalController->runtime->interrupters[0] .eventRingDequeuePointer[0] = 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); fireEventCode(xhciEvent, U32(trb), trb->dataLow); } } @@ -157,8 +151,9 @@ globalController = controller; restartXHCIController(controller); - setupTrbRing(&controller->commands, 256); - setupTrbRing(&controller->events, 256); + setupTrbRing(&controller->commands, 255); + // someting goes wrong when size > around 230 + setupTrbRing(&controller->events, 200); readExtendedCapabilities(controller); setupOperationalRegisters(controller); setupEventRingSegmentTable(controller); diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index 5647c74..3ede05d 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -283,9 +283,8 @@ device->buffer = malloc(0x1000); device->normalFunction = getFunction(serviceId, "hid_normal"); device->inputGroups = NULL; - printf("registered a new HID device, dumping report descriptor here:\n"); + printf("registered a new HID device, dumping report descriptor:\n"); uint32_t totalBits = parseReportDescriptor(report, &device->inputGroups); - printf("start waiting\n"); uint32_t getIntervalFunction = getFunction(serviceId, "hid_interval"); device->interval = request(serviceId, getIntervalFunction, usbDevice, 0); fork(hidListening, device, 0, 0); diff --git a/src/userland/usb/xhci/controller.c b/src/userland/usb/xhci/controller.c index 14c9a0a..d272bf5 100644 --- a/src/userland/usb/xhci/controller.c +++ b/src/userland/usb/xhci/controller.c @@ -41,8 +41,7 @@ controller->eventRingSegmentTable[0].ringSegmentBaseAddress[0] = U32(controller->events.physical); - controller->eventRingSegmentTable[0].ringSegmentSize = - controller->events.size; + controller->eventRingSegmentTable[0].ringSegmentSize = controller->events.size - 1; } void readExtendedCapabilities(XHCIController *controller) { @@ -135,17 +134,12 @@ if (globalController->runtime->interrupters[0].management & 1) { globalController->runtime->interrupters[0].management |= 1; XHCITRB *trb; - uint32_t index; - while ((trb = trbRingFetch(&globalController->events, &index))) { + while ((trb = trbRingFetch(&globalController->events, NULL))) { globalController->runtime->interrupters[0] .eventRingDequeuePointer[0] = 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); fireEventCode(xhciEvent, U32(trb), trb->dataLow); } } @@ -157,8 +151,9 @@ globalController = controller; restartXHCIController(controller); - setupTrbRing(&controller->commands, 256); - setupTrbRing(&controller->events, 256); + setupTrbRing(&controller->commands, 255); + // someting goes wrong when size > around 230 + setupTrbRing(&controller->events, 200); readExtendedCapabilities(controller); setupOperationalRegisters(controller); setupEventRingSegmentTable(controller); diff --git a/src/userland/usb/xhci/trbRing.c b/src/userland/usb/xhci/trbRing.c index fac19e1..544189b 100644 --- a/src/userland/usb/xhci/trbRing.c +++ b/src/userland/usb/xhci/trbRing.c @@ -7,14 +7,8 @@ XHCITRB *result = &ring->physical[ring->enqueue]; ring->enqueue++; if (ring->enqueue == ring->size - 1) { - if (ring->trbs[ring->enqueue].control & 1) { - ring->trbs[ring->enqueue].control &= ~1; - } else { - ring->trbs[ring->enqueue].control |= 1; - } - if (ring->trbs[ring->enqueue].control & 1) { - ring->cycle ^= 1; - } + ring->trbs[ring->enqueue].control = 1 ^ ring->trbs[ring->enqueue].control; + ring->cycle ^= 1; ring->enqueue = 0; } return result; @@ -29,15 +23,15 @@ } XHCITRB *result = &ring->trbs[ring->dequeue]; ring->dequeue++; - if (ring->dequeue == ring->size) { + if (ring->dequeue == ring->size - 1) { ring->dequeue = 0; - ring->cycle ^= -1; + ring->cycle ^= 1; } return result; } void setupTrbRing(TrbRing *ring, uint32_t size) { - ring->trbs = requestMemory(1, 0, 0); + ring->trbs = malloc(sizeof(XHCITRB) * (size + 1)); ring->physical = getPhysicalAddress((void *)ring->trbs); ring->cycle = true; ring->enqueue = 0; @@ -45,12 +39,14 @@ ring->size = size; // define link to beginning ring->trbs[ring->size - 1].dataLow = U32(ring->physical); - ring->trbs[ring->size - 1].control |= 1 << 1 | COMMAND_TYPE(6); + ring->trbs[ring->size - 1].dataHigh = 0; + ring->trbs[ring->size - 1].control = 1 << 1 | COMMAND_TYPE(6); + printf("TRB ring: size %i, malloced %i bytes", size, sizeof(XHCITRB) * (size + 1)); } TrbRing *createSlotTRB(SlotXHCI *slot) { TrbRing *ring = malloc(sizeof(TrbRing)); - setupTrbRing(ring, 256); + setupTrbRing(ring, 255); slot->inputContext->deviceContext.endpoints[0].transferDequeuePointerLow = U32(ring->physical) | 1; slot->inputContext->deviceContext.endpoints[0].transferDequeuePointerHigh = diff --git a/src/userland/hid/main.c b/src/userland/hid/main.c index 5647c74..3ede05d 100644 --- a/src/userland/hid/main.c +++ b/src/userland/hid/main.c @@ -283,9 +283,8 @@ device->buffer = malloc(0x1000); device->normalFunction = getFunction(serviceId, "hid_normal"); device->inputGroups = NULL; - printf("registered a new HID device, dumping report descriptor here:\n"); + printf("registered a new HID device, dumping report descriptor:\n"); uint32_t totalBits = parseReportDescriptor(report, &device->inputGroups); - printf("start waiting\n"); uint32_t getIntervalFunction = getFunction(serviceId, "hid_interval"); device->interval = request(serviceId, getIntervalFunction, usbDevice, 0); fork(hidListening, device, 0, 0); diff --git a/src/userland/usb/xhci/controller.c b/src/userland/usb/xhci/controller.c index 14c9a0a..d272bf5 100644 --- a/src/userland/usb/xhci/controller.c +++ b/src/userland/usb/xhci/controller.c @@ -41,8 +41,7 @@ controller->eventRingSegmentTable[0].ringSegmentBaseAddress[0] = U32(controller->events.physical); - controller->eventRingSegmentTable[0].ringSegmentSize = - controller->events.size; + controller->eventRingSegmentTable[0].ringSegmentSize = controller->events.size - 1; } void readExtendedCapabilities(XHCIController *controller) { @@ -135,17 +134,12 @@ if (globalController->runtime->interrupters[0].management & 1) { globalController->runtime->interrupters[0].management |= 1; XHCITRB *trb; - uint32_t index; - while ((trb = trbRingFetch(&globalController->events, &index))) { + while ((trb = trbRingFetch(&globalController->events, NULL))) { globalController->runtime->interrupters[0] .eventRingDequeuePointer[0] = 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); fireEventCode(xhciEvent, U32(trb), trb->dataLow); } } @@ -157,8 +151,9 @@ globalController = controller; restartXHCIController(controller); - setupTrbRing(&controller->commands, 256); - setupTrbRing(&controller->events, 256); + setupTrbRing(&controller->commands, 255); + // someting goes wrong when size > around 230 + setupTrbRing(&controller->events, 200); readExtendedCapabilities(controller); setupOperationalRegisters(controller); setupEventRingSegmentTable(controller); diff --git a/src/userland/usb/xhci/trbRing.c b/src/userland/usb/xhci/trbRing.c index fac19e1..544189b 100644 --- a/src/userland/usb/xhci/trbRing.c +++ b/src/userland/usb/xhci/trbRing.c @@ -7,14 +7,8 @@ XHCITRB *result = &ring->physical[ring->enqueue]; ring->enqueue++; if (ring->enqueue == ring->size - 1) { - if (ring->trbs[ring->enqueue].control & 1) { - ring->trbs[ring->enqueue].control &= ~1; - } else { - ring->trbs[ring->enqueue].control |= 1; - } - if (ring->trbs[ring->enqueue].control & 1) { - ring->cycle ^= 1; - } + ring->trbs[ring->enqueue].control = 1 ^ ring->trbs[ring->enqueue].control; + ring->cycle ^= 1; ring->enqueue = 0; } return result; @@ -29,15 +23,15 @@ } XHCITRB *result = &ring->trbs[ring->dequeue]; ring->dequeue++; - if (ring->dequeue == ring->size) { + if (ring->dequeue == ring->size - 1) { ring->dequeue = 0; - ring->cycle ^= -1; + ring->cycle ^= 1; } return result; } void setupTrbRing(TrbRing *ring, uint32_t size) { - ring->trbs = requestMemory(1, 0, 0); + ring->trbs = malloc(sizeof(XHCITRB) * (size + 1)); ring->physical = getPhysicalAddress((void *)ring->trbs); ring->cycle = true; ring->enqueue = 0; @@ -45,12 +39,14 @@ ring->size = size; // define link to beginning ring->trbs[ring->size - 1].dataLow = U32(ring->physical); - ring->trbs[ring->size - 1].control |= 1 << 1 | COMMAND_TYPE(6); + ring->trbs[ring->size - 1].dataHigh = 0; + ring->trbs[ring->size - 1].control = 1 << 1 | COMMAND_TYPE(6); + printf("TRB ring: size %i, malloced %i bytes", size, sizeof(XHCITRB) * (size + 1)); } TrbRing *createSlotTRB(SlotXHCI *slot) { TrbRing *ring = malloc(sizeof(TrbRing)); - setupTrbRing(ring, 256); + setupTrbRing(ring, 255); slot->inputContext->deviceContext.endpoints[0].transferDequeuePointerLow = U32(ring->physical) | 1; slot->inputContext->deviceContext.endpoints[0].transferDequeuePointerHigh = diff --git a/src/userland/usb/xhci/xhci.c b/src/userland/usb/xhci/xhci.c index 6475e34..8e8fd6c 100644 --- a/src/userland/usb/xhci/xhci.c +++ b/src/userland/usb/xhci/xhci.c @@ -147,7 +147,7 @@ direction << 2 | endpoint->attributes & 3; endpointContext->maxPacketSize = endpoint->maxPacketSize; slot->endpointRings[endpointIndex] = malloc(sizeof(TrbRing)); - setupTrbRing(slot->endpointRings[endpointIndex], 256); + setupTrbRing(slot->endpointRings[endpointIndex], 255); endpointContext->transferDequeuePointerLow = U32(slot->endpointRings[endpointIndex]->physical) | 1; endpointContext->transferDequeuePointerHigh = 0;