summaryrefslogtreecommitdiffstats
path: root/src/occ_gpe1/gpe1_memory_power_control.c
blob: a988d48f1be7a152a82dcc352b2733a9c3b8d17b (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
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/occ_gpe1/gpe1_memory_power_control.c $                    */
/*                                                                        */
/* OpenPOWER OnChipController Project                                     */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,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                                                     */

#include "pk.h"
#include "ppe42_scom.h"
#include "ipc_api.h"
#include "ipc_async_cmd.h"
#include "gpe_err.h"
#include "gpe_util.h"
#include "mem_structs.h"
#include "gpe1.h"
#include "mca_addresses.h"
#include "gpe1_memory_power_control.h"

/*
 * Function Specifications:
 *
 * Name: gpe_mem_power_control
 *
 * Description:  memory power control code on the GPE
 *
 * Inputs:       cmd is a pointer to IPC msg's cmd and cmd_data struct
 *
 * Outputs:      error: sets rc, address, and ffdc in the cmd_data's
 *                      GpeErrorStruct
 *
 * End Function Specification
 */
void gpe_mem_power_control(ipc_msg_t* cmd, void* arg)
{
    // Note: arg was set to 0 in ipc func table (ipc_func_tables.c), so don't use it.
    // the ipc arguments passed through the ipc_msg_t structure, has a pointer
    // to the mem_power_control_args_t struct.

    int      rc;
    uint64_t pcrRegValue;      // holds Power Control Register0
    uint64_t strRegValue;      // holds STR0 SCOM register value
    ipc_async_cmd_t *async_cmd = (ipc_async_cmd_t*)cmd;
    mem_power_control_args_t *args = (mem_power_control_args_t*)async_cmd->cmd_data;

    uint8_t mc = args->mc, port = args->port;  // memory controller pair and port

    args->error.error = 0;
    args->error.ffdc = 0;

    do
    {
        // Read Power Control Register 0 SCOM
        rc = getscom_abs(POWER_CTRL_REG0(mc,port), &pcrRegValue);

        if(rc)
        {
            PK_TRACE("gpe_mem_power_control: Power Control Register 0 read fails"
                     "MC#|Port:0x%08x, Address:0x%08x, rc:0x%08x",
                     (uint32_t)((mc << 16) | port),
                     POWER_CTRL_REG0(mc,port), rc);

            gpe_set_ffdc(&(args->error), POWER_CTRL_REG0(mc,port),
                         GPE_RC_SCOM_GET_FAILED, rc);
            break;
        }

        // Read STR0 SCOM Register
        rc = getscom_abs(STR_REG0(mc,port), &strRegValue);

        if(rc)
        {
            PK_TRACE("gpe_mem_power_control: STR Register 0 read fails"
                     "MC#|Port:0x%08x, Address:0x%08x, rc:0x%08x",
                     (uint32_t)((mc << 16) | port),
                     STR_REG0(mc,port), rc);

            gpe_set_ffdc(&(args->error), STR_REG0(mc,port),
                         GPE_RC_SCOM_GET_FAILED, rc);
            break;
        }

        switch(args->mem_pwr_ctl)
        {
            // MEM_PWR_CTL_OFF: clears the following memory control bits:
            //           -  master_enable (PCR0(2)),
            //           -  power_down_enable (PCR0(22)),
            //           -  STR_enable (STR(0)),
            //           -  disable_memory_clocks (STR(1)).
        case MEM_PWR_CTL_OFF:
            pcrRegValue = CLR_2BITS(pcrRegValue, PCR0_MASTER_ENABLE_BIT, PCR0_POWERDOWN_ENABLE_BIT);
            strRegValue = CLR_2BITS(strRegValue, STR0_STR_ENABLE_BIT, STR0_DISABLE_MEMORY_CLOCKS_BIT);
            break;

            // MEM_PWR_CTL_POWER_DOWN:
            //         sets:
            //           -  master_enable (PCR0(2)),
            //           -  power_down_enable (PCR0(22)),
            //         and clears:
            //           -  STR_enable (STR(0)),
            //           -  disable_memory_clocks (STR(1)).
        case MEM_PWR_CTL_POWER_DOWN:
            pcrRegValue = SET_2BITS(pcrRegValue, PCR0_MASTER_ENABLE_BIT, PCR0_POWERDOWN_ENABLE_BIT);

            strRegValue = CLR_2BITS(strRegValue, STR0_STR_ENABLE_BIT, STR0_DISABLE_MEMORY_CLOCKS_BIT);
            break;

            // MEM_PWR_CTL_PD_AND_STR:
            //         sets:
            //           -  master_enable (PCR0(2)),
            //           -  power_down_enable (PCR0(22)),
            //           -  STR_enable (STR(0)),
            //         and clears:
            //           -  disable_memory_clocks (STR(1)).
        case MEM_PWR_CTL_PD_AND_STR:
        // HW bug with disabling memory clock, treat PD_AND_STR_CLK_STOP same as PD_AND_STR
        // It is unknown if this will ever be fixed in a future RIT
        case MEM_PWR_CTL_PD_AND_STR_CLK_STOP:
            pcrRegValue = SET_2BITS(pcrRegValue, PCR0_MASTER_ENABLE_BIT, PCR0_POWERDOWN_ENABLE_BIT);
            strRegValue = SET_BIT(strRegValue, STR0_STR_ENABLE_BIT);

            strRegValue = CLR_BIT(strRegValue, STR0_DISABLE_MEMORY_CLOCKS_BIT);
            break;

            // MEM_PWR_CTL_PD_AND_STR_CLK_STOP: set the following memory power control bits
            //           -  master_enable (PCR0(2)),
            //           -  power_down_enable (PCR0(22)),
            //           -  STR_enable (STR(0)),
            //           -  disable_memory_clocks (STR(1)).
//        case MEM_PWR_CTL_PD_AND_STR_CLK_STOP:
//            pcrRegValue = SET_2BITS(pcrRegValue, PCR0_MASTER_ENABLE_BIT, PCR0_POWERDOWN_ENABLE_BIT);
//            strRegValue = SET_2BITS(strRegValue, STR0_STR_ENABLE_BIT, STR0_DISABLE_MEMORY_CLOCKS_BIT);
//            break;

        default:
            PK_TRACE("gpe_mem_power_control: Invalid memory power control command:0x%d",
                     args->mem_pwr_ctl);
            rc = GPE_RC_INVALID_MEM_PWR_CTL;

            gpe_set_ffdc(&(args->error), 0, rc, args->mem_pwr_ctl);
            break;
        }
        if(rc)
        {
            break;
        }

        // Write Modified Power Control Register 0 SCOM
        rc = putscom_abs(POWER_CTRL_REG0(mc,port), pcrRegValue);

        if(rc)
        {
            PK_TRACE("gpe_mem_power_control: Power Control Register 0 write fails"
                     "MC#|Port:0x%08x, Address:0x%08x, rc:0x%08x",
                     (uint32_t)((mc << 16) | port),
                     POWER_CTRL_REG0(mc,port), rc);

            gpe_set_ffdc(&(args->error), POWER_CTRL_REG0(mc,port),
                         GPE_RC_SCOM_PUT_FAILED, rc);
            break;
        }

        // Write Modified STR0 SCOM Register
        rc = putscom_abs(STR_REG0(mc,port), strRegValue);

        if(rc)
        {
            PK_TRACE("gpe_mem_power_control: STR Register 0 write fails"
                     "MC#|Port:0x%08x, Address:0x%08x, rc:0x%08x",
                     (uint32_t)((mc << 16) | port),
                     STR_REG0(mc,port), rc);

            gpe_set_ffdc(&(args->error), STR_REG0(mc,port),
                         GPE_RC_SCOM_PUT_FAILED, rc);
        }
    } while(0);


    if(rc)
    {
        GPE1_DIMM_DBG("gpe_mem_power_control: Failed to apply memory power control");
    }
    else
    {
        GPE1_DIMM_DBG("gpe_mem_power_control: Memory Power Control Register successfully written"
                      "mc|port#:0x%04x, PCR0:0x%08x, STR0:0x%08x",
                      (uint16_t)((mc << 8) | port),
                      pcrRegValue, strRegValue);
    }


    // send back a response, IPC success even if ffdc/rc are non zeros
    rc = ipc_send_rsp(cmd, IPC_RC_SUCCESS);
    if(rc)
    {
        PK_TRACE("gpe_mem_power_control: Failed to send response back. Halting GPE1", rc);
        gpe_set_ffdc(&(args->error), 0x00, GPE_RC_IPC_SEND_FAILED, rc);
        pk_halt();
    }

}
OpenPOWER on IntegriCloud