]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Bus/Isa/IsaFloppyDxe/IsaFloppy.c
IntelFrameworkModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Isa / IsaFloppyDxe / IsaFloppy.c
index e819a1d13219e0b3939c1450bf697cd8751274ab..6d7edd6f10446dad32b95b16d9ce09865fbd3f82 100644 (file)
@@ -1,28 +1,21 @@
-/**@file\r
-  ISA Floppy Driver\r
-  1. Support two types diskette drive  \r
+/** @file\r
+  ISA Floppy Disk UEFI Driver conforming to the UEFI driver model\r
+\r
+  1. Support two types diskette drive\r
      1.44M drive and 2.88M drive (and now only support 1.44M)\r
-  2. Support two diskette drives\r
+  2. Support two diskette drives per floppy disk controller\r
   3. Use DMA channel 2 to transfer data\r
   4. Do not use interrupt\r
   5. Support diskette change line signal and write protect\r
-  \r
-  conforming to EFI driver model\r
-  \r
-Copyright (c) 2006 - 2007, Intel Corporation.<BR>\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 #include "IsaFloppy.h"\r
 \r
-LIST_ENTRY              gControllerHead = INITIALIZE_LIST_HEAD_VARIABLE(gControllerHead);\r
+LIST_ENTRY  mControllerHead = INITIALIZE_LIST_HEAD_VARIABLE (mControllerHead);\r
 \r
 //\r
 // ISA Floppy Driver Binding Protocol\r
@@ -38,14 +31,13 @@ EFI_DRIVER_BINDING_PROTOCOL gFdcControllerDriver = {
 \r
 \r
 /**\r
-  The user Entry Point for module IsaFloppy. The user code starts with this function.\r
+  The main Entry Point for this driver.\r
 \r
-  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
-  @param[in] SystemTable    A pointer to the EFI System Table.\r
-  \r
-  @retval EFI_SUCCESS       The entry point is executed successfully.\r
-  @retval other             Some error occurs when executing this entry point.\r
+  @param[in] ImageHandle  The firmware allocated handle for the EFI image.\r
+  @param[in] SystemTable  A pointer to the EFI System Table.\r
 \r
+  @retval EFI_SUCCESS     The entry point is executed successfully.\r
+  @retval other           Some error occurs when executing this entry point.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -54,7 +46,7 @@ InitializeIsaFloppy(
   IN EFI_SYSTEM_TABLE     *SystemTable\r
   )\r
 {\r
-  EFI_STATUS              Status;\r
+  EFI_STATUS  Status;\r
 \r
   //\r
   // Install driver model protocol(s).\r
@@ -69,19 +61,21 @@ InitializeIsaFloppy(
              );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-\r
   return Status;\r
 }\r
 \r
 /**\r
-  Test controller is a Floppy Disk Controller\r
-  \r
-  @param This                 Pointer of EFI_DRIVER_BINDING_PROTOCOL\r
-  @param Controller           driver's controller\r
-  @param RemainingDevicePath  children device path\r
-  \r
-  @retval EFI_UNSUPPORTED controller is not floppy disk\r
-  @retval EFI_SUCCESS     controller is floppy disk\r
+  Test if the controller is a floppy disk drive device\r
+\r
+  @param[in] This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in] Controller           The handle of the controller to test.\r
+  @param[in] RemainingDevicePath  A pointer to the remaining portion of a device path.\r
+\r
+  @retval EFI_SUCCESS             The device is supported by this driver.\r
+  @retval EFI_ALREADY_STARTED     The device is already being managed by this driver.\r
+  @retval EFI_ACCESS_DENIED       The device is already being managed by a different driver\r
+                                  or an application that requires exclusive access.\r
+  @retval EFI_UNSUPPORTED         The device is is not supported by this driver.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -91,8 +85,35 @@ FdcControllerDriverSupported (
   IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
   )\r
 {\r
-  EFI_STATUS                          Status;\r
-  EFI_ISA_IO_PROTOCOL                 *IsaIo;\r
+  EFI_STATUS                Status;\r
+  EFI_ISA_IO_PROTOCOL       *IsaIo;\r
+  EFI_DEVICE_PATH_PROTOCOL  *ParentDevicePath;\r
+\r
+  //\r
+  // Ignore the parameter RemainingDevicePath because this is a device driver.\r
+  //\r
+\r
+  //\r
+  // Open the device path protocol\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Controller,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID **) &ParentDevicePath,\r
+                  This->DriverBindingHandle,\r
+                  Controller,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  gBS->CloseProtocol (\r
+         Controller,\r
+         &gEfiDevicePathProtocolGuid,\r
+         This->DriverBindingHandle,\r
+         Controller\r
+         );\r
 \r
   //\r
   // Open the ISA I/O Protocol\r
@@ -109,7 +130,7 @@ FdcControllerDriverSupported (
     return Status;\r
   }\r
   //\r
-  // Use the ISA I/O Protocol to see if Controller is a Floppy Disk Controller\r
+  // Use the ISA I/O Protocol to see if Controller is a floppy disk drive device\r
   //\r
   Status = EFI_SUCCESS;\r
   if (IsaIo->ResourceList->Device.HID != EISA_PNP_ID (0x604)) {\r
@@ -129,13 +150,20 @@ FdcControllerDriverSupported (
 }\r
 \r
 /**\r
-  Create floppy control instance on controller.\r
-  \r
-  @param This         Pointer of EFI_DRIVER_BINDING_PROTOCOL\r
-  @param Controller   driver controller handle\r
-  @param RemainingDevicePath Children's device path\r
-  \r
-  @retval whether success to create floppy control instance.\r
+  Start this driver on Controller.\r
+\r
+  @param[in] This                  A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in] ControllerHandle      The handle of the controller to start. This handle\r
+                                   must support a protocol interface that supplies\r
+                                   an I/O abstraction to the driver.\r
+  @param[in] RemainingDevicePath   A pointer to the remaining portion of a device path.\r
+                                   This parameter is ignored by device drivers, and is optional for bus drivers.\r
+\r
+  @retval EFI_SUCCESS              The device was started.\r
+  @retval EFI_DEVICE_ERROR         The device could not be started due to a device error.\r
+                                   Currently not implemented.\r
+  @retval EFI_OUT_OF_RESOURCES     The request could not be completed due to a lack of resources.\r
+  @retval Others                   The driver failded to start the device.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -145,13 +173,13 @@ FdcControllerDriverStart (
   IN EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
   )\r
 {\r
-  EFI_STATUS                                Status;\r
-  FDC_BLK_IO_DEV                            *FdcDev;\r
-  EFI_ISA_IO_PROTOCOL                       *IsaIo;\r
-  UINTN                                     Index;\r
-  LIST_ENTRY                                *List;\r
-  BOOLEAN                                   Found;\r
-  EFI_DEVICE_PATH_PROTOCOL                  *ParentDevicePath;\r
+  EFI_STATUS                Status;\r
+  FDC_BLK_IO_DEV            *FdcDev;\r
+  EFI_ISA_IO_PROTOCOL       *IsaIo;\r
+  UINTN                     Index;\r
+  LIST_ENTRY                *List;\r
+  BOOLEAN                   Found;\r
+  EFI_DEVICE_PATH_PROTOCOL  *ParentDevicePath;\r
 \r
   FdcDev  = NULL;\r
   IsaIo   = NULL;\r
@@ -194,14 +222,14 @@ FdcControllerDriverStart (
     goto Done;\r
   }\r
   //\r
-  // Allocate the Floppy Disk Controller's Device structure\r
+  // Allocate the floppy device's Device structure\r
   //\r
   FdcDev = AllocateZeroPool (sizeof (FDC_BLK_IO_DEV));\r
   if (FdcDev == NULL) {\r
     goto Done;\r
   }\r
   //\r
-  // Initialize the Floppy Disk Controller's Device structure\r
+  // Initialize the floppy device's device structure\r
   //\r
   FdcDev->Signature       = FDC_BLK_IO_DEV_SIGNATURE;\r
   FdcDev->Handle          = Controller;\r
@@ -212,10 +240,11 @@ FdcControllerDriverStart (
   FdcDev->ControllerState = NULL;\r
   FdcDev->DevicePath      = ParentDevicePath;\r
 \r
-  ADD_FLOPPY_NAME (FdcDev);\r
-  \r
+  FdcDev->ControllerNameTable = NULL;\r
+  AddName (FdcDev);\r
+\r
   //\r
-  // Look up the base address of the Floppy Disk Controller\r
+  // Look up the base address of the Floppy Disk Controller which controls this floppy device\r
   //\r
   for (Index = 0; FdcDev->IsaIo->ResourceList->ResourceItem[Index].Type != EfiIsaAcpiResourceEndOfList; Index++) {\r
     if (FdcDev->IsaIo->ResourceList->ResourceItem[Index].Type == EfiIsaAcpiResourceIo) {\r
@@ -223,11 +252,11 @@ FdcControllerDriverStart (
     }\r
   }\r
   //\r
-  // Maintain the list of controller list\r
+  // Maintain the list of floppy disk controllers\r
   //\r
   Found = FALSE;\r
-  List  = gControllerHead.ForwardLink;\r
-  while (List != &gControllerHead) {\r
+  List  = mControllerHead.ForwardLink;\r
+  while (List != &mControllerHead) {\r
     FdcDev->ControllerState = FLOPPY_CONTROLLER_FROM_LIST_ENTRY (List);\r
     if (FdcDev->BaseAddress == FdcDev->ControllerState->BaseAddress) {\r
       Found = TRUE;\r
@@ -239,7 +268,7 @@ FdcControllerDriverStart (
 \r
   if (!Found) {\r
     //\r
-    // The Controller is new\r
+    // A new floppy disk controller controlling this floppy disk drive is found\r
     //\r
     FdcDev->ControllerState = AllocatePool (sizeof (FLOPPY_CONTROLLER_CONTEXT));\r
     if (FdcDev->ControllerState == NULL) {\r
@@ -252,10 +281,10 @@ FdcControllerDriverStart (
     FdcDev->ControllerState->BaseAddress        = FdcDev->BaseAddress;\r
     FdcDev->ControllerState->NumberOfDrive      = 0;\r
 \r
-    InsertTailList (&gControllerHead, &FdcDev->ControllerState->Link);\r
+    InsertTailList (&mControllerHead, &FdcDev->ControllerState->Link);\r
   }\r
   //\r
-  // Create a timer event for each Floppd Disk Controller.\r
+  // Create a timer event for each floppy disk drive device.\r
   // This timer event is used to control the motor on and off\r
   //\r
   Status = gBS->CreateEvent (\r
@@ -304,8 +333,9 @@ FdcControllerDriverStart (
                   &FdcDev->BlkIo,\r
                   NULL\r
                   );\r
-\r
-  FdcDev->ControllerState->NumberOfDrive++;\r
+  if (!EFI_ERROR (Status)) {\r
+    FdcDev->ControllerState->NumberOfDrive++;\r
+  }\r
 \r
 Done:\r
   if (EFI_ERROR (Status)) {\r
@@ -317,14 +347,19 @@ Done:
       );\r
 \r
     //\r
-    // Close the device path protocol\r
+    // If a floppy drive device structure was allocated, then free it\r
     //\r
-    gBS->CloseProtocol (\r
-           Controller,\r
-           &gEfiDevicePathProtocolGuid,\r
-           This->DriverBindingHandle,\r
-           Controller\r
-           );\r
+    if (FdcDev != NULL) {\r
+      if (FdcDev->Event != NULL) {\r
+        //\r
+        // Close the event for turning the motor off\r
+        //\r
+        gBS->CloseEvent (FdcDev->Event);\r
+      }\r
+\r
+      FreeUnicodeStringTable (FdcDev->ControllerNameTable);\r
+      FreePool (FdcDev);\r
+    }\r
 \r
     //\r
     // Close the ISA I/O Protocol\r
@@ -337,38 +372,34 @@ Done:
              Controller\r
              );\r
     }\r
+\r
     //\r
-    // If a Floppy Disk Controller Device structure was allocated, then free it\r
+    // Close the device path protocol\r
     //\r
-    if (FdcDev != NULL) {\r
-      if (FdcDev->Event != NULL) {\r
-        //\r
-        // Close the event for turning the motor off\r
-        //\r
-        gBS->CloseEvent (FdcDev->Event);\r
-      }\r
-\r
-      FreeUnicodeStringTable (FdcDev->ControllerNameTable);\r
-      gBS->FreePool (FdcDev);\r
-    }\r
+    gBS->CloseProtocol (\r
+           Controller,\r
+           &gEfiDevicePathProtocolGuid,\r
+           This->DriverBindingHandle,\r
+           Controller\r
+           );\r
   }\r
 \r
   return Status;\r
 }\r
 \r
 /**\r
-  Stop this driver on ControllerHandle. Support stoping any child handles\r
-  created by this driver.\r
-\r
-  @param  This              Protocol instance pointer.\r
-  @param  Controller        Handle of device to stop driver on\r
-  @param  NumberOfChildren  Number of Handles in ChildHandleBuffer. If number of\r
-                            children is zero stop the entire bus driver.\r
-  @param  ChildHandleBuffer List of Child Handles to Stop.\r
-\r
-  @retval EFI_SUCCESS       This driver is removed ControllerHandle\r
-  @retval other             This driver was not removed from this device\r
-\r
+  Stop this driver on ControllerHandle.\r
+\r
+  @param[in] This               A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
+  @param[in] ControllerHandle   A handle to the device being stopped. The handle must\r
+                                support a bus specific I/O protocol for the driver\r
+                                to use to stop the device.\r
+  @param[in] NumberOfChildren   The number of child device handles in ChildHandleBuffer.\r
+  @param[in] ChildHandleBuffer  An array of child handles to be freed. May be NULL\r
+                                if NumberOfChildren is 0.\r
+\r
+  @retval EFI_SUCCESS           The device was stopped.\r
+  @retval EFI_DEVICE_ERROR      The device could not be stopped due to a device error.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -383,6 +414,10 @@ FdcControllerDriverStop (
   EFI_BLOCK_IO_PROTOCOL *BlkIo;\r
   FDC_BLK_IO_DEV        *FdcDev;\r
 \r
+  //\r
+  // Ignore NumberOfChildren since this is a device driver\r
+  //\r
+\r
   //\r
   // Get the Block I/O Protocol on Controller\r
   //\r
@@ -398,7 +433,7 @@ FdcControllerDriverStop (
     return Status;\r
   }\r
   //\r
-  // Get the Floppy Disk Controller's Device structure\r
+  // Get the floppy drive device's Device structure\r
   //\r
   FdcDev = FDD_BLK_IO_FROM_THIS (BlkIo);\r
 \r
@@ -411,11 +446,6 @@ FdcControllerDriverStop (
     FdcDev->DevicePath\r
     );\r
 \r
-  //\r
-  // Turn the motor off on the Floppy Disk Controller\r
-  //\r
-  FddTimerProc (FdcDev->Event, FdcDev);\r
-\r
   //\r
   // Uninstall the Block I/O Protocol\r
   //\r
@@ -427,6 +457,17 @@ FdcControllerDriverStop (
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
+\r
+  //\r
+  // Close the event for turning the motor off\r
+  //\r
+  gBS->CloseEvent (FdcDev->Event);\r
+\r
+  //\r
+  // Turn the motor off on the floppy drive device\r
+  //\r
+  FddTimerProc (FdcDev->Event, FdcDev);\r
+\r
   //\r
   // Close the device path protocol\r
   //\r
@@ -452,21 +493,16 @@ FdcControllerDriverStop (
   //\r
   FdcDev->ControllerState->NumberOfDrive--;\r
 \r
-  //\r
-  // Close the event for turning the motor off\r
-  //\r
-  gBS->CloseEvent (FdcDev->Event);\r
-\r
   //\r
   // Free the cache if one was allocated\r
   //\r
   FdcFreeCache (FdcDev);\r
 \r
   //\r
-  // Free the Floppy Disk Controller's Device structure\r
+  // Free the floppy drive device's device structure\r
   //\r
   FreeUnicodeStringTable (FdcDev->ControllerNameTable);\r
-  gBS->FreePool (FdcDev);\r
+  FreePool (FdcDev);\r
 \r
   return EFI_SUCCESS;\r
 }\r