]>
Commit | Line | Data |
---|---|---|
bcecde14 | 1 | /** @file\r |
2 | \r | |
e24fc103 | 3 | Copyright (c) 1999 - 2011, Intel Corporation. All rights reserved.<BR>\r |
bcecde14 | 4 | \r |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions\r | |
7 | of the BSD License which accompanies this distribution. The\r | |
8 | full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #ifndef _BIOS_BLOCK_IO_H_\r | |
17 | #define _BIOS_BLOCK_IO_H_\r | |
18 | \r | |
19 | #include <Uefi.h>\r | |
20 | \r | |
21 | #include <Protocol/BlockIo.h>\r | |
22 | #include <Protocol/PciIo.h>\r | |
23 | #include <Protocol/LegacyBios.h>\r | |
24 | #include <Protocol/DevicePath.h>\r | |
25 | #include <Guid/LegacyBios.h>\r | |
e24fc103 | 26 | #include <Guid/BlockIoVendor.h>\r |
bcecde14 | 27 | \r |
28 | #include <Library/UefiDriverEntryPoint.h>\r | |
29 | #include <Library/DebugLib.h>\r | |
30 | #include <Library/BaseMemoryLib.h>\r | |
31 | #include <Library/UefiBootServicesTableLib.h>\r | |
32 | #include <Library/UefiLib.h>\r | |
33 | #include <Library/DevicePathLib.h>\r | |
34 | #include <Library/MemoryAllocationLib.h>\r | |
35 | \r | |
36 | #include <IndustryStandard/Pci.h>\r | |
37 | \r | |
38 | #include "Edd.h"\r | |
39 | \r | |
bcecde14 | 40 | //\r |
41 | // Global Variables\r | |
42 | //\r | |
43 | extern EFI_COMPONENT_NAME_PROTOCOL gBiosBlockIoComponentName;\r | |
44 | extern EFI_COMPONENT_NAME2_PROTOCOL gBiosBlockIoComponentName2;\r | |
45 | \r | |
46 | \r | |
47 | //\r | |
48 | // Define the I2O class code\r | |
49 | //\r | |
50 | #define PCI_BASE_CLASS_INTELLIGENT 0x0e\r | |
51 | #define PCI_SUB_CLASS_INTELLIGENT 0x00\r | |
52 | \r | |
53 | //\r | |
54 | // Number of pages needed for our buffer under 1MB\r | |
55 | //\r | |
56 | #define BLOCK_IO_BUFFER_PAGE_SIZE (((sizeof (EDD_DEVICE_ADDRESS_PACKET) + sizeof (BIOS_LEGACY_DRIVE) + MAX_EDD11_XFER) / EFI_PAGE_SIZE) + 1 \\r | |
57 | )\r | |
58 | \r | |
59 | //\r | |
60 | // Driver Binding Protocol functions\r | |
61 | //\r | |
62 | \r | |
63 | /**\r | |
64 | Check whether the driver supports this device.\r | |
65 | \r | |
66 | @param This The Udriver binding protocol.\r | |
67 | @param Controller The controller handle to check.\r | |
68 | @param RemainingDevicePath The remaining device path.\r | |
69 | \r | |
70 | @retval EFI_SUCCESS The driver supports this controller.\r | |
71 | @retval other This device isn't supported.\r | |
72 | \r | |
73 | **/\r | |
74 | EFI_STATUS\r | |
75 | EFIAPI\r | |
76 | BiosBlockIoDriverBindingSupported (\r | |
77 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
78 | IN EFI_HANDLE Controller,\r | |
79 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
80 | );\r | |
81 | \r | |
82 | \r | |
83 | /**\r | |
84 | Starts the device with this driver.\r | |
85 | \r | |
86 | @param This The driver binding instance.\r | |
87 | @param Controller Handle of device to bind driver to.\r | |
88 | @param RemainingDevicePath Optional parameter use to pick a specific child\r | |
89 | device to start.\r | |
90 | \r | |
91 | @retval EFI_SUCCESS The controller is controlled by the driver.\r | |
92 | @retval Other This controller cannot be started.\r | |
93 | \r | |
94 | **/\r | |
95 | EFI_STATUS\r | |
96 | EFIAPI\r | |
97 | BiosBlockIoDriverBindingStart (\r | |
98 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
99 | IN EFI_HANDLE Controller,\r | |
100 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
101 | );\r | |
102 | \r | |
103 | /**\r | |
104 | Stop the device handled by this driver.\r | |
105 | \r | |
106 | @param This The driver binding protocol.\r | |
107 | @param Controller The controller to release.\r | |
108 | @param NumberOfChildren The number of handles in ChildHandleBuffer.\r | |
109 | @param ChildHandleBuffer The array of child handle.\r | |
110 | \r | |
111 | @retval EFI_SUCCESS The device was stopped.\r | |
112 | @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r | |
113 | @retval Others Fail to uninstall protocols attached on the device.\r | |
114 | \r | |
115 | **/\r | |
116 | EFI_STATUS\r | |
117 | EFIAPI\r | |
118 | BiosBlockIoDriverBindingStop (\r | |
119 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
120 | IN EFI_HANDLE Controller,\r | |
121 | IN UINTN NumberOfChildren,\r | |
122 | IN EFI_HANDLE *ChildHandleBuffer\r | |
123 | );\r | |
124 | \r | |
125 | //\r | |
126 | // Other internal functions\r | |
127 | //\r | |
128 | \r | |
129 | /**\r | |
130 | Build device path for EDD 3.0.\r | |
131 | \r | |
132 | @param BaseDevicePath Base device path.\r | |
133 | @param Drive Legacy drive.\r | |
134 | @param DevicePath Device path for output.\r | |
135 | \r | |
136 | @retval EFI_SUCCESS The device path is built successfully.\r | |
137 | @retval EFI_UNSUPPORTED It is failed to built device path.\r | |
138 | \r | |
139 | **/\r | |
140 | EFI_STATUS\r | |
141 | BuildEdd30DevicePath (\r | |
142 | IN EFI_DEVICE_PATH_PROTOCOL *BaseDevicePath,\r | |
143 | IN BIOS_LEGACY_DRIVE *Drive,\r | |
144 | IN EFI_DEVICE_PATH_PROTOCOL **DevicePath\r | |
145 | );\r | |
146 | \r | |
147 | /**\r | |
148 | Initialize block I/O device instance\r | |
149 | \r | |
150 | @param Dev Instance of block I/O device instance\r | |
151 | \r | |
152 | @retval TRUE Initialization succeeds.\r | |
153 | @retval FALSE Initialization fails.\r | |
154 | \r | |
155 | **/\r | |
156 | BOOLEAN\r | |
157 | BiosInitBlockIo (\r | |
158 | IN BIOS_BLOCK_IO_DEV *Dev\r | |
159 | );\r | |
160 | \r | |
161 | /**\r | |
162 | Read BufferSize bytes from Lba into Buffer.\r | |
163 | \r | |
164 | @param This Indicates a pointer to the calling context.\r | |
165 | @param MediaId Id of the media, changes every time the media is replaced.\r | |
166 | @param Lba The starting Logical Block Address to read from\r | |
167 | @param BufferSize Size of Buffer, must be a multiple of device block size.\r | |
168 | @param Buffer A pointer to the destination buffer for the data. The caller is\r | |
169 | responsible for either having implicit or explicit ownership of the buffer.\r | |
170 | \r | |
171 | @retval EFI_SUCCESS The data was read correctly from the device.\r | |
172 | @retval EFI_DEVICE_ERROR The device reported an error while performing the read.\r | |
173 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
174 | @retval EFI_MEDIA_CHANGED The MediaId does not matched the current device.\r | |
175 | @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.\r | |
176 | @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid, \r | |
177 | or the buffer is not on proper alignment.\r | |
178 | \r | |
179 | **/\r | |
180 | EFI_STATUS\r | |
181 | EFIAPI\r | |
182 | Edd30BiosReadBlocks (\r | |
183 | IN EFI_BLOCK_IO_PROTOCOL *This,\r | |
184 | IN UINT32 MediaId,\r | |
185 | IN EFI_LBA Lba,\r | |
186 | IN UINTN BufferSize,\r | |
187 | OUT VOID *Buffer\r | |
188 | );\r | |
189 | \r | |
190 | /**\r | |
191 | Write BufferSize bytes from Lba into Buffer.\r | |
192 | \r | |
193 | @param This Indicates a pointer to the calling context.\r | |
194 | @param MediaId The media ID that the write request is for.\r | |
195 | @param Lba The starting logical block address to be written. The caller is\r | |
196 | responsible for writing to only legitimate locations.\r | |
197 | @param BufferSize Size of Buffer, must be a multiple of device block size.\r | |
198 | @param Buffer A pointer to the source buffer for the data.\r | |
199 | \r | |
200 | @retval EFI_SUCCESS The data was written correctly to the device.\r | |
201 | @retval EFI_WRITE_PROTECTED The device can not be written to.\r | |
202 | @retval EFI_DEVICE_ERROR The device reported an error while performing the write.\r | |
203 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
204 | @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.\r | |
205 | @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.\r | |
206 | @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid, \r | |
207 | or the buffer is not on proper alignment.\r | |
208 | \r | |
209 | **/\r | |
210 | EFI_STATUS\r | |
211 | EFIAPI\r | |
212 | Edd30BiosWriteBlocks (\r | |
213 | IN EFI_BLOCK_IO_PROTOCOL *This,\r | |
214 | IN UINT32 MediaId,\r | |
215 | IN EFI_LBA Lba,\r | |
216 | IN UINTN BufferSize,\r | |
217 | OUT VOID *Buffer\r | |
218 | );\r | |
219 | \r | |
220 | /**\r | |
221 | Flush the Block Device.\r | |
222 | \r | |
223 | @param This Indicates a pointer to the calling context.\r | |
224 | \r | |
225 | @retval EFI_SUCCESS All outstanding data was written to the device\r | |
226 | @retval EFI_DEVICE_ERROR The device reported an error while writting back the data\r | |
227 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
228 | \r | |
229 | **/\r | |
230 | EFI_STATUS\r | |
231 | EFIAPI\r | |
232 | BiosBlockIoFlushBlocks (\r | |
233 | IN EFI_BLOCK_IO_PROTOCOL *This\r | |
234 | );\r | |
235 | \r | |
236 | /**\r | |
237 | Reset the Block Device.\r | |
238 | \r | |
239 | @param This Indicates a pointer to the calling context.\r | |
240 | @param ExtendedVerification Driver may perform diagnostics on reset.\r | |
241 | \r | |
242 | @retval EFI_SUCCESS The device was reset.\r | |
243 | @retval EFI_DEVICE_ERROR The device is not functioning properly and could\r | |
244 | not be reset.\r | |
245 | \r | |
246 | **/\r | |
247 | EFI_STATUS\r | |
248 | EFIAPI\r | |
249 | BiosBlockIoReset (\r | |
250 | IN EFI_BLOCK_IO_PROTOCOL *This,\r | |
251 | IN BOOLEAN ExtendedVerification\r | |
252 | );\r | |
253 | \r | |
254 | /**\r | |
255 | Read BufferSize bytes from Lba into Buffer.\r | |
256 | \r | |
257 | @param This Indicates a pointer to the calling context.\r | |
258 | @param MediaId Id of the media, changes every time the media is replaced.\r | |
259 | @param Lba The starting Logical Block Address to read from\r | |
260 | @param BufferSize Size of Buffer, must be a multiple of device block size.\r | |
261 | @param Buffer A pointer to the destination buffer for the data. The caller is\r | |
262 | responsible for either having implicit or explicit ownership of the buffer.\r | |
263 | \r | |
264 | @retval EFI_SUCCESS The data was read correctly from the device.\r | |
265 | @retval EFI_DEVICE_ERROR The device reported an error while performing the read.\r | |
266 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
267 | @retval EFI_MEDIA_CHANGED The MediaId does not matched the current device.\r | |
268 | @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.\r | |
269 | @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid, \r | |
270 | or the buffer is not on proper alignment.\r | |
271 | \r | |
272 | **/\r | |
273 | EFI_STATUS\r | |
274 | EFIAPI\r | |
275 | Edd11BiosReadBlocks (\r | |
276 | IN EFI_BLOCK_IO_PROTOCOL *This,\r | |
277 | IN UINT32 MediaId,\r | |
278 | IN EFI_LBA Lba,\r | |
279 | IN UINTN BufferSize,\r | |
280 | OUT VOID *Buffer\r | |
281 | );\r | |
282 | \r | |
283 | /**\r | |
284 | Write BufferSize bytes from Lba into Buffer.\r | |
285 | \r | |
286 | @param This Indicates a pointer to the calling context.\r | |
287 | @param MediaId The media ID that the write request is for.\r | |
288 | @param Lba The starting logical block address to be written. The caller is\r | |
289 | responsible for writing to only legitimate locations.\r | |
290 | @param BufferSize Size of Buffer, must be a multiple of device block size.\r | |
291 | @param Buffer A pointer to the source buffer for the data.\r | |
292 | \r | |
293 | @retval EFI_SUCCESS The data was written correctly to the device.\r | |
294 | @retval EFI_WRITE_PROTECTED The device can not be written to.\r | |
295 | @retval EFI_DEVICE_ERROR The device reported an error while performing the write.\r | |
296 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
297 | @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.\r | |
298 | @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.\r | |
299 | @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid, \r | |
300 | or the buffer is not on proper alignment.\r | |
301 | \r | |
302 | **/\r | |
303 | EFI_STATUS\r | |
304 | EFIAPI\r | |
305 | Edd11BiosWriteBlocks (\r | |
306 | IN EFI_BLOCK_IO_PROTOCOL *This,\r | |
307 | IN UINT32 MediaId,\r | |
308 | IN EFI_LBA Lba,\r | |
309 | IN UINTN BufferSize,\r | |
310 | OUT VOID *Buffer\r | |
311 | );\r | |
312 | \r | |
313 | /**\r | |
314 | Read BufferSize bytes from Lba into Buffer.\r | |
315 | \r | |
316 | @param This Indicates a pointer to the calling context.\r | |
317 | @param MediaId Id of the media, changes every time the media is replaced.\r | |
318 | @param Lba The starting Logical Block Address to read from\r | |
319 | @param BufferSize Size of Buffer, must be a multiple of device block size.\r | |
320 | @param Buffer A pointer to the destination buffer for the data. The caller is\r | |
321 | responsible for either having implicit or explicit ownership of the buffer.\r | |
322 | \r | |
323 | @retval EFI_SUCCESS The data was read correctly from the device.\r | |
324 | @retval EFI_DEVICE_ERROR The device reported an error while performing the read.\r | |
325 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
326 | @retval EFI_MEDIA_CHANGED The MediaId does not matched the current device.\r | |
327 | @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.\r | |
328 | @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid, \r | |
329 | or the buffer is not on proper alignment.\r | |
330 | \r | |
331 | **/\r | |
332 | EFI_STATUS\r | |
333 | EFIAPI\r | |
334 | BiosReadLegacyDrive (\r | |
335 | IN EFI_BLOCK_IO_PROTOCOL *This,\r | |
336 | IN UINT32 MediaId,\r | |
337 | IN EFI_LBA Lba,\r | |
338 | IN UINTN BufferSize,\r | |
339 | OUT VOID *Buffer\r | |
340 | );\r | |
341 | \r | |
342 | /**\r | |
343 | Write BufferSize bytes from Lba into Buffer.\r | |
344 | \r | |
345 | @param This Indicates a pointer to the calling context.\r | |
346 | @param MediaId The media ID that the write request is for.\r | |
347 | @param Lba The starting logical block address to be written. The caller is\r | |
348 | responsible for writing to only legitimate locations.\r | |
349 | @param BufferSize Size of Buffer, must be a multiple of device block size.\r | |
350 | @param Buffer A pointer to the source buffer for the data.\r | |
351 | \r | |
352 | @retval EFI_SUCCESS The data was written correctly to the device.\r | |
353 | @retval EFI_WRITE_PROTECTED The device can not be written to.\r | |
354 | @retval EFI_DEVICE_ERROR The device reported an error while performing the write.\r | |
355 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
356 | @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current device.\r | |
357 | @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.\r | |
358 | @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid, \r | |
359 | or the buffer is not on proper alignment.\r | |
360 | \r | |
361 | **/\r | |
362 | EFI_STATUS\r | |
363 | EFIAPI\r | |
364 | BiosWriteLegacyDrive (\r | |
365 | IN EFI_BLOCK_IO_PROTOCOL *This,\r | |
366 | IN UINT32 MediaId,\r | |
367 | IN EFI_LBA Lba,\r | |
368 | IN UINTN BufferSize,\r | |
369 | OUT VOID *Buffer\r | |
370 | );\r | |
371 | \r | |
372 | /**\r | |
373 | Gets parameters of block I/O device.\r | |
374 | \r | |
375 | @param BiosBlockIoDev Instance of block I/O device.\r | |
376 | @param Drive Legacy drive.\r | |
377 | \r | |
378 | @return Result of device parameter retrieval.\r | |
379 | \r | |
380 | **/\r | |
381 | UINTN\r | |
382 | Int13GetDeviceParameters (\r | |
383 | IN BIOS_BLOCK_IO_DEV *BiosBlockIoDev,\r | |
384 | IN BIOS_LEGACY_DRIVE *Drive\r | |
385 | );\r | |
386 | \r | |
387 | /**\r | |
388 | Extension of INT13 call.\r | |
389 | \r | |
390 | @param BiosBlockIoDev Instance of block I/O device.\r | |
391 | @param Drive Legacy drive.\r | |
392 | \r | |
393 | @return Result of this extension.\r | |
394 | \r | |
395 | **/\r | |
396 | UINTN\r | |
397 | Int13Extensions (\r | |
398 | IN BIOS_BLOCK_IO_DEV *BiosBlockIoDev,\r | |
399 | IN BIOS_LEGACY_DRIVE *Drive\r | |
400 | );\r | |
401 | \r | |
402 | /**\r | |
403 | Gets parameters of legacy drive.\r | |
404 | \r | |
405 | @param BiosBlockIoDev Instance of block I/O device.\r | |
406 | @param Drive Legacy drive.\r | |
407 | \r | |
408 | @return Result of drive parameter retrieval.\r | |
409 | \r | |
410 | **/\r | |
411 | UINTN\r | |
412 | GetDriveParameters (\r | |
413 | IN BIOS_BLOCK_IO_DEV *BiosBlockIoDev,\r | |
414 | IN BIOS_LEGACY_DRIVE *Drive\r | |
415 | );\r | |
416 | \r | |
417 | /**\r | |
418 | Build device path for device.\r | |
419 | \r | |
420 | @param BaseDevicePath Base device path.\r | |
421 | @param Drive Legacy drive.\r | |
422 | @param DevicePath Device path for output.\r | |
423 | \r | |
424 | **/\r | |
425 | VOID\r | |
426 | SetBiosInitBlockIoDevicePath (\r | |
427 | IN EFI_DEVICE_PATH_PROTOCOL *BaseDevicePath,\r | |
428 | IN BIOS_LEGACY_DRIVE *Drive,\r | |
429 | OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath\r | |
430 | );\r | |
431 | \r | |
432 | #endif\r |