summaryrefslogtreecommitdiff
path: root/Silicon/Intel/LewisburgPkg/AcpiTables/Dsdt/PchRstPcieStorage.asl
blob: bef1a7e82aeca47ac3c8501723abcd7173f77810 (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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/** @file

Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.

THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

**/

#define PCI_CARD_BASE_ADDR0     0x10
#define PCI_CARD_BASE_ADDR1     0x14
#define PCI_CARD_BASE_ADDR2     0x18
#define PCI_CARD_BASE_ADDR3     0x1C
#define PCI_CARD_BASE_ADDR4     0x20
#define PCI_CARD_BASE_ADDR5     0x24

  //RST Pcie Storage Remapped Base Address Index Value
  Name(PRBI, 0)

  //RST Pcie Storage Remapped Base Address Data Value
  Name(PRBD, 0)

  //RST Pcie Storage Endpoint Command Data
  Name(PCMD, 0)

  //RST Pcie Storage Cycle Router
  Name(NCRN, 0)

  //
  // Variables list to store corresponding value for different NVM device
  //
  Name(NITV, 0)  // Interface Type
  Name(NPMV, 0)  // Power Management Capability Pointer
  Name(NPCV, 0)  // PCIe Capabilities Pointer
  Name(NL1V, 0)  // L1SS Capability Pointer
  Name(ND2V, 0)  // Endpoint L1SS Control Data2
  Name(ND1V, 0)  // Endpoint L1SS Control Data1
  Name(NLRV, 0)  // LTR Capability Pointer
  Name(NLDV, 0)  // Endpoint LTR Data
  Name(NEAV, 0)  // Endpoint LCTL Data
  Name(NEBV, 0)  // Endpoint DCTL Data
  Name(NECV, 0)  // Endpoint DCTL2 Data
  Name(NRAV, 0)  // RootPort DCTL2 Data
  Name(NMBV, 0)  // Endpoint unique MSI-X Table BAR
  Name(NMVV, 0)  // Endpoint unique MSI-X Table BAR value
  Name(NPBV, 0)  // Endpoint unique MSI-X PBA BAR
  Name(NPVV, 0)  // Endpoint unique MSI-X PBA BAR value

  Method(EPD0, 0, Serialized) // Put Remapped Device into D0 state
  {
    RDCA(NCRN,Add(NPMV,0x04),0xFFFFFFFC,0x0,ENDPOINT_WRITE)
  }

  Method(EPD3, 0, Serialized) // Put Remapped Device into D3 state
  {
    RDCA(NCRN,Add(NPMV,0x04),0xFFFFFFFC,0x3,ENDPOINT_WRITE)
  }
     
  //
  // Restore of Remapped Device and Hidden Root Port 
  // This method is called after the endpoint is to be power ungated (D3-cold to D0 unitialized)
  //
  Method(CNRS, 0, Serialized) 
  {
    //
    // Return if RST Pcie Storage Remapping is disabled
    //
    If(LEqual(NITV,0)) 
    {
      Return(0)
    }
  
    //
    // Clear all BARs in Remapped Device
    //
    RDCA(NCRN,PCI_CARD_BASE_ADDR0,0x0,0x0,ENDPOINT_WRITE)
    RDCA(NCRN,PCI_CARD_BASE_ADDR1,0x0,0x0,ENDPOINT_WRITE)
    RDCA(NCRN,PCI_CARD_BASE_ADDR2,0x0,0x0,ENDPOINT_WRITE)
    RDCA(NCRN,PCI_CARD_BASE_ADDR3,0x0,0x0,ENDPOINT_WRITE)
    RDCA(NCRN,PCI_CARD_BASE_ADDR4,0x0,0x0,ENDPOINT_WRITE)
    RDCA(NCRN,PCI_CARD_BASE_ADDR5,0x0,0x0,ENDPOINT_WRITE)

    //
    // Restore Endpoint CMD and remapped BAR 
    //
    RDCA(NCRN,0x4,0xFFFFFFF8,PCMD,ENDPOINT_WRITE)
    RDCA(NCRN,PRBI,0x0,PRBD,ENDPOINT_WRITE)

    //
    // Restore of Remapped Device L1 Substate if this Capability is supported
    //
    If(LNotEqual(NL1V,0))
    {
      RDCA(NCRN,Add(NL1V,0x0C),0xFFFFFF00,ND2V,ENDPOINT_WRITE)
      RDCA(NCRN,Add(NL1V,0x08),0x0000000F,And(ND1V,0xFFFFFFF0),ENDPOINT_WRITE)
      RDCA(NCRN,Add(NL1V,0x08),0xFFFFFFFF,ND1V,ENDPOINT_WRITE)
    }

    //
    // Restore of Remapped Device LTR if this Capability is supported
    //
    If(LNotEqual(NLRV,0))
    {
      RDCA(NCRN,Add(NLRV,0x04),0xFFFFFFFF,NLDV,ENDPOINT_WRITE)
    }

    //
    // Restore of Remapped Device Link Control's "Enable Clock Power Management" field and "Common Clock Configuration" field
    //
    RDCA(NCRN,Add(NPCV,0x10),0xFFFFFEBF,And(NEAV,0xFFFC),ENDPOINT_WRITE)

    //
    // Restore of Remapped Device Device Control 2 field
    //
    RDCA(NCRN,Add(NPCV,0x28),0xFFFFFBFF,NECV,ENDPOINT_WRITE)

    //
    // Restore of Remapped Device Device Control field
    //
    RDCA(NCRN,Add(NPCV,0x8),0xFFFFFF1F,NEBV,ENDPOINT_WRITE)

    //
    // Restore of Hidden Root Port field
    //
    RDCA(NCRN,0x68,0xFFFFFBFF,NRAV,ROOTPORT_WRITE)

    //
    // Check CCC bit
    // If this bit is 1, perform link retrain by setting the "Retrain Link" bit
    //
    If(LEqual(And(NEAV,0x40),0x40)) 
    {
      RDCA(NCRN,0x50,0xFFFFFFDF,0x20,ROOTPORT_WRITE)
      //
      // Poll PCIe Link Active status till it is active
      //
      while(LEqual(And(RDCA(NCRN,0x52,0x0,0x0,ROOTPORT_READ),0x2000),0))
      {
        Stall(10)
      }
    }

    //
    // Restore of Remapped Device Link Control's "Active State Link PM Control" field
    //
    RDCA(NCRN,Add(NPCV,0x10),0xFFFFFFFC,And(NEAV,0x0003),ENDPOINT_WRITE)

    //
    // Restore of Remapped Device related device BAR for the MSI-X Table BAR if the device supports unique MSI-X Table BAR
    //
    If(LNotEqual(NMVV,0))
    {
      RDCA(NCRN,NMBV,0x0,NMVV,ENDPOINT_WRITE)
    }

    //
    // Restore of Remapped Device related device BAR for the MSI-X PBA BAR if the device supports unique MSI-X PBA BAR
    //
    If(LNotEqual(NPVV,0))
    {
      RDCA(NCRN,NPBV,0x0,NPVV,ENDPOINT_WRITE)
    }
    //Fix warning: not all control paths return a value
    Return(0)
  }
 
  Method(_PS3,0,Serialized)
  {
    //
    // Return if RST Pcie Storage Remapping is disabled
    //
    If(LEqual(NITV,0)) 
    {
      //Fix warning: restricted method should not return a value

    }

    //
    // Store Endpoint CMD and remapped BAR for CNRS() restoration
    //
    Store(RDCA(NCRN,0x4,0x0,0x0,ENDPOINT_READ),PCMD)
    If(LEqual(NITV,1)) // Store BAR5 if Endpoint is AHCI Interface
    {
      Store(0x24,PRBI)
      Store(RDCA(NCRN,0x24,0x0,0x0,ENDPOINT_READ),PRBD)
    }
    ElseIf(LEqual(NITV,2)) // Store BAR0 if Endpoint is NVMe Interface
    {
      Store(0x10,PRBI)
      Store(RDCA(NCRN,0x10,0x0,0x0,ENDPOINT_READ),PRBD)
    }

    EPD3()
    RPD3(NCRN)
  }

  Method(_PS0,0,Serialized)
  {
    //
    // Return if RST Pcie Storage Remapping is disabled
    //
    If(LEqual(NITV,0)) 
    {
      //Fix warning: restricted method should not return a value
    }
    RPD0(NCRN)
    EPD0()
        
    //
    // Check NSR bit in PMCS
    // If this bit is 0, invoke CNRS() to perform restoration on the remapped device and hidden root port  
    //
    Store(RDCA(NCRN,Add(NPMV,0x04),0x0,0x0,ENDPOINT_READ),Local0)
    If(LEqual(And(Local0,0x8),0)) 
    {
      CNRS()
    }
  }