diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index 7633554..99f196d 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -99,9 +99,25 @@ } operational->deviceNotificationControl = 2; operational->configure |= 16; - DeviceContext *context = malloc(sizeof(DeviceContext)); + DeviceContextArray *deviceContextArray = malloc(sizeof(DeviceContextArray)); operational->deviceContextArray = - (uint64_t)U32(getPhysicalAddress(context)); + (uint64_t)U32(getPhysicalAddress(deviceContextArray)); + uint32_t maxScratchpatchBufferCount = + ((capabilities->capabilityParameters2 >> 27) & 0x1F) | + ((capabilities->capabilityParameters2 >> 16) & 0xE0); + if (maxScratchpatchBufferCount) { + printf("creatng scratchpad buffers\n"); + uint64_t *scratchpadBuffers = + malloc(sizeof(uint64_t) * maxScratchpatchBufferCount); + for (uint32_t i = 0; i < maxScratchpatchBufferCount; i++) { + scratchpadBuffers[i] = U32(getPhysicalAddress(malloc(4096))); + } + deviceContextArray->scratchpadBufferBase = + U32(getPhysicalAddress(scratchpadBuffers)); + } else { + printf("no scratchpad buffers implemented\n"); + deviceContextArray->scratchpadBufferBase = 0; + } XHCIPortRegister *ports = OFFSET(operational, 0x400); for (uint32_t i = 0; i < 16; i++) { diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index 7633554..99f196d 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -99,9 +99,25 @@ } operational->deviceNotificationControl = 2; operational->configure |= 16; - DeviceContext *context = malloc(sizeof(DeviceContext)); + DeviceContextArray *deviceContextArray = malloc(sizeof(DeviceContextArray)); operational->deviceContextArray = - (uint64_t)U32(getPhysicalAddress(context)); + (uint64_t)U32(getPhysicalAddress(deviceContextArray)); + uint32_t maxScratchpatchBufferCount = + ((capabilities->capabilityParameters2 >> 27) & 0x1F) | + ((capabilities->capabilityParameters2 >> 16) & 0xE0); + if (maxScratchpatchBufferCount) { + printf("creatng scratchpad buffers\n"); + uint64_t *scratchpadBuffers = + malloc(sizeof(uint64_t) * maxScratchpatchBufferCount); + for (uint32_t i = 0; i < maxScratchpatchBufferCount; i++) { + scratchpadBuffers[i] = U32(getPhysicalAddress(malloc(4096))); + } + deviceContextArray->scratchpadBufferBase = + U32(getPhysicalAddress(scratchpadBuffers)); + } else { + printf("no scratchpad buffers implemented\n"); + deviceContextArray->scratchpadBufferBase = 0; + } XHCIPortRegister *ports = OFFSET(operational, 0x400); for (uint32_t i = 0; i < 16; i++) { diff --git a/src/userland/usb/usb.h b/src/userland/usb/usb.h index 3dcea62..f7c6a3b 100644 --- a/src/userland/usb/usb.h +++ b/src/userland/usb/usb.h @@ -83,6 +83,11 @@ } DeviceContext; typedef struct { + uint64_t scratchpadBufferBase; + uint64_t deviceContextPointer[16]; +} DeviceContextArray; + +typedef struct { uint32_t statusControl, powerManagement, linkInfo, reserved; } XHCIPortRegister;