summaryrefslogtreecommitdiffstats
path: root/src/occ_405/proc/proc_data_control.c
blob: c68b4223141b1195c0748f224f66b9e14e38104e (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/occ/proc/proc_data_control.c $                            */
/*                                                                        */
/* OpenPOWER OnChipController Project                                     */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2011,2015                        */
/* [+] 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                                                     */

#include "proc_data.h"
#include "occhw_async.h"
#include "threadSch.h"
#include "pmc_register_addresses.h"
#include "proc_data_service_codes.h"
#include "occ_service_codes.h"
#include "errl.h"
#include "trac.h"
#include "rtls.h"
#include "apss.h"
#include "state.h"
#include "occ_sys_config.h"

// Pore flex request for GPE job. The initialization will be done one time
// during pore flex create.
PoreFlex G_core_data_control_req;

// Global double buffering for core data control
GPE_BUFFER(PcbsPstateRegs G_core_data_control_a[MAX_NUM_HW_CORES]) = {{{0}}};
GPE_BUFFER(PcbsPstateRegs G_core_data_control_b[MAX_NUM_HW_CORES]) = {{{0}}};

// Pointer to the core data control that will be used by GPE engine.
GPE_BUFFER(PcbsPstateRegs * G_core_data_control_gpewrite_ptr) = { &G_core_data_control_a[0] };

// Pointer to the core data control that will be written to by the OCC FW.
GPE_BUFFER(PcbsPstateRegs * G_core_data_control_occwrite_ptr) = { &G_core_data_control_b[0] };

// The Gpe parameter fields are set up each time before the GPE starts.
GPE_BUFFER(GpeSetPstatesParms G_core_data_control_parms);

// Function Specification
//
// Name: proc_set_pstate
//
// Description: Function to demonstrate setting Pstates to all cores
//              Should only be run from RTL
//
// End Function Specification
void proc_set_pstate_all(Pstate i_pstate)
{
  uint8_t l_chiplet = 0;

  for(; l_chiplet<MAX_NUM_HW_CORES; l_chiplet++)
  {
     set_chiplet_pstate(G_core_data_control_occwrite_ptr,
                        l_chiplet,
                        i_pstate,
                        i_pstate);
  }

  PROC_DBG("Setting Pstates to %d\n",i_pstate);
}


// Function Specification
//
// Name: proc_set_core_pstate
//
// Description: Function to demonstrate setting Pstates to all cores
//              Should only be run from RTL
//
// End Function Specification
void proc_set_core_pstate(Pstate i_pstate, uint8_t i_core)
{
  set_chiplet_pstate(G_core_data_control_occwrite_ptr,
                        CORE_OCC2HW(i_core),
                        i_pstate,
                        i_pstate);
}

// Function Specification
//
// Name: proc_set_core_bounds
//
// Description: Function to set core pmin/pmax
//              Should only be run from RTL
//
// End Function Specification
void proc_set_core_bounds(Pstate i_pmin, Pstate i_pmax, uint8_t i_core)
{
    Pstate l_pmax;
    uint8_t l_hw_core = CORE_OCC2HW(i_core);

    //don't allow pmax to be set lower than pmin
    if(i_pmax < i_pmin)
    {
        l_pmax = i_pmin;
    }
    else
    {
        l_pmax = i_pmax;
    }

    set_chiplet_pmax(G_core_data_control_occwrite_ptr,
                     l_hw_core,
                     l_pmax);
    set_chiplet_pmin(G_core_data_control_occwrite_ptr,
                     l_hw_core,
                     i_pmin);
}


// Function Specification
//
// Name: proc_core_data_control_init
//
// Description: Initializations needed for core data control task
//
// End Function Specification
void proc_core_data_control_init( void )
{
    errlHndl_t l_err = NULL;   //Error handler
    tracDesc_t l_trace = NULL; //Temporary trace descriptor
    int         rc = 0; //Return code

    do
    {
        //FIXME: Need to change this to use PGPE queue
        //Initializes PoreFlex object for pstate control
        rc = pore_flex_create( &G_core_data_control_req,  //gpe_req for the task
                &G_pore_gpe0_queue,                       //queue
                gpe_set_pstates,                          //entry point
                (uint32_t) &G_core_data_control_parms,    //parm for the task
                SSX_WAIT_FOREVER,                         //no timeout
                NULL,                                     //callback
                NULL,                                     //callback argument
                0 );                                      //options
        if( rc )
        {
            //If fail to create pore flex object then there is a problem.
            TRAC_ERR("Fail to create core control poreFlex object[0x%x]", rc );

            /*
             * @errortype
             * @moduleid    PROC_CORE_INIT_MOD
             * @reasoncode  SSX_GENERIC_FAILURE
             * @userdata1   pore_flex_create return code
             * @userdata4   ERC_PROC_CONTROL_INIT_FAILURE
             * @devdesc     Failure to create poreflex object
             */
            l_err = createErrl(
                    PROC_CORE_INIT_MOD,                     //modId
                    SSX_GENERIC_FAILURE,                    //reasoncode
                    ERC_PROC_CONTROL_INIT_FAILURE,          //Extended reason code
                    ERRL_SEV_PREDICTIVE,                    //Severity
                    l_trace,    //TODO: create l_trace      //Trace Buf
                    DEFAULT_TRACE_SIZE,                     //Trace Size
                    rc,                                     //userdata1
                    0                                       //userdata2
                    );

            // commit error log
            REQUEST_RESET(l_err); //$gm006
            break;
        }

    } while(0);
}

// Function Specification
//
// Name: task_core_data_control
//
// Description: Control core actuation for all configured cores on every tick.
//
// End Function Specification
void task_core_data_control( task_t * i_task )
{
//TEMP/TODO: proc_core_data_control_init needs to be called from proc_core_init()
//           when this task is enabled for it to function properly.
    errlHndl_t       l_err   = NULL;     //Error handler
    tracDesc_t       l_trace = NULL;     //Temporary trace descriptor
    int              rc      = 0;        //Return code
    PcbsPstateRegs * l_temp  = NULL;

    do
    {

        //Check to see if the previous GPE request still running
        if( !(async_request_is_idle(&G_core_data_control_req.request)) )
        {
            break;
        }

        //Check to see if the previosuly GPE request has been succeeded
        if( async_request_completed(&G_core_data_control_req.request) )
        {
            //If the previous GPE request succeeded then swap the
            //gpewrite ptr with the occwrite ptr.
            l_temp = G_core_data_control_occwrite_ptr;
            G_core_data_control_gpewrite_ptr = l_temp;
        }

        //Setup the core data control parms
        G_core_data_control_parms.config = (uint64_t) (((uint64_t) G_present_hw_cores) << 32);
        if(G_sysConfigData.system_type.kvm)
        {
            //Set the chiplet bounds (pmax/pmin) only on opal
            G_core_data_control_parms.select = GPE_SET_PSTATES_PMBR;
        }
        else
        {
            //Set the chiplet pstate request on non-opal systems
            G_core_data_control_parms.select = GPE_SET_PSTATES_PMCR;
        }

        G_core_data_control_parms.regs = (uint32_t) G_core_data_control_gpewrite_ptr;

        rc = pore_flex_schedule( &G_core_data_control_req );
        if( rc != 0 )
        {
            TRAC_ERR("Failed PoreFlex schedule core data control [%x] \n", rc);

            /*
             * @errortype
             * @moduleid    PROC_TASK_CORE_DATA_MOD
             * @reasoncode  SSX_GENERIC_FAILURE
             * @userdata1   pore_flex_schedule return code
             * @userdata4   ERC_PROC_CONTROL_TASK_FAILURE
             * @devdesc     Failure to schedule poreflex object
             */
            l_err = createErrl(
                    PROC_TASK_CORE_DATA_MOD,                //modId
                    SSX_GENERIC_FAILURE,                    //reasoncode
                    ERC_PROC_CONTROL_TASK_FAILURE,          //Extended reason code
                    ERRL_SEV_PREDICTIVE,                    //Severity
                    l_trace,    //TODO: create l_trace      //Trace Buf
                    DEFAULT_TRACE_SIZE,                     //Trace Size
                    rc,                                     //userdata1
                    0                                       //userdata2
                    );

            // commit error log
            REQUEST_RESET(l_err);
            break;
        }
    } while(0);

    return;
}
OpenPOWER on IntegriCloud