ReactOS  0.4.13-dev-651-g5dbc677
hardware.cpp File Reference
#include "usbehci.h"
#include <debug.h>
Include dependency graph for hardware.cpp:

Go to the source code of this file.

Classes

class  CUSBHardwareDevice
 

Macros

#define NDEBUG
 

Typedefs

typedef VOID __stdcall HD_INIT_CALLBACK(IN PVOID CallBackContext)
 

Functions

BOOLEAN NTAPI InterruptServiceRoutine (IN PKINTERRUPT Interrupt, IN PVOID ServiceContext)
 
VOID NTAPI EhciDeferredRoutine (IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
 
VOID NTAPI StatusChangeWorkItemRoutine (PVOID Context)
 
NTSTATUS NTAPI CreateUSBHardware (PUSBHARDWAREDEVICE *OutHardware)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file hardware.cpp.

Typedef Documentation

◆ HD_INIT_CALLBACK

typedef VOID __stdcall HD_INIT_CALLBACK(IN PVOID CallBackContext)

Definition at line 16 of file hardware.cpp.

Function Documentation

◆ CreateUSBHardware()

NTSTATUS NTAPI CreateUSBHardware ( PUSBHARDWAREDEVICE OutHardware)

Definition at line 1474 of file hardware.cpp.

1476 {
1478 
1480 
1481  if (!This)
1483 
1484  This->AddRef();
1485 
1486  // return result
1487  *OutHardware = (PUSBHARDWAREDEVICE)This;
1488 
1489  return STATUS_SUCCESS;
1490 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
IUSBHardwareDevice * PUSBHARDWAREDEVICE
#define TAG_USBEHCI
Definition: usbehci.h:12
return STATUS_SUCCESS
Definition: btrfs.c:2777

Referenced by CHCDController::Initialize().

◆ EhciDeferredRoutine()

VOID NTAPI EhciDeferredRoutine ( IN PKDPC  Dpc,
IN PVOID  DeferredContext,
IN PVOID  SystemArgument1,
IN PVOID  SystemArgument2 
)

Definition at line 1290 of file hardware.cpp.

1295 {
1297  ULONG CStatus, PortStatus, PortCount, i, ShouldRingDoorBell, QueueSCEWorkItem;
1299  EHCI_USBCMD_CONTENT UsbCmd;
1300 
1302  CStatus = PtrToUlong(SystemArgument2);
1303 
1304  DPRINT("EhciDeferredRoutine CStatus %lx\n", CStatus);
1305 
1306  //
1307  // check for completion of async schedule
1308  //
1309  if (CStatus & (EHCI_STS_RECL| EHCI_STS_INT | EHCI_ERROR_INT))
1310  {
1311  //
1312  // check if there is a door bell ring in progress
1313  //
1314  if (This->m_DoorBellRingInProgress == FALSE)
1315  {
1316  if (CStatus & EHCI_ERROR_INT)
1317  {
1318  //
1319  // controller reported error
1320  //
1321  DPRINT1("CStatus %lx\n", CStatus);
1322  //ASSERT(FALSE);
1323  }
1324 
1325  //
1326  // inform IUSBQueue of a completed queue head
1327  //
1328  This->m_UsbQueue->InterruptCallback(Status, &ShouldRingDoorBell);
1329 
1330  //
1331  // was a queue head completed?
1332  //
1333  if (ShouldRingDoorBell)
1334  {
1335  //
1336  // set door ring bell in progress status flag
1337  //
1338  This->m_DoorBellRingInProgress = TRUE;
1339 
1340  //
1341  // get command register
1342  //
1343  This->GetCommandRegister(&UsbCmd);
1344 
1345  //
1346  // set door rang bell bit
1347  //
1348  UsbCmd.DoorBell = TRUE;
1349 
1350  //
1351  // update command status
1352  //
1353  This->SetCommandRegister(&UsbCmd);
1354  }
1355  }
1356  }
1357 
1358  //
1359  // check if the controller has acknowledged the door bell
1360  //
1361  if (CStatus & EHCI_STS_IAA)
1362  {
1363  //
1364  // controller has acknowledged, assert we rang the bell
1365  //
1366  PC_ASSERT(This->m_DoorBellRingInProgress == TRUE);
1367 
1368  //
1369  // now notify IUSBQueue that it can free completed requests
1370  //
1371  This->m_UsbQueue->CompleteAsyncRequests();
1372 
1373  //
1374  // door ring bell completed
1375  //
1376  This->m_DoorBellRingInProgress = FALSE;
1377  }
1378 
1379  This->GetDeviceDetails(NULL, NULL, &PortCount, NULL);
1380  if (CStatus & EHCI_STS_PCD)
1381  {
1382  QueueSCEWorkItem = FALSE;
1383  for (i = 0; i < PortCount; i++)
1384  {
1385  PortStatus = This->EHCI_READ_REGISTER_ULONG(EHCI_PORTSC + (4 * i));
1386 
1387  //
1388  // Device connected or removed
1389  //
1391  {
1393  {
1394  DPRINT1("Device connected on port %lu\n", i);
1395 
1396  if (This->m_Capabilities.HCSParams.CHCCount)
1397  {
1399  {
1400  DPRINT1("Misbehaving controller. Port should be disabled at this point\n");
1401  }
1402 
1404  {
1405  DPRINT1("Low speed device connected. Releasing ownership\n");
1406  This->EHCI_WRITE_REGISTER_ULONG(EHCI_PORTSC + (4 * i), PortStatus | EHCI_PRT_RELEASEOWNERSHIP);
1407  continue;
1408  }
1409  }
1410 
1411  //
1412  // work to do
1413  //
1414  QueueSCEWorkItem = TRUE;
1415  }
1416  else
1417  {
1418  DPRINT1("Device disconnected on port %lu\n", i);
1419 
1420  //
1421  // work to do
1422  //
1423  QueueSCEWorkItem = TRUE;
1424  }
1425  }
1426  }
1427 
1428  //
1429  // is there a status change callback and a high speed device connected / disconnected
1430  //
1431  if (QueueSCEWorkItem && This->m_SCECallBack != NULL)
1432  {
1433  if (InterlockedCompareExchange(&This->m_StatusChangeWorkItemStatus, 1, 0) == 0)
1434  {
1435  //
1436  // queue work item for processing
1437  //
1438  ExQueueWorkItem(&This->m_StatusChangeWorkItem, DelayedWorkQueue);
1439  }
1440  }
1441  }
1442  return;
1443 }
#define EHCI_PORTSC
Definition: hardware.h:35
#define EHCI_PRT_ENABLED
Definition: hardware.h:69
#define TRUE
Definition: types.h:120
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:717
#define PC_ASSERT(exp)
Definition: usbehci.h:17
LONG NTSTATUS
Definition: precomp.h:26
#define EHCI_PRT_RELEASEOWNERSHIP
Definition: hardware.h:79
#define InterlockedCompareExchange
Definition: interlocked.h:104
#define EHCI_STS_PCD
Definition: hardware.h:53
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
#define EHCI_STS_INT
Definition: hardware.h:51
void DPRINT(...)
Definition: polytest.cpp:61
#define EHCI_ERROR_INT
Definition: hardware.h:62
#define PtrToUlong(u)
Definition: config.h:107
#define EHCI_PRT_CONNECTSTATUSCHANGE
Definition: hardware.h:68
_In_opt_ PVOID _In_opt_ PVOID SystemArgument1
Definition: ketypes.h:675
#define EHCI_IS_LOW_SPEED(x)
Definition: hardware.h:83
_Outptr_ PUSB_DEVICE_HANDLE _In_ PUSB_DEVICE_HANDLE _In_ USHORT PortStatus
Definition: hubbusif.h:40
Status
Definition: gdiplustypes.h:24
_In_opt_ PVOID _In_opt_ PVOID _In_opt_ PVOID SystemArgument2
Definition: ketypes.h:675
#define DPRINT1
Definition: precomp.h:8
#define EHCI_PRT_CONNECTED
Definition: hardware.h:67
unsigned int ULONG
Definition: retypes.h:1
#define EHCI_STS_RECL
Definition: hardware.h:59
return STATUS_SUCCESS
Definition: btrfs.c:2777
#define EHCI_STS_IAA
Definition: hardware.h:56

◆ InterruptServiceRoutine()

BOOLEAN NTAPI InterruptServiceRoutine ( IN PKINTERRUPT  Interrupt,
IN PVOID  ServiceContext 
)

Definition at line 1242 of file hardware.cpp.

1245 {
1247  ULONG CStatus;
1248 
1250  CStatus = This->EHCI_READ_REGISTER_ULONG(EHCI_USBSTS);
1251 
1253  DPRINT("InterruptServiceRoutine CStatus %lx\n", CStatus);
1254 
1255  //
1256  // Check that it belongs to EHCI
1257  //
1258  if (!CStatus)
1259  return FALSE;
1260 
1261  //
1262  // Clear the Status
1263  //
1264  This->EHCI_WRITE_REGISTER_ULONG(EHCI_USBSTS, CStatus);
1265 
1266  if (CStatus & EHCI_STS_FATAL)
1267  {
1268  This->StopController();
1269  DPRINT1("EHCI: Host System Error!\n");
1270  return TRUE;
1271  }
1272 
1273  if (CStatus & EHCI_ERROR_INT)
1274  {
1275  DPRINT1("EHCI Status = 0x%x\n", CStatus);
1276  }
1277 
1278  if (CStatus & EHCI_STS_HALT)
1279  {
1280  DPRINT1("Host Error Unexpected Halt\n");
1281  // FIXME: Reset controller\n");
1282  return TRUE;
1283  }
1284 
1285  KeInsertQueueDpc(&This->m_IntDpcObject, This, UlongToPtr(CStatus));
1286  return TRUE;
1287 }
#define TRUE
Definition: types.h:120
BOOLEAN NTAPI KeInsertQueueDpc(IN PKDPC Dpc, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: dpc.c:724
#define EHCI_STS_PCD
Definition: hardware.h:53
#define EHCI_STS_FLR
Definition: hardware.h:54
#define EHCI_STS_INT
Definition: hardware.h:51
void DPRINT(...)
Definition: polytest.cpp:61
#define EHCI_ERROR_INT
Definition: hardware.h:62
#define UlongToPtr(u)
Definition: config.h:106
#define EHCI_STS_HALT
Definition: hardware.h:58
_In_ PKSERVICE_ROUTINE _In_opt_ PVOID ServiceContext
Definition: iofuncs.h:798
#define DPRINT1
Definition: precomp.h:8
#define EHCI_USBSTS
Definition: hardware.h:28
unsigned int ULONG
Definition: retypes.h:1
#define EHCI_STS_FATAL
Definition: hardware.h:55
#define EHCI_STS_IAA
Definition: hardware.h:56

◆ StatusChangeWorkItemRoutine()

VOID NTAPI StatusChangeWorkItemRoutine ( PVOID  Context)

Definition at line 1447 of file hardware.cpp.

1449 {
1450  //
1451  // cast to hardware object
1452  //
1454 
1455  //
1456  // is there a callback
1457  //
1458  if (This->m_SCECallBack)
1459  {
1460  //
1461  // issue callback
1462  //
1463  This->m_SCECallBack(This->m_SCEContext);
1464  }
1465 
1466  //
1467  // reset active status
1468  //
1469  InterlockedDecrement(&This->m_StatusChangeWorkItemStatus);
1470 }
#define InterlockedDecrement
Definition: armddk.h:52

Referenced by TimerDpcRoutine().