summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/attn/test/attnfakeipoll.C
blob: 65693137759ffeac6cb25fed3bbde3fc512d1874 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/attn/test/attnfakeipoll.C $                      */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2012,2013              */
/*                                                                        */
/* p1                                                                     */
/*                                                                        */
/* Object Code Only (OCO) source materials                                */
/* Licensed Internal Code Source Materials                                */
/* IBM HostBoot Licensed Internal Code                                    */
/*                                                                        */
/* The source code for this program is not published or otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* Origin: 30                                                             */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
/**
 * @file attnfakeipoll.C
 *
 * @brief HBATTN fake Ipoll mask register class method definitions.
 */

#include "attnfakeipoll.H"
#include "attnfakesys.H"
#include "attnfakepresenter.H"
#include "../attntarget.H"

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

namespace ATTN
{

struct InterruptProperties
{
    FakeSystem * system;

    FakeIpoll * inst;
};

errlHndl_t FakeIpoll::processPutReg(
        FakeSystem & i_sys,
        TARGETING::TargetHandle_t i_target,
        uint64_t i_address,
        uint64_t i_new,
        uint64_t i_old)
{
    errlHndl_t err = NULL;

    // check for a gfir bit turning on, or
    // if ipoll is unmasked while gfir is high
    // then raise an interrupt

    uint64_t ipollContent = i_address == IPOLL::address
        ? i_new
        : i_sys.getReg(i_target, IPOLL::address);

    uint64_t content = i_address == iv_address
        ? i_new
        : i_sys.getReg(i_target, iv_address);

    bool masked = (ipollContent & iv_ipollbits);
    bool hi = (content & iv_gfirbits);

    bool unmasked = i_address == IPOLL::address
        ? ~ipollContent & i_old & iv_ipollbits
        : false;

    bool set = false;

    if(i_address == GP1::address)
    {
            set = i_new != i_old;
    }
    else if(i_address != IPOLL::address)
    {
        set = ((content & iv_gfirbits) && !(i_old & iv_gfirbits));
    }

    if((set && !masked)
            || (unmasked && hi))
    {
        err = i_sys.modifyReg(
                i_target,
                IPOLL_STATUS_REG,
                iv_ipollbits,
                SCOM_OR);

        interrupt(i_sys, i_target, ATTENTION);
    }
    else
    {
        err = i_sys.modifyReg(
                i_target,
                IPOLL_STATUS_REG,
                ~iv_ipollbits,
                SCOM_AND);
    }

    return err;
}

void FakeIpoll::processEoi(
        FakeSystem & i_sys,
        TARGETING::TargetHandle_t i_source,
        MessageType i_type)
{
    // if gfir is still high and unmasked raise
    // another interrupt...

    uint64_t ipollContent = i_sys.getReg(i_source, IPOLL::address);
    uint64_t content = i_sys.getReg(i_source, iv_address);

    bool masked = ipollContent & iv_ipollbits;
    bool high = content & iv_gfirbits;

    if(high && !masked && iv_address != GP1::address)
    {
        interrupt(i_sys, i_source, ATTENTION);
    }
}

void FakeIpoll::callback(
        TargetHandle_t i_source,
        MessageType i_type,
        void * i_properties)
{
    InterruptProperties * p = static_cast<InterruptProperties *>(i_properties);

    FakeSystem & f = *p->system;
    FakeIpoll & inst = *p->inst;

    inst.processEoi(f, i_source, i_type);

    delete p;
}

void FakeIpoll::interrupt(
        FakeSystem & i_system,
        TargetHandle_t i_source,
        MessageType i_type)
{
    // instruct the presenter to raise an interrupt, using
    // our callback

    InterruptProperties * p = new InterruptProperties;

    p->inst = this;
    p->system = & i_system;

    iv_presenter->interrupt(i_source, i_type, p, &callback);
}

void FakeIpoll::install(FakeSystem & i_sys)
{
    // monitor ipoll
    i_sys.addReg(IPOLL::address, *this);

    // monitor signal being masked by ipoll
    i_sys.addReg(iv_address, *this);
}

void getMask(uint64_t i_pos, void * i_data)
{
    uint64_t & mask = *static_cast<uint64_t *>(i_data);

    uint64_t tmp = 0;
    GP1::getCheckbits(i_pos, tmp);

    mask |= tmp;
}

FakeIpoll::FakeIpoll(
        uint64_t i_type,
        FakePresenter & i_presenter) :
     iv_address(0),
     iv_gfirbits(0),
     iv_ipollbits(0),
     iv_presenter(&i_presenter)
{
    if(i_type == HOST)
    {
        // figure out what bits to monitor
        // in the nest gp1 register, if
        // this instance is monitoring
        // HOST attentions.

        GP1::forEach(0xffffffffffffffffull, &iv_gfirbits, &getMask);
        iv_address = GP1::address;
    }

    else
    {
        GFIR::getAddress(i_type, iv_address);
        GFIR::getCheckbits(i_type, iv_gfirbits);
    }

    IPOLL::getCheckbits(i_type, iv_ipollbits);
}
}
OpenPOWER on IntegriCloud