]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/EhciDxe/EhciUrb.c
Improve coding style in MdeModulePkg.
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / EhciDxe / EhciUrb.c
index 7b8b7b58f238266e7b4c9114bbad2c16a54a2bbd..593652f3e09fef1f50516e99519848d9eda94dbd 100644 (file)
@@ -1,6 +1,9 @@
 /** @file\r
 \r
-Copyright (c) 2007, Intel Corporation\r
+    This file contains URB request, each request is warpped in a\r
+    URB (Usb Request Block).\r
+\r
+Copyright (c) 2007 - 2010, Intel Corporation\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
@@ -9,39 +12,30 @@ http://opensource.org/licenses/bsd-license.php
 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
-Module Name:\r
-\r
-    EhciUrb.c\r
-\r
-Abstract:\r
-\r
-    This file contains URB request, each request is warpped in a\r
-    URB (Usb Request Block)\r
-\r
-Revision History\r
-\r
 **/\r
 \r
 #include "Ehci.h"\r
 \r
 \r
 /**\r
-  Create a single QTD to hold the data\r
+  Create a single QTD to hold the data.\r
 \r
-  @param  Ehc                   The EHCI device\r
-  @param  Data                  Current data not associated with a QTD\r
-  @param  DataLen               The length of the data\r
-  @param  PktId                 Packet ID to use in the QTD\r
-  @param  Toggle                Data toggle to use in the QTD\r
-  @param  MaxPacket             Maximu packet length of the endpoint\r
+  @param  Ehc                   The EHCI device.\r
+  @param  Data                  The cpu memory address of current data not associated with a QTD.\r
+  @param  DataPhy               The pci bus address of current data not associated with a QTD.\r
+  @param  DataLen               The length of the data.\r
+  @param  PktId                 Packet ID to use in the QTD.\r
+  @param  Toggle                Data toggle to use in the QTD.\r
+  @param  MaxPacket             Maximu packet length of the endpoint.\r
 \r
-  @return Created QTD or NULL if failed to create one\r
+  @return Created QTD or NULL if failed to create one.\r
 \r
 **/\r
 EHC_QTD *\r
 EhcCreateQtd (\r
   IN USB2_HC_DEV          *Ehc,\r
   IN UINT8                *Data,\r
+  IN UINT8                *DataPhy,\r
   IN UINTN                DataLen,\r
   IN UINT8                PktId,\r
   IN UINT8                Toggle,\r
@@ -74,7 +68,7 @@ EhcCreateQtd (
   QtdHw->Status     = QTD_STAT_ACTIVE;\r
   QtdHw->Pid        = PktId;\r
   QtdHw->ErrCnt     = QTD_MAX_ERR;\r
-  QtdHw->IOC        = 0;\r
+  QtdHw->Ioc        = 0;\r
   QtdHw->TotalBytes = 0;\r
   QtdHw->DataToggle = Toggle;\r
 \r
@@ -90,10 +84,10 @@ EhcCreateQtd (
       // compute the offset and clear Reserved fields. This is already\r
       // done in the data point.\r
       //\r
-      QtdHw->Page[Index]      = EHC_LOW_32BIT (Data);\r
-      QtdHw->PageHigh[Index]  = EHC_HIGH_32BIT (Data);\r
+      QtdHw->Page[Index]      = EHC_LOW_32BIT (DataPhy);\r
+      QtdHw->PageHigh[Index]  = EHC_HIGH_32BIT (DataPhy);\r
 \r
-      ThisBufLen              = QTD_BUF_LEN - (EHC_LOW_32BIT (Data) & QTD_BUF_MASK);\r
+      ThisBufLen              = QTD_BUF_LEN - (EHC_LOW_32BIT (DataPhy) & QTD_BUF_MASK);\r
 \r
       if (Len + ThisBufLen >= DataLen) {\r
         Len = DataLen;\r
@@ -102,6 +96,7 @@ EhcCreateQtd (
 \r
       Len += ThisBufLen;\r
       Data += ThisBufLen;\r
+      DataPhy += ThisBufLen;\r
     }\r
 \r
     //\r
@@ -130,13 +125,10 @@ EhcCreateQtd (
   2. Microframe S-mask\r
   3. Microframe C-mask\r
 \r
-  @param  Ep                    The queue head's related endpoint\r
-  @param  QhHw                  The queue head to initialize\r
-\r
-  @return None\r
+  @param  Ep                    The queue head's related endpoint.\r
+  @param  QhHw                  The queue head to initialize.\r
 \r
 **/\r
-STATIC\r
 VOID\r
 EhcInitIntQh (\r
   IN USB_ENDPOINT         *Ep,\r
@@ -173,12 +165,12 @@ EhcInitIntQh (
 \r
 \r
 /**\r
-  Allocate and initialize a EHCI queue head\r
+  Allocate and initialize a EHCI queue head.\r
 \r
-  @param  Ehci                  The EHCI device\r
-  @param  Ep                    The endpoint to create queue head for\r
+  @param  Ehci                  The EHCI device.\r
+  @param  Ep                    The endpoint to create queue head for.\r
 \r
-  @return Created queue head or NULL if failed to create one\r
+  @return Created queue head or NULL if failed to create one.\r
 \r
 **/\r
 EHC_QH *\r
@@ -258,21 +250,19 @@ EhcCreateQh (
 }\r
 \r
 \r
-\r
 /**\r
   Convert the poll interval from application to that\r
   be used by EHCI interface data structure. Only need\r
   to get the max 2^n that is less than interval. UEFI\r
   can't support high speed endpoint with a interval less\r
   than 8 microframe because interval is specified in\r
-  the unit of ms (millisecond)\r
+  the unit of ms (millisecond).\r
 \r
-  @param  Interval              The interval to convert\r
+  @param  Interval              The interval to convert.\r
 \r
-  @return The converted interval\r
+  @return The converted interval.\r
 \r
 **/\r
-STATIC\r
 UINTN\r
 EhcConvertPollRate (\r
   IN  UINTN               Interval\r
@@ -294,21 +284,17 @@ EhcConvertPollRate (
     BitCount++;\r
   }\r
 \r
-  return 1 << (BitCount - 1);\r
+  return (UINTN)1 << (BitCount - 1);\r
 }\r
 \r
 \r
-\r
 /**\r
-  Free a list of QTDs\r
+  Free a list of QTDs.\r
 \r
-  @param  Ehc                   The EHCI device\r
-  @param  Qtds                  The list head of the QTD\r
-\r
-  @return None\r
+  @param  Ehc                   The EHCI device.\r
+  @param  Qtds                  The list head of the QTD.\r
 \r
 **/\r
-STATIC\r
 VOID\r
 EhcFreeQtds (\r
   IN USB2_HC_DEV          *Ehc,\r
@@ -331,10 +317,8 @@ EhcFreeQtds (
 /**\r
   Free an allocated URB. It is possible for it to be partially inited.\r
 \r
-  @param  Ehc                   The EHCI device\r
-  @param  Urb                   The URB to free\r
-\r
-  @return None\r
+  @param  Ehc                   The EHCI device.\r
+  @param  Urb                   The URB to free.\r
 \r
 **/\r
 VOID\r
@@ -368,18 +352,16 @@ EhcFreeUrb (
 }\r
 \r
 \r
-\r
 /**\r
-  Create a list of QTDs for the URB\r
+  Create a list of QTDs for the URB.\r
 \r
-  @param  Ehc                   The EHCI device\r
-  @param  Urb                   The URB to create QTDs for\r
+  @param  Ehc                   The EHCI device.\r
+  @param  Urb                   The URB to create QTDs for.\r
 \r
-  @retval EFI_OUT_OF_RESOURCES  Failed to allocate resource for QTD\r
-  @retval EFI_SUCCESS           The QTDs are allocated for the URB\r
+  @retval EFI_OUT_OF_RESOURCES  Failed to allocate resource for QTD.\r
+  @retval EFI_SUCCESS           The QTDs are allocated for the URB.\r
 \r
 **/\r
-STATIC\r
 EFI_STATUS\r
 EhcCreateQtds (\r
   IN USB2_HC_DEV          *Ehc,\r
@@ -396,6 +378,7 @@ EhcCreateQtds (
   UINT8                   Toggle;\r
   UINTN                   Len;\r
   UINT8                   Pid;\r
+  EFI_PHYSICAL_ADDRESS    PhyAddr;\r
 \r
   ASSERT ((Urb != NULL) && (Urb->Qh != NULL));\r
 \r
@@ -411,8 +394,9 @@ EhcCreateQtds (
   StatusQtd = NULL;\r
   AlterNext = QTD_LINK (NULL, TRUE);\r
 \r
+  PhyAddr   = UsbHcGetPciAddressForHostMem (Ehc->MemPool, Ehc->ShortReadStop, sizeof (EHC_QTD));\r
   if (Ep->Direction == EfiUsbDataIn) {\r
-    AlterNext = QTD_LINK (Ehc->ShortReadStop, FALSE);\r
+    AlterNext = QTD_LINK (PhyAddr, FALSE);\r
   }\r
 \r
   //\r
@@ -420,7 +404,7 @@ EhcCreateQtds (
   //\r
   if (Urb->Ep.Type == EHC_CTRL_TRANSFER) {\r
     Len = sizeof (EFI_USB_DEVICE_REQUEST);\r
-    Qtd = EhcCreateQtd (Ehc, Urb->RequestPhy, Len, QTD_PID_SETUP, 0, Ep->MaxPacket);\r
+    Qtd = EhcCreateQtd (Ehc, (UINT8 *)Urb->Request, (UINT8 *)Urb->RequestPhy, Len, QTD_PID_SETUP, 0, Ep->MaxPacket);\r
 \r
     if (Qtd == NULL) {\r
       return EFI_OUT_OF_RESOURCES;\r
@@ -440,14 +424,15 @@ EhcCreateQtds (
       Pid = QTD_PID_INPUT;\r
     }\r
 \r
-    StatusQtd = EhcCreateQtd (Ehc, NULL, 0, Pid, 1, Ep->MaxPacket);\r
+    StatusQtd = EhcCreateQtd (Ehc, NULL, NULL, 0, Pid, 1, Ep->MaxPacket);\r
 \r
     if (StatusQtd == NULL) {\r
       goto ON_ERROR;\r
     }\r
 \r
     if (Ep->Direction == EfiUsbDataIn) {\r
-      AlterNext = QTD_LINK (StatusQtd, FALSE);\r
+      PhyAddr   = UsbHcGetPciAddressForHostMem (Ehc->MemPool, StatusQtd, sizeof (EHC_QTD));\r
+      AlterNext = QTD_LINK (PhyAddr, FALSE);\r
     }\r
 \r
     Toggle = 1;\r
@@ -468,6 +453,7 @@ EhcCreateQtds (
   while (Len < Urb->DataLen) {\r
     Qtd = EhcCreateQtd (\r
             Ehc,\r
+            (UINT8 *) Urb->Data + Len,\r
             (UINT8 *) Urb->DataPhy + Len,\r
             Urb->DataLen - Len,\r
             Pid,\r
@@ -486,7 +472,7 @@ EhcCreateQtds (
     // Switch the Toggle bit if odd number of packets are included in the QTD.\r
     //\r
     if (((Qtd->DataLen + Ep->MaxPacket - 1) / Ep->MaxPacket) % 2) {\r
-      Toggle = 1 - Toggle;\r
+      Toggle = (UINT8) (1 - Toggle);\r
     }\r
 \r
     Len += Qtd->DataLen;\r
@@ -513,14 +499,16 @@ EhcCreateQtds (
     }\r
 \r
     NextQtd             = EFI_LIST_CONTAINER (Entry->ForwardLink, EHC_QTD, QtdList);\r
-    Qtd->QtdHw.NextQtd  = QTD_LINK (NextQtd, FALSE);\r
+    PhyAddr             = UsbHcGetPciAddressForHostMem (Ehc->MemPool, NextQtd, sizeof (EHC_QTD));\r
+    Qtd->QtdHw.NextQtd  = QTD_LINK (PhyAddr, FALSE);\r
   }\r
 \r
   //\r
   // Link the QTDs to the queue head\r
   //\r
   NextQtd           = EFI_LIST_CONTAINER (Qh->Qtds.ForwardLink, EHC_QTD, QtdList);\r
-  Qh->QhHw.NextQtd  = QTD_LINK (NextQtd, FALSE);\r
+  PhyAddr           = UsbHcGetPciAddressForHostMem (Ehc->MemPool, NextQtd, sizeof (EHC_QTD));\r
+  Qh->QhHw.NextQtd  = QTD_LINK (PhyAddr, FALSE);\r
   return EFI_SUCCESS;\r
 \r
 ON_ERROR:\r
@@ -530,24 +518,24 @@ ON_ERROR:
 \r
 \r
 /**\r
-  Create a new URB and its associated QTD\r
-\r
-  @param  Ehc                   The EHCI device\r
-  @param  DevAddr               The device address\r
-  @param  EpAddr                Endpoint addrress & its direction\r
-  @param  DevSpeed              The device speed\r
-  @param  Toggle                Initial data toggle to use\r
-  @param  MaxPacket             The max packet length of the endpoint\r
-  @param  Hub                   The transaction translator to use\r
-  @param  Type                  The transaction type\r
-  @param  Request               The standard USB request for control transfer\r
-  @param  Data                  The user data to transfer\r
-  @param  DataLen               The length of data buffer\r
-  @param  Callback              The function to call when data is transferred\r
-  @param  Context               The context to the callback\r
-  @param  Interval              The interval for interrupt transfer\r
-\r
-  @return Created URB or NULL\r
+  Create a new URB and its associated QTD.\r
+\r
+  @param  Ehc                   The EHCI device.\r
+  @param  DevAddr               The device address.\r
+  @param  EpAddr                Endpoint addrress & its direction.\r
+  @param  DevSpeed              The device speed.\r
+  @param  Toggle                Initial data toggle to use.\r
+  @param  MaxPacket             The max packet length of the endpoint.\r
+  @param  Hub                   The transaction translator to use.\r
+  @param  Type                  The transaction type.\r
+  @param  Request               The standard USB request for control transfer.\r
+  @param  Data                  The user data to transfer.\r
+  @param  DataLen               The length of data buffer.\r
+  @param  Callback              The function to call when data is transferred.\r
+  @param  Context               The context to the callback.\r
+  @param  Interval              The interval for interrupt transfer.\r
+\r
+  @return Created URB or NULL.\r
 \r
 **/\r
 URB *\r
@@ -588,8 +576,8 @@ EhcCreateUrb (
 \r
   Ep              = &Urb->Ep;\r
   Ep->DevAddr     = DevAddr;\r
-  Ep->EpAddr      = EpAddr & 0x0F;\r
-  Ep->Direction   = ((EpAddr & 0x80) ? EfiUsbDataIn : EfiUsbDataOut);\r
+  Ep->EpAddr      = (UINT8) (EpAddr & 0x0F);\r
+  Ep->Direction   = (((EpAddr & 0x80) != 0) ? EfiUsbDataIn : EfiUsbDataOut);\r
   Ep->DevSpeed    = DevSpeed;\r
   Ep->MaxPacket   = MaxPacket;\r
 \r