summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/hwp/build_winkle_images/proc_pba_bar_config/proc_pba_bar_config.C
blob: c12affb5892f782f0e9089d220cb690435d4dfba (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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/hwpf/hwp/build_winkle_images/proc_pba_bar_config/proc_pba_bar_config.C $ */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2012                   */
/*                                                                        */
/* 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                                                     */

// $Id: proc_pba_bar_config.C,v 1.8 2012/08/13 13:04:20 stillgs Exp $
// $Source: /afs/awd/projects/eclipz/KnowledgeBase/.cvsroot/eclipz/chips/p8/working/procedures/ipl/fapi/proc_pba_bar_config.C,v $
//------------------------------------------------------------------------------
// *! (C) Copyright International Business Machines Corp. 2011
// *! All Rights Reserved -- Property of IBM
// *! *** IBM Confidential ***
//------------------------------------------------------------------------------
// *! OWNER NAME: Klaus P. Gungl         Email: kgungl@de.ibm.com
// *!
// *!
/// \file proc_pba_bar_config.C
/// \brief Initialize PAB and PAB_MSK of PBA
// *!
// *! The purpose of this procedure is to set the PBA BAR, PBA BAR Mask and PBA scope value / registers
// *!
// *! Following proposals here: pass values for one set of pbabar, pass reference to structure for one set of pbabar, pass struct of struct containing
// *! all setup values
// *!
// *! High-level procedure flow:
// *!   parameter checking
// *!   set PBA_BAR
// *!   set PBA_BARMSK
// *!
// *! Procedure Prereq:
// *!   o System clocks are running
// *!
// *! list of changes
// *! 2011/11/22 all variables / passing calling parameters are uint64_t, cmd_scope is enum, MASK is not bitmask parameter but size
// *!            structure for init contain uint64_t only.
// *!
//------------------------------------------------------------------------------


// ----------------------------------------------------------------------
// Includes
// ----------------------------------------------------------------------
#include <fapi.H>
#include "p8_scom_addresses.H"
#include "proc_pba_init.H"
#include "proc_pba_bar_config.H"
#include "pba_firmware_register.H"
#include "proc_pm.H"


extern "C" {


using namespace fapi;

// ----------------------------------------------------------------------
// Constant definitions
// ----------------------------------------------------------------------

// for range checking            0x0123456701234567
#define BAR_ADDR_RANGECHECK_     0x0003FFFFFFF00000ull
#define BAR_ADDR_RANGECHECK_HIGH 0xFFFC000000000000ull
#define BAR_ADDR_RANGECHECK_LOW  0x00000000000FFFFFull
#define BAR_SIZE_RANGECHECK      0x000001FFFFF00000ull
#define BAR_SIZE_RANGECHECK_HIGH 0xFFFFFE0000000000ull
#define BAR_SIZE_RANGECHECK_LOW  0x00000000000FFFFFull

// ----------------------------------------------------------------------
// Global variables
// ----------------------------------------------------------------------

// ----------------------------------------------------------------------
// Prototypes
// ----------------------------------------------------------------------

// ----------------------------------------------------------------------
// Function definitions
// ----------------------------------------------------------------------

uint64_t PowerOf2Roundedup (uint64_t value);


// --------------------------------------------- proc_pba_bar_config ----
// function:
// initialize initialize a specific set of PBA_BAR (=cmd_scope and address), PBA_BARMSK (mask/size)
// pass values directly
//! init_pba_bar_ps
//! initialize a set of  PBA_BAR and PBA_BARMSK registers, calling parameters: reference to structure of initialization values
/*!
@param i_target the target
@param i_index specifies which set of BAR / BARMSK registers to set. [0..3]
@param i_pba_bar_addr PBA base address - 1MB grandularity
@param i_pba_bar_size PBA region size in MB;  if not a power of two value,
        the value will be rounded up to the next power of 2 for setting the
        hardware mask
@param i_pba_cmd_scope command scope according to pba spec
*/

fapi::ReturnCode
proc_pba_bar_config (const Target&  i_target,
                             uint32_t       i_index,
                             uint64_t       i_pba_bar_addr,
                             uint64_t       i_pba_bar_size,
                             uint64_t       i_pba_cmd_scope
                     )
{


    ecmdDataBufferBase  data(64);
    fapi::ReturnCode    l_rc;
    uint32_t            l_ecmdRc = 0;

    pba_barn_t          bar;
    pba_barmskn_t       barmask;

    uint64_t            work_size;

    FAPI_DBG("Called with index %x, address 0x%16llX, size 0x%16llX scope 0x%16llX",
                        i_index, i_pba_bar_addr, i_pba_bar_size, i_pba_cmd_scope);

    // check if pba_bar scope in range
    if ( i_pba_cmd_scope > PBA_CMD_SCOPE_FOREIGN1 )
    {
        FAPI_ERR("ERROR: PB Command Scope out of Range");
        FAPI_SET_HWP_ERROR(l_rc, RC_PROC_PBA_BAR_SCOPE_OUT_OF_RANGE);
        return l_rc;
    }

    // check if pba_addr amd pba_size are within range, high order bits checked, not low order!
    // this means if we need a check for "is this value on the correct boundary value => needs to be implemented
    if ( (BAR_ADDR_RANGECHECK_HIGH & i_pba_bar_addr) != 0x0ull)
    {
        FAPI_ERR("ERROR: Address out of Range");
        FAPI_SET_HWP_ERROR(l_rc, RC_PROC_PBA_ADDR_OUT_OF_RANGE);
        return l_rc;
    }
    if ( (i_pba_bar_size) == 0x0ull)
    {
        FAPI_ERR("ERROR: Size must be 1MB or greater");
        FAPI_SET_HWP_ERROR(l_rc, RC_PROC_PBA_BAR_MASK_OUT_OF_RANGE);  // \todo change xml!!!
        return l_rc;
    }

    // The PBA Mask indicates which bits from 23:43 (1MB grandularity) are
    // enabled to be passed from the OCI addresses.  Inverting this mask
    // indicates which address bits are going to come from the PBA BAR value.
    // The image address (the starting address) must match these post mask bits
    // to be resident in the range.
    //
    // Starting bit number: 64 bit Big Endian
    //                                          12223344
    //                                          60482604
    // region_inverted_mask = i_mem_mask ^ BAR_MASK_LIMIT;  // XOR


    // Check that the image address passed is within the memory region that
    // is also passed.
    //
    // The PBA Mask indicates which bits from 23:43 (1MB grandularity) are
    // enabled to be passed from the OCI addresses.  Inverting this mask
    // indicates which address bits are going to come from the PBA BAR value.
    // The image address (the starting address) must match these post mask bits
    // to be resident in the range.
    //
    // Starting bit number: 64 bit Big Endian
    //                                          12223344
    //                                          60482604
    // region_inverted_mask = i_mem_mask ^ BAR_MASK_LIMIT;  // XOR

    // Set bits 14:22 as these are unconditional address bits
    //region_inverted_mask = region_inverted_mask | BAR_ADDR_UNMASKED;
    //computed_image_address = region_inverted_mask && image_address;
    // Need to AND the address
    //if (computed_image_address != i_mem_bar )
    //{
    //    FAPI_ERR("SLW image address check failure. ");
    //    FAPI_SET_HWP_ERROR(rc, RC_PROCPM_POREBAR_IMAGE_ADDR_ERROR);
    //    return rc;
    //}



    // put the parameters into the correct fields
    bar.value=0;
    bar.fields.cmd_scope = i_pba_cmd_scope;
    bar.fields.addr = i_pba_bar_addr >> 20;

    FAPI_DBG("bar.fields   address  0x%16llX, scope  0x%16llX",
                        bar.fields.addr, bar.fields.cmd_scope);
    FAPI_DBG("bar.value             0x%16llX", bar.value);

     // Write the BAR
    l_ecmdRc |= data.setDoubleWord(0, bar.value);
    if (l_ecmdRc)
    {
       FAPI_ERR("Error (0x%x) setting up ecmdDataBufferBase", l_ecmdRc);
       l_rc.setEcmdError(l_ecmdRc);
       return l_rc;
    }

    FAPI_DBG("  PBA_BAR%x:  %16llX", i_index,  data.getDoubleWord(0));
    l_rc = fapiPutScom(i_target, PBA_BARs[i_index], data);
    if(l_rc)
    {
        FAPI_ERR("PBA_BAR Putscom failed");
        return l_rc;
    }

    // Compute and write the mask based on passed region size.

    // If the size is already a power of 2, then set the mask to that value - 1.
    // If the is not a power of 2, then set the mask the rounded up power of 2
    // value minus 1.

    work_size = PowerOf2Roundedup(i_pba_bar_size);
    FAPI_DBG("  i_pba_bar_size %16llu work_size:  %16llu", i_pba_bar_size, work_size);

    barmask.value=0;
    barmask.fields.mask = work_size-1;

    FAPI_DBG("bar.fields   mask  0x%16llX", barmask.fields.mask);


    // Write the MASK

    // The size is tranlated to a mask by:
    //  Shifting the s
    //
    //
    //

    l_ecmdRc |= data.setDoubleWord(0, barmask.value);
    if (l_ecmdRc)
    {
       FAPI_ERR("Error (0x%x) setting up ecmdDataBufferBase", l_ecmdRc);
       l_rc.setEcmdError(l_ecmdRc);
       return l_rc;
    }

    FAPI_DBG("  PBA_BARMSK%x:  %16llu", i_index,  data.getDoubleWord(0));
    l_rc = fapiPutScom(i_target, PBA_BARMSKs[i_index], data);
    if(l_rc)
    {
      FAPI_ERR("PBA_MASK Putscom failed");
      return l_rc;
    }

    return l_rc;
}

///-----------------------------------------------------------------------------
/// Determine if a number is a power of two or not
///-----------------------------------------------------------------------------
bool
isPowerOfTwo(uint64_t value)
{
    // if value ANDed with the value-1 is 0, then value is a power of 2.
    // if value is 0, this is considered not a power of 2 and will return false.

    return !(value & (value - 1));

}

///-----------------------------------------------------------------------------
/// Round up to next higher power of 2 (return value if it's already a power of
/// 2).
///-----------------------------------------------------------------------------
uint64_t
PowerOf2Roundedup (uint64_t value)
{
    if (value < 0)
        return 0;
    --value;
    value |= value >> 1;
    value |= value >> 2;
    value |= value >> 4;
    value |= value >> 8;
    value |= value >> 16;
    return value+1;
}


} //end extern C

OpenPOWER on IntegriCloud