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