summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/hwp/tod_init/TodSvc.C
blob: e9c87e3bdef9b22ea2b502f691b54fb4e886fd27 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/hwpf/hwp/tod_init/TodSvc.C $                          */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 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 TodSvc.C
 *
 *  @brief Implements the TodSvc class that provides the Time Of Day service
 *
 *  HWP_IGNORE_VERSION_CHECK
 *
 */

#include <p8_scom_addresses.H>
#include <errl/errlentry.H>
#include <errl/errlmanager.H>
#include <tod_init/tod_init_reasoncodes.H>
#include "TodTopologyManager.H"
#include "TodTrace.H"
#include "TodSvcUtil.H"
#include "TodHwpIntf.H"
#include "TodControls.H"
#include "TodSvc.H"
#include "proc_tod_utils.H"

namespace TOD
{

TodSvc & TodSvc::getTheInstance()
{
    return Singleton<TodSvc>::instance();
}

//******************************************************************************
//TodSvc::todSetup
//******************************************************************************
errlHndl_t TodSvc::todSetup()
{
    TOD_ENTER("todSetup");

    errlHndl_t l_errHdl = NULL;
    bool l_isTodRunning = false;
    TodTopologyManager l_primary(TOD_PRIMARY);
    TodControls & l_Tod = TodControls::getTheInstance();

    do
    {
        l_errHdl = l_Tod.isTodRunning(l_isTodRunning);
        if ( l_errHdl )
        {
            TOD_INF("Call to isTodRunning failed , cannot create topology");
            break;
        }

        if ( l_isTodRunning )
        {
            TOD_ERR("Cannot create TOD topology while the Chip TOD logic"
                    "is running ");
            /*@
             * @errortype
             * @reasoncode   TOD_INVALID_ACTION
             * @moduleid     TOD_SETUP
             * @userdata1    ChipTOD logic HW state , 1=running , zero otherwise
             * @devdesc      Error: can not create TOD topology when TOD
             *               HW is running
             */
            l_errHdl = new ERRORLOG::ErrlEntry(
                               ERRORLOG::ERRL_SEV_INFORMATIONAL,
                               TOD_SETUP,
                               TOD_INVALID_ACTION,
                               l_isTodRunning ? 1 : 0, 0);
            break;
        }

        l_Tod.destroy(TOD_PRIMARY);
        l_Tod.destroy(TOD_SECONDARY);

        //We're going to setup TOD for this IPL
        //1) Build a set of datastructures to setup creation of the TOD
        //topologies.
        l_errHdl = l_Tod.buildTodDrawers(TOD_PRIMARY);
        if(l_errHdl)
        {
            TOD_ERR("TOD setup failure: failed to build TOD drawers "
                     "for primary topology.");
            break;
        }

        //2) Ask the topology manager to setup the primary topology
        l_errHdl = l_primary.create();
        if(l_errHdl)
        {
            TOD_ERR("TOD setup failure: failed to create primary topology.");
            break;
        }
        l_primary.dumpTopology();

        //3) Call hardware procedures to configure the TOD hardware logic for
        //the primary topology and to fill up the TOD regs.
        l_errHdl = todSetupHwp(TOD_PRIMARY);
        if(l_errHdl)
        {
            TOD_ERR("TOD setup failure: primary topology setup HWP.");
            break;
        }
        l_errHdl = todSaveRegsHwp(TOD_PRIMARY);
        if(l_errHdl)
        {
            TOD_ERR("TOD setup failure: primary topology register save HWP.");
            break;
        }

        //Primary successfully configured
        l_Tod.setConfigStatus(TOD_PRIMARY,true);

        //Build datastructures for secondary topology
        l_errHdl = l_Tod.buildTodDrawers(TOD_SECONDARY);
        if(l_errHdl)
        {
            TOD_ERR("TOD setup failure: failed to build TOD drawers "
                     "for secondary topology.");
            //Report the error as informational - loss of redundancy,
            //but no loss of TOD function.
            errlCommit( l_errHdl, TOD_COMP_ID );
            break;
        }

        //4) Ask the topology manager to setup the secondary topology
        TodTopologyManager l_secondary(TOD_SECONDARY);
        l_errHdl = l_secondary.create();
        if(l_errHdl)
        {
            TOD_ERR("TOD setup failure: failed to create secondary topology.");
            //Report the error as informational - loss of redundancy,
            //but no loss of TOD function.
            errlCommit( l_errHdl, TOD_COMP_ID );
            break;
        }
        l_secondary.dumpTopology();

        //5) Call hardware procedures to configure the TOD hardware logic for
        //the secondary topology and to fill up the TOD regs.
        l_errHdl = todSetupHwp(TOD_SECONDARY);
        if(l_errHdl)
        {
            TOD_ERR("TOD setup failure: secondary topology setup HWP.");
            //Report the error as informational - loss of redundancy,
            //but no loss of TOD function.
            errlCommit( l_errHdl, TOD_COMP_ID );
            break;
        }

        //Secondary successfully configured
        l_Tod.setConfigStatus(TOD_SECONDARY,true);

        //Need to call this again if the secondary topology got set up,
        //that would have updated more regs.
        l_errHdl = todSaveRegsHwp(TOD_PRIMARY);
        if(l_errHdl)
        {
            TOD_ERR("TOD setup failure: primary topology register save HWP.");
            break;
        }

        //Done with TOD setup
    }while(0);

    if((NULL == l_errHdl) &&
       (false ==  l_isTodRunning ))
    {
        l_primary.dumpTodRegs();

        //If we are then atleast Primary or both configurations were
        //successfully setup. If both were successfuly setup then we can use
        //writeTodProcData for either of them else we should call
        //writeTodProcData for only primary.
        //Ultimately it should be good enough to call the method for Primary
        l_errHdl = l_Tod.writeTodProcData(TOD_PRIMARY);
        if(l_errHdl)
        {
            TOD_ERR("TOD setup failure:Failed to write topology register data"
            " to the file.");
        }
    }

    TOD_EXIT("todSetup. errHdl = %p", l_errHdl);

    return l_errHdl;
}

//******************************************************************************
//TodSvc::todInit
//******************************************************************************
errlHndl_t TodSvc::todInit()
{
    return todInitHwp(TOD_PRIMARY);
}

//******************************************************************************
//TodSvc::readTod
//******************************************************************************
errlHndl_t TodSvc::readTod(uint64_t& o_todValue) const
{
    TOD_ENTER("readTod");

    errlHndl_t l_errHdl = NULL;

    do
    {
        //Get the MDMT
        TodProc* l_pMDMT =
            TodControls::getTheInstance().getMDMT(TOD_PRIMARY);
        if(NULL == l_pMDMT)
        {
            TOD_ERR("MDMT not found");
            /*@
             * @errortype
             * @reasoncode   TOD_NO_MASTER_PROC
             * @moduleid     TOD_READ
             * @devdesc      MDMT could not be found
             */
            l_errHdl = new ERRORLOG::ErrlEntry(
                               ERRORLOG::ERRL_SEV_INFORMATIONAL,
                               TOD_READ,
                               TOD_NO_MASTER_PROC);
            break;
        }

        //SCOM the TOD value reg
        ecmdDataBufferBase o_todValueBuf(64);
        l_errHdl = todGetScom(l_pMDMT->getTarget(),
                              TOD_VALUE_REG_00040020,
                              o_todValueBuf);
        if(l_errHdl)
        {
            TOD_ERR("TOD read error: failed to SCOM TOD value register "
                     "address 0x%.16llX on MDMT 0x%.8X.",
                     TOD_VALUE_REG_00040020,
                     l_pMDMT->getTarget()->getAttr<TARGETING::ATTR_HUID>());
            break;
        }
        o_todValue = o_todValueBuf.getDoubleWord(0);

        TOD_INF("TOD value : 0x%.16llx", o_todValue );

    }while(0);

    TOD_EXIT("readTod. errHdl = %p", l_errHdl);

    return l_errHdl;
}

//******************************************************************************
//TodSvc::TodSvc
//******************************************************************************
TodSvc::TodSvc()
{
    TOD_ENTER("TodSvc constructor");

    TOD_EXIT("TodSvc constructor");
}

//******************************************************************************
//TodSvc::~TodSvc
//******************************************************************************
TodSvc::~TodSvc()
{
    TOD_ENTER("TodSvc destructor");

    //Free up held memory
    TodControls::getTheInstance().destroy(TOD_PRIMARY);
    TodControls::getTheInstance().destroy(TOD_SECONDARY);

    TOD_EXIT("TodSvc destructor");
}

} //namespace TOD
OpenPOWER on IntegriCloud