]> git.proxmox.com Git - mirror_edk2.git/blame - InOsEmuPkg/EmuBlockIoDxe/EmuBlockIo.c
Add support for SerialPortLib that maps into POSIX StdIn and StdOut. Add a device...
[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
033d0e5f 235 Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);\r
d59326d3 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
033d0e5f 267EmuBlockIoReadBlocks (\r
d59326d3 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
033d0e5f 280 Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);\r
d59326d3 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
033d0e5f 327 Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);\r
d59326d3 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
033d0e5f 359 Private = EMU_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);\r
d59326d3 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
033d0e5f 444 if (CompareGuid (EmuIoThunk->Protocol, &gEmuBlockIoProtocolGuid)) {\r
d59326d3 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
7e284acb 506 EMU_BLOCK_IO_PRIVATE *Private = NULL;\r
d59326d3 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 // Set DiskType\r
525 //\r
033d0e5f 526 if (!CompareGuid (EmuIoThunk->Protocol, &gEmuBlockIoProtocolGuid)) {\r
d59326d3 527 Status = EFI_UNSUPPORTED;\r
528 goto Done;\r
529 }\r
530\r
531 Status = EmuIoThunk->Open (EmuIoThunk);\r
532 if (EFI_ERROR (Status)) {\r
533 goto Done;\r
534 }\r
535\r
536 Private = AllocatePool (sizeof (EMU_BLOCK_IO_PRIVATE));\r
537 if (Private == NULL) {\r
538 goto Done;\r
539 }\r
540\r
541 Private->Signature = EMU_BLOCK_IO_PRIVATE_SIGNATURE;\r
542 Private->IoThunk = EmuIoThunk;\r
543 Private->Io = EmuIoThunk->Interface;\r
033d0e5f 544 Private->EfiHandle = Handle;\r
d59326d3 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
63947cc4 557 Private->BlockIo2.FlushBlocksEx = EmuBlockIo2Flush;\r
d59326d3 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