summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/attn/common/attnsvc_common.C
blob: 71a24f7da735669c99dde9e81f8dd2efa1b5a3aa (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/attn/common/attnsvc_common.C $                   */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2014,2016                        */
/* [+] 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                                                     */
/**
 * @file attnsvc_common.C
 *
 * @brief HBATTN common service class function definitions.
 */

#include <errl/errlmanager.H>
#include "common/attnsvc_common.H"
#include "common/attntrace.H"
#include "common/attnprd.H"
#include "common/attnproc.H"
#include "common/attnmem.H"
#include "common/attntarget.H"

using namespace std;
using namespace PRDF;
using namespace TARGETING;
using namespace ERRORLOG;

namespace ATTN
{
enum
{
    // interrupts to host bridge -IPOLL MASK
    ROUTE_TO_HOST      = 0x0400000000000000ull
};



/**
 * @brief calculated mask cache for ipoll
 */
class HostMask
{
    uint64_t iv_hostMask;
    uint64_t iv_nonHostMask;

    HostMask() : iv_hostMask(0), iv_nonHostMask(0)
    {
        uint64_t  l_hostMask;

        // Get attentions only reported on proc/host side
        IPOLL::getCheckbits(UNIT_CS,   l_hostMask);
        IPOLL::getCheckbits(HOST_ATTN, iv_hostMask);
        iv_hostMask |= l_hostMask;

        IPOLL::forEach(~0, &iv_nonHostMask, &getIpollMask);

        iv_nonHostMask = iv_nonHostMask & ~iv_hostMask;
    }

    static void getIpollMask(uint64_t i_type, void * i_data)
    {
        uint64_t & mask = *static_cast<uint64_t *>(i_data);

        uint64_t tmp = 0;
        IPOLL::getCheckbits(i_type, tmp);

        mask |= tmp;
    }

    static HostMask & get()
    {
        static HostMask hm;

        return hm;
    }

    public:

    static uint64_t host()
    {
        return get().iv_hostMask;
    }

    static uint64_t nonHost()
    {
        return get().iv_nonHostMask;
    }
};

errlHndl_t ServiceCommon::configureInterrupts(
        ConfigureMode i_mode)
{
    errlHndl_t err = NULL;
    TargetHandleList  procs;
    getTargetService().getAllChips(procs, TYPE_PROC);
    TargetHandleList::iterator it = procs.begin();


    while(it != procs.end())
    {
        // enable/disable MCSes
        //@TODO: RTC:150944  Do we need to enable/disable MCS ? Doubt it
        //       Seems to be related strictly to that GPIO P8 workaround


        #ifndef __HOSTBOOT_RUNTIME
        uint64_t  mask = 0;
        // enable attentions in ipoll mask
        mask = HostMask::nonHost();
        mask |= HostMask::host();

        // We never messed with FSP mask bits in P8, so
        // not doing it on P9 either.
        mask |= ATTN::ROUTE_TO_HOST;

        // this doesn't have an and/or reg for some reason...
        err = modifyScom(*it,
                         IPOLL::address,
                         i_mode == UP ? ~mask : mask,
                         i_mode == UP ? SCOM_AND : SCOM_OR);

        if(err)
        {
            break;
        }

        #endif // NOT  __HOSTBOOT_RUNTIME

        ++it;
    }

    return err;
}

void ServiceCommon::processAttnPreAck(const TargetHandle_t i_proc)
{
    uint64_t hostMask = HostMask::host();
    uint64_t nonHostMask = HostMask::nonHost();
    uint64_t data = 0;

    // do the minimum that is required
    // for sending EOI without getting
    // another interrupt. This should be
    // masking the appropriate bit in
    // the ipoll mask.

    // Instead of reading the IPOLL status
    // register, we will just mask all
    // potential interrupts on HOST side.

    data = hostMask | nonHostMask;

    // the other thread might be trying to unmask
    // on the same target.  The mutex ensures
    // neither thread corrupts the register.

    mutex_lock(&iv_mutex);

    errlHndl_t err = modifyScom(i_proc, IPOLL::address, data, SCOM_OR);

    mutex_unlock(&iv_mutex);

    ATTN_TRACE("processAttnPreAck Host:%llx  NonHost:%llx  Data:%llx",
                hostMask, nonHostMask, data);

    if(err)
    {
        errlCommit(err, ATTN_COMP_ID);
    }
}

void ServiceCommon::processAttentions(const TargetHandleList & i_procs)
{
    errlHndl_t err = NULL;
    AttentionList attentions;
    // this should be the opposite of what we used for masking in preAck
    uint64_t  restoreMask = ~(HostMask::host() | HostMask::nonHost());

    MemOps & memOps = getMemOps();
    ProcOps & procOps = getProcOps();

    do {

        attentions.clear();

        // enumerate the highest priority pending attention
        // on every chip and then give the entire set to PRD

        TargetHandleList::const_iterator pit = i_procs.end();

        while(pit-- != i_procs.begin())
        {
            // enumerate proc local attentions (xstp,spcl,rec).
            err = procOps.resolveIpoll(*pit, attentions);

            if(err)
            {
                errlCommit(err, ATTN_COMP_ID);
            }

            // enumerate host attentions and convert
            // to centaur targets  (NOOP for now on P9)
            err = memOps.resolve(*pit, attentions);

            if(err)
            {
                errlCommit(err, ATTN_COMP_ID);
            }
        }

        err = getPrdWrapper().callPrd(attentions);

        if(err)
        {
            errlCommit(err, ATTN_COMP_ID);
        }

        // unmask proc local attentions
        // (xstp,rec,special) in ipoll mask

        // any pending attentions will be found
        // on the next pass

        pit = i_procs.end();

        while(pit-- != i_procs.begin())
        {
            mutex_lock(&iv_mutex);

            // the other thread might be trying to mask
            // on the same target.  The mutex ensures
            // neither thread corrupts the register.

            err = modifyScom(
                    *pit,
                    IPOLL::address,
                    restoreMask,
                    SCOM_AND);

            mutex_unlock(&iv_mutex);

            ATTN_TRACE("ProcessATTN:: IPOLL RESTORE :%llx", restoreMask );

            if(err)
            {
                errlCommit(err, ATTN_COMP_ID);
            }
        }

        // if on a given Centaur with a pending attention
        // on an MBA, an attention comes on in the other MBA
        // we don't get an interrupt for that.  So make another
        // pass and check for that.

    } while(!attentions.empty());

}

ServiceCommon::ServiceCommon()
{
    mutex_init(&iv_mutex);
}

ServiceCommon::~ServiceCommon()
{
    mutex_destroy(&iv_mutex);
}

errlHndl_t ServiceCommon::handleAttentions(const TargetHandle_t i_proc)
{
    errlHndl_t err = NULL;
    AttentionList attentions;

    MemOps & memOps = getMemOps();
    ProcOps & procOps = getProcOps();

    do {

       attentions.clear();

       // query the proc resolver for active attentions
       err = procOps.resolve(i_proc, 0, attentions);

       if(err)
       {
           ATTN_ERR("procOps.resolve() returned error.HUID:0X%08X ",
                     get_huid( i_proc ));
           break;
       }

       // query the mem resolver for active attentions

       err = memOps.resolve(i_proc, attentions);

       if(err)
       {
           ATTN_ERR("memOps.resolve() returned error.HUID:0X%08X ",
                     get_huid( i_proc ));
           break;
       }

       ATTN_TRACE("handleAttns %d active( PRD)", attentions.size() );
       if(!attentions.empty())
       {
           err = getPrdWrapper().callPrd(attentions);
       }

       if(err)
       {
           ATTN_ERR("callPrd() returned error." )
           break;
       }
       #ifdef __HOSTBOOT_RUNTIME
       // During runtime, we will only handle one attention at a time
       //and give control back to OPAL.
       break;
       #endif //__HOSTBOOT_RUNTIME

   } while(!attentions.empty());

   return err;
}
}
OpenPOWER on IntegriCloud