]>
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 | |
76 | \r | |
11f43dfd | 77 | EFI_STATUS\r |
78 | EFIAPI\r | |
79 | FdcControllerDriverSupported (\r | |
80 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
81 | IN EFI_HANDLE Controller,\r | |
82 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
83 | )\r | |
84 | /*++\r | |
85 | \r | |
86 | Routine Description:\r | |
87 | \r | |
88 | ControllerDriver Protocol Method\r | |
89 | \r | |
90 | Arguments:\r | |
91 | \r | |
92 | Returns:\r | |
93 | \r | |
94 | --*/\r | |
95 | // GC_TODO: This - add argument and description to function comment\r | |
96 | // GC_TODO: Controller - add argument and description to function comment\r | |
97 | // GC_TODO: RemainingDevicePath - add argument and description to function comment\r | |
98 | {\r | |
99 | EFI_STATUS Status;\r | |
100 | EFI_ISA_IO_PROTOCOL *IsaIo;\r | |
101 | \r | |
102 | //\r | |
103 | // Open the ISA I/O Protocol\r | |
104 | //\r | |
105 | Status = gBS->OpenProtocol (\r | |
106 | Controller,\r | |
107 | &gEfiIsaIoProtocolGuid,\r | |
108 | (VOID **) &IsaIo,\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 | // Use the ISA I/O Protocol to see if Controller is a Floppy Disk Controller\r | |
118 | //\r | |
119 | Status = EFI_SUCCESS;\r | |
120 | if (IsaIo->ResourceList->Device.HID != EISA_PNP_ID (0x604)) {\r | |
121 | Status = EFI_UNSUPPORTED;\r | |
122 | }\r | |
123 | //\r | |
124 | // Close the ISA I/O Protocol\r | |
125 | //\r | |
126 | gBS->CloseProtocol (\r | |
127 | Controller,\r | |
128 | &gEfiIsaIoProtocolGuid,\r | |
129 | This->DriverBindingHandle,\r | |
130 | Controller\r | |
131 | );\r | |
132 | \r | |
133 | return Status;\r | |
134 | }\r | |
135 | \r | |
136 | EFI_STATUS\r | |
137 | EFIAPI\r | |
138 | FdcControllerDriverStart (\r | |
139 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
140 | IN EFI_HANDLE Controller,\r | |
141 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r | |
142 | )\r | |
143 | /*++\r | |
144 | \r | |
145 | Routine Description:\r | |
146 | \r | |
147 | Arguments:\r | |
148 | \r | |
149 | Returns:\r | |
150 | \r | |
151 | --*/\r | |
152 | // GC_TODO: This - add argument and description to function comment\r | |
153 | // GC_TODO: Controller - add argument and description to function comment\r | |
154 | // GC_TODO: RemainingDevicePath - add argument and description to function comment\r | |
155 | {\r | |
156 | EFI_STATUS Status;\r | |
157 | FDC_BLK_IO_DEV *FdcDev;\r | |
158 | EFI_ISA_IO_PROTOCOL *IsaIo;\r | |
159 | UINTN Index;\r | |
160 | LIST_ENTRY *List;\r | |
161 | BOOLEAN Found;\r | |
162 | EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r | |
163 | \r | |
164 | FdcDev = NULL;\r | |
165 | IsaIo = NULL;\r | |
166 | \r | |
167 | //\r | |
168 | // Open the device path protocol\r | |
169 | //\r | |
170 | Status = gBS->OpenProtocol (\r | |
171 | Controller,\r | |
172 | &gEfiDevicePathProtocolGuid,\r | |
173 | (VOID **) &ParentDevicePath,\r | |
174 | This->DriverBindingHandle,\r | |
175 | Controller,\r | |
176 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
177 | );\r | |
178 | if (EFI_ERROR (Status)) {\r | |
179 | return Status;\r | |
180 | }\r | |
181 | //\r | |
182 | // Report enable progress code\r | |
183 | //\r | |
184 | REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r | |
185 | EFI_PROGRESS_CODE,\r | |
186 | EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_PC_ENABLE,\r | |
187 | ParentDevicePath\r | |
188 | );\r | |
189 | \r | |
190 | //\r | |
191 | // Open the ISA I/O Protocol\r | |
192 | //\r | |
193 | Status = gBS->OpenProtocol (\r | |
194 | Controller,\r | |
195 | &gEfiIsaIoProtocolGuid,\r | |
196 | (VOID **) &IsaIo,\r | |
197 | This->DriverBindingHandle,\r | |
198 | Controller,\r | |
199 | EFI_OPEN_PROTOCOL_BY_DRIVER\r | |
200 | );\r | |
201 | if (EFI_ERROR (Status)) {\r | |
202 | goto Done;\r | |
203 | }\r | |
204 | //\r | |
205 | // Allocate the Floppy Disk Controller's Device structure\r | |
206 | //\r | |
207 | FdcDev = AllocateZeroPool (sizeof (FDC_BLK_IO_DEV));\r | |
208 | if (FdcDev == NULL) {\r | |
209 | goto Done;\r | |
210 | }\r | |
211 | //\r | |
212 | // Initialize the Floppy Disk Controller's Device structure\r | |
213 | //\r | |
214 | FdcDev->Signature = FDC_BLK_IO_DEV_SIGNATURE;\r | |
215 | FdcDev->Handle = Controller;\r | |
216 | FdcDev->IsaIo = IsaIo;\r | |
217 | FdcDev->Disk = (EFI_FDC_DISK) IsaIo->ResourceList->Device.UID;\r | |
218 | FdcDev->Cache = NULL;\r | |
219 | FdcDev->Event = NULL;\r | |
220 | FdcDev->ControllerState = NULL;\r | |
221 | FdcDev->DevicePath = ParentDevicePath;\r | |
222 | \r | |
223 | ADD_FLOPPY_NAME (FdcDev);\r | |
224 | \r | |
225 | //\r | |
226 | // Look up the base address of the Floppy Disk Controller\r | |
227 | //\r | |
228 | for (Index = 0; FdcDev->IsaIo->ResourceList->ResourceItem[Index].Type != EfiIsaAcpiResourceEndOfList; Index++) {\r | |
229 | if (FdcDev->IsaIo->ResourceList->ResourceItem[Index].Type == EfiIsaAcpiResourceIo) {\r | |
230 | FdcDev->BaseAddress = (UINT16) FdcDev->IsaIo->ResourceList->ResourceItem[Index].StartRange;\r | |
231 | }\r | |
232 | }\r | |
233 | //\r | |
234 | // Maintain the list of controller list\r | |
235 | //\r | |
236 | Found = FALSE;\r | |
237 | List = gControllerHead.ForwardLink;\r | |
238 | while (List != &gControllerHead) {\r | |
239 | FdcDev->ControllerState = FLOPPY_CONTROLLER_FROM_LIST_ENTRY (List);\r | |
240 | if (FdcDev->BaseAddress == FdcDev->ControllerState->BaseAddress) {\r | |
241 | Found = TRUE;\r | |
242 | break;\r | |
243 | }\r | |
244 | \r | |
245 | List = List->ForwardLink;\r | |
246 | }\r | |
247 | \r | |
248 | if (!Found) {\r | |
249 | //\r | |
250 | // The Controller is new\r | |
251 | //\r | |
252 | FdcDev->ControllerState = AllocatePool (sizeof (FLOPPY_CONTROLLER_CONTEXT));\r | |
253 | if (FdcDev->ControllerState == NULL) {\r | |
254 | goto Done;\r | |
255 | }\r | |
256 | \r | |
257 | FdcDev->ControllerState->Signature = FLOPPY_CONTROLLER_CONTEXT_SIGNATURE;\r | |
258 | FdcDev->ControllerState->FddResetPerformed = FALSE;\r | |
259 | FdcDev->ControllerState->NeedRecalibrate = FALSE;\r | |
260 | FdcDev->ControllerState->BaseAddress = FdcDev->BaseAddress;\r | |
261 | FdcDev->ControllerState->NumberOfDrive = 0;\r | |
262 | \r | |
263 | InsertTailList (&gControllerHead, &FdcDev->ControllerState->Link);\r | |
264 | }\r | |
265 | //\r | |
266 | // Create a timer event for each Floppd Disk Controller.\r | |
267 | // This timer event is used to control the motor on and off\r | |
268 | //\r | |
269 | Status = gBS->CreateEvent (\r | |
270 | EVT_TIMER | EVT_NOTIFY_SIGNAL,\r | |
271 | TPL_NOTIFY,\r | |
272 | FddTimerProc,\r | |
273 | FdcDev,\r | |
274 | &FdcDev->Event\r | |
275 | );\r | |
276 | if (EFI_ERROR (Status)) {\r | |
277 | goto Done;\r | |
278 | }\r | |
279 | //\r | |
280 | // Reset the Floppy Disk Controller\r | |
281 | //\r | |
282 | if (!FdcDev->ControllerState->FddResetPerformed) {\r | |
283 | FdcDev->ControllerState->FddResetPerformed = TRUE;\r | |
284 | FdcDev->ControllerState->FddResetStatus = FddReset (FdcDev);\r | |
285 | }\r | |
286 | \r | |
287 | if (EFI_ERROR (FdcDev->ControllerState->FddResetStatus)) {\r | |
288 | Status = EFI_DEVICE_ERROR;\r | |
289 | goto Done;\r | |
290 | }\r | |
291 | \r | |
292 | REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r | |
293 | EFI_PROGRESS_CODE,\r | |
294 | EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_PC_PRESENCE_DETECT,\r | |
295 | ParentDevicePath\r | |
296 | );\r | |
297 | \r | |
298 | //\r | |
299 | // Discover the Floppy Drive\r | |
300 | //\r | |
301 | Status = DiscoverFddDevice (FdcDev);\r | |
302 | if (EFI_ERROR (Status)) {\r | |
303 | Status = EFI_DEVICE_ERROR;\r | |
304 | goto Done;\r | |
305 | }\r | |
306 | //\r | |
307 | // Install protocol interfaces for the serial device.\r | |
308 | //\r | |
309 | Status = gBS->InstallMultipleProtocolInterfaces (\r | |
310 | &Controller,\r | |
311 | &gEfiBlockIoProtocolGuid,\r | |
312 | &FdcDev->BlkIo,\r | |
313 | NULL\r | |
314 | );\r | |
315 | \r | |
316 | FdcDev->ControllerState->NumberOfDrive++;\r | |
317 | \r | |
318 | Done:\r | |
319 | if (EFI_ERROR (Status)) {\r | |
320 | \r | |
321 | REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r | |
322 | EFI_ERROR_CODE | EFI_ERROR_MINOR,\r | |
323 | EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_EC_CONTROLLER_ERROR,\r | |
324 | ParentDevicePath\r | |
325 | );\r | |
326 | \r | |
327 | //\r | |
328 | // Close the device path protocol\r | |
329 | //\r | |
330 | gBS->CloseProtocol (\r | |
331 | Controller,\r | |
332 | &gEfiDevicePathProtocolGuid,\r | |
333 | This->DriverBindingHandle,\r | |
334 | Controller\r | |
335 | );\r | |
336 | \r | |
337 | //\r | |
338 | // Close the ISA I/O Protocol\r | |
339 | //\r | |
340 | if (IsaIo != NULL) {\r | |
341 | gBS->CloseProtocol (\r | |
342 | Controller,\r | |
343 | &gEfiIsaIoProtocolGuid,\r | |
344 | This->DriverBindingHandle,\r | |
345 | Controller\r | |
346 | );\r | |
347 | }\r | |
348 | //\r | |
349 | // If a Floppy Disk Controller Device structure was allocated, then free it\r | |
350 | //\r | |
351 | if (FdcDev != NULL) {\r | |
352 | if (FdcDev->Event != NULL) {\r | |
353 | //\r | |
354 | // Close the event for turning the motor off\r | |
355 | //\r | |
356 | gBS->CloseEvent (FdcDev->Event);\r | |
357 | }\r | |
358 | \r | |
359 | FreeUnicodeStringTable (FdcDev->ControllerNameTable);\r | |
360 | gBS->FreePool (FdcDev);\r | |
361 | }\r | |
362 | }\r | |
363 | \r | |
364 | return Status;\r | |
365 | }\r | |
366 | \r | |
367 | EFI_STATUS\r | |
368 | EFIAPI\r | |
369 | FdcControllerDriverStop (\r | |
370 | IN EFI_DRIVER_BINDING_PROTOCOL *This,\r | |
371 | IN EFI_HANDLE Controller,\r | |
372 | IN UINTN NumberOfChildren,\r | |
373 | IN EFI_HANDLE *ChildHandleBuffer\r | |
374 | )\r | |
375 | /*++\r | |
376 | \r | |
377 | Routine Description:\r | |
378 | \r | |
379 | Arguments:\r | |
380 | \r | |
381 | Returns:\r | |
382 | \r | |
383 | --*/\r | |
384 | // GC_TODO: This - add argument and description to function comment\r | |
385 | // GC_TODO: Controller - add argument and description to function comment\r | |
386 | // GC_TODO: NumberOfChildren - add argument and description to function comment\r | |
387 | // GC_TODO: ChildHandleBuffer - add argument and description to function comment\r | |
388 | // GC_TODO: EFI_SUCCESS - add return value to function comment\r | |
389 | {\r | |
390 | EFI_STATUS Status;\r | |
391 | EFI_BLOCK_IO_PROTOCOL *BlkIo;\r | |
392 | FDC_BLK_IO_DEV *FdcDev;\r | |
393 | \r | |
394 | //\r | |
395 | // Get the Block I/O Protocol on Controller\r | |
396 | //\r | |
397 | Status = gBS->OpenProtocol (\r | |
398 | Controller,\r | |
399 | &gEfiBlockIoProtocolGuid,\r | |
400 | (VOID **) &BlkIo,\r | |
401 | This->DriverBindingHandle,\r | |
402 | Controller,\r | |
403 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
404 | );\r | |
405 | if (EFI_ERROR (Status)) {\r | |
406 | return Status;\r | |
407 | }\r | |
408 | //\r | |
409 | // Get the Floppy Disk Controller's Device structure\r | |
410 | //\r | |
411 | FdcDev = FDD_BLK_IO_FROM_THIS (BlkIo);\r | |
412 | \r | |
413 | //\r | |
414 | // Report disable progress code\r | |
415 | //\r | |
416 | REPORT_STATUS_CODE_WITH_DEVICE_PATH (\r | |
417 | EFI_PROGRESS_CODE,\r | |
418 | EFI_PERIPHERAL_REMOVABLE_MEDIA | EFI_P_PC_DISABLE,\r | |
419 | FdcDev->DevicePath\r | |
420 | );\r | |
421 | \r | |
422 | //\r | |
423 | // Turn the motor off on the Floppy Disk Controller\r | |
424 | //\r | |
425 | FddTimerProc (FdcDev->Event, FdcDev);\r | |
426 | \r | |
427 | //\r | |
428 | // Uninstall the Block I/O Protocol\r | |
429 | //\r | |
430 | Status = gBS->UninstallProtocolInterface (\r | |
431 | Controller,\r | |
432 | &gEfiBlockIoProtocolGuid,\r | |
433 | &FdcDev->BlkIo\r | |
434 | );\r | |
435 | if (EFI_ERROR (Status)) {\r | |
436 | return Status;\r | |
437 | }\r | |
438 | //\r | |
439 | // Close the device path protocol\r | |
440 | //\r | |
441 | gBS->CloseProtocol (\r | |
442 | Controller,\r | |
443 | &gEfiDevicePathProtocolGuid,\r | |
444 | This->DriverBindingHandle,\r | |
445 | Controller\r | |
446 | );\r | |
447 | \r | |
448 | //\r | |
449 | // Close the ISA I/O Protocol\r | |
450 | //\r | |
451 | gBS->CloseProtocol (\r | |
452 | Controller,\r | |
453 | &gEfiIsaIoProtocolGuid,\r | |
454 | This->DriverBindingHandle,\r | |
455 | Controller\r | |
456 | );\r | |
457 | \r | |
458 | //\r | |
459 | // Free the controller list if needed\r | |
460 | //\r | |
461 | FdcDev->ControllerState->NumberOfDrive--;\r | |
462 | \r | |
463 | //\r | |
464 | // Close the event for turning the motor off\r | |
465 | //\r | |
466 | gBS->CloseEvent (FdcDev->Event);\r | |
467 | \r | |
468 | //\r | |
469 | // Free the cache if one was allocated\r | |
470 | //\r | |
471 | FdcFreeCache (FdcDev);\r | |
472 | \r | |
473 | //\r | |
474 | // Free the Floppy Disk Controller's Device structure\r | |
475 | //\r | |
476 | FreeUnicodeStringTable (FdcDev->ControllerNameTable);\r | |
477 | gBS->FreePool (FdcDev);\r | |
478 | \r | |
479 | return EFI_SUCCESS;\r | |
480 | }\r |