]>
Commit | Line | Data |
---|---|---|
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 |
12 | Copyright (c) 2006 - 2007, Intel Corporation.<BR>\r | |
13 | All rights reserved. This program and the accompanying materials\r | |
14 | are licensed and made available under the terms and conditions of the BSD License\r | |
15 | which accompanies this distribution. The full text of the license may be found at\r | |
16 | http://opensource.org/licenses/bsd-license.php\r | |
11f43dfd | 17 | \r |
f8cd287b | 18 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r |
19 | WITHOUT 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 | |
25 | LIST_ENTRY gControllerHead = INITIALIZE_LIST_HEAD_VARIABLE(gControllerHead);\r | |
26 | \r | |
27 | //\r | |
28 | // ISA Floppy Driver Binding Protocol\r | |
29 | //\r | |
30 | EFI_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 | |
50 | EFI_STATUS\r | |
51 | EFIAPI\r | |
52 | InitializeIsaFloppy(\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 | |
f3d08ccf | 62 | Status = EfiLibInstallDriverBindingComponentName2 (\r |
99bda0fd | 63 | ImageHandle,\r |
64 | SystemTable,\r | |
65 | &gFdcControllerDriver,\r | |
66 | ImageHandle,\r | |
67 | &gIsaFloppyComponentName,\r | |
f3d08ccf | 68 | &gIsaFloppyComponentName2\r |
99bda0fd | 69 | );\r |
70 | ASSERT_EFI_ERROR (Status);\r | |
71 | \r | |
72 | \r | |
73 | return Status;\r | |
74 | }\r | |
75 | \r | |
bcd70414 | 76 | /**\r |
77 | Test controller is a Floppy Disk Controller\r | |
78 | \r | |
79 | @param This Pointer of EFI_DRIVER_BINDING_PROTOCOL\r | |
80 | @param Controller driver's controller\r | |
81 | @param RemainingDevicePath children device path\r | |
82 | \r | |
83 | @retval EFI_UNSUPPORTED controller is not floppy disk\r | |
84 | @retval EFI_SUCCESS controller is floppy disk\r | |
85 | **/\r | |
11f43dfd | 86 | EFI_STATUS\r |
87 | EFIAPI\r | |
88 | FdcControllerDriverSupported (\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 |
94 | EFI_STATUS Status;\r | |
95 | EFI_ISA_IO_PROTOCOL *IsaIo;\r | |
96 | \r | |
97 | //\r | |
98 | // Open the ISA I/O Protocol\r | |
99 | //\r | |
100 | Status = gBS->OpenProtocol (\r | |
101 | Controller,\r | |
102 | &gEfiIsaIoProtocolGuid,\r | |
103 | (VOID **) &IsaIo,\r | |
104 | This->DriverBindingHandle,\r | |
105 | Controller,\r | |
106 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
107 | );\r | |
108 | if (EFI_ERROR (Status)) {\r | |
109 | return Status;\r | |
110 | }\r | |
111 | //\r | |
112 | // Use the ISA I/O Protocol to see if Controller is a Floppy Disk Controller\r | |
113 | //\r | |
114 | Status = EFI_SUCCESS;\r | |
115 | if (IsaIo->ResourceList->Device.HID != EISA_PNP_ID (0x604)) {\r | |
116 | Status = EFI_UNSUPPORTED;\r | |
117 | }\r | |
118 | //\r | |
119 | // Close the ISA I/O Protocol\r | |
120 | //\r | |
121 | gBS->CloseProtocol (\r | |
122 | Controller,\r | |
123 | &gEfiIsaIoProtocolGuid,\r | |
124 | This->DriverBindingHandle,\r | |
125 | Controller\r | |
126 | );\r | |
127 | \r | |
128 | return Status;\r | |
129 | }\r | |
130 | \r | |
bcd70414 | 131 | /**\r |
132 | Create floppy control instance on controller.\r | |
133 | \r | |
134 | @param This Pointer of EFI_DRIVER_BINDING_PROTOCOL\r | |
135 | @param Controller driver controller handle\r | |
136 | @param RemainingDevicePath Children's device path\r | |
137 | \r | |
138 | @retval whether success to create floppy control instance.\r | |
139 | **/\r | |
11f43dfd | 140 | EFI_STATUS\r |
141 | EFIAPI\r | |
142 | FdcControllerDriverStart (\r | |
143 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
144 | IN EFI_HANDLE Controller,\r | |
145 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
146 | )\r | |
11f43dfd | 147 | {\r |
148 | EFI_STATUS Status;\r | |
149 | FDC_BLK_IO_DEV *FdcDev;\r | |
150 | EFI_ISA_IO_PROTOCOL *IsaIo;\r | |
151 | UINTN Index;\r | |
152 | LIST_ENTRY *List;\r | |
153 | BOOLEAN Found;\r | |
154 | EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r | |
155 | \r | |
156 | FdcDev = NULL;\r | |
157 | IsaIo = NULL;\r | |
158 | \r | |
159 | //\r | |
160 | // Open the device path protocol\r | |
161 | //\r | |
162 | Status = gBS->OpenProtocol (\r | |
163 | Controller,\r | |
164 | &gEfiDevicePathProtocolGuid,\r | |
165 | (VOID **) &ParentDevicePath,\r | |
166 | This->DriverBindingHandle,\r | |
167 | Controller,\r | |
168 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
169 | );\r | |
170 | if (EFI_ERROR (Status)) {\r | |
171 | return Status;\r | |
172 | }\r | |
173 | //\r | |
174 | // Report enable progress code\r | |
175 | //\r | |
176 | REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r | |
177 | EFI_PROGRESS_CODE,\r | |
178 | EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_PC_ENABLE,\r | |
179 | ParentDevicePath\r | |
180 | );\r | |
181 | \r | |
182 | //\r | |
183 | // Open the ISA I/O Protocol\r | |
184 | //\r | |
185 | Status = gBS->OpenProtocol (\r | |
186 | Controller,\r | |
187 | &gEfiIsaIoProtocolGuid,\r | |
188 | (VOID **) &IsaIo,\r | |
189 | This->DriverBindingHandle,\r | |
190 | Controller,\r | |
191 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
192 | );\r | |
193 | if (EFI_ERROR (Status)) {\r | |
194 | goto Done;\r | |
195 | }\r | |
196 | //\r | |
197 | // Allocate the Floppy Disk Controller's Device structure\r | |
198 | //\r | |
199 | FdcDev = AllocateZeroPool (sizeof (FDC_BLK_IO_DEV));\r | |
200 | if (FdcDev == NULL) {\r | |
201 | goto Done;\r | |
202 | }\r | |
203 | //\r | |
204 | // Initialize the Floppy Disk Controller's Device structure\r | |
205 | //\r | |
206 | FdcDev->Signature = FDC_BLK_IO_DEV_SIGNATURE;\r | |
207 | FdcDev->Handle = Controller;\r | |
208 | FdcDev->IsaIo = IsaIo;\r | |
209 | FdcDev->Disk = (EFI_FDC_DISK) IsaIo->ResourceList->Device.UID;\r | |
210 | FdcDev->Cache = NULL;\r | |
211 | FdcDev->Event = NULL;\r | |
212 | FdcDev->ControllerState = NULL;\r | |
213 | FdcDev->DevicePath = ParentDevicePath;\r | |
214 | \r | |
215 | ADD_FLOPPY_NAME (FdcDev);\r | |
216 | \r | |
217 | //\r | |
218 | // Look up the base address of the Floppy Disk Controller\r | |
219 | //\r | |
220 | for (Index = 0; FdcDev->IsaIo->ResourceList->ResourceItem[Index].Type != EfiIsaAcpiResourceEndOfList; Index++) {\r | |
221 | if (FdcDev->IsaIo->ResourceList->ResourceItem[Index].Type == EfiIsaAcpiResourceIo) {\r | |
222 | FdcDev->BaseAddress = (UINT16) FdcDev->IsaIo->ResourceList->ResourceItem[Index].StartRange;\r | |
223 | }\r | |
224 | }\r | |
225 | //\r | |
226 | // Maintain the list of controller list\r | |
227 | //\r | |
228 | Found = FALSE;\r | |
229 | List = gControllerHead.ForwardLink;\r | |
230 | while (List != &gControllerHead) {\r | |
231 | FdcDev->ControllerState = FLOPPY_CONTROLLER_FROM_LIST_ENTRY (List);\r | |
232 | if (FdcDev->BaseAddress == FdcDev->ControllerState->BaseAddress) {\r | |
233 | Found = TRUE;\r | |
234 | break;\r | |
235 | }\r | |
236 | \r | |
237 | List = List->ForwardLink;\r | |
238 | }\r | |
239 | \r | |
240 | if (!Found) {\r | |
241 | //\r | |
242 | // The Controller is new\r | |
243 | //\r | |
244 | FdcDev->ControllerState = AllocatePool (sizeof (FLOPPY_CONTROLLER_CONTEXT));\r | |
245 | if (FdcDev->ControllerState == NULL) {\r | |
246 | goto Done;\r | |
247 | }\r | |
248 | \r | |
249 | FdcDev->ControllerState->Signature = FLOPPY_CONTROLLER_CONTEXT_SIGNATURE;\r | |
250 | FdcDev->ControllerState->FddResetPerformed = FALSE;\r | |
251 | FdcDev->ControllerState->NeedRecalibrate = FALSE;\r | |
252 | FdcDev->ControllerState->BaseAddress = FdcDev->BaseAddress;\r | |
253 | FdcDev->ControllerState->NumberOfDrive = 0;\r | |
254 | \r | |
255 | InsertTailList (&gControllerHead, &FdcDev->ControllerState->Link);\r | |
256 | }\r | |
257 | //\r | |
258 | // Create a timer event for each Floppd Disk Controller.\r | |
259 | // This timer event is used to control the motor on and off\r | |
260 | //\r | |
261 | Status = gBS->CreateEvent (\r | |
262 | EVT_TIMER | EVT_NOTIFY_SIGNAL,\r | |
263 | TPL_NOTIFY,\r | |
264 | FddTimerProc,\r | |
265 | FdcDev,\r | |
266 | &FdcDev->Event\r | |
267 | );\r | |
268 | if (EFI_ERROR (Status)) {\r | |
269 | goto Done;\r | |
270 | }\r | |
271 | //\r | |
272 | // Reset the Floppy Disk Controller\r | |
273 | //\r | |
274 | if (!FdcDev->ControllerState->FddResetPerformed) {\r | |
275 | FdcDev->ControllerState->FddResetPerformed = TRUE;\r | |
276 | FdcDev->ControllerState->FddResetStatus = FddReset (FdcDev);\r | |
277 | }\r | |
278 | \r | |
279 | if (EFI_ERROR (FdcDev->ControllerState->FddResetStatus)) {\r | |
280 | Status = EFI_DEVICE_ERROR;\r | |
281 | goto Done;\r | |
282 | }\r | |
283 | \r | |
284 | REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r | |
285 | EFI_PROGRESS_CODE,\r | |
286 | EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_PC_PRESENCE_DETECT,\r | |
287 | ParentDevicePath\r | |
288 | );\r | |
289 | \r | |
290 | //\r | |
291 | // Discover the Floppy Drive\r | |
292 | //\r | |
293 | Status = DiscoverFddDevice (FdcDev);\r | |
294 | if (EFI_ERROR (Status)) {\r | |
295 | Status = EFI_DEVICE_ERROR;\r | |
296 | goto Done;\r | |
297 | }\r | |
298 | //\r | |
299 | // Install protocol interfaces for the serial device.\r | |
300 | //\r | |
301 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
302 | &Controller,\r | |
303 | &gEfiBlockIoProtocolGuid,\r | |
304 | &FdcDev->BlkIo,\r | |
305 | NULL\r | |
306 | );\r | |
307 | \r | |
308 | FdcDev->ControllerState->NumberOfDrive++;\r | |
309 | \r | |
310 | Done:\r | |
311 | if (EFI_ERROR (Status)) {\r | |
312 | \r | |
313 | REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r | |
314 | EFI_ERROR_CODE | EFI_ERROR_MINOR,\r | |
315 | EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_EC_CONTROLLER_ERROR,\r | |
316 | ParentDevicePath\r | |
317 | );\r | |
318 | \r | |
319 | //\r | |
320 | // Close the device path protocol\r | |
321 | //\r | |
322 | gBS->CloseProtocol (\r | |
323 | Controller,\r | |
324 | &gEfiDevicePathProtocolGuid,\r | |
325 | This->DriverBindingHandle,\r | |
326 | Controller\r | |
327 | );\r | |
328 | \r | |
329 | //\r | |
330 | // Close the ISA I/O Protocol\r | |
331 | //\r | |
332 | if (IsaIo != NULL) {\r | |
333 | gBS->CloseProtocol (\r | |
334 | Controller,\r | |
335 | &gEfiIsaIoProtocolGuid,\r | |
336 | This->DriverBindingHandle,\r | |
337 | Controller\r | |
338 | );\r | |
339 | }\r | |
340 | //\r | |
341 | // If a Floppy Disk Controller Device structure was allocated, then free it\r | |
342 | //\r | |
343 | if (FdcDev != NULL) {\r | |
344 | if (FdcDev->Event != NULL) {\r | |
345 | //\r | |
346 | // Close the event for turning the motor off\r | |
347 | //\r | |
348 | gBS->CloseEvent (FdcDev->Event);\r | |
349 | }\r | |
350 | \r | |
351 | FreeUnicodeStringTable (FdcDev->ControllerNameTable);\r | |
352 | gBS->FreePool (FdcDev);\r | |
353 | }\r | |
354 | }\r | |
355 | \r | |
356 | return Status;\r | |
357 | }\r | |
358 | \r | |
bcd70414 | 359 | /**\r |
360 | Stop this driver on ControllerHandle. Support stoping any child handles\r | |
361 | created by this driver.\r | |
362 | \r | |
363 | @param This Protocol instance pointer.\r | |
fdb05fa3 | 364 | @param Controller Handle of device to stop driver on\r |
bcd70414 | 365 | @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r |
366 | children is zero stop the entire bus driver.\r | |
367 | @param ChildHandleBuffer List of Child Handles to Stop.\r | |
368 | \r | |
369 | @retval EFI_SUCCESS This driver is removed ControllerHandle\r | |
370 | @retval other This driver was not removed from this device\r | |
371 | \r | |
372 | **/\r | |
11f43dfd | 373 | EFI_STATUS\r |
374 | EFIAPI\r | |
375 | FdcControllerDriverStop (\r | |
376 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
377 | IN EFI_HANDLE Controller,\r | |
378 | IN UINTN NumberOfChildren,\r | |
379 | IN EFI_HANDLE *ChildHandleBuffer\r | |
380 | )\r | |
11f43dfd | 381 | {\r |
382 | EFI_STATUS Status;\r | |
383 | EFI_BLOCK_IO_PROTOCOL *BlkIo;\r | |
384 | FDC_BLK_IO_DEV *FdcDev;\r | |
385 | \r | |
386 | //\r | |
387 | // Get the Block I/O Protocol on Controller\r | |
388 | //\r | |
389 | Status = gBS->OpenProtocol (\r | |
390 | Controller,\r | |
391 | &gEfiBlockIoProtocolGuid,\r | |
392 | (VOID **) &BlkIo,\r | |
393 | This->DriverBindingHandle,\r | |
394 | Controller,\r | |
395 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
396 | );\r | |
397 | if (EFI_ERROR (Status)) {\r | |
398 | return Status;\r | |
399 | }\r | |
400 | //\r | |
401 | // Get the Floppy Disk Controller's Device structure\r | |
402 | //\r | |
403 | FdcDev = FDD_BLK_IO_FROM_THIS (BlkIo);\r | |
404 | \r | |
405 | //\r | |
406 | // Report disable progress code\r | |
407 | //\r | |
408 | REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r | |
409 | EFI_PROGRESS_CODE,\r | |
410 | EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_PC_DISABLE,\r | |
411 | FdcDev->DevicePath\r | |
412 | );\r | |
413 | \r | |
414 | //\r | |
415 | // Turn the motor off on the Floppy Disk Controller\r | |
416 | //\r | |
417 | FddTimerProc (FdcDev->Event, FdcDev);\r | |
418 | \r | |
419 | //\r | |
420 | // Uninstall the Block I/O Protocol\r | |
421 | //\r | |
422 | Status = gBS->UninstallProtocolInterface (\r | |
423 | Controller,\r | |
424 | &gEfiBlockIoProtocolGuid,\r | |
425 | &FdcDev->BlkIo\r | |
426 | );\r | |
427 | if (EFI_ERROR (Status)) {\r | |
428 | return Status;\r | |
429 | }\r | |
430 | //\r | |
431 | // Close the device path protocol\r | |
432 | //\r | |
433 | gBS->CloseProtocol (\r | |
434 | Controller,\r | |
435 | &gEfiDevicePathProtocolGuid,\r | |
436 | This->DriverBindingHandle,\r | |
437 | Controller\r | |
438 | );\r | |
439 | \r | |
440 | //\r | |
441 | // Close the ISA I/O Protocol\r | |
442 | //\r | |
443 | gBS->CloseProtocol (\r | |
444 | Controller,\r | |
445 | &gEfiIsaIoProtocolGuid,\r | |
446 | This->DriverBindingHandle,\r | |
447 | Controller\r | |
448 | );\r | |
449 | \r | |
450 | //\r | |
451 | // Free the controller list if needed\r | |
452 | //\r | |
453 | FdcDev->ControllerState->NumberOfDrive--;\r | |
454 | \r | |
455 | //\r | |
456 | // Close the event for turning the motor off\r | |
457 | //\r | |
458 | gBS->CloseEvent (FdcDev->Event);\r | |
459 | \r | |
460 | //\r | |
461 | // Free the cache if one was allocated\r | |
462 | //\r | |
463 | FdcFreeCache (FdcDev);\r | |
464 | \r | |
465 | //\r | |
466 | // Free the Floppy Disk Controller's Device structure\r | |
467 | //\r | |
468 | FreeUnicodeStringTable (FdcDev->ControllerNameTable);\r | |
469 | gBS->FreePool (FdcDev);\r | |
470 | \r | |
471 | return EFI_SUCCESS;\r | |
472 | }\r | |
bcd70414 | 473 | \r |