summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/hwp/tod_init/proc_tod_utils/proc_tod_utils.C
blob: a284a06e3fd6a823b2e9fb0f5fdfd95646568170 (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/hwpf/hwp/tod_init/proc_tod_utils/proc_tod_utils.C $   */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2013,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                                                     */
// $Id: proc_tod_utils.C,v 1.4 2012/10/23 19:17:00 jklazyns Exp $
//------------------------------------------------------------------------------
// *! (C) Copyright International Business Machines Corp. 2012
// *! All Rights Reserved -- Property of IBM
// *! *** IBM Confidential ***
// *!
// *! TITLE : proc_tod_utils.C
// *!
// *! DESCRIPTION : TOD helper functions; not called directly, but used by other
// *!               FAPI procedures
// *!
// *! OWNER NAME  : Nick Klazynski  Email: jklazyns@us.ibm.com
// *! BACKUP NAME :                 Email:
// *!
// *! ADDITIONAL COMMENTS :
// *!
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Includes
//------------------------------------------------------------------------------
#include "proc_tod_utils.H"
#include "p8_scom_addresses.H"

//------------------------------------------------------------------------------
// Function definitions
//------------------------------------------------------------------------------

extern "C"
{

//------------------------------------------------------------------------------
// function: proc_tod_utils_get_tfmr_reg
//
// parameters: i_target     => chip target
//             o_tfmr_val   => TFMR value read
// returns: FAPI_RC_SUCCESS if TFMR read is successful
//          else FAPI or ECMD error is sent through
//
//------------------------------------------------------------------------------
fapi::ReturnCode proc_tod_utils_get_tfmr_reg(
    const fapi::Target& i_target,
    ecmdDataBufferBase& o_tfmr_val)
{
    fapi::ReturnCode rc;
    ecmdDataBufferBase data(64);
    uint32_t rc_ecmd = 0;

    FAPI_INF("proc_tod_utils_get_tfmr_reg: Start");

    do
    {
        //FAPI_DBG("proc_tod_utils_get_tfmr_reg: Setting SPR_MODE to LPAR0/T0");
        rc_ecmd |= data.flushTo0();
        rc_ecmd |= data.setBit(SPR_MODE_REG_MODE_SPRC_WR_EN);
        rc_ecmd |= data.setBit(SPR_MODE_REG_MODE_SPRC0_SEL);
        rc_ecmd |= data.setBit(SPR_MODE_REG_MODE_SPRC_T0_SEL);
        if (rc_ecmd)
        {
            FAPI_ERR("proc_tod_utils_get_tfmr_reg: Error 0x%08X in ecmdDataBuffer setup for EX_PERV_SPR_MODE_10013281 SCOM.",  rc_ecmd);
            rc.setEcmdError(rc_ecmd);
            break;
        }
        rc = fapiPutScom(i_target, EX_PERV_SPR_MODE_10013281, data);
        if (!rc.ok())
        {
            FAPI_ERR("proc_tod_utils_get_tfmr_reg: fapiPutScom error for EX_PERV_SPR_MODE_10013281 SCOM.");
            break;
        }
        //FAPI_DBG("proc_tod_utils_get_tfmr_reg: Setting SPRC to T0's TMFR");
        rc_ecmd |= data.flushTo0();
        rc_ecmd |= data.insertFromRight(SPRC_REG_SEL_TFMR_T0,SPRC_REG_SEL,SPRC_REG_SEL_LEN);
        if (rc_ecmd)
        {
            FAPI_ERR("proc_tod_utils_get_tfmr_reg: Error 0x%08X in ecmdDataBuffer setup for EX_PERV_L0_SCOM_SPRC_10013280 SCOM.",  rc_ecmd);
            rc.setEcmdError(rc_ecmd);
            break;
        }
        rc = fapiPutScom(i_target, EX_PERV_L0_SCOM_SPRC_10013280, data);
        if (!rc.ok())
        {
            FAPI_ERR("proc_tod_utils_get_tfmr_reg: fapiPutScom error for EX_PERV_L0_SCOM_SPRC_10013280 SCOM.");
            break;
        }

        //FAPI_DBG("proc_tod_utils_get_tfmr_reg: Reading SPRD for T0's TMFR");
        rc = fapiGetScom(i_target, EX_PERV_SPRD_L0_100132A3, o_tfmr_val);
        if (!rc.ok())
        {
            FAPI_ERR("proc_tod_utils_get_tfmr_reg: fapiGetScom error for EX_PERV_SPRD_L0_100132A3 SCOM.");
            break;
        }

    } while(0);

    FAPI_INF("proc_tod_utils_get_tfmr_reg: End");
    return rc;
}

//------------------------------------------------------------------------------
// function: proc_tod_utils_set_tfmr_reg
//
// parameters: i_target     => chip target
//             i_tfmr_val   => TFMR value to write
// returns: FAPI_RC_SUCCESS if TFMR write is successful
//          else FAPI or ECMD error is sent through
//
//------------------------------------------------------------------------------
fapi::ReturnCode proc_tod_utils_set_tfmr_reg(
    const fapi::Target& i_target,
    ecmdDataBufferBase& i_tfmr_val)
{
    fapi::ReturnCode rc;
    ecmdDataBufferBase data(64);
    uint32_t rc_ecmd = 0;

    FAPI_INF("proc_tod_utils_set_tfmr_reg: Start");

    do
    {
        //FAPI_DBG("proc_tod_utils_set_tfmr_reg: Setting SPR_MODE to LPAR0/T0");
        rc_ecmd |= data.flushTo0();
        rc_ecmd |= data.setBit(SPR_MODE_REG_MODE_SPRC_WR_EN);
        rc_ecmd |= data.setBit(SPR_MODE_REG_MODE_SPRC0_SEL);
        rc_ecmd |= data.setBit(SPR_MODE_REG_MODE_SPRC_T0_SEL);
        if (rc_ecmd)
        {
            FAPI_ERR("proc_tod_utils_set_tfmr_reg: Error 0x%08X in ecmdDataBuffer setup for EX_PERV_SPR_MODE_10013281 SCOM.",  rc_ecmd);
            rc.setEcmdError(rc_ecmd);
            break;
        }
        rc = fapiPutScom(i_target, EX_PERV_SPR_MODE_10013281, data);
        if (!rc.ok())
        {
            FAPI_ERR("proc_tod_utils_set_tfmr_reg: fapiPutScom error for EX_PERV_SPR_MODE_10013281 SCOM.");
            break;
        }
        //FAPI_DBG("proc_tod_utils_set_tfmr_reg: Setting SPRC to T0's TMFR");
        rc_ecmd |= data.flushTo0();
        rc_ecmd |= data.insertFromRight(SPRC_REG_SEL_TFMR_T0,SPRC_REG_SEL,SPRC_REG_SEL_LEN);
        if (rc_ecmd)
        {
            FAPI_ERR("proc_tod_utils_set_tfmr_reg: Error 0x%08X in ecmdDataBuffer setup for EX_PERV_L0_SCOM_SPRC_10013280 SCOM.",  rc_ecmd);
            rc.setEcmdError(rc_ecmd);
            break;
        }
        rc = fapiPutScom(i_target, EX_PERV_L0_SCOM_SPRC_10013280, data);
        if (!rc.ok())
        {
            FAPI_ERR("proc_tod_utils_set_tfmr_reg: fapiPutScom error for EX_PERV_L0_SCOM_SPRC_10013280 SCOM.");
            break;
        }
        //FAPI_DBG("proc_tod_utils_set_tfmr_reg: Writing SPRD to set T0's TMFR");
        rc = fapiPutScom(i_target, EX_PERV_SPRD_L0_100132A3, i_tfmr_val);
        if (!rc.ok())
        {
            FAPI_ERR("proc_tod_utils_set_tfmr_reg: fapiGetScom error for EX_PERV_SPRD_L0_100132A3 SCOM.");
            break;
        }
    } while(0);

    FAPI_INF("proc_tod_utils_set_tfmr_reg: End");
    return rc;
}

} // extern "C"
OpenPOWER on IntegriCloud