Author: rgampa Date: Wed Aug 2 16:17:54 2017 New Revision: 75470
URL: http://svn.reactos.org/svn/reactos?rev=75470&view=rev Log: [USBXHCI] - various changes to scratchpad buffer allocation. CORE-13344
Modified: branches/GSoC_2017/usbxhci/reactos/drivers/usb/usbxhci/usbxhci.c branches/GSoC_2017/usbxhci/reactos/drivers/usb/usbxhci/usbxhci.h
Modified: branches/GSoC_2017/usbxhci/reactos/drivers/usb/usbxhci/usbxhci.c URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2017/usbxhci/reactos/driver... ============================================================================== --- branches/GSoC_2017/usbxhci/reactos/drivers/usb/usbxhci/usbxhci.c [iso-8859-1] (original) +++ branches/GSoC_2017/usbxhci/reactos/drivers/usb/usbxhci/usbxhci.c [iso-8859-1] Wed Aug 2 16:17:54 2017 @@ -249,41 +249,60 @@ */ // check if the controller supports 4k page size or quit. PageSize = XhciExtension-> PageSize; - if (PageSize & (1 << 0) == 0){ + MaxScratchPadBuffers = XhciExtension->MaxScratchPadBuffers; + + if (MaxScratchPadBuffers == 0){ // xHCI may declare 0 scratchpad arrays. if so there is no need for memory allocation. + return MP_STATUS_SUCCESS; + } + //if (PageSize & (1 << 0) == 0){ // this is how it is implemented in Haiko + if (1 << (PageSize + 12) == PAGE_SIZE) { DPRINT1("XHCI_InitializeResources : fail. does not support 4k page size %p\n",PageSize); return MP_STATUS_FAILURE; } + DbgBreakPoint(); // allocate scratchpad buffer array PHYSICAL_ADDRESS Zero, Max; - MaxScratchPadBuffers = XhciExtension->MaxScratchPadBuffers; Zero.QuadPart = 0; Max.QuadPart = -1; - - PMDL ScratchPadArray; - //PXHCI_SCRATCHPAD_BUFFER_ARRAY BufferArrayPointer; - PHYSICAL_ADDRESS *temp; - ScratchPadArray = MmAllocatePagesForMdlEx(Zero, Max, Zero, MaxScratchPadBuffers*8 , MmNonCached, 0); - - temp = MmGetSystemAddressForMdlSafe(ScratchPadArray, 0); // PRiority?? - //BufferArrayPointer = (PXHCI_SCRATCHPAD_BUFFER_ARRAY) MmGetSystemAddressForMdlSafe(ScratchPadArray, 0); - HcResourcesVA-> DCBAA.ContextBaseAddr[0] = *temp; + PMDL ScratchPadArrayMDL; + PXHCI_SCRATCHPAD_BUFFER_ARRAY BufferArrayPointer; + //ScratchPadArrayMDL = MmAllocatePagesForMdlEx(Zero, Max, Zero, MaxScratchPadBuffers* sizeof(XHCI_SCRATCHPAD_BUFFER_ARRAY), MmNonCached, 0); + BufferArrayPointer = (PXHCI_SCRATCHPAD_BUFFER_ARRAY)MmAllocateContiguousMemory (MaxScratchPadBuffers* sizeof(XHCI_SCRATCHPAD_BUFFER_ARRAY),Max); + ScratchPadArrayMDL = IoAllocateMdl((PVOID) BufferArrayPointer, MaxScratchPadBuffers* sizeof(XHCI_SCRATCHPAD_BUFFER_ARRAY), FALSE, FALSE, NULL); + MmBuildMdlForNonPagedPool(ScratchPadArrayMDL); + + if (ScratchPadArrayMDL == NULL) { + DPRINT1("XHCI_InitializeResources : Scratch pad array could not be allocated. it is NULL\n"); + return MP_STATUS_FAILURE; + } + + if (MmGetMdlByteCount(ScratchPadArrayMDL) < MaxScratchPadBuffers* sizeof(XHCI_SCRATCHPAD_BUFFER_ARRAY)) { + DPRINT1("XHCI_InitializeResources : Scratch pad array could not be allocated. it is smaller than required\n"); + MmFreePagesFromMdl(ScratchPadArrayMDL); + ExFreePool(ScratchPadArrayMDL); + return MP_STATUS_FAILURE; + } + + //temp = MmGetSystemAddressForMdlSafe(ScratchPadArrayMDL, NormalPagePriority); // PRiority?? + //BufferArrayPointer = (PXHCI_SCRATCHPAD_BUFFER_ARRAY) MmGetSystemAddressForMdlSafe(ScratchPadArrayMDL, 0); + HcResourcesVA-> DCBAA.ContextBaseAddr[0] = MmGetPhysicalAddress((PVOID)BufferArrayPointer); //allocate scratchpad buffers + PVOID BufferAddr; PMDL ScrathcPadBuffer; - PHYSICAL_ADDRESS *ScratchArray; - ScratchArray = MmGetSystemAddressForMdlSafe(ScratchPadArray, 0); for (int i = 0; i < MaxScratchPadBuffers ; i++){ ScrathcPadBuffer = MmAllocatePagesForMdlEx(Zero, Max, Zero, PAGE_SIZE, MmNonCached, 0); - temp = MmGetSystemAddressForMdlSafe(ScrathcPadBuffer, 0); - ScratchArray[i] = *temp; + BufferAddr = MmGetSystemAddressForMdlSafe(ScrathcPadBuffer, NormalPagePriority); if (ScrathcPadBuffer == NULL) { return MP_STATUS_FAILURE; } if (MmGetMdlByteCount(ScrathcPadBuffer) < PAGE_SIZE) { MmFreePagesFromMdl(ScrathcPadBuffer); + ExFreePool(ScrathcPadBuffer); return MP_STATUS_FAILURE; } - } - XhciExtension-> ScratchPadArray = ScratchPadArray; + BufferArrayPointer[i].AsULONGLONG = MmGetPhysicalAddress(BufferAddr).QuadPart; + } + XhciExtension-> ScratchPadArray = ScratchPadArrayMDL; //DbgBreakPoint(); return MP_STATUS_SUCCESS; } @@ -420,6 +439,7 @@ DPRINT("XHCI_StartController: DoorBellRegisterBase - %p\n", DoorBellRegisterBase); DPRINT("XHCI_StartController: RunTimeRegisterBase - %p\n", RunTimeRegisterBase); DPRINT("XHCI_StartController: PageSize - %p\n", XhciExtension->PageSize); + DPRINT("XHCI_StartController: MaxScratchPadBuffers - %p\n", MaxScratchPadBuffers);
RegPacket.UsbPortReadWriteConfigSpace(XhciExtension, 1, @@ -465,12 +485,18 @@ { DPRINT1("XHCI_StopController: UNIMPLEMENTED. FIXME\n"); PXHCI_EXTENSION XhciExtension; + USHORT MaxScratchPadBuffers; + PMDL ScratchPadArray; XhciExtension = (PXHCI_EXTENSION) xhciExtension; - PMDL ScratchPadArray; + MaxScratchPadBuffers = XhciExtension->MaxScratchPadBuffers; // free memory allocated to scratchpad buffers. ScratchPadArray = XhciExtension-> ScratchPadArray; - //ExFreePool(Mdl) after MmFreePagesFromMdl to free the scratchpad buffer ARRAY - MmFreePagesFromMdl(ScratchPadArray); + if (MaxScratchPadBuffers != 0){ + //ExFreePool(Mdl) after MmFreePagesFromMdl to free the scratchpad buffer ARRAY + MmFreePagesFromMdl(ScratchPadArray); + ExFreePool(ScratchPadArray); + } + }
VOID
Modified: branches/GSoC_2017/usbxhci/reactos/drivers/usb/usbxhci/usbxhci.h URL: http://svn.reactos.org/svn/reactos/branches/GSoC_2017/usbxhci/reactos/driver... ============================================================================== --- branches/GSoC_2017/usbxhci/reactos/drivers/usb/usbxhci/usbxhci.h [iso-8859-1] (original) +++ branches/GSoC_2017/usbxhci/reactos/drivers/usb/usbxhci/usbxhci.h [iso-8859-1] Wed Aug 2 16:17:54 2017 @@ -7,7 +7,6 @@ #include <hubbusif.h> #include <usbbusif.h> #include <usbdlib.h> -//#include <xdk/mmfuncs.h> #include "..\usbmport.h" #include "hardware.h"
@@ -225,12 +224,11 @@
typedef struct _XHCI_HC_RESOURCES { XHCI_DEVICE_CONTEXT_BASE_ADD_ARRAY DCBAA; - //XHCI_COMMAND_RING CommandRing; DECLSPEC_ALIGN(16) XHCI_RING EventRing ; DECLSPEC_ALIGN(64) XHCI_RING CommandRing ; XHCI_EVENT_RING_SEGMENT_TABLE EventRingSegTable; } XHCI_HC_RESOURCES, *PXHCI_HC_RESOURCES; - +//C_ASSERT (FIELD_OFFSET(XHCI_HC_RESOURCES,EventRing)); typedef struct _XHCI_ENDPOINT { ULONG Reserved; } XHCI_ENDPOINT, *PXHCI_ENDPOINT; @@ -246,6 +244,7 @@ }; ULONGLONG AsULONGLONG; } XHCI_SCRATCHPAD_BUFFER_ARRAY, *PXHCI_SCRATCHPAD_BUFFER_ARRAY; +C_ASSERT(sizeof(XHCI_SCRATCHPAD_BUFFER_ARRAY) == 8); //roothub functions VOID NTAPI