1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
|
/*++
Copyright (C) Microsoft Corporation. All rights reserved.
Module Name:
zpodd.c
Abstract:
Code for Zero Power ODD support.
Environment:
kernel mode only
Notes:
Revision History:
--*/
#include "ntddk.h"
#include "ntddstor.h"
#include "wdmguid.h"
#include "cdrom.h"
#include "mmc.h"
#include "ioctl.h"
#include "scratch.h"
#ifdef DEBUG_USE_WPP
#include "zpodd.tmh"
#endif
_IRQL_requires_max_(PASSIVE_LEVEL)
ULONG
DeviceGetZPODDEnabledFromRegistry();
_IRQL_requires_max_(PASSIVE_LEVEL)
NTSTATUS
DeviceQueryD3ColdInterface(
_In_ PCDROM_DEVICE_EXTENSION DeviceExtension,
_Out_ PD3COLD_SUPPORT_INTERFACE D3ColdInterface
);
_IRQL_requires_max_(PASSIVE_LEVEL)
NTSTATUS
DeviceSendEnableIdlePowerIoctl(
_In_ PCDROM_DEVICE_EXTENSION DeviceExtension,
_In_ BOOLEAN WakeCapable,
_In_ BOOLEAN Enable,
_In_ ULONG D3IdleTimeout
);
#if ALLOC_PRAGMA
#pragma alloc_text(PAGE, DeviceInitializeZPODD)
#pragma alloc_text(PAGE, DeviceGetZPODDEnabledFromRegistry)
#pragma alloc_text(PAGE, DeviceQueryD3ColdInterface)
#pragma alloc_text(PAGE, DeviceSendEnableIdlePowerIoctl)
#pragma alloc_text(PAGE, DeviceReleaseZPODDResources)
#pragma alloc_text(PAGE, DeviceZPODDIsInHomePosition)
#pragma alloc_text(PAGE, DeviceMarkActive)
#endif
#pragma warning(push)
#pragma warning(disable:4152) // nonstandard extension, function/data pointer conversion in expression
#pragma warning(disable:26000) // read overflow reported because of pointer type conversion
_IRQL_requires_max_(PASSIVE_LEVEL)
NTSTATUS
DeviceInitializeZPODD(
_In_ PCDROM_DEVICE_EXTENSION DeviceExtension
)
/*++
Routine Description:
This routine initialize the contents of ZPODD structure.
Arguments:
DeviceExtension - the device extension
Return Value:
NTSTATUS
--*/
{
NTSTATUS status = STATUS_SUCCESS;
NTSTATUS tempStatus = STATUS_SUCCESS;
PZERO_POWER_ODD_INFO zpoddInfo = NULL;
PFEATURE_DATA_REMOVABLE_MEDIUM removableMediumHeader = NULL;
ULONG ZPODDEnabledInRegistry = 0;
PD3COLD_SUPPORT_INTERFACE d3ColdInterface = NULL;
DEVICE_WAKE_DEPTH deepestWakeableDstate = DeviceWakeDepthNotWakeable;
BOOLEAN inHomePosition = FALSE;
PAGED_CODE();
if (DeviceExtension->ZeroPowerODDInfo != NULL)
{
//
// Already initialized.
//
goto Cleanup;
}
ZPODDEnabledInRegistry = DeviceGetZPODDEnabledFromRegistry();
if (ZPODDEnabledInRegistry == 0)
{
//
// User has explicitly disabled Zero Power ODD.
//
status = STATUS_NOT_SUPPORTED;
TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_POWER,
"DeviceInitializeZPODD: ZPODD not enabled due to registry settings.\n"
));
goto Cleanup;
}
zpoddInfo = ExAllocatePool2(POOL_FLAG_NON_PAGED,
sizeof(ZERO_POWER_ODD_INFO),
CDROM_TAG_ZERO_POWER_ODD);
if (zpoddInfo == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;
goto Cleanup;
}
//
// Check the system for the following prerequisites:
//
// 1. SATA: Device Attention line
// 2. SATA: Asynchronous Notification
// 3. ODD: LoChange / MediaRemoval
// 4. ACPI: Wake capable
//
// Only drawer and slot loading types have well defined behaviors in the spec, so only these two
// types are supported.
//
//
// Check for DA & AN
//
if ((DeviceExtension->PowerDescriptor == NULL) ||
(DeviceExtension->PowerDescriptor->DeviceAttentionSupported == FALSE) ||
(DeviceExtension->PowerDescriptor->AsynchronousNotificationSupported == FALSE))
{
status = STATUS_NOT_SUPPORTED;
TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_POWER,
"DeviceInitializeZPODD: ZPODD not enabled due to SATA features not present.\n"
));
goto Cleanup;
}
//
// Check for LoChange / MediaRemoval
//
removableMediumHeader = (PFEATURE_DATA_REMOVABLE_MEDIUM)
DeviceFindFeaturePage(DeviceExtension->DeviceAdditionalData.Mmc.CapabilitiesBuffer,
DeviceExtension->DeviceAdditionalData.Mmc.CapabilitiesBufferSize,
FeatureRemovableMedium);
if ((removableMediumHeader == NULL) ||
!((removableMediumHeader->LoadingMechanism == LOADING_MECHANISM_TRAY) && (removableMediumHeader->Load == 0) && // Drawer ...
(removableMediumHeader->DBML != FALSE)) && // requires LoChange/NotBusy
!((removableMediumHeader->LoadingMechanism == LOADING_MECHANISM_CADDY) && (removableMediumHeader->Load == 0) && // Slot ...
(DeviceExtension->MediaChangeDetectionInfo->Gesn.Supported != FALSE))) // requires MediaRemoval
{
status = STATUS_NOT_SUPPORTED;
TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_POWER,
"DeviceInitializeZPODD: ZPODD not enabled due to ODD features not present.\n"
));
goto Cleanup;
}
zpoddInfo->LoadingMechanism = removableMediumHeader->LoadingMechanism;
zpoddInfo->Load = removableMediumHeader->Load;
//
// Check for ACPI
//
status = DeviceQueryD3ColdInterface(DeviceExtension, &zpoddInfo->D3ColdInterface);
if (!NT_SUCCESS(status))
{
TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_POWER,
"DeviceInitializeZPODD: Query D3Cold support interface failed.\n"
));
goto Cleanup;
}
//
// If the platform supports Zero Power ODD, the following conditions must be met:
//
// 1. The deepest wakeable D-state for the device is D3Cold;
// 2. The platform supports D3Cold for the device.
//
d3ColdInterface = &zpoddInfo->D3ColdInterface;
status = d3ColdInterface->GetIdleWakeInfo(d3ColdInterface->Context,
PowerSystemWorking,
&deepestWakeableDstate);
if (!NT_SUCCESS(status))
{
goto Cleanup;
}
//
// DeviceExtension->PowerDescriptor->D3ColdSupported is retrieved from lower layer.
// It has more accurate supportive information than just uses d3ColdInterface->GetD3ColdCapability
//
if ((deepestWakeableDstate != DeviceWakeDepthD3cold) ||
(DeviceExtension->PowerDescriptor->D3ColdSupported == FALSE))
{
status = STATUS_NOT_SUPPORTED;
TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_POWER,
"DeviceInitializeZPODD: ZPODD not enabled due to ACPI support not present.\n"
));
goto Cleanup;
}
//
// The system meets all requirements. Go ahead and enable ZPODD.
//
//
// Register with the runtime power framework.
// Note that no un-registration is needed during tear-down.
// D3Cold will be enabled (success case of following call) or disabled by port driver during processing Enable Idle Power IOCTL.
//
status = DeviceSendEnableIdlePowerIoctl(DeviceExtension, TRUE, TRUE, DELAY_TIME_TO_ENTER_ZERO_POWER_IN_MS);
if (!NT_SUCCESS(status))
{
TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_POWER,
"DeviceInitializeZPODD: ZPODD not enabled due to runtime power framework.\n"
));
goto Cleanup;
}
TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_POWER,
"DeviceInitializeZPODD: ZPODD is enabled.\n"
));
DeviceExtension->ZeroPowerODDInfo = zpoddInfo;
//
// If device is not in home position, then we should take an active reference here
// to prevent it from being powered off.
//
inHomePosition = DeviceZPODDIsInHomePosition(DeviceExtension);
if (inHomePosition == FALSE)
{
TracePrint((TRACE_LEVEL_INFORMATION, TRACE_FLAG_POWER,
"DeviceInitializeZPODD: not ready to power off, device marked as active\n"));
DeviceMarkActive(DeviceExtension, TRUE, FALSE);
}
else
{
//
// cache get configuration response.
// failing is not critical, so we don't want to check for status here.
//
if (zpoddInfo->GetConfigurationBuffer == NULL)
{
tempStatus = DeviceGetConfigurationWithAlloc(DeviceExtension->Device,
&zpoddInfo->GetConfigurationBuffer,
&zpoddInfo->GetConfigurationBufferSize,
FeatureProfileList,
SCSI_GET_CONFIGURATION_REQUEST_TYPE_ALL);
UNREFERENCED_PARAMETER(tempStatus); // Avoid PREFAST warning.
}
}
Cleanup:
if (!NT_SUCCESS(status))
{
//
// We register always even in non-ZPODD case, per request from storport.
//
tempStatus = DeviceSendEnableIdlePowerIoctl(DeviceExtension, FALSE, FALSE, DELAY_TIME_TO_ENTER_ZERO_POWER_IN_MS);
if (NT_SUCCESS(tempStatus))
{
//
// Mark the device active; this reference will never be released unless the system enters a
// low power state.
//
DeviceMarkActive(DeviceExtension, TRUE, FALSE);
}
FREE_POOL(zpoddInfo);
}
//
// If Zero Power ODD is not supported, we should not block the device init sequence.
//
return STATUS_SUCCESS;
}
_IRQL_requires_max_(PASSIVE_LEVEL)
ULONG
DeviceGetZPODDEnabledFromRegistry()
/*++
Routine Description:
Get the ZeroPowerODDEnabled value from registry, which dictates if Zero Power ODD
should be enabled or not. If the value is not in registry, by default Zero
Power ODD is enabled.
Arguments:
None
Return Value:
ULONG
--*/
{
NTSTATUS status = STATUS_SUCCESS;
WDFKEY registryKey = NULL;
ULONG ZPODDEnabled = 0;
DECLARE_CONST_UNICODE_STRING(registryValueName, L"ZeroPowerODDEnabled");
PAGED_CODE();
//
// open the Parameters key under the service key.
//
status = WdfDriverOpenParametersRegistryKey(WdfGetDriver(),
KEY_READ,
WDF_NO_OBJECT_ATTRIBUTES,
®istryKey);
if (NT_SUCCESS(status))
{
status = WdfRegistryQueryULong(registryKey,
®istryValueName,
&ZPODDEnabled);
WdfRegistryClose(registryKey);
}
if (!NT_SUCCESS(status))
{
//
// By default, Zero Power ODD is enabled
//
ZPODDEnabled = 1;
}
return ZPODDEnabled;
}
_IRQL_requires_max_(PASSIVE_LEVEL)
NTSTATUS
DeviceQueryD3ColdInterface(
_In_ PCDROM_DEVICE_EXTENSION DeviceExtension,
_Out_ PD3COLD_SUPPORT_INTERFACE D3ColdInterface
)
/*++
Routine Description:
Queries ACPI for the D3Cold support interface.
Arguments:
DeviceExtension - the device extension
D3ColdInterface - output buffer receiving the interface
Return Value:
NTSTATUS
--*/
{
PIRP irp = NULL;
KEVENT event;
NTSTATUS status = STATUS_SUCCESS;
PDEVICE_OBJECT targetDevice = NULL;
IO_STATUS_BLOCK ioStatus = {0};
PIO_STACK_LOCATION irpStack = NULL;
PAGED_CODE();
RtlZeroMemory(D3ColdInterface, sizeof(D3COLD_SUPPORT_INTERFACE));
//
// Query D3COLD support interface synchronously
//
KeInitializeEvent(&event, NotificationEvent, FALSE);
targetDevice = IoGetAttachedDeviceReference(DeviceExtension->DeviceObject);
irp = IoBuildSynchronousFsdRequest(IRP_MJ_PNP,
targetDevice,
NULL,
0,
0,
&event,
&ioStatus);
if (irp == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;
goto Cleanup;
}
irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
irp->IoStatus.Information = 0;
irpStack = IoGetNextIrpStackLocation(irp);
irpStack->MinorFunction = IRP_MN_QUERY_INTERFACE;
irpStack->Parameters.QueryInterface.InterfaceType = (LPGUID) &GUID_D3COLD_SUPPORT_INTERFACE;
irpStack->Parameters.QueryInterface.Size = sizeof (D3COLD_SUPPORT_INTERFACE);
irpStack->Parameters.QueryInterface.Version = D3COLD_SUPPORT_INTERFACE_VERSION;
irpStack->Parameters.QueryInterface.Interface = (PINTERFACE) D3ColdInterface;
irpStack->Parameters.QueryInterface.InterfaceSpecificData = NULL;
status = IoCallDriver(targetDevice, irp);
if (status == STATUS_PENDING)
{
KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
status = ioStatus.Status;
}
if (!NT_SUCCESS(status))
{
goto Cleanup;
}
NT_ASSERT(D3ColdInterface->SetD3ColdSupport != NULL);
NT_ASSERT(D3ColdInterface->GetIdleWakeInfo != NULL);
NT_ASSERT(D3ColdInterface->GetD3ColdCapability != NULL);
Cleanup:
ObDereferenceObject(targetDevice);
return status;
}
_IRQL_requires_max_(PASSIVE_LEVEL)
NTSTATUS
DeviceSendEnableIdlePowerIoctl(
_In_ PCDROM_DEVICE_EXTENSION DeviceExtension,
_In_ BOOLEAN WakeCapable,
_In_ BOOLEAN Enable,
_In_ ULONG D3IdleTimeout
)
/*++
Routine Description:
Enables idle power support.
Arguments:
DeviceExtension - the device extension
WakeCapable - whether the device is wake capable
Enable - enable / disable idle power management
Return Value:
NTSTATUS
--*/
{
NTSTATUS status = STATUS_SUCCESS;
STORAGE_IDLE_POWER idlePower = {0};
IO_STATUS_BLOCK ioStatus = {0};
PIRP irp = NULL;
KEVENT event;
PAGED_CODE();
idlePower.Version = 1;
idlePower.Size = sizeof (STORAGE_IDLE_POWER);
idlePower.WakeCapableHint = WakeCapable;
idlePower.D3ColdSupported = Enable;
idlePower.D3IdleTimeout = D3IdleTimeout;
KeInitializeEvent(&event, NotificationEvent, FALSE);
irp = IoBuildDeviceIoControlRequest(IOCTL_STORAGE_ENABLE_IDLE_POWER,
DeviceExtension->LowerPdo,
&idlePower,
sizeof(STORAGE_IDLE_POWER),
NULL,
0,
FALSE,
&event,
&ioStatus);
if (irp == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;
}
else
{
//
// Send the synchronous request to port driver.
//
status = IoCallDriver(DeviceExtension->LowerPdo, irp);
if (status == STATUS_PENDING)
{
KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
status = ioStatus.Status;
}
}
TracePrint((TRACE_LEVEL_INFORMATION,
TRACE_FLAG_POWER,
"DeviceSendEnableIdlePowerIoctl: Port driver returned status (%x) for FDO (%p)\n"
"\tD3ColdSupported: %u\n"
"\tD3IdleTimeout: %u (ms)",
status,
DeviceExtension->DeviceObject,
Enable,
DELAY_TIME_TO_ENTER_ZERO_POWER_IN_MS));
return status;
}
_IRQL_requires_max_(APC_LEVEL)
VOID
DeviceReleaseZPODDResources(
_In_ PCDROM_DEVICE_EXTENSION DeviceExtension
)
/*++
Routine Description:
This routine will cleanup any resources allocated for ZPODD.
Arguments:
DeviceExtension - the device context
Return Value:
None.
--*/
{
PZERO_POWER_ODD_INFO zpoddInfo = DeviceExtension->ZeroPowerODDInfo;
PAGED_CODE()
if (zpoddInfo != NULL)
{
FREE_POOL(zpoddInfo->GetConfigurationBuffer);
FREE_POOL(zpoddInfo);
}
return;
}
NTSTATUS
DeviceZPODDGetPowerupReason(
_In_ PCDROM_DEVICE_EXTENSION DeviceExtension,
_Out_ PSTORAGE_IDLE_POWERUP_REASON PowerupReason
)
/*++
Routine Description:
This routine queries the port driver for what caused the power up.
Arguments:
DeviceExtension - device extension.
PowerupReason - what caused the power up.
Return Value:
NTSTATUS
--*/
{
NTSTATUS status = STATUS_SUCCESS;
PIRP irp = NULL;
IO_STATUS_BLOCK ioStatus = {0};
KEVENT event;
RtlZeroMemory(PowerupReason, sizeof (STORAGE_IDLE_POWERUP_REASON));
PowerupReason->Size = sizeof (STORAGE_IDLE_POWERUP_REASON);
PowerupReason->Version = STORAGE_IDLE_POWERUP_REASON_VERSION_V1;
//
// Setup a synchronous irp.
//
KeInitializeEvent(&event, NotificationEvent, FALSE);
irp = IoBuildDeviceIoControlRequest(IOCTL_STORAGE_GET_IDLE_POWERUP_REASON,
DeviceExtension->LowerPdo,
PowerupReason,
sizeof (STORAGE_IDLE_POWERUP_REASON),
PowerupReason,
sizeof (STORAGE_IDLE_POWERUP_REASON),
FALSE,
&event,
&ioStatus);
if (irp == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES;
}
else
{
//
// Send the synchronous request to port driver.
//
status = IoCallDriver(DeviceExtension->LowerPdo, irp);
if (status == STATUS_PENDING)
{
KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
status = ioStatus.Status;
}
}
return status;
}
_IRQL_requires_max_(PASSIVE_LEVEL)
BOOLEAN
DeviceZPODDIsInHomePosition(
_In_ PCDROM_DEVICE_EXTENSION DeviceExtension
)
/*++
Routine Description:
Checks to see if the device is ready to be powered off.
Requirements are: 1. tray closed 2. no media present.
Arguments:
DeviceExtension - device extension.
Return Value:
BOOLEAN
--*/
{
NTSTATUS status = STATUS_SUCCESS;
PZERO_POWER_ODD_INFO zpoddInfo = DeviceExtension->ZeroPowerODDInfo;
SCSI_REQUEST_BLOCK srb = {0};
PCDB cdb = (PCDB) srb.Cdb;
BOOLEAN inHomePosition = FALSE;
PAGED_CODE();
if (zpoddInfo != NULL)
{
//
// Clear sense data.
//
zpoddInfo->SenseKey = 0;
zpoddInfo->AdditionalSenseCode = 0;
zpoddInfo->AdditionalSenseCodeQualifier = 0;
//
// Send a Test Unit Ready to check media & tray status.
//
RtlZeroMemory(&srb, sizeof(SCSI_REQUEST_BLOCK));
srb.CdbLength = 6;
cdb->CDB6GENERIC.OperationCode = SCSIOP_TEST_UNIT_READY;
srb.TimeOutValue = CDROM_TEST_UNIT_READY_TIMEOUT;
status = DeviceSendSrbSynchronously(DeviceExtension->Device,
&srb,
NULL,
0,
FALSE,
NULL);
//
// At this time, sense data, if available, is already copied into zpoddInfo.
//
// We don't check for status because we expect it to fail in case there is no media in device.
//
// Should enter Zero Power state if:
//
// Drawer: 02/3A/01
// Slot: 02/3A/xx
//
if (((zpoddInfo->LoadingMechanism == LOADING_MECHANISM_TRAY) && (zpoddInfo->Load == 0) && // Drawer
(zpoddInfo->SenseKey == SCSI_SENSE_NOT_READY) &&
(zpoddInfo->AdditionalSenseCode == SCSI_ADSENSE_NO_MEDIA_IN_DEVICE) &&
(zpoddInfo->AdditionalSenseCodeQualifier == 0x01)) ||
((zpoddInfo->LoadingMechanism == LOADING_MECHANISM_CADDY) && (zpoddInfo->Load == 0) && // Slot
(zpoddInfo->SenseKey == SCSI_SENSE_NOT_READY) &&
(zpoddInfo->AdditionalSenseCode == SCSI_ADSENSE_NO_MEDIA_IN_DEVICE)))
{
inHomePosition = TRUE;
}
}
return inHomePosition;
}
_IRQL_requires_max_(PASSIVE_LEVEL)
VOID
DeviceMarkActive(
_In_ PCDROM_DEVICE_EXTENSION DeviceExtension,
_In_ BOOLEAN IsActive,
_In_ BOOLEAN SetIdleTimeout
)
/*++
Routine Description:
This routine will mark the device as active / idle.
Arguments:
DeviceExtension - the device context
IsActive - if the device should be marked as active
Return Value:
None.
--*/
{
NTSTATUS status = STATUS_SUCCESS;
PZERO_POWER_ODD_INFO zpoddInfo = DeviceExtension->ZeroPowerODDInfo;
PAGED_CODE()
if (DeviceExtension->IsActive != IsActive)
{
if ((IsActive == FALSE) && (zpoddInfo != NULL))
{
// cache get configuration response.
// failing is not critical, so we don't want to check for status here.
if (zpoddInfo->GetConfigurationBuffer == NULL)
{
(VOID)DeviceGetConfigurationWithAlloc(DeviceExtension->Device,
&zpoddInfo->GetConfigurationBuffer,
&zpoddInfo->GetConfigurationBufferSize,
FeatureProfileList,
SCSI_GET_CONFIGURATION_REQUEST_TYPE_ALL);
}
}
if (SetIdleTimeout)
{
status = DeviceSendEnableIdlePowerIoctl(DeviceExtension,
FALSE,
FALSE,
IsActive ? DELAY_TIME_TO_ENTER_ZERO_POWER_IN_MS : DELAY_TIME_TO_ENTER_AOAC_IDLE_POWER_IN_MS);
}
if (NT_SUCCESS(status))
{
DeviceSendIoctlAsynchronously(DeviceExtension,
IsActive ? IOCTL_STORAGE_POWER_ACTIVE : IOCTL_STORAGE_POWER_IDLE,
DeviceExtension->LowerPdo);
}
DeviceExtension->IsActive = IsActive;
}
}
#pragma warning(pop) // un-sets any local warning changes
|