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