Re: [edk2] [PATCH V2 1/4] MdeModulePkg XhciDxe: Extract new XhciInsertAsyncIntTransfer function

2018-10-26 Thread Zeng, Star
Good catch. I just posted V3 patches to cover it.

Thanks,
Star
-Original Message-
From: Wu, Hao A 
Sent: Friday, October 26, 2018 3:33 PM
To: Zeng, Star ; edk2-devel@lists.01.org
Cc: Ni, Ruiyu ; Wang, Jian J ; Yao, 
Jiewen 
Subject: RE: [PATCH V2 1/4] MdeModulePkg XhciDxe: Extract new 
XhciInsertAsyncIntTransfer function

Hi Star,

The interface for function XhciInsertAsyncIntTransfer() does not match between 
XhciSched.c and XhciSched.h.

Other than that:
Reviewed-by: Hao Wu 

Best Regards,
Hao Wu


> -Original Message-
> From: Zeng, Star
> Sent: Friday, October 26, 2018 1:42 PM
> To: edk2-devel@lists.01.org
> Cc: Zeng, Star; Ni, Ruiyu; Wu, Hao A; Wang, Jian J; Yao, Jiewen
> Subject: [PATCH V2 1/4] MdeModulePkg XhciDxe: Extract new 
> XhciInsertAsyncIntTransfer function
> 
> V2:
> Add the missing "FreePool (Data);".
> Remove the unnecessary indentation change.
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1274
> 
> Extract new XhciInsertAsyncIntTransfer function from 
> XhcAsyncInterruptTransfer.
> 
> It is code preparation for following patch, no essential functional 
> change.
> 
> Cc: Ruiyu Ni 
> Cc: Hao Wu 
> Cc: Jian J Wang 
> Cc: Jiewen Yao 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Star Zeng 
> ---
>  MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c  | 18 +
>  MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 65
> 
>  MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.h | 28 ++
>  3 files changed, 94 insertions(+), 17 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> index f1c60bef01c0..7f64f9c7c982 100644
> --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> @@ -1346,7 +1346,6 @@ XhcAsyncInterruptTransfer (
>EFI_STATUS  Status;
>UINT8   SlotId;
>UINT8   Index;
> -  UINT8   *Data;
>EFI_TPL OldTpl;
> 
>//
> @@ -1413,36 +1412,21 @@ XhcAsyncInterruptTransfer (
>  goto ON_EXIT;
>}
> 
> -  Data = AllocateZeroPool (DataLength);
> -
> -  if (Data == NULL) {
> -DEBUG ((EFI_D_ERROR, "XhcAsyncInterruptTransfer: failed to allocate
> buffer\n"));
> -Status = EFI_OUT_OF_RESOURCES;
> -goto ON_EXIT;
> -  }
> -
> -  Urb = XhcCreateUrb (
> +  Urb = XhciInsertAsyncIntTransfer (
>Xhc,
>DeviceAddress,
>EndPointAddress,
>DeviceSpeed,
>MaximumPacketLength,
> -  XHC_INT_TRANSFER_ASYNC,
> -  NULL,
> -  Data,
>DataLength,
>CallBackFunction,
>Context
>);
> -
>if (Urb == NULL) {
> -DEBUG ((EFI_D_ERROR, "XhcAsyncInterruptTransfer: failed to create
> URB\n"));
> -FreePool (Data);
>  Status = EFI_OUT_OF_RESOURCES;
>  goto ON_EXIT;
>}
> 
> -  InsertHeadList (>AsyncIntTransfers, >UrbList);
>//
>// Ring the doorbell
>//
> diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> index 166c44bf5e66..75959ae08363 100644
> --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> @@ -1411,6 +1411,71 @@ XhciDelAllAsyncIntTransfers (  }
> 
>  /**
> +  Insert a single asynchronous interrupt transfer for  the device and 
> + endpoint.
> +
> +  @param XhcThe XHCI Instance
> +  @param BusAddrThe logical device address assigned by UsbBus driver
> +  @param EpAddr Endpoint addrress
> +  @param DevSpeed   The device speed
> +  @param MaxPacket  The max packet length of the endpoint
> +  @param DataLenThe length of data buffer
> +  @param Callback   The function to call when data is transferred
> +  @param ContextThe context to the callback
> +
> +  @return Created URB or NULL
> +
> +**/
> +URB *
> +XhciInsertAsyncIntTransfer (
> +  IN USB_XHCI_INSTANCE  *Xhc,
> +  IN UINT8  BusAddr,
> +  IN UINT8  EpAddr,
> +  IN UINT8  DevSpeed,
> +  IN UINTN  MaxPacket,
> +  IN UINTN  DataLen,
> +  IN EFI_ASYNC_USB_TRANSFER_CALLBACKCallback,
> +  IN VOID   *Context
> +  )
> +{
> +  VOID  *Data;
> +  URB   *Urb;
> +
> +  Data = AllocateZeroPool (DataLen);
> +  if (Data == NULL) {
> +DEBUG ((DEBUG_ERROR, "%a: failed to allocate buffer\n",
> __FUNCTION__));
> +return NULL;
> +  }
> +
> +  Urb = XhcCreateUrb (
> +  Xhc,
> +  BusAddr,
> +  EpAddr,
> +  DevSpeed,
> +  MaxPacket,
> +  XHC_INT_TRANSFER_ASYNC,
> +  NULL,
> +  Data,
> +  DataLen,
> +  Callback,
> +  Context
> +  );
> +  if (Urb == NULL) {
> +DEBUG ((DEBUG_ERROR, "%a: failed to create URB\n", __FUNCTION__));
> 

Re: [edk2] [PATCH V2 1/4] MdeModulePkg XhciDxe: Extract new XhciInsertAsyncIntTransfer function

2018-10-26 Thread Wu, Hao A
Hi Star,

The interface for function XhciInsertAsyncIntTransfer() does not match between
XhciSched.c and XhciSched.h.

Other than that:
Reviewed-by: Hao Wu 

Best Regards,
Hao Wu


> -Original Message-
> From: Zeng, Star
> Sent: Friday, October 26, 2018 1:42 PM
> To: edk2-devel@lists.01.org
> Cc: Zeng, Star; Ni, Ruiyu; Wu, Hao A; Wang, Jian J; Yao, Jiewen
> Subject: [PATCH V2 1/4] MdeModulePkg XhciDxe: Extract new
> XhciInsertAsyncIntTransfer function
> 
> V2:
> Add the missing "FreePool (Data);".
> Remove the unnecessary indentation change.
> 
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1274
> 
> Extract new XhciInsertAsyncIntTransfer function from
> XhcAsyncInterruptTransfer.
> 
> It is code preparation for following patch,
> no essential functional change.
> 
> Cc: Ruiyu Ni 
> Cc: Hao Wu 
> Cc: Jian J Wang 
> Cc: Jiewen Yao 
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Star Zeng 
> ---
>  MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c  | 18 +
>  MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 65
> 
>  MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.h | 28 ++
>  3 files changed, 94 insertions(+), 17 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> index f1c60bef01c0..7f64f9c7c982 100644
> --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
> @@ -1346,7 +1346,6 @@ XhcAsyncInterruptTransfer (
>EFI_STATUS  Status;
>UINT8   SlotId;
>UINT8   Index;
> -  UINT8   *Data;
>EFI_TPL OldTpl;
> 
>//
> @@ -1413,36 +1412,21 @@ XhcAsyncInterruptTransfer (
>  goto ON_EXIT;
>}
> 
> -  Data = AllocateZeroPool (DataLength);
> -
> -  if (Data == NULL) {
> -DEBUG ((EFI_D_ERROR, "XhcAsyncInterruptTransfer: failed to allocate
> buffer\n"));
> -Status = EFI_OUT_OF_RESOURCES;
> -goto ON_EXIT;
> -  }
> -
> -  Urb = XhcCreateUrb (
> +  Urb = XhciInsertAsyncIntTransfer (
>Xhc,
>DeviceAddress,
>EndPointAddress,
>DeviceSpeed,
>MaximumPacketLength,
> -  XHC_INT_TRANSFER_ASYNC,
> -  NULL,
> -  Data,
>DataLength,
>CallBackFunction,
>Context
>);
> -
>if (Urb == NULL) {
> -DEBUG ((EFI_D_ERROR, "XhcAsyncInterruptTransfer: failed to create
> URB\n"));
> -FreePool (Data);
>  Status = EFI_OUT_OF_RESOURCES;
>  goto ON_EXIT;
>}
> 
> -  InsertHeadList (>AsyncIntTransfers, >UrbList);
>//
>// Ring the doorbell
>//
> diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> index 166c44bf5e66..75959ae08363 100644
> --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c
> @@ -1411,6 +1411,71 @@ XhciDelAllAsyncIntTransfers (
>  }
> 
>  /**
> +  Insert a single asynchronous interrupt transfer for
> +  the device and endpoint.
> +
> +  @param XhcThe XHCI Instance
> +  @param BusAddrThe logical device address assigned by UsbBus driver
> +  @param EpAddr Endpoint addrress
> +  @param DevSpeed   The device speed
> +  @param MaxPacket  The max packet length of the endpoint
> +  @param DataLenThe length of data buffer
> +  @param Callback   The function to call when data is transferred
> +  @param ContextThe context to the callback
> +
> +  @return Created URB or NULL
> +
> +**/
> +URB *
> +XhciInsertAsyncIntTransfer (
> +  IN USB_XHCI_INSTANCE  *Xhc,
> +  IN UINT8  BusAddr,
> +  IN UINT8  EpAddr,
> +  IN UINT8  DevSpeed,
> +  IN UINTN  MaxPacket,
> +  IN UINTN  DataLen,
> +  IN EFI_ASYNC_USB_TRANSFER_CALLBACKCallback,
> +  IN VOID   *Context
> +  )
> +{
> +  VOID  *Data;
> +  URB   *Urb;
> +
> +  Data = AllocateZeroPool (DataLen);
> +  if (Data == NULL) {
> +DEBUG ((DEBUG_ERROR, "%a: failed to allocate buffer\n",
> __FUNCTION__));
> +return NULL;
> +  }
> +
> +  Urb = XhcCreateUrb (
> +  Xhc,
> +  BusAddr,
> +  EpAddr,
> +  DevSpeed,
> +  MaxPacket,
> +  XHC_INT_TRANSFER_ASYNC,
> +  NULL,
> +  Data,
> +  DataLen,
> +  Callback,
> +  Context
> +  );
> +  if (Urb == NULL) {
> +DEBUG ((DEBUG_ERROR, "%a: failed to create URB\n", __FUNCTION__));
> +FreePool (Data);
> +return NULL;
> +  }
> +
> +  //
> +  // New asynchronous transfer must inserted to the head.
> +  // Check the comments in XhcMoniteAsyncRequests
> +  //
> +  InsertHeadList (>AsyncIntTransfers, >UrbList);
> +
> +  return Urb;
> +}
> +
> +/**
>Update the queue head for next round of asynchronous