Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 lines
4.8 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. smbpoll.c
  5. Abstract:
  6. Device polling for
  7. SMB Host Controller Driver for ALI chipset
  8. Author:
  9. Michael Hills
  10. Environment:
  11. Notes:
  12. Revision History:
  13. --*/
  14. #include "smbalip.h"
  15. VOID
  16. SmbAliPollDpc (
  17. IN struct _KDPC *Dpc,
  18. IN struct _SMB_CLASS* SmbClass,
  19. IN PVOID SystemArgument1,
  20. IN PVOID SystemArgument2
  21. );
  22. VOID
  23. SmbAliPollWorker (
  24. IN PDEVICE_OBJECT DeviceObject,
  25. IN struct _SMB_CLASS* SmbClass
  26. );
  27. //LARGE_INTEGER SmbAlertPollRate = {-1*SECONDS, -1}; // 1 second poll rate
  28. LARGE_INTEGER SmbDevicePollRate = {-5*SECONDS, -1}; // 5 second poll rate
  29. LONG SmbDevicePollPeriod = 5000; // 5000 ms = 5 sec
  30. // address, command, protocol, valid_data, last_data
  31. SMB_ALI_POLL_ENTRY SmbDevicePollList [2] = {
  32. {0x0b, 0x16, SMB_READ_WORD, FALSE, 0}, // battery, BatteryStatus()
  33. {0x09, 0x13, SMB_READ_WORD, FALSE, 0} // charger, ChargerStatus()
  34. };
  35. VOID
  36. SmbAliStartDevicePolling (
  37. IN struct _SMB_CLASS* SmbClass
  38. )
  39. {
  40. PSMB_ALI_DATA AliData = (PSMB_ALI_DATA)(SmbClass->Miniport);
  41. AliData->PollList = SmbDevicePollList;
  42. AliData->PollListCount = sizeof (SmbDevicePollList)/sizeof(SMB_ALI_POLL_ENTRY);
  43. AliData->PollWorker = IoAllocateWorkItem (SmbClass->DeviceObject);
  44. KeInitializeTimer (&AliData->PollTimer);
  45. KeInitializeDpc (&AliData->PollDpc,
  46. SmbAliPollDpc,
  47. SmbClass);
  48. KeInitializeEvent (&AliData->PollWorkerActive, NotificationEvent, TRUE);
  49. KeSetTimerEx (&AliData->PollTimer,
  50. SmbDevicePollRate,
  51. SmbDevicePollPeriod,
  52. &AliData->PollDpc);
  53. }
  54. VOID
  55. SmbAliStopDevicePolling (
  56. IN struct _SMB_CLASS* SmbClass
  57. )
  58. {
  59. PSMB_ALI_DATA AliData = (PSMB_ALI_DATA)(SmbClass->Miniport);
  60. KeCancelTimer (&AliData->PollTimer);
  61. if (KeResetEvent(&AliData->PollWorkerActive) == 0) {
  62. KeWaitForSingleObject (&AliData->PollWorkerActive,
  63. Executive, KernelMode, FALSE, NULL);
  64. }
  65. }
  66. VOID
  67. SmbAliPollDpc (
  68. IN struct _KDPC *Dpc,
  69. IN struct _SMB_CLASS* SmbClass,
  70. IN PVOID SystemArgument1,
  71. IN PVOID SystemArgument2
  72. )
  73. {
  74. PSMB_ALI_DATA AliData = (PSMB_ALI_DATA)(SmbClass->Miniport);
  75. if (KeResetEvent(&AliData->PollWorkerActive) != 0) {
  76. IoQueueWorkItem (AliData->PollWorker, SmbAliPollWorker, DelayedWorkQueue, SmbClass);
  77. }
  78. }
  79. VOID
  80. SmbAliPollWorker (
  81. IN PDEVICE_OBJECT DeviceObject,
  82. IN struct _SMB_CLASS* SmbClass
  83. )
  84. {
  85. PSMB_ALI_DATA AliData = (PSMB_ALI_DATA)(SmbClass->Miniport);
  86. PIRP irp;
  87. SMB_REQUEST smbRequest;
  88. IO_STATUS_BLOCK ioStatus;
  89. KEVENT event;
  90. ULONG i;
  91. KeInitializeEvent (&event, SynchronizationEvent, FALSE);
  92. SmbPrint(SMB_TRACE, ("SmbAliPollWorker: Entered\n"));
  93. for (i = 0; i < AliData->PollListCount; i++) {
  94. smbRequest.Protocol = AliData->PollList[i].Protocol;
  95. smbRequest.Address = AliData->PollList[i].Address;
  96. smbRequest.Command = AliData->PollList[i].Command;
  97. irp = IoBuildDeviceIoControlRequest (
  98. SMB_BUS_REQUEST,
  99. SmbClass->DeviceObject,
  100. &smbRequest,
  101. sizeof (smbRequest),
  102. &smbRequest,
  103. sizeof (smbRequest),
  104. TRUE,
  105. &event,
  106. &ioStatus);
  107. if (!irp) {
  108. continue;
  109. }
  110. IoCallDriver (SmbClass->DeviceObject, irp);
  111. KeWaitForSingleObject (&event, Executive, KernelMode, FALSE, NULL);
  112. if (!NT_SUCCESS(ioStatus.Status)) {
  113. continue;
  114. }
  115. if (smbRequest.Status != SMB_STATUS_OK) {
  116. if (AliData->PollList[i].ValidData) {
  117. AliData->PollList[i].ValidData = FALSE;
  118. }
  119. } else {
  120. //BUGBUG: only supports word protocols
  121. if ((!AliData->PollList[i].ValidData) ||
  122. (AliData->PollList[i].LastData != *((PUSHORT)smbRequest.Data))) {
  123. AliData->PollList[i].ValidData = TRUE;
  124. AliData->PollList[i].LastData = *((PUSHORT)smbRequest.Data);
  125. SmbPrint(SMB_TRACE, ("SmbAliPollWorker: Alarm: Address 0x%02x Data 0x%04x\n", AliData->PollList[i].Address, AliData->PollList[i].LastData));
  126. SmbClassLockDevice (SmbClass);
  127. SmbClassAlarm (SmbClass,
  128. AliData->PollList[i].Address,
  129. AliData->PollList[i].LastData);
  130. SmbClassUnlockDevice (SmbClass);
  131. }
  132. SmbPrint(SMB_TRACE, ("SmbAliPollWorker: AlarmData: Address 0x%02x Data 0x%04x\n", AliData->PollList[i].Address, AliData->PollList[i].LastData));
  133. }
  134. }
  135. KeSetEvent (&AliData->PollWorkerActive, 0, FALSE);
  136. }