X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;ds=sidebyside;f=MdeModulePkg%2FBus%2FPci%2FUhciDxe%2FUhci.c;h=92567f93e48d565bd626fbfa84b1bfd68fa8af40;hb=cd5ebaa06dca3e6ef3c464081e6defe00d358c69;hp=c20e94419671b9cf57aa4e4a8be09bfbe5b03abf;hpb=aa79b0b3799e95bc21e0df32a135cc5a4d749e4b;p=mirror_edk2.git diff --git a/MdeModulePkg/Bus/Pci/UhciDxe/Uhci.c b/MdeModulePkg/Bus/Pci/UhciDxe/Uhci.c index c20e944196..92567f93e4 100644 --- a/MdeModulePkg/Bus/Pci/UhciDxe/Uhci.c +++ b/MdeModulePkg/Bus/Pci/UhciDxe/Uhci.c @@ -2,8 +2,8 @@ The UHCI driver model and HC protocol routines. -Copyright (c) 2004 - 2008, Intel Corporation -All rights reserved. This program and the accompanying materials +Copyright (c) 2004 - 2010, 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 @@ -318,7 +318,7 @@ Uhci2GetCapability ( Uhc->RootPorts = *PortNumber; - DEBUG ((EFI_D_INFO, "Uhci2GetCapability: %d ports\n", Uhc->RootPorts)); + DEBUG ((EFI_D_INFO, "Uhci2GetCapability: %d ports\n", (UINT32)Uhc->RootPorts)); return EFI_SUCCESS; } @@ -633,6 +633,7 @@ Uhci2ControlTransfer ( UINT8 *DataPhy; VOID *DataMap; BOOLEAN IsSlowDevice; + UINTN TransferDataLength; Uhc = UHC_FROM_USB2_HC_PROTO (This); TDs = NULL; @@ -660,10 +661,16 @@ Uhci2ControlTransfer ( return EFI_INVALID_PARAMETER; } - if ((TransferDirection != EfiUsbNoData) && (DataLength == NULL)) { + if ((TransferDirection != EfiUsbNoData) && (Data == NULL || DataLength == NULL)) { return EFI_INVALID_PARAMETER; } + if (TransferDirection == EfiUsbNoData) { + TransferDataLength = 0; + } else { + TransferDataLength = *DataLength; + } + *TransferResult = EFI_USB_ERR_SYSTEM; Status = EFI_DEVICE_ERROR; @@ -700,9 +707,11 @@ Uhci2ControlTransfer ( Uhc, DeviceAddress, PktId, + (UINT8*)Request, RequestPhy, + (UINT8*)Data, DataPhy, - *DataLength, + TransferDataLength, (UINT8) MaximumPacketLength, IsSlowDevice ); @@ -717,7 +726,7 @@ Uhci2ControlTransfer ( // the TD to corrosponding queue head, then check // the execution result // - UhciLinkTdToQh (Uhc->CtrlQh, TDs); + UhciLinkTdToQh (Uhc, Uhc->CtrlQh, TDs); Status = UhciExecuteTransfer (Uhc, Uhc->CtrlQh, TDs, TimeOut, IsSlowDevice, &QhResult); UhciUnlinkTdFromQh (Uhc->CtrlQh, TDs); @@ -851,6 +860,7 @@ Uhci2BulkTransfer ( DeviceAddress, EndPointAddress, PktId, + (UINT8 *)*Data, DataPhy, *DataLength, DataToggle, @@ -871,7 +881,7 @@ Uhci2BulkTransfer ( // BulkQh = Uhc->BulkQh; - UhciLinkTdToQh (BulkQh, TDs); + UhciLinkTdToQh (Uhc, BulkQh, TDs); Status = UhciExecuteTransfer (Uhc, BulkQh, TDs, TimeOut, FALSE, &QhResult); UhciUnlinkTdFromQh (BulkQh, TDs); @@ -939,7 +949,6 @@ Uhci2AsyncInterruptTransfer ( EFI_STATUS Status; UINT8 *DataPtr; UINT8 *DataPhy; - VOID *DataMap; UINT8 PktId; Uhc = UHC_FROM_USB2_HC_PROTO (This); @@ -947,7 +956,6 @@ Uhci2AsyncInterruptTransfer ( IntTds = NULL; DataPtr = NULL; DataPhy = NULL; - DataMap = NULL; IsSlowDevice = (BOOLEAN) ((EFI_USB_SPEED_LOW == DeviceSpeed) ? TRUE : FALSE); @@ -988,40 +996,30 @@ Uhci2AsyncInterruptTransfer ( return EFI_DEVICE_ERROR; } + if ((EndPointAddress & 0x80) == 0) { + PktId = OUTPUT_PACKET_ID; + } else { + PktId = INPUT_PACKET_ID; + } + // // Allocate and map source data buffer for bus master access. // - DataPtr = AllocatePool (DataLength); + DataPtr = UsbHcAllocateMem (Uhc->MemPool, DataLength); if (DataPtr == NULL) { return EFI_OUT_OF_RESOURCES; } - OldTpl = gBS->RaiseTPL (UHCI_TPL); + DataPhy = (UINT8 *) (UINTN) UsbHcGetPciAddressForHostMem (Uhc->MemPool, DataPtr, DataLength); - // - // Map the user data then create a queue head and - // list of TD for it. - // - Status = UhciMapUserData ( - Uhc, - EfiUsbDataIn, - DataPtr, - &DataLength, - &PktId, - &DataPhy, - &DataMap - ); - - if (EFI_ERROR (Status)) { - goto FREE_DATA; - } + OldTpl = gBS->RaiseTPL (UHCI_TPL); Qh = UhciCreateQh (Uhc, PollingInterval); if (Qh == NULL) { Status = EFI_OUT_OF_RESOURCES; - goto UNMAP_DATA; + goto FREE_DATA; } IntTds = UhciCreateBulkOrIntTds ( @@ -1029,6 +1027,7 @@ Uhci2AsyncInterruptTransfer ( DeviceAddress, EndPointAddress, PktId, + DataPtr, DataPhy, DataLength, DataToggle, @@ -1041,7 +1040,7 @@ Uhci2AsyncInterruptTransfer ( goto DESTORY_QH; } - UhciLinkTdToQh (Qh, IntTds); + UhciLinkTdToQh (Uhc, Qh, IntTds); // // Save QH-TD structures to async Interrupt transfer list, @@ -1055,7 +1054,6 @@ Uhci2AsyncInterruptTransfer ( EndPointAddress, DataLength, PollingInterval, - DataMap, DataPtr, CallBackFunction, Context, @@ -1066,7 +1064,7 @@ Uhci2AsyncInterruptTransfer ( goto DESTORY_QH; } - UhciLinkQhToFrameList (Uhc->FrameBase, Qh); + UhciLinkQhToFrameList (Uhc, Qh); gBS->RestoreTPL (OldTpl); return EFI_SUCCESS; @@ -1074,11 +1072,8 @@ Uhci2AsyncInterruptTransfer ( DESTORY_QH: UsbHcFreeMem (Uhc->MemPool, Qh, sizeof (UHCI_QH_SW)); -UNMAP_DATA: - Uhc->PciIo->Unmap (Uhc->PciIo, DataMap); - FREE_DATA: - gBS->FreePool (DataPtr); + UsbHcFreeMem (Uhc->MemPool, DataPtr, DataLength); Uhc->PciIo->Flush (Uhc->PciIo); gBS->RestoreTPL (OldTpl); @@ -1202,6 +1197,7 @@ Uhci2SyncInterruptTransfer ( DeviceAddress, EndPointAddress, PktId, + (UINT8 *)Data, DataPhy, *DataLength, DataToggle, @@ -1217,7 +1213,7 @@ Uhci2SyncInterruptTransfer ( } - UhciLinkTdToQh (Uhc->SyncIntQh, TDs); + UhciLinkTdToQh (Uhc, Uhc->SyncIntQh, TDs); Status = UhciExecuteTransfer (Uhc, Uhc->SyncIntQh, TDs, TimeOut, IsSlowDevice, &QhResult); @@ -1384,7 +1380,7 @@ UhciDriverBindingSupported ( Status = PciIo->Pci.Read ( PciIo, EfiPciIoWidthUint8, - CLASSC_OFFSET, + PCI_CLASSCODE_OFFSET, sizeof (USB_CLASSC) / sizeof (UINT8), &UsbClassCReg ); @@ -1399,7 +1395,7 @@ UhciDriverBindingSupported ( // if ((UsbClassCReg.BaseCode != PCI_CLASS_SERIAL) || (UsbClassCReg.SubClassCode != PCI_CLASS_SERIAL_USB) || - (UsbClassCReg.PI != PCI_CLASSC_PI_UHCI) + (UsbClassCReg.ProgInterface != PCI_IF_UHCI) ) { Status = EFI_UNSUPPORTED; @@ -1490,7 +1486,7 @@ UhciAllocateDev ( return Uhc; ON_ERROR: - gBS->FreePool (Uhc); + FreePool (Uhc); return NULL; } @@ -1500,8 +1496,6 @@ ON_ERROR: @param Uhc The UHCI device to release. - @return None. - **/ VOID UhciFreeDev ( @@ -1512,6 +1506,10 @@ UhciFreeDev ( gBS->CloseEvent (Uhc->AsyncIntMonitor); } + if (Uhc->ExitBootServiceEvent != NULL) { + gBS->CloseEvent (Uhc->ExitBootServiceEvent); + } + if (Uhc->MemPool != NULL) { UsbHcFreeMemPool (Uhc->MemPool); } @@ -1520,7 +1518,7 @@ UhciFreeDev ( FreeUnicodeStringTable (Uhc->CtrlNameTable); } - gBS->FreePool (Uhc); + FreePool (Uhc); } @@ -1530,8 +1528,6 @@ UhciFreeDev ( @param Controller Controller handle. @param This Protocol instance pointer. - @return None. - **/ VOID UhciCleanDevUp ( @@ -1569,6 +1565,31 @@ UhciCleanDevUp ( UhciFreeDev (Uhc); } +/** + One notified function to stop the Host Controller when gBS->ExitBootServices() called. + + @param Event Pointer to this event + @param Context Event hanlder private data + +**/ +VOID +EFIAPI +UhcExitBootService ( + EFI_EVENT Event, + VOID *Context + ) +{ + USB_HC_DEV *Uhc; + + Uhc = (USB_HC_DEV *) Context; + + // + // Stop the Host Controller + // + UhciStopHc (Uhc, UHC_GENERIC_TIMEOUT); + + return; +} /** Starting the Usb UHCI Driver. @@ -1700,6 +1721,21 @@ UhciDriverBindingStart ( goto FREE_UHC; } + // + // Create event to stop the HC when exit boot service. + // + Status = gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_NOTIFY, + UhcExitBootService, + Uhc, + &gEfiEventExitBootServicesGuid, + &Uhc->ExitBootServiceEvent + ); + if (EFI_ERROR (Status)) { + goto UNINSTALL_USBHC; + } + // // Install the component name protocol // @@ -1727,6 +1763,14 @@ UhciDriverBindingStart ( UhciWriteReg (Uhc->PciIo, USBCMD_OFFSET, USBCMD_RS | USBCMD_MAXP); return EFI_SUCCESS; + +UNINSTALL_USBHC: + gBS->UninstallMultipleProtocolInterfaces ( + Controller, + &gEfiUsb2HcProtocolGuid, + &Uhc->Usb2Hc, + NULL + ); FREE_UHC: UhciFreeDev (Uhc);