Leaked source code of windows server 2003
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.

1585 lines
43 KiB

  1. /*--------------------------------------------------------------------------
  2. *
  3. * Copyright (C) Cyclades Corporation, 1996-2001.
  4. * All rights reserved.
  5. *
  6. * Cyclom-Y Port Driver
  7. *
  8. * This file: cyyutils.c
  9. *
  10. * Description: This module contains the code related to queueing
  11. * and completion manipulation on requests.
  12. *
  13. * Notes: This code supports Windows 2000 and Windows XP,
  14. * x86 and IA64 processors.
  15. *
  16. * Complies with Cyclades SW Coding Standard rev 1.3.
  17. *
  18. *--------------------------------------------------------------------------
  19. */
  20. /*-------------------------------------------------------------------------
  21. *
  22. * Change History
  23. *
  24. *--------------------------------------------------------------------------
  25. *
  26. *
  27. *--------------------------------------------------------------------------
  28. */
  29. #include "precomp.h"
  30. VOID
  31. CyyRundownIrpRefs(
  32. IN PIRP *CurrentOpIrp,
  33. IN PKTIMER IntervalTimer,
  34. IN PKTIMER TotalTimer,
  35. IN PCYY_DEVICE_EXTENSION PDevExt
  36. );
  37. #ifdef ALLOC_PRAGMA
  38. #pragma alloc_text(PAGESER,CyyGetNextIrp)
  39. #pragma alloc_text(PAGESER, CyyGetNextIrpLocked)
  40. #pragma alloc_text(PAGESER,CyyTryToCompleteCurrent)
  41. #pragma alloc_text(PAGESER,CyyStartOrQueue)
  42. #pragma alloc_text(PAGESER,CyyCancelQueued)
  43. #pragma alloc_text(PAGESER,CyyCompleteIfError)
  44. #pragma alloc_text(PAGESER,CyyRundownIrpRefs)
  45. //#pragma alloc_text(PAGESRP0, CyyLogError) //It can be called at raised IRQL
  46. #pragma alloc_text(PAGESRP0, CyyMarkHardwareBroken)
  47. #endif
  48. static const PHYSICAL_ADDRESS CyyPhysicalZero = {0};
  49. VOID
  50. CyyKillAllReadsOrWrites(
  51. IN PDEVICE_OBJECT DeviceObject,
  52. IN PLIST_ENTRY QueueToClean,
  53. IN PIRP *CurrentOpIrp
  54. )
  55. /*--------------------------------------------------------------------------
  56. CyyKillAllReadsOrWrites()
  57. Routine Description: This function is used to cancel all queued and
  58. the current irps for reads or for writes.
  59. Arguments:
  60. DeviceObject - A pointer to the serial device object.
  61. QueueToClean - A pointer to the queue which we're going to clean out.
  62. CurrentOpIrp - Pointer to a pointer to the current irp.
  63. Return Value: None.
  64. --------------------------------------------------------------------------*/
  65. {
  66. KIRQL cancelIrql;
  67. PDRIVER_CANCEL cancelRoutine;
  68. // Acquire cancel spin lock to prevent irps from moving around.
  69. IoAcquireCancelSpinLock(&cancelIrql);
  70. // Clean the list from back to front.
  71. while (!IsListEmpty(QueueToClean)) {
  72. PIRP currentLastIrp = CONTAINING_RECORD(QueueToClean->Blink,
  73. IRP,Tail.Overlay.ListEntry);
  74. RemoveEntryList(QueueToClean->Blink);
  75. cancelRoutine = currentLastIrp->CancelRoutine;
  76. currentLastIrp->CancelIrql = cancelIrql;
  77. currentLastIrp->CancelRoutine = NULL;
  78. currentLastIrp->Cancel = TRUE;
  79. cancelRoutine(DeviceObject,currentLastIrp);
  80. IoAcquireCancelSpinLock(&cancelIrql);
  81. }
  82. // The queue is clean. Now go after the current if it's there.
  83. if (*CurrentOpIrp) {
  84. cancelRoutine = (*CurrentOpIrp)->CancelRoutine;
  85. (*CurrentOpIrp)->Cancel = TRUE;
  86. // If the current irp is not in a cancelable state
  87. // then it *will* try to enter one and the above
  88. // assignment will kill it. If it already is in
  89. // a cancelable state then the following will kill it.
  90. if (cancelRoutine) {
  91. (*CurrentOpIrp)->CancelRoutine = NULL;
  92. (*CurrentOpIrp)->CancelIrql = cancelIrql;
  93. // mark it as canceled and call the cancel routine for it
  94. cancelRoutine(DeviceObject,*CurrentOpIrp);
  95. } else {
  96. IoReleaseCancelSpinLock(cancelIrql);
  97. }
  98. } else {
  99. IoReleaseCancelSpinLock(cancelIrql);
  100. }
  101. }
  102. VOID
  103. CyyGetNextIrp(
  104. IN PIRP *CurrentOpIrp,
  105. IN PLIST_ENTRY QueueToProcess,
  106. OUT PIRP *NextIrp,
  107. IN BOOLEAN CompleteCurrent,
  108. IN PCYY_DEVICE_EXTENSION extension
  109. )
  110. /*--------------------------------------------------------------------------
  111. CyyGetNextIrp()
  112. Routine Description: This function is used to make the head of the
  113. particular queue the current irp. It also completes the what
  114. was the old current irp if desired.
  115. Arguments:
  116. CurrentOpIrp - Pointer to a pointer to the currently active
  117. irp for the particular work list. Note that
  118. this item is not actually part of the list.
  119. QueueToProcess - The list to pull the new item off of.
  120. NextIrp - The next Irp to process. Note that CurrentOpIrp
  121. will be set to this value under protection of the
  122. cancel spin lock. However, if *NextIrp is NULL when
  123. this routine returns, it is not necessaryly true the
  124. what is pointed to by CurrentOpIrp will also be NULL.
  125. The reason for this is that if the queue is empty
  126. when we hold the cancel spin lock, a new irp may come
  127. in immediately after we release the lock.
  128. CompleteCurrent - If TRUE then this routine will complete the
  129. irp pointed to by the pointer argument
  130. CurrentOpIrp.
  131. Return Value: None.
  132. --------------------------------------------------------------------------*/
  133. {
  134. KIRQL oldIrql;
  135. CYY_LOCKED_PAGED_CODE();
  136. IoAcquireCancelSpinLock(&oldIrql);
  137. CyyGetNextIrpLocked(CurrentOpIrp, QueueToProcess, NextIrp,
  138. CompleteCurrent, extension, oldIrql);
  139. //TODO FANNY: CHECK IF REPLACING CODE THAT WAS HERE BY
  140. //CyyGetNextIrpLocked MY FIX FOR THE BUG FOUND IN MODEM SHARE
  141. //WAS OVERWRITTEN.
  142. }
  143. VOID
  144. CyyGetNextIrpLocked(
  145. IN PIRP *CurrentOpIrp,
  146. IN PLIST_ENTRY QueueToProcess,
  147. OUT PIRP *NextIrp,
  148. IN BOOLEAN CompleteCurrent,
  149. IN PCYY_DEVICE_EXTENSION extension,
  150. IN KIRQL OldIrql
  151. )
  152. /*++
  153. Routine Description:
  154. This function is used to make the head of the particular
  155. queue the current irp. It also completes the what
  156. was the old current irp if desired. The difference between
  157. this and CyyGetNextIrp() is that for this we assume the caller
  158. holds the cancel spinlock and we should release it when we're done.
  159. Arguments:
  160. CurrentOpIrp - Pointer to a pointer to the currently active
  161. irp for the particular work list. Note that
  162. this item is not actually part of the list.
  163. QueueToProcess - The list to pull the new item off of.
  164. NextIrp - The next Irp to process. Note that CurrentOpIrp
  165. will be set to this value under protection of the
  166. cancel spin lock. However, if *NextIrp is NULL when
  167. this routine returns, it is not necessaryly true the
  168. what is pointed to by CurrentOpIrp will also be NULL.
  169. The reason for this is that if the queue is empty
  170. when we hold the cancel spin lock, a new irp may come
  171. in immediately after we release the lock.
  172. CompleteCurrent - If TRUE then this routine will complete the
  173. irp pointed to by the pointer argument
  174. CurrentOpIrp.
  175. OldIrql - IRQL which the cancel spinlock was acquired at and what we
  176. should restore it to.
  177. Return Value:
  178. None.
  179. --*/
  180. {
  181. PIRP oldIrp;
  182. CYY_LOCKED_PAGED_CODE();
  183. oldIrp = *CurrentOpIrp;
  184. #if DBG
  185. if (oldIrp) {
  186. if (CompleteCurrent) {
  187. ASSERT(!oldIrp->CancelRoutine);
  188. }
  189. }
  190. #endif
  191. //
  192. // Check to see if there is a new irp to start up.
  193. //
  194. if (!IsListEmpty(QueueToProcess)) {
  195. PLIST_ENTRY headOfList;
  196. headOfList = RemoveHeadList(QueueToProcess);
  197. *CurrentOpIrp = CONTAINING_RECORD(
  198. headOfList,
  199. IRP,
  200. Tail.Overlay.ListEntry
  201. );
  202. IoSetCancelRoutine(
  203. *CurrentOpIrp,
  204. NULL
  205. );
  206. } else {
  207. *CurrentOpIrp = NULL;
  208. }
  209. *NextIrp = *CurrentOpIrp;
  210. IoReleaseCancelSpinLock(OldIrql);
  211. if (CompleteCurrent) {
  212. if (oldIrp) {
  213. CyyCompleteRequest(extension, oldIrp, IO_SERIAL_INCREMENT);
  214. }
  215. }
  216. }
  217. VOID
  218. CyyTryToCompleteCurrent(
  219. IN PCYY_DEVICE_EXTENSION Extension,
  220. IN PKSYNCHRONIZE_ROUTINE SynchRoutine OPTIONAL,
  221. IN KIRQL IrqlForRelease,
  222. IN NTSTATUS StatusToUse,
  223. IN PIRP *CurrentOpIrp,
  224. IN PLIST_ENTRY QueueToProcess OPTIONAL,
  225. IN PKTIMER IntervalTimer OPTIONAL,
  226. IN PKTIMER TotalTimer OPTIONAL,
  227. IN PSERIAL_START_ROUTINE Starter OPTIONAL,
  228. IN PSERIAL_GET_NEXT_ROUTINE GetNextIrp OPTIONAL,
  229. IN LONG RefType
  230. )
  231. /*--------------------------------------------------------------------------
  232. CyyTryToCompleteCurrent()
  233. Routine Description: This routine attempts to kill all of the reasons
  234. there are references on the current read/write. If everything can be
  235. killed it will complete this read/write and try to start another.
  236. NOTE: This routine assumes that the cancel spinlock is being held.
  237. Arguments:
  238. Extension - Simply a pointer to the device extension.
  239. SynchRoutine - A routine that will synchronize with the isr
  240. and attempt to remove the knowledge of the
  241. current irp from the isr. NOTE: This pointer
  242. can be null.
  243. IrqlForRelease - This routine is called with the cancel spinlock held.
  244. This is the irql that was current when the cancel
  245. spinlock was acquired.
  246. StatusToUse - The irp's status field will be set to this value, if
  247. this routine can complete the irp.
  248. Return Value: None.
  249. --------------------------------------------------------------------------*/
  250. {
  251. CYY_LOCKED_PAGED_CODE();
  252. // We can decrement the reference to "remove" the fact
  253. // that the caller no longer will be accessing this irp.
  254. SERIAL_CLEAR_REFERENCE(*CurrentOpIrp,RefType);
  255. if (SynchRoutine) {
  256. KeSynchronizeExecution(Extension->Interrupt,SynchRoutine,Extension);
  257. }
  258. // Try to run down all other references to this irp.
  259. CyyRundownIrpRefs(CurrentOpIrp,IntervalTimer,TotalTimer,Extension);
  260. // See if the ref count is zero after trying to kill everybody else.
  261. if (!SERIAL_REFERENCE_COUNT(*CurrentOpIrp)) {
  262. PIRP newIrp;
  263. // The ref count was zero so we should complete this request.
  264. // The following call will also cause the current irp to be
  265. // completed.
  266. (*CurrentOpIrp)->IoStatus.Status = StatusToUse;
  267. if (StatusToUse == STATUS_CANCELLED) {
  268. (*CurrentOpIrp)->IoStatus.Information = 0;
  269. }
  270. if (GetNextIrp) {
  271. IoReleaseCancelSpinLock(IrqlForRelease);
  272. GetNextIrp(CurrentOpIrp,QueueToProcess,&newIrp,TRUE
  273. ,Extension
  274. );
  275. if (newIrp) {
  276. Starter(Extension);
  277. }
  278. } else {
  279. PIRP oldIrp = *CurrentOpIrp;
  280. // There was no get next routine. We will simply complete
  281. // the irp. We should make sure that we null out the
  282. // pointer to the pointer to this irp.
  283. *CurrentOpIrp = NULL;
  284. IoReleaseCancelSpinLock(IrqlForRelease);
  285. CyyCompleteRequest(Extension, oldIrp, IO_SERIAL_INCREMENT);
  286. }
  287. } else {
  288. IoReleaseCancelSpinLock(IrqlForRelease);
  289. }
  290. }
  291. VOID
  292. CyyRundownIrpRefs(
  293. IN PIRP *CurrentOpIrp,
  294. IN PKTIMER IntervalTimer OPTIONAL,
  295. IN PKTIMER TotalTimer OPTIONAL,
  296. IN PCYY_DEVICE_EXTENSION PDevExt
  297. )
  298. /*++
  299. Routine Description:
  300. This routine runs through the various items that *could*
  301. have a reference to the current read/write. It try's to kill
  302. the reason. If it does succeed in killing the reason it
  303. will decrement the reference count on the irp.
  304. NOTE: This routine assumes that it is called with the cancel
  305. spin lock held.
  306. Arguments:
  307. CurrentOpIrp - Pointer to a pointer to current irp for the
  308. particular operation.
  309. IntervalTimer - Pointer to the interval timer for the operation.
  310. NOTE: This could be null.
  311. TotalTimer - Pointer to the total timer for the operation.
  312. NOTE: This could be null.
  313. PDevExt - Pointer to device extension
  314. Return Value:
  315. None.
  316. --*/
  317. {
  318. CYY_LOCKED_PAGED_CODE();
  319. //
  320. // This routine is called with the cancel spin lock held
  321. // so we know only one thread of execution can be in here
  322. // at one time.
  323. //
  324. //
  325. // First we see if there is still a cancel routine. If
  326. // so then we can decrement the count by one.
  327. //
  328. if ((*CurrentOpIrp)->CancelRoutine) {
  329. SERIAL_CLEAR_REFERENCE(
  330. *CurrentOpIrp,
  331. SERIAL_REF_CANCEL
  332. );
  333. IoSetCancelRoutine(
  334. *CurrentOpIrp,
  335. NULL
  336. );
  337. }
  338. if (IntervalTimer) {
  339. //
  340. // Try to cancel the operations interval timer. If the operation
  341. // returns true then the timer did have a reference to the
  342. // irp. Since we've canceled this timer that reference is
  343. // no longer valid and we can decrement the reference count.
  344. //
  345. // If the cancel returns false then this means either of two things:
  346. //
  347. // a) The timer has already fired.
  348. //
  349. // b) There never was an interval timer.
  350. //
  351. // In the case of "b" there is no need to decrement the reference
  352. // count since the "timer" never had a reference to it.
  353. //
  354. // In the case of "a", then the timer itself will be coming
  355. // along and decrement it's reference. Note that the caller
  356. // of this routine might actually be the this timer, but it
  357. // has already decremented the reference.
  358. //
  359. if (CyyCancelTimer(IntervalTimer, PDevExt)) {
  360. SERIAL_CLEAR_REFERENCE(
  361. *CurrentOpIrp,
  362. SERIAL_REF_INT_TIMER
  363. );
  364. }
  365. }
  366. if (TotalTimer) {
  367. //
  368. // Try to cancel the operations total timer. If the operation
  369. // returns true then the timer did have a reference to the
  370. // irp. Since we've canceled this timer that reference is
  371. // no longer valid and we can decrement the reference count.
  372. //
  373. // If the cancel returns false then this means either of two things:
  374. //
  375. // a) The timer has already fired.
  376. //
  377. // b) There never was an total timer.
  378. //
  379. // In the case of "b" there is no need to decrement the reference
  380. // count since the "timer" never had a reference to it.
  381. //
  382. // In the case of "a", then the timer itself will be coming
  383. // along and decrement it's reference. Note that the caller
  384. // of this routine might actually be the this timer, but it
  385. // has already decremented the reference.
  386. //
  387. if (CyyCancelTimer(TotalTimer, PDevExt)) {
  388. SERIAL_CLEAR_REFERENCE(
  389. *CurrentOpIrp,
  390. SERIAL_REF_TOTAL_TIMER
  391. );
  392. }
  393. }
  394. }
  395. NTSTATUS
  396. CyyStartOrQueue(
  397. IN PCYY_DEVICE_EXTENSION Extension,
  398. IN PIRP Irp,
  399. IN PLIST_ENTRY QueueToExamine,
  400. IN PIRP *CurrentOpIrp,
  401. IN PSERIAL_START_ROUTINE Starter
  402. )
  403. /*--------------------------------------------------------------------------
  404. CyyStartOrQueue()
  405. Routine Description: This routine either starts or queues requests to
  406. the driver.
  407. Arguments:
  408. Extension - Points to the serial device extension.
  409. Irp - The irp. The irp will be marked pending.
  410. QueueToExamine - The queue the irp will be placed on.
  411. CurrentOpIrp - Pointer to a pointer to the irp that is current
  412. for the queue. The pointer pointed to will be set with to Irp if
  413. what CurrentOpIrp points to is NULL.
  414. Starter - The routine to call if the queue is empty.
  415. Return Value:
  416. This routine will return STATUS_PENDING if the queue is
  417. not empty. Otherwise, it will return the status returned
  418. from the starter routine (or cancel, if the cancel bit is
  419. on in the irp).
  420. --------------------------------------------------------------------------*/
  421. {
  422. KIRQL oldIrql;
  423. CYY_LOCKED_PAGED_CODE();
  424. IoAcquireCancelSpinLock(&oldIrql);
  425. // If this is a write irp then take the amount of characters
  426. // to write and add it to the count of characters to write.
  427. if (IoGetCurrentIrpStackLocation(Irp)->MajorFunction == IRP_MJ_WRITE) {
  428. Extension->TotalCharsQueued += IoGetCurrentIrpStackLocation(Irp)->
  429. Parameters.Write.Length;
  430. } else {
  431. if ((IoGetCurrentIrpStackLocation(Irp)->MajorFunction
  432. == IRP_MJ_DEVICE_CONTROL) &&
  433. ((IoGetCurrentIrpStackLocation(Irp)
  434. ->Parameters.DeviceIoControl.IoControlCode ==
  435. IOCTL_SERIAL_IMMEDIATE_CHAR) ||
  436. (IoGetCurrentIrpStackLocation(Irp)
  437. ->Parameters.DeviceIoControl.IoControlCode ==
  438. IOCTL_SERIAL_XOFF_COUNTER))) {
  439. Extension->TotalCharsQueued++;
  440. }
  441. }
  442. if ((IsListEmpty(QueueToExamine)) && !(*CurrentOpIrp)) {
  443. // no current operation. Mark this one as current and start it up.
  444. *CurrentOpIrp = Irp;
  445. IoReleaseCancelSpinLock(oldIrql);
  446. return Starter(Extension);
  447. } else {
  448. // We don't know how long the irp will be in the queue.
  449. if (Irp->Cancel) {
  450. PIO_STACK_LOCATION irpSp = IoGetCurrentIrpStackLocation(Irp);
  451. IoReleaseCancelSpinLock(oldIrql);
  452. if (irpSp->Parameters.DeviceIoControl.IoControlCode ==
  453. IOCTL_SERIAL_SET_QUEUE_SIZE) {
  454. //
  455. // We shoved the pointer to the memory into the
  456. // the type 3 buffer pointer which we KNOW we
  457. // never use.
  458. //
  459. ASSERT(irpSp->Parameters.DeviceIoControl.Type3InputBuffer);
  460. ExFreePool(irpSp->Parameters.DeviceIoControl.Type3InputBuffer);
  461. irpSp->Parameters.DeviceIoControl.Type3InputBuffer = NULL;
  462. }
  463. Irp->IoStatus.Status = STATUS_CANCELLED;
  464. CyyCompleteRequest(Extension, Irp, 0);
  465. return STATUS_CANCELLED;
  466. } else {
  467. Irp->IoStatus.Status = STATUS_PENDING;
  468. IoMarkIrpPending(Irp);
  469. InsertTailList(QueueToExamine,&Irp->Tail.Overlay.ListEntry);
  470. IoSetCancelRoutine(Irp,CyyCancelQueued);
  471. IoReleaseCancelSpinLock(oldIrql);
  472. return STATUS_PENDING;
  473. }
  474. }
  475. }
  476. VOID
  477. CyyCancelQueued(
  478. PDEVICE_OBJECT DeviceObject,
  479. PIRP Irp
  480. )
  481. /*--------------------------------------------------------------------------
  482. CyyCancelQueued()
  483. Routine Description: This routine is used to cancel Irps that currently
  484. reside on a queue.
  485. Arguments:
  486. DeviceObject - Pointer to the device object for this device
  487. Irp - Pointer to the IRP to be canceled.
  488. Return Value: None.
  489. --------------------------------------------------------------------------*/
  490. {
  491. PCYY_DEVICE_EXTENSION extension = DeviceObject->DeviceExtension;
  492. PIO_STACK_LOCATION irpSp = IoGetCurrentIrpStackLocation(Irp);
  493. CYY_LOCKED_PAGED_CODE();
  494. Irp->IoStatus.Status = STATUS_CANCELLED;
  495. Irp->IoStatus.Information = 0;
  496. RemoveEntryList(&Irp->Tail.Overlay.ListEntry);
  497. if (irpSp->MajorFunction == IRP_MJ_WRITE) {
  498. // write. subtract from the count of characters to write.
  499. extension->TotalCharsQueued -= irpSp->Parameters.Write.Length;
  500. } else if (irpSp->MajorFunction == IRP_MJ_DEVICE_CONTROL) {
  501. if ((irpSp->Parameters.DeviceIoControl.IoControlCode ==
  502. IOCTL_SERIAL_IMMEDIATE_CHAR) ||
  503. (irpSp->Parameters.DeviceIoControl.IoControlCode ==
  504. IOCTL_SERIAL_XOFF_COUNTER)) {
  505. // immediate. Decrement the count of chars queued.
  506. extension->TotalCharsQueued--;
  507. } else if (irpSp->Parameters.DeviceIoControl.IoControlCode ==
  508. IOCTL_SERIAL_SET_QUEUE_SIZE) {
  509. // resize. Deallocate the pool passed "resizing" routine.
  510. // We shoved the pointer to the memory into the
  511. // the type 3 buffer pointer which we KNOW we never use.
  512. ASSERT(irpSp->Parameters.DeviceIoControl.Type3InputBuffer);
  513. ExFreePool(irpSp->Parameters.DeviceIoControl.Type3InputBuffer);
  514. irpSp->Parameters.DeviceIoControl.Type3InputBuffer = NULL;
  515. }
  516. }
  517. IoReleaseCancelSpinLock(Irp->CancelIrql);
  518. CyyCompleteRequest(extension, Irp, IO_SERIAL_INCREMENT);
  519. }
  520. NTSTATUS
  521. CyyCompleteIfError(
  522. PDEVICE_OBJECT DeviceObject,
  523. PIRP Irp
  524. )
  525. /*--------------------------------------------------------------------------
  526. CyyCompleteIfError()
  527. Routine Description: If the current irp is not an
  528. IOCTL_SERIAL_GET_COMMSTATUS request and there is an error and the
  529. application requested abort on errors, then cancel the irp.
  530. Arguments:
  531. DeviceObject - Pointer to the device object for this device
  532. Irp - Pointer to the IRP to test.
  533. Return Value:
  534. STATUS_SUCCESS or STATUS_CANCELLED.
  535. --------------------------------------------------------------------------*/
  536. {
  537. PCYY_DEVICE_EXTENSION extension = DeviceObject->DeviceExtension;
  538. NTSTATUS status = STATUS_SUCCESS;
  539. CYY_LOCKED_PAGED_CODE();
  540. if ((extension->HandFlow.ControlHandShake &
  541. SERIAL_ERROR_ABORT) && extension->ErrorWord) {
  542. PIO_STACK_LOCATION irpSp = IoGetCurrentIrpStackLocation(Irp);
  543. // There is a current error in the driver. No requests should
  544. // come through except for the GET_COMMSTATUS.
  545. if ((irpSp->MajorFunction != IRP_MJ_DEVICE_CONTROL) ||
  546. (irpSp->Parameters.DeviceIoControl.IoControlCode !=
  547. IOCTL_SERIAL_GET_COMMSTATUS)) {
  548. status = STATUS_CANCELLED;
  549. Irp->IoStatus.Status = STATUS_CANCELLED;
  550. Irp->IoStatus.Information = 0;
  551. CyyCompleteRequest(extension, Irp, 0);
  552. }
  553. }
  554. return status;
  555. }
  556. VOID
  557. CyyFilterCancelQueued(IN PDEVICE_OBJECT PDevObj, IN PIRP PIrp)
  558. /*++
  559. Routine Description:
  560. This routine will be used cancel irps on the stalled queue.
  561. Arguments:
  562. PDevObj - Pointer to the device object.
  563. PIrp - Pointer to the Irp to cancel
  564. Return Value:
  565. None.
  566. --*/
  567. {
  568. PCYY_DEVICE_EXTENSION pDevExt = PDevObj->DeviceExtension;
  569. PIO_STACK_LOCATION pIrpSp = IoGetCurrentIrpStackLocation(PIrp);
  570. PIrp->IoStatus.Status = STATUS_CANCELLED;
  571. PIrp->IoStatus.Information = 0;
  572. RemoveEntryList(&PIrp->Tail.Overlay.ListEntry);
  573. IoReleaseCancelSpinLock(PIrp->CancelIrql);
  574. }
  575. VOID
  576. CyyKillAllStalled(IN PDEVICE_OBJECT PDevObj)
  577. {
  578. KIRQL cancelIrql;
  579. PDRIVER_CANCEL cancelRoutine;
  580. PCYY_DEVICE_EXTENSION pDevExt = PDevObj->DeviceExtension;
  581. IoAcquireCancelSpinLock(&cancelIrql);
  582. while (!IsListEmpty(&pDevExt->StalledIrpQueue)) {
  583. PIRP currentLastIrp = CONTAINING_RECORD(pDevExt->StalledIrpQueue.Blink,
  584. IRP, Tail.Overlay.ListEntry);
  585. RemoveEntryList(pDevExt->StalledIrpQueue.Blink);
  586. cancelRoutine = currentLastIrp->CancelRoutine;
  587. currentLastIrp->CancelIrql = cancelIrql;
  588. currentLastIrp->CancelRoutine = NULL;
  589. currentLastIrp->Cancel = TRUE;
  590. cancelRoutine(PDevObj, currentLastIrp);
  591. IoAcquireCancelSpinLock(&cancelIrql);
  592. }
  593. IoReleaseCancelSpinLock(cancelIrql);
  594. }
  595. NTSTATUS
  596. CyyFilterIrps(IN PIRP PIrp, IN PCYY_DEVICE_EXTENSION PDevExt)
  597. /*++
  598. Routine Description:
  599. This routine will be used to approve irps for processing.
  600. If an irp is approved, success will be returned. If not,
  601. the irp will be queued or rejected outright. The IoStatus struct
  602. and return value will appropriately reflect the actions taken.
  603. Arguments:
  604. PIrp - Pointer to the Irp to cancel
  605. PDevExt - Pointer to the device extension
  606. Return Value:
  607. None.
  608. --*/
  609. {
  610. PIO_STACK_LOCATION pIrpStack;
  611. KIRQL oldIrqlFlags;
  612. pIrpStack = IoGetCurrentIrpStackLocation(PIrp);
  613. KeAcquireSpinLock(&PDevExt->FlagsLock, &oldIrqlFlags);
  614. if ((PDevExt->DevicePNPAccept == CYY_PNPACCEPT_OK)
  615. && ((PDevExt->Flags & CYY_FLAGS_BROKENHW) == 0)) {
  616. KeReleaseSpinLock(&PDevExt->FlagsLock, oldIrqlFlags);
  617. return STATUS_SUCCESS;
  618. }
  619. if ((PDevExt->DevicePNPAccept & CYY_PNPACCEPT_REMOVING)
  620. || (PDevExt->Flags & CYY_FLAGS_BROKENHW)
  621. || (PDevExt->DevicePNPAccept & CYY_PNPACCEPT_SURPRISE_REMOVING)) {
  622. KeReleaseSpinLock(&PDevExt->FlagsLock, oldIrqlFlags);
  623. //
  624. // Accept all PNP IRP's -- we assume PNP can synchronize itself
  625. //
  626. if (pIrpStack->MajorFunction == IRP_MJ_PNP) {
  627. return STATUS_SUCCESS;
  628. }
  629. PIrp->IoStatus.Status = STATUS_DELETE_PENDING;
  630. return STATUS_DELETE_PENDING;
  631. }
  632. if (PDevExt->DevicePNPAccept & CYY_PNPACCEPT_STOPPING) {
  633. KIRQL oldIrql;
  634. KeReleaseSpinLock(&PDevExt->FlagsLock, oldIrqlFlags);
  635. //
  636. // Accept all PNP IRP's -- we assume PNP can synchronize itself
  637. //
  638. if (pIrpStack->MajorFunction == IRP_MJ_PNP) {
  639. return STATUS_SUCCESS;
  640. }
  641. IoAcquireCancelSpinLock(&oldIrql);
  642. if (PIrp->Cancel) {
  643. IoReleaseCancelSpinLock(oldIrql);
  644. PIrp->IoStatus.Status = STATUS_CANCELLED;
  645. return STATUS_CANCELLED;
  646. } else {
  647. //
  648. // Mark the Irp as pending
  649. //
  650. PIrp->IoStatus.Status = STATUS_PENDING;
  651. IoMarkIrpPending(PIrp);
  652. //
  653. // Queue up the IRP
  654. //
  655. InsertTailList(&PDevExt->StalledIrpQueue,
  656. &PIrp->Tail.Overlay.ListEntry);
  657. IoSetCancelRoutine(PIrp, CyyFilterCancelQueued);
  658. IoReleaseCancelSpinLock(oldIrql);
  659. return STATUS_PENDING;
  660. }
  661. }
  662. KeReleaseSpinLock(&PDevExt->FlagsLock, oldIrqlFlags);
  663. return STATUS_SUCCESS;
  664. }
  665. VOID
  666. CyyUnstallIrps(IN PCYY_DEVICE_EXTENSION PDevExt)
  667. /*++
  668. Routine Description:
  669. This routine will be used to restart irps temporarily stalled on
  670. the stall queue due to a stop or some such nonsense.
  671. Arguments:
  672. PDevExt - Pointer to the device extension
  673. Return Value:
  674. None.
  675. --*/
  676. {
  677. PLIST_ENTRY pIrpLink;
  678. PIRP pIrp;
  679. PIO_STACK_LOCATION pIrpStack;
  680. PDEVICE_OBJECT pDevObj;
  681. PDRIVER_OBJECT pDrvObj;
  682. KIRQL oldIrql;
  683. CyyDbgPrintEx(DPFLTR_TRACE_LEVEL, ">CyyUnstallIrps(%X)\n", PDevExt);
  684. IoAcquireCancelSpinLock(&oldIrql);
  685. pIrpLink = PDevExt->StalledIrpQueue.Flink;
  686. while (pIrpLink != &PDevExt->StalledIrpQueue) {
  687. pIrp = CONTAINING_RECORD(pIrpLink, IRP, Tail.Overlay.ListEntry);
  688. RemoveEntryList(&pIrp->Tail.Overlay.ListEntry);
  689. pIrpStack = IoGetCurrentIrpStackLocation(pIrp);
  690. pDevObj = pIrpStack->DeviceObject;
  691. pDrvObj = pDevObj->DriverObject;
  692. IoSetCancelRoutine(pIrp, NULL);
  693. IoReleaseCancelSpinLock(oldIrql);
  694. CyyDbgPrintEx(CYYPNPPOWER, "Unstalling Irp 0x%x with 0x%x\n",
  695. pIrp, pIrpStack->MajorFunction);
  696. pDrvObj->MajorFunction[pIrpStack->MajorFunction](pDevObj, pIrp);
  697. IoAcquireCancelSpinLock(&oldIrql);
  698. pIrpLink = PDevExt->StalledIrpQueue.Flink;
  699. }
  700. IoReleaseCancelSpinLock(oldIrql);
  701. CyyDbgPrintEx(DPFLTR_TRACE_LEVEL, "<CyyUnstallIrps\n");
  702. }
  703. NTSTATUS
  704. CyyIRPPrologue(IN PIRP PIrp, IN PCYY_DEVICE_EXTENSION PDevExt)
  705. /*++
  706. Routine Description:
  707. This function must be called at any IRP dispatch entry point. It,
  708. with CyyIRPEpilogue(), keeps track of all pending IRP's for the given
  709. PDevObj.
  710. Arguments:
  711. PDevObj - Pointer to the device object we are tracking pending IRP's for.
  712. Return Value:
  713. Tentative status of the Irp.
  714. --*/
  715. {
  716. InterlockedIncrement(&PDevExt->PendingIRPCnt);
  717. return CyyFilterIrps(PIrp, PDevExt);
  718. }
  719. VOID
  720. CyyIRPEpilogue(IN PCYY_DEVICE_EXTENSION PDevExt)
  721. /*++
  722. Routine Description:
  723. This function must be called at any IRP dispatch entry point. It,
  724. with CyyIRPPrologue(), keeps track of all pending IRP's for the given
  725. PDevObj.
  726. Arguments:
  727. PDevObj - Pointer to the device object we are tracking pending IRP's for.
  728. Return Value:
  729. None.
  730. --*/
  731. {
  732. LONG pendingCnt;
  733. pendingCnt = InterlockedDecrement(&PDevExt->PendingIRPCnt);
  734. ASSERT(pendingCnt >= 0);
  735. if (pendingCnt == 0) {
  736. KeSetEvent(&PDevExt->PendingIRPEvent, IO_NO_INCREMENT, FALSE);
  737. }
  738. }
  739. BOOLEAN
  740. CyyInsertQueueDpc(IN PRKDPC PDpc, IN PVOID Sarg1, IN PVOID Sarg2,
  741. IN PCYY_DEVICE_EXTENSION PDevExt)
  742. /*++
  743. Routine Description:
  744. This function must be called to queue DPC's for the serial driver.
  745. Arguments:
  746. PDpc thru Sarg2 - Standard args to KeInsertQueueDpc()
  747. PDevExt - Pointer to the device extension for the device that needs to
  748. queue a DPC
  749. Return Value:
  750. Kicks up return value from KeInsertQueueDpc()
  751. --*/
  752. {
  753. BOOLEAN queued;
  754. InterlockedIncrement(&PDevExt->DpcCount);
  755. LOGENTRY(LOG_CNT, 'DpI1', PDpc, PDevExt->DpcCount, 0); // Added in build 2128
  756. queued = KeInsertQueueDpc(PDpc, Sarg1, Sarg2);
  757. if (!queued) {
  758. ULONG pendingCnt;
  759. pendingCnt = InterlockedDecrement(&PDevExt->DpcCount);
  760. // LOGENTRY(LOG_CNT, 'DpD1', PDpc, PDevExt->DpcCount, 0); Added in build 2128
  761. if (pendingCnt == 0) {
  762. KeSetEvent(&PDevExt->PendingDpcEvent, IO_NO_INCREMENT, FALSE);
  763. LOGENTRY(LOG_CNT, 'DpF1', PDpc, PDevExt->DpcCount, 0); // Added in build 2128
  764. }
  765. }
  766. #if 0 // DBG
  767. if (queued) {
  768. int i;
  769. for (i = 0; i < MAX_DPC_QUEUE; i++) {
  770. if (PDevExt->DpcQueued[i].Dpc == PDpc) {
  771. PDevExt->DpcQueued[i].QueuedCount++;
  772. break;
  773. }
  774. }
  775. ASSERT(i < MAX_DPC_QUEUE);
  776. }
  777. #endif
  778. return queued;
  779. }
  780. BOOLEAN
  781. CyySetTimer(IN PKTIMER Timer, IN LARGE_INTEGER DueTime,
  782. IN PKDPC Dpc OPTIONAL, IN PCYY_DEVICE_EXTENSION PDevExt)
  783. /*++
  784. Routine Description:
  785. This function must be called to set timers for the serial driver.
  786. Arguments:
  787. Timer - pointer to timer dispatcher object
  788. DueTime - time at which the timer should expire
  789. Dpc - option Dpc
  790. PDevExt - Pointer to the device extension for the device that needs to
  791. set a timer
  792. Return Value:
  793. Kicks up return value from KeSetTimer()
  794. --*/
  795. {
  796. BOOLEAN set;
  797. InterlockedIncrement(&PDevExt->DpcCount);
  798. LOGENTRY(LOG_CNT, 'DpI2', Dpc, PDevExt->DpcCount, 0); // Added in build 2128
  799. set = KeSetTimer(Timer, DueTime, Dpc);
  800. if (set) {
  801. InterlockedDecrement(&PDevExt->DpcCount);
  802. // LOGENTRY(LOG_CNT, 'DpD2', Dpc, PDevExt->DpcCount, 0); // Added in build 2128
  803. }
  804. #if 0 // DBG
  805. if (set) {
  806. int i;
  807. for (i = 0; i < MAX_DPC_QUEUE; i++) {
  808. if (PDevExt->DpcQueued[i].Dpc == Dpc) {
  809. PDevExt->DpcQueued[i].QueuedCount++;
  810. break;
  811. }
  812. }
  813. ASSERT(i < MAX_DPC_QUEUE);
  814. }
  815. #endif
  816. return set;
  817. }
  818. BOOLEAN
  819. CyyCancelTimer(IN PKTIMER Timer, IN PCYY_DEVICE_EXTENSION PDevExt)
  820. /*++
  821. Routine Description:
  822. This function must be called to cancel timers for the serial driver.
  823. Arguments:
  824. Timer - pointer to timer dispatcher object
  825. PDevExt - Pointer to the device extension for the device that needs to
  826. set a timer
  827. Return Value:
  828. True if timer was cancelled
  829. --*/
  830. {
  831. BOOLEAN cancelled;
  832. cancelled = KeCancelTimer(Timer);
  833. if (cancelled) {
  834. CyyDpcEpilogue(PDevExt, Timer->Dpc);
  835. }
  836. return cancelled;
  837. }
  838. VOID
  839. CyyDpcEpilogue(IN PCYY_DEVICE_EXTENSION PDevExt, PKDPC PDpc)
  840. /*++
  841. Routine Description:
  842. This function must be called at the end of every dpc function.
  843. Arguments:
  844. PDevObj - Pointer to the device object we are tracking dpc's for.
  845. Return Value:
  846. None.
  847. --*/
  848. {
  849. LONG pendingCnt;
  850. #if 1 // !DBG
  851. UNREFERENCED_PARAMETER(PDpc);
  852. #endif
  853. pendingCnt = InterlockedDecrement(&PDevExt->DpcCount);
  854. // LOGENTRY(LOG_CNT, 'DpD3', PDpc, PDevExt->DpcCount, 0); Added in build 2128
  855. ASSERT(pendingCnt >= 0);
  856. #if 0 //DBG
  857. {
  858. int i;
  859. for (i = 0; i < MAX_DPC_QUEUE; i++) {
  860. if (PDevExt->DpcQueued[i].Dpc == PDpc) {
  861. PDevExt->DpcQueued[i].FlushCount++;
  862. ASSERT(PDevExt->DpcQueued[i].QueuedCount >=
  863. PDevExt->DpcQueued[i].FlushCount);
  864. break;
  865. }
  866. }
  867. ASSERT(i < MAX_DPC_QUEUE);
  868. }
  869. #endif
  870. if (pendingCnt == 0) {
  871. KeSetEvent(&PDevExt->PendingDpcEvent, IO_NO_INCREMENT, FALSE);
  872. LOGENTRY(LOG_CNT, 'DpF2', PDpc, PDevExt->DpcCount, 0); // Added in build 2128
  873. }
  874. }
  875. VOID
  876. CyyUnlockPages(IN PKDPC PDpc, IN PVOID PDeferredContext,
  877. IN PVOID PSysContext1, IN PVOID PSysContext2)
  878. /*++
  879. Routine Description:
  880. This function is a DPC routine queue from the ISR if he released the
  881. last lock on pending DPC's.
  882. Arguments:
  883. PDpdc, PSysContext1, PSysContext2 -- not used
  884. PDeferredContext -- Really the device extension
  885. Return Value:
  886. None.
  887. --*/
  888. {
  889. PCYY_DEVICE_EXTENSION pDevExt
  890. = (PCYY_DEVICE_EXTENSION)PDeferredContext;
  891. UNREFERENCED_PARAMETER(PDpc);
  892. UNREFERENCED_PARAMETER(PSysContext1);
  893. UNREFERENCED_PARAMETER(PSysContext2);
  894. KeSetEvent(&pDevExt->PendingDpcEvent, IO_NO_INCREMENT, FALSE);
  895. }
  896. NTSTATUS
  897. CyyIoCallDriver(PCYY_DEVICE_EXTENSION PDevExt, PDEVICE_OBJECT PDevObj,
  898. PIRP PIrp)
  899. /*++
  900. Routine Description:
  901. This function must be called instead of IoCallDriver. It automatically
  902. updates Irp tracking for PDevObj.
  903. Arguments:
  904. PDevExt - Device extension attached to PDevObj
  905. PDevObj - Pointer to the device object we are tracking pending IRP's for.
  906. PIrp - Pointer to the Irp we are passing to the next driver.
  907. Return Value:
  908. None.
  909. --*/
  910. {
  911. NTSTATUS status;
  912. status = IoCallDriver(PDevObj, PIrp);
  913. CyyIRPEpilogue(PDevExt);
  914. return status;
  915. }
  916. NTSTATUS
  917. CyyPoCallDriver(PCYY_DEVICE_EXTENSION PDevExt, PDEVICE_OBJECT PDevObj,
  918. PIRP PIrp)
  919. /*++
  920. Routine Description:
  921. This function must be called instead of PoCallDriver. It automatically
  922. updates Irp tracking for PDevObj.
  923. Arguments:
  924. PDevExt - Device extension attached to PDevObj
  925. PDevObj - Pointer to the device object we are tracking pending IRP's for.
  926. PIrp - Pointer to the Irp we are passing to the next driver.
  927. Return Value:
  928. None.
  929. --*/
  930. {
  931. NTSTATUS status;
  932. status = PoCallDriver(PDevObj, PIrp);
  933. CyyIRPEpilogue(PDevExt);
  934. return status;
  935. }
  936. VOID
  937. CyyLogError(
  938. IN PDRIVER_OBJECT DriverObject,
  939. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  940. IN PHYSICAL_ADDRESS P1,
  941. IN PHYSICAL_ADDRESS P2,
  942. IN ULONG SequenceNumber,
  943. IN UCHAR MajorFunctionCode,
  944. IN UCHAR RetryCount,
  945. IN ULONG UniqueErrorValue,
  946. IN NTSTATUS FinalStatus,
  947. IN NTSTATUS SpecificIOStatus,
  948. IN ULONG LengthOfInsert1,
  949. IN PWCHAR Insert1,
  950. IN ULONG LengthOfInsert2,
  951. IN PWCHAR Insert2
  952. )
  953. /*++
  954. Routine Description:
  955. This routine allocates an error log entry, copies the supplied data
  956. to it, and requests that it be written to the error log file.
  957. Arguments:
  958. DriverObject - A pointer to the driver object for the device.
  959. DeviceObject - A pointer to the device object associated with the
  960. device that had the error, early in initialization, one may not
  961. yet exist.
  962. P1,P2 - If phyical addresses for the controller ports involved
  963. with the error are available, put them through as dump data.
  964. SequenceNumber - A ulong value that is unique to an IRP over the
  965. life of the irp in this driver - 0 generally means an error not
  966. associated with an irp.
  967. MajorFunctionCode - If there is an error associated with the irp,
  968. this is the major function code of that irp.
  969. RetryCount - The number of times a particular operation has been
  970. retried.
  971. UniqueErrorValue - A unique long word that identifies the particular
  972. call to this function.
  973. FinalStatus - The final status given to the irp that was associated
  974. with this error. If this log entry is being made during one of
  975. the retries this value will be STATUS_SUCCESS.
  976. SpecificIOStatus - The IO status for a particular error.
  977. LengthOfInsert1 - The length in bytes (including the terminating NULL)
  978. of the first insertion string.
  979. Insert1 - The first insertion string.
  980. LengthOfInsert2 - The length in bytes (including the terminating NULL)
  981. of the second insertion string. NOTE, there must
  982. be a first insertion string for their to be
  983. a second insertion string.
  984. Insert2 - The second insertion string.
  985. Return Value:
  986. None.
  987. --*/
  988. {
  989. PIO_ERROR_LOG_PACKET errorLogEntry;
  990. PVOID objectToUse;
  991. SHORT dumpToAllocate = 0;
  992. PUCHAR ptrToFirstInsert;
  993. PUCHAR ptrToSecondInsert;
  994. //PAGED_CODE(); It can be called at raised IRQL.
  995. if (Insert1 == NULL) {
  996. LengthOfInsert1 = 0;
  997. }
  998. if (Insert2 == NULL) {
  999. LengthOfInsert2 = 0;
  1000. }
  1001. if (ARGUMENT_PRESENT(DeviceObject)) {
  1002. objectToUse = DeviceObject;
  1003. } else {
  1004. objectToUse = DriverObject;
  1005. }
  1006. if (CyyMemCompare(
  1007. P1,
  1008. (ULONG)1,
  1009. CyyPhysicalZero,
  1010. (ULONG)1
  1011. ) != AddressesAreEqual) {
  1012. dumpToAllocate = (SHORT)sizeof(PHYSICAL_ADDRESS);
  1013. }
  1014. if (CyyMemCompare(
  1015. P2,
  1016. (ULONG)1,
  1017. CyyPhysicalZero,
  1018. (ULONG)1
  1019. ) != AddressesAreEqual) {
  1020. dumpToAllocate += (SHORT)sizeof(PHYSICAL_ADDRESS);
  1021. }
  1022. errorLogEntry = IoAllocateErrorLogEntry(
  1023. objectToUse,
  1024. (UCHAR)(sizeof(IO_ERROR_LOG_PACKET) +
  1025. dumpToAllocate
  1026. + LengthOfInsert1 +
  1027. LengthOfInsert2)
  1028. );
  1029. if ( errorLogEntry != NULL ) {
  1030. errorLogEntry->ErrorCode = SpecificIOStatus;
  1031. errorLogEntry->SequenceNumber = SequenceNumber;
  1032. errorLogEntry->MajorFunctionCode = MajorFunctionCode;
  1033. errorLogEntry->RetryCount = RetryCount;
  1034. errorLogEntry->UniqueErrorValue = UniqueErrorValue;
  1035. errorLogEntry->FinalStatus = FinalStatus;
  1036. errorLogEntry->DumpDataSize = dumpToAllocate;
  1037. if (dumpToAllocate) {
  1038. RtlCopyMemory(
  1039. &errorLogEntry->DumpData[0],
  1040. &P1,
  1041. sizeof(PHYSICAL_ADDRESS)
  1042. );
  1043. if (dumpToAllocate > sizeof(PHYSICAL_ADDRESS)) {
  1044. RtlCopyMemory(
  1045. ((PUCHAR)&errorLogEntry->DumpData[0])
  1046. +sizeof(PHYSICAL_ADDRESS),
  1047. &P2,
  1048. sizeof(PHYSICAL_ADDRESS)
  1049. );
  1050. ptrToFirstInsert =
  1051. ((PUCHAR)&errorLogEntry->DumpData[0])+(2*sizeof(PHYSICAL_ADDRESS));
  1052. } else {
  1053. ptrToFirstInsert =
  1054. ((PUCHAR)&errorLogEntry->DumpData[0])+sizeof(PHYSICAL_ADDRESS);
  1055. }
  1056. } else {
  1057. ptrToFirstInsert = (PUCHAR)&errorLogEntry->DumpData[0];
  1058. }
  1059. ptrToSecondInsert = ptrToFirstInsert + LengthOfInsert1;
  1060. if (LengthOfInsert1) {
  1061. errorLogEntry->NumberOfStrings = 1;
  1062. errorLogEntry->StringOffset = (USHORT)(ptrToFirstInsert -
  1063. (PUCHAR)errorLogEntry);
  1064. RtlCopyMemory(
  1065. ptrToFirstInsert,
  1066. Insert1,
  1067. LengthOfInsert1
  1068. );
  1069. if (LengthOfInsert2) {
  1070. errorLogEntry->NumberOfStrings = 2;
  1071. RtlCopyMemory(
  1072. ptrToSecondInsert,
  1073. Insert2,
  1074. LengthOfInsert2
  1075. );
  1076. }
  1077. }
  1078. IoWriteErrorLogEntry(errorLogEntry);
  1079. }
  1080. }
  1081. VOID
  1082. CyyMarkHardwareBroken(IN PCYY_DEVICE_EXTENSION PDevExt)
  1083. /*++
  1084. Routine Description:
  1085. Marks a UART as broken. This causes the driver stack to stop accepting
  1086. requests and eventually be removed.
  1087. Arguments:
  1088. PDevExt - Device extension attached to PDevObj
  1089. Return Value:
  1090. None.
  1091. --*/
  1092. {
  1093. PAGED_CODE();
  1094. //
  1095. // Mark as damaged goods
  1096. //
  1097. CyySetFlags(PDevExt, CYY_FLAGS_BROKENHW);
  1098. //
  1099. // Write a log entry
  1100. //
  1101. CyyLogError(PDevExt->DriverObject, NULL, CyyPhysicalZero,
  1102. CyyPhysicalZero, 0, 0, 0, PDevExt->PortIndex+1, STATUS_SUCCESS,
  1103. CYY_HARDWARE_FAILURE, PDevExt->DeviceName.Length
  1104. + sizeof(WCHAR), PDevExt->DeviceName.Buffer, 0, NULL);
  1105. //
  1106. // Invalidate the device
  1107. //
  1108. IoInvalidateDeviceState(PDevExt->Pdo);
  1109. }
  1110. VOID
  1111. CyySetDeviceFlags(IN PCYY_DEVICE_EXTENSION PDevExt, OUT PULONG PFlags,
  1112. IN ULONG Value, IN BOOLEAN Set)
  1113. /*++
  1114. Routine Description:
  1115. Sets flags in a value protected by the flags spinlock. This is used
  1116. to set values that would stop IRP's from being accepted.
  1117. Arguments:
  1118. PDevExt - Device extension attached to PDevObj
  1119. PFlags - Pointer to the flags variable that needs changing
  1120. Value - Value to modify flags variable with
  1121. Set - TRUE if |= , FALSE if &=
  1122. Return Value:
  1123. None.
  1124. --*/
  1125. {
  1126. KIRQL oldIrql;
  1127. KeAcquireSpinLock(&PDevExt->FlagsLock, &oldIrql);
  1128. if (Set) {
  1129. *PFlags |= Value;
  1130. } else {
  1131. *PFlags &= ~Value;
  1132. }
  1133. KeReleaseSpinLock(&PDevExt->FlagsLock, oldIrql);
  1134. }