Author: apriyadarshi
Date: Thu Jun 16 21:14:03 2016
New Revision: 71650
URL:
http://svn.reactos.org/svn/reactos?rev=71650&view=rev
Log:
fixed portCount boundary problem :D
Modified:
branches/GSoC_2016/AHCI/drivers/storage/storahci/storahci.c
branches/GSoC_2016/AHCI/drivers/storage/storahci/storahci.h
Modified: branches/GSoC_2016/AHCI/drivers/storage/storahci/storahci.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2016/AHCI/drivers/storage/…
==============================================================================
--- branches/GSoC_2016/AHCI/drivers/storage/storahci/storahci.c [iso-8859-1] (original)
+++ branches/GSoC_2016/AHCI/drivers/storage/storahci/storahci.c [iso-8859-1] Thu Jun 16
21:14:03 2016
@@ -35,7 +35,7 @@
portNumber = PortExtension->PortNumber;
NT_ASSERT(abar != NULL);
- NT_ASSERT(portNumber < MAXIMUM_AHCI_PORT_COUNT);
+ NT_ASSERT(portNumber < adapterExtension->PortCount);
PortExtension->Port = &abar->PortList[portNumber];
@@ -120,18 +120,15 @@
portCount = 0;
portImplemented = AdapterExtension->PortImplemented;
- // make sure we don't allocate too much memory for the ports we have not
implemented
- // LOGIC: AND with all MAXIMUM_AHCI_PORT_COUNT (low significant) bits set
- portImplemented = portImplemented & ((1 << MAXIMUM_AHCI_PORT_COUNT) - 1);
- while (portImplemented > 0)
- {
- portCount++;
- portImplemented &= (portImplemented - 1);
- }
-
- NT_ASSERT(portCount <= MAXIMUM_AHCI_PORT_COUNT);
+ NT_ASSERT(portImplemented != 0);
+ for (index = MAXIMUM_AHCI_PORT_COUNT - 1; index > 0; index--)
+ if ((portImplemented & (1 << index)) != 0)
+ break;
+
+ portCount = index + 1;
DebugPrint("\tPort Count: %d\n", portCount);
+ AdapterExtension->PortCount = portCount;
nonCachedExtensionSize = sizeof(AHCI_COMMAND_HEADER) * AlignedNCS + //should be 1K
aligned
sizeof(AHCI_RECEIVED_FIS);
@@ -151,7 +148,7 @@
nonCachedExtension = AdapterExtension->NonCachedExtension;
AhciZeroMemory(nonCachedExtension, nonCachedExtensionSize * portCount);
- for (index = 0; index < MAXIMUM_AHCI_PORT_COUNT; index++)
+ for (index = 0; index < portCount; index++)
{
AdapterExtension->PortExtension[index].IsActive = FALSE;
if ((AdapterExtension->PortImplemented & (1 << index)) != 0)
@@ -298,7 +295,7 @@
*
* The Storport driver calls the HwStorInterrupt routine after the HBA generates an
interrupt request.
*
- * @param adapterExtension
+ * @param AdapterExtension
*
* @return
* return TRUE Indicates that an interrupt was pending on adapter.
@@ -306,48 +303,46 @@
*/
BOOLEAN
AhciHwInterrupt(
- __in PVOID AdapterExtension
- )
-{
- ULONG portPending, nextPort, i;
- PAHCI_ADAPTER_EXTENSION adapterExtension;
+ __in PAHCI_ADAPTER_EXTENSION AdapterExtension
+ )
+{
+ ULONG portPending, nextPort, i, portCount;
DebugPrint("AhciHwInterrupt()\n");
- adapterExtension = AdapterExtension;
-
- if (adapterExtension->StateFlags.Removed)
+ if (AdapterExtension->StateFlags.Removed)
{
return FALSE;
}
- portPending = StorPortReadRegisterUlong(adapterExtension, adapterExtension->IS);
+ portPending = StorPortReadRegisterUlong(AdapterExtension, AdapterExtension->IS);
// we process interrupt for implemented ports only
- portPending = portPending & adapterExtension->PortImplemented;
+ portCount = AdapterExtension->PortCount;
+ portPending = portPending & AdapterExtension->PortImplemented;
if (portPending == 0)
{
return FALSE;
}
- for (i = 1; i <= MAXIMUM_AHCI_PORT_COUNT; i++)
- {
- nextPort = (adapterExtension->LastInterruptPort + i) %
MAXIMUM_AHCI_PORT_COUNT;
+ for (i = 1; i <= portCount; i++)
+ {
+ nextPort = (AdapterExtension->LastInterruptPort + i) % portCount;
if ((portPending & (0x1 << nextPort)) == 0)
continue;
NT_ASSERT(IsPortValid(AdapterExtension, nextPort));
- if ((nextPort == adapterExtension->LastInterruptPort) ||
- (adapterExtension->PortExtension[nextPort].IsActive == FALSE))
+ if ((nextPort == AdapterExtension->LastInterruptPort) ||
+ (AdapterExtension->PortExtension[nextPort].IsActive == FALSE))
{
return FALSE;
}
// we can assign this interrupt to this port
- adapterExtension->LastInterruptPort = nextPort;
- AhciInterruptHandler(&adapterExtension->PortExtension[nextPort]);
+ AdapterExtension->LastInterruptPort = nextPort;
+ AhciInterruptHandler(&AdapterExtension->PortExtension[nextPort]);
// interrupt belongs to this device
// should always return TRUE
@@ -448,19 +443,22 @@
if (cdb->CDB10.OperationCode == SCSIOP_INQUIRY)
{
Srb->SrbStatus = DeviceInquiryRequest(adapterExtension, Srb, cdb);
- StorPortNotification(RequestComplete, adapterExtension, Srb);
- return TRUE;
+ }
+ else
+ {
+ Srb->SrbStatus = SRB_STATUS_NO_DEVICE;
}
}
else
{
Srb->SrbStatus = SRB_STATUS_BAD_FUNCTION;
- StorPortNotification(RequestComplete, adapterExtension, Srb);
- return TRUE;
}
- }
-
- DebugPrint("\tUnknow function code recieved: %x\n", function);
+
+ StorPortNotification(RequestComplete, adapterExtension, Srb);
+ return TRUE;
+ }
+
+ DebugPrint("\tUnknown function code recieved: %x\n", function);
Srb->SrbStatus = SRB_STATUS_BAD_FUNCTION;
StorPortNotification(RequestComplete, adapterExtension, Srb);
return TRUE;
@@ -672,7 +670,7 @@
return SP_RETURN_ERROR;
}
- for (index = 0; index < MAXIMUM_AHCI_PORT_COUNT; index++)
+ for (index = 0; index < adapterExtension->PortCount; index++)
{
if ((adapterExtension->PortImplemented & (0x1<<index)) != 0)
AhciPortInitialize(&adapterExtension->PortExtension[index]);
@@ -812,7 +810,7 @@
PortExtension = &AdapterExtension->PortExtension[PathId];
- NT_ASSERT(PathId < MAXIMUM_AHCI_PORT_COUNT);
+ NT_ASSERT(PathId < AdapterExtension->PortCount);
// add Srb to queue
AddQueue(&PortExtension->SrbQueue, Srb);
@@ -1021,7 +1019,7 @@
{
NT_ASSERT(pathId >= 0);
- if (pathId >= MAXIMUM_AHCI_PORT_COUNT)
+ if (pathId >= AdapterExtension->PortCount)
{
return FALSE;
}
Modified: branches/GSoC_2016/AHCI/drivers/storage/storahci/storahci.h
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2016/AHCI/drivers/storage/…
==============================================================================
--- branches/GSoC_2016/AHCI/drivers/storage/storahci/storahci.h [iso-8859-1] (original)
+++ branches/GSoC_2016/AHCI/drivers/storage/storahci/storahci.h [iso-8859-1] Thu Jun 16
21:14:03 2016
@@ -10,7 +10,7 @@
#define DEBUG 1
-#define MAXIMUM_AHCI_PORT_COUNT 12
+#define MAXIMUM_AHCI_PORT_COUNT 25
#define MAXIMUM_QUEUE_BUFFER_SIZE 255
#define MAXIMUM_TRANSFER_LENGTH (128*1024) // 128 KB
@@ -20,6 +20,7 @@
#define AHCI_Global_HBA_CONTROL_MRSM (1 << 2)
#define AHCI_Global_HBA_CONTROL_AE (1 << 31)
#define AHCI_Global_HBA_CAP_S64A (1 << 31)
+#define AHCI_Global_Port_CMD_IDLE ((1 << 0) | (1 << 4) | (1
<< 14) | (1 << 15)) // PxCMD.ST, PxCMD.CR, PxCMD.FRE and PxCMD.FR
// 3.1.1 NCS = CAP[12:08] -> Align
#define AHCI_Global_Port_CAP_NCS(x) (((x) & 0xF00) >> 8)
@@ -254,6 +255,7 @@
ULONG AhciBaseAddress;
PULONG IS;// Interrupt Status, In case of MSIM == `1`
ULONG PortImplemented;// bit-mapping of ports which are implemented
+ ULONG PortCount;
USHORT VendorID;
USHORT DeviceID;