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

#ifndef PROC_PSTATE_H
#define PROC_PSTATE_H

#include "ssx.h"
#include "cmdh_service_codes.h"
#include "errl.h"
#include "trac.h"
#include "rtls.h"
#include "occ_common.h"
#include "p9_pstates_common.h"
#include "state.h"
#include "cmdh_fsp_cmds.h"
#include "cmdh_dbug_cmd.h"
//#include "gpsm.h"
//#include "pstates.h"

// The pstate associated with highest possible frequency
// is always 0 in POWER9.
#define PMAX 0

typedef enum
{
    PSTATES_IN_TRANSITION = -1,
    PSTATES_DISABLED      = 0,
    PSTATES_ENABLED       = 1,
    PSTATES_FAILED        = 2,
} pstateStatus;


typedef enum
{
    OPAL_STATIC = 0,
    OPAL_DYNAMIC = 1,
} opalDataType;


typedef struct __attribute__ ((packed))
{
    uint8_t              valid;
    uint8_t              version;
    uint8_t              occ_role;
    uint8_t              pmin;
    uint8_t              pnominal;
    uint8_t              pturbo;
    uint8_t              puturbo;
    uint8_t              reserved;

} opal_config_t;


typedef struct __attribute__ ((packed))
{
    int8_t               pstate;
    uint8_t              flag;
    uint16_t             reserved;
    uint32_t             freq_khz;
} opal_pstate_data_t;


typedef struct __attribute__ ((packed))
{
    uint8_t              occ_state;
    uint8_t              dynamic_major_version;
    uint8_t              dynamic_minor_version;
    uint8_t              gpus_present;
    uint8_t              reserved[1];
    uint8_t              proc_throt_status;
    uint8_t              mem_throt_status;
    uint8_t              quick_power_drop;
    uint8_t              power_shift_ratio;
    uint8_t              power_cap_type;
    uint16_t             min_power_cap;
    uint16_t             max_power_cap;
    uint16_t             current_power_cap;
    uint16_t             soft_min_power_cap;
} opal_dynamic_t;

// This size must be a multiple of 128
typedef struct __attribute__ ((packed))
{
    opal_dynamic_t       dynamic;       // Dynamic OPAL parameters: 18B
    uint8_t              pad[110];      // Reserved dynamic space: 110B
} opal_dynamic_table_t __attribute__ ((aligned (128)));

#define PSTATE_ENTRIES 256    // number of generated PSTATES entries in OPAL table
#define DYNAMIC_MINOR_V_GPU_PRESENCE 1    // OPAL Dynamic minor version for GPU support

// This size must be a multiple of 128
typedef struct __attribute__ ((packed))
{
    opal_config_t        config;                  // Static OPAL config parameters: 8B
    uint8_t              reserved[16];            // Reserved static space: 16B
    opal_pstate_data_t   pstates[PSTATE_ENTRIES]; // Generated Pstates Table: 2048B
    uint8_t              max_pstate[24];          // Maximum Pstate with N active cores is max_pstate[N-1]: 24B
    uint8_t              pad[80];                 // Padding in reserved static space: 80B
} opal_static_table_t __attribute__ ((aligned (128)));


extern uint32_t    G_mhz_per_pstate;

// Per quad pstate
extern uint8_t     G_desired_pstate[MAXIMUM_QUADS];

extern opal_dynamic_table_t G_opal_dynamic_table;
extern opal_static_table_t G_opal_static_table;

// States for updating opal data in main memory
typedef enum
{
    OPAL_TABLE_UPDATE_IDLE = 0x00,            // No dynmaic table update in process
    OPAL_TABLE_UPDATE_DYNAMIC_COPY = 0x01,    // BCE scheduled to copy dynamic date to main memory
    OPAL_TABLE_UPDATE_NOTIFY_HOST = 0x02,     // BCE copy finished notify host
    OPAL_TABLE_UPDATE_BCE_FAIL = 0x03,        // BCE failed, retry
    OPAL_TABLE_UPDATE_CRITICAL_ERROR = 0x04,  // Critical BCE error, stop trying to update dynamic data
} OPAL_TABLE_UPDATE_STATE;

extern volatile uint8_t G_opal_table_update_state;

// Helper function to translate from Frequency to nearest Pstate
Pstate proc_freq2pstate(uint32_t i_freq_mhz);

// Helper function to translate from Pstate to nearest Frequency
uint32_t proc_pstate2freq(Pstate i_pstate);

// Helper function to determine if we are in HW Pstate mode
inline bool proc_is_hwpstate_enabled(void);

// Copy pstate data to opal table
void populate_opal_dynamic_data(void);

// Copy all opal static data to opal table
void populate_opal_static_data(void);

// Copy pstates sections of opal static data to opal table
void populate_opal_static_pstates_data(void);

// Copy config section of  opal static data to opal table
void populate_opal_static_config_data(void);

// Copy opal static/dynamic table to mainstore memory at OPAL_OFFSET_HOMER
void populate_opal_tbl_to_mem(opalDataType opal_data_type);

// Check if opal table needs update
void check_for_opal_updates(void);

// update dynamic opal data in SRAM & main memory
void update_dynamic_opal_data (void);

void proc_pstate_kvm_setup(void);

#endif
OpenPOWER on IntegriCloud