summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/hwp/fapiTestHwp.C
blob: 86abbcef5943784200331f6ecb1d465cbced8530 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/hwpf/hwp/fapiTestHwp.C $                              */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2011,2014              */
/*                                                                        */
/* 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 fapiTestHwp.C
 *
 *  @brief Implements a simple test Hardware Procedure
 */

/*
 * Change Log ******************************************************************
 * Flag     Defect/Feature  User        Date        Description
 * ------   --------------  ----------  ----------- ----------------------------
 *                          mjjones     04/21/2011  Created.
 *                          mjjones     06/02/2011  Use ecmdDataBufferBase
 *                          mjjones     06/28/2011  Removed attribute tests
 *                          andrewg     07/07/2011  Added test for hw team to fill in
 *                          mjjones     08/10/2011  Removed clock HWP
 *                          mjjones     09/01/2011  Call toString in InitialTest
 *                          mjjones     09/14/2011  Update to scom function name
 *                          camvanng    09/28/2011  Added test for initfile
 *                          camvanng    11/16/2011  Change function name
 *                                                  fapiHwpExecInitFile()
 *                          mjjones     01/13/2012  Use new ReturnCode interfaces
 *                          mjjones     02/21/2012  Use new Target toEcmdString
 *                          camvanng    05/07/2012  Suppport for associated
 *                                                  target attributes
 *
 *  HWP_IGNORE_VERSION_CHECK
 */

#include <fapiTestHwp.H>
#include <fapiHwAccess.H>
#include <fapiHwpExecInitFile.H>
extern "C"
{

//******************************************************************************
// hwpInitialTest function - Override with whatever you want here
//******************************************************************************
fapi::ReturnCode hwpInitialTest(const std::vector<fapi::Target> & i_target)
{
    FAPI_INF("Performing HWP: hwpInitialTest");

    // Print the ecmd string of the target(s)
    for (size_t i = 0; i < i_target.size(); i++)
    {
        FAPI_INF("hwpInitialTest: target[%u]: %s", i, i_target.at(i).toEcmdString());
    }

    fapi::ReturnCode l_rc;
    uint32_t l_ecmdRc = ECMD_DBUF_SUCCESS;

    do
    {
        // Use PORE_GPE0_SCRATCH2_0x0006000C Scom register for testing
        const uint64_t l_addr = 0x0006000C;
        ecmdDataBufferBase l_ScomData(64);
        uint64_t l_originalScomData = 0;

        // --------------------------------------------------------
        // 1. fapiGetScom test
        // --------------------------------------------------------
        l_rc = fapiGetScom(i_target.front(), l_addr, l_ScomData);
        if (l_rc != fapi::FAPI_RC_SUCCESS)
        {
            FAPI_ERR("hwpInitialTest: Error from fapiGetScom");
            break;
        }
        else
        {
            // Save the original data so we can restore it later
            l_originalScomData = l_ScomData.getDoubleWord(0);
            FAPI_INF("hwpInitialTest: GetScom data 0x%.16llX", l_originalScomData);
        }

        // --------------------------------------------------------
        // 2. fapiPutScom test
        // --------------------------------------------------------
        uint64_t l_scomWriteValue = 0x9000000000000000ULL;

        l_ecmdRc = l_ScomData.setDoubleWord(0, l_scomWriteValue);
        if (l_ecmdRc != ECMD_DBUF_SUCCESS)
        {
            FAPI_ERR("hwpInitialTest: fapiPutScom test, error from ecmdDataBuffer setDoubleWord() - rc 0x%.8X", l_ecmdRc);
            l_rc.setEcmdError(l_ecmdRc);
            break;
        }

        l_rc = fapiPutScom(i_target.front(), l_addr, l_ScomData);
        if (l_rc != fapi::FAPI_RC_SUCCESS)
        {
            FAPI_ERR("hwpInitialTest: Error from fapiPutScom");
            break;
        }
        else
        {
            FAPI_INF("hwpInitialTest: PutScom data 0x%.16llX", l_scomWriteValue);
        }

        // --------------------------------------------------------
        // 3. fapiPutScomUnderMask test
        // --------------------------------------------------------
        l_scomWriteValue = 0xA000000000000000ULL;
        uint64_t l_mask  = 0x3000000000000000ULL;
        ecmdDataBufferBase l_maskData(64);

        l_ecmdRc = l_ScomData.setDoubleWord(0, l_scomWriteValue);
        l_ecmdRc |= l_maskData.setDoubleWord(0, l_mask);
        if (l_ecmdRc != ECMD_DBUF_SUCCESS)
        {
            FAPI_ERR("hwpInitialTest: fapiPutScomUnderMask test, error from ecmdDataBuffer setDoubleWord() - rc 0x%.8X", l_ecmdRc);
            l_rc.setEcmdError(l_ecmdRc);;
            break;
        }


        l_rc = fapiPutScomUnderMask(i_target.front(), l_addr, l_ScomData, l_maskData);
        if (l_rc != fapi::FAPI_RC_SUCCESS)
        {
            FAPI_ERR("hwpInitialTest: Error from fapiPutScomUnderMask");
            break;
        }
        else
        {
            FAPI_INF("hwpInitialTest: fapiPutScomUnderMask data 0x%.16llX, mask 0x%.16llX",
                     l_scomWriteValue, l_mask);
        }

        // --------------------------------------------------------
        // 4. fapiPutScom to restore original value
        // --------------------------------------------------------
        l_ecmdRc = l_ScomData.setDoubleWord(0, l_originalScomData);
        if (l_ecmdRc != ECMD_DBUF_SUCCESS)
        {
            FAPI_ERR("hwpInitialTest: fapiPutScom to restore, error from ecmdDataBuffer setDoubleWord() - rc 0x%.8X", l_ecmdRc);
            l_rc.setEcmdError(l_ecmdRc);
            break;
        }

        l_rc = fapiPutScom(i_target.front(), l_addr, l_ScomData);
        if (l_rc != fapi::FAPI_RC_SUCCESS)
        {
            FAPI_ERR("hwpInitialTest: Error from fapiPutScom");
            break;
        }
        else
        {
            FAPI_INF("hwpInitialTest: PutScom data 0x%.16llX", l_originalScomData);
        }

#if 0
// @todo
// Per Dean, there's no access to the CFAM engines on the master processor, therefore,
// we *should not* allow access to them on any processor in any position
// from a FAPI standpoint.
// This means that get/put/modifyCfamRegister can't not be called on any of the processors.
// These functions, therefore, can only be called on the Centaur, which is not available
// at this time.
// When Centaur is supported:
//  - Don't use i_target.front() (a processor) as a target. Set the target as one of the Centaurs.
//  - Enable this block of code and test the cfam access functions on the Centaur.

        // --------------------------------------------------------
        // 5. fapiGetCfamRegister test
        // --------------------------------------------------------
        ecmdDataBufferBase l_cfamData(32); // 32-bit cfam data holder
        uint32_t l_originalCfamData = 0;
        const uint32_t l_cfamAddr = 0x100A; // ChipID register
        l_rc = fapiGetCfamRegister(i_target.front(), l_cfamAddr, l_cfamData);
        if (l_rc != fapi::FAPI_RC_SUCCESS)
        {
            FAPI_ERR("hwpInitialTest: Error from fapiGetCfamRegister");
            break;
        }
        else
        {
            l_originalCfamData = l_cfamData.getWord(0);
            FAPI_INF("hwpInitialTest: fapiGetCfamRegister data 0x%.8X",
                    l_originalCfamData);
        }

        // --------------------------------------------------------
        // 6. fapiPutCfamRegister test
        // --------------------------------------------------------
        uint32_t l_cfamWriteValue = 0x90000000;
        l_ecmdRc = l_cfamData.setWord(0, l_cfamWriteValue);
        if (l_ecmdRc != ECMD_DBUF_SUCCESS)
        {
            FAPI_ERR("hwpInitialTest: fapiPutCfamRegister test, error from ecmdDataBuffer setWord() - rc 0x%.8X", l_ecmdRc);
            l_rc.setEcmdError(l_ecmdRc);;
            break;
        }


        l_rc = fapiPutCfamRegister(i_target.front(), l_cfamAddr, l_cfamData);
        if (l_rc != fapi::FAPI_RC_SUCCESS)
        {
            FAPI_ERR("hwpInitialTest: Error from fapiPutCfamRegister");
            break;
        }
        else
        {
            FAPI_INF("hwpInitialTest: fapiPutCfamRegister data 0x%.8X",
                    l_cfamData.getWord(0));
        }

        // --------------------------------------------------------
        // 7. fapiModifyCfamRegister test
        // --------------------------------------------------------
        l_cfamWriteValue = 0xA0000000;
        l_ecmdRc = l_cfamData.setWord(0, l_cfamWriteValue);
        if (l_ecmdRc != ECMD_DBUF_SUCCESS)
        {
            FAPI_ERR("hwpInitialTest: fapiModifyCfamRegister test, error from ecmdDataBuffer setWord() - rc 0x%.8X", l_ecmdRc);
            l_rc.setEcmdError(l_ecmdRc);;
            break;
        }

        l_rc = fapiModifyCfamRegister(i_target.front(), l_cfamAddr,
                l_cfamData, fapi::CHIP_OP_MODIFY_MODE_AND);
        if (l_rc != fapi::FAPI_RC_SUCCESS)
        {
            FAPI_ERR("hwpInitialTest: Error from fapiPutCfamRegister");
            break;
        }
        else
        {
            FAPI_INF("hwpInitialTest: fapiPutCfamRegister data 0x%.8X",
                    l_cfamData.getWord(0));
        }

        // --------------------------------------------------------
        // 8. fapiPutCfamRegister to restore original CFAM value
        // --------------------------------------------------------
        l_ecmdRc = l_cfamData.setWord(0, l_originalCfamData);
        if (l_ecmdRc != ECMD_DBUF_SUCCESS)
        {
            FAPI_ERR("hwpInitialTest: fapiPutCfamRegister to restore, error from ecmdDataBuffer setWord() - rc 0x%.8X", l_ecmdRc);
            l_rc.setEcmdError(l_ecmdRc);;
            break;
        }

        l_rc = fapiPutCfamRegister(i_target.front(), l_cfamAddr, l_cfamData);
        if (l_rc != fapi::FAPI_RC_SUCCESS)
        {
            FAPI_ERR("hwpInitialTest: Error from fapiPutCfamRegister to restore");
            break;
        }
        else
        {
            FAPI_INF("hwpInitialTest: fapiPutCfamRegister data 0x%.8X",
                    l_cfamData.getWord(0));
        }

#endif

        // --------------------------------------------------------
        // 9. fapiHwpExecInitFile test
        // --------------------------------------------------------

        //Call Hwp to execute the sample initfile
        FAPI_EXEC_HWP(l_rc, fapiHwpExecInitFile, i_target, "sample.if");
        if (l_rc != fapi::FAPI_RC_SUCCESS)
        {
            FAPI_ERR("hwpInitialTest: Error from fapiHwpExecInitFile");
            break;
        }
        else
        {
            FAPI_INF("hwpInitialTest: fapiHwpExecInitFile passed");
        }

    } while (0);

    return l_rc;
}


} // extern "C"
OpenPOWER on IntegriCloud