summaryrefslogtreecommitdiffstats
path: root/src/import/chips/p9/procedures/hwp/core/p9_thread_control.H
blob: 14821a5c03687ee5e7fd7d3fe2f5720236c144aa (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: import/chips/p9/procedures/hwp/core/p9_thread_control.H $     */
/*                                                                        */
/* OpenPOWER sbe Project                                                  */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2016                        */
/* [+] 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                                                     */
//------------------------------------------------------------------------------
// *! TITLE       : p9_thread_control
// *! DESCRIPTION : Core Thread start/stop/step/query/activate operations
// *!               Use to start (start or sreset) thread instruction execution,
// *!                 stop instruction execution, or single instruction step.
// *!               Also used to query the state of a thread.
//------------------------------------------------------------------------------

// *HWP HWP Owner: Nick Klazynski <dyem@us.ibm.com>
// *HWP FW Owner:  Thi Tran <thi@us.ibm.com>
// *HWP Team:  Quad
// *HWP Level: 2
// *HWP Consumed by: FSP:HB:HS

#ifndef _P9_THREAD_CONTROL_H_
#define _P9_THREAD_CONTROL_H_

#include <fapi2.H>
#include <return_code.H>
#include <error_scope.H>

#include "p9_quad_scom_addresses.H"

extern "C"
{

//------------------------------------------------------------------------------
// Constants
//------------------------------------------------------------------------------
    const uint8_t MAX_NUM_OF_THREADS = 4;

// THREAD_STATE bit definitions
    const uint64_t THREAD_STATE_RUNNING            = 0x8000000000000000ULL;
    const uint64_t THREAD_STATE_STOP               = 0x4000000000000000ULL;
    const uint64_t THREAD_STATE_QUIESCED           = 0x2000000000000000ULL;
    const uint64_t THREAD_STATE_MAINT              = 0x1000000000000000ULL;
    const uint64_t THREAD_STATE_ICT_EMPTY          = 0x0800000000000000ULL;
    const uint64_t THREAD_STATE_LSU_QUIESCED       = 0x0400000000000000ULL;
    const uint64_t THREAD_STATE_ISTEP_SUCCESS      = 0x0200000000000000ULL;
    const uint64_t THREAD_STATE_ISTEP_READY        = 0x0100000000000000ULL;

// A macro to wrap the warning check boiler plate
// If the action failed and i_warncheck is set add a trace and continue anyway
#define PTC_ASSERT_WARN( __conditional__, __warning__, __ffdc__, ... )  \
    if (! (__conditional__))                                            \
    {                                                                   \
        if (__warning__)                                                \
        {                                                               \
            FAPI_INF(__VA_ARGS__);                                      \
        }                                                               \
        else                                                            \
        {                                                               \
            (__ffdc__).execute();                                       \
            FAPI_ERR(__VA_ARGS__);                                      \
            goto fapi_try_exit;                                         \
        }                                                               \
    }                                                                   \


// ProcThreadControl input commands
// If you make this an enum, the compiler can
// check that a case statement has all the elements
// covered.
    enum ThreadCommands
    {
        PTC_CMD_SRESET            = 0,
        PTC_CMD_STEP              = 1,
        PTC_CMD_START             = 2,
        PTC_CMD_STOP              = 3,
        PTC_CMD_QUERY             = 4,
    };

    enum ThreadRasStatus
    {
        CORE_MAINT_MODE = 0,
        THREAD_QUIESCED = 1,
        ICT_EMPTY       = 2,
        LSU_QUIESCED    = 3,
        STEP_SUCCESS    = 4,
    };

    enum PTC_Constants
    {
        RAS_MODE_STEP_SHIFT       = 52,
        PTC_STEP_COMP_POLL_LIMIT  = 10,
    };

// Bit positions in the DIRECT_CONTROL register
    enum ThreadControl
    {
        CLEAR_MAINT      = 3,
        SRESET_REQUEST   = 4,
        CORE_STEP        = 5,
        CORE_START       = 6,
        CORE_STOP        = 7,
    };

/// @typedef p9_thread_control_FP_t
/// function pointer typedef definition for HWP call support
    typedef fapi2::ReturnCode (*p9_thread_control_FP_t) (
        const fapi2::Target<fapi2::TARGET_TYPE_CORE>&,
        const uint8_t, const ThreadCommands, const bool,
        fapi2::buffer<uint64_t>&, uint64_t&);

//--------------------------------------------------------------------------
/// @brief p9_thread_control: utility subroutine to control thread state
/// @param[in] i_target ex target
/// @param[in] i_threads fused thread bitset (0b00000000..0b11111111)
/// @param[in] i_command  one of
///               PTC_CMD_SRESET => initiate sreset thread command
///               PTC_CMD_START  => initiate start thread command
///               PTC_CMD_STOP   => initiate stop thread command
///               PTC_CMD_STEP   => initiate step thread command
///               PTC_CMD_QUERY  => query and return thread state
/// @param[in] i_warncheck convert pre/post checks errors to warnings
/// @return FAPI_RC_SUCCESS if operation was successful,
///         function-specific fail codes (see function definitions),
///         else error
//-------------------------------------------------------------------------
//fapi2::ReturnCode p9_thread_control(const fapi2::Target<fapi2::TARGET_TYPE_EX>& i_target,
//        const uint8_t i_threads, const ThreadCommands i_command,
//        const bool i_warncheck);

//--------------------------------------------------------------------------
/// @brief p9_thread_control: utility subroutine to control thread state
///
/// @param[in] i_target core target
/// @param[in] i_threads     Desired thread bit set, multiple thread settings
///                          are allowed.
///                             0b0000         No thread (No-op)
///                             0b1000         Thread 0
///                             0b0100         Thread 1
///                             0b0010         Thread 2
///                             0b0001         Thread 3
/// @param[in] i_command  one of
///               PTC_CMD_SRESET => initiate sreset thread command
///               PTC_CMD_START  => initiate start thread command
///               PTC_CMD_STOP   => initiate stop thread command
///               PTC_CMD_STEP   => initiate step thread command
///               PTC_CMD_QUERY  => query and return thread state
/// @param[in] i_warncheck convert pre/post checks errors to warnings
/// @param[out] o_rasStatusReg  Complete RAS status reg 64-bit buffer after
///                             executing command.
/// @param[out] o_state Thread state, only valid for PTC_CMD_QUERY command.
///                    See p9_thread_control.H for THREAD_STATE bit definitions.
///
/// @return FAPI_RC_SUCCESS if operation was successful,
///         function-specific fail codes (see function definitions),
///         else error
//--------------------------------------------------------------------------
    fapi2::ReturnCode p9_thread_control(const fapi2::Target<fapi2::TARGET_TYPE_CORE>& i_target,
                                        const uint8_t i_threads, const ThreadCommands i_command,
                                        const bool i_warncheck,
                                        fapi2::buffer<uint64_t>& o_rasStatusReg,
                                        uint64_t& o_state);

} // extern

#endif // _P9_THREAD_CONTROL_H_
OpenPOWER on IntegriCloud