]> git.proxmox.com Git - mirror_edk2.git/blame - InOsEmuPkg/EmuBlockIoDxe/EmuBlockIo.c
Add BlockIO support to the emulator, still needs testing. Also update Emulator start...
[mirror_edk2.git] / InOsEmuPkg / EmuBlockIoDxe / EmuBlockIo.c
CommitLineData
d59326d3 1/**@file\r
2\r
3Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>\r
4This program and the accompanying materials \r
5are licensed and made available under the terms and conditions of the BSD License \r
6which accompanies this distribution. The full text of the license may be found at \r
7http://opensource.org/licenses/bsd-license.php \r
8 \r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
11bbe\r
12**/\r
13\r
14#include "EmuBlockIo.h"\r
15\r
16\r
17/**\r
18 Reset the block device hardware.\r
19\r
20 @param[in] This Indicates a pointer to the calling context.\r
21 @param[in] ExtendedVerification Indicates that the driver may perform a more\r
22 exhausive verfication operation of the device\r
23 during reset.\r
24\r
25 @retval EFI_SUCCESS The device was reset.\r
26 @retval EFI_DEVICE_ERROR The device is not functioning properly and could\r
27 not be reset.\r
28\r
29**/\r
30EFI_STATUS\r
31EFIAPI\r
32EmuBlockIo2Reset (\r
33 IN EFI_BLOCK_IO2_PROTOCOL *This,\r
34 IN BOOLEAN ExtendedVerification\r
35 )\r
36{\r
37 EFI_STATUS Status;\r
38 EMU_BLOCK_IO_PRIVATE *Private;\r
39 EFI_TPL OldTpl;\r
40\r
41 Private = EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This);\r
42\r
43 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
44\r
45 Status = Private->Io->Reset (Private->Io, ExtendedVerification);\r
46\r
47 gBS->RestoreTPL (OldTpl);\r
48 return Status;\r
49}\r
50\r
51/**\r
52 Read BufferSize bytes from Lba into Buffer.\r
53 \r
54 This function reads the requested number of blocks from the device. All the\r
55 blocks are read, or an error is returned.\r
56 If EFI_DEVICE_ERROR, EFI_NO_MEDIA,_or EFI_MEDIA_CHANGED is returned and\r
57 non-blocking I/O is being used, the Event associated with this request will\r
58 not be signaled.\r
59\r
60 @param[in] This Indicates a pointer to the calling context.\r
61 @param[in] MediaId Id of the media, changes every time the media is \r
62 replaced.\r
63 @param[in] Lba The starting Logical Block Address to read from.\r
64 @param[in, out] Token A pointer to the token associated with the transaction.\r
65 @param[in] BufferSize Size of Buffer, must be a multiple of device block size. \r
66 @param[out] Buffer A pointer to the destination buffer for the data. The \r
67 caller is responsible for either having implicit or \r
68 explicit ownership of the buffer.\r
69\r
70 @retval EFI_SUCCESS The read request was queued if Token->Event is\r
71 not NULL.The data was read correctly from the\r
72 device if the Token->Event is NULL.\r
73 @retval EFI_DEVICE_ERROR The device reported an error while performing\r
74 the read.\r
75 @retval EFI_NO_MEDIA There is no media in the device.\r
76 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.\r
77 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the\r
78 intrinsic block size of the device.\r
79 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid, \r
80 or the buffer is not on proper alignment.\r
81 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack\r
82 of resources.\r
83**/\r
84EFI_STATUS\r
85EFIAPI\r
86EmuBlockIo2ReadBlocksEx (\r
87 IN EFI_BLOCK_IO2_PROTOCOL *This,\r
88 IN UINT32 MediaId,\r
89 IN EFI_LBA LBA,\r
90 IN OUT EFI_BLOCK_IO2_TOKEN *Token,\r
91 IN UINTN BufferSize,\r
92 OUT VOID *Buffer\r
93 )\r
94{\r
95 EFI_STATUS Status;\r
96 EMU_BLOCK_IO_PRIVATE *Private;\r
97 EFI_TPL OldTpl;\r
98\r
99 Private = EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This);\r
100\r
101 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
102\r
103 Status = Private->Io->ReadBlocks (Private->Io, MediaId, LBA, Token, BufferSize, Buffer);\r
104\r
105 gBS->RestoreTPL (OldTpl);\r
106 return Status;\r
107}\r
108\r
109\r
110/**\r
111 Write BufferSize bytes from Lba into Buffer.\r
112\r
113 This function writes the requested number of blocks to the device. All blocks\r
114 are written, or an error is returned.If EFI_DEVICE_ERROR, EFI_NO_MEDIA,\r
115 EFI_WRITE_PROTECTED or EFI_MEDIA_CHANGED is returned and non-blocking I/O is\r
116 being used, the Event associated with this request will not be signaled.\r
117\r
118 @param[in] This Indicates a pointer to the calling context.\r
119 @param[in] MediaId The media ID that the write request is for.\r
120 @param[in] Lba The starting logical block address to be written. The\r
121 caller is responsible for writing to only legitimate\r
122 locations.\r
123 @param[in, out] Token A pointer to the token associated with the transaction.\r
124 @param[in] BufferSize Size of Buffer, must be a multiple of device block size.\r
125 @param[in] Buffer A pointer to the source buffer for the data.\r
126\r
127 @retval EFI_SUCCESS The write request was queued if Event is not NULL.\r
128 The data was written correctly to the device if\r
129 the Event is NULL.\r
130 @retval EFI_WRITE_PROTECTED The device can not be written to.\r
131 @retval EFI_NO_MEDIA There is no media in the device.\r
132 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.\r
133 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.\r
134 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.\r
135 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid, \r
136 or the buffer is not on proper alignment.\r
137 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack\r
138 of resources.\r
139\r
140**/\r
141EFI_STATUS\r
142EFIAPI \r
143EmuBlockIo2WriteBlocksEx (\r
144 IN EFI_BLOCK_IO2_PROTOCOL *This,\r
145 IN UINT32 MediaId,\r
146 IN EFI_LBA LBA,\r
147 IN OUT EFI_BLOCK_IO2_TOKEN *Token,\r
148 IN UINTN BufferSize,\r
149 IN VOID *Buffer\r
150 )\r
151{\r
152 EFI_STATUS Status;\r
153 EMU_BLOCK_IO_PRIVATE *Private;\r
154 EFI_TPL OldTpl;\r
155\r
156 Private = EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This);\r
157\r
158 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
159\r
160 Status = Private->Io->WriteBlocks (Private->Io, MediaId, LBA, Token, BufferSize, Buffer);\r
161\r
162 gBS->RestoreTPL (OldTpl);\r
163 return Status;\r
164}\r
165\r
166\r
167\r
168/**\r
169 Flush the Block Device.\r
170 \r
171 If EFI_DEVICE_ERROR, EFI_NO_MEDIA,_EFI_WRITE_PROTECTED or EFI_MEDIA_CHANGED\r
172 is returned and non-blocking I/O is being used, the Event associated with\r
173 this request will not be signaled. \r
174\r
175 @param[in] This Indicates a pointer to the calling context.\r
176 @param[in,out] Token A pointer to the token associated with the transaction\r
177\r
178 @retval EFI_SUCCESS The flush request was queued if Event is not NULL.\r
179 All outstanding data was written correctly to the\r
180 device if the Event is NULL.\r
181 @retval EFI_DEVICE_ERROR The device reported an error while writting back\r
182 the data.\r
183 @retval EFI_WRITE_PROTECTED The device cannot be written to.\r
184 @retval EFI_NO_MEDIA There is no media in the device.\r
185 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.\r
186 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack\r
187 of resources.\r
188\r
189**/\r
190EFI_STATUS\r
191EFIAPI\r
192EmuBlockIo2Flush (\r
193 IN EFI_BLOCK_IO2_PROTOCOL *This,\r
194 IN OUT EFI_BLOCK_IO2_TOKEN *Token\r
195 )\r
196{\r
197 EFI_STATUS Status;\r
198 EMU_BLOCK_IO_PRIVATE *Private;\r
199 EFI_TPL OldTpl;\r
200\r
201 Private = EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This);\r
202\r
203 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
204\r
205 Status = Private->Io->FlushBlocks (Private->Io, Token);\r
206\r
207 gBS->RestoreTPL (OldTpl);\r
208 return Status;\r
209}\r
210\r
211\r
212\r
213/**\r
214 Reset the Block Device.\r
215\r
216 @param This Indicates a pointer to the calling context.\r
217 @param ExtendedVerification Driver may perform diagnostics on reset.\r
218\r
219 @retval EFI_SUCCESS The device was reset.\r
220 @retval EFI_DEVICE_ERROR The device is not functioning properly and could\r
221 not be reset.\r
222\r
223**/\r
224EFI_STATUS\r
225EFIAPI\r
226EmuBlockIoReset (\r
227 IN EFI_BLOCK_IO_PROTOCOL *This,\r
228 IN BOOLEAN ExtendedVerification\r
229 )\r
230{\r
231 EFI_STATUS Status;\r
232 EMU_BLOCK_IO_PRIVATE *Private;\r
233 EFI_TPL OldTpl;\r
234\r
235 Private = EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This);\r
236\r
237 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
238\r
239 Status = Private->Io->Reset (Private->Io, ExtendedVerification);\r
240\r
241 gBS->RestoreTPL (OldTpl);\r
242 return Status;\r
243}\r
244\r
245\r
246/**\r
247 Read BufferSize bytes from Lba into Buffer.\r
248\r
249 @param This Indicates a pointer to the calling context.\r
250 @param MediaId Id of the media, changes every time the media is replaced.\r
251 @param Lba The starting Logical Block Address to read from\r
252 @param BufferSize Size of Buffer, must be a multiple of device block size.\r
253 @param Buffer A pointer to the destination buffer for the data. The caller is\r
254 responsible for either having implicit or explicit ownership of the buffer.\r
255\r
256 @retval EFI_SUCCESS The data was read correctly from the device.\r
257 @retval EFI_DEVICE_ERROR The device reported an error while performing the read.\r
258 @retval EFI_NO_MEDIA There is no media in the device.\r
259 @retval EFI_MEDIA_CHANGED The MediaId does not matched the current device.\r
260 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.\r
261 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid, \r
262 or the buffer is not on proper alignment.\r
263\r
264**/\r
265EFI_STATUS\r
266EFIAPI\r
267EmuBlockIoReadBlocks\r
268(\r
269 IN EFI_BLOCK_IO_PROTOCOL *This,\r
270 IN UINT32 MediaId,\r
271 IN EFI_LBA Lba,\r
272 IN UINTN BufferSize,\r
273 OUT VOID *Buffer\r
274 )\r
275{\r
276 EFI_STATUS Status;\r
277 EMU_BLOCK_IO_PRIVATE *Private;\r
278 EFI_TPL OldTpl;\r
279 EFI_BLOCK_IO2_TOKEN Token;\r
280\r
281 Private = EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This);\r
282\r
283 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
284\r
285 Token.Event = NULL;\r
286 Status = Private->Io->ReadBlocks (Private->Io, MediaId, Lba, &Token, BufferSize, Buffer);\r
287\r
288 gBS->RestoreTPL (OldTpl);\r
289 return Status;\r
290}\r
291\r
292\r
293/**\r
294 Write BufferSize bytes from Lba into Buffer.\r
295\r
296 @param This Indicates a pointer to the calling context.\r
297 @param MediaId The media ID that the write request is for.\r
298 @param Lba The starting logical block address to be written. The caller is\r
299 responsible for writing to only legitimate locations.\r
300 @param BufferSize Size of Buffer, must be a multiple of device block size.\r
301 @param Buffer A pointer to the source buffer for the data.\r
302\r
303 @retval EFI_SUCCESS The data was written correctly to the device.\r
304 @retval EFI_WRITE_PROTECTED The device can not be written to.\r
305 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.\r
306 @retval EFI_NO_MEDIA There is no media in the device.\r
307 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.\r
308 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.\r
309 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid, \r
310 or the buffer is not on proper alignment.\r
311\r
312**/\r
313EFI_STATUS\r
314EFIAPI\r
315EmuBlockIoWriteBlocks (\r
316 IN EFI_BLOCK_IO_PROTOCOL *This,\r
317 IN UINT32 MediaId,\r
318 IN EFI_LBA Lba,\r
319 IN UINTN BufferSize,\r
320 IN VOID *Buffer\r
321 )\r
322{\r
323 EFI_STATUS Status;\r
324 EMU_BLOCK_IO_PRIVATE *Private;\r
325 EFI_TPL OldTpl;\r
326 EFI_BLOCK_IO2_TOKEN Token;\r
327\r
328 Private = EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This);\r
329\r
330 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
331\r
332 Token.Event = NULL;\r
333 Status = Private->Io->WriteBlocks (Private->Io, MediaId, Lba, &Token, BufferSize, Buffer);\r
334\r
335 gBS->RestoreTPL (OldTpl);\r
336 return Status;\r
337}\r
338\r
339/**\r
340 Flush the Block Device.\r
341\r
342 @param This Indicates a pointer to the calling context.\r
343\r
344 @retval EFI_SUCCESS All outstanding data was written to the device\r
345 @retval EFI_DEVICE_ERROR The device reported an error while writting back the data\r
346 @retval EFI_NO_MEDIA There is no media in the device.\r
347\r
348**/\r
349EFI_STATUS\r
350EFIAPI\r
351EmuBlockIoFlushBlocks (\r
352 IN EFI_BLOCK_IO_PROTOCOL *This\r
353 )\r
354{\r
355 EFI_STATUS Status;\r
356 EMU_BLOCK_IO_PRIVATE *Private;\r
357 EFI_TPL OldTpl;\r
358 EFI_BLOCK_IO2_TOKEN Token;\r
359\r
360 Private = EMU_BLOCK_IO2_PRIVATE_DATA_FROM_THIS (This);\r
361\r
362 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
363\r
364 Token.Event = NULL;\r
365 Status = Private->Io->FlushBlocks (Private->Io, &Token);\r
366\r
367 gBS->RestoreTPL (OldTpl);\r
368 return Status;\r
369}\r
370\r
371\r
372\r
373/**\r
374 Tests to see if this driver supports a given controller. If a child device is provided, \r
375 it further tests to see if this driver supports creating a handle for the specified child device.\r
376\r
377 This function checks to see if the driver specified by This supports the device specified by \r
378 ControllerHandle. Drivers will typically use the device path attached to \r
379 ControllerHandle and/or the services from the bus I/O abstraction attached to \r
380 ControllerHandle to determine if the driver supports ControllerHandle. This function \r
381 may be called many times during platform initialization. In order to reduce boot times, the tests \r
382 performed by this function must be very small, and take as little time as possible to execute. This \r
383 function must not change the state of any hardware devices, and this function must be aware that the \r
384 device specified by ControllerHandle may already be managed by the same driver or a \r
385 different driver. This function must match its calls to AllocatePages() with FreePages(), \r
386 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol(). \r
387 Because ControllerHandle may have been previously started by the same driver, if a protocol is \r
388 already in the opened state, then it must not be closed with CloseProtocol(). This is required \r
389 to guarantee the state of ControllerHandle is not modified by this function.\r
390\r
391 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
392 @param[in] ControllerHandle The handle of the controller to test. This handle \r
393 must support a protocol interface that supplies \r
394 an I/O abstraction to the driver.\r
395 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This \r
396 parameter is ignored by device drivers, and is optional for bus \r
397 drivers. For bus drivers, if this parameter is not NULL, then \r
398 the bus driver must determine if the bus controller specified \r
399 by ControllerHandle and the child controller specified \r
400 by RemainingDevicePath are both supported by this \r
401 bus driver.\r
402\r
403 @retval EFI_SUCCESS The device specified by ControllerHandle and\r
404 RemainingDevicePath is supported by the driver specified by This.\r
405 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r
406 RemainingDevicePath is already being managed by the driver\r
407 specified by This.\r
408 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r
409 RemainingDevicePath is already being managed by a different\r
410 driver or an application that requires exclusive access.\r
411 Currently not implemented.\r
412 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r
413 RemainingDevicePath is not supported by the driver specified by This.\r
414**/\r
415EFI_STATUS\r
416EFIAPI\r
417EmuBlockIoDriverBindingSupported (\r
418 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
419 IN EFI_HANDLE Handle,\r
420 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
421 )\r
422{\r
423 EFI_STATUS Status;\r
424 EMU_IO_THUNK_PROTOCOL *EmuIoThunk;\r
425\r
426 //\r
427 // Open the IO Abstraction(s) needed to perform the supported test\r
428 //\r
429 Status = gBS->OpenProtocol (\r
430 Handle,\r
431 &gEmuIoThunkProtocolGuid,\r
432 (VOID **)&EmuIoThunk,\r
433 This->DriverBindingHandle,\r
434 Handle,\r
435 EFI_OPEN_PROTOCOL_BY_DRIVER\r
436 );\r
437 if (EFI_ERROR (Status)) {\r
438 return Status;\r
439 }\r
440\r
441 //\r
442 // Make sure GUID is for a File System handle.\r
443 //\r
444 Status = EFI_UNSUPPORTED;\r
445 if (CompareGuid (EmuIoThunk->Protocol, &gEmuVirtualDisksGuid)) {\r
446 Status = EFI_SUCCESS;\r
447 }\r
448\r
449 //\r
450 // Close the I/O Abstraction(s) used to perform the supported test\r
451 //\r
452 gBS->CloseProtocol (\r
453 Handle,\r
454 &gEmuIoThunkProtocolGuid,\r
455 This->DriverBindingHandle,\r
456 Handle\r
457 );\r
458 return Status;\r
459}\r
460\r
461\r
462/**\r
463 Starts a device controller or a bus controller.\r
464\r
465 The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
466 As a result, much of the error checking on the parameters to Start() has been moved into this \r
467 common boot service. It is legal to call Start() from other locations, \r
468 but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
469 1. ControllerHandle must be a valid EFI_HANDLE.\r
470 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
471 EFI_DEVICE_PATH_PROTOCOL.\r
472 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
473 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS. \r
474\r
475 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
476 @param[in] ControllerHandle The handle of the controller to start. This handle \r
477 must support a protocol interface that supplies \r
478 an I/O abstraction to the driver.\r
479 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This \r
480 parameter is ignored by device drivers, and is optional for bus \r
481 drivers. For a bus driver, if this parameter is NULL, then handles \r
482 for all the children of Controller are created by this driver. \r
483 If this parameter is not NULL and the first Device Path Node is \r
484 not the End of Device Path Node, then only the handle for the \r
485 child device specified by the first Device Path Node of \r
486 RemainingDevicePath is created by this driver.\r
487 If the first Device Path Node of RemainingDevicePath is \r
488 the End of Device Path Node, no child handle is created by this\r
489 driver.\r
490\r
491 @retval EFI_SUCCESS The device was started.\r
492 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r
493 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
494 @retval Others The driver failded to start the device.\r
495\r
496**/\r
497EFI_STATUS\r
498EFIAPI\r
499EmuBlockIoDriverBindingStart (\r
500 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
501 IN EFI_HANDLE Handle,\r
502 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
503 )\r
504{\r
505 EFI_STATUS Status;\r
506 EMU_IO_THUNK_PROTOCOL *EmuIoThunk;\r
507 EMU_BLOCK_IO_PRIVATE *Private;\r
508\r
509 //\r
510 // Grab the protocols we need\r
511 //\r
512 \r
513 Status = gBS->OpenProtocol (\r
514 Handle,\r
515 &gEmuIoThunkProtocolGuid,\r
516 (void *)&EmuIoThunk,\r
517 This->DriverBindingHandle,\r
518 Handle,\r
519 EFI_OPEN_PROTOCOL_BY_DRIVER\r
520 );\r
521 if (EFI_ERROR (Status)) {\r
522 return Status;\r
523 }\r
524 //\r
525 // Set DiskType\r
526 //\r
527 if (!CompareGuid (EmuIoThunk->Protocol, &gEmuVirtualDisksGuid)) {\r
528 Status = EFI_UNSUPPORTED;\r
529 goto Done;\r
530 }\r
531\r
532 Status = EmuIoThunk->Open (EmuIoThunk);\r
533 if (EFI_ERROR (Status)) {\r
534 goto Done;\r
535 }\r
536\r
537 Private = AllocatePool (sizeof (EMU_BLOCK_IO_PRIVATE));\r
538 if (Private == NULL) {\r
539 goto Done;\r
540 }\r
541\r
542 Private->Signature = EMU_BLOCK_IO_PRIVATE_SIGNATURE;\r
543 Private->IoThunk = EmuIoThunk;\r
544 Private->Io = EmuIoThunk->Interface;\r
545 \r
546 Private->BlockIo.Revision = EFI_BLOCK_IO_PROTOCOL_REVISION2;\r
547 Private->BlockIo.Media = &Private->Media;\r
548 Private->BlockIo.Reset = EmuBlockIoReset;\r
549 Private->BlockIo.ReadBlocks = EmuBlockIoReadBlocks;\r
550 Private->BlockIo.WriteBlocks = EmuBlockIoWriteBlocks;\r
551 Private->BlockIo.FlushBlocks = EmuBlockIoFlushBlocks;\r
552\r
553 Private->BlockIo2.Media = &Private->Media;\r
554 Private->BlockIo2.Reset = EmuBlockIo2Reset;\r
555 Private->BlockIo2.ReadBlocksEx = EmuBlockIo2ReadBlocksEx;\r
556 Private->BlockIo2.WriteBlocksEx = EmuBlockIo2WriteBlocksEx;\r
557 Private->BlockIo2.FlushBlocksEx = (EFI_BLOCK_FLUSH_EX)EmuBlockIoFlushBlocks;\r
558\r
559 Private->ControllerNameTable = NULL;\r
560\r
561 Status = Private->Io->CreateMapping (Private->Io, &Private->Media);\r
562 if (EFI_ERROR (Status)) {\r
563 goto Done;\r
564 }\r
565\r
566 AddUnicodeString2 (\r
567 "eng",\r
568 gEmuBlockIoComponentName.SupportedLanguages,\r
569 &Private->ControllerNameTable,\r
570 EmuIoThunk->ConfigString,\r
571 TRUE\r
572 );\r
573 \r
574 AddUnicodeString2 (\r
575 "en",\r
576 gEmuBlockIoComponentName2.SupportedLanguages,\r
577 &Private->ControllerNameTable,\r
578 EmuIoThunk->ConfigString,\r
579 FALSE\r
580 );\r
581\r
582 Status = gBS->InstallMultipleProtocolInterfaces (\r
583 &Handle,\r
584 &gEfiBlockIoProtocolGuid, &Private->BlockIo,\r
585 &gEfiBlockIo2ProtocolGuid, &Private->BlockIo2,\r
586 NULL\r
587 );\r
588\r
589Done:\r
590 if (EFI_ERROR (Status)) {\r
591 if (Private != NULL) {\r
592 if (Private->ControllerNameTable != NULL) {\r
593 FreeUnicodeStringTable (Private->ControllerNameTable);\r
594 }\r
595 \r
596 gBS->FreePool (Private);\r
597 \r
598 }\r
599 \r
600 gBS->CloseProtocol (\r
601 Handle,\r
602 &gEmuIoThunkProtocolGuid,\r
603 This->DriverBindingHandle,\r
604 Handle\r
605 );\r
606 }\r
607\r
608 return Status;\r
609}\r
610\r
611\r
612/**\r
613 Stops a device controller or a bus controller.\r
614 \r
615 The Stop() function is designed to be invoked from the EFI boot service DisconnectController(). \r
616 As a result, much of the error checking on the parameters to Stop() has been moved \r
617 into this common boot service. It is legal to call Stop() from other locations, \r
618 but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
619 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
620 same driver's Start() function.\r
621 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
622 EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
623 Start() function, and the Start() function must have called OpenProtocol() on\r
624 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
625 \r
626 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
627 @param[in] ControllerHandle A handle to the device being stopped. The handle must \r
628 support a bus specific I/O protocol for the driver \r
629 to use to stop the device.\r
630 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r
631 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL \r
632 if NumberOfChildren is 0.\r
633\r
634 @retval EFI_SUCCESS The device was stopped.\r
635 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
636\r
637**/\r
638EFI_STATUS\r
639EFIAPI\r
640EmuBlockIoDriverBindingStop (\r
641 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
642 IN EFI_HANDLE Handle,\r
643 IN UINTN NumberOfChildren,\r
644 IN EFI_HANDLE *ChildHandleBuffer\r
645 )\r
646{\r
647 EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
648 EFI_STATUS Status;\r
649 EMU_BLOCK_IO_PRIVATE *Private;\r
650\r
651 //\r
652 // Get our context back\r
653 //\r
654 Status = gBS->OpenProtocol (\r
655 Handle,\r
656 &gEfiBlockIoProtocolGuid,\r
657 (void *)&BlockIo,\r
658 This->DriverBindingHandle,\r
659 Handle,\r
660 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
661 );\r
662 if (EFI_ERROR (Status)) {\r
663 return EFI_UNSUPPORTED;\r
664 }\r
665\r
666 Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (BlockIo);\r
667 Status = Private->IoThunk->Close (Private->IoThunk);\r
668\r
669 Status = gBS->UninstallMultipleProtocolInterfaces (\r
670 Private->EfiHandle,\r
671 &gEfiBlockIoProtocolGuid, &Private->BlockIo,\r
672 &gEfiBlockIo2ProtocolGuid, &Private->BlockIo2,\r
673 NULL\r
674 );\r
675 if (!EFI_ERROR (Status)) {\r
676 Status = gBS->CloseProtocol (\r
677 Handle,\r
678 &gEmuIoThunkProtocolGuid,\r
679 This->DriverBindingHandle,\r
680 Handle\r
681 );\r
682 }\r
683 \r
684 if (!EFI_ERROR (Status)) {\r
685 //\r
686 // Free our instance data\r
687 //\r
688 FreeUnicodeStringTable (Private->ControllerNameTable);\r
689 gBS->FreePool (Private);\r
690 }\r
691\r
692 return Status;\r
693}\r
694\r
695\r
696\r
697\r
698\r
699EFI_DRIVER_BINDING_PROTOCOL gEmuBlockIoDriverBinding = {\r
700 EmuBlockIoDriverBindingSupported,\r
701 EmuBlockIoDriverBindingStart,\r
702 EmuBlockIoDriverBindingStop,\r
703 0xa,\r
704 NULL,\r
705 NULL\r
706};\r
707\r
708\r
709\r
710\r
711/**\r
712 The user Entry Point for module EmuBlockIo . The user code starts with this function.\r
713\r
714 @param[in] ImageHandle The firmware allocated handle for the EFI image. \r
715 @param[in] SystemTable A pointer to the EFI System Table.\r
716 \r
717 @retval EFI_SUCCESS The entry point is executed successfully.\r
718 @retval other Some error occurs when executing this entry point.\r
719\r
720**/\r
721EFI_STATUS\r
722EFIAPI\r
723InitializeEmuBlockIo (\r
724 IN EFI_HANDLE ImageHandle,\r
725 IN EFI_SYSTEM_TABLE *SystemTable\r
726 )\r
727{\r
728 EFI_STATUS Status;\r
729\r
730 Status = EfiLibInstallAllDriverProtocols2 (\r
731 ImageHandle,\r
732 SystemTable,\r
733 &gEmuBlockIoDriverBinding,\r
734 ImageHandle,\r
735 &gEmuBlockIoComponentName,\r
736 &gEmuBlockIoComponentName2,\r
737 NULL,\r
738 NULL,\r
739 &gEmuBlockIoDriverDiagnostics,\r
740 &gEmuBlockIoDriverDiagnostics2\r
741 );\r
742 ASSERT_EFI_ERROR (Status);\r
743\r
744\r
745 return Status;\r
746}\r
747\r
748\r
749\r