]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Bus/Isa/IsaFloppyDxe/IsaFloppy.c
IntelFrameworkModulePkg: Clean up source files
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Isa / IsaFloppyDxe / IsaFloppy.c
CommitLineData
d6321d6e 1/** @file\r
2 ISA Floppy Disk UEFI Driver conforming to the UEFI driver model\r
3\r
0a6f4824 4 1. Support two types diskette drive\r
11f43dfd 5 1.44M drive and 2.88M drive (and now only support 1.44M)\r
d6321d6e 6 2. Support two diskette drives per floppy disk controller\r
11f43dfd 7 3. Use DMA channel 2 to transfer data\r
8 4. Do not use interrupt\r
9 5. Support diskette change line signal and write protect\r
0a6f4824
LG
10\r
11Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
180a5a35 12This program and the accompanying materials\r
f8cd287b 13are licensed and made available under the terms and conditions of the BSD License\r
14which accompanies this distribution. The full text of the license may be found at\r
15http://opensource.org/licenses/bsd-license.php\r
11f43dfd 16\r
f8cd287b 17THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
18WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11f43dfd 19\r
f8cd287b 20**/\r
11f43dfd 21\r
22#include "IsaFloppy.h"\r
23\r
d6321d6e 24LIST_ENTRY mControllerHead = INITIALIZE_LIST_HEAD_VARIABLE (mControllerHead);\r
11f43dfd 25\r
26//\r
27// ISA Floppy Driver Binding Protocol\r
28//\r
29EFI_DRIVER_BINDING_PROTOCOL gFdcControllerDriver = {\r
30 FdcControllerDriverSupported,\r
31 FdcControllerDriverStart,\r
32 FdcControllerDriverStop,\r
33 0xa,\r
34 NULL,\r
35 NULL\r
36};\r
37\r
99bda0fd 38\r
39/**\r
d6321d6e 40 The main Entry Point for this driver.\r
99bda0fd 41\r
0a6f4824 42 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
d6321d6e 43 @param[in] SystemTable A pointer to the EFI System Table.\r
0a6f4824 44\r
d6321d6e 45 @retval EFI_SUCCESS The entry point is executed successfully.\r
46 @retval other Some error occurs when executing this entry point.\r
99bda0fd 47**/\r
48EFI_STATUS\r
49EFIAPI\r
50InitializeIsaFloppy(\r
51 IN EFI_HANDLE ImageHandle,\r
52 IN EFI_SYSTEM_TABLE *SystemTable\r
53 )\r
54{\r
d6321d6e 55 EFI_STATUS Status;\r
99bda0fd 56\r
57 //\r
58 // Install driver model protocol(s).\r
59 //\r
f3d08ccf 60 Status = EfiLibInstallDriverBindingComponentName2 (\r
99bda0fd 61 ImageHandle,\r
62 SystemTable,\r
63 &gFdcControllerDriver,\r
64 ImageHandle,\r
65 &gIsaFloppyComponentName,\r
f3d08ccf 66 &gIsaFloppyComponentName2\r
99bda0fd 67 );\r
68 ASSERT_EFI_ERROR (Status);\r
69\r
99bda0fd 70 return Status;\r
71}\r
72\r
bcd70414 73/**\r
d6321d6e 74 Test if the controller is a floppy disk drive device\r
0a6f4824
LG
75\r
76 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
d6321d6e 77 @param[in] Controller The handle of the controller to test.\r
78 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path.\r
0a6f4824 79\r
d6321d6e 80 @retval EFI_SUCCESS The device is supported by this driver.\r
81 @retval EFI_ALREADY_STARTED The device is already being managed by this driver.\r
0a6f4824 82 @retval EFI_ACCESS_DENIED The device is already being managed by a different driver\r
d6321d6e 83 or an application that requires exclusive access.\r
84 @retval EFI_UNSUPPORTED The device is is not supported by this driver.\r
bcd70414 85**/\r
11f43dfd 86EFI_STATUS\r
87EFIAPI\r
88FdcControllerDriverSupported (\r
89 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
90 IN EFI_HANDLE Controller,\r
91 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
92 )\r
11f43dfd 93{\r
d6321d6e 94 EFI_STATUS Status;\r
95 EFI_ISA_IO_PROTOCOL *IsaIo;\r
96 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r
97\r
98 //\r
99 // Ignore the parameter RemainingDevicePath because this is a device driver.\r
100 //\r
101\r
102 //\r
103 // Open the device path protocol\r
104 //\r
105 Status = gBS->OpenProtocol (\r
106 Controller,\r
107 &gEfiDevicePathProtocolGuid,\r
108 (VOID **) &ParentDevicePath,\r
109 This->DriverBindingHandle,\r
110 Controller,\r
111 EFI_OPEN_PROTOCOL_BY_DRIVER\r
112 );\r
113 if (EFI_ERROR (Status)) {\r
114 return Status;\r
115 }\r
116\r
117 gBS->CloseProtocol (\r
118 Controller,\r
119 &gEfiDevicePathProtocolGuid,\r
120 This->DriverBindingHandle,\r
121 Controller\r
122 );\r
11f43dfd 123\r
124 //\r
125 // Open the ISA I/O Protocol\r
126 //\r
127 Status = gBS->OpenProtocol (\r
128 Controller,\r
129 &gEfiIsaIoProtocolGuid,\r
130 (VOID **) &IsaIo,\r
131 This->DriverBindingHandle,\r
132 Controller,\r
133 EFI_OPEN_PROTOCOL_BY_DRIVER\r
134 );\r
135 if (EFI_ERROR (Status)) {\r
136 return Status;\r
137 }\r
138 //\r
d6321d6e 139 // Use the ISA I/O Protocol to see if Controller is a floppy disk drive device\r
11f43dfd 140 //\r
141 Status = EFI_SUCCESS;\r
142 if (IsaIo->ResourceList->Device.HID != EISA_PNP_ID (0x604)) {\r
143 Status = EFI_UNSUPPORTED;\r
144 }\r
145 //\r
146 // Close the ISA I/O Protocol\r
147 //\r
148 gBS->CloseProtocol (\r
149 Controller,\r
150 &gEfiIsaIoProtocolGuid,\r
151 This->DriverBindingHandle,\r
152 Controller\r
153 );\r
154\r
155 return Status;\r
156}\r
157\r
bcd70414 158/**\r
d6321d6e 159 Start this driver on Controller.\r
160\r
161 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
0a6f4824
LG
162 @param[in] ControllerHandle The handle of the controller to start. This handle\r
163 must support a protocol interface that supplies\r
d6321d6e 164 an I/O abstraction to the driver.\r
0a6f4824 165 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path.\r
d6321d6e 166 This parameter is ignored by device drivers, and is optional for bus drivers.\r
167\r
168 @retval EFI_SUCCESS The device was started.\r
169 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.\r
170 Currently not implemented.\r
171 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
172 @retval Others The driver failded to start the device.\r
bcd70414 173**/\r
11f43dfd 174EFI_STATUS\r
175EFIAPI\r
176FdcControllerDriverStart (\r
177 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
178 IN EFI_HANDLE Controller,\r
179 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
180 )\r
11f43dfd 181{\r
d6321d6e 182 EFI_STATUS Status;\r
183 FDC_BLK_IO_DEV *FdcDev;\r
184 EFI_ISA_IO_PROTOCOL *IsaIo;\r
185 UINTN Index;\r
186 LIST_ENTRY *List;\r
187 BOOLEAN Found;\r
188 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r
11f43dfd 189\r
190 FdcDev = NULL;\r
191 IsaIo = NULL;\r
192\r
193 //\r
194 // Open the device path protocol\r
195 //\r
196 Status = gBS->OpenProtocol (\r
197 Controller,\r
198 &gEfiDevicePathProtocolGuid,\r
199 (VOID **) &ParentDevicePath,\r
200 This->DriverBindingHandle,\r
201 Controller,\r
202 EFI_OPEN_PROTOCOL_BY_DRIVER\r
203 );\r
204 if (EFI_ERROR (Status)) {\r
205 return Status;\r
206 }\r
207 //\r
208 // Report enable progress code\r
209 //\r
210 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
211 EFI_PROGRESS_CODE,\r
212 EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_PC_ENABLE,\r
213 ParentDevicePath\r
214 );\r
215\r
216 //\r
217 // Open the ISA I/O Protocol\r
218 //\r
219 Status = gBS->OpenProtocol (\r
220 Controller,\r
221 &gEfiIsaIoProtocolGuid,\r
222 (VOID **) &IsaIo,\r
223 This->DriverBindingHandle,\r
224 Controller,\r
225 EFI_OPEN_PROTOCOL_BY_DRIVER\r
226 );\r
227 if (EFI_ERROR (Status)) {\r
228 goto Done;\r
229 }\r
230 //\r
d6321d6e 231 // Allocate the floppy device's Device structure\r
11f43dfd 232 //\r
233 FdcDev = AllocateZeroPool (sizeof (FDC_BLK_IO_DEV));\r
234 if (FdcDev == NULL) {\r
235 goto Done;\r
236 }\r
237 //\r
d6321d6e 238 // Initialize the floppy device's device structure\r
11f43dfd 239 //\r
240 FdcDev->Signature = FDC_BLK_IO_DEV_SIGNATURE;\r
241 FdcDev->Handle = Controller;\r
242 FdcDev->IsaIo = IsaIo;\r
243 FdcDev->Disk = (EFI_FDC_DISK) IsaIo->ResourceList->Device.UID;\r
244 FdcDev->Cache = NULL;\r
245 FdcDev->Event = NULL;\r
246 FdcDev->ControllerState = NULL;\r
247 FdcDev->DevicePath = ParentDevicePath;\r
248\r
d6321d6e 249 FdcDev->ControllerNameTable = NULL;\r
250 AddName (FdcDev);\r
0a6f4824 251\r
11f43dfd 252 //\r
d6321d6e 253 // Look up the base address of the Floppy Disk Controller which controls this floppy device\r
11f43dfd 254 //\r
255 for (Index = 0; FdcDev->IsaIo->ResourceList->ResourceItem[Index].Type != EfiIsaAcpiResourceEndOfList; Index++) {\r
256 if (FdcDev->IsaIo->ResourceList->ResourceItem[Index].Type == EfiIsaAcpiResourceIo) {\r
257 FdcDev->BaseAddress = (UINT16) FdcDev->IsaIo->ResourceList->ResourceItem[Index].StartRange;\r
258 }\r
259 }\r
260 //\r
d6321d6e 261 // Maintain the list of floppy disk controllers\r
11f43dfd 262 //\r
263 Found = FALSE;\r
d6321d6e 264 List = mControllerHead.ForwardLink;\r
265 while (List != &mControllerHead) {\r
11f43dfd 266 FdcDev->ControllerState = FLOPPY_CONTROLLER_FROM_LIST_ENTRY (List);\r
267 if (FdcDev->BaseAddress == FdcDev->ControllerState->BaseAddress) {\r
268 Found = TRUE;\r
269 break;\r
270 }\r
271\r
272 List = List->ForwardLink;\r
273 }\r
274\r
275 if (!Found) {\r
276 //\r
d6321d6e 277 // A new floppy disk controller controlling this floppy disk drive is found\r
11f43dfd 278 //\r
279 FdcDev->ControllerState = AllocatePool (sizeof (FLOPPY_CONTROLLER_CONTEXT));\r
280 if (FdcDev->ControllerState == NULL) {\r
281 goto Done;\r
282 }\r
283\r
284 FdcDev->ControllerState->Signature = FLOPPY_CONTROLLER_CONTEXT_SIGNATURE;\r
285 FdcDev->ControllerState->FddResetPerformed = FALSE;\r
286 FdcDev->ControllerState->NeedRecalibrate = FALSE;\r
287 FdcDev->ControllerState->BaseAddress = FdcDev->BaseAddress;\r
288 FdcDev->ControllerState->NumberOfDrive = 0;\r
289\r
d6321d6e 290 InsertTailList (&mControllerHead, &FdcDev->ControllerState->Link);\r
11f43dfd 291 }\r
292 //\r
d6321d6e 293 // Create a timer event for each floppy disk drive device.\r
11f43dfd 294 // This timer event is used to control the motor on and off\r
295 //\r
296 Status = gBS->CreateEvent (\r
297 EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
298 TPL_NOTIFY,\r
299 FddTimerProc,\r
300 FdcDev,\r
301 &FdcDev->Event\r
302 );\r
303 if (EFI_ERROR (Status)) {\r
304 goto Done;\r
305 }\r
306 //\r
307 // Reset the Floppy Disk Controller\r
308 //\r
309 if (!FdcDev->ControllerState->FddResetPerformed) {\r
310 FdcDev->ControllerState->FddResetPerformed = TRUE;\r
311 FdcDev->ControllerState->FddResetStatus = FddReset (FdcDev);\r
312 }\r
313\r
314 if (EFI_ERROR (FdcDev->ControllerState->FddResetStatus)) {\r
315 Status = EFI_DEVICE_ERROR;\r
316 goto Done;\r
317 }\r
318\r
319 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
320 EFI_PROGRESS_CODE,\r
321 EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_PC_PRESENCE_DETECT,\r
322 ParentDevicePath\r
323 );\r
324\r
325 //\r
326 // Discover the Floppy Drive\r
327 //\r
328 Status = DiscoverFddDevice (FdcDev);\r
329 if (EFI_ERROR (Status)) {\r
330 Status = EFI_DEVICE_ERROR;\r
331 goto Done;\r
332 }\r
333 //\r
334 // Install protocol interfaces for the serial device.\r
335 //\r
336 Status = gBS->InstallMultipleProtocolInterfaces (\r
337 &Controller,\r
338 &gEfiBlockIoProtocolGuid,\r
339 &FdcDev->BlkIo,\r
340 NULL\r
341 );\r
d6321d6e 342 if (!EFI_ERROR (Status)) {\r
343 FdcDev->ControllerState->NumberOfDrive++;\r
344 }\r
11f43dfd 345\r
346Done:\r
347 if (EFI_ERROR (Status)) {\r
348\r
349 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
350 EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
351 EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_EC_CONTROLLER_ERROR,\r
352 ParentDevicePath\r
353 );\r
354\r
355 //\r
d6321d6e 356 // If a floppy drive device structure was allocated, then free it\r
11f43dfd 357 //\r
d6321d6e 358 if (FdcDev != NULL) {\r
359 if (FdcDev->Event != NULL) {\r
360 //\r
361 // Close the event for turning the motor off\r
362 //\r
363 gBS->CloseEvent (FdcDev->Event);\r
364 }\r
365\r
366 FreeUnicodeStringTable (FdcDev->ControllerNameTable);\r
367 FreePool (FdcDev);\r
368 }\r
11f43dfd 369\r
370 //\r
371 // Close the ISA I/O Protocol\r
372 //\r
373 if (IsaIo != NULL) {\r
374 gBS->CloseProtocol (\r
375 Controller,\r
376 &gEfiIsaIoProtocolGuid,\r
377 This->DriverBindingHandle,\r
378 Controller\r
379 );\r
380 }\r
d6321d6e 381\r
11f43dfd 382 //\r
d6321d6e 383 // Close the device path protocol\r
11f43dfd 384 //\r
d6321d6e 385 gBS->CloseProtocol (\r
386 Controller,\r
387 &gEfiDevicePathProtocolGuid,\r
388 This->DriverBindingHandle,\r
389 Controller\r
390 );\r
11f43dfd 391 }\r
392\r
393 return Status;\r
394}\r
395\r
bcd70414 396/**\r
d6321d6e 397 Stop this driver on ControllerHandle.\r
398\r
399 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
0a6f4824
LG
400 @param[in] ControllerHandle A handle to the device being stopped. The handle must\r
401 support a bus specific I/O protocol for the driver\r
d6321d6e 402 to use to stop the device.\r
403 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r
0a6f4824 404 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r
d6321d6e 405 if NumberOfChildren is 0.\r
406\r
407 @retval EFI_SUCCESS The device was stopped.\r
408 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
bcd70414 409**/\r
11f43dfd 410EFI_STATUS\r
411EFIAPI\r
412FdcControllerDriverStop (\r
413 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
414 IN EFI_HANDLE Controller,\r
415 IN UINTN NumberOfChildren,\r
416 IN EFI_HANDLE *ChildHandleBuffer\r
417 )\r
11f43dfd 418{\r
419 EFI_STATUS Status;\r
420 EFI_BLOCK_IO_PROTOCOL *BlkIo;\r
421 FDC_BLK_IO_DEV *FdcDev;\r
422\r
d6321d6e 423 //\r
424 // Ignore NumberOfChildren since this is a device driver\r
425 //\r
426\r
11f43dfd 427 //\r
428 // Get the Block I/O Protocol on Controller\r
429 //\r
430 Status = gBS->OpenProtocol (\r
431 Controller,\r
432 &gEfiBlockIoProtocolGuid,\r
433 (VOID **) &BlkIo,\r
434 This->DriverBindingHandle,\r
435 Controller,\r
436 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
437 );\r
438 if (EFI_ERROR (Status)) {\r
439 return Status;\r
440 }\r
441 //\r
d6321d6e 442 // Get the floppy drive device's Device structure\r
11f43dfd 443 //\r
444 FdcDev = FDD_BLK_IO_FROM_THIS (BlkIo);\r
445\r
446 //\r
447 // Report disable progress code\r
448 //\r
449 REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r
450 EFI_PROGRESS_CODE,\r
451 EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_PC_DISABLE,\r
452 FdcDev->DevicePath\r
453 );\r
454\r
11f43dfd 455 //\r
456 // Uninstall the Block I/O Protocol\r
457 //\r
458 Status = gBS->UninstallProtocolInterface (\r
459 Controller,\r
460 &gEfiBlockIoProtocolGuid,\r
461 &FdcDev->BlkIo\r
462 );\r
463 if (EFI_ERROR (Status)) {\r
464 return Status;\r
465 }\r
d6321d6e 466\r
467 //\r
468 // Close the event for turning the motor off\r
469 //\r
470 gBS->CloseEvent (FdcDev->Event);\r
471\r
472 //\r
473 // Turn the motor off on the floppy drive device\r
474 //\r
475 FddTimerProc (FdcDev->Event, FdcDev);\r
476\r
11f43dfd 477 //\r
478 // Close the device path protocol\r
479 //\r
480 gBS->CloseProtocol (\r
481 Controller,\r
482 &gEfiDevicePathProtocolGuid,\r
483 This->DriverBindingHandle,\r
484 Controller\r
485 );\r
486\r
487 //\r
488 // Close the ISA I/O Protocol\r
489 //\r
490 gBS->CloseProtocol (\r
491 Controller,\r
492 &gEfiIsaIoProtocolGuid,\r
493 This->DriverBindingHandle,\r
494 Controller\r
495 );\r
496\r
497 //\r
498 // Free the controller list if needed\r
499 //\r
500 FdcDev->ControllerState->NumberOfDrive--;\r
501\r
11f43dfd 502 //\r
503 // Free the cache if one was allocated\r
504 //\r
505 FdcFreeCache (FdcDev);\r
506\r
507 //\r
d6321d6e 508 // Free the floppy drive device's device structure\r
11f43dfd 509 //\r
510 FreeUnicodeStringTable (FdcDev->ControllerNameTable);\r
d6321d6e 511 FreePool (FdcDev);\r
11f43dfd 512\r
513 return EFI_SUCCESS;\r
514}\r
bcd70414 515\r