Home | History | Annotate | Download | only in UhciDxe
      1 /** @file
      2 
      3   The definition for EHCI register operation routines.
      4 
      5 Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
      6 This program and the accompanying materials
      7 are licensed and made available under the terms and conditions of the BSD License
      8 which accompanies this distribution.  The full text of the license may be found at
      9 http://opensource.org/licenses/bsd-license.php
     10 
     11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     13 
     14 **/
     15 
     16 #ifndef _EFI_UHCI_SCHED_H_
     17 #define _EFI_UHCI_SCHED_H_
     18 
     19 
     20 #define UHCI_ASYNC_INT_SIGNATURE  SIGNATURE_32 ('u', 'h', 'c', 'a')
     21 //
     22 // The failure mask for USB transfer return status. If any of
     23 // these bit is set, the transfer failed. EFI_USB_ERR_NOEXECUTE
     24 // and EFI_USB_ERR_NAK are not considered as error condition:
     25 // the transfer is still going on.
     26 //
     27 #define USB_ERR_FAIL_MASK  (EFI_USB_ERR_STALL   | EFI_USB_ERR_BUFFER | \
     28                             EFI_USB_ERR_BABBLE  | EFI_USB_ERR_CRC    | \
     29                             EFI_USB_ERR_TIMEOUT | EFI_USB_ERR_BITSTUFF | \
     30                             EFI_USB_ERR_SYSTEM)
     31 
     32 
     33 //
     34 // Structure to return the result of UHCI QH execution.
     35 // Result is the final result of the QH's QTD. NextToggle
     36 // is the next data toggle to use. Complete is the actual
     37 // length of data transferred.
     38 //
     39 typedef struct {
     40   UINT32                  Result;
     41   UINT8                   NextToggle;
     42   UINTN                   Complete;
     43 } UHCI_QH_RESULT;
     44 
     45 typedef struct _UHCI_ASYNC_REQUEST  UHCI_ASYNC_REQUEST;
     46 
     47 //
     48 // Structure used to manager the asynchronous interrupt transfers.
     49 //
     50 struct _UHCI_ASYNC_REQUEST{
     51   UINTN                           Signature;
     52   LIST_ENTRY                      Link;
     53   UHCI_ASYNC_REQUEST              *Recycle;
     54 
     55   //
     56   // Endpoint attributes
     57   //
     58   UINT8                           DevAddr;
     59   UINT8                           EndPoint;
     60   BOOLEAN                         IsLow;
     61   UINTN                           Interval;
     62 
     63   //
     64   // Data and UHC structures
     65   //
     66   UHCI_QH_SW                      *QhSw;
     67   UHCI_TD_SW                      *FirstTd;
     68   UINT8                           *Data;      // Allocated host memory, not mapped memory
     69   UINTN                           DataLen;
     70   VOID                            *Mapping;
     71 
     72   //
     73   // User callback and its context
     74   //
     75   EFI_ASYNC_USB_TRANSFER_CALLBACK Callback;
     76   VOID                            *Context;
     77 };
     78 
     79 #define UHCI_ASYNC_INT_FROM_LINK(a) \
     80           CR (a, UHCI_ASYNC_REQUEST, Link, UHCI_ASYNC_INT_SIGNATURE)
     81 
     82 
     83 /**
     84   Create Frame List Structure.
     85 
     86   @param  Uhc                    The UHCI device.
     87 
     88   @return EFI_OUT_OF_RESOURCES   Can't allocate memory resources.
     89   @return EFI_UNSUPPORTED        Map memory fail.
     90   @return EFI_SUCCESS            Success.
     91 
     92 **/
     93 EFI_STATUS
     94 UhciInitFrameList (
     95   IN USB_HC_DEV         *Uhc
     96   );
     97 
     98 /**
     99   Destory FrameList buffer.
    100 
    101   @param  Uhc                    The UHCI device.
    102 
    103   @return None.
    104 
    105 **/
    106 VOID
    107 UhciDestoryFrameList (
    108   IN USB_HC_DEV           *Uhc
    109   );
    110 
    111 
    112 /**
    113   Convert the poll rate to the maxium 2^n that is smaller
    114   than Interval.
    115 
    116   @param  Interval               The poll rate to convert.
    117 
    118   @return The converted poll rate.
    119 
    120 **/
    121 UINTN
    122 UhciConvertPollRate (
    123   IN  UINTN               Interval
    124   );
    125 
    126 
    127 /**
    128   Link a queue head (for asynchronous interrupt transfer) to
    129   the frame list.
    130 
    131   @param  Uhc                    The UHCI device.
    132   @param  Qh                     The queue head to link into.
    133 
    134 **/
    135 VOID
    136 UhciLinkQhToFrameList (
    137   USB_HC_DEV              *Uhc,
    138   UHCI_QH_SW              *Qh
    139   );
    140 
    141 
    142 /**
    143   Unlink QH from the frame list is easier: find all
    144   the precedence node, and pointer there next to QhSw's
    145   next.
    146 
    147   @param  Uhc                    The UHCI device.
    148   @param  Qh                     The queue head to unlink.
    149 
    150 **/
    151 VOID
    152 UhciUnlinkQhFromFrameList (
    153   USB_HC_DEV              *Uhc,
    154   UHCI_QH_SW              *Qh
    155   );
    156 
    157 
    158 /**
    159   Check the result of the transfer.
    160 
    161   @param  Uhc                    The UHCI device.
    162   @param  Qh                     The queue head of the transfer.
    163   @param  Td                     The first TDs of the transfer.
    164   @param  TimeOut                TimeOut value in milliseconds.
    165   @param  IsLow                  Is Low Speed Device.
    166   @param  QhResult               The variable to return result.
    167 
    168   @retval EFI_SUCCESS            The transfer finished with success.
    169   @retval EFI_DEVICE_ERROR       Transfer failed.
    170 
    171 **/
    172 EFI_STATUS
    173 UhciExecuteTransfer (
    174   IN  USB_HC_DEV          *Uhc,
    175   IN  UHCI_QH_SW          *Qh,
    176   IN  UHCI_TD_SW          *Td,
    177   IN  UINTN               TimeOut,
    178   IN  BOOLEAN             IsLow,
    179   OUT UHCI_QH_RESULT      *QhResult
    180   );
    181 
    182 
    183 /**
    184   Create Async Request node, and Link to List.
    185 
    186   @param  Uhc                    The UHCI device.
    187   @param  Qh                     The queue head of the transfer.
    188   @param  FirstTd                First TD of the transfer.
    189   @param  DevAddr                Device Address.
    190   @param  EndPoint               EndPoint Address.
    191   @param  DataLen                Data length.
    192   @param  Interval               Polling Interval when inserted to frame list.
    193   @param  Data                   Data buffer, unmapped.
    194   @param  Callback               Callback after interrupt transfeer.
    195   @param  Context                Callback Context passed as function parameter.
    196   @param  IsLow                  Is Low Speed.
    197 
    198   @retval EFI_SUCCESS            An asynchronous transfer is created.
    199   @retval EFI_INVALID_PARAMETER  Paremeter is error.
    200   @retval EFI_OUT_OF_RESOURCES   Failed because of resource shortage.
    201 
    202 **/
    203 EFI_STATUS
    204 UhciCreateAsyncReq (
    205   IN USB_HC_DEV                       *Uhc,
    206   IN UHCI_QH_SW                       *Qh,
    207   IN UHCI_TD_SW                       *FirstTd,
    208   IN UINT8                            DevAddr,
    209   IN UINT8                            EndPoint,
    210   IN UINTN                            DataLen,
    211   IN UINTN                            Interval,
    212   IN UINT8                            *Data,
    213   IN EFI_ASYNC_USB_TRANSFER_CALLBACK  Callback,
    214   IN VOID                             *Context,
    215   IN BOOLEAN                          IsLow
    216   );
    217 
    218 
    219 /**
    220   Delete Async Interrupt QH and TDs.
    221 
    222   @param  Uhc                    The UHCI device.
    223   @param  DevAddr                Device Address.
    224   @param  EndPoint               EndPoint Address.
    225   @param  Toggle                 The next data toggle to use.
    226 
    227   @retval EFI_SUCCESS            The request is deleted.
    228   @retval EFI_INVALID_PARAMETER  Paremeter is error.
    229   @retval EFI_NOT_FOUND          The asynchronous isn't found.
    230 
    231 **/
    232 EFI_STATUS
    233 UhciRemoveAsyncReq (
    234   IN  USB_HC_DEV          *Uhc,
    235   IN  UINT8               DevAddr,
    236   IN  UINT8               EndPoint,
    237   OUT UINT8               *Toggle
    238   );
    239 
    240 
    241 /**
    242   Release all the asynchronous transfers on the lsit.
    243 
    244   @param  Uhc                    The UHCI device.
    245 
    246   @return None.
    247 
    248 **/
    249 VOID
    250 UhciFreeAllAsyncReq (
    251   IN USB_HC_DEV           *Uhc
    252   );
    253 
    254 
    255 /**
    256   Interrupt transfer periodic check handler.
    257 
    258   @param  Event                  The event of the time.
    259   @param  Context                Context of the event, pointer to USB_HC_DEV.
    260 
    261   @return None.
    262 
    263 **/
    264 VOID
    265 EFIAPI
    266 UhciMonitorAsyncReqList (
    267   IN EFI_EVENT            Event,
    268   IN VOID                 *Context
    269   );
    270 
    271 #endif
    272