summaryrefslogtreecommitdiff
path: root/ReferenceCode/Chipset/LynxPoint/PchInit/Pei/PchUsbInit.c
blob: 44381fc8240c26e235b28b08b1fb4c9f4b8d561b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/** @file
  Initializes PCH USB Controllers.

@copyright
  Copyright (c) 2009 - 2013 Intel Corporation. All rights reserved
  This software and associated documentation (if any) is furnished
  under a license and may only be used or copied in accordance
  with the terms of the license. Except as permitted by such
  license, no part of this software or documentation may be
  reproduced, stored in a retrieval system, or transmitted in any
  form or by any means without the express written consent of
  Intel Corporation.

  This file contains an 'Intel Peripheral Driver' and uniquely
  identified as "Intel Reference Module" and is
  licensed for Intel CPUs and chipsets under the terms of your
  license agreement with Intel or your vendor.  This file may
  be modified by the user, subject to additional terms of the
  license agreement

**/
#include "PchInitPeim.h"

/**
  The function performing USB init in PEI phase. This could be used by USB recovery
  or debug features that need USB initialization during PEI phase.
  Note: Before executing this function, please be sure that PCH_INIT_PPI.Initialize
  has been done and PchUsbPolicyPpi has been installed.

  @param[in] PeiServices    General purpose services available to every PEIM

  @retval EFI_SUCCESS       The function completed successfully
  @retval Others            All other error conditions encountered result in an ASSERT.
**/
EFI_STATUS
EFIAPI
PchUsbInit (
  IN EFI_PEI_SERVICES             **PeiServices
  )
{
  EFI_STATUS          Status;
  PCH_USB_POLICY_PPI  *PchUsbPolicyPpi;

  DEBUG ((EFI_D_INFO, "PchUsbInit() - Start\n"));

  ///
  /// Get PchUsbPolicy PPI for PCH_USB_CONFIG
  ///
  Status = (**PeiServices).LocatePpi (
                            PeiServices,
                            &gPchUsbPolicyPpiGuid,
                            0,
                            NULL,
                            (VOID **)&PchUsbPolicyPpi
                            );

  if (Status == EFI_SUCCESS) {
#ifdef EFI_DEBUG
    DEBUG ((EFI_D_INFO, "\n------------------------ PchUsbPolicyPpi Dump Begin -----------------\n"));
    DEBUG ((EFI_D_INFO, "Revision : 0x%x\n", PchUsbPolicyPpi->Revision));
    DEBUG ((EFI_D_INFO, "Mode : 0x%x\n", PchUsbPolicyPpi->Mode));
    DEBUG ((EFI_D_INFO, "EhciMemBaseAddr : 0x%x\n", PchUsbPolicyPpi->EhciMemBaseAddr));
    DEBUG ((EFI_D_INFO, "EhciMemLength : 0x%x\n", PchUsbPolicyPpi->EhciMemLength));
    DEBUG ((EFI_D_INFO, "XhciMemBaseAddr : 0x%x\n", PchUsbPolicyPpi->XhciMemBaseAddr));
#endif
    Status = PchStartUsbInit (
              PchUsbPolicyPpi->UsbConfig,
              (UINT32) PchUsbPolicyPpi->EhciMemBaseAddr,
              (UINT32) PchUsbPolicyPpi->XhciMemBaseAddr,
              PchUsbPolicyPpi->Revision
              );
#ifdef EFI_DEBUG
    DEBUG ((EFI_D_INFO, "\n"));
    DEBUG ((EFI_D_INFO, "\n------------------------ PchUsbPolicyPpi Dump End -----------------\n"));
#endif
  }
  DEBUG ((EFI_D_INFO, "PchUsbInit() - End\n"));
  return Status;
}

/**
  The function performing USB init in PEI phase. This could be
  used by USB recovery ,debug features or usb precondition
  enabled case that need USB initialization during PEI phase.
  Please be sure the function should not be executed in if the
  boot mode is S3 resume.

  @param[in] UsbConfig            Pointer to a PCH_USB_CONFIG that provides the platform setting
  @param[in] EhciMemBaseAddr      Predefined Ehci memory base address for Ehci hc configuration
  @param[in] XhciMemBaseAddr      Predefined Xhci memory base address for Xhci hc configuration
  @param[in] Revision             Revision of PCH_USB_CONFIG

  @retval EFI_SUCCESS             The function completed successfully
  @retval Others                  All other error conditions encountered result in an ASSERT
**/
EFI_STATUS
PchStartUsbInit (
  IN PCH_USB_CONFIG               *UsbConfig,
  IN UINT32                       EhciMemBaseAddr,
  IN UINT32                       XhciMemBaseAddr,
  IN UINT8                        Revision
  )
{
  EFI_STATUS          Status;
  UINT32              RootComplexBar;
  UINT32              FuncDisableReg;
#ifdef EFI_DEBUG
  UINT8               i;
#endif

  DEBUG ((EFI_D_INFO, "PchStartUsbInit() - Start\n"));
  Status = EFI_INVALID_PARAMETER;
  if (UsbConfig != NULL) {
#ifdef EFI_DEBUG
    DEBUG ((EFI_D_INFO, "Revision : 0x%x\n", Revision));
    DEBUG ((EFI_D_INFO, "EhciMemBaseAddr : 0x%x\n", EhciMemBaseAddr));
    DEBUG ((EFI_D_INFO, "XhciMemBaseAddr : 0x%x\n", XhciMemBaseAddr));

    DEBUG ((EFI_D_INFO, "\n"));
    DEBUG ((EFI_D_INFO, "------------------------ PCH_USB_CONFIG Dump Start -----------------\n"));
    DEBUG ((EFI_D_INFO, " PCH_USB_CONFIG UsbPerPortCtl= %x\n", UsbConfig->UsbPerPortCtl));
    DEBUG ((EFI_D_INFO, " PCH_USB_CONFIG Ehci1Usbr= %x\n", UsbConfig->Ehci1Usbr));
    DEBUG ((EFI_D_INFO, " PCH_USB_CONFIG Ehci2Usbr= %x\n", UsbConfig->Ehci2Usbr));
    for (i = 0; i < GetPchUsbMaxPhysicalPortNum (); i++) {
      DEBUG ((EFI_D_INFO, " PCH_USB_CONFIG PortSettings[%d] Enabled= %x\n", i, UsbConfig->PortSettings[i].Enable));
      DEBUG ((EFI_D_INFO, " PCH_USB_CONFIG PortSettings[%d] Location = %x\n", i, UsbConfig->PortSettings[i].Location));
    }

    for (i = 0; i < GetPchXhciMaxUsb3PortNum (); i++) {
      DEBUG ((EFI_D_INFO, " PCH_USB_CONFIG Port30Settings[%d] Enabled= %x\n", i, UsbConfig->Port30Settings[i].Enable));
    }

    for (i = 0; i < GetPchEhciMaxControllerNum (); i++) {
      DEBUG ((EFI_D_INFO, " PCH_USB_CONFIG Usb20Settings[%d] Enabled= %x\n", i, UsbConfig->Usb20Settings[i].Enable));
    }

    DEBUG ((EFI_D_INFO, " PCH_USB_CONFIG Usb30Settings.Mode= %x\n", UsbConfig->Usb30Settings.Mode));
    DEBUG ((EFI_D_INFO, " PCH_USB_CONFIG Usb30Settings.PreBootSupport= %x\n", UsbConfig->Usb30Settings.PreBootSupport));
    DEBUG ((EFI_D_INFO, " XhciStreams is obsoleted, it doesn't effect any setting change since Revision 2.\n"));
    DEBUG ((EFI_D_INFO, " PCH_USB_CONFIG Usb30Settings.ManualMode= %x\n", UsbConfig->Usb30Settings.ManualMode));
    DEBUG ((EFI_D_INFO, " PCH_USB_CONFIG Usb30Settings.XhciIdleL1= %x\n", UsbConfig->Usb30Settings.XhciIdleL1));

    for (i = 0; i < GetPchUsbMaxPhysicalPortNum (); i++) {
      if (UsbConfig->Usb30Settings.ManualModeUsb20PerPinRoute[i] == 0) {
        DEBUG ((EFI_D_INFO, " PCH_USB_CONFIG Usb30Settings.ManualModeUsb20PerPinRoute[%d]= EHCI\n", i));
      } else {
        DEBUG ((EFI_D_INFO, " PCH_USB_CONFIG Usb30Settings.ManualModeUsb20PerPinRoute[%d]= XHCI\n", i));
      }
    }

    for (i = 0; i < GetPchXhciMaxUsb3PortNum (); i++) {
      DEBUG ((EFI_D_INFO,
              "PCH_USB_CONFIG Usb30Settings.ManualModeUsb30PerPinEnable[%d]= %x\n",
              i,
              UsbConfig->Usb30Settings.ManualModeUsb30PerPinEnable[i]));
    }

    for (i = 0; i < GetPchUsbMaxPhysicalPortNum (); i++) {
      DEBUG ((EFI_D_INFO, " PCH_USB_CONFIG Usb20OverCurrentPins[%d]= OC%x\n", i, UsbConfig->Usb20OverCurrentPins[i]));
    }

    for (i = 0; i < GetPchXhciMaxUsb3PortNum (); i++) {
      DEBUG ((EFI_D_INFO, " PCH_USB_CONFIG Usb30OverCurrentPins[%d]= OC%x\n", i, UsbConfig->Usb30OverCurrentPins[i]));
    }

    for (i = 0; i < GetPchEhciMaxUsbPortNum (); i++) {
      DEBUG ((EFI_D_INFO, " PCH_USB_CONFIG Usb20PortLength[%d]= %x.%0x\n", i, UsbConfig->PortSettings[i].Usb20PortLength >> 4, UsbConfig->PortSettings[i].Usb20PortLength & 0xF));
    }
    DEBUG ((EFI_D_INFO, "\n"));
    DEBUG ((EFI_D_INFO, "\n------------------------ PCH_USB_CONFIG Dump End -----------------\n"));
#endif
    RootComplexBar  = PCH_RCRB_BASE;
    FuncDisableReg  = MmioRead32 (RootComplexBar + R_PCH_RCRB_FUNC_DIS);

    Status = CommonUsbInit (
              UsbConfig,
              (UINT32) EhciMemBaseAddr,
              (UINT32) XhciMemBaseAddr,
              0,
              RootComplexBar,
              &FuncDisableReg,
              Revision
              );

    ASSERT_EFI_ERROR (Status);

    MmioWrite32 ((UINTN) (RootComplexBar + R_PCH_RCRB_FUNC_DIS), (UINT32) (FuncDisableReg));
    //
    // Reads back for posted write to take effect
    //
    MmioRead32 ((UINTN) (RootComplexBar + R_PCH_RCRB_FUNC_DIS));
  }

  DEBUG ((EFI_D_INFO, "PchStartUsbInit() - End\n"));

  return Status;

}