Author: rgampa
Date: Tue Aug 1 07:10:06 2017
New Revision: 75466
URL:
http://svn.reactos.org/svn/reactos?rev=75466&view=rev
Log:
[USBXHCI]
- scratchpad buffer allocation.
- scratchpad buffer array allocation.
- need to free the buffer memory in the stop controller function.
CORE-13344
Modified:
branches/GSoC_2017/usbxhci/reactos/drivers/usb/usbxhci/CMakeLists.txt
branches/GSoC_2017/usbxhci/reactos/drivers/usb/usbxhci/hardware.h
branches/GSoC_2017/usbxhci/reactos/drivers/usb/usbxhci/roothub.c
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/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2017/usbxhci/reactos/drive…
==============================================================================
--- branches/GSoC_2017/usbxhci/reactos/drivers/usb/usbxhci/CMakeLists.txt [iso-8859-1]
(original)
+++ branches/GSoC_2017/usbxhci/reactos/drivers/usb/usbxhci/CMakeLists.txt [iso-8859-1] Tue
Aug 1 07:10:06 2017
@@ -12,5 +12,6 @@
set_module_type(usbxhci kernelmodedriver)
add_importlibs(usbxhci usbport ntoskrnl hal usbd)
+add_target_compile_definitions(usbxhci NTDDI_VERSION=NTDDI_WS03SP1)
add_pch(usbxhci usbxhci.h SOURCE)
add_cd_file(TARGET usbxhci DESTINATION reactos/system32/drivers NO_CAB FOR all)
Modified: branches/GSoC_2017/usbxhci/reactos/drivers/usb/usbxhci/hardware.h
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2017/usbxhci/reactos/drive…
==============================================================================
--- branches/GSoC_2017/usbxhci/reactos/drivers/usb/usbxhci/hardware.h [iso-8859-1]
(original)
+++ branches/GSoC_2017/usbxhci/reactos/drivers/usb/usbxhci/hardware.h [iso-8859-1] Tue Aug
1 07:10:06 2017
@@ -10,6 +10,7 @@
// operational register offsets
#define XHCI_USBCMD 0
#define XHCI_USBSTS 1
+#define XHCI_PGSZ 2
#define XHCI_DNCTRL 5
#define XHCI_CRCR 6
#define XHCI_DCBAAP 12
Modified: branches/GSoC_2017/usbxhci/reactos/drivers/usb/usbxhci/roothub.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2017/usbxhci/reactos/drive…
==============================================================================
--- branches/GSoC_2017/usbxhci/reactos/drivers/usb/usbxhci/roothub.c [iso-8859-1]
(original)
+++ branches/GSoC_2017/usbxhci/reactos/drivers/usb/usbxhci/roothub.c [iso-8859-1] Tue Aug
1 07:10:06 2017
@@ -138,7 +138,9 @@
portstatus.UsbPortStatusChange.HsDeviceAttachedChange =
PortStatusRegister.ConnectStatusChange;
portstatus.UsbPortStatusChange.TestModeChange =
0;//PortStatusRegister.ConnectStatusChange;
portstatus.UsbPortStatusChange.IndicatorControlChange =0;//
PortStatusRegister.ConnectStatusChange;
-
+
+ DPRINT("XHCI_RH_GetPortStatus: PortStatus - %p\n",
portstatus.AsULONG);
+ DPRINT("XHCI_RH_GetPortStatus: Port - %i\n", Port);
*PortStatus = portstatus.AsULONG;
return MP_STATUS_SUCCESS;
Modified: branches/GSoC_2017/usbxhci/reactos/drivers/usb/usbxhci/usbxhci.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2017/usbxhci/reactos/drive…
==============================================================================
--- 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] Tue Aug
1 07:10:06 2017
@@ -163,7 +163,8 @@
PHYSICAL_ADDRESS HcResourcesPA;
PULONG BaseIoAdress;
PULONG OperationalRegs;
-
+ USHORT PageSize;
+ USHORT MaxScratchPadBuffers;
PULONG RunTimeRegisterBase;
XHCI_INTERRUPTER_MANAGEMENT Iman;
@@ -238,7 +239,51 @@
HcResourcesVA->EventRing.firstSeg.XhciTrb[i].EventTRB.Word2=0;
HcResourcesVA->EventRing.firstSeg.XhciTrb[i].EventTRB.Word3=0;
}
-
+ /*PHYSICAL_ADDRESS Zero, Max;
+ Zero.QuadPart = 0;
+ Max.QuadPart = -1;
+ PMDL Mdl = MmAllocatePagesForMdlEx(Zero, Max, Zero, NumScratchPages * PAGE_SIZE,
MmNonCached, 0);
+ if (Mdl == NULL) { fail }
+ if (MmGetMdlByteCount(Mdl) < NumScratchPages * PAGE_SIZE) {
MmFreePagesFromMdl(Mdl); fail }
+ Allocate scratchpad buffers.
+ */
+ // check if the controller supports 4k page size or quit.
+ PageSize = XhciExtension-> PageSize;
+ if (PageSize & (1 << 0) == 0){
+ DPRINT1("XHCI_InitializeResources : fail. does not support 4k page size
%p\n",PageSize);
+ return MP_STATUS_FAILURE;
+ }
+ // 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;
+ //allocate scratchpad buffers
+ 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;
+ if (ScrathcPadBuffer == NULL) {
+ return MP_STATUS_FAILURE;
+ }
+ if (MmGetMdlByteCount(ScrathcPadBuffer) < PAGE_SIZE) {
+ MmFreePagesFromMdl(ScrathcPadBuffer);
+ return MP_STATUS_FAILURE;
+ }
+ }
+ XhciExtension-> ScratchPadArray = ScratchPadArray;
//DbgBreakPoint();
return MP_STATUS_SUCCESS;
}
@@ -328,9 +373,10 @@
XHCI_RT_REGISTER_SPACE_OFFSET RTSOffsetRegister;
UCHAR CapabilityRegLength;
UCHAR Fladj;
-
-
-
+ XHCI_PAGE_SIZE PageSizeReg;
+ USHORT MaxScratchPadBuffers;
+ XHCI_HC_STRUCTURAL_PARAMS_2 HCSPARAMS2;
+
if ((Resources->TypesResources & (USBPORT_RESOURCES_MEMORY |
USBPORT_RESOURCES_INTERRUPT)) !=
(USBPORT_RESOURCES_MEMORY |
USBPORT_RESOURCES_INTERRUPT))
{
@@ -360,10 +406,20 @@
RunTimeRegisterBase = (PULONG)((PBYTE)BaseIoAdress + RTSOffsetRegister.AsULONG );
XhciExtension->RunTimeRegisterBase = RunTimeRegisterBase ;
+ PageSizeReg.AsULONG = READ_REGISTER_ULONG(OperationalRegs + XHCI_PGSZ);
+ XhciExtension->PageSize = PageSizeReg.PageSize;
+ HCSPARAMS2.AsULONG = READ_REGISTER_ULONG(BaseIoAdress + XHCI_HCSP2);
+ MaxScratchPadBuffers = 0;
+ MaxScratchPadBuffers = HCSPARAMS2.MaxSPBuffersHi;
+ MaxScratchPadBuffers= MaxScratchPadBuffers<<5;
+ MaxScratchPadBuffers = MaxScratchPadBuffers + HCSPARAMS2.MaxSPBuffersLo;
+ XhciExtension->MaxScratchPadBuffers = MaxScratchPadBuffers;
+
DPRINT("XHCI_StartController: BaseIoAdress - %p\n", BaseIoAdress);
DPRINT("XHCI_StartController: OperationalRegs - %p\n", OperationalRegs);
DPRINT("XHCI_StartController: DoorBellRegisterBase - %p\n",
DoorBellRegisterBase);
DPRINT("XHCI_StartController: RunTimeRegisterBase - %p\n",
RunTimeRegisterBase);
+ DPRINT("XHCI_StartController: PageSize - %p\n",
XhciExtension->PageSize);
RegPacket.UsbPortReadWriteConfigSpace(XhciExtension,
1,
@@ -408,6 +464,13 @@
IN BOOLEAN IsDoDisableInterrupts)
{
DPRINT1("XHCI_StopController: UNIMPLEMENTED. FIXME\n");
+ PXHCI_EXTENSION XhciExtension;
+ XhciExtension = (PXHCI_EXTENSION) xhciExtension;
+ PMDL ScratchPadArray;
+ // free memory allocated to scratchpad buffers.
+ ScratchPadArray = XhciExtension-> ScratchPadArray;
+ //ExFreePool(Mdl) after MmFreePagesFromMdl to free the scratchpad buffer ARRAY
+ MmFreePagesFromMdl(ScratchPadArray);
}
VOID
@@ -466,8 +529,11 @@
WRITE_REGISTER_ULONG(RunTimeRegisterBase + XHCI_IMAN, Iman.AsULONG);
DPRINT1("XHCI_InterruptService: Succesful Interupt\n");
// changing the enque pointer
- erstdp.AsULONGLONG = READ_REGISTER_ULONG(RunTimeRegisterBase + XHCI_ERSTDP +
1)|READ_REGISTER_ULONG(RunTimeRegisterBase + XHCI_ERSTDP);
- erstdp.AsULONGLONG = erstdp.AsULONGLONG +2;
+ erstdp.AsULONGLONG = READ_REGISTER_ULONG(RunTimeRegisterBase + XHCI_ERSTDP + 1);
+ erstdp.AsULONGLONG = erstdp.AsULONGLONG <<32;
+ erstdp.AsULONGLONG = erstdp.AsULONGLONG + READ_REGISTER_ULONG(RunTimeRegisterBase +
XHCI_ERSTDP);
+
+ erstdp.EventRingSegDequeuePointer = erstdp.EventRingSegDequeuePointer +1;
erstdp.DequeueERSTIndex =0;
XHCI_Write64bitReg (RunTimeRegisterBase + XHCI_ERSTDP, erstdp.AsULONGLONG);
Modified: branches/GSoC_2017/usbxhci/reactos/drivers/usb/usbxhci/usbxhci.h
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2017/usbxhci/reactos/drive…
==============================================================================
--- 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] Tue Aug
1 07:10:06 2017
@@ -7,12 +7,14 @@
#include <hubbusif.h>
#include <usbbusif.h>
#include <usbdlib.h>
+//#include <xdk/mmfuncs.h>
#include "..\usbmport.h"
#include "hardware.h"
extern USBPORT_REGISTRATION_PACKET RegPacket;
#define XHCI_FLAGS_CONTROLLER_SUSPEND 0x01
+
//Data structures
typedef struct _XHCI_DEVICE_CONTEXT_BASE_ADD_ARRAY {
PHYSICAL_ADDRESS ContextBaseAddr [256];
@@ -200,7 +202,7 @@
PXHCI_SEGMENT enqueue_segment;
PXHCI_SEGMENT dequeue_segment;
ULONGLONG Padding;
-} XHCI_RING , *PXHCI_RING;
+} XHCI_RING, *PXHCI_RING;
typedef struct _XHCI_EXTENSION {
ULONG Reserved;
@@ -215,14 +217,17 @@
ULONG PortRoutingControl;
USHORT NumberOfPorts; // HCSPARAMS1 => N_PORTS
USHORT PortPowerControl; // HCSPARAMS => Port Power Control (PPC)
+ USHORT PageSize;
+ USHORT MaxScratchPadBuffers;
+ PMDL ScratchPadArray;
} XHCI_EXTENSION, *PXHCI_EXTENSION;
typedef struct _XHCI_HC_RESOURCES {
XHCI_DEVICE_CONTEXT_BASE_ADD_ARRAY DCBAA;
//XHCI_COMMAND_RING CommandRing;
- XHCI_RING EventRing ;
- XHCI_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;
@@ -234,6 +239,13 @@
ULONG Reserved;
} XHCI_TRANSFER, *PXHCI_TRANSFER;
+typedef union _XHCI_SCRATCHPAD_BUFFER_ARRAY{
+ struct {
+ ULONGLONG RsvdZ1 : 12;
+ ULONGLONG bufferBaseAddr : 52;
+ };
+ ULONGLONG AsULONGLONG;
+} XHCI_SCRATCHPAD_BUFFER_ARRAY, *PXHCI_SCRATCHPAD_BUFFER_ARRAY;
//roothub functions
VOID
NTAPI