]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - EmulatorPkg/EmuBlockIoDxe/EmuBlockIo.c
MdeModulePkg/BdsDxe: Call PlatformBootManagerUnableToBoot()
[mirror_edk2.git] / EmulatorPkg / EmuBlockIoDxe / EmuBlockIo.c
... / ...
CommitLineData
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_IO_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 IN EFI_BLOCK_IO_PROTOCOL *This,\r
269 IN UINT32 MediaId,\r
270 IN EFI_LBA Lba,\r
271 IN UINTN BufferSize,\r
272 OUT VOID *Buffer\r
273 )\r
274{\r
275 EFI_STATUS Status;\r
276 EMU_BLOCK_IO_PRIVATE *Private;\r
277 EFI_TPL OldTpl;\r
278 EFI_BLOCK_IO2_TOKEN Token;\r
279\r
280 Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);\r
281\r
282 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
283\r
284 Token.Event = NULL;\r
285 Status = Private->Io->ReadBlocks (Private->Io, MediaId, Lba, &Token, BufferSize, Buffer);\r
286\r
287 gBS->RestoreTPL (OldTpl);\r
288 return Status;\r
289}\r
290\r
291\r
292/**\r
293 Write BufferSize bytes from Lba into Buffer.\r
294\r
295 @param This Indicates a pointer to the calling context.\r
296 @param MediaId The media ID that the write request is for.\r
297 @param Lba The starting logical block address to be written. The caller is\r
298 responsible for writing to only legitimate locations.\r
299 @param BufferSize Size of Buffer, must be a multiple of device block size.\r
300 @param Buffer A pointer to the source buffer for the data.\r
301\r
302 @retval EFI_SUCCESS The data was written correctly to the device.\r
303 @retval EFI_WRITE_PROTECTED The device can not be written to.\r
304 @retval EFI_DEVICE_ERROR The device reported an error while performing the write.\r
305 @retval EFI_NO_MEDIA There is no media in the device.\r
306 @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.\r
307 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.\r
308 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,\r
309 or the buffer is not on proper alignment.\r
310\r
311**/\r
312EFI_STATUS\r
313EFIAPI\r
314EmuBlockIoWriteBlocks (\r
315 IN EFI_BLOCK_IO_PROTOCOL *This,\r
316 IN UINT32 MediaId,\r
317 IN EFI_LBA Lba,\r
318 IN UINTN BufferSize,\r
319 IN VOID *Buffer\r
320 )\r
321{\r
322 EFI_STATUS Status;\r
323 EMU_BLOCK_IO_PRIVATE *Private;\r
324 EFI_TPL OldTpl;\r
325 EFI_BLOCK_IO2_TOKEN Token;\r
326\r
327 Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);\r
328\r
329 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
330\r
331 Token.Event = NULL;\r
332 Status = Private->Io->WriteBlocks (Private->Io, MediaId, Lba, &Token, BufferSize, Buffer);\r
333\r
334 gBS->RestoreTPL (OldTpl);\r
335 return Status;\r
336}\r
337\r
338/**\r
339 Flush the Block Device.\r
340\r
341 @param This Indicates a pointer to the calling context.\r
342\r
343 @retval EFI_SUCCESS All outstanding data was written to the device\r
344 @retval EFI_DEVICE_ERROR The device reported an error while writting back the data\r
345 @retval EFI_NO_MEDIA There is no media in the device.\r
346\r
347**/\r
348EFI_STATUS\r
349EFIAPI\r
350EmuBlockIoFlushBlocks (\r
351 IN EFI_BLOCK_IO_PROTOCOL *This\r
352 )\r
353{\r
354 EFI_STATUS Status;\r
355 EMU_BLOCK_IO_PRIVATE *Private;\r
356 EFI_TPL OldTpl;\r
357 EFI_BLOCK_IO2_TOKEN Token;\r
358\r
359 Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);\r
360\r
361 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
362\r
363 Token.Event = NULL;\r
364 Status = Private->Io->FlushBlocks (Private->Io, &Token);\r
365\r
366 gBS->RestoreTPL (OldTpl);\r
367 return Status;\r
368}\r
369\r
370\r
371\r
372/**\r
373 Tests to see if this driver supports a given controller. If a child device is provided,\r
374 it further tests to see if this driver supports creating a handle for the specified child device.\r
375\r
376 This function checks to see if the driver specified by This supports the device specified by\r
377 ControllerHandle. Drivers will typically use the device path attached to\r
378 ControllerHandle and/or the services from the bus I/O abstraction attached to\r
379 ControllerHandle to determine if the driver supports ControllerHandle. This function\r
380 may be called many times during platform initialization. In order to reduce boot times, the tests\r
381 performed by this function must be very small, and take as little time as possible to execute. This\r
382 function must not change the state of any hardware devices, and this function must be aware that the\r
383 device specified by ControllerHandle may already be managed by the same driver or a\r
384 different driver. This function must match its calls to AllocatePages() with FreePages(),\r
385 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().\r
386 Because ControllerHandle may have been previously started by the same driver, if a protocol is\r
387 already in the opened state, then it must not be closed with CloseProtocol(). This is required\r
388 to guarantee the state of ControllerHandle is not modified by this function.\r
389\r
390 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
391 @param[in] ControllerHandle The handle of the controller to test. This handle\r
392 must support a protocol interface that supplies\r
393 an I/O abstraction to the driver.\r
394 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
395 parameter is ignored by device drivers, and is optional for bus\r
396 drivers. For bus drivers, if this parameter is not NULL, then\r
397 the bus driver must determine if the bus controller specified\r
398 by ControllerHandle and the child controller specified\r
399 by RemainingDevicePath are both supported by this\r
400 bus driver.\r
401\r
402 @retval EFI_SUCCESS The device specified by ControllerHandle and\r
403 RemainingDevicePath is supported by the driver specified by This.\r
404 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r
405 RemainingDevicePath is already being managed by the driver\r
406 specified by This.\r
407 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r
408 RemainingDevicePath is already being managed by a different\r
409 driver or an application that requires exclusive access.\r
410 Currently not implemented.\r
411 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r
412 RemainingDevicePath is not supported by the driver specified by This.\r
413**/\r
414EFI_STATUS\r
415EFIAPI\r
416EmuBlockIoDriverBindingSupported (\r
417 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
418 IN EFI_HANDLE Handle,\r
419 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
420 )\r
421{\r
422 EFI_STATUS Status;\r
423 EMU_IO_THUNK_PROTOCOL *EmuIoThunk;\r
424\r
425 //\r
426 // Open the IO Abstraction(s) needed to perform the supported test\r
427 //\r
428 Status = gBS->OpenProtocol (\r
429 Handle,\r
430 &gEmuIoThunkProtocolGuid,\r
431 (VOID **)&EmuIoThunk,\r
432 This->DriverBindingHandle,\r
433 Handle,\r
434 EFI_OPEN_PROTOCOL_BY_DRIVER\r
435 );\r
436 if (EFI_ERROR (Status)) {\r
437 return Status;\r
438 }\r
439\r
440 //\r
441 // Make sure GUID is for a File System handle.\r
442 //\r
443 Status = EFI_UNSUPPORTED;\r
444 if (CompareGuid (EmuIoThunk->Protocol, &gEmuBlockIoProtocolGuid)) {\r
445 Status = EFI_SUCCESS;\r
446 }\r
447\r
448 //\r
449 // Close the I/O Abstraction(s) used to perform the supported test\r
450 //\r
451 gBS->CloseProtocol (\r
452 Handle,\r
453 &gEmuIoThunkProtocolGuid,\r
454 This->DriverBindingHandle,\r
455 Handle\r
456 );\r
457 return Status;\r
458}\r
459\r
460\r
461/**\r
462 Starts a device controller or a bus controller.\r
463\r
464 The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
465 As a result, much of the error checking on the parameters to Start() has been moved into this\r
466 common boot service. It is legal to call Start() from other locations,\r
467 but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
468 1. ControllerHandle must be a valid EFI_HANDLE.\r
469 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
470 EFI_DEVICE_PATH_PROTOCOL.\r
471 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
472 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r
473\r
474 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
475 @param[in] ControllerHandle The handle of the controller to start. This handle\r
476 must support a protocol interface that supplies\r
477 an I/O abstraction to the driver.\r
478 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
479 parameter is ignored by device drivers, and is optional for bus\r
480 drivers. For a bus driver, if this parameter is NULL, then handles\r
481 for all the children of Controller are created by this driver.\r
482 If this parameter is not NULL and the first Device Path Node is\r
483 not the End of Device Path Node, then only the handle for the\r
484 child device specified by the first Device Path Node of\r
485 RemainingDevicePath is created by this driver.\r
486 If the first Device Path Node of RemainingDevicePath is\r
487 the End of Device Path Node, no child handle is created by this\r
488 driver.\r
489\r
490 @retval EFI_SUCCESS The device was started.\r
491 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r
492 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
493 @retval Others The driver failded to start the device.\r
494\r
495**/\r
496EFI_STATUS\r
497EFIAPI\r
498EmuBlockIoDriverBindingStart (\r
499 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
500 IN EFI_HANDLE Handle,\r
501 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
502 )\r
503{\r
504 EFI_STATUS Status;\r
505 EMU_IO_THUNK_PROTOCOL *EmuIoThunk;\r
506 EMU_BLOCK_IO_PRIVATE *Private = NULL;\r
507\r
508 //\r
509 // Grab the protocols we need\r
510 //\r
511\r
512 Status = gBS->OpenProtocol (\r
513 Handle,\r
514 &gEmuIoThunkProtocolGuid,\r
515 (void *)&EmuIoThunk,\r
516 This->DriverBindingHandle,\r
517 Handle,\r
518 EFI_OPEN_PROTOCOL_BY_DRIVER\r
519 );\r
520 if (EFI_ERROR (Status)) {\r
521 return Status;\r
522 }\r
523\r
524 if (!CompareGuid (EmuIoThunk->Protocol, &gEmuBlockIoProtocolGuid)) {\r
525 Status = EFI_UNSUPPORTED;\r
526 goto Done;\r
527 }\r
528\r
529 Status = EmuIoThunk->Open (EmuIoThunk);\r
530 if (EFI_ERROR (Status)) {\r
531 goto Done;\r
532 }\r
533\r
534 Private = AllocatePool (sizeof (EMU_BLOCK_IO_PRIVATE));\r
535 if (Private == NULL) {\r
536 goto Done;\r
537 }\r
538\r
539 Private->Signature = EMU_BLOCK_IO_PRIVATE_SIGNATURE;\r
540 Private->IoThunk = EmuIoThunk;\r
541 Private->Io = EmuIoThunk->Interface;\r
542 Private->EfiHandle = Handle;\r
543\r
544 Private->BlockIo.Revision = EFI_BLOCK_IO_PROTOCOL_REVISION2;\r
545 Private->BlockIo.Media = &Private->Media;\r
546 Private->BlockIo.Reset = EmuBlockIoReset;\r
547 Private->BlockIo.ReadBlocks = EmuBlockIoReadBlocks;\r
548 Private->BlockIo.WriteBlocks = EmuBlockIoWriteBlocks;\r
549 Private->BlockIo.FlushBlocks = EmuBlockIoFlushBlocks;\r
550\r
551 Private->BlockIo2.Media = &Private->Media;\r
552 Private->BlockIo2.Reset = EmuBlockIo2Reset;\r
553 Private->BlockIo2.ReadBlocksEx = EmuBlockIo2ReadBlocksEx;\r
554 Private->BlockIo2.WriteBlocksEx = EmuBlockIo2WriteBlocksEx;\r
555 Private->BlockIo2.FlushBlocksEx = EmuBlockIo2Flush;\r
556\r
557 Private->ControllerNameTable = NULL;\r
558\r
559 Status = Private->Io->CreateMapping (Private->Io, &Private->Media);\r
560 if (EFI_ERROR (Status)) {\r
561 goto Done;\r
562 }\r
563\r
564 AddUnicodeString2 (\r
565 "eng",\r
566 gEmuBlockIoComponentName.SupportedLanguages,\r
567 &Private->ControllerNameTable,\r
568 EmuIoThunk->ConfigString,\r
569 TRUE\r
570 );\r
571\r
572 AddUnicodeString2 (\r
573 "en",\r
574 gEmuBlockIoComponentName2.SupportedLanguages,\r
575 &Private->ControllerNameTable,\r
576 EmuIoThunk->ConfigString,\r
577 FALSE\r
578 );\r
579\r
580 Status = gBS->InstallMultipleProtocolInterfaces (\r
581 &Handle,\r
582 &gEfiBlockIoProtocolGuid, &Private->BlockIo,\r
583 &gEfiBlockIo2ProtocolGuid, &Private->BlockIo2,\r
584 NULL\r
585 );\r
586\r
587Done:\r
588 if (EFI_ERROR (Status)) {\r
589 if (Private != NULL) {\r
590 if (Private->ControllerNameTable != NULL) {\r
591 FreeUnicodeStringTable (Private->ControllerNameTable);\r
592 }\r
593\r
594 gBS->FreePool (Private);\r
595\r
596 }\r
597\r
598 gBS->CloseProtocol (\r
599 Handle,\r
600 &gEmuIoThunkProtocolGuid,\r
601 This->DriverBindingHandle,\r
602 Handle\r
603 );\r
604 }\r
605\r
606 return Status;\r
607}\r
608\r
609\r
610/**\r
611 Stops a device controller or a bus controller.\r
612\r
613 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r
614 As a result, much of the error checking on the parameters to Stop() has been moved\r
615 into this common boot service. It is legal to call Stop() from other locations,\r
616 but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
617 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
618 same driver's Start() function.\r
619 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
620 EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
621 Start() function, and the Start() function must have called OpenProtocol() on\r
622 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
623\r
624 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
625 @param[in] ControllerHandle A handle to the device being stopped. The handle must\r
626 support a bus specific I/O protocol for the driver\r
627 to use to stop the device.\r
628 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r
629 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r
630 if NumberOfChildren is 0.\r
631\r
632 @retval EFI_SUCCESS The device was stopped.\r
633 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
634\r
635**/\r
636EFI_STATUS\r
637EFIAPI\r
638EmuBlockIoDriverBindingStop (\r
639 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
640 IN EFI_HANDLE Handle,\r
641 IN UINTN NumberOfChildren,\r
642 IN EFI_HANDLE *ChildHandleBuffer\r
643 )\r
644{\r
645 EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
646 EFI_STATUS Status;\r
647 EMU_BLOCK_IO_PRIVATE *Private;\r
648\r
649 //\r
650 // Get our context back\r
651 //\r
652 Status = gBS->OpenProtocol (\r
653 Handle,\r
654 &gEfiBlockIoProtocolGuid,\r
655 (void *)&BlockIo,\r
656 This->DriverBindingHandle,\r
657 Handle,\r
658 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
659 );\r
660 if (EFI_ERROR (Status)) {\r
661 return EFI_UNSUPPORTED;\r
662 }\r
663\r
664 Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (BlockIo);\r
665 Status = Private->IoThunk->Close (Private->IoThunk);\r
666\r
667 Status = gBS->UninstallMultipleProtocolInterfaces (\r
668 Private->EfiHandle,\r
669 &gEfiBlockIoProtocolGuid, &Private->BlockIo,\r
670 &gEfiBlockIo2ProtocolGuid, &Private->BlockIo2,\r
671 NULL\r
672 );\r
673 if (!EFI_ERROR (Status)) {\r
674 Status = gBS->CloseProtocol (\r
675 Handle,\r
676 &gEmuIoThunkProtocolGuid,\r
677 This->DriverBindingHandle,\r
678 Handle\r
679 );\r
680 }\r
681\r
682 if (!EFI_ERROR (Status)) {\r
683 //\r
684 // Free our instance data\r
685 //\r
686 FreeUnicodeStringTable (Private->ControllerNameTable);\r
687 gBS->FreePool (Private);\r
688 }\r
689\r
690 return Status;\r
691}\r
692\r
693\r
694\r
695\r
696\r
697EFI_DRIVER_BINDING_PROTOCOL gEmuBlockIoDriverBinding = {\r
698 EmuBlockIoDriverBindingSupported,\r
699 EmuBlockIoDriverBindingStart,\r
700 EmuBlockIoDriverBindingStop,\r
701 0xa,\r
702 NULL,\r
703 NULL\r
704};\r
705\r
706\r
707\r
708\r
709/**\r
710 The user Entry Point for module EmuBlockIo . The user code starts with this function.\r
711\r
712 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
713 @param[in] SystemTable A pointer to the EFI System Table.\r
714\r
715 @retval EFI_SUCCESS The entry point is executed successfully.\r
716 @retval other Some error occurs when executing this entry point.\r
717\r
718**/\r
719EFI_STATUS\r
720EFIAPI\r
721InitializeEmuBlockIo (\r
722 IN EFI_HANDLE ImageHandle,\r
723 IN EFI_SYSTEM_TABLE *SystemTable\r
724 )\r
725{\r
726 EFI_STATUS Status;\r
727\r
728 Status = EfiLibInstallAllDriverProtocols2 (\r
729 ImageHandle,\r
730 SystemTable,\r
731 &gEmuBlockIoDriverBinding,\r
732 ImageHandle,\r
733 &gEmuBlockIoComponentName,\r
734 &gEmuBlockIoComponentName2,\r
735 NULL,\r
736 NULL,\r
737 &gEmuBlockIoDriverDiagnostics,\r
738 &gEmuBlockIoDriverDiagnostics2\r
739 );\r
740 ASSERT_EFI_ERROR (Status);\r
741\r
742\r
743 return Status;\r
744}\r
745\r
746\r
747\r