diff --git a/src/userland/scisi/main.c b/src/userland/scisi/main.c index ade0a20..2598d0d 100644 --- a/src/userland/scisi/main.c +++ b/src/userland/scisi/main.c @@ -13,6 +13,9 @@ command->control = 0; command->size = sizeof(InquiryCommand) - sizeof(uint32_t); request(device->serviceId, device->outFunction, device->out, U32(getPhysicalAddress(command))); + request(device->serviceId, device->inFunction, device->in, U32(getPhysicalAddress(command))); + request(device->serviceId, device->inFunction, device->in, U32(getPhysicalAddress(command))); + request(device->serviceId, device->inFunction, device->in, U32(getPhysicalAddress(command))); } int32_t registerDevice(uint32_t in, uint32_t out, uint32_t serviceName, uint32_t serviceId) { diff --git a/src/userland/scisi/main.c b/src/userland/scisi/main.c index ade0a20..2598d0d 100644 --- a/src/userland/scisi/main.c +++ b/src/userland/scisi/main.c @@ -13,6 +13,9 @@ command->control = 0; command->size = sizeof(InquiryCommand) - sizeof(uint32_t); request(device->serviceId, device->outFunction, device->out, U32(getPhysicalAddress(command))); + request(device->serviceId, device->inFunction, device->in, U32(getPhysicalAddress(command))); + request(device->serviceId, device->inFunction, device->in, U32(getPhysicalAddress(command))); + request(device->serviceId, device->inFunction, device->in, U32(getPhysicalAddress(command))); } int32_t registerDevice(uint32_t in, uint32_t out, uint32_t serviceName, uint32_t serviceId) { diff --git a/src/userland/usb/include/usb.h b/src/userland/usb/include/usb.h index f73e4c6..de68bb0 100644 --- a/src/userland/usb/include/usb.h +++ b/src/userland/usb/include/usb.h @@ -72,6 +72,7 @@ void (*command)(void *, uint8_t, uint8_t, uint16_t, uint8_t); uint32_t (*configureEndpoint)(void *, UsbEndpointDescriptor *); void (*writeNormal)(void *, void *, uint32_t, uint32_t); + void (*readNormal)(void *, void *, uint32_t, uint32_t); } UsbHostControllerInterface; typedef struct { diff --git a/src/userland/scisi/main.c b/src/userland/scisi/main.c index ade0a20..2598d0d 100644 --- a/src/userland/scisi/main.c +++ b/src/userland/scisi/main.c @@ -13,6 +13,9 @@ command->control = 0; command->size = sizeof(InquiryCommand) - sizeof(uint32_t); request(device->serviceId, device->outFunction, device->out, U32(getPhysicalAddress(command))); + request(device->serviceId, device->inFunction, device->in, U32(getPhysicalAddress(command))); + request(device->serviceId, device->inFunction, device->in, U32(getPhysicalAddress(command))); + request(device->serviceId, device->inFunction, device->in, U32(getPhysicalAddress(command))); } int32_t registerDevice(uint32_t in, uint32_t out, uint32_t serviceName, uint32_t serviceId) { diff --git a/src/userland/usb/include/usb.h b/src/userland/usb/include/usb.h index f73e4c6..de68bb0 100644 --- a/src/userland/usb/include/usb.h +++ b/src/userland/usb/include/usb.h @@ -72,6 +72,7 @@ void (*command)(void *, uint8_t, uint8_t, uint16_t, uint8_t); uint32_t (*configureEndpoint)(void *, UsbEndpointDescriptor *); void (*writeNormal)(void *, void *, uint32_t, uint32_t); + void (*readNormal)(void *, void *, uint32_t, uint32_t); } UsbHostControllerInterface; typedef struct { diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index 8ffd584..1b2a9e1 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -60,14 +60,15 @@ endpoint = (void *) findDescriptor((void *) endpoint + endpoint->size, 5); uint8_t endpoint2 = getEndpointIndex(endpoint); uint32_t deviceType = interface->subClass & 0xFF | interface->protocol & 0xFF << 8; - uint8_t inEndpoint = endpoint1 & 1 ? endpoint1 : endpoint2; - uint8_t outEndpoint = endpoint1 & 1 ? endpoint2 : endpoint1; + uint8_t outEndpoint = endpoint1 & 1 ? endpoint1 : endpoint2; + uint8_t inEndpoint = endpoint1 & 1 ? endpoint2 : endpoint1; registerMassStorage(slot->id | (uint32_t) inEndpoint << 16, slot->id | (uint32_t) outEndpoint << 16); } void setupInterfaces(UsbSlot *slot) { // only doing blank interface descriptors for now, there are // also interface assosciations... + // also: only the first interface descriptor is used and set up here... UsbInterfaceDescriptor *interface = (void *)slot->descriptor + slot->descriptor->size; slot->interface->setupEndpointsStart(slot->data, slot->descriptor->configurationValue); UsbInterfaceDescriptor *firstInterface = NULL; @@ -174,6 +175,14 @@ write(usbSlot->data, buffer + 4, slotId >> 16, size); } +void storageRead(uint32_t slotId, void *buffer) { + uint32_t *bufferHere = requestMemory(1, NULL, buffer); + uint32_t size = *bufferHere; + UsbSlot *usbSlot = listGet(usbSlots, slotId & 0xFFFF); + void (*read)(void *, void *, uint32_t, uint32_t) = usbSlot->interface->readNormal; + read(usbSlot->data, buffer + 4, slotId >> 16, size); +} + uint32_t hidInterval(uint32_t slotId) { UsbSlot *usbSlot = listGet(usbSlots, slotId & 0xFFFF); return usbSlot->interval; @@ -225,6 +234,7 @@ createFunction("hid_normal", (void *)hidNormal); createFunction("hid_interval", (void *)hidInterval); createFunction("storage_out", (void *)storageWrite); + createFunction("storage_in", (void *)storageRead); createFunction("get_type", (void *)getType); for (uint32_t i = 0;; i++) { uint32_t class = getDeviceClass(i, 0); diff --git a/src/userland/scisi/main.c b/src/userland/scisi/main.c index ade0a20..2598d0d 100644 --- a/src/userland/scisi/main.c +++ b/src/userland/scisi/main.c @@ -13,6 +13,9 @@ command->control = 0; command->size = sizeof(InquiryCommand) - sizeof(uint32_t); request(device->serviceId, device->outFunction, device->out, U32(getPhysicalAddress(command))); + request(device->serviceId, device->inFunction, device->in, U32(getPhysicalAddress(command))); + request(device->serviceId, device->inFunction, device->in, U32(getPhysicalAddress(command))); + request(device->serviceId, device->inFunction, device->in, U32(getPhysicalAddress(command))); } int32_t registerDevice(uint32_t in, uint32_t out, uint32_t serviceName, uint32_t serviceId) { diff --git a/src/userland/usb/include/usb.h b/src/userland/usb/include/usb.h index f73e4c6..de68bb0 100644 --- a/src/userland/usb/include/usb.h +++ b/src/userland/usb/include/usb.h @@ -72,6 +72,7 @@ void (*command)(void *, uint8_t, uint8_t, uint16_t, uint8_t); uint32_t (*configureEndpoint)(void *, UsbEndpointDescriptor *); void (*writeNormal)(void *, void *, uint32_t, uint32_t); + void (*readNormal)(void *, void *, uint32_t, uint32_t); } UsbHostControllerInterface; typedef struct { diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index 8ffd584..1b2a9e1 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -60,14 +60,15 @@ endpoint = (void *) findDescriptor((void *) endpoint + endpoint->size, 5); uint8_t endpoint2 = getEndpointIndex(endpoint); uint32_t deviceType = interface->subClass & 0xFF | interface->protocol & 0xFF << 8; - uint8_t inEndpoint = endpoint1 & 1 ? endpoint1 : endpoint2; - uint8_t outEndpoint = endpoint1 & 1 ? endpoint2 : endpoint1; + uint8_t outEndpoint = endpoint1 & 1 ? endpoint1 : endpoint2; + uint8_t inEndpoint = endpoint1 & 1 ? endpoint2 : endpoint1; registerMassStorage(slot->id | (uint32_t) inEndpoint << 16, slot->id | (uint32_t) outEndpoint << 16); } void setupInterfaces(UsbSlot *slot) { // only doing blank interface descriptors for now, there are // also interface assosciations... + // also: only the first interface descriptor is used and set up here... UsbInterfaceDescriptor *interface = (void *)slot->descriptor + slot->descriptor->size; slot->interface->setupEndpointsStart(slot->data, slot->descriptor->configurationValue); UsbInterfaceDescriptor *firstInterface = NULL; @@ -174,6 +175,14 @@ write(usbSlot->data, buffer + 4, slotId >> 16, size); } +void storageRead(uint32_t slotId, void *buffer) { + uint32_t *bufferHere = requestMemory(1, NULL, buffer); + uint32_t size = *bufferHere; + UsbSlot *usbSlot = listGet(usbSlots, slotId & 0xFFFF); + void (*read)(void *, void *, uint32_t, uint32_t) = usbSlot->interface->readNormal; + read(usbSlot->data, buffer + 4, slotId >> 16, size); +} + uint32_t hidInterval(uint32_t slotId) { UsbSlot *usbSlot = listGet(usbSlots, slotId & 0xFFFF); return usbSlot->interval; @@ -225,6 +234,7 @@ createFunction("hid_normal", (void *)hidNormal); createFunction("hid_interval", (void *)hidInterval); createFunction("storage_out", (void *)storageWrite); + createFunction("storage_in", (void *)storageRead); createFunction("get_type", (void *)getType); for (uint32_t i = 0;; i++) { uint32_t class = getDeviceClass(i, 0); diff --git a/src/userland/usb/xhci/xhci.c b/src/userland/usb/xhci/xhci.c index 7be7c32..35c1feb 100644 --- a/src/userland/usb/xhci/xhci.c +++ b/src/userland/usb/xhci/xhci.c @@ -84,15 +84,14 @@ } void doXhciWriteNormal(SlotXHCI * slot, void *bufferPhysical, uint32_t endpointIndex, uint32_t transferSize) { - printf("still alive: %x, %x, %i, %i\n", slot, bufferPhysical, endpointIndex, transferSize); - printf("%x", slot->inputContext->deviceContext.endpoints[endpointIndex].endpointType); + // incidentally, this also works for reading from the XHCI device. nice! XHCINormalTRB normal = {0}; normal.dataBuffer[0] = U32(bufferPhysical); normal.dataBuffer[1] = 0; normal.interrupterTarget = 0; normal.interruptOnCompletion = 1; normal.interruptOnShortPacket = 1; - normal.transferSize = 4; + normal.transferSize = transferSize; normal.type = 1; uint32_t commandAddress = U32(enqueueCommand( slot->endpointRings[endpointIndex], (void *)&normal)); @@ -182,4 +181,5 @@ .doNormal = (void *)xhciNormal, .command = (void *)doXhciCommand, .writeNormal = (void *)doXhciWriteNormal, + .readNormal = (void *)doXhciWriteNormal, }; diff --git a/src/userland/scisi/main.c b/src/userland/scisi/main.c index ade0a20..2598d0d 100644 --- a/src/userland/scisi/main.c +++ b/src/userland/scisi/main.c @@ -13,6 +13,9 @@ command->control = 0; command->size = sizeof(InquiryCommand) - sizeof(uint32_t); request(device->serviceId, device->outFunction, device->out, U32(getPhysicalAddress(command))); + request(device->serviceId, device->inFunction, device->in, U32(getPhysicalAddress(command))); + request(device->serviceId, device->inFunction, device->in, U32(getPhysicalAddress(command))); + request(device->serviceId, device->inFunction, device->in, U32(getPhysicalAddress(command))); } int32_t registerDevice(uint32_t in, uint32_t out, uint32_t serviceName, uint32_t serviceId) { diff --git a/src/userland/usb/include/usb.h b/src/userland/usb/include/usb.h index f73e4c6..de68bb0 100644 --- a/src/userland/usb/include/usb.h +++ b/src/userland/usb/include/usb.h @@ -72,6 +72,7 @@ void (*command)(void *, uint8_t, uint8_t, uint16_t, uint8_t); uint32_t (*configureEndpoint)(void *, UsbEndpointDescriptor *); void (*writeNormal)(void *, void *, uint32_t, uint32_t); + void (*readNormal)(void *, void *, uint32_t, uint32_t); } UsbHostControllerInterface; typedef struct { diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index 8ffd584..1b2a9e1 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -60,14 +60,15 @@ endpoint = (void *) findDescriptor((void *) endpoint + endpoint->size, 5); uint8_t endpoint2 = getEndpointIndex(endpoint); uint32_t deviceType = interface->subClass & 0xFF | interface->protocol & 0xFF << 8; - uint8_t inEndpoint = endpoint1 & 1 ? endpoint1 : endpoint2; - uint8_t outEndpoint = endpoint1 & 1 ? endpoint2 : endpoint1; + uint8_t outEndpoint = endpoint1 & 1 ? endpoint1 : endpoint2; + uint8_t inEndpoint = endpoint1 & 1 ? endpoint2 : endpoint1; registerMassStorage(slot->id | (uint32_t) inEndpoint << 16, slot->id | (uint32_t) outEndpoint << 16); } void setupInterfaces(UsbSlot *slot) { // only doing blank interface descriptors for now, there are // also interface assosciations... + // also: only the first interface descriptor is used and set up here... UsbInterfaceDescriptor *interface = (void *)slot->descriptor + slot->descriptor->size; slot->interface->setupEndpointsStart(slot->data, slot->descriptor->configurationValue); UsbInterfaceDescriptor *firstInterface = NULL; @@ -174,6 +175,14 @@ write(usbSlot->data, buffer + 4, slotId >> 16, size); } +void storageRead(uint32_t slotId, void *buffer) { + uint32_t *bufferHere = requestMemory(1, NULL, buffer); + uint32_t size = *bufferHere; + UsbSlot *usbSlot = listGet(usbSlots, slotId & 0xFFFF); + void (*read)(void *, void *, uint32_t, uint32_t) = usbSlot->interface->readNormal; + read(usbSlot->data, buffer + 4, slotId >> 16, size); +} + uint32_t hidInterval(uint32_t slotId) { UsbSlot *usbSlot = listGet(usbSlots, slotId & 0xFFFF); return usbSlot->interval; @@ -225,6 +234,7 @@ createFunction("hid_normal", (void *)hidNormal); createFunction("hid_interval", (void *)hidInterval); createFunction("storage_out", (void *)storageWrite); + createFunction("storage_in", (void *)storageRead); createFunction("get_type", (void *)getType); for (uint32_t i = 0;; i++) { uint32_t class = getDeviceClass(i, 0); diff --git a/src/userland/usb/xhci/xhci.c b/src/userland/usb/xhci/xhci.c index 7be7c32..35c1feb 100644 --- a/src/userland/usb/xhci/xhci.c +++ b/src/userland/usb/xhci/xhci.c @@ -84,15 +84,14 @@ } void doXhciWriteNormal(SlotXHCI * slot, void *bufferPhysical, uint32_t endpointIndex, uint32_t transferSize) { - printf("still alive: %x, %x, %i, %i\n", slot, bufferPhysical, endpointIndex, transferSize); - printf("%x", slot->inputContext->deviceContext.endpoints[endpointIndex].endpointType); + // incidentally, this also works for reading from the XHCI device. nice! XHCINormalTRB normal = {0}; normal.dataBuffer[0] = U32(bufferPhysical); normal.dataBuffer[1] = 0; normal.interrupterTarget = 0; normal.interruptOnCompletion = 1; normal.interruptOnShortPacket = 1; - normal.transferSize = 4; + normal.transferSize = transferSize; normal.type = 1; uint32_t commandAddress = U32(enqueueCommand( slot->endpointRings[endpointIndex], (void *)&normal)); @@ -182,4 +181,5 @@ .doNormal = (void *)xhciNormal, .command = (void *)doXhciCommand, .writeNormal = (void *)doXhciWriteNormal, + .readNormal = (void *)doXhciWriteNormal, }; diff --git a/src/userland/usbStorage/main.c b/src/userland/usbStorage/main.c index 184ce0c..12c883b 100644 --- a/src/userland/usbStorage/main.c +++ b/src/userland/usbStorage/main.c @@ -33,10 +33,20 @@ REQUEST(registerScisi, "scisi", "register"); ListElement *devices; -uint32_t in(uint32_t in) { +uint32_t in(uint32_t in, void *data) { StorageDevice *device = listGet(devices, in & 0xFFFF); uint16_t endpoint = in >> 16; printf("reading from device %i (usb device %i, endpoint %i, id %x)...\n", device->id, device->deviceId, endpoint, in); + + uint32_t *dataHere = malloc(100); + *dataHere = 100; + uint32_t size = *dataHere; + uint8_t *resultData = (void *)dataHere; + + request(device->serviceId, device->inFunction, in & 0xFFFF0000 | device->deviceId, U32(getPhysicalAddress(resultData))); + for (uint32_t i = 1; i <= 8; i++) { + printf("read: %x %x %x %x\n", resultData[4*i], resultData[4*i + 1], resultData[4*i + 2], resultData[4*i + 3]); + } return 0; } @@ -46,16 +56,17 @@ StorageDevice *device = listGet(devices, out & 0xFFFF); uint16_t endpoint = out >> 16; CommandBlockWrapper *command = malloc(sizeof(CommandBlockWrapper)); - command->size = 15 + size; + command->size = 31; command->signature = 0x43425355; command->tag = 0xB105F00D; // just testing for now... command->length = 0; command->flags.values.direction = 1; command->LUN = 0; command->length = size; + command->transferSize = 5; memcpy(dataHere + 1, command->data, size); - request(device->serviceId, device->outFunction, out & 0xFFFF0000 | device->deviceId, U32(getPhysicalAddress(command))); printf("writing to device %i (usb device %i, endpoint %i, id %x)...\n", device->id, device->deviceId, endpoint, out); + request(device->serviceId, device->outFunction, out & 0xFFFF0000 | device->deviceId, U32(getPhysicalAddress(command))); freePage(dataHere); return 0; }