summaryrefslogtreecommitdiffstats
path: root/src/include/kernel/cpumgr.H
blob: 23207bf11c17d818172fe159d0f0497fe40f6f6f (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/include/kernel/cpumgr.H $                                 */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2010,2013              */
/*                                                                        */
/* p1                                                                     */
/*                                                                        */
/* Object Code Only (OCO) source materials                                */
/* Licensed Internal Code Source Materials                                */
/* IBM HostBoot Licensed Internal Code                                    */
/*                                                                        */
/* The source code for this program is not published or otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* Origin: 30                                                             */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
#ifndef __KERNEL_CPUMGR_H
#define __KERNEL_CPUMGR_H

#include <kernel/types.h>
#include <kernel/cpu.H>
#include <kernel/barrier.H>
#include <kernel/idebug.H>

class CpuManager
{
    public:
        enum
        {
            CPU_PERIODIC_CHECK_MEMORY = 128,    // Is this even needed anymore?
            CPU_PERIODIC_FLUSH_PAGETABLE = 256,
            CPU_PERIODIC_DEFRAG = 949,  // TODO Any bigger not currently hit
        };

        /** @fn getCurrentCPU
         *  Returns a pointer to the current CPU structure by using the
         *  task structure in SPRG3.
         */
        static cpu_t* getCurrentCPU()
        {
            size_t pir = getPIR();
            return cv_cpus[pir / KERNEL_MAX_SUPPORTED_CPUS_PER_NODE]
                          [pir % KERNEL_MAX_SUPPORTED_CPUS_PER_NODE];
        }
        static cpu_t* getCpu(size_t i)
        {
            cpu_t** c = cv_cpus[i / KERNEL_MAX_SUPPORTED_CPUS_PER_NODE];

            if (NULL == c)
            {
                return NULL;
            }
            else
            {
                return c[i % KERNEL_MAX_SUPPORTED_CPUS_PER_NODE];
            }
        }

        /** @brief Return pointer to master CPU object.
        */
        static cpu_t* getMasterCPU();

        static void init();
        static void init_slave_smp(cpu_t*);

        /** @fn requestShutdown
         *  Requests that all CPUs shutdown
         */
        static void requestShutdown(uint64_t i_status);

        /** @fn isShutdownRequested
         *  Returns if a shutdown of all CPUs was requested
         */
        static bool isShutdownRequested() { return cv_shutdown_requested; }

        /** @fn getShutdownStatus
         *  Returns the status code that needs to be posted during shutdown
         */
        static uint32_t getShutdownStatus() { return cv_shutdown_status; }

        /** @fn executePeriodics
         * Perform periodic actions
         * @param[in] cpu_t the CPU
         */
        static void executePeriodics(cpu_t * i_cpu);

        /** @fn activateCPU
         * Activate a cpu to show it is running
         * @param[in] cpu_t the CPU
         * @post Active flag on in cpu_t structure
         */
        static void activateCPU(cpu_t * i_cpu);

        /** @fn deactivateCPU
         *  Deactivate a cpu to show it is not running.
         *  @param[in] cpu_t the CPU
         *  @post Active flag is off in cpu_t structure.
         */
        static void deactivateCPU(cpu_t * i_cpu);

        /** @fn getCpuCount
         *  Return the number of active CPUs.
         */
        static size_t getCpuCount() { return cv_cpuSeq & 0xFFFFFFFF; }

        /** @fn getCpuSeqId
         *  Return the current CPU start sequence ID.
         */
        static size_t getCpuSeqId() { return cv_cpuSeq >> 32; }

        /** @fn getCpuCountAndSeqId
         *  Atomically retrieve both the current active CPU count and
         *  sequence ID.
         *
         */
        static void getCpuCountAndSeqId(uint32_t& o_count, uint32_t& o_seq)
        {
            uint64_t cpuSeq = cv_cpuSeq;
            o_count = cpuSeq & 0xFFFFFFFF;
            o_seq = cpuSeq >> 32;
        }

        /** @fn getThreadCount
         *  Return the number of HW threads for this CPU core type.
         */
        static size_t getThreadCount();

        /** @fn startCore
         *  Create structures to support a core activating and start the core.
         *
         *  @param[in] pir - PIR value of first thread in core.
         *  @param[in] i_threads - Bitstring of threads to enable (left-justified).
         */
        static int startCore(uint64_t pir,uint64_t i_threads);


        /** @fn forceMemoryPeriodic()
         * Force the memory free / coalesce operations to be performed on the
         * next "periodic" interval.
         */
        static void forceMemoryPeriodic();


        /** @fn critAssert()
         * Functional call to force terminate immediate on all threads
         * @param[in] i_failAddr - Address from where the assert was called
         */
        static void critAssert(uint64_t i_failAddr);

        /** Desired value for MSR after wakeup.
         *
         *  bit 0 - 64 bit mode.
         *  bit 3 - Hypervisor mode.
         *  bit 51 - Machine-check enable
         */
        static const uint64_t WAKEUP_MSR_VALUE =    0x9000000000001000;

        /** Desired value for LPCR after wakeup.
         *
         *  bit 49 - Wake-up from external interrupt.
         *  bit 50 - Wake-up from decrementer.
         *  bit 51 - Wake-up from machine check.
         *  bit 60 - LPES(0) = 1 (see ISA).
         *  bit 61 - LPES(1) = 0 (P8 RFC02204 forces to 0)
         */
        static const uint64_t WAKEUP_LPCR_VALUE =   0x0000000000007008;

        /** Desired value for RPR after wakeup.
         *
         *      Priority     Us    PHYP
         *      Very Low      0      0
         *      Low           1      1    <--- hostboot "low"
         *      Med Low       3      3
         *      Med          32      7    <--- hostboot "high"
         *      Med High     33     15
         *      High         34     31
         *      Very High    63     63
         */
        static const uint64_t WAKEUP_RPR_VALUE =    0x0001032021223F;

    protected:
        CpuManager();
        ~CpuManager() {}

        /** @fn startCPU
         *  Starts the requested CPU. Default of -1 implies current CPU.
         */
        void startCPU(ssize_t i = -1);
        void startSlaveCPU(cpu_t*);

    private:
        /** Per-CPU kernel structures.
         *
         *  There is one entry per hardware thread and they are stored as
         *  a two dimensional array of (cpu_t*)s: cv_cpus[node][thread]
         *
         *  This needs to be a global variable rather than an instance
         *  variable of a singleton because it is needed within the kernel
         *  assembly code for interrupt / exception handling.  For instance,
         *  when secondary CPUs start they need to find their own stack from
         *  these structures.  Any changes to this structure needs to be
         *  kept in sync with the assembly code (ex. start.S).
         */
        static cpu_t** cv_cpus[KERNEL_MAX_SUPPORTED_NODES];


            /** Number of active CPUs.
             *  Stored as "(seqID << 32) | cpus"
             */
        static uint64_t cv_cpuSeq;

        static bool cv_forcedMemPeriodic;       //!<  force free / coalesce.

        // If a shutdown of all CPUs is requested
        static bool cv_shutdown_requested;

        // The status code that needs to be posted during shutdown
        static uint64_t cv_shutdown_status;

        static InteractiveDebug cv_interactive_debug;

        /** Timebase of the master the last time a CPU was started.
         *
         *  This is used when slave CPUs activate to determine if the
         *  timebases need to be synchronized.
         */
        uint64_t iv_lastStartTimebase;

};

#endif
OpenPOWER on IntegriCloud