<commit_before>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/pm/p9_pm_recovery_ffdc_defines.H $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2019                        */
/* [+] 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                                                     */
#ifndef __PM_RECOVERY_FFDC_DEFINES_
#define __PM_RECOVERY_FFDC_DEFINES_

#include <p9_hcd_memmap_base.H>
#include <endian.h>

#if( __BYTE_ORDER == __BIG_ENDIAN )
#define REV_2_BYTE(WORD) WORD
#else
#define REV_2_BYTE(WORD) \
    ( (((WORD) >> 8) & 0x00FF) | (((WORD) << 8) & 0xFF00) )
#endif

namespace p9_stop_recov_ffdc
{

/**
 * @brief   enumerates all the platforms involved with STOP Recovery.
 */
enum PmComplexPlatId
{
    PLAT_CME    =   0x01,
    PLAT_SGPE   =   0x02,
    PLAT_PGPE   =   0x03,
    PLAT_OCC    =   0x04,
    PLAT_PPM    =   0x05,
};

/**
 * @brief enumerates type of FFDC data
 */
enum FfdcDataType
{
    IMAGE_HEADER     =  0x01,
    DASH_BOARD_VAR   =  0x02,
    TRACES           =  0x03,
    INTERNAL_REG     =  0x04,
    SCOM_REG         =  0x05,
};

/**
 * @brief enumerates bit position used as validity mark of PPE FFDC sub-section.
 */

enum PpeFfdcValidStatus
{
    PPE_FFDC_INVALID        =   0x00,  //entire PPE FFDC is not valid
    PPE_DASHBOARD_VALID     =   0x01,  // PPE globals are valid
    PPE_IMAGE_HEADER_VALID  =   0x02,  // PPE image header is valid
    PPE_TRACE_VALID         =   0x04,  // PPE Traces are valid
    PPE_STATE_VALID         =   0x08,  // PPE XIRS, GPES and SPRs are valid
    PPE_INT_REG_VALID       =   0x10,  // PPE Int Regs are valid
    PPE_HALT_STATE_VALID    =   0x20,  // PPE Halt State Info is valid
    PPE_FFDC_ALL_VALID      =   0x3F,  // Entire PPE FFDC is valid
};

/**
 * @brief enumerates PPE's HALT conditions as inteprreted from XSR[0:3]
 */
enum PpeHaltCondition
{
    PPE_HALT_COND_NONE    = 0x00, // Not halted
    PPE_HALT_COND_BAD     = 0x08, // Halted, but cannot map source
    PPE_HALT_COND_XCR     = 0x09, // Halted via XCR
    PPE_HALT_COND_WDT     = 0x0A, // Halted via Watch Dog
    PPE_HALT_COND_NMI     = 0x0B, // Halted via unmaskable intr
    PPE_HALT_COND_DBG     = 0x0C, // Debug halt
    PPE_HALT_COND_DBCR    = 0x0D, // Halt via Debug Control Reg
    PPE_HALT_COND_EXT_HLT = 0x0E, // Ext halt_req input active
    PPE_HALT_COND_HW      = 0x0F, // Halted with a HW failure
    PPE_HALT_COND_UNKNOWN = 0xFF  // Could not read or interpret XSR
};

/**
 * @brief   models header of FFDC region of HOMER associated with a CME.
 */
struct __attribute__((packed)) PpeFfdcHeader
{
    uint32_t  iv_ppeMagicNumber;
    uint8_t   iv_ppeNumber;
    uint8_t   iv_headerSize;
    uint16_t  iv_sectionSize;
    uint8_t   iv_ffdcValid;
    uint8_t   iv_ppeHaltCondition;
    uint16_t  iv_dashBoardOffset;
    uint16_t  iv_sramHeaderOffset;
    uint16_t  iv_sprOffset;
    uint16_t  iv_intRegOffset;
    uint16_t  iv_offsetTraces;
    uint8_t   iv_reserve[4];
};

/**
 * @brief models Quad FFDC header.
 */
struct __attribute__((packed)) QuadFfdcHeader
{
    uint32_t iv_quadMagicWord;
    uint8_t  iv_quadInstance;
    uint8_t  iv_quadHeaderSize;
    uint16_t iv_sectionSize;
    uint16_t iv_offsetCppm0;
    uint16_t iv_offsetCppm1;
    uint16_t iv_offsetCppm2;
    uint16_t iv_offsetCppm3;
    uint16_t iv_offsetCme0;
    uint16_t iv_offsetCme1;
    uint16_t iv_offsetQppm;
    uint8_t  iv_reserve[2];
};

/**
 * @brief enumerates bit position used as validity mark of OCC FFDC sub-section.
 */
enum OccFfdcValidStatus
{
    OCC_FFDC_INVALID             =   0x00,  // None of the FFDC section is valid
    OCC_FFDC_TRACE_ERR_VALID     =   0x01,  // OCC ERR traces section valid
    OCC_FFDC_TRACE_IMP_VALID     =   0x02,  // OCC IMP traces section valid
    OCC_FFDC_TRACE_INF_VALID     =   0x04,  // OCC INF traces section valid
    OCC_FFDC_TRACE_SSX_VALID     =   0x08,  // OCC SSX trace section valid
    OCC_FFDC_TRACE_GPE0_VALID    =   0x10,  // OCC GPE0 Trace Section valid
    OCC_FFDC_TRACE_GPE1_VALID    =   0x20,  // OCC GPE1 Trace Section Valid
    OCC_FFDC_SHARED_REGION_VALID =   0x40,  // OCC Shared Region Section valid
    OCC_FFDC_REGISTERS_VALID     =   0x80,  // OCC Register Section valid
    OCC_FFDC_VALID_ALL           =   ( OCC_FFDC_TRACE_ERR_VALID |
                                       OCC_FFDC_TRACE_IMP_VALID |
                                       OCC_FFDC_TRACE_INF_VALID |
                                       OCC_FFDC_TRACE_SSX_VALID |
                                       OCC_FFDC_TRACE_GPE0_VALID |
                                       OCC_FFDC_TRACE_GPE1_VALID |
                                       OCC_FFDC_SHARED_REGION_VALID |
                                       OCC_FFDC_REGISTERS_VALID )
};

/**
 *  * @brief models OCC Region FFDC header.
 *   */
struct __attribute__((packed)) OccFfdcHeader
{
    uint32_t iv_magicWord;
    uint8_t  iv_ffdcValid;
    uint8_t  iv_headerSize;
    uint16_t iv_sectionSize;
    uint16_t iv_offsetErrTrace;
    uint16_t iv_offsetImpTrace;
    uint16_t iv_offsetInfTrace;
    uint16_t iv_offsetSsxTrace;
    uint16_t iv_offsetGpe0Trace;
    uint16_t iv_offsetGpe1Trace;
    uint16_t iv_offsetSharedSram;
    uint16_t iv_offsetOccRegs;
};

/**
 * @brief   a union modelling PPE FFDC region's header area.
 */
union PpeFfdcHdrRegion
{
    uint8_t iv_ppeFfdcHdrArea[FFDC_PPE_HDR_SIZE];
    PpeFfdcHeader iv_ppeFfdcHdr;
};

/**
 *  * @brief   a union modelling OCC FFDC region's header area.
 *   */
union OccFfdcHdrRegion
{
    uint8_t iv_ppeFfdcHdrArea[FFDC_OCC_REGION_HDR_SIZE];
    OccFfdcHeader iv_occFfdcHdr;
};

/**
 * @brief   models CME's FFDC region.
 */
struct  __attribute__((packed)) PpeFfdcLayout
{
    PpeFfdcHdrRegion iv_ppeFfdcHdr;
    uint8_t iv_ppeGlobals[FFDC_PPE_SCORE_BOARD_SIZE];
    uint8_t iv_ppeImageHeader[FFDC_PPE_IMG_HDR_SIZE];
    uint8_t iv_ppeXirReg[FFDC_PPE_XIR_SIZE];
    uint8_t iv_ppeSpr[FFDC_PPE_SPR_SIZE];
    uint8_t iv_ppeGprs[FFDC_PPE_GPR_SIZE];
    uint8_t iv_ppeInternalReg[FFDC_PPE_INTERNAL_REG_SIZE];
    uint8_t iv_ppeTraces[FFDC_PPE_TRACES_SIZE];
};

/**
 * @brief   models Quad FFDC region of HOMER.
 */
struct __attribute__((packed)) HomerQuadFfdcRegion
{
    uint8_t iv_quadFfdcHeader[FFDC_QUAD_HDR_SIZE];
    uint8_t iv_quadCppmRegion[FFDC_CPPM_REGISTERS_SIZE];
    uint8_t iv_quadCmeBlock[MAX_CMES_PER_QUAD][FFDC_PPE_BLOCK_SIZE];
    uint8_t iv_quadQppmRegion[FFDC_QPPM_REGISTERS_SIZE];
};

/**
 * @brief   models OCC FFDC region of HOMER.
 */
struct __attribute__((packed)) OccFfdcRegion
{
    uint8_t iv_occFfdcHeader[FFDC_OCC_REGION_HDR_SIZE];
    uint8_t iv_occTraceErr[FFDC_TRACE_ERR_SIZE];
    uint8_t iv_occTraceImp[FFDC_TRACE_IMP_SIZE];
    uint8_t iv_occTraceInf[FFDC_TRACE_INF_SIZE];
    uint8_t iv_occTraceSsx[FFDC_TRACE_SSX_SIZE];
    uint8_t iv_occTraceGpe0[FFDC_TRACE_GPE0_SIZE];
    uint8_t iv_occTraceGpe1[FFDC_TRACE_GPE1_SIZE];
    uint8_t iv_occSharedSram[FFDC_SHARED_SRAM_SIZE];
    uint8_t iv_occRegs[FFDC_OCC_REGS_SIZE];
};

/**
 * @brief   models full FFDC region of HOMER.
 */
struct  __attribute__((packed)) HomerFfdcRegion
{
    uint8_t iv_homerFfdcHeader[FFDC_HOMER_TOP_HEADER];
    HomerQuadFfdcRegion iv_quadFfdc[MAX_QUADS_PER_CHIP];
    PpeFfdcLayout       iv_sgpeFfdcRegion;
    PpeFfdcLayout       iv_pgpeFfdcRegion;
    OccFfdcRegion       iv_occFfdcRegion;
};

}   //namespace p9_stop_recov_ffdc ends
#endif //__PM_RECOVERY_FFDC_DEFINES_
<commit_msg>PM Recovery FFDC: Added support to collect Register data for PPM<commit_after>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/pm/p9_pm_recovery_ffdc_defines.H $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2019                        */
/* [+] 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                                                     */
#ifndef __PM_RECOVERY_FFDC_DEFINES_
#define __PM_RECOVERY_FFDC_DEFINES_

#include <p9_hcd_memmap_base.H>
#include <endian.h>

#if( __BYTE_ORDER == __BIG_ENDIAN )
#define REV_2_BYTE(WORD) WORD
#else
#define REV_2_BYTE(WORD) \
    ( (((WORD) >> 8) & 0x00FF) | (((WORD) << 8) & 0xFF00) )
#endif

namespace p9_stop_recov_ffdc
{

/**
 * @brief   enumerates all the platforms involved with STOP Recovery.
 */
enum PmComplexPlatId
{
    PLAT_CME    =   0x01,
    PLAT_SGPE   =   0x02,
    PLAT_PGPE   =   0x03,
    PLAT_OCC    =   0x04,
    PLAT_PPM    =   0x05,
};

/**
 * @brief enumerates type of FFDC data
 */
enum FfdcDataType
{
    IMAGE_HEADER     =  0x01,
    DASH_BOARD_VAR   =  0x02,
    TRACES           =  0x03,
    INTERNAL_REG     =  0x04,
    SCOM_REG         =  0x05,
};

/**
 * @brief enumerates bit position used as validity mark of PPE FFDC sub-section.
 */

enum PpeFfdcValidStatus
{
    PPE_FFDC_INVALID        =   0x00,  //entire PPE FFDC is not valid
    PPE_DASHBOARD_VALID     =   0x01,  // PPE globals are valid
    PPE_IMAGE_HEADER_VALID  =   0x02,  // PPE image header is valid
    PPE_TRACE_VALID         =   0x04,  // PPE Traces are valid
    PPE_STATE_VALID         =   0x08,  // PPE XIRS, GPES and SPRs are valid
    PPE_INT_REG_VALID       =   0x10,  // PPE Int Regs are valid
    PPE_HALT_STATE_VALID    =   0x20,  // PPE Halt State Info is valid
    PPE_FFDC_ALL_VALID      =   0x3F,  // Entire PPE FFDC is valid
};

/**
 * @brief enumerates PPE's HALT conditions as inteprreted from XSR[0:3]
 */
enum PpeHaltCondition
{
    PPE_HALT_COND_NONE    = 0x00, // Not halted
    PPE_HALT_COND_BAD     = 0x08, // Halted, but cannot map source
    PPE_HALT_COND_XCR     = 0x09, // Halted via XCR
    PPE_HALT_COND_WDT     = 0x0A, // Halted via Watch Dog
    PPE_HALT_COND_NMI     = 0x0B, // Halted via unmaskable intr
    PPE_HALT_COND_DBG     = 0x0C, // Debug halt
    PPE_HALT_COND_DBCR    = 0x0D, // Halt via Debug Control Reg
    PPE_HALT_COND_EXT_HLT = 0x0E, // Ext halt_req input active
    PPE_HALT_COND_HW      = 0x0F, // Halted with a HW failure
    PPE_HALT_COND_UNKNOWN = 0xFF  // Could not read or interpret XSR
};

/**
 * @brief   models header of FFDC region of HOMER associated with a CME.
 */
struct __attribute__((packed)) PpeFfdcHeader
{
    uint32_t  iv_ppeMagicNumber;
    uint8_t   iv_ppeNumber;
    uint8_t   iv_headerSize;
    uint16_t  iv_sectionSize;
    uint8_t   iv_ffdcValid;
    uint8_t   iv_ppeHaltCondition;
    uint16_t  iv_dashBoardOffset;
    uint16_t  iv_sramHeaderOffset;
    uint16_t  iv_sprOffset;
    uint16_t  iv_intRegOffset;
    uint16_t  iv_offsetTraces;
    uint8_t   iv_reserve[4];
};

/**
 * @brief models Quad FFDC header.
 */
struct __attribute__((packed)) QuadFfdcHeader
{
    uint32_t iv_quadMagicWord;
    uint8_t  iv_quadInstance;
    uint8_t  iv_quadHeaderSize;
    uint16_t iv_sectionSize;
    uint16_t iv_offsetCppm0;
    uint16_t iv_offsetCppm1;
    uint16_t iv_offsetCppm2;
    uint16_t iv_offsetCppm3;
    uint16_t iv_offsetCme0;
    uint16_t iv_offsetCme1;
    uint16_t iv_offsetQppm;
    uint8_t  iv_ffdcValid;
    uint8_t  iv_reserve;
};

/**
 * @brief enumerates bit position used as validity mark of OCC FFDC sub-section.
 */
enum OccFfdcValidStatus
{
    OCC_FFDC_INVALID             =   0x00,  // None of the FFDC section is valid
    OCC_FFDC_TRACE_ERR_VALID     =   0x01,  // OCC ERR traces section valid
    OCC_FFDC_TRACE_IMP_VALID     =   0x02,  // OCC IMP traces section valid
    OCC_FFDC_TRACE_INF_VALID     =   0x04,  // OCC INF traces section valid
    OCC_FFDC_TRACE_SSX_VALID     =   0x08,  // OCC SSX trace section valid
    OCC_FFDC_TRACE_GPE0_VALID    =   0x10,  // OCC GPE0 Trace Section valid
    OCC_FFDC_TRACE_GPE1_VALID    =   0x20,  // OCC GPE1 Trace Section Valid
    OCC_FFDC_SHARED_REGION_VALID =   0x40,  // OCC Shared Region Section valid
    OCC_FFDC_REGISTERS_VALID     =   0x80,  // OCC Register Section valid
    OCC_FFDC_VALID_ALL           =   ( OCC_FFDC_TRACE_ERR_VALID |
                                       OCC_FFDC_TRACE_IMP_VALID |
                                       OCC_FFDC_TRACE_INF_VALID |
                                       OCC_FFDC_TRACE_SSX_VALID |
                                       OCC_FFDC_TRACE_GPE0_VALID |
                                       OCC_FFDC_TRACE_GPE1_VALID |
                                       OCC_FFDC_SHARED_REGION_VALID |
                                       OCC_FFDC_REGISTERS_VALID )
};

/**
 * @brief models C_Q_PPM FFDC header.
 */
struct __attribute__((packed)) PpmFfdcHeader
{
    uint32_t iv_ppmMagicWord;
    uint8_t  iv_Instance;
    uint8_t  iv_ppmHeaderSize;
    uint16_t iv_sectionSize;
    uint8_t  iv_ffdcValid;
    uint8_t iv_reserved[7];
};

/**
 *  * @brief models OCC Region FFDC header.
 *   */
struct __attribute__((packed)) OccFfdcHeader
{
    uint32_t iv_magicWord;
    uint8_t  iv_ffdcValid;
    uint8_t  iv_headerSize;
    uint16_t iv_sectionSize;
    uint16_t iv_offsetErrTrace;
    uint16_t iv_offsetImpTrace;
    uint16_t iv_offsetInfTrace;
    uint16_t iv_offsetSsxTrace;
    uint16_t iv_offsetGpe0Trace;
    uint16_t iv_offsetGpe1Trace;
    uint16_t iv_offsetSharedSram;
    uint16_t iv_offsetOccRegs;
};

/**
 * @brief   a union modelling PPE FFDC region's header area.
 */
union PpeFfdcHdrRegion
{
    uint8_t iv_ppeFfdcHdrArea[FFDC_PPE_HDR_SIZE];
    PpeFfdcHeader iv_ppeFfdcHdr;
};

/**
 *  * @brief   a union modelling OCC FFDC region's header area.
 *   */
union OccFfdcHdrRegion
{
    uint8_t iv_ppeFfdcHdrArea[FFDC_OCC_REGION_HDR_SIZE];
    OccFfdcHeader iv_occFfdcHdr;
};

/**
 * @brief   models CME's FFDC region.
 */
struct  __attribute__((packed)) PpeFfdcLayout
{
    PpeFfdcHdrRegion iv_ppeFfdcHdr;
    uint8_t iv_ppeGlobals[FFDC_PPE_SCORE_BOARD_SIZE];
    uint8_t iv_ppeImageHeader[FFDC_PPE_IMG_HDR_SIZE];
    uint8_t iv_ppeXirReg[FFDC_PPE_XIR_SIZE];
    uint8_t iv_ppeSpr[FFDC_PPE_SPR_SIZE];
    uint8_t iv_ppeGprs[FFDC_PPE_GPR_SIZE];
    uint8_t iv_ppeInternalReg[FFDC_PPE_INTERNAL_REG_SIZE];
    uint8_t iv_ppeTraces[FFDC_PPE_TRACES_SIZE];
};

/**
 * @brief   models Quad FFDC region of HOMER.
 */
struct __attribute__((packed)) HomerQuadFfdcRegion
{
    uint8_t iv_quadFfdcHeader[FFDC_QUAD_HDR_SIZE];
    uint8_t iv_quadCppmRegion[MAX_CORES_PER_QUAD][FFDC_CPPM_REGISTERS_SIZE];
    uint8_t iv_quadCmeBlock[MAX_CMES_PER_QUAD][FFDC_PPE_BLOCK_SIZE];
    uint8_t iv_quadQppmRegion[FFDC_QPPM_REGISTERS_SIZE];
};

/**
 * @brief   models OCC FFDC region of HOMER.
 */
struct __attribute__((packed)) OccFfdcRegion
{
    uint8_t iv_occFfdcHeader[FFDC_OCC_REGION_HDR_SIZE];
    uint8_t iv_occTraceErr[FFDC_TRACE_ERR_SIZE];
    uint8_t iv_occTraceImp[FFDC_TRACE_IMP_SIZE];
    uint8_t iv_occTraceInf[FFDC_TRACE_INF_SIZE];
    uint8_t iv_occTraceSsx[FFDC_TRACE_SSX_SIZE];
    uint8_t iv_occTraceGpe0[FFDC_TRACE_GPE0_SIZE];
    uint8_t iv_occTraceGpe1[FFDC_TRACE_GPE1_SIZE];
    uint8_t iv_occSharedSram[FFDC_SHARED_SRAM_SIZE];
    uint8_t iv_occRegs[FFDC_OCC_REGS_SIZE];
};

/**
 * @brief   models full FFDC region of HOMER.
 */
struct  __attribute__((packed)) HomerFfdcRegion
{
    uint8_t iv_homerFfdcHeader[FFDC_HOMER_TOP_HEADER];
    HomerQuadFfdcRegion iv_quadFfdc[MAX_QUADS_PER_CHIP];
    PpeFfdcLayout       iv_sgpeFfdcRegion;
    PpeFfdcLayout       iv_pgpeFfdcRegion;
    OccFfdcRegion       iv_occFfdcRegion;
};

}   //namespace p9_stop_recov_ffdc ends
#endif //__PM_RECOVERY_FFDC_DEFINES_
<|endoftext|>


<commit_before>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/pm/p9_query_cache_access_state.C $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,2019                        */
/* [+] 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                                                     */
///
/// @file  p9_query_cache_access_state.C
/// @brief Check the stop level for the EX caches and sets boolean scomable parameters
///
// *HWP HWP Owner: Christina Graves <clgraves@us.ibm.com>
// *HWP Backup HWP Owner: Greg Still <stillgs@us.ibm.com>
// *HWP FW Owner:  Sangeetha T S <sangeet2@in.ibm.com>
// *HWP Team: PM
// *HWP Level: 2
// *HWP Consumed by: FSP:HS:SBE
///
///
///
/// @verbatim
/// High-level procedure flow:
///     - For the quad target, read the Stop State History register in the PPM
///       and use the actual stop level to determine if the quad has power and is being
///       clocked.
/// @endverbatim
///
//------------------------------------------------------------------------------

// ----------------------------------------------------------------------
// Includes
// ----------------------------------------------------------------------

#include <p9_quad_scom_addresses.H>
#include <p9_query_cache_access_state.H>

// ----------------------------------------------------------------------
// Constants
// ----------------------------------------------------------------------

const uint32_t eq_clk_l2_pos[] = {8, 9};
const uint32_t eq_clk_l3_pos[] = {6, 7};
const uint32_t SSH_REG_STOP_LEVEL = 8;
const uint32_t SSH_REG_STOP_LEVEL_LEN = 4;

// ----------------------------------------------------------------------
// Procedure Function
// ----------------------------------------------------------------------

fapi2::ReturnCode
p9_query_cache_access_state(
    const fapi2::Target<fapi2::TARGET_TYPE_EQ>& i_target,
    bool& o_l2_is_scomable,
    bool& o_l2_is_scannable,
    bool& o_l3_is_scomable,
    bool& o_l3_is_scannable)
{
    fapi2::buffer<uint64_t> l_qsshsrc;
    uint32_t l_quadStopLevel = 0;
    fapi2::buffer<uint64_t> l_data64;
    bool l_is_scomable = 1;
    uint8_t l_chpltNumber = 0;
    uint32_t l_exPos = 0;
    uint8_t l_execution_platform = 0;
    uint32_t l_stop_state_reg = 0;
    const fapi2::Target<fapi2::TARGET_TYPE_SYSTEM> FAPI_SYSTEM;

    FAPI_INF("> p9_query_cache_access_state...");

    //Get the stop state from the SSHRC in the EQPPM
    //First figure out whether we should use the C_PPM_SSHFSP (if FSP platform) or C_PPM_SSHHYP (if HOST platform)
    FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_EXECUTION_PLATFORM, FAPI_SYSTEM, l_execution_platform),
             "Error: Failed to get platform");

    if (l_execution_platform == 0x02)
    {
        l_stop_state_reg =  C_PPM_SSHFSP;
    }
    else
    {
        l_stop_state_reg = C_PPM_SSHHYP;
    }

    FAPI_TRY(fapi2::getScom(i_target, l_stop_state_reg, l_qsshsrc), "Error reading data from QPPM SSHSRC");

    //A unit is scommable if clocks are running
    //A unit is scannable if the unit is powered up

    //Extract the core stop state
    l_qsshsrc.extractToRight<uint32_t>(l_quadStopLevel, SSH_REG_STOP_LEVEL, SSH_REG_STOP_LEVEL_LEN);

    FAPI_DBG("EQ Stop State: EQ(%d)", l_quadStopLevel);

    //Set all attribtes to 1, then clear them based on the stop state
    o_l2_is_scomable = 1;
    o_l2_is_scannable = 1;
    o_l3_is_scomable = 1;
    o_l3_is_scannable = 1;

    // STOP8 - Half Quad Deep Sleep
    //   VSU, ISU are powered off
    //   IFU, LSU are powered off
    //   PC, Core EPS are powered off
    //   L20-EX0 is clocked off if both cores are >= 8
    //   L20-EX1 is clocked off if both cores are >= 8
    if (l_quadStopLevel >= 8)
    {
        o_l2_is_scomable = 0;
    }

    // STOP9 - Fast Winkle (lab use only)
    // Both cores and cache are clocked off
    if (l_quadStopLevel >= 9)
    {
        o_l3_is_scomable = 0;
    }

    // STOP11 - Deep Winkle
    // Both cores and cache are powered off
    if (l_quadStopLevel >= 11)
    {
        o_l2_is_scannable = 0;
        o_l3_is_scannable = 0;
    }

    //Read clock status to confirm stop state history is accurate
    //If we trust the stop state history, this could be removed to save on code size
    //Compare Hardware status vs stop state status. If there is a mismatch the HW value overrides the stop state

    FAPI_TRY(fapi2::getScom(i_target, EQ_CLOCK_STAT_SL, l_data64), "Error reading data from EQ_CLOCK_STAT_SL");

    FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CHIP_UNIT_POS, i_target, l_chpltNumber),
             "Error: Failed to get the position of the EX:0x%08X", i_target);
    l_exPos = l_chpltNumber % 2;

    l_is_scomable = !l_data64.getBit(eq_clk_l2_pos[l_exPos]);

    if (o_l2_is_scomable != l_is_scomable)
    {
        FAPI_INF("Clock status didn't match stop state, overriding is_scomable status");
        o_l2_is_scomable = l_is_scomable;
    }

    l_is_scomable = !l_data64.getBit(eq_clk_l3_pos[l_exPos]);

    if (o_l3_is_scomable != l_is_scomable)
    {
        FAPI_INF("Clock status didn't match stop state, overriding is_scomable status");
        o_l3_is_scomable = l_is_scomable;
    }

fapi_try_exit:
    FAPI_INF("< p9_query_cache_access_state...");
    return fapi2::current_err;
}
<commit_msg>Update p9_query_cache_access_state to use the correct scom register<commit_after>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/pm/p9_query_cache_access_state.C $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,2019                        */
/* [+] 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                                                     */
///
/// @file  p9_query_cache_access_state.C
/// @brief Check the stop level for the EX caches and sets boolean scomable parameters
///
// *HWP HWP Owner: Christina Graves <clgraves@us.ibm.com>
// *HWP Backup HWP Owner: Greg Still <stillgs@us.ibm.com>
// *HWP FW Owner:  Sangeetha T S <sangeet2@in.ibm.com>
// *HWP Team: PM
// *HWP Level: 2
// *HWP Consumed by: FSP:HS:SBE
///
///
///
/// @verbatim
/// High-level procedure flow:
///     - For the quad target, read the Stop State History register in the PPM
///       and use the actual stop level to determine if the quad has power and is being
///       clocked.
/// @endverbatim
///
//------------------------------------------------------------------------------

// ----------------------------------------------------------------------
// Includes
// ----------------------------------------------------------------------

#include <p9_quad_scom_addresses.H>
#include <p9_query_cache_access_state.H>

// ----------------------------------------------------------------------
// Constants
// ----------------------------------------------------------------------

const uint32_t eq_clk_l2_pos[] = {8, 9};
const uint32_t eq_clk_l3_pos[] = {6, 7};
const uint32_t SSH_REG_STOP_LEVEL = 8;
const uint32_t SSH_REG_STOP_LEVEL_LEN = 4;

// ----------------------------------------------------------------------
// Procedure Function
// ----------------------------------------------------------------------

fapi2::ReturnCode
p9_query_cache_access_state(
    const fapi2::Target<fapi2::TARGET_TYPE_EQ>& i_target,
    bool& o_l2_is_scomable,
    bool& o_l2_is_scannable,
    bool& o_l3_is_scomable,
    bool& o_l3_is_scannable)
{
    fapi2::buffer<uint64_t> l_qsshsrc;
    uint32_t l_quadStopLevel = 0;
    fapi2::buffer<uint64_t> l_data64;
    bool l_is_scomable = 1;
    uint8_t l_chpltNumber = 0;
    uint32_t l_exPos = 0;
    uint8_t l_execution_platform = 0;
    uint32_t l_stop_state_reg = 0;
    const fapi2::Target<fapi2::TARGET_TYPE_SYSTEM> FAPI_SYSTEM;

    FAPI_INF("> p9_query_cache_access_state...");

    //Get the stop state from the SSHRC in the EQPPM
    //First figure out whether we should use the C_PPM_SSHFSP (if FSP platform) or C_PPM_SSHHYP (if HOST platform)
    FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_EXECUTION_PLATFORM, FAPI_SYSTEM, l_execution_platform),
             "Error: Failed to get platform");

    if (l_execution_platform == 0x02)
    {
        l_stop_state_reg =  EQ_PPM_SSHFSP;
    }
    else
    {
        l_stop_state_reg = EQ_PPM_SSHHYP;
    }

    FAPI_TRY(fapi2::getScom(i_target, l_stop_state_reg, l_qsshsrc), "Error reading data from QPPM SSHSRC");

    //A unit is scommable if clocks are running
    //A unit is scannable if the unit is powered up

    //Extract the core stop state
    l_qsshsrc.extractToRight<uint32_t>(l_quadStopLevel, SSH_REG_STOP_LEVEL, SSH_REG_STOP_LEVEL_LEN);

    FAPI_DBG("EQ Stop State: EQ(%d)", l_quadStopLevel);

    //Set all attribtes to 1, then clear them based on the stop state
    o_l2_is_scomable = 1;
    o_l2_is_scannable = 1;
    o_l3_is_scomable = 1;
    o_l3_is_scannable = 1;

    // STOP8 - Half Quad Deep Sleep
    //   VSU, ISU are powered off
    //   IFU, LSU are powered off
    //   PC, Core EPS are powered off
    //   L20-EX0 is clocked off if both cores are >= 8
    //   L20-EX1 is clocked off if both cores are >= 8
    if (l_quadStopLevel >= 8)
    {
        o_l2_is_scomable = 0;
    }

    // STOP9 - Fast Winkle (lab use only)
    // Both cores and cache are clocked off
    if (l_quadStopLevel >= 9)
    {
        o_l3_is_scomable = 0;
    }

    // STOP11 - Deep Winkle
    // Both cores and cache are powered off
    if (l_quadStopLevel >= 11)
    {
        o_l2_is_scannable = 0;
        o_l3_is_scannable = 0;
    }

    //Read clock status to confirm stop state history is accurate
    //If we trust the stop state history, this could be removed to save on code size
    //Compare Hardware status vs stop state status. If there is a mismatch the HW value overrides the stop state

    FAPI_TRY(fapi2::getScom(i_target, EQ_CLOCK_STAT_SL, l_data64), "Error reading data from EQ_CLOCK_STAT_SL");

    FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CHIP_UNIT_POS, i_target, l_chpltNumber),
             "Error: Failed to get the position of the EX:0x%08X", i_target);
    l_exPos = l_chpltNumber % 2;

    l_is_scomable = !l_data64.getBit(eq_clk_l2_pos[l_exPos]);

    if (o_l2_is_scomable != l_is_scomable)
    {
        FAPI_INF("Clock status didn't match stop state, overriding is_scomable status");
        o_l2_is_scomable = l_is_scomable;
    }

    l_is_scomable = !l_data64.getBit(eq_clk_l3_pos[l_exPos]);

    if (o_l3_is_scomable != l_is_scomable)
    {
        FAPI_INF("Clock status didn't match stop state, overriding is_scomable status");
        o_l3_is_scomable = l_is_scomable;
    }

fapi_try_exit:
    FAPI_INF("< p9_query_cache_access_state...");
    return fapi2::current_err;
}
<|endoftext|>


<commit_before>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/pm/p9_query_cache_access_state.C $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,2019                        */
/* [+] 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                                                     */
///
/// @file  p9_query_cache_access_state.C
/// @brief Check the stop level for the EX caches and sets boolean scomable parameters
///
// *HWP HWP Owner: Christina Graves <clgraves@us.ibm.com>
// *HWP Backup HWP Owner: Greg Still <stillgs@us.ibm.com>
// *HWP FW Owner:  Sangeetha T S <sangeet2@in.ibm.com>
// *HWP Team: PM
// *HWP Level: 2
// *HWP Consumed by: FSP:HS:SBE
///
///
///
/// @verbatim
/// High-level procedure flow:
///     - For the quad target, read the Stop State History register in the PPM
///       and use the actual stop level to determine if the quad has power and is being
///       clocked.
/// @endverbatim
///
//------------------------------------------------------------------------------

// ----------------------------------------------------------------------
// Includes
// ----------------------------------------------------------------------

#include <p9_quad_scom_addresses.H>
#include <p9_query_cache_access_state.H>

// ----------------------------------------------------------------------
// Constants
// ----------------------------------------------------------------------

const uint32_t eq_clk_l2_pos[] = {8, 9};
const uint32_t eq_clk_l3_pos[] = {6, 7};
const uint32_t SSH_REG_STOP_LEVEL = 8;
const uint32_t SSH_REG_STOP_LEVEL_LEN = 4;
const uint32_t SSH_REG_STOP_GATED = 0;

// ----------------------------------------------------------------------
// Procedure Function
// ----------------------------------------------------------------------

fapi2::ReturnCode
p9_query_cache_access_state(
    const fapi2::Target<fapi2::TARGET_TYPE_EQ>& i_target,
    bool& o_l2_is_scomable,
    bool& o_l2_is_scannable,
    bool& o_l3_is_scomable,
    bool& o_l3_is_scannable)
{
    fapi2::buffer<uint64_t> l_qsshsrc;
    uint32_t l_quadStopLevel = 0;
    fapi2::buffer<uint64_t> l_data64;
    bool l_is_scomable = 1;
    uint8_t l_chpltNumber = 0;
    uint32_t l_exPos = 0;
    uint8_t l_execution_platform = 0;
    uint32_t l_stop_state_reg = 0;
    const fapi2::Target<fapi2::TARGET_TYPE_SYSTEM> FAPI_SYSTEM;

    FAPI_INF("> p9_query_cache_access_state...");

    //Get the stop state from the SSHRC in the EQPPM
    //First figure out whether we should use the C_PPM_SSHFSP (if FSP platform) or C_PPM_SSHHYP (if HOST platform)
    FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_EXECUTION_PLATFORM, FAPI_SYSTEM, l_execution_platform),
             "Error: Failed to get platform");

    if (l_execution_platform == 0x02)
    {
        l_stop_state_reg =  EQ_PPM_SSHFSP;
    }
    else
    {
        l_stop_state_reg = EQ_PPM_SSHHYP;
    }

    FAPI_TRY(fapi2::getScom(i_target, l_stop_state_reg, l_qsshsrc), "Error reading data from QPPM SSHSRC");

    //A unit is scommable if clocks are running
    //A unit is scannable if the unit is powered up

    //Extract the core stop state
    l_qsshsrc.extractToRight<uint32_t>(l_quadStopLevel, SSH_REG_STOP_LEVEL, SSH_REG_STOP_LEVEL_LEN);

    FAPI_DBG("EQ Stop State: EQ(%d)", l_quadStopLevel);

    //Set all attribtes to 1, then clear them based on the stop state
    o_l2_is_scomable = 1;
    o_l2_is_scannable = 1;
    o_l3_is_scomable = 1;
    o_l3_is_scannable = 1;

    //Looking at the stop states is only valid if quad is stop gated -- else it is fully running
    if (l_qsshsrc.getBit(SSH_REG_STOP_GATED))
    {
        // STOP8 - Half Quad Deep Sleep
        //   VSU, ISU are powered off
        //   IFU, LSU are powered off
        //   PC, Core EPS are powered off
        //   L20-EX0 is clocked off if both cores are >= 8
        //   L20-EX1 is clocked off if both cores are >= 8
        if (l_quadStopLevel >= 8)
        {
            o_l2_is_scomable = 0;
        }

        // STOP9 - Fast Winkle (lab use only)
        // Both cores and cache are clocked off
        if (l_quadStopLevel >= 9)
        {
            o_l3_is_scomable = 0;
        }

        // STOP11 - Deep Winkle
        // Both cores and cache are powered off
        if (l_quadStopLevel >= 11)
        {
            o_l2_is_scannable = 0;
            o_l3_is_scannable = 0;
        }
        else
        {
            //Read clock status to confirm stop state history is accurate
            //If we trust the stop state history, this could be removed to save on code size
            //Compare Hardware status vs stop state status. If there is a mismatch the HW value overrides the stop state

            FAPI_TRY(fapi2::getScom(i_target, EQ_CLOCK_STAT_SL, l_data64), "Error reading data from EQ_CLOCK_STAT_SL");

            FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CHIP_UNIT_POS, i_target, l_chpltNumber),
                     "Error: Failed to get the position of the EX:0x%08X", i_target);
            l_exPos = l_chpltNumber % 2;

            l_is_scomable = !l_data64.getBit(eq_clk_l2_pos[l_exPos]);

            if (o_l2_is_scomable != l_is_scomable)
            {
                FAPI_INF("Clock status didn't match stop state, overriding is_scomable status");
                o_l2_is_scomable = l_is_scomable;
            }

            l_is_scomable = !l_data64.getBit(eq_clk_l3_pos[l_exPos]);

            if (o_l3_is_scomable != l_is_scomable)
            {
                FAPI_INF("Clock status didn't match stop state, overriding is_scomable status");
                o_l3_is_scomable = l_is_scomable;
            }
        }
    }

fapi_try_exit:
    FAPI_INF("< p9_query_cache_access_state...");
    return fapi2::current_err;
}
<commit_msg>Improve power and clock checking when checking for stop states<commit_after>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/pm/p9_query_cache_access_state.C $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,2019                        */
/* [+] 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                                                     */
///
/// @file  p9_query_cache_access_state.C
/// @brief Check the stop level for the EX caches and sets boolean scomable parameters
///
// *HWP HWP Owner: Christina Graves <clgraves@us.ibm.com>
// *HWP Backup HWP Owner: Greg Still <stillgs@us.ibm.com>
// *HWP FW Owner:  Sangeetha T S <sangeet2@in.ibm.com>
// *HWP Team: PM
// *HWP Level: 2
// *HWP Consumed by: FSP:HS:SBE
///
///
///
/// @verbatim
/// High-level procedure flow:
///     - For the quad target, read the Stop State History register in the PPM
///       and use the actual stop level to determine if the quad has power and is being
///       clocked.
/// @endverbatim
///
//------------------------------------------------------------------------------

// ----------------------------------------------------------------------
// Includes
// ----------------------------------------------------------------------

#include <p9_quad_scom_addresses.H>
#include <p9_query_cache_access_state.H>

// ----------------------------------------------------------------------
// Constants
// ----------------------------------------------------------------------

const uint32_t eq_clk_l2_pos[] = {8, 9};
const uint32_t eq_clk_l3_pos[] = {6, 7};
const uint32_t SSH_REG_STOP_LEVEL = 8;
const uint32_t SSH_REG_STOP_LEVEL_LEN = 4;
const uint32_t SSH_REG_STOP_GATED = 0;

// ----------------------------------------------------------------------
// Procedure Function
// ----------------------------------------------------------------------

fapi2::ReturnCode
p9_query_cache_access_state(
    const fapi2::Target<fapi2::TARGET_TYPE_EQ>& i_target,
    bool& o_l2_is_scomable,
    bool& o_l2_is_scannable,
    bool& o_l3_is_scomable,
    bool& o_l3_is_scannable)
{
    fapi2::buffer<uint64_t> l_qsshsrc;
    uint32_t l_quadStopLevel = 0;
    fapi2::buffer<uint64_t> l_data64;
    bool l_is_scomable = 1;
    uint8_t l_chpltNumber = 0;
    uint32_t l_exPos = 0;
    uint8_t l_execution_platform = 0;
    uint32_t l_stop_state_reg = 0;
    const fapi2::Target<fapi2::TARGET_TYPE_SYSTEM> FAPI_SYSTEM;

    FAPI_INF("> p9_query_cache_access_state...");

    //Get the stop state from the SSHRC in the EQPPM
    //First figure out whether we should use the C_PPM_SSHFSP (if FSP platform) or C_PPM_SSHHYP (if HOST platform)
    FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_EXECUTION_PLATFORM, FAPI_SYSTEM, l_execution_platform),
             "Error: Failed to get platform");

    if (l_execution_platform == 0x02)
    {
        l_stop_state_reg =  EQ_PPM_SSHFSP;
    }
    else
    {
        l_stop_state_reg = EQ_PPM_SSHHYP;
    }

    FAPI_TRY(fapi2::getScom(i_target, l_stop_state_reg, l_qsshsrc), "Error reading data from QPPM SSHSRC");

    //A unit is scommable if clocks are running
    //A unit is scannable if the unit is powered up

    //Extract the quad stop state
    if (l_qsshsrc.getBit(SSH_REG_STOP_GATED))
    {
        l_qsshsrc.extractToRight<uint32_t>(l_quadStopLevel, SSH_REG_STOP_LEVEL, SSH_REG_STOP_LEVEL_LEN);
    }

    FAPI_DBG("EQ Stop State: EQ(%d)", l_quadStopLevel);

    //Set all attributes to 1, then clear them based on the stop state
    o_l2_is_scomable = 1;
    o_l2_is_scannable = 1;
    o_l3_is_scomable = 1;
    o_l3_is_scannable = 1;

    //Looking at the stop states is only valid if quad is stop gated -- else it is fully running
    if (l_qsshsrc.getBit(SSH_REG_STOP_GATED))
    {
        // STOP8 - Half Quad Deep Sleep
        //   VSU, ISU are powered off
        //   IFU, LSU are powered off
        //   PC, Core EPS are powered off
        //   L20-EX0 is clocked off if both cores are >= 8
        //   L20-EX1 is clocked off if both cores are >= 8
        if (l_quadStopLevel >= 8)
        {
            o_l2_is_scomable = 0;
        }

        // STOP9 - Fast Winkle (lab use only)
        // Both cores and cache are clocked off
        if (l_quadStopLevel >= 9)
        {
            o_l3_is_scomable = 0;
        }

        // STOP11 - Deep Winkle
        // Both cores and cache are powered off
        if (l_quadStopLevel >= 11)
        {
            o_l2_is_scannable = 0;
            o_l3_is_scannable = 0;
        }
        else
        {
            //Read clock status to confirm stop state history is accurate
            //If we trust the stop state history, this could be removed to save on code size
            //Compare Hardware status vs stop state status. If there is a mismatch the HW value overrides the stop state

            FAPI_TRY(fapi2::getScom(i_target, EQ_CLOCK_STAT_SL, l_data64), "Error reading data from EQ_CLOCK_STAT_SL");

            FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_CHIP_UNIT_POS, i_target, l_chpltNumber),
                     "Error: Failed to get the position of the EX:0x%08X", i_target);
            l_exPos = l_chpltNumber % 2;

            l_is_scomable = !l_data64.getBit(eq_clk_l2_pos[l_exPos]);

            if (o_l2_is_scomable != l_is_scomable)
            {
                FAPI_INF("Clock status didn't match stop state, overriding is_scomable status");
                o_l2_is_scomable = l_is_scomable;
            }

            l_is_scomable = !l_data64.getBit(eq_clk_l3_pos[l_exPos]);

            if (o_l3_is_scomable != l_is_scomable)
            {
                FAPI_INF("Clock status didn't match stop state, overriding is_scomable status");
                o_l3_is_scomable = l_is_scomable;
            }
        }
    }

fapi_try_exit:
    FAPI_INF("< p9_query_cache_access_state...");
    return fapi2::current_err;
}
<|endoftext|>


<commit_before>#pragma once

#include "libkrbn/impl/libkrbn_complex_modifications_assets_manager.hpp"
#include "libkrbn/impl/libkrbn_configuration_monitor.hpp"
#include "libkrbn/impl/libkrbn_connected_devices_monitor.hpp"
#include "libkrbn/impl/libkrbn_file_monitor.hpp"
#include "libkrbn/impl/libkrbn_frontmost_application_monitor.hpp"
#include "libkrbn/impl/libkrbn_grabber_client.hpp"
#include "libkrbn/impl/libkrbn_hid_value_monitor.hpp"
#include "libkrbn/impl/libkrbn_log_monitor.hpp"
#include "libkrbn/impl/libkrbn_system_preferences_monitor.hpp"
#include "libkrbn/impl/libkrbn_version_monitor.hpp"

class libkrbn_components_manager {
public:
  //
  // version_monitor_
  //

  void enable_version_monitor(libkrbn_version_monitor_callback callback,
                              void* refcon) {
    version_monitor_ = std::make_unique<libkrbn_version_monitor>(callback,
                                                                 refcon);
  }

  void disable_version_monitor(void) {
    version_monitor_ = nullptr;
  }

  //
  // configuration_monitor_
  //

  void enable_configuration_monitor(libkrbn_configuration_monitor_callback callback,
                                    void* refcon) {
    configuration_monitor_ = std::make_unique<libkrbn_configuration_monitor>(callback,
                                                                             refcon);
  }

  void disable_configuration_monitor(void) {
    configuration_monitor_ = nullptr;
  }

  //
  // complex_modifications_assets_manager_;
  //

  void enable_complex_modifications_assets_manager(void) {
    complex_modifications_assets_manager_ = std::make_unique<libkrbn_complex_modifications_assets_manager>();
  }

  void disable_complex_modifications_assets_manager(void) {
    complex_modifications_assets_manager_ = nullptr;
  }

  std::shared_ptr<libkrbn_complex_modifications_assets_manager> get_complex_modifications_assets_manager(void) const {
    return complex_modifications_assets_manager_;
  }

  //
  // system_preferences_monitor_
  //

  void enable_system_preferences_monitor(libkrbn_system_preferences_monitor_callback callback,
                                         void* refcon) {
    system_preferences_monitor_ = std::make_unique<libkrbn_system_preferences_monitor>(callback,
                                                                                refcon);
  }

  void disable_system_preferences_monitor(void) {
    system_preferences_monitor_ = nullptr;
  }

  //
  // connected_devices_monitor_
  //

  void enable_connected_devices_monitor(libkrbn_connected_devices_monitor_callback callback,
                                        void* refcon) {
    connected_devices_monitor_ = std::make_unique<libkrbn_connected_devices_monitor>(callback,
                                                                                refcon);
  }

  void disable_connected_devices_monitor(void) {
    connected_devices_monitor_ = nullptr;
  }

  //
  // kextd_state_json_file_monitor
  //

  void enable_kextd_state_json_file_monitor(libkrbn_file_monitor_callback callback,
                                            void* refcon) {
    kextd_state_json_file_monitor_ = std::make_unique<libkrbn_file_monitor>(krbn::constants::get_kextd_state_json_file_path(),
                                                                            callback,
                                                                            refcon);
  }

  void disable_kextd_state_json_file_monitor(void) {
    kextd_state_json_file_monitor_ = nullptr;
  }

  //
  // observer_state_json_file_monitor
  //

  void enable_observer_state_json_file_monitor(libkrbn_file_monitor_callback callback,
                                               void* refcon) {
    observer_state_json_file_monitor_ = std::make_unique<libkrbn_file_monitor>(krbn::constants::get_observer_state_json_file_path(),
                                                                               callback,
                                                                               refcon);
  }

  void disable_observer_state_json_file_monitor(void) {
    observer_state_json_file_monitor_ = nullptr;
  }

  //
  // grabber_state_json_file_monitor
  //

  void enable_grabber_state_json_file_monitor(libkrbn_file_monitor_callback callback,
                                              void* refcon) {
    grabber_state_json_file_monitor_ = std::make_unique<libkrbn_file_monitor>(krbn::constants::get_grabber_state_json_file_path(),
                                                                              callback,
                                                                              refcon);
  }

  void disable_grabber_state_json_file_monitor(void) {
    grabber_state_json_file_monitor_ = nullptr;
  }

  //
  // device_details_json_file_monitor
  //

  void enable_device_details_json_file_monitor(libkrbn_file_monitor_callback callback,
                                               void* refcon) {
    device_details_json_file_monitor_ = std::make_unique<libkrbn_file_monitor>(krbn::constants::get_device_details_json_file_path(),
                                                                               callback,
                                                                               refcon);
  }

  void disable_device_details_json_file_monitor(void) {
    device_details_json_file_monitor_ = nullptr;
  }

  //
  // manipulator_environment_json_file_monitor
  //

  void enable_manipulator_environment_json_file_monitor(libkrbn_file_monitor_callback callback,
                                                        void* refcon) {
    manipulator_environment_json_file_monitor_ = std::make_unique<libkrbn_file_monitor>(krbn::constants::get_manipulator_environment_json_file_path(),
                                                                                callback,
                                                                                refcon);
  }

  void disable_manipulator_environment_json_file_monitor(void) {
    manipulator_environment_json_file_monitor_ = nullptr;
  }

  //
  // notification_message_json_file_monitor
  //

  void enable_notification_message_json_file_monitor(libkrbn_file_monitor_callback callback,
                                                     void* refcon) {
    notification_message_json_file_monitor_ = std::make_unique<libkrbn_file_monitor>(krbn::constants::get_user_notification_message_file_path(),
                                                                                callback,
                                                                                refcon);
  }

  void disable_notification_message_json_file_monitor(void) {
    notification_message_json_file_monitor_ = nullptr;
  }

  //
  // frontmost_application_monitor_
  //

  void enable_frontmost_application_monitor(libkrbn_frontmost_application_monitor_callback callback,
                                            void* refcon) {
    frontmost_application_monitor_ = std::make_unique<libkrbn_frontmost_application_monitor>(callback,
                                                                                refcon);
  }

  void disable_frontmost_application_monitor(void) {
    frontmost_application_monitor_ = nullptr;
  }

  //
  // log_monitor_
  //

  void enable_log_monitor(libkrbn_log_monitor_callback callback,
                          void* refcon) {
    log_monitor_ = std::make_unique<libkrbn_log_monitor>(callback,
                                                         refcon);
  }

  void disable_log_monitor(void) {
    log_monitor_ = nullptr;
  }

  //
  // hid_value_monitor_
  //

  void enable_hid_value_monitor(libkrbn_hid_value_monitor_callback callback,
                                void* refcon) {
    hid_value_monitor_ = std::make_unique<libkrbn_hid_value_monitor>(callback,
                                                                     refcon);
  }

  void disable_hid_value_monitor(void) {
    hid_value_monitor_ = nullptr;
  }

  bool hid_value_monitor_observed(void) {
    if (hid_value_monitor_) {
      return hid_value_monitor_->get_observed();
    }
    return false;
  }

  //
  // grabber_client_
  //

  void enable_grabber_client(libkrbn_grabber_client_connected_callback connected_callback,
                             libkrbn_grabber_client_connect_failed_callback connect_failed_callback,
                             libkrbn_grabber_client_closed_callback closed_callback) {
    grabber_client_ = std::make_unique<libkrbn_grabber_client>(connected_callback,
                                                               connect_failed_callback,
                                                               closed_callback);
  }

  void disable_grabber_client(void) {
    grabber_client_ = nullptr;
  }

  void grabber_client_async_set_variable(const std::string& name, int value) {
    grabber_client_->async_set_variable(name, value);
  }

  void grabber_client_sync_set_variable(const std::string& name, int value) {
    grabber_client_->sync_set_variable(name, value);
  }

private:
  std::unique_ptr<libkrbn_version_monitor> version_monitor_;
  std::unique_ptr<libkrbn_configuration_monitor> configuration_monitor_;
  std::shared_ptr<libkrbn_complex_modifications_assets_manager> complex_modifications_assets_manager_;
  std::unique_ptr<libkrbn_system_preferences_monitor> system_preferences_monitor_;
  std::unique_ptr<libkrbn_connected_devices_monitor> connected_devices_monitor_;
  std::unique_ptr<libkrbn_file_monitor> kextd_state_json_file_monitor_;
  std::unique_ptr<libkrbn_file_monitor> observer_state_json_file_monitor_;
  std::unique_ptr<libkrbn_file_monitor> grabber_state_json_file_monitor_;
  std::unique_ptr<libkrbn_file_monitor> device_details_json_file_monitor_;
  std::unique_ptr<libkrbn_file_monitor> manipulator_environment_json_file_monitor_;
  std::unique_ptr<libkrbn_file_monitor> notification_message_json_file_monitor_;
  std::unique_ptr<libkrbn_frontmost_application_monitor> frontmost_application_monitor_;
  std::unique_ptr<libkrbn_log_monitor> log_monitor_;
  std::unique_ptr<libkrbn_hid_value_monitor> hid_value_monitor_;
  std::unique_ptr<libkrbn_grabber_client> grabber_client_;
};
<commit_msg>add nullptr check<commit_after>#pragma once

#include "libkrbn/impl/libkrbn_complex_modifications_assets_manager.hpp"
#include "libkrbn/impl/libkrbn_configuration_monitor.hpp"
#include "libkrbn/impl/libkrbn_connected_devices_monitor.hpp"
#include "libkrbn/impl/libkrbn_file_monitor.hpp"
#include "libkrbn/impl/libkrbn_frontmost_application_monitor.hpp"
#include "libkrbn/impl/libkrbn_grabber_client.hpp"
#include "libkrbn/impl/libkrbn_hid_value_monitor.hpp"
#include "libkrbn/impl/libkrbn_log_monitor.hpp"
#include "libkrbn/impl/libkrbn_system_preferences_monitor.hpp"
#include "libkrbn/impl/libkrbn_version_monitor.hpp"

class libkrbn_components_manager {
public:
  //
  // version_monitor_
  //

  void enable_version_monitor(libkrbn_version_monitor_callback callback,
                              void* refcon) {
    version_monitor_ = std::make_unique<libkrbn_version_monitor>(callback,
                                                                 refcon);
  }

  void disable_version_monitor(void) {
    version_monitor_ = nullptr;
  }

  //
  // configuration_monitor_
  //

  void enable_configuration_monitor(libkrbn_configuration_monitor_callback callback,
                                    void* refcon) {
    configuration_monitor_ = std::make_unique<libkrbn_configuration_monitor>(callback,
                                                                             refcon);
  }

  void disable_configuration_monitor(void) {
    configuration_monitor_ = nullptr;
  }

  //
  // complex_modifications_assets_manager_;
  //

  void enable_complex_modifications_assets_manager(void) {
    complex_modifications_assets_manager_ = std::make_unique<libkrbn_complex_modifications_assets_manager>();
  }

  void disable_complex_modifications_assets_manager(void) {
    complex_modifications_assets_manager_ = nullptr;
  }

  std::shared_ptr<libkrbn_complex_modifications_assets_manager> get_complex_modifications_assets_manager(void) const {
    return complex_modifications_assets_manager_;
  }

  //
  // system_preferences_monitor_
  //

  void enable_system_preferences_monitor(libkrbn_system_preferences_monitor_callback callback,
                                         void* refcon) {
    system_preferences_monitor_ = std::make_unique<libkrbn_system_preferences_monitor>(callback,
                                                                                refcon);
  }

  void disable_system_preferences_monitor(void) {
    system_preferences_monitor_ = nullptr;
  }

  //
  // connected_devices_monitor_
  //

  void enable_connected_devices_monitor(libkrbn_connected_devices_monitor_callback callback,
                                        void* refcon) {
    connected_devices_monitor_ = std::make_unique<libkrbn_connected_devices_monitor>(callback,
                                                                                refcon);
  }

  void disable_connected_devices_monitor(void) {
    connected_devices_monitor_ = nullptr;
  }

  //
  // kextd_state_json_file_monitor
  //

  void enable_kextd_state_json_file_monitor(libkrbn_file_monitor_callback callback,
                                            void* refcon) {
    kextd_state_json_file_monitor_ = std::make_unique<libkrbn_file_monitor>(krbn::constants::get_kextd_state_json_file_path(),
                                                                            callback,
                                                                            refcon);
  }

  void disable_kextd_state_json_file_monitor(void) {
    kextd_state_json_file_monitor_ = nullptr;
  }

  //
  // observer_state_json_file_monitor
  //

  void enable_observer_state_json_file_monitor(libkrbn_file_monitor_callback callback,
                                               void* refcon) {
    observer_state_json_file_monitor_ = std::make_unique<libkrbn_file_monitor>(krbn::constants::get_observer_state_json_file_path(),
                                                                               callback,
                                                                               refcon);
  }

  void disable_observer_state_json_file_monitor(void) {
    observer_state_json_file_monitor_ = nullptr;
  }

  //
  // grabber_state_json_file_monitor
  //

  void enable_grabber_state_json_file_monitor(libkrbn_file_monitor_callback callback,
                                              void* refcon) {
    grabber_state_json_file_monitor_ = std::make_unique<libkrbn_file_monitor>(krbn::constants::get_grabber_state_json_file_path(),
                                                                              callback,
                                                                              refcon);
  }

  void disable_grabber_state_json_file_monitor(void) {
    grabber_state_json_file_monitor_ = nullptr;
  }

  //
  // device_details_json_file_monitor
  //

  void enable_device_details_json_file_monitor(libkrbn_file_monitor_callback callback,
                                               void* refcon) {
    device_details_json_file_monitor_ = std::make_unique<libkrbn_file_monitor>(krbn::constants::get_device_details_json_file_path(),
                                                                               callback,
                                                                               refcon);
  }

  void disable_device_details_json_file_monitor(void) {
    device_details_json_file_monitor_ = nullptr;
  }

  //
  // manipulator_environment_json_file_monitor
  //

  void enable_manipulator_environment_json_file_monitor(libkrbn_file_monitor_callback callback,
                                                        void* refcon) {
    manipulator_environment_json_file_monitor_ = std::make_unique<libkrbn_file_monitor>(krbn::constants::get_manipulator_environment_json_file_path(),
                                                                                callback,
                                                                                refcon);
  }

  void disable_manipulator_environment_json_file_monitor(void) {
    manipulator_environment_json_file_monitor_ = nullptr;
  }

  //
  // notification_message_json_file_monitor
  //

  void enable_notification_message_json_file_monitor(libkrbn_file_monitor_callback callback,
                                                     void* refcon) {
    notification_message_json_file_monitor_ = std::make_unique<libkrbn_file_monitor>(krbn::constants::get_user_notification_message_file_path(),
                                                                                callback,
                                                                                refcon);
  }

  void disable_notification_message_json_file_monitor(void) {
    notification_message_json_file_monitor_ = nullptr;
  }

  //
  // frontmost_application_monitor_
  //

  void enable_frontmost_application_monitor(libkrbn_frontmost_application_monitor_callback callback,
                                            void* refcon) {
    frontmost_application_monitor_ = std::make_unique<libkrbn_frontmost_application_monitor>(callback,
                                                                                refcon);
  }

  void disable_frontmost_application_monitor(void) {
    frontmost_application_monitor_ = nullptr;
  }

  //
  // log_monitor_
  //

  void enable_log_monitor(libkrbn_log_monitor_callback callback,
                          void* refcon) {
    log_monitor_ = std::make_unique<libkrbn_log_monitor>(callback,
                                                         refcon);
  }

  void disable_log_monitor(void) {
    log_monitor_ = nullptr;
  }

  //
  // hid_value_monitor_
  //

  void enable_hid_value_monitor(libkrbn_hid_value_monitor_callback callback,
                                void* refcon) {
    hid_value_monitor_ = std::make_unique<libkrbn_hid_value_monitor>(callback,
                                                                     refcon);
  }

  void disable_hid_value_monitor(void) {
    hid_value_monitor_ = nullptr;
  }

  bool hid_value_monitor_observed(void) {
    if (hid_value_monitor_) {
      return hid_value_monitor_->get_observed();
    }
    return false;
  }

  //
  // grabber_client_
  //

  void enable_grabber_client(libkrbn_grabber_client_connected_callback connected_callback,
                             libkrbn_grabber_client_connect_failed_callback connect_failed_callback,
                             libkrbn_grabber_client_closed_callback closed_callback) {
    grabber_client_ = std::make_unique<libkrbn_grabber_client>(connected_callback,
                                                               connect_failed_callback,
                                                               closed_callback);
  }

  void disable_grabber_client(void) {
    grabber_client_ = nullptr;
  }

  void grabber_client_async_set_variable(const std::string& name, int value) {
    if (grabber_client_) {
      grabber_client_->async_set_variable(name, value);
    }
  }

  void grabber_client_sync_set_variable(const std::string& name, int value) {
    if (grabber_client_) {
      grabber_client_->sync_set_variable(name, value);
    }
  }

private:
  std::unique_ptr<libkrbn_version_monitor> version_monitor_;
  std::unique_ptr<libkrbn_configuration_monitor> configuration_monitor_;
  std::shared_ptr<libkrbn_complex_modifications_assets_manager> complex_modifications_assets_manager_;
  std::unique_ptr<libkrbn_system_preferences_monitor> system_preferences_monitor_;
  std::unique_ptr<libkrbn_connected_devices_monitor> connected_devices_monitor_;
  std::unique_ptr<libkrbn_file_monitor> kextd_state_json_file_monitor_;
  std::unique_ptr<libkrbn_file_monitor> observer_state_json_file_monitor_;
  std::unique_ptr<libkrbn_file_monitor> grabber_state_json_file_monitor_;
  std::unique_ptr<libkrbn_file_monitor> device_details_json_file_monitor_;
  std::unique_ptr<libkrbn_file_monitor> manipulator_environment_json_file_monitor_;
  std::unique_ptr<libkrbn_file_monitor> notification_message_json_file_monitor_;
  std::unique_ptr<libkrbn_frontmost_application_monitor> frontmost_application_monitor_;
  std::unique_ptr<libkrbn_log_monitor> log_monitor_;
  std::unique_ptr<libkrbn_hid_value_monitor> hid_value_monitor_;
  std::unique_ptr<libkrbn_grabber_client> grabber_client_;
};
<|endoftext|>


<commit_before>#include <uv.h>
#include "../../../ui.h"
#include "nbind/nbind.h"

extern int uiConnectionNumber();
extern int uiEventsPending();

uv_poll_t * handle;

static void onEventsPending(uv_poll_t* handle, int status, int events) {
	Nan::HandleScope scope;
	while(uiEventsPending()) {
		uiMainStep(0);
	}

}

bool running = false;

struct EventLoop {
	static void start () {
		if (running) {
			return;
		}
		running = true;
		uiMainSteps();

		int fd = uiConnectionNumber();
		handle = new uv_poll_t();

		uv_poll_init(uv_default_loop(), handle, fd);

		uv_poll_start(handle, UV_WRITABLE, onEventsPending);
	}

	static void stop () {
		if (!running) {
			return;
		}
		running = false;
		uiQuit();
		uv_poll_stop(handle);
	}
};

NBIND_CLASS(EventLoop) {
		method(start);
		method(stop);
}
<commit_msg>switch to readable<commit_after>#include <uv.h>
#include "../../../ui.h"
#include "nbind/nbind.h"

extern int uiConnectionNumber();
extern int uiEventsPending();

uv_poll_t * handle;

static void onEventsPending(uv_poll_t* handle, int status, int events) {
	printf("onEventsPending\n");
	Nan::HandleScope scope;
	while(uiEventsPending()) {
		uiMainStep(0);
	}
	printf("onEventsPending exited\n");
}

bool running = false;

struct EventLoop {
	static void start () {
		if (running) {
			return;
		}
		running = true;
		uiMainSteps();

		int fd = uiConnectionNumber();
		handle = new uv_poll_t();

		uv_poll_init(uv_default_loop(), handle, fd);

		uv_poll_start(handle, UV_READABLE, onEventsPending);
	}

	static void stop () {
		if (!running) {
			return;
		}
		running = false;
		uiQuit();
		uv_poll_stop(handle);
	}
};

NBIND_CLASS(EventLoop) {
		method(start);
		method(stop);
}
<|endoftext|>


<commit_before>//	Copyright 2017 Adam Smith
//	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.

#include "asmith/serial/json.hpp"
#include <cctype>

namespace asmith { namespace serial {

	void json_skip_whitespace(std::istream& aStream) {
		char c = aStream.peek();
		while(std::isspace(c)) {
			aStream.read(&c, 1);
		}
	}

	value::type json_determine_type(std::istream& aStream) {
		json_skip_whitespace(aStream);
		char c = aStream.peek();
		switch(c) {
		case 'n':
			return value::NULL_T;
		case 't':
		case 'f':
			return value::BOOl_T;
		case '0':
		case '1':
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':
		case '8':
		case '9':
			return value::NUMBER_T;
		case '"':
			return value::STRING_T;
		case '[':
			return value::ARRAY_T;
		case '{':
			return value::OBJECT_T;
		default:
			throw std::runtime_error("asmith::json_format::read_serial : Could not determin JSON type");
		}
	}

	value json_read_value(std::istream&);

	value json_read_null(std::istream& aStream) {
		json_skip_whitespace(aStream);

		char buf[4];
		aStream.read(buf, 4);
		if(memcmp(buf, "null", 4) != 0) throw std::runtime_error("asmith::json_format::read_serial : Expected 'null'");
		return value();
	}

	value json_read_bool(std::istream& aStream) {
		json_skip_whitespace(aStream);

		char buf[5];
		aStream.read(buf, 4);
		if(memcmp(buf, "true", 4) == 0) {
			return value(true);
		}else if(memcmp(buf, "fals", 4) == 0) {
			aStream.read(buf, 1);
			if(buf[0] == 'e') return value(false);
		}
		throw std::runtime_error("asmith::json_format::read_serial : Expected 'true' or 'false'");
	}

	value json_read_number(std::istream& aStream) {
		json_skip_whitespace(aStream);

		static const auto is_number = [](const char c)->bool {
			return (c >= '0' && c <= '9') || c == '+' || c == '-' || c == '.' || c == 'e' || c == 'E';
		};

		char buf[32];
		size_t s = 0;
		char c = aStream.peek();
		while(is_number(c)) {
			buf[s++] = c;
			aStream.read(&c, 1);
		}
		buf[s] = '\0';
		return value(atof(buf));
	}

	value json_read_string(std::istream& aStream) {
		json_skip_whitespace(aStream);

		char c = aStream.peek();
		if(c != '"') throw std::runtime_error("asmith::json_format::read_serial : Expected string to begin with '\"'");

		value tmp;
		value::string_t& str = tmp.set_string();

		aStream.read(&c, 1);
		while(c != '"') {
			str += c;
			aStream.read(&c, 1);
			if(aStream.eof()) throw std::runtime_error("asmith::json_format::read_serial : Expected string to end with '\"'");
		}

		return tmp;
	}

	value json_read_array(std::istream& aStream) {
		json_skip_whitespace(aStream);

		char c = aStream.peek();
		if(c != '[') throw std::runtime_error("asmith::json_format::read_serial : Expected array to begin with '['");
		json_skip_whitespace(aStream);

		value tmp;
		value::array_t& array_ = tmp.set_array();

		c = aStream.peek();
		while(c != ']') {
			if(aStream.eof()) throw std::runtime_error("asmith::json_format::read_serial : Expected array to end with ']'");
			array_.push_back(json_read_value(aStream));
			json_skip_whitespace(aStream);
			c = aStream.peek();
			if(c == ']') break;
			else if(c != ',') throw std::runtime_error("asmith::json_format::read_serial : Expected array elements to be seperated with ','");
			aStream.read(&c, 1);
			json_skip_whitespace(aStream);
		}
		aStream.read(&c, 1);

		return tmp;

	}

	value json_read_object(std::istream& aStream) {
		json_skip_whitespace(aStream);

		//! \todo Implement
		return value();
	}

	value json_read_value(std::istream& aStream) {
		switch(json_determine_type(aStream)) {
		case value::NULL_T:
			return json_read_null(aStream);
		case value::BOOl_T:
			return json_read_bool(aStream);
		case value::NUMBER_T:
			return json_read_number(aStream);
		case value::STRING_T:
			return json_read_string(aStream);
		case value::ARRAY_T:
			return json_read_array(aStream);
		case value::OBJECT_T:
			return json_read_object(aStream);
		default:
			throw std::runtime_error("asmith::json_format::read_serial : Could not determin JSON type");
		}
	}

	void json_format::write_serial(const value& aType, std::ostream& aStream) {
		const value::type tBuf = aType.get_type();

		switch(tBuf) {
		case value::NULL_T:
			aStream << "null";
			break;
		case value::BOOl_T:
			aStream << (aType.get_bool() ? "true" : "false");
			break;
		case value::CHAR_T:
			aStream << '"' << aType.get_char() << '"';
			break;
		case value::NUMBER_T:
			aStream << aType.get_number();
			break;
		case value::STRING_T:
			aStream << '"' << aType.get_string() << '"';
			break;
		case value::ARRAY_T:
			{
				aStream << '[';
				const value::array_t tmp = aType.get_array();
				const size_t s = tmp.size();
				for(size_t i = 0; i < s; ++i) {
					write_serial(tmp[i], aStream);
					if(i + 1 < s) aStream << ',';
				}
				aStream << ']';
			}
			break;
		case value::OBJECT_T:
		{
			aStream << '{';
			const value::object_t tmp = aType.get_object();
			const size_t s = tmp.size();
			size_t i = 0;
			for(const auto& v : tmp) {
				aStream << '"' << v.first<< '"' << ':';
				write_serial(v.second, aStream);
				if(i + 1 < s) aStream << ',';
				++i;
			}
			aStream << '}';
		}
		break;
		default:
			throw std::runtime_error("json_format : Invalid serial type");
			break;
		}
	}

	value json_format::read_serial(std::istream& aStream) {
		//! \todo Implement
		return value();
	}
}}<commit_msg>Implemented object reading<commit_after>//	Copyright 2017 Adam Smith
//	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.

#include "asmith/serial/json.hpp"
#include <cctype>

namespace asmith { namespace serial {

	void json_skip_whitespace(std::istream& aStream) {
		char c = aStream.peek();
		while(std::isspace(c)) {
			aStream.read(&c, 1);
		}
	}

	value::type json_determine_type(std::istream& aStream) {
		json_skip_whitespace(aStream);
		char c = aStream.peek();
		switch(c) {
		case 'n':
			return value::NULL_T;
		case 't':
		case 'f':
			return value::BOOl_T;
		case '0':
		case '1':
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':
		case '8':
		case '9':
			return value::NUMBER_T;
		case '"':
			return value::STRING_T;
		case '[':
			return value::ARRAY_T;
		case '{':
			return value::OBJECT_T;
		default:
			throw std::runtime_error("asmith::json_format::read_serial : Could not determin JSON type");
		}
	}

	value json_read_value(std::istream&);

	value json_read_null(std::istream& aStream) {
		json_skip_whitespace(aStream);

		char buf[4];
		aStream.read(buf, 4);
		if(memcmp(buf, "null", 4) != 0) throw std::runtime_error("asmith::json_format::read_serial : Expected 'null'");
		return value();
	}

	value json_read_bool(std::istream& aStream) {
		json_skip_whitespace(aStream);

		char buf[5];
		aStream.read(buf, 4);
		if(memcmp(buf, "true", 4) == 0) {
			return value(true);
		}else if(memcmp(buf, "fals", 4) == 0) {
			aStream.read(buf, 1);
			if(buf[0] == 'e') return value(false);
		}
		throw std::runtime_error("asmith::json_format::read_serial : Expected 'true' or 'false'");
	}

	value json_read_number(std::istream& aStream) {
		json_skip_whitespace(aStream);

		static const auto is_number = [](const char c)->bool {
			return (c >= '0' && c <= '9') || c == '+' || c == '-' || c == '.' || c == 'e' || c == 'E';
		};

		char buf[32];
		size_t s = 0;
		char c = aStream.peek();
		while(is_number(c)) {
			buf[s++] = c;
			aStream.read(&c, 1);
		}
		buf[s] = '\0';
		return value(atof(buf));
	}

	value json_read_string(std::istream& aStream) {
		json_skip_whitespace(aStream);

		char c = aStream.peek();
		if(c != '"') throw std::runtime_error("asmith::json_format::read_serial : Expected string to begin with '\"'");

		value tmp;
		value::string_t& str = tmp.set_string();

		aStream.read(&c, 1);
		while(c != '"') {
			str += c;
			aStream.read(&c, 1);
			if(aStream.eof()) throw std::runtime_error("asmith::json_format::read_serial : Expected string to end with '\"'");
		}

		return tmp;
	}

	value json_read_array(std::istream& aStream) {
		json_skip_whitespace(aStream);

		char c = aStream.peek();
		if(c != '[') throw std::runtime_error("asmith::json_format::read_serial : Expected array to begin with '['");
		json_skip_whitespace(aStream);

		value tmp;
		value::array_t& array_ = tmp.set_array();

		c = aStream.peek();
		while(c != ']') {
			if(aStream.eof()) throw std::runtime_error("asmith::json_format::read_serial : Expected array to end with ']'");
			array_.push_back(json_read_value(aStream));
			json_skip_whitespace(aStream);
			c = aStream.peek();
			if(c == ']') break;
			else if(c != ',') throw std::runtime_error("asmith::json_format::read_serial : Expected array elements to be seperated with ','");
			aStream.read(&c, 1);
			json_skip_whitespace(aStream);
		}
		aStream.read(&c, 1);

		return tmp;
	}

	value json_read_object(std::istream& aStream) {
		json_skip_whitespace(aStream);

		char c = aStream.peek();
		if(c != '{') throw std::runtime_error("asmith::json_format::read_serial : Expected object to begin with '{'");
		json_skip_whitespace(aStream);

		value tmp;
		value::object_t& object = tmp.set_object();

		c = aStream.peek();
		while(c != '}') {
			if(aStream.eof()) throw std::runtime_error("asmith::json_format::read_serial : Expected object to end with '}'");
			const value::string_t name = json_read_string(aStream).get_string();
			json_skip_whitespace(aStream);
			aStream.read(&c, 1);
			if(c != ':') throw std::runtime_error("asmith::json_format::read_serial : Expected object name to be end with ':'");
			json_skip_whitespace(aStream);
			object.emplace(name, json_read_value(aStream));
			json_skip_whitespace(aStream);
			c = aStream.peek();
			if(c == '}') break;
			else if(c != ',') throw std::runtime_error("asmith::json_format::read_serial : Expected object elements to be seperated with ','");
			aStream.read(&c, 1);
			json_skip_whitespace(aStream);
		}
		aStream.read(&c, 1);

		return tmp;
	}

	value json_read_value(std::istream& aStream) {
		switch(json_determine_type(aStream)) {
		case value::NULL_T:
			return json_read_null(aStream);
		case value::BOOl_T:
			return json_read_bool(aStream);
		case value::NUMBER_T:
			return json_read_number(aStream);
		case value::STRING_T:
			return json_read_string(aStream);
		case value::ARRAY_T:
			return json_read_array(aStream);
		case value::OBJECT_T:
			return json_read_object(aStream);
		default:
			throw std::runtime_error("asmith::json_format::read_serial : Could not determin JSON type");
		}
	}

	void json_format::write_serial(const value& aType, std::ostream& aStream) {
		const value::type tBuf = aType.get_type();

		switch(tBuf) {
		case value::NULL_T:
			aStream << "null";
			break;
		case value::BOOl_T:
			aStream << (aType.get_bool() ? "true" : "false");
			break;
		case value::CHAR_T:
			aStream << '"' << aType.get_char() << '"';
			break;
		case value::NUMBER_T:
			aStream << aType.get_number();
			break;
		case value::STRING_T:
			aStream << '"' << aType.get_string() << '"';
			break;
		case value::ARRAY_T:
			{
				aStream << '[';
				const value::array_t tmp = aType.get_array();
				const size_t s = tmp.size();
				for(size_t i = 0; i < s; ++i) {
					write_serial(tmp[i], aStream);
					if(i + 1 < s) aStream << ',';
				}
				aStream << ']';
			}
			break;
		case value::OBJECT_T:
		{
			aStream << '{';
			const value::object_t tmp = aType.get_object();
			const size_t s = tmp.size();
			size_t i = 0;
			for(const auto& v : tmp) {
				aStream << '"' << v.first<< '"' << ':';
				write_serial(v.second, aStream);
				if(i + 1 < s) aStream << ',';
				++i;
			}
			aStream << '}';
		}
		break;
		default:
			throw std::runtime_error("json_format : Invalid serial type");
			break;
		}
	}

	value json_format::read_serial(std::istream& aStream) {
		//! \todo Implement
		return value();
	}
}}<|endoftext|>


<commit_before>#pragma once
/*
*  Author(s):
*  - Chris  Kilner <ckilner@aldebaran-robotics.com>
*  - Cedric Gestes <gestes@aldebaran-robotics.com>
*
*  Copyright (C) 2010 Aldebaran Robotics
*/

#ifndef _QI_TRANSPORT_TRANSPORT_CONTEXT_HPP_
#define _QI_TRANSPORT_TRANSPORT_CONTEXT_HPP_

#include <string>
#include <qi/transport/buffer.hpp>

namespace qi {
  namespace transport {

    class TransportContext {
    public:
      TransportContext();
      ~TransportContext();

    //TODO: protected:
      template <typename T>
      T &getContext(const std::string &address) {
        //we only have one context type, so we dont need address ATM
        (void) address;
        return *static_cast<T*>(_ctx);
      }

    protected:
      void *_ctx;
    };

  }
}

#endif  // _QI_TRANSPORT_TRANSPORT_CLIENT_HPP_
<commit_msg>transport: make getContext protected. users dont need that function<commit_after>#pragma once
/*
*  Author(s):
*  - Chris  Kilner <ckilner@aldebaran-robotics.com>
*  - Cedric Gestes <gestes@aldebaran-robotics.com>
*
*  Copyright (C) 2010 Aldebaran Robotics
*/

#ifndef _QI_TRANSPORT_TRANSPORT_CONTEXT_HPP_
#define _QI_TRANSPORT_TRANSPORT_CONTEXT_HPP_

#include <string>
#include <qi/transport/buffer.hpp>

namespace qi {
  namespace transport {

    class TransportContext {
    public:
      TransportContext();
      ~TransportContext();

    protected:
      friend class TransportClient;
      friend class TransportServer;
      friend class TransportSubscriber;
      friend class TransportPublisher;

      //protected because, this return implementation detail not relevant for users.
      //that's why we have friend classes.
      template <typename T>
      T &getContext(const std::string &address) {
        //we only have one context type, so we dont need address ATM
        (void) address;
        return *static_cast<T*>(_ctx);
      }

    protected:
      void *_ctx;
    };

  }
}

#endif  // _QI_TRANSPORT_TRANSPORT_CLIENT_HPP_
<|endoftext|>