summaryrefslogtreecommitdiffstats
path: root/import/chips/p9/procedures/ppe_closed/sgpe/stop_gpe/p9_sgpe_stop_irq_handlers.c
blob: 961c163af94266813dad33b8cd4982795d0a26b8 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: import/chips/p9/procedures/ppe_closed/sgpe/stop_gpe/p9_sgpe_stop_irq_handlers.c $ */
/*                                                                        */
/* OpenPOWER HCODE Project                                                */
/*                                                                        */
/* COPYRIGHT 2015,2017                                                    */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

#include "p9_sgpe_stop.h"
#include "p9_sgpe_stop_enter_marks.h"
#include "p9_sgpe_irq.h"

SgpeStopRecord G_sgpe_stop_record __attribute__((section (".dump_ptrs"))) =
{
    // core levels
    {   {0, 0, 0, 0},
        {0, 0, 0, 0},
        {0, 0, 0, 0},
        {0, 0, 0, 0},
        {0, 0, 0, 0},
        {0, 0, 0, 0}
    },
    // quad states
    {   {0, 0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0, 0}
    },
    // group vectors
    {   {0, 0, 0, 0, 0},
        {0, 0, 0, 0},
        {0, 0, 0},
        {0, 0, 0},
        {0, 0, 0},
        {0, 0, 0}
    },
    // wof status
    {0, 0, 0, 0},
    // semaphores
    {{0, 0}}
};

// PCB Interrupt Type2
// Payload
//   0    - set = Hardware Exit | unset = Firmware Stop
//   1    - set = Firmware Exit | unset = Firmware Entry (valid if b0 unset)
//   2:7  - Reserved
//   8:11 - Stop Level                                   (valid if b0 unset)
//
// SgpeStopRecord Structure
//     A) record all core latest stop levels from pcb interrupt payload
//     B) from A determine the overall quad/ex event(enter which level or exit)
//     C) with latest B, remember the vector of quad/ex entering and exiting
//     entry and exit will loop the vector for targets (or multicast) and
//     take a look at the events for stop flow depth
//     Possible entry/exit flow
//     Enter:
//       0  -> ex
//       ex -> eq
//       0  -> eq
//     Exit:
//       ex -> 0
//       eq -> ex -> 0
//

void
p9_sgpe_stop_pig_handler(void* arg, PkIrqId irq)
{
    PkMachineContext  ctx;
    uint32_t          cirq        = 0;
    uint32_t          qirq        = 0;
    uint32_t          cloop       = 0;
    uint32_t          qloop       = 0;
    uint32_t          cpending_t2 = 0;
    uint32_t          cpending_t3 = 0;
    uint32_t          qpending_t6 = 0;
    uint32_t          cpayload_t2 = 0;
    uint32_t          cpayload_t3 = 0;
    uint32_t          qpayload_t6 = 0;
    uint64_t          scom_data   = 0;

    //=========================
    MARK_TRAP(STOP_PIG_HANDLER)
    //=========================

    PK_TRACE_DBG("PIG-IRQ: %d", irq);
    // Disable type2/3/6 interrupt
    out32(OCB_OIMR1_OR, (BITS32(15, 2) | BIT32(19)));
    // Read type2/3/6 interrupt status
    qirq = in32(OCB_OISR1);
    cirq = qirq & BITS32(15, 2);
    qirq = qirq & BIT32(19);
    // Clear type2/3/6 interrupt status
    out32(OCB_OISR1_CLR, (cirq | qirq));

    // read type2/3/6 interrupt pending status
    // then clear interrupt pending status
    if (cirq & BIT32(15))
    {
        cpending_t2 = in32(OCB_OPITNPRA(2));
        out32(OCB_OPITNPRA_CLR(2), cpending_t2);
        PK_TRACE("Type2: %x", cpending_t2);
    }

    if (cirq & BIT32(16))
    {
        cpending_t3 = in32(OCB_OPITNPRA(3));
        out32(OCB_OPITNPRA_CLR(3), cpending_t3);
        PK_TRACE("Type3: %x", cpending_t3);
    }

    if (qirq)
    {
        qpending_t6 = in32(OCB_OPIT6PRB);
        out32(OCB_OPIT6PRB_CLR, qpending_t6);
        PK_TRACE_DBG("Type6: %x", qpending_t6);
    }

    // clear group before analyzing input
    G_sgpe_stop_record.group.qswu[VECTOR_ENTRY] = 0;
    G_sgpe_stop_record.group.core[VECTOR_ENTRY] = 0;
    G_sgpe_stop_record.group.qswu[VECTOR_EXIT]  = 0;
    G_sgpe_stop_record.group.core[VECTOR_EXIT]  = 0;
    G_sgpe_stop_record.group.ex_l[VECTOR_EXIT]  = 0;
    G_sgpe_stop_record.group.ex_r[VECTOR_EXIT]  = 0;
    G_sgpe_stop_record.group.ex_b[VECTOR_EXIT]  = 0;
    G_sgpe_stop_record.group.quad[VECTOR_EXIT]  = 0;

    // loop all quads
    for(qloop = 0; qloop < MAX_QUADS; qloop++)
    {

        // if no quad special wakeup, skip to core request
        if (qirq && (BIT32(qloop) & qpending_t6 &
                     G_sgpe_stop_record.group.quad[VECTOR_CONFIG]))
        {

            // read payload on quad has interrupt pending
            qpayload_t6 = in32(OCB_OPIT6QN(qloop));
            PK_TRACE_DBG("Quad[%d] Payload [%x]", qloop, qpayload_t6);

            if (qpayload_t6 & TYPE6_PAYLOAD_EXIT_EVENT)
            {
                PK_TRACE_DBG("Quad Request Special Wakeup");

                if (G_sgpe_stop_record.group.qswu[VECTOR_CONFIG] & BIT32(qloop))
                {
                    PK_TRACE_DBG("Quad Already in Special Wakeup");
                }
                else
                {
                    G_sgpe_stop_record.group.qswu[VECTOR_EXIT] |= BIT32(qloop);
                    G_sgpe_stop_record.group.quad[VECTOR_EXIT] |= BIT32(qloop);
                    G_sgpe_stop_record.group.ex_l[VECTOR_EXIT] |= BIT32(qloop);
                    G_sgpe_stop_record.group.ex_r[VECTOR_EXIT] |= BIT32(qloop);
                    G_sgpe_stop_record.group.ex_b[VECTOR_EXIT] |=
                        BITS32((qloop << 1), 2);
                }
            }
            else
            {
                PK_TRACE_DBG("Quad Drop Special Wakeup, Clearing Done");
                GPE_PUTSCOM(GPE_SCOM_ADDR_QUAD(PPM_GPMMR_CLR, qloop), BIT64(0));

                G_sgpe_stop_record.group.qswu[VECTOR_ENTRY]  |=  BIT32(qloop);
                G_sgpe_stop_record.group.qswu[VECTOR_CONFIG] &= ~BIT32(qloop);
            }
        }

        // if no core request, skip to next quad
        if(!cirq || (!(BITS32((qloop << 2), 4) & (cpending_t2 | cpending_t3) &
                       G_sgpe_stop_record.group.core[VECTOR_CONFIG])))
        {
            continue;
        }

        PK_TRACE_DBG("Quad[%d] Has Core Request:", qloop);
        PK_TRACE_DBG("Now clv[%d][%d][%d][%d]",
                     G_sgpe_stop_record.level[qloop][0],
                     G_sgpe_stop_record.level[qloop][1],
                     G_sgpe_stop_record.level[qloop][2],
                     G_sgpe_stop_record.level[qloop][3]);

        // then loop all cores in the quad
        for(cloop = 0; cloop < CORES_PER_QUAD; cloop++)
        {
            // again skip core that doesnt have interrupt cpending
            if (!((cpending_t2 | cpending_t3) & BIT32((qloop << 2) + cloop)))
            {
                continue;
            }

            // read payload on core has interrupt2 cpending
            cpayload_t2 = 0;
            cpayload_t3 = 0;

            if (cpending_t2 & BIT32((qloop << 2) + cloop))
            {
                cpayload_t2 = in32(OCB_OPIT2CN(((qloop << 2) + cloop)));
            }

            // read payload on core has interrupt3 cpending
            if (cpending_t3 & BIT32((qloop << 2) + cloop))
            {
                cpayload_t3 = in32(OCB_OPIT3CN(((qloop << 2) + cloop)));
            }

            PK_TRACE_INF("Core[%d] Type2 Payload [%x] Type3 Payload [%x]",
                         ((qloop << 2) + cloop), cpayload_t2, cpayload_t3);

            GPE_GETSCOM(GPE_SCOM_ADDR_CORE(CPPM_CPMMR,
                                           ((qloop << 2) + cloop)), scom_data);

            // T2       T3     NS         given point to SGPE
            // exit     exit   SGPE  ---- proceed with exit
            // entry    exit   SGPE  ---- discard exit, proceed with entry
            // exit     entry  SGPE  ---- discard exit, proceed with entry
            // entry    entry  SGPE  ---- error
            //
            // exit     exit   CME   ---- error (hardware phantom exit can only send one type)
            // entry    exit   CME   ---- error (entry dominiant error)
            // exit     entry  CME   ---- error (entry dominiant error)
            // entry    entry  CME   ---- error (entry dominiant error)

            // T2 T3
            // 0  0  Error
            // E  E  Error
            // E  0  Entry
            // 0  E  Entry
            // X  E  Entry
            // E  X  Entry
            // X  0  Exit
            // 0  X  Exit
            // X  X  Exit
            // exit  = both exit or one exit + one empty
            // entry = one entry + one exit/empty

            // both empty
            if ((!cpayload_t2) && (!cpayload_t3))
            {
                PK_TRACE_ERR("ERROR: Empty Requests on Both Type2 and Type3. HALT SGPE!");
                PK_PANIC(SGPE_PIG_TYPE23_BOTH_EMPTY);
            }
            // both entry
            else if ((cpayload_t2 && (!(cpayload_t2 & TYPE2_PAYLOAD_EXIT_EVENT))) &&
                     (cpayload_t3 && (!(cpayload_t3 & TYPE2_PAYLOAD_EXIT_EVENT))))
            {
                PK_TRACE_ERR("ERROR: Entry Requests on Both Type2 and Type3. HALT SGPE!");
                PK_PANIC(SGPE_PIG_TYPE23_BOTH_ENTRY);
            }
            // if t2 entry (t3 exit or empty)
            else if (cpayload_t2 && (!(cpayload_t2 & TYPE2_PAYLOAD_EXIT_EVENT)))
            {
                if (!(scom_data & BIT64(13)))
                {
                    // wakeup=normal + notify=cme -> error
                    if (cpayload_t2 != 0x400)
                    {
                        PK_TRACE_ERR("ERROR: Received Type2 Entry PIG When Wakeup_notify_select = 0. HALT SGPE!");
                        PK_PANIC(SGPE_PIG_TYPE2_ENTRY_WNS_CME);
                    }

                    // wakeup=pc + notify=cme -> ignore phantom(already handoff to cme by other wakeup)
                }
                else
                {
                    // wakeup=pc + notify=sgpe -> go exit with flag to do extra doorbell from normal wakeup
                    if (cpayload_t2 == 0x400)
                    {
                        G_sgpe_stop_record.group.core[VECTOR_PCWU] |= BIT32(((qloop << 2) + cloop));
                    }

                    // wakeup=normal + notify=sgpe -> go exit
                    PK_TRACE_INF("Core Request Entry via Type2");
                    G_sgpe_stop_record.level[qloop][cloop] =
                        (cpayload_t2 & TYPE2_PAYLOAD_STOP_LEVEL);
                    G_sgpe_stop_record.group.core[VECTOR_ENTRY] |=
                        BIT32(((qloop << 2) + cloop));
                }
            }
            // if t3 entry (t2 exit or empty)
            else if (cpayload_t3 && (!(cpayload_t3 & TYPE2_PAYLOAD_EXIT_EVENT)))
            {
                if (!(scom_data & BIT64(13)))
                {
                    PK_TRACE_ERR("ERROR: Received Type3 Entry PIG When Wakeup_notify_select = 0. HALT SGPE!");
                    PK_PANIC(SGPE_PIG_TYPE3_ENTRY_WNS_CME);
                }

                PK_TRACE_INF("Core Request Entry via Type3");
                G_sgpe_stop_record.level[qloop][cloop] =
                    (cpayload_t3 & TYPE2_PAYLOAD_STOP_LEVEL);
                G_sgpe_stop_record.group.core[VECTOR_ENTRY] |=
                    BIT32(((qloop << 2) + cloop));
            }
            // both exit or one exit + one empty
            else
            {
                if (!(scom_data & BIT64(13)))
                {
                    if ((cpayload_t2 & TYPE2_PAYLOAD_EXIT_EVENT) &&
                        (cpayload_t3 & TYPE2_PAYLOAD_EXIT_EVENT))
                    {
                        PK_TRACE_ERR("ERROR: Received Both Types of Exit PIG When Wakeup_notify_select = 0. HALT SGPE!");
                        PK_PANIC(SGPE_PIG_TYPE23_EXIT_WNS_CME);
                    }
                    else
                    {
                        PK_TRACE_INF("WARNING: Received Phantom Exit PIG When Wakeup_notify_select = 0");
                    }
                }
                else
                {
                    PK_TRACE_INF("Core Request Exit");

                    if (cloop < CORES_PER_EX)
                    {
                        G_sgpe_stop_record.group.ex_l[VECTOR_EXIT] |=
                            BIT32(qloop);
                        G_sgpe_stop_record.group.ex_b[VECTOR_EXIT] |=
                            BIT32((qloop << 1));
                    }
                    else
                    {
                        G_sgpe_stop_record.group.ex_r[VECTOR_EXIT] |=
                            BIT32(qloop);
                        G_sgpe_stop_record.group.ex_b[VECTOR_EXIT] |=
                            BIT32(((qloop << 1) + 1));
                    }

                    G_sgpe_stop_record.group.quad[VECTOR_EXIT] |=
                        BIT32(qloop);
                    G_sgpe_stop_record.group.core[VECTOR_EXIT] |=
                        BIT32(((qloop << 2) + cloop));
                }
            }
        }

        PK_TRACE_DBG("New Core Levels[%d][%d][%d][%d]",
                     G_sgpe_stop_record.level[qloop][0],
                     G_sgpe_stop_record.level[qloop][1],
                     G_sgpe_stop_record.level[qloop][2],
                     G_sgpe_stop_record.level[qloop][3]);
    }

    G_sgpe_stop_record.group.ex_b[VECTOR_EXIT] &=
        G_sgpe_stop_record.group.ex_b[VECTOR_CONFIG];
    G_sgpe_stop_record.group.ex_l[VECTOR_EXIT] &=
        G_sgpe_stop_record.group.ex_l[VECTOR_CONFIG];
    G_sgpe_stop_record.group.ex_r[VECTOR_EXIT] &=
        G_sgpe_stop_record.group.ex_r[VECTOR_CONFIG];

    PK_TRACE_DBG("Quad Special Wakeup: Raise[%x], Drop[%x]",
                 G_sgpe_stop_record.group.qswu[VECTOR_EXIT],
                 G_sgpe_stop_record.group.qswu[VECTOR_ENTRY]);
    PK_TRACE_DBG("Core Request Stop:   Entry[%x], Exit[%x]",
                 G_sgpe_stop_record.group.core[VECTOR_ENTRY],
                 G_sgpe_stop_record.group.core[VECTOR_EXIT]);

    if ((!G_sgpe_stop_record.group.core[VECTOR_EXIT])  &&
        (!G_sgpe_stop_record.group.core[VECTOR_ENTRY]) &&
        (!G_sgpe_stop_record.group.qswu[VECTOR_EXIT])  &&
        (!G_sgpe_stop_record.group.qswu[VECTOR_ENTRY]))
    {
        PK_TRACE_INF("Nothing to do, Clear Masks");
        out32(OCB_OIMR1_CLR, (BITS32(15, 2) | BIT32(19)));
        pk_irq_vec_restore(&ctx);
    }
    else
    {
        if (G_sgpe_stop_record.group.core[VECTOR_EXIT] ||
            G_sgpe_stop_record.group.qswu[VECTOR_EXIT])
        {
            PK_TRACE_INF("Unblock Exit");
            pk_semaphore_post(&(G_sgpe_stop_record.sem[1]));
        }

        if (G_sgpe_stop_record.group.core[VECTOR_ENTRY] ||
            G_sgpe_stop_record.group.qswu[VECTOR_ENTRY])
        {
            PK_TRACE_INF("Unblock Entry");
            pk_semaphore_post(&(G_sgpe_stop_record.sem[0]));
        }
    }
}
OpenPOWER on IntegriCloud