TianoCore EDK2 master
Loading...
Searching...
No Matches
XhcPeim.h File Reference
#include <PiPei.h>
#include <Ppi/UsbController.h>
#include <Ppi/Usb2HostController.h>
#include <Ppi/IoMmu.h>
#include <Ppi/EndOfPeiPhase.h>
#include <Library/DebugLib.h>
#include <Library/PeimEntryPoint.h>
#include <Library/PeiServicesLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/TimerLib.h>
#include <Library/IoLib.h>
#include <Library/MemoryAllocationLib.h>
#include "UsbHcMem.h"
#include "XhciReg.h"
#include "XhciSched.h"

Go to the source code of this file.

Data Structures

struct  _USB_DEV_CONTEXT
 
struct  _PEI_XHC_DEV
 

Macros

#define CMD_RING_TRB_NUMBER   0x100
 
#define TR_RING_TRB_NUMBER   0x100
 
#define ERST_NUMBER   0x01
 
#define EVENT_RING_TRB_NUMBER   0x200
 
#define XHC_1_MICROSECOND   1
 
#define XHC_1_MILLISECOND   (1000 * XHC_1_MICROSECOND)
 
#define XHC_1_SECOND   (1000 * XHC_1_MILLISECOND)
 
#define XHC_RESET_TIMEOUT   (1000)
 
#define XHC_RESET_RECOVERY_DELAY   (10 * 1000)
 
#define XHC_ROOT_PORT_STATE_STABLE   (200 * XHC_1_MILLISECOND)
 
#define XHC_GENERIC_TIMEOUT   (10 * 1000)
 
#define XHC_LOW_32BIT(Addr64)   ((UINT32)(((UINTN)(Addr64)) & 0XFFFFFFFF))
 
#define XHC_HIGH_32BIT(Addr64)   ((UINT32)(RShiftU64((UINTN)(Addr64), 32) & 0XFFFFFFFF))
 
#define XHC_BIT_IS_SET(Data, Bit)   ((BOOLEAN)(((Data) & (Bit)) == (Bit)))
 
#define XHC_REG_BIT_IS_SET(XHC, Offset, Bit)    (XHC_BIT_IS_SET(XhcPeiReadOpReg ((XHC), (Offset)), (Bit)))
 
#define USB_DESC_TYPE_HUB   0x29
 
#define USB_DESC_TYPE_HUB_SUPER_SPEED   0x2a
 
#define USB_REQUEST_TYPE(Dir, Type, Target)    ((UINT8)((((Dir) == EfiUsbDataIn ? 0x01 : 0) << 7) | (Type) | (Target)))
 
#define USB_XHC_DEV_SIGNATURE   SIGNATURE_32 ('x', 'h', 'c', 'i')
 
#define PEI_RECOVERY_USB_XHC_DEV_FROM_THIS(a)   CR (a, PEI_XHC_DEV, Usb2HostControllerPpi, USB_XHC_DEV_SIGNATURE)
 
#define PEI_RECOVERY_USB_XHC_DEV_FROM_THIS_NOTIFY(a)   CR (a, PEI_XHC_DEV, EndOfPeiNotifyList, USB_XHC_DEV_SIGNATURE)
 

Typedefs

typedef struct _PEI_XHC_DEV PEI_XHC_DEV
 
typedef struct _USB_DEV_CONTEXT USB_DEV_CONTEXT
 

Functions

USBHC_MEM_POOLUsbHcInitMemPool (VOID)
 
VOID UsbHcFreeMemPool (IN USBHC_MEM_POOL *Pool)
 
VOID * UsbHcAllocateMem (IN USBHC_MEM_POOL *Pool, IN UINTN Size)
 
VOID UsbHcFreeMem (IN USBHC_MEM_POOL *Pool, IN VOID *Mem, IN UINTN Size)
 
VOID IoMmuInit (VOID)
 
EFI_STATUS IoMmuMap (IN EDKII_IOMMU_OPERATION Operation, IN VOID *HostAddress, IN OUT UINTN *NumberOfBytes, OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, OUT VOID **Mapping)
 
EFI_STATUS IoMmuUnmap (IN VOID *Mapping)
 
EFI_STATUS IoMmuAllocateBuffer (IN UINTN Pages, OUT VOID **HostAddress, OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, OUT VOID **Mapping)
 
EFI_STATUS IoMmuFreeBuffer (IN UINTN Pages, IN VOID *HostAddress, IN VOID *Mapping)
 
EFI_STATUS IoMmuAllocateAlignedBuffer (IN UINTN Pages, IN UINTN Alignment, OUT VOID **HostAddress, OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, OUT VOID **Mapping)
 

Detailed Description

Private Header file for Usb Host Controller PEIM

Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.

SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file XhcPeim.h.

Macro Definition Documentation

◆ CMD_RING_TRB_NUMBER

#define CMD_RING_TRB_NUMBER   0x100

Definition at line 35 of file XhcPeim.h.

◆ ERST_NUMBER

#define ERST_NUMBER   0x01

Definition at line 37 of file XhcPeim.h.

◆ EVENT_RING_TRB_NUMBER

#define EVENT_RING_TRB_NUMBER   0x200

Definition at line 38 of file XhcPeim.h.

◆ PEI_RECOVERY_USB_XHC_DEV_FROM_THIS

#define PEI_RECOVERY_USB_XHC_DEV_FROM_THIS (   a)    CR (a, PEI_XHC_DEV, Usb2HostControllerPpi, USB_XHC_DEV_SIGNATURE)

Definition at line 189 of file XhcPeim.h.

◆ PEI_RECOVERY_USB_XHC_DEV_FROM_THIS_NOTIFY

#define PEI_RECOVERY_USB_XHC_DEV_FROM_THIS_NOTIFY (   a)    CR (a, PEI_XHC_DEV, EndOfPeiNotifyList, USB_XHC_DEV_SIGNATURE)

Definition at line 190 of file XhcPeim.h.

◆ TR_RING_TRB_NUMBER

#define TR_RING_TRB_NUMBER   0x100

Definition at line 36 of file XhcPeim.h.

◆ USB_DESC_TYPE_HUB

#define USB_DESC_TYPE_HUB   0x29

Definition at line 74 of file XhcPeim.h.

◆ USB_DESC_TYPE_HUB_SUPER_SPEED

#define USB_DESC_TYPE_HUB_SUPER_SPEED   0x2a

Definition at line 75 of file XhcPeim.h.

◆ USB_REQUEST_TYPE

#define USB_REQUEST_TYPE (   Dir,
  Type,
  Target 
)     ((UINT8)((((Dir) == EfiUsbDataIn ? 0x01 : 0) << 7) | (Type) | (Target)))

Definition at line 82 of file XhcPeim.h.

◆ USB_XHC_DEV_SIGNATURE

#define USB_XHC_DEV_SIGNATURE   SIGNATURE_32 ('x', 'h', 'c', 'i')

Definition at line 141 of file XhcPeim.h.

◆ XHC_1_MICROSECOND

#define XHC_1_MICROSECOND   1

Definition at line 40 of file XhcPeim.h.

◆ XHC_1_MILLISECOND

#define XHC_1_MILLISECOND   (1000 * XHC_1_MICROSECOND)

Definition at line 41 of file XhcPeim.h.

◆ XHC_1_SECOND

#define XHC_1_SECOND   (1000 * XHC_1_MILLISECOND)

Definition at line 42 of file XhcPeim.h.

◆ XHC_BIT_IS_SET

#define XHC_BIT_IS_SET (   Data,
  Bit 
)    ((BOOLEAN)(((Data) & (Bit)) == (Bit)))

Definition at line 69 of file XhcPeim.h.

◆ XHC_GENERIC_TIMEOUT

#define XHC_GENERIC_TIMEOUT   (10 * 1000)

Definition at line 65 of file XhcPeim.h.

◆ XHC_HIGH_32BIT

#define XHC_HIGH_32BIT (   Addr64)    ((UINT32)(RShiftU64((UINTN)(Addr64), 32) & 0XFFFFFFFF))

Definition at line 68 of file XhcPeim.h.

◆ XHC_LOW_32BIT

#define XHC_LOW_32BIT (   Addr64)    ((UINT32)(((UINTN)(Addr64)) & 0XFFFFFFFF))

Definition at line 67 of file XhcPeim.h.

◆ XHC_REG_BIT_IS_SET

#define XHC_REG_BIT_IS_SET (   XHC,
  Offset,
  Bit 
)     (XHC_BIT_IS_SET(XhcPeiReadOpReg ((XHC), (Offset)), (Bit)))

Definition at line 71 of file XhcPeim.h.

◆ XHC_RESET_RECOVERY_DELAY

#define XHC_RESET_RECOVERY_DELAY   (10 * 1000)

Definition at line 54 of file XhcPeim.h.

◆ XHC_RESET_TIMEOUT

#define XHC_RESET_TIMEOUT   (1000)

Definition at line 48 of file XhcPeim.h.

◆ XHC_ROOT_PORT_STATE_STABLE

#define XHC_ROOT_PORT_STATE_STABLE   (200 * XHC_1_MILLISECOND)

Definition at line 59 of file XhcPeim.h.

Typedef Documentation

◆ PEI_XHC_DEV

typedef struct _PEI_XHC_DEV PEI_XHC_DEV

Definition at line 28 of file XhcPeim.h.

◆ USB_DEV_CONTEXT

Definition at line 29 of file XhcPeim.h.

Function Documentation

◆ IoMmuAllocateAlignedBuffer()

EFI_STATUS IoMmuAllocateAlignedBuffer ( IN UINTN  Pages,
IN UINTN  Alignment,
OUT VOID **  HostAddress,
OUT EFI_PHYSICAL_ADDRESS DeviceAddress,
OUT VOID **  Mapping 
)

Allocates aligned pages that are suitable for an OperationBusMasterCommonBuffer or OperationBusMasterCommonBuffer64 mapping.

Parameters
PagesThe number of pages to allocate.
AlignmentThe requested alignment of the allocation. Must be a power of two.
HostAddressA pointer to store the base system memory address of the allocated range.
DeviceAddressThe resulting map address for the bus master PCI controller to use to access the hosts HostAddress.
MappingA resulting value to pass to Unmap().
Return values
EFI_SUCCESSThe requested memory pages were allocated.
EFI_UNSUPPORTEDAttributes is unsupported. The only legal attribute bits are MEMORY_WRITE_COMBINE and MEMORY_CACHED.
EFI_INVALID_PARAMETEROne or more parameters are invalid.
EFI_OUT_OF_RESOURCESThe memory pages could not be allocated.

Definition at line 255 of file DmaMem.c.

◆ IoMmuAllocateBuffer()

EFI_STATUS IoMmuAllocateBuffer ( IN UINTN  Pages,
OUT VOID **  HostAddress,
OUT EFI_PHYSICAL_ADDRESS DeviceAddress,
OUT VOID **  Mapping 
)

Allocates pages that are suitable for an OperationBusMasterCommonBuffer or OperationBusMasterCommonBuffer64 mapping.

Parameters
PagesThe number of pages to allocate.
HostAddressA pointer to store the base system memory address of the allocated range.
DeviceAddressThe resulting map address for the bus master PCI controller to use to access the hosts HostAddress.
MappingA resulting value to pass to Unmap().
Return values
EFI_SUCCESSThe requested memory pages were allocated.
EFI_UNSUPPORTEDAttributes is unsupported. The only legal attribute bits are MEMORY_WRITE_COMBINE and MEMORY_CACHED.
EFI_INVALID_PARAMETEROne or more parameters are invalid.
EFI_OUT_OF_RESOURCESThe memory pages could not be allocated.

Definition at line 170 of file DmaMem.c.

◆ IoMmuFreeBuffer()

EFI_STATUS IoMmuFreeBuffer ( IN UINTN  Pages,
IN VOID *  HostAddress,
IN VOID *  Mapping 
)

Frees memory that was allocated with AllocateBuffer().

Parameters
PagesThe number of pages to free.
HostAddressThe base system memory address of the allocated range.
MappingThe mapping value returned from Map().
Return values
EFI_SUCCESSThe requested memory pages were freed.
EFI_INVALID_PARAMETERThe memory range specified by HostAddress and Pages was not allocated with AllocateBuffer().

Definition at line 251 of file DmaMem.c.

◆ IoMmuInit()

VOID IoMmuInit ( VOID  )

Initialize IOMMU.

Definition at line 375 of file DmaMem.c.

◆ IoMmuMap()

EFI_STATUS IoMmuMap ( IN EDKII_IOMMU_OPERATION  Operation,
IN VOID *  HostAddress,
IN OUT UINTN NumberOfBytes,
OUT EFI_PHYSICAL_ADDRESS DeviceAddress,
OUT VOID **  Mapping 
)

Provides the controller-specific addresses required to access system memory from a DMA bus master.

Parameters
OperationIndicates if the bus master is going to read or write to system memory.
HostAddressThe system memory address to map to the PCI controller.
NumberOfBytesOn input the number of bytes to map. On output the number of bytes that were mapped.
DeviceAddressThe resulting map address for the bus master PCI controller to use to access the hosts HostAddress.
MappingA resulting value to pass to Unmap().
Return values
EFI_SUCCESSThe range was mapped for the returned NumberOfBytes.
EFI_UNSUPPORTEDThe HostAddress cannot be mapped as a common buffer.
EFI_INVALID_PARAMETEROne or more parameters are invalid.
EFI_OUT_OF_RESOURCESThe request could not be completed due to a lack of resources.
EFI_DEVICE_ERRORThe system hardware could not map the requested address.

Definition at line 60 of file DmaMem.c.

◆ IoMmuUnmap()

EFI_STATUS IoMmuUnmap ( IN VOID *  Mapping)

Completes the Map() operation and releases any corresponding resources.

Parameters
MappingThe mapping value returned from Map().
Return values
EFI_SUCCESSThe range was unmapped.
EFI_INVALID_PARAMETERMapping is not a value that was returned by Map().
EFI_DEVICE_ERRORThe data was not committed to the target system memory.

Definition at line 132 of file DmaMem.c.

◆ UsbHcAllocateMem()

VOID * UsbHcAllocateMem ( IN USBHC_MEM_POOL Pool,
IN UINTN  Size 
)

Allocate some memory from the host controller's memory pool which can be used to communicate with host controller.

Parameters
PoolThe host controller's memory pool.
SizeSize of the memory to allocate.
Returns
The allocated memory or NULL.

Definition at line 419 of file UsbHcMem.c.

◆ UsbHcFreeMem()

VOID UsbHcFreeMem ( IN USBHC_MEM_POOL Pool,
IN VOID *  Mem,
IN UINTN  Size 
)

Free the allocated memory back to the memory pool.

Parameters
PoolThe memory pool of the host controller.
MemThe memory to free.
SizeThe size of the memory to free.

Definition at line 493 of file UsbHcMem.c.

◆ UsbHcFreeMemPool()

VOID UsbHcFreeMemPool ( IN USBHC_MEM_POOL Pool)

Release the memory management pool.

Parameters
PoolThe USB memory pool to free.

Release the memory management pool.

Parameters
PoolThe USB memory pool to free.
Return values
EFI_SUCCESSThe memory pool is freed.
EFI_DEVICE_ERRORFailed to free the memory pool.

Release the memory management pool.

Parameters
PoolThe USB memory pool to free.
Returns
EFI_SUCCESS The memory pool is freed.
EFI_DEVICE_ERROR Failed to free the memory pool.

Definition at line 385 of file UsbHcMem.c.

◆ UsbHcInitMemPool()

USBHC_MEM_POOL * UsbHcInitMemPool ( VOID  )

Initialize the memory management pool for the host controller.

Returns
Pointer to the allocated memory pool or NULL if failed.

Definition at line 347 of file UsbHcMem.c.