X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=IntelFrameworkModulePkg%2FBus%2FIsa%2FIsaBusDxe%2FIsaBus.c;h=4acb22626bda8c5ded36de6fb5c617d18a6a8600;hb=180a5a35cb49699bd249dee19e41cee34c856a58;hp=80c942e289d3142eca2120e8729f71cf7346c658;hpb=bcd70414877e56f3bffff0bf11b07a30ef51a68f;p=mirror_edk2.git diff --git a/IntelFrameworkModulePkg/Bus/Isa/IsaBusDxe/IsaBus.c b/IntelFrameworkModulePkg/Bus/Isa/IsaBusDxe/IsaBus.c index 80c942e289..4acb22626b 100644 --- a/IntelFrameworkModulePkg/Bus/Isa/IsaBusDxe/IsaBus.c +++ b/IntelFrameworkModulePkg/Bus/Isa/IsaBusDxe/IsaBus.c @@ -1,14 +1,13 @@ -/**@file +/** @file + ISA Bus UEFI driver. - Discovers all the ISA Controllers and their resources by using the ISA PnP + Discovers all the ISA Controllers and their resources by using the ISA ACPI Protocol, produces an instance of the ISA I/O Protocol for every ISA - Controller found, loads and initializes all ISA Device Drivers, matches ISA - Device Drivers with their respective ISA Controllers in a deterministic - manner, and informs a ISA Device Driver when it is to start managing an ISA - Controller. + Controller found. This driver is designed to manage a PCI-to-ISA bridge Device + such as LPC bridge. -Copyright (c) 2006 - 2007, Intel Corporation.
-All rights reserved. This program and the accompanying materials +Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php @@ -18,7 +17,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ - #include "InternalIsaBus.h" // @@ -34,14 +32,13 @@ EFI_DRIVER_BINDING_PROTOCOL gIsaBusControllerDriver = { }; /** - The user Entry Point for module IsaBus. The user code starts with this function. + The main entry point for the ISA Bus driver. - @param[in] ImageHandle The firmware allocated handle for the EFI image. - @param[in] SystemTable A pointer to the EFI System Table. + @param[in] ImageHandle The firmware allocated handle for the EFI image. + @param[in] SystemTable A pointer to the EFI System Table. - @retval EFI_SUCCESS The entry point is executed successfully. - @retval other Some error occurs when executing this entry point. - + @retval EFI_SUCCESS The entry point is executed successfully. + @retval EFI_OUT_OF_RESOURCES There was not enough memory in pool to install all the protocols. **/ EFI_STATUS EFIAPI @@ -65,47 +62,43 @@ InitializeIsaBus( ); ASSERT_EFI_ERROR (Status); - return Status; } +/** + Tests to see if a controller can be managed by the ISA Bus Driver. If a child device is provided, + it further tests to see if this driver supports creating a handle for the specified child device. + + Note that the ISA Bus driver always creates all of its child handles on the first call to Start(). + How the Start() function of a driver is implemented can affect how the Supported() function is implemented. + + @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance. + @param[in] Controller The handle of the controller to test. + @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. + + @retval EFI_SUCCESS The device is supported by this driver. + @retval EFI_ALREADY_STARTED The device is already being managed by this driver. + @retval EFI_ACCESS_DENIED The device is already being managed by a different driver + or an application that requires exclusive access. + @retval EFI_UNSUPPORTED The device is is not supported by this driver. +**/ EFI_STATUS EFIAPI IsaBusControllerDriverSupported ( - IN EFI_DRIVER_BINDING_PROTOCOL * This, + IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, - IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL ) -/** - - Routine Description: - - This function checks to see if a controller can be managed by the ISA Bus - Driver. This is done by checking to see if the controller supports the - EFI_PCI_IO_PROTOCOL protocol, and then looking at the PCI Configuration - Header to see if the device is a PCI to ISA bridge. The class code of - PCI to ISA bridge: Base class 06h, Sub class 01h Interface 00h - - Arguments: - - This - The EFI_DRIVER_BINDING_PROTOCOL instance. - Controller - The handle of the device to check. - RemainingDevicePath - A pointer to the remaining portion of a device path. - - Returns: - - EFI_SUCCESS - The device is supported by this driver. - EFI_UNSUPPORTED - The device is not supported by this driver. - -**/ { - EFI_STATUS Status; - EFI_ISA_ACPI_PROTOCOL *IsaAcpi; + EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath; + EFI_ISA_ACPI_PROTOCOL *IsaAcpi; // // If RemainingDevicePath is not NULL, it should verify that the first device - // path node in RemainingDevicePath is an ACPI Device path node + // path node in RemainingDevicePath is an ACPI Device path node which is a + // legal Device Path Node for this bus driver's children. // if (RemainingDevicePath != NULL) { if (RemainingDevicePath->Type != ACPI_DEVICE_PATH) { @@ -123,11 +116,43 @@ IsaBusControllerDriverSupported ( } } // - // Test the existence of DEVICE_PATH protocol + // Try to open EFI DEVICE PATH protocol on the controller // Status = gBS->OpenProtocol ( Controller, &gEfiDevicePathProtocolGuid, + (VOID **) &ParentDevicePath, + This->DriverBindingHandle, + Controller, + EFI_OPEN_PROTOCOL_BY_DRIVER + ); + // + // Although this driver creates all child handles at one time, + // but because all child handles may be not stopped at one time in EFI Driver Binding.Stop(), + // So it is allowed to create child handles again in successive calls to EFI Driver Binding.Start(). + // + if (Status == EFI_ALREADY_STARTED) { + return EFI_SUCCESS; + } + + if (EFI_ERROR (Status)) { + return Status; + } + + gBS->CloseProtocol ( + Controller, + &gEfiDevicePathProtocolGuid, + This->DriverBindingHandle, + Controller + ); + + // + // Try to get Pci IO Protocol because it is assumed + // to have been opened by ISA ACPI driver + // + Status = gBS->OpenProtocol ( + Controller, + &gEfiPciIoProtocolGuid, NULL, This->DriverBindingHandle, Controller, @@ -136,8 +161,9 @@ IsaBusControllerDriverSupported ( if (EFI_ERROR (Status)) { return Status; } + // - // Get the Isa Acpi protocol + // Try to open the Isa Acpi protocol on the controller // Status = gBS->OpenProtocol ( Controller, @@ -147,14 +173,14 @@ IsaBusControllerDriverSupported ( Controller, EFI_OPEN_PROTOCOL_BY_DRIVER ); - if (Status == EFI_ALREADY_STARTED) { - return EFI_SUCCESS; - } - if (EFI_ERROR (Status)) { return Status; } + // + // Add more check to see if the child device is valid by calling IsaAcpi->DeviceEnumerate? + // + gBS->CloseProtocol ( Controller, &gEfiIsaAcpiProtocolGuid, @@ -165,37 +191,40 @@ IsaBusControllerDriverSupported ( return Status; } +/** + Start this driver on ControllerHandle. + + Note that the ISA Bus driver always creates all of its child handles on the first call to Start(). + The Start() function is designed to be invoked from the EFI boot service ConnectController(). + As a result, much of the error checking on the parameters to Start() has been moved into this + common boot service. It is legal to call Start() from other locations, but the following calling + restrictions must be followed or the system behavior will not be deterministic. + 1. ControllerHandle must be a valid EFI_HANDLE. + 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned + EFI_DEVICE_PATH_PROTOCOL. + 3. Prior to calling Start(), the Supported() function for the driver specified by This must + have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS. + + @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance. + @param[in] ControllerHandle The handle of the controller to start. This handle + must support a protocol interface that supplies + an I/O abstraction to the driver. + @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. + This parameter is ignored by device drivers, and is optional for bus drivers. + + @retval EFI_SUCCESS The device was started. + @retval EFI_DEVICE_ERROR The device could not be started due to a device error. + Currently not implemented. + @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources. + @retval Others The driver failded to start the device. +**/ EFI_STATUS EFIAPI IsaBusControllerDriverStart ( - IN EFI_DRIVER_BINDING_PROTOCOL * This, + IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, - IN EFI_DEVICE_PATH_PROTOCOL * RemainingDevicePath OPTIONAL + IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL ) -/** - - Routine Description: - - This function tells the ISA Bus Driver to start managing a PCI to ISA - Bridge controller. - - Arguments: - - This - The EFI_DRIVER_BINDING_PROTOCOL instance. - Controller - A handle to the device being started. - RemainingDevicePath - A pointer to the remaining portion of a device path. - - Returns: - - EFI_SUCCESS - The device was started. - EFI_UNSUPPORTED - The device is not supported. - EFI_DEVICE_ERROR - The device could not be started due to a device error. - EFI_ALREADY_STARTED - The device has already been started. - EFI_INVALID_PARAMETER - One of the parameters has an invalid value. - EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of - resources. - -**/ { EFI_STATUS Status; EFI_PCI_IO_PROTOCOL *PciIo; @@ -208,57 +237,38 @@ IsaBusControllerDriverStart ( // // Local variables declaration for StatusCode reporting // - EFI_RESOURCE_ALLOC_FAILURE_ERROR_DATA AllocFailExtendedData; EFI_DEVICE_PATH_PROTOCOL *DevicePathData; // - // Initialize status code structure - // - AllocFailExtendedData.DataHeader.HeaderSize = sizeof (EFI_STATUS_CODE_DATA); - AllocFailExtendedData.DataHeader.Size = sizeof (EFI_RESOURCE_ALLOC_FAILURE_ERROR_DATA) - sizeof (EFI_STATUS_CODE_DATA); - CopyMem ( - &AllocFailExtendedData.DataHeader.Type, - &gEfiStatusCodeSpecificDataGuid, - sizeof (EFI_GUID) - ); - - // - // Open Device Path Protocol + // Get Pci IO Protocol // Status = gBS->OpenProtocol ( Controller, - &gEfiDevicePathProtocolGuid, - (VOID **) &ParentDevicePath, + &gEfiPciIoProtocolGuid, + (VOID **) &PciIo, This->DriverBindingHandle, Controller, - EFI_OPEN_PROTOCOL_BY_DRIVER + EFI_OPEN_PROTOCOL_GET_PROTOCOL ); - if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) { + if (EFI_ERROR (Status)) { return Status; } + // - // Open Pci IO Protocol + // Open Device Path Protocol // Status = gBS->OpenProtocol ( Controller, - &gEfiPciIoProtocolGuid, - (VOID **) &PciIo, + &gEfiDevicePathProtocolGuid, + (VOID **) &ParentDevicePath, This->DriverBindingHandle, Controller, - EFI_OPEN_PROTOCOL_GET_PROTOCOL + EFI_OPEN_PROTOCOL_BY_DRIVER ); - if (EFI_ERROR (Status)) { - // - // Close opened protocol - // - gBS->CloseProtocol ( - Controller, - &gEfiDevicePathProtocolGuid, - This->DriverBindingHandle, - Controller - ); + if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) { return Status; } + // // Open ISA Acpi Protocol // @@ -280,12 +290,6 @@ IsaBusControllerDriverStart ( This->DriverBindingHandle, Controller ); - gBS->CloseProtocol ( - Controller, - &gEfiPciIoProtocolGuid, - This->DriverBindingHandle, - Controller - ); return Status; } // @@ -351,6 +355,10 @@ IsaBusControllerDriverStart ( // // Create handle for this ISA device // + // If any child device handle was created in previous call to Start() and not stopped + // in previous call to Stop(), it will not be created again because the + // InstallMultipleProtocolInterfaces() boot service will reject same device path. + // Status = IsaCreateDevice ( This, Controller, @@ -358,7 +366,6 @@ IsaBusControllerDriverStart ( ParentDevicePath, ResourceList, &DevicePathData - //&AllocFailExtendedData.DevicePath ); if (EFI_ERROR (Status)) { @@ -381,9 +388,6 @@ IsaBusControllerDriverStart ( // // It's hard to tell which resource conflicts // - AllocFailExtendedData.Bar = 0; - AllocFailExtendedData.ReqRes = NULL; - AllocFailExtendedData.AllocRes = NULL; REPORT_STATUS_CODE_WITH_DEVICE_PATH ( EFI_ERROR_CODE, (EFI_IO_BUS_LPC | EFI_IOB_EC_RESOURCE_CONFLICT), @@ -406,6 +410,31 @@ IsaBusControllerDriverStart ( return EFI_SUCCESS; } +/** + Stop this driver on ControllerHandle. + + The Stop() function is designed to be invoked from the EFI boot service DisconnectController(). + As a result, much of the error checking on the parameters to Stop() has been moved + into this common boot service. It is legal to call Stop() from other locations, + but the following calling restrictions must be followed or the system behavior will not be deterministic. + 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this + same driver's Start() function. + 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid + EFI_HANDLE. In addition, all of these handles must have been created in this driver's + Start() function, and the Start() function must have called OpenProtocol() on + ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER. + + @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance. + @param[in] ControllerHandle A handle to the device being stopped. The handle must + support a bus specific I/O protocol for the driver + to use to stop the device. + @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer. + @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL + if NumberOfChildren is 0. + + @retval EFI_SUCCESS The device was stopped. + @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error. +**/ EFI_STATUS EFIAPI IsaBusControllerDriverStop ( @@ -414,52 +443,18 @@ IsaBusControllerDriverStop ( IN UINTN NumberOfChildren, IN EFI_HANDLE * ChildHandleBuffer OPTIONAL ) -/** - - Routine Description: - - This function tells the ISA Bus Driver to stop managing a PCI to ISA - Bridge controller. - - Arguments: - - This - The EFI_DRIVER_BINDING_PROTOCOL instance. - Controller - A handle to the device being stopped. - NumberOfChindren - The number of child device handles in ChildHandleBuffer. - ChildHandleBuffer - An array of child handles to be freed. - - - Returns: - - EFI_SUCCESS - The device was stopped. - EFI_DEVICE_ERROR - The device could not be stopped due to a device error. - EFI_NOT_STARTED - The device has not been started. - EFI_INVALID_PARAMETER - One of the parameters has an invalid value. - EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of - resources. - -**/ { EFI_STATUS Status; UINTN Index; BOOLEAN AllChildrenStopped; ISA_IO_DEVICE *IsaIoDevice; EFI_ISA_IO_PROTOCOL *IsaIo; + EFI_PCI_IO_PROTOCOL *PciIo; if (NumberOfChildren == 0) { // // Close the bus driver // - Status = gBS->CloseProtocol ( - Controller, - &gEfiPciIoProtocolGuid, - This->DriverBindingHandle, - Controller - ); - if (EFI_ERROR (Status)) { - return Status; - } - Status = gBS->CloseProtocol ( Controller, &gEfiDevicePathProtocolGuid, @@ -507,6 +502,16 @@ IsaBusControllerDriverStop ( IsaIoDevice = ISA_IO_DEVICE_FROM_ISA_IO_THIS (IsaIo); + // + // Close the child handle + // + + Status = gBS->CloseProtocol ( + Controller, + &gEfiPciIoProtocolGuid, + This->DriverBindingHandle, + ChildHandleBuffer[Index] + ); Status = gBS->UninstallMultipleProtocolInterfaces ( ChildHandleBuffer[Index], &gEfiDevicePathProtocolGuid, @@ -517,18 +522,21 @@ IsaBusControllerDriverStop ( ); if (!EFI_ERROR (Status)) { + FreePool (IsaIoDevice->DevicePath); + FreePool (IsaIoDevice); + } else { // - // Close the child handle + // Re-open PCI IO Protocol on behalf of the child device + // because of failure of destroying the child device handle // - Status = gBS->CloseProtocol ( - Controller, - &gEfiPciIoProtocolGuid, - This->DriverBindingHandle, - ChildHandleBuffer[Index] - ); - - gBS->FreePool (IsaIoDevice->DevicePath); - gBS->FreePool (IsaIoDevice); + gBS->OpenProtocol ( + Controller, + &gEfiPciIoProtocolGuid, + (VOID **) &PciIo, + This->DriverBindingHandle, + ChildHandleBuffer[Index], + EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER + ); } } @@ -543,9 +551,25 @@ IsaBusControllerDriverStop ( return EFI_SUCCESS; } + // // Internal Function // + +/** + Create EFI Handle for a ISA device found via ISA ACPI Protocol + + @param[in] This The EFI_DRIVER_BINDING_PROTOCOL instance. + @param[in] Controller The handle of ISA bus controller(PCI to ISA bridge) + @param[in] PciIo The Pointer to the PCI protocol + @param[in] ParentDevicePath Device path of the ISA bus controller + @param[in] IsaDeviceResourceList The resource list of the ISA device + @param[out] ChildDevicePath The pointer to the child device. + + @retval EFI_SUCCESS The handle for the child device was created. + @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources. + @retval EFI_DEVICE_ERROR The handle for the child device can not be created. +**/ EFI_STATUS IsaCreateDevice ( IN EFI_DRIVER_BINDING_PROTOCOL *This, @@ -555,29 +579,6 @@ IsaCreateDevice ( IN EFI_ISA_ACPI_RESOURCE_LIST *IsaDeviceResourceList, OUT EFI_DEVICE_PATH_PROTOCOL **ChildDevicePath ) -/** - - Routine Description: - - Create ISA device found by IsaPnpProtocol - - Arguments: - - This - The EFI_DRIVER_BINDING_PROTOCOL instance. - Controller - The handle of ISA bus controller(PCI to ISA bridge) - PciIo - The Pointer to the PCI protocol - ParentDevicePath - Device path of the ISA bus controller - IsaDeviceResourceList - The resource list of the ISA device - ChildDevicePath - The pointer to the child device. - - Returns: - - EFI_SUCCESS - Create the child device. - EFI_OUT_OF_RESOURCES - The request could not be completed due to a lack of - resources. - EFI_DEVICE_ERROR - Can not create child device. - -**/ { EFI_STATUS Status; ISA_IO_DEVICE *IsaIoDevice; @@ -598,11 +599,8 @@ IsaCreateDevice ( // // Initialize the ISA I/O instance structure // - Status = InitializeIsaIoInstance (IsaIoDevice, IsaDeviceResourceList); - if (EFI_ERROR (Status)) { - gBS->FreePool (IsaIoDevice); - return Status; - } + InitializeIsaIoInstance (IsaIoDevice, IsaDeviceResourceList); + // // Build the child device path // @@ -618,15 +616,14 @@ IsaCreateDevice ( ); if (IsaIoDevice->DevicePath == NULL) { - Status = EFI_DEVICE_ERROR; + Status = EFI_OUT_OF_RESOURCES; goto Done; } *ChildDevicePath = IsaIoDevice->DevicePath; // - // Create a child handle and attach the DevicePath, - // PCI I/O, and Controller State + // Create a child handle and install Device Path and ISA I/O protocols // Status = gBS->InstallMultipleProtocolInterfaces ( &IsaIoDevice->Handle, @@ -663,11 +660,12 @@ Done: if (EFI_ERROR (Status)) { if (IsaIoDevice->DevicePath != NULL) { - gBS->FreePool (IsaIoDevice->DevicePath); + FreePool (IsaIoDevice->DevicePath); } - gBS->FreePool (IsaIoDevice); + FreePool (IsaIoDevice); } return Status; } +