summaryrefslogtreecommitdiff
path: root/Platform/Intel/KabylakeOpenBoardPkg/Features/Tbt/AcpiTables/Rtd3SptPcieTbt.asl
blob: b54b5a41c3af18124d61809673caa7ae1f936c6a (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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
/** @file
  ACPI RTD3 SSDT table for SPT PCIe

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 PID_ICC                                   0xDC
#define R_PCH_PCR_ICC_MSKCKRQ                     0x100C                  ///< Mask Control CLKREQ

External(PCRA,MethodObj)
External(PCRO,MethodObj)
External(\MMRP, MethodObj)
External(\MMTB, MethodObj)
External(\TRDO, IntObj)
External(\TRD3, IntObj)
External(\TBPE, IntObj)
External(\TOFF, IntObj)
External(\TBSE, IntObj)
External(\TBOD, IntObj)
External(\TBRP, IntObj)
External(\TBHR, IntObj)
External(\RTBC, IntObj)
External(\TBCD, IntObj)

Name(G2SD, 0) // Go2Sx done, set by GO2S, cleaned by _ON

Name(WKEN, 0)

  Method(_S0W, 0)
  {
  /// This method returns the lowest D-state supported by PCIe root port during S0 state

   ///- PMEs can be generated from D3hot for ULT
      Return(4)

  /** @defgroup pcie_s0W PCIE _S0W **/
  } // End _S0W

  Method (_DSD, 0) {
    Return (
      Package () {
        ToUUID("6211E2C0-58A3-4AF3-90E1-927A4E0C55A4"),
        Package () {
          Package (2) {"HotPlugSupportInD3", 1},
        }
      }
    ) // End of Return ()
  }

    Method(_DSW, 3)
    {
    /// This method is used to enable/disable wake from PCIe (WKEN)
      If (LGreaterEqual(Arg1, 1)) { /// If entering Sx, need to disable WAKE# from generating runtime PME
                                    /// Also set 2 to TOFF.
        Store(0, WKEN)
        Store (2, TOFF)
      } Else {  /// If Staying in S0
        If(LAnd(Arg0, Arg2)) ///- Check if Exiting D0 and arming for wake
        { ///- Set PME
          Store(1, WKEN)
          Store (1, TOFF)
        } Else { ///- Disable runtime PME, either because staying in D0 or disabling wake
          Store(0, WKEN)
          Store(0, TOFF)
        }
      }

    /** @defgroup pcie_dsw PCIE _DSW **/
    } // End _DSW


    PowerResource(PXP, 0, 0)
    {
    /// Define the PowerResource for PCIe slot
    /// Method: _STA(), _ON(), _OFF()
    /** @defgroup pcie_pxp PCIE Power Resource **/

      Method(_STA, 0)
      {
          Return(PSTA())
      }  /** @defgroup pcie_sta PCIE _STA method **/

      Method(_ON) /// Turn on core power to PCIe Slot
      {
        Store(1, TRDO)
        PON()
        Store(0, TRDO)
      } /** @defgroup pcie_on PCIE _ON method **/

      Method(_OFF) /// Turn off core power to PCIe Slot
      {
        Store(1, TRD3)
        POFF()
        Store(0, TRD3)
      } // End of Method_OFF
    } // End PXP

    Method(PSTA, 0)
    {
    /// Returns the status of PCIe slot core power
      // detect power pin status
      if(LNotEqual(DeRefOf(Index(PWRG, 0)),0)) {
        if(LEqual(DeRefOf(Index(PWRG, 0)),1)) { // GPIO mode
          if(LEqual(\_SB.GGOV(DeRefOf(Index(PWRG, 2))),DeRefOf(Index(PWRG, 3)))){
            Return (1)
          } Else {
            Return (0)
          }
        } // GPIO mode
        if(LEqual(DeRefOf(Index(PWRG, 0)),2))  { // IOEX mode
          if(LEqual(\_SB.PCI0.GEXP.GEPS(DeRefOf(Index(PWRG, 1)),DeRefOf(Index(PWRG, 2))),DeRefOf(Index(PWRG, 3)))){
            Return (1)
          } Else {
            Return (0)
          }
        } // IOEX mode
      }
      // detect reset pin status
      if(LNotEqual(DeRefOf(Index(RSTG, 0)),0)) {
        if(LEqual(DeRefOf(Index(RSTG, 0)),1)) { // GPIO mode
          if(LEqual(\_SB.GGOV(DeRefOf(Index(RSTG, 2))),DeRefOf(Index(RSTG, 3)))){
            Return (1)
          } Else {
            Return (0)
          }
        } // GPIO mode
        if(LEqual(DeRefOf(Index(RSTG, 0)),2))  { // IOEX mode
          if(LEqual(\_SB.PCI0.GEXP.GEPS(DeRefOf(Index(RSTG, 1)),DeRefOf(Index(RSTG, 2))),DeRefOf(Index(RSTG, 3)))){
            Return (1)
          } Else {
            Return (0)
          }
        } // IOEX mode
      }
      Return (0)
    }  /** @defgroup pcie_sta PCIE _STA method **/

    Method (SXEX, 0, Serialized) {

      Store(\MMTB(TBSE), Local7)
      OperationRegion(TBDI, SystemMemory, Local7, 0x550)// TBT HR PCICFG MMIO
      Field(TBDI,DWordAcc, NoLock, Preserve) {
        DIVI, 32,
        CMDR, 32,
        Offset(0x548),
        TB2P, 32,
        P2TB, 32
      }

      Store(100, Local1)
      Store(0x09, P2TB) // Write SX_EXIT_TBT_CONNECTED to PCIe2TBT
      While (LGreater(Local1, 0)) {

        Store(Subtract(Local1, 1), Local1)
        Store(TB2P, Local2)
        If (LEqual(Local2, 0xFFFFFFFF)) { // Device gone
          Return()
        }
        If (And(Local2, 1)) { // Done
          break
        }
        Sleep(5)
      }
      Store(0x0, P2TB) // Write 0 to PCIe2TBT

      // Fast Link bring-up flow
      Store(500, Local1)
      While (LGreater(Local1, 0)) {
        Store(Subtract(Local1, 1), Local1)
        Store(TB2P, Local2)
        If (LEqual(Local2, 0xFFFFFFFF)) {// Device gone
          Return()
        }
        If (LNotEqual(DIVI, 0xFFFFFFFF)) {
          break
        }
        Sleep(10)
      }
    } // End of Method(SXEX, 0, Serialized)

    Method(PON) /// Turn on core power to PCIe Slot
    {

      Store(\MMRP(\TBSE), Local7)
      OperationRegion(L23P,SystemMemory,Local7,0xE4)
      Field(L23P,WordAcc, NoLock, Preserve)
      {
        Offset(0xA4),// PMCSR
        PSD0, 2, // PowerState
        Offset(0xE2),// 0xE2, RPPGEN - Root Port Power Gating Enable
        , 2,
        L2TE, 1,      // 2,   L23_Rdy Entry Request (L23ER)
        L2TR, 1,       // 3,   L23_Rdy to Detect Transition (L23R2DT)
      }

      Store(\MMTB(\TBSE), Local6)
      OperationRegion(TBDI, SystemMemory, Local6, 0x550)// TBT HR PCICFG MMIO
      Field(TBDI,DWordAcc, NoLock, Preserve) {
        DIVI, 32,
        CMDR, 32,
        Offset(0xA4),
        TBPS, 2, // PowerState of TBT
        Offset(0x548),
        TB2P, 32,
        P2TB, 32
      }
 
      Store(0, TOFF)
      // Check RTD3 power enable, if already ON, no need to execute sx_exit
      If (TBPE) {
        Return()
      }

      Store(0,G2SD)
      If (\RTBC) {
        /// de-assert CLK_REQ MSK
        if(LNotEqual(DeRefOf(Index(SCLK, 0)),0)) { // if power gating enabled
          PCRA(PID_ICC,R_PCH_PCR_ICC_MSKCKRQ,Not(DeRefOf(Index(SCLK, 1))))  // And ~SCLK to clear bit
        }
        Sleep(\TBCD)
      }

      /// Turn ON Power for PCIe Slot
      if(LNotEqual(DeRefOf(Index(PWRG, 0)),0)) { // if power gating enabled
        if(LEqual(DeRefOf(Index(PWRG, 0)),1)) { // GPIO mode
          \_SB.SGOV(DeRefOf(Index(PWRG, 2)),DeRefOf(Index(PWRG, 3)))
          Store(1, TBPE)
          Sleep(PEP0)     /// Sleep for programmable delay
        }
        if(LEqual(DeRefOf(Index(PWRG, 0)),2))  { // IOEX mode
          \_SB.PCI0.GEXP.SGEP(DeRefOf(Index(PWRG, 1)),DeRefOf(Index(PWRG, 2)),DeRefOf(Index(PWRG, 3)))
          Store(1, TBPE)
          Sleep(PEP0)     /// Sleep for programmable delay
        }
      }

      /// De-Assert Reset Pin
      if(LNotEqual(DeRefOf(Index(RSTG, 0)),0)) { // if reset pin enabled
        if(LEqual(DeRefOf(Index(RSTG, 0)),1)) { // GPIO mode
          \_SB.SGOV(DeRefOf(Index(RSTG, 2)),DeRefOf(Index(RSTG, 3)))
        }
        if(LEqual(DeRefOf(Index(RSTG, 0)),2)) { // IOEX mode
          \_SB.PCI0.GEXP.SGEP(DeRefOf(Index(RSTG, 1)),DeRefOf(Index(RSTG, 2)),DeRefOf(Index(RSTG, 3)))
        }
      }

      /// Clear DLSULPPGE, then set L23_Rdy to Detect Transition  (L23R2DT)
      Store(0, DPGE)
      Store(1, L2TR)
      Sleep(16)
      Store(0, Local0)
      /// Wait up to 12 ms for transition to Detect
      While(L2TR) {
        If(Lgreater(Local0, 4))    // Debug - Wait for 5 ms
        {
          Break
        }
        Sleep(16)
        Increment(Local0)
      }
      /// Once in Detect, wait up to 124 ms for Link Active (typically happens in under 70ms)
      /// Worst case per PCIe spec from Detect to Link Active is:
      /// 24ms in Detect (12+12), 72ms in Polling (24+48), 28ms in Config (24+2+2+2+2)
      Store(1, DPGE)
      Store(0, Local0)
      While(LEqual(LASX,0)) {
        If(Lgreater(Local0, 8))
        {
          Break
        }
        Sleep(16)
        Increment(Local0)
      }
      Store(0, LEDM) /// Set PCIEDBG.DMIL1EDM (324[3]) = 0

      // TBT special sleep.
      Store(PSD0, Local1)
      Store(0, PSD0)// D0
      Store(20, Local2) // Poll for TBT, up to 200 ms

      While (LGreater(Local2, 0)) {
        Store(Subtract(Local2, 1), Local2)
        Store(TB2P, Local3)
        If (LNotEqual(Local3, 0xFFFFFFFF)) { // Done
          break
        }
        Sleep(10)
      }

      If (LLessEqual(Local2, 0)) {
      }
      SXEX()
      Store(Local1, PSD0) // Back to Local1
    } /** @defgroup pcie_on PCIE _ON method **/

    Method(POFF) { /// Turn off core power to PCIe Slot
      If (LEqual(TOFF, 0)) {
        Return()
      }
      Store(\MMRP(\TBSE), Local7)
      OperationRegion(L23P, SystemMemory, Local7, 0xE4)
      Field(L23P,WordAcc, NoLock, Preserve)
      {
        Offset(0xA4),// PMCSR
        PSD0, 2, // PowerState
        Offset(0xE2),// 0xE2, RPPGEN - Root Port Power Gating Enable
        , 2,
        L2TE, 1,      // 2,   L23_Rdy Entry Request (L23ER)
        L2TR, 1,       // 3,   L23_Rdy to Detect Transition (L23R2DT)
      }

      Store(\MMTB(TBSE), Local6)
      OperationRegion(TBDI, SystemMemory, Local6, 0x550)// TBT HR PCICFG MMIO
      Field(TBDI,DWordAcc, NoLock, Preserve) {
        DIVI, 32,
        CMDR, 32,
        Offset(0xA4),
        TBPS, 2, // PowerState of TBT
        Offset(0x548),
        TB2P, 32,
        P2TB, 32
      }

      Store(PSD0, Local1)
      Store(0, PSD0)// D0

      Store(P2TB, Local3)

      If (Lgreater(TOFF, 1)) {
        Sleep(10)
        Store(Local1, PSD0) // Back to Local1
        Return()
      }
      Store(0, TOFF)

      Store(Local1, PSD0) // Back to Local1

      /// Set L23_Rdy Entry Request (L23ER)
      Store(1, L2TE)
      Sleep(16)
      Store(0, Local0)
      While(L2TE) {
        If(Lgreater(Local0, 4))    /// Debug - Wait for 5 ms
        {
          Break
        }
        Sleep(16)
        Increment(Local0)
      }
      Store(1, LEDM) /// PCIEDBG.DMIL1EDM (324[3]) = 1

      /// Assert Reset Pin
      if(LNotEqual(DeRefOf(Index(RSTG, 0)),0)) { // if reset pin enabled
        if(LEqual(DeRefOf(Index(RSTG, 0)),1)) { // GPIO mode
          \_SB.SGOV(DeRefOf(Index(RSTG, 2)),Xor(DeRefOf(Index(RSTG, 3)),1))
        }
        if(LEqual(DeRefOf(Index(RSTG, 0)),2)) { // IOEX mode
          \_SB.PCI0.GEXP.SGEP(DeRefOf(Index(RSTG, 1)),DeRefOf(Index(RSTG, 2)),Xor(DeRefOf(Index(RSTG, 3)),1))
        }
      }
      If (\RTBC) {
        /// assert CLK_REQ MSK
        if(LNotEqual(DeRefOf(Index(SCLK, 0)),0)) { // if power gating enabled
          PCRO(PID_ICC,R_PCH_PCR_ICC_MSKCKRQ,DeRefOf(Index(SCLK, 1)))    // Or SCLK to set bit
          Sleep(16)
        }
      }

      /// Power OFF for TBT
      if(LNotEqual(DeRefOf(Index(PWRG, 0)),0)) { // if power gating enabled
        if(LEqual(DeRefOf(Index(PWRG, 0)),1)) { // GPIO mode
          \_SB.SGOV(DeRefOf(Index(PWRG, 2)),Xor(DeRefOf(Index(PWRG, 3)),1))
        }
        if(LEqual(DeRefOf(Index(PWRG, 0)),2))  { // IOEX mode
          \_SB.PCI0.GEXP.SGEP(DeRefOf(Index(PWRG, 1)),DeRefOf(Index(PWRG, 2)),Xor(DeRefOf(Index(PWRG, 3)),1))
        }
      }

      Store(0, TBPE)

      Store(1, LDIS) /// Set Link Disable
      Store(0, LDIS) /// Toggle link disable

      /// enable WAKE
      If (WKEN) {
        If (LNotEqual(DeRefOf(Index(WAKG, 0)),0)) { // if power gating enabled
          If (LEqual(DeRefOf(Index(WAKG, 0)),1)) { // GPIO mode
            \_SB.SGOV(DeRefOf(Index(WAKG, 2)),DeRefOf(Index(WAKG, 3)))
            \_SB.SHPO(DeRefOf(Index(WAKG, 2)), 0) // set gpio ownership to ACPI(0=ACPI mode, 1=GPIO mode)
          }
          If (LEqual(DeRefOf(Index(WAKG, 0)),2))  { // IOEX mode
            \_SB.PCI0.GEXP.SGEP(DeRefOf(Index(WAKG, 1)),DeRefOf(Index(WAKG, 2)),DeRefOf(Index(WAKG, 3)))
          }
        }
      }
      Sleep(\TBOD)
      /** @defgroup pcie_off PCIE _OFF method **/
    } // End of Method_OFF

    Name(_PR0, Package(){PXP})
    Name(_PR3, Package(){PXP})