summaryrefslogtreecommitdiffstats
path: root/src/include/usr/fapi2/attribute_service.H
blob: f21020610466c123055caad7070a3e6102d8edea (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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/include/usr/fapi2/attribute_service.H $                   */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2017                        */
/* [+] 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                                                     */
///
/// @brief Defines the PLAT attribute access macros and the functions that
///        access attributes for FAPI2
///
/// Note that platform code must provide the code.
///

#ifndef ATTRIBUTESERVICE_H_
#define ATTRIBUTESERVICE_H_

//******************************************************************************
// Includes
//******************************************************************************

#include <stdint.h>
#include <return_code.H>
#include <target.H>
#include <target_types.H>

#include <plat_attribute_service.H>
#include <fapi2_attribute_service.H>
#include <targeting/common/attributes.H>
#include <fapi2platattrmacros.H>

#include <devicefw/driverif.H>
#include <plat_attr_override_sync.H>
#include <vpd/spdenums.H>

//******************************************************************************
// Interface
//******************************************************************************

namespace fapi2
{

namespace platAttrSvc
{

///
/// @brief Gets the TARGETING object for the input FAPI target
///
/// @param[in] i_pFapiTarget   FAPI2 Target reference
/// @param[o]  o_pTarget       Output TARGETING object
/// @param[in] i_expectedType  Expecting TARGETING object type
/// @return errlHndl_t
///
errlHndl_t getTargetingTarget(const Target<TARGET_TYPE_ALL>& i_pFapiTarget,
                   TARGETING::Target* & o_pTarget,
                   const TARGETING::TYPE i_expectedType = TARGETING::TYPE_NA);

///
/// @brief Helper function for getTargetingAttr, this function is a friend of
///        TARGETING::Target so it can call _tryGetAttr
///
///
/// @param[in] i_pTargTarget Targeting Target reference
/// @param[in] i_targAttrId  TARGETING Attribute ID
/// @param[in] i_attrSize    Size of attribute in bytes
/// @param[in] o_pAttr       Pointer to attribute where value is copied to
/// @return                  boolean describing if it was successful
bool getTargetingAttrHelper(TARGETING::Target * l_pTargTarget,
                            const TARGETING::ATTRIBUTE_ID i_targAttrId,
                            const uint32_t i_attrSize, void * o_pAttr);

///
/// @brief Gets a Targeting attribute, this is called by the macro that maps a
///        FAPI Attribute get to a TARGETING attribute and should not be called
///        directly
///
/// @param[in] i_pFapiTarget FAPI2 Target reference
/// @param[in] i_targAttrId  TARGETING Attribute ID
/// @param[in] i_attrSize    Size of attribute in bytes
/// @param[in] o_pAttr       Pointer to attribute where value is copied to
/// @return fapi2::ReturnCode. FAPI2_RC_SUCCESS if success, else error code.
///
ReturnCode getTargetingAttr(const Target<TARGET_TYPE_ALL,
                                        plat_target_handle_t >& i_pFapiTarget,
                            const TARGETING::ATTRIBUTE_ID i_targAttrId,
                            const uint32_t i_attrSize,
                            void * o_pAttr);

///
/// @brief Helper function for setTargetingAttr, this function is a friend of
///        TARGETING::Target so it can call _trySetAttr
///
///
/// @param[in] i_pTargTarget Targeting Target reference
/// @param[in] i_targAttrId  TARGETING Attribute ID
/// @param[in] i_attrSize    Size of attribute in bytes
/// @param[in] o_pAttr       Pointer to attribute where value is copied to
/// @return                  boolean describing if it was successful
///
bool setTargetingAttrHelper(TARGETING::Target * l_pTargTarget,
                            const TARGETING::ATTRIBUTE_ID i_targAttrId,
                            const uint32_t i_attrSize,
                            void * o_pAttr);

///
/// @brief Sets a Targeting attribute, this is called by the macro that maps a
///        FAPI Attribute set to a FAPI2 TARGETING attribute and should not be
///        called directly
///
/// @param[in] i_pFapiTarget FAPI2 Target reference
/// @param[in] i_targAttrId  TARGETING Attribute ID
/// @param[in] i_attrSize    Size of attribute in bytes
/// @param[in] i_pAttr       Pointer to attribute where value is retrieved from
/// @return fapi2::ReturnCode. FAPI2_RC_SUCCESS if success, else error code.
///
ReturnCode setTargetingAttr(const Target<TARGET_TYPE_ALL>& i_pFapiTarget,
                            const TARGETING::ATTRIBUTE_ID i_targAttrId,
                            const uint32_t i_attrSize,
                            void * i_pAttr);

///
/// @brief This function is called by the FAPI_ATTR_GET macro when accessing
/// an attribute where zero needs to be returned. The use-case is for attributes
/// that exist solely for overriding
///
/// @param[out] o_data Pointer to user's attribute variable
/// @param[in]  i_len  Size of o_data
/// @return fapi2::ReturnCode. FAPI2_RC_SUCCESS if success, else error code.
///
inline ReturnCode platGetZeroAttrData(void * o_data,
                                          size_t i_len)
{
    memset(o_data, 0, i_len);
    return fapi2::FAPI2_RC_SUCCESS;
}


///
/// @brief This function is called by the FAPI_ATTR_GET macro when getting
/// ATTR_NAME. It should not be called directly
///
/// @param[in]  i_pFapiTarget FAPI2 Target reference
/// @param[out] o_name        Output Name (from enum ATTR_NAME_Enum)
/// @return fapi2::ReturnCode. FAPI2_RC_SUCCESS if success, else error code.
///
ReturnCode platGetTargetName(const Target<TARGET_TYPE_ALL>& i_pFapiTarget,
                                 uint8_t & o_name);

///
/// @brief This function is called by the FAPI_ATTR_GET macro when getting
/// ATTR_FUNCTIONAL. It should not be called directly
///
/// @param[in]  i_pFapiTarget    FAPI2 Target reference
/// @param[out] o_functional     1 = functional, else 0
/// @return fapi2::ReturnCode. FAPI2_RC_SUCCESS if success, else error code.
///
ReturnCode platGetFunctional(const Target<TARGET_TYPE_ALL>& i_pFapiTarget,
                                  uint8_t & o_functional);

///
/// @brief This function is called by the FAPI_ATTR_GET macro when getting
/// ATTR_POS. It should not be called directly
///
/// This is needed because the HWPF attribute is a uint32_t and the Hostboot
/// attribute is a uint16_t so a direct map will not work
///
/// @param[in]  i_pFapiTarget FAPI2 Target reference
/// @param[out] o_pos         Output Posititon
/// @return fapi2::ReturnCode. FAPI2_RC_SUCCESS if success, else error code.
///
ReturnCode platGetTargetPos(const Target<TARGET_TYPE_ALL>& i_pFapiTarget,
                                 uint32_t & o_pos);


///
/// @brief This function is called by the FAPI_ATTR_GET macro when getting
/// ATTR_FUSED_CORE_MODE. It should not be called directly
///
///
/// @param[out] o_isFused         0 if not fused
/// @return ReturnCode           Always FAPI2_RC_SUCCESS, this cannot fail
///                              if a toplevel target cannot be found then
///                              an assert triggers in the platform call
///
ReturnCode platGetFusedCoreMode(uint8_t & o_isFused);

///
/// @brief This function is called by the FAPI_ATTR_GET macro when getting
/// ATTR_POUNDV_BUCKET_DATA. It should not be called directly
///
///
/// @param[in]  i_fapiTarget     FAPI2 Target reference
///                                Don't need to check the type here, get macro
///                                does it for us, thus use the all type to
///                                allow streamlined dump of ATTR
/// @param[out] o_pos            Output pound v bucket data
/// @return ReturnCode           Always FAPI2_RC_SUCCESS, this cannot fail
///                              if a toplevel target cannot be found then
///                              an assert triggers in the platform call
///
ReturnCode platGetPoundVBucketData(const Target<TARGET_TYPE_ALL>& i_fapiTarget,
                                  uint8_t * o_poundVData);

///
/// @brief This function is called by the FAPI_ATTR_GET macro when getting
/// ATTR_POUNDW_BUCKET_DATA. It should not be called directly
///
///
/// @param[in]  i_fapiTarget     FAPI2 Target reference
///                                Don't need to check the type here, get macro
///                                does it for us, thus use the all type to
///                                allow streamlined dump of ATTR
/// @param[out] o_pos            Output pound w bucket data
/// @return ReturnCode           Always FAPI2_RC_SUCCESS, this cannot fail
///                              if a toplevel target cannot be found then
///                              an assert triggers in the platform call
///
ReturnCode platGetPoundWBucketData(const Target<TARGET_TYPE_ALL>& i_fapiTarget,
                                  uint8_t * o_poundWData);

///
/// @brief This function is called by the FAPI_ATTR_GET macro when getting
/// ATTR_WOF_TABLE_DATA. It should not be called directly
///
///
/// @param[in]  i_fapiTarget     FAPI2 Target reference
///                                Currently system target and unused,
///                                Could change to proc target later.
///                                Don't need to check the type here, get macro
///                                does it for us, thus use the all type to
///                                allow streamlined dump of ATTR
/// @param[out] o_pos            Output WOF table data
/// @return ReturnCode           Always FAPI2_RC_SUCCESS, this cannot fail
///                              if a toplevel target cannot be found then
///                              an assert triggers in the platform call
///
ReturnCode platGetWOFTableData(const Target<TARGET_TYPE_ALL>& i_fapiTarget,
                               uint8_t * o_wofTableData);

///
/// @brief This function is called by the FAPI_ATTR_GET macro when getting
/// the Bad DQ Bitmap attribute. It should not be called directly.
///
/// @param[in]  i_fapiTarget  DIMM target pointer
/// @param[out] o_data        Bad DIMM DQ Bitmap
/// @return     ReturnCode.   Zero on success, else platform specified error
///
ReturnCode fapiAttrGetBadDqBitmap( const Target<TARGET_TYPE_ALL>& i_fapiTarget,
                                   ATTR_BAD_DQ_BITMAP_Type (&o_data) );

///
/// @brief This function is called by the FAPI_ATTR_SET macro when setting
/// the Bad DQ Bitmap attribute. It should not be called directly.
///
/// @param[in]  i_fapiTarget  DIMM target pointer
/// @param[in]  i_data        Bad DIMM DQ Bitmap
/// @return     ReturnCode.   Zero on success, else platform specified error
///
ReturnCode fapiAttrSetBadDqBitmap( const Target<TARGET_TYPE_ALL>& i_fapiTarget,
                                   ATTR_BAD_DQ_BITMAP_Type (&i_data) );

/// @brief This function is called by the FAPI_ATTR_GET macro when getting
/// the SECURITY_MODE attribute. It should not be called directly.
///
/// @param[out] o_securityMode   Provides the attribute contents to the caller
/// @return ReturnCode           Always FAPI2_RC_SUCCESS, this cannot fail.
///                              If a toplevel target cannot be found then
///                              an assert triggers in the platform call
///
ReturnCode platGetSecurityMode(uint8_t & o_securityMode);

/// @brief This function is called by the FAPI_ATTR_SET macro when setting
/// the SECURITY_MODE attribute. It should not be called directly. There are no
/// parameters. This is intentional as setting this attribute is not supported
/// from FAPI or FAPI runtime code. A FAPI INFO trace will be printed explaining
/// this.
///
/// @return ReturnCode           Always FAPI2_RC_SUCCESS, this cannot fail.
ReturnCode platSetSecurityMode();

// -----------------------------------------------------------------------------
// End TODO: End to be supported functions
// -----------------------------------------------------------------------------

} // namespace platAttrSvc

} // namespace fapi2

/**
 *  @brief Macro that directly maps a FAPI_ATTR_GET to a Targeting attr get
 *
 *  Firstly there is a compile time check that the user's VAL variable matches
 *  the Targeting attribute type, this is optimized out, then there is a
 *  single function call
 */
#define FAPI2_PLAT_ATTR_SVC_GETMACRO_DIRECT(ID, PTARGET, VAL) \
platAttrSvc::getTargetingAttr(PTARGET, (const TARGETING::ATTRIBUTE_ID)\
fapiToTargeting::ID, sizeof(VAL), &(VAL))


/**
 *  @brief Macro that directly maps a FAPI_ATTR_SET to a Targeting attr set
 *
 *  Firstly there is a compile time check that the user's VAL variable matches
 *  the Targeting attribute type, this is optimized out, then there is a
 *  single function call
 */
#define FAPI2_PLAT_ATTR_SVC_SETMACRO_DIRECT(ID, PTARGET, VAL) \
platAttrSvc::setTargetingAttr(PTARGET, (const TARGETING::ATTRIBUTE_ID)\
fapiToTargeting::ID, sizeof(VAL), &(VAL))



//------------------------------------------------------------------------------
// MACRO to route ATTR_NAME access to the correct Hostboot function
//------------------------------------------------------------------------------
#define ATTR_NAME_GETMACRO(ID, PTARGET, VAL) \
    AttrOverrideSync::getAttrOverrideFunc(ID, PTARGET, &VAL)\
    ? fapi2::ReturnCode() : \
    fapi2::platAttrSvc::platGetTargetName(PTARGET, VAL)

//------------------------------------------------------------------------------
// MACRO to route ATTR_FUNCTIONAL access to the correct Hostboot function
//------------------------------------------------------------------------------
#define ATTR_FUNCTIONAL_GETMACRO(ID, PTARGET, VAL) \
    AttrOverrideSync::getAttrOverrideFunc(ID, PTARGET, &VAL)\
    ? fapi2::ReturnCode() : \
    fapi2::platAttrSvc::platGetFunctional(PTARGET, VAL)

//------------------------------------------------------------------------------
// MACRO to route ATTR_POS access to the correct Hostboot function
//------------------------------------------------------------------------------
#define ATTR_POS_GETMACRO(ID, PTARGET, VAL) \
    AttrOverrideSync::getAttrOverrideFunc(ID, PTARGET, &VAL)\
    ? fapi2::ReturnCode() : \
    fapi2::platAttrSvc::platGetTargetPos(PTARGET, VAL)

//------------------------------------------------------------------------------
// MACRO to route ATTR_FUSED_CORE access to the correct Hostboot function
//------------------------------------------------------------------------------
#define ATTR_FUSED_CORE_MODE_GETMACRO(ID, PTARGET, VAL) \
    AttrOverrideSync::getAttrOverrideFunc(ID, PTARGET, &VAL)\
    ? fapi2::ReturnCode() : \
    fapi2::platAttrSvc::platGetFusedCoreMode(VAL)

//------------------------------------------------------------------------------
// MACRO to route ATTR_POUNDV_BUCKET_DATA access to the correct HB function
//------------------------------------------------------------------------------
#define ATTR_POUNDV_BUCKET_DATA_GETMACRO(ID, TARGET, VAL) \
    AttrOverrideSync::getAttrOverrideFunc(ID, TARGET, &VAL)\
    ? fapi2::ReturnCode() : \
    fapi2::platAttrSvc::platGetPoundVBucketData(TARGET,VAL)

//------------------------------------------------------------------------------
// MACRO to route ATTR_POUNDW_BUCKET_DATA access to the correct HB function
//------------------------------------------------------------------------------
#define ATTR_POUNDW_BUCKET_DATA_GETMACRO(ID, TARGET, VAL) \
    AttrOverrideSync::getAttrOverrideFunc(ID, TARGET, &VAL)\
    ? fapi2::ReturnCode() : \
    fapi2::platAttrSvc::platGetPoundWBucketData(TARGET,VAL)

//------------------------------------------------------------------------------
// MACRO to route ATTR_WOF_TABLE_DATA access to the correct HB function
//------------------------------------------------------------------------------
#define ATTR_WOF_TABLE_DATA_GETMACRO(ID, TARGET, VAL) \
    AttrOverrideSync::getAttrOverrideFunc(ID, TARGET, &VAL)\
    ? fapi2::ReturnCode() : \
    fapi2::platAttrSvc::platGetWOFTableData(TARGET,VAL)

//------------------------------------------------------------------------------
// MACRO to route ATTR_BAD_DQ_BITMAP read access to the correct HB function
//------------------------------------------------------------------------------
#define ATTR_BAD_DQ_BITMAP_GETMACRO(ID, TARGET, VAL) \
    AttrOverrideSync::getAttrOverrideFunc(ID, TARGET, &VAL)\
    ? fapi2::ReturnCode() : \
    fapi2::platAttrSvc::fapiAttrGetBadDqBitmap(TARGET, VAL)

//------------------------------------------------------------------------------
// MACRO to route ATTR_BAD_DQ_BITMAP write access to the correct HB function
//------------------------------------------------------------------------------
#define ATTR_BAD_DQ_BITMAP_SETMACRO(ID, TARGET, VAL) \
    AttrOverrideSync::getAttrOverrideFunc(ID, TARGET, &VAL)\
    ? fapi2::ReturnCode() : \
    fapi2::platAttrSvc::fapiAttrSetBadDqBitmap(TARGET, VAL)

//------------------------------------------------------------------------------
// MACRO to route ATTR_SECURITY_MODE access to the correct HB function
//------------------------------------------------------------------------------
#define ATTR_SECURITY_MODE_GETMACRO(ID, TARGET, VAL) \
    AttrOverrideSync::getAttrOverrideFunc(ID, TARGET, &VAL)\
    ? fapi2::ReturnCode() : \
    fapi2::platAttrSvc::platGetSecurityMode(VAL)
#define ATTR_SECURITY_MODE_SETMACRO(ID, TARGET, VAL) \
    AttrOverrideSync::getAttrOverrideFunc(ID, TARGET, &VAL)\
    ? fapi2::ReturnCode() : \
    fapi2::platAttrSvc::platSetSecurityMode()

#endif // ATTRIBUTESERVICE_H_
OpenPOWER on IntegriCloud