ReactOS  0.4.14-dev-297-g23e575c
wmi.c
Go to the documentation of this file.
1 #include "miniport.h"
2 #include "BusLogic958.h" // includes scsi.h
3 #include "wmistr.h" // WMI definitions
4 
5 #include "BT958dt.h"
6 
7 #define BT958Wmi_MofResourceName L"MofResource"
8 
9 #define BT958_SETUP_GUID_INDEX 0
10 
12 
13 UCHAR
15 (
16  IN PHW_DEVICE_EXTENSION HwDeviceExtension,
18 );
19 
20 BOOLEAN
22 (
24  IN PSCSIWMI_REQUEST_CONTEXT RequestContext,
28  IN OUT PULONG InstanceLengthArray,
31 );
32 
33 UCHAR
35 (
37  IN PSCSIWMI_REQUEST_CONTEXT RequestContext,
39 );
40 
42 {
44  1,
45  0
46  },
47 };
48 
49 #define BT958GuidCount (sizeof(BT958GuidList) / sizeof(SCSIWMIGUIDREGINFO))
50 
51 
53  IN PHW_DEVICE_EXTENSION HwDeviceExtension
54  )
55 {
57 
58  WmiLibContext = &HwDeviceExtension->WmiLibContext;
59 
60  WmiLibContext->GuidList = BT958GuidList;
61  WmiLibContext->GuidCount = BT958GuidCount;
62  WmiLibContext->QueryWmiRegInfo = BT958QueryWmiRegInfo;
63  WmiLibContext->QueryWmiDataBlock = BT958QueryWmiDataBlock;
64  WmiLibContext->SetWmiDataItem = NULL;
65  WmiLibContext->SetWmiDataBlock = NULL;
66  WmiLibContext->WmiFunctionControl = NULL;
67  WmiLibContext->ExecuteWmiMethod = NULL;
68 }
69 
70 
71 
72 BOOLEAN
74  IN PHW_DEVICE_EXTENSION HwDeviceExtension,
76  )
77 /*++
78 
79 Routine Description:
80 
81  Process an SRB_FUNCTION_WMI request packet.
82 
83  This routine is called from the SCSI port driver synchronized with the
84  kernel via BT958StartIo. On completion of WMI processing, the SCSI
85  port driver is notified that the adapter can take another request, if
86  any are available.
87 
88 Arguments:
89 
90  HwDeviceExtension - HBA miniport driver's adapter data storage.
91 
92  Srb - IO request packet.
93 
94 Return Value:
95 
96  Value to return to BT958StartIo caller. Always TRUE.
97 
98 --*/
99 {
100  UCHAR status;
101  SCSIWMI_REQUEST_CONTEXT requestContext;
102  ULONG retSize;
103  BOOLEAN pending;
104 
105  // Validate our assumptions.
106  ASSERT(Srb->Function == SRB_FUNCTION_WMI);
107  ASSERT(Srb->Length == sizeof(SCSI_WMI_REQUEST_BLOCK));
108  ASSERT(Srb->DataTransferLength >= sizeof(ULONG));
109  ASSERT(Srb->DataBuffer);
110 
111  // Check if the WMI SRB is targeted for the adapter or one of the disks
112  if (!(Srb->WMIFlags & SRB_WMI_FLAGS_ADAPTER_REQUEST))
113  {
114 
115  // This is targeted to one of the disks, since there are no per disk
116  // wmi information we return an error. Note that if there was per
117  // disk information, then you'd likely have a differen WmiLibContext
118  // and a different set of guids.
119  Srb->DataTransferLength = 0;
120  Srb->SrbStatus = SRB_STATUS_SUCCESS;
121 
122  }
123  else
124  {
125  // Process the incoming WMI request.
126  pending = ScsiPortWmiDispatchFunction(&HwDeviceExtension->WmiLibContext,
127  Srb->WMISubFunction,
128  HwDeviceExtension,
129  &requestContext,
130  Srb->DataPath,
131  Srb->DataTransferLength,
132  Srb->DataBuffer);
133 
134  // We assume that the wmi request will never pend so that we can
135  // allocate the requestContext from stack. If the WMI request could
136  // ever pend then we'd need to allocate the request context from
137  // the SRB extension.
138  //
139  ASSERT(! pending);
140 
141  retSize = ScsiPortWmiGetReturnSize(&requestContext);
142  status = ScsiPortWmiGetReturnStatus(&requestContext);
143 
144  // We can do this since we assume it is done synchronously
145  Srb->DataTransferLength = retSize;
146 
147  //
148  // Adapter ready for next request.
149  //
150 
151  Srb->SrbStatus = status;
152  }
153 
154  ScsiPortNotification(RequestComplete, HwDeviceExtension, Srb);
155  ScsiPortNotification(NextRequest, HwDeviceExtension, NULL);
156 
157  return TRUE;
158 }
159 
160 
161 
162 BOOLEAN
164  IN PVOID Context,
165  IN PSCSIWMI_REQUEST_CONTEXT RequestContext,
169  IN OUT PULONG InstanceLengthArray,
172  )
173 /*++
174 
175 Routine Description:
176 
177  This routine is a callback into the miniport to query for the contents of
178  one or more instances of a data block. This callback may be called with
179  an output buffer that is too small to return all of the data queried.
180  In this case the callback is responsible to report the correct output
181  buffer size needed.
182 
183  If the request can be completed immediately without pending,
184  ScsiPortWmiPostProcess should be called from within this callback and
185  FALSE returned.
186 
187  If the request cannot be completed within this callback then TRUE should
188  be returned. Once the pending operations are finished the miniport should
189  call ScsiPortWmiPostProcess and then complete the srb.
190 
191 Arguments:
192 
193  DeviceContext is a caller specified context value originally passed to
194  ScsiPortWmiDispatchFunction.
195 
196  RequestContext is a context associated with the srb being processed.
197 
198  GuidIndex is the index into the list of guids provided when the
199  miniport registered
200 
201  InstanceIndex is the index that denotes first instance of the data block
202  is being queried.
203 
204  InstanceCount is the number of instances expected to be returned for
205  the data block.
206 
207  InstanceLengthArray is a pointer to an array of ULONG that returns the
208  lengths of each instance of the data block. This may be NULL when
209  there is not enough space in the output buffer to fufill the request.
210  In this case the miniport should call ScsiPortWmiPostProcess with
211  a status of SRB_STATUS_DATA_OVERRUN and the size of the output buffer
212  needed to fufill the request.
213 
214  BufferAvail on entry has the maximum size available to write the data
215  blocks in the output buffer. If the output buffer is not large enough
216  to return all of the data blocks then the miniport should call
217  ScsiPortWmiPostProcess with a status of SRB_STATUS_DATA_OVERRUN
218  and the size of the output buffer needed to fufill the request.
219 
220  Buffer on return is filled with the returned data blocks. Note that each
221  instance of the data block must be aligned on a 8 byte boundry. This
222  may be NULL when there is not enough space in the output buffer to
223  fufill the request. In this case the miniport should call
224  ScsiPortWmiPostProcess with a status of SRB_STATUS_DATA_OVERRUN and
225  the size of the output buffer needed to fufill the request.
226 
227 
228 Return Value:
229 
230  TRUE if request is pending else FALSE
231 
232 --*/
233 {
235  ULONG size = 0;
236  UCHAR status;
237 
238  //
239  // Only ever registers 1 instance per guid
240  ASSERT((InstanceIndex == 0) &&
241  (InstanceCount == 1));
242 
243  switch (GuidIndex)
244  {
246  {
247  size = sizeof(BT958ExtendedSetupInfo)-1;
248  if (OutBufferSize < size)
249  {
250  //
251  // The buffer passed to return the data is too small
252  //
254  break;
255  }
256 
257  if ( !BT958ReadExtendedSetupInfo(HwDeviceExtension,
258  Buffer))
259  {
260  ASSERT(FALSE);
261  size = 0;
263  }
264  else
265  {
266  *InstanceLengthArray = size;
268  }
269  break;
270  }
271 
272  default:
273  {
275  }
276  }
277 
278  ScsiPortWmiPostProcess( RequestContext,
279  status,
280  size);
281 
282  return status;
283 }
284 
285 UCHAR
287  IN PVOID Context,
288  IN PSCSIWMI_REQUEST_CONTEXT RequestContext,
290  )
291 /*++
292 
293 Routine Description:
294 
295  This routine is a callback into the driver to retrieve information about
296  the guids being registered.
297 
298  Implementations of this routine may be in paged memory
299 
300 Arguments:
301 
302  DeviceObject is the device whose registration information is needed
303 
304  *RegFlags returns with a set of flags that describe all of the guids being
305  registered for this device. If the device wants enable and disable
306  collection callbacks before receiving queries for the registered
307  guids then it should return the WMIREG_FLAG_EXPENSIVE flag. Also the
308  returned flags may specify WMIREG_FLAG_INSTANCE_PDO in which case
309  the instance name is determined from the PDO associated with the
310  device object. Note that the PDO must have an associated devnode. If
311  WMIREG_FLAG_INSTANCE_PDO is not set then Name must return a unique
312  name for the device. These flags are ORed into the flags specified
313  by the GUIDREGINFO for each guid.
314 
315  InstanceName returns with the instance name for the guids if
316  WMIREG_FLAG_INSTANCE_PDO is not set in the returned *RegFlags. The
317  caller will call ExFreePool with the buffer returned.
318 
319  *RegistryPath returns with the registry path of the driver. This is
320  required
321 
322  *MofResourceName returns with the name of the MOF resource attached to
323  the binary file. If the driver does not have a mof resource attached
324  then this can be returned as NULL.
325 
326  *Pdo returns with the device object for the PDO associated with this
327  device if the WMIREG_FLAG_INSTANCE_PDO flag is returned in
328  *RegFlags.
329 
330 Return Value:
331 
332  status
333 
334 --*/
335 {
337  return SRB_STATUS_SUCCESS;
338 }
339 
340 
341 UCHAR
343  IN PHW_DEVICE_EXTENSION HwDeviceExtension,
345  )
346 /*++
347 
348 Routine Description:
349 
350  Read the adapter setup information into the supplied buffer. The buffer
351  must be RM_CFG_MAX_SIZE (255) bytes large.
352 
353 Arguments:
354 
355  HwDeviceExtension - HBA miniport driver's adapter data storage.
356 
357  Buffer - Buffer to hold adapter's setup information structure [manual 5-10].
358 
359 Return Value:
360 
361  TRUE on success, FALSE on failure.
362 
363 --*/
364 {
365  UCHAR numberOfBytes = sizeof(BT958ExtendedSetupInfo)-1;
366 
367  PHW_DEVICE_EXTENSION deviceExtension = HwDeviceExtension;
368  BusLogic_HostAdapter_T *HostAdapter = &(deviceExtension->hcs);
369  BusLogic_ExtendedSetupInformation_T ExtendedSetupInformation;
370  BusLogic_RequestedReplyLength_T RequestedReplyLength = sizeof(ExtendedSetupInformation);
371  BOOLEAN Result = TRUE;
372 
373  BusLogic_WmiExtendedSetupInformation_T WmiExtendedSetupInfo;
374  PUCHAR SourceBuf = (PUCHAR) &WmiExtendedSetupInfo;
375 
376 
377  //
378  // Issue the Inquire Extended Setup Information command. Only genuine
379  // BusLogic Host Adapters and TRUE clones support this command. Adaptec 1542C
380  // series Host Adapters that respond to the Geometry Register I/O port will
381  // fail this command.
382  RequestedReplyLength = sizeof(ExtendedSetupInformation);
383  if (BusLogic_Command(HostAdapter,
385  &RequestedReplyLength,
386  sizeof(RequestedReplyLength),
387  &ExtendedSetupInformation,
388  sizeof(ExtendedSetupInformation))
389  != sizeof(ExtendedSetupInformation))
390  {
391  Result = FALSE;
392  }
393 
394  WmiExtendedSetupInfo.BusType = ExtendedSetupInformation.BusType;
395  WmiExtendedSetupInfo.BIOS_Address = ExtendedSetupInformation.BIOS_Address;
396  WmiExtendedSetupInfo.ScatterGatherLimit = ExtendedSetupInformation.ScatterGatherLimit;
397  WmiExtendedSetupInfo.MailboxCount = ExtendedSetupInformation.MailboxCount;
398  WmiExtendedSetupInfo.BaseMailboxAddress = ExtendedSetupInformation.BaseMailboxAddress;
399  WmiExtendedSetupInfo.FastOnEISA = ExtendedSetupInformation.Misc.FastOnEISA;
400  WmiExtendedSetupInfo.LevelSensitiveInterrupt = ExtendedSetupInformation.Misc.LevelSensitiveInterrupt;
401  WmiExtendedSetupInfo.FirmwareRevision[0] = ExtendedSetupInformation.FirmwareRevision[0];
402  WmiExtendedSetupInfo.FirmwareRevision[1] = ExtendedSetupInformation.FirmwareRevision[1];
403  WmiExtendedSetupInfo.FirmwareRevision[2] = ExtendedSetupInformation.FirmwareRevision[2];
404  WmiExtendedSetupInfo.HostWideSCSI = ExtendedSetupInformation.HostWideSCSI;
405  WmiExtendedSetupInfo.HostDifferentialSCSI= ExtendedSetupInformation.HostDifferentialSCSI;
406  WmiExtendedSetupInfo.HostSupportsSCAM = ExtendedSetupInformation.HostSupportsSCAM;
407  WmiExtendedSetupInfo.HostUltraSCSI = ExtendedSetupInformation.HostUltraSCSI;
408  WmiExtendedSetupInfo.HostSmartTermination= ExtendedSetupInformation.HostSmartTermination;
409 
410  for (; numberOfBytes; numberOfBytes--)
411  {
412  *Buffer++ = *SourceBuf++;
413  }
414  return TRUE;
415 }
416 
BusLogic_BusAddress_T BaseMailboxAddress
Definition: BusLogic958.h:801
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
BOOLEAN BT958WmiSrb(IN PHW_DEVICE_EXTENSION HwDeviceExtension, IN OUT PSCSI_WMI_REQUEST_BLOCK Srb)
Definition: wmi.c:73
_In_ PVOID WmiLibContext
Definition: batclass.h:377
#define ScsiPortWmiGetReturnStatus(RequestContext)
Definition: scsiwmi.h:189
unsigned char * PUCHAR
Definition: retypes.h:3
_In_ LPGUID _In_ ULONG InstanceIndex
Definition: classpnp.h:1057
_In_ PIRP _In_ ULONG _In_ ULONG _In_ ULONG _In_ ULONG OutBufferSize
Definition: classpnp.h:429
#define BT958Wmi_MofResourceName
Definition: wmi.c:7
SCSIWMIGUIDREGINFO BT958GuidList[]
Definition: wmi.c:41
uint16_t * PWCHAR
Definition: typedefs.h:54
SCSIPORTAPI VOID NTAPI ScsiPortWmiPostProcess(_Inout_ PSCSIWMI_REQUEST_CONTEXT RequestContext, _In_ UCHAR SrbStatus, _In_ ULONG BufferUsed)
#define SRB_STATUS_ERROR
Definition: srb.h:336
#define ScsiPortWmiGetReturnSize(RequestContext)
Definition: scsiwmi.h:182
_Must_inspect_result_ SCSIPORTAPI BOOLEAN NTAPI ScsiPortWmiDispatchFunction(_In_ PSCSI_WMILIB_CONTEXT WmiLibInfo, _In_ UCHAR MinorFunction, _In_ PVOID DeviceContext, _In_ PSCSIWMI_REQUEST_CONTEXT RequestContext, _In_ PVOID DataPath, _In_ ULONG BufferSize, _In_ PVOID Buffer)
UCHAR BT958ReadExtendedSetupInfo(IN PHW_DEVICE_EXTENSION HwDeviceExtension, OUT PUCHAR Buffer)
Definition: wmi.c:342
BusLogic_BusAddress_T BaseMailboxAddress
Definition: BusLogic958.h:344
int BusLogic_Command(BusLogic_HostAdapter_T *HostAdapter, BusLogic_OperationCode_T OperationCode, void *ParameterData, int ParameterLength, void *ReplyData, int ReplyLength)
Definition: BusLogic958.c:606
unsigned char BOOLEAN
_Out_ ULONG _Out_ PUNICODE_STRING _Out_ PUNICODE_STRING MofResourceName
Definition: classpnp.h:386
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
_In_ PIRP _In_ ULONG GuidIndex
Definition: classpnp.h:401
Definition: bufpool.h:45
#define SRB_FUNCTION_WMI
Definition: srb.h:323
GUID BT958WmiExtendedSetupInfoGuid
Definition: wmi.c:11
BusLogic_HostAdapter_T hcs
Definition: BusLogic958.h:757
GLsizeiptr size
Definition: glext.h:5919
BOOLEAN BT958QueryWmiDataBlock(IN PVOID Context, IN PSCSIWMI_REQUEST_CONTEXT RequestContext, IN ULONG GuidIndex, IN ULONG InstanceIndex, IN ULONG InstanceCount, IN OUT PULONG InstanceLengthArray, IN ULONG OutBufferSize, OUT PUCHAR Buffer)
Definition: wmi.c:163
#define SRB_STATUS_DATA_OVERRUN
Definition: srb.h:349
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
unsigned char UCHAR
Definition: xmlstorage.h:181
#define BT958GuidCount
Definition: wmi.c:49
#define SRB_WMI_FLAGS_ADAPTER_REQUEST
Definition: srb.h:419
VOID __cdecl ScsiPortNotification(IN SCSI_NOTIFICATION_TYPE NotificationType, IN PVOID HwDeviceExtension, IN ...)
Definition: scsiport.c:1308
struct _HW_DEVICE_EXTENSION * PHW_DEVICE_EXTENSION
void BT958WmiInitialize(IN PHW_DEVICE_EXTENSION HwDeviceExtension)
Definition: wmi.c:52
#define BT958_SETUP_GUID_INDEX
Definition: wmi.c:9
struct BusLogic_ExtendedSetupInformation::@1277 Misc
unsigned int * PULONG
Definition: retypes.h:1
#define OUT
Definition: typedefs.h:39
unsigned int ULONG
Definition: retypes.h:1
_In_ ULONG InstanceCount
Definition: iofuncs.h:1319
#define SRB_STATUS_SUCCESS
Definition: srb.h:333
UCHAR BusLogic_RequestedReplyLength_T
Definition: BusLogic958.h:169
#define BT958Wmi_ExtendedSetupInfo_Guid
Definition: BT958dt.h:27
struct _BT958ExtendedSetupInfo BT958ExtendedSetupInfo
IN PSCSI_REQUEST_BLOCK Srb
Definition: class2.h:49
static SERVICE_STATUS status
Definition: service.c:31
UCHAR BT958QueryWmiRegInfo(IN PVOID Context, IN PSCSIWMI_REQUEST_CONTEXT RequestContext, OUT PWCHAR *MofResourceName)
Definition: wmi.c:286
Definition: ps.c:97