From 871d02a4e2c66e7c0501812abd86a27009cc73e0 Mon Sep 17 00:00:00 2001 From: Claus Michael Olsen Date: Wed, 5 Apr 2017 05:16:51 -0500 Subject: Code restruct: TOR API Key_Cronus_Test=XIP_REGRESS Code restructuring aiming at: - utilizing TOR magic header info - enforce a common approach for - extracting metadata for all image,chipType combinations - traversing images for all image,chipType combinations - shrinking code size by reusing common code segments - improve readability by - separating more clearly metadata extraction and image traversal - slight rearrange of certain code segments - remove leftover hardcoded assumptions about ring/TOR data and structs - variables appropriately renamed and now all using camel style Change-Id: I50ace8b2fdb340a97ce6d74ce545c5e1acd21c40 Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/38863 Tested-by: HWSV CI Tested-by: PPE CI Tested-by: Jenkins Server Tested-by: Cronus HW CI Tested-by: FSP CI Jenkins Tested-by: Hostboot CI Reviewed-by: GIRISANKAR PAULRAJ Reviewed-by: Thi N. Tran Reviewed-by: Jennifer A. Stofer Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/43250 Reviewed-by: Hostboot Team Reviewed-by: Sachin Gupta --- .../chips/centaur/utils/imageProcs/cen_ringId.C | 2 +- .../chips/centaur/utils/imageProcs/cen_ringId.H | 6 +- .../chips/common/utils/imageProcs/common_ringId.C | 198 +++ .../chips/common/utils/imageProcs/common_ringId.H | 179 +- .../p9/utils/imageProcs/p9_infrastruct_help.H | 13 +- src/import/chips/p9/utils/imageProcs/p9_ringId.C | 2 +- src/import/chips/p9/utils/imageProcs/p9_ringId.H | 11 +- src/import/chips/p9/utils/imageProcs/p9_tor.C | 1753 ++++---------------- src/import/chips/p9/utils/imageProcs/p9_tor.H | 139 +- src/import/chips/p9/xip/Makefile | 1 + src/import/chips/p9/xip/p9_xip_tool.C | 57 +- 11 files changed, 747 insertions(+), 1614 deletions(-) create mode 100644 src/import/chips/common/utils/imageProcs/common_ringId.C (limited to 'src/import/chips') diff --git a/src/import/chips/centaur/utils/imageProcs/cen_ringId.C b/src/import/chips/centaur/utils/imageProcs/cen_ringId.C index e19aa46e..ebd8e759 100644 --- a/src/import/chips/centaur/utils/imageProcs/cen_ringId.C +++ b/src/import/chips/centaur/utils/imageProcs/cen_ringId.C @@ -181,7 +181,7 @@ void CEN_RID::ringid_get_chiplet_properties( } } -GenRingIdList* CEN_RID::ringid_get_ring_properties(RingId_t i_ringId) +GenRingIdList* CEN_RID::ringid_get_ring_list(RingId_t i_ringId) { ChipletData_t* l_cpltData; GenRingIdList* l_ringList[2]; // 0: common, 1: instance diff --git a/src/import/chips/centaur/utils/imageProcs/cen_ringId.H b/src/import/chips/centaur/utils/imageProcs/cen_ringId.H index 593fa6a6..f1672e40 100644 --- a/src/import/chips/centaur/utils/imageProcs/cen_ringId.H +++ b/src/import/chips/centaur/utils/imageProcs/cen_ringId.H @@ -380,8 +380,7 @@ static const RingProperties_t RING_PROPERTIES[NUM_RING_IDS] = // returns our own chiplet enum value for this ringId ChipletType_t -ringid_get_chiplet( - RingId_t i_ringId); +ringid_get_chiplet(RingId_t i_ringId); // returns data structures defined for chiplet type // as determined by ringId @@ -396,8 +395,7 @@ ringid_get_chiplet_properties( // returns properties of a ring as determined by ringId GenRingIdList* -ringid_get_ring_properties( - RingId_t i_ringId); +ringid_get_ring_list(RingId_t i_ringId); #endif // _CEN_RINGID_H_ diff --git a/src/import/chips/common/utils/imageProcs/common_ringId.C b/src/import/chips/common/utils/imageProcs/common_ringId.C new file mode 100644 index 00000000..3fa7aac5 --- /dev/null +++ b/src/import/chips/common/utils/imageProcs/common_ringId.C @@ -0,0 +1,198 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/import/chips/common/utils/imageProcs/common_ringId.C $ */ +/* */ +/* OpenPOWER sbe Project */ +/* */ +/* Contributors Listed Below - COPYRIGHT 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 */ +#include + +namespace P9_RID +{ +#include +}; +namespace CEN_RID +{ +#include +}; +#include + +// These strings must adhere precisely to the enum of ppeType. +const char* ppeTypeName[] = { "SBE", + "CME", + "SGPE" + }; + +// These strings must adhere precisely to the enum of RingVariant. +const char* ringVariantName[] = { "BASE", + "CC", + "RL", + "OVRD", + "OVLY" + }; + + + +int ringid_get_noof_chiplets( ChipType_t i_chipType, + uint32_t i_torMagic, + uint8_t* o_numChiplets ) +{ + switch (i_chipType) + { + case CT_P9N: + case CT_P9C: + if ( i_torMagic == TOR_MAGIC_SBE || + i_torMagic == TOR_MAGIC_OVRD || + i_torMagic == TOR_MAGIC_OVLY ) + { + *o_numChiplets = P9_RID::SBE_NOOF_CHIPLETS; + } + else if ( i_torMagic == TOR_MAGIC_CME ) + { + *o_numChiplets = P9_RID::CME_NOOF_CHIPLETS; + } + else if ( i_torMagic == TOR_MAGIC_SGPE ) + { + *o_numChiplets = P9_RID::SGPE_NOOF_CHIPLETS; + } + else + { + MY_ERR("Invalid torMagic (=0x%08x) for chipType (=CT_P9x=%d)\n", i_torMagic, i_chipType); + return TOR_INVALID_MAGIC_NUMBER; + } + + break; + + case CT_CEN: + if ( i_torMagic == TOR_MAGIC_CEN || + i_torMagic == TOR_MAGIC_OVRD ) + { + *o_numChiplets = CEN_RID::CEN_NOOF_CHIPLETS; + } + else + { + MY_ERR("Invalid torMagic (=0x%08x) for chipType (=CT_CEN)\n", i_torMagic); + return TOR_INVALID_MAGIC_NUMBER; + } + + break; + + default: + MY_ERR("Invalid chipType (=0x%02x)\n", i_chipType); + return TOR_INVALID_CHIPTYPE; + } + + return TOR_SUCCESS; +} + + +int ringid_get_properties( ChipType_t i_chipType, + uint32_t i_torMagic, + ChipletType_t i_chiplet, + ChipletData_t** o_chipletData, + GenRingIdList** o_ringIdListCommon, + GenRingIdList** o_ringIdListInstance, + RingVariantOrder** o_ringVariantOrder, + RingProperties_t** o_ringProps, + uint8_t* o_numVariants ) +{ + switch (i_chipType) + { + case CT_P9N: + case CT_P9C: + if ( i_torMagic == TOR_MAGIC_SBE || + i_torMagic == TOR_MAGIC_OVRD || + i_torMagic == TOR_MAGIC_OVLY ) + { + P9_RID::ringid_get_chiplet_properties( + i_chiplet, + o_chipletData, + o_ringIdListCommon, + o_ringIdListInstance, + o_ringVariantOrder, + o_numVariants ); + + if ( i_torMagic == TOR_MAGIC_OVRD || + i_torMagic == TOR_MAGIC_OVLY ) + { + *o_numVariants = 1; + } + } + else if ( i_torMagic == TOR_MAGIC_CME ) + { + *o_chipletData = (ChipletData_t*)&P9_RID::EC::g_chipletData; + *o_ringIdListCommon = (GenRingIdList*)P9_RID::EC::RING_ID_LIST_COMMON; + *o_ringIdListInstance = (GenRingIdList*)P9_RID::EC::RING_ID_LIST_INSTANCE; + *o_ringVariantOrder = (RingVariantOrder*)P9_RID::EC::RING_VARIANT_ORDER; + *o_numVariants = P9_RID::EC::g_chipletData.iv_num_ring_variants; + } + else if ( i_torMagic == TOR_MAGIC_SGPE ) + { + *o_chipletData = (ChipletData_t*)&P9_RID::EQ::g_chipletData; + *o_ringIdListCommon = (GenRingIdList*)P9_RID::EQ::RING_ID_LIST_COMMON; + *o_ringIdListInstance = (GenRingIdList*)P9_RID::EQ::RING_ID_LIST_INSTANCE; + *o_ringVariantOrder = (RingVariantOrder*)P9_RID::EQ::RING_VARIANT_ORDER; + *o_numVariants = P9_RID::EQ::g_chipletData.iv_num_ring_variants; + } + else + { + MY_ERR("Invalid torMagic (=0x%08x) for chipType=CT_P9x=%d\n", i_torMagic, i_chipType); + return TOR_INVALID_MAGIC_NUMBER; + } + + *o_ringProps = (RingProperties_t*)P9_RID::RING_PROPERTIES; + + break; + + case CT_CEN: + if ( i_torMagic == TOR_MAGIC_CEN || + i_torMagic == TOR_MAGIC_OVRD ) + { + CEN_RID::ringid_get_chiplet_properties( + i_chiplet, + o_chipletData, + o_ringIdListCommon, + o_ringIdListInstance, + o_ringVariantOrder, + o_numVariants ); + + if ( i_torMagic == TOR_MAGIC_OVRD) + { + *o_numVariants = 1; + } + } + else + { + MY_ERR("Invalid torMagic (=0x%08x) for chipType=CT_CEN\n", i_torMagic); + return TOR_INVALID_MAGIC_NUMBER; + } + + *o_ringProps = (RingProperties_t*)CEN_RID::RING_PROPERTIES; + + break; + + default: + MY_ERR("Invalid chipType (=0x%02x)\n", i_chipType); + return TOR_INVALID_CHIPTYPE; + + } + + return TOR_SUCCESS; +} diff --git a/src/import/chips/common/utils/imageProcs/common_ringId.H b/src/import/chips/common/utils/imageProcs/common_ringId.H index 7d7efdd2..8da6a095 100644 --- a/src/import/chips/common/utils/imageProcs/common_ringId.H +++ b/src/import/chips/common/utils/imageProcs/common_ringId.H @@ -29,8 +29,12 @@ #include #include + +//////////////////////////////////////////////////////////////////////////////// +// Declare assumptions - Begin // -// Various data typedefs for enums. Serves following purposes: + +// Various data type defs for enums. Serves following purposes: // - Reduces space since enum defaults to an int type. // - Enables using these types without the scope operator for // those enums that are namespaced, e.g. RingID. @@ -43,11 +47,91 @@ typedef uint8_t PpeType_t; // Type for PpeType typedef uint8_t ChipType_t; // Type for ChipType enum typedef uint8_t RingType_t; // Type for RingType enum typedef uint8_t RingVariant_t; // Type for RingVariant enum +typedef uint32_t TorCpltOffset_t; // Type for offset value to chiplet's CMN or INST section + +#define UNDEFINED_RING_ID (RingId_t)0xffff +#define INVALID_RING_TYPE (RingType_t)0xff +#define INVALID_CHIPLET_TYPE (ChipletType_t)0xff +#define UNDEFINED_CHIP_TYPE (ChipType_t)0xff +#define MAX_TOR_RING_OFFSET (uint16_t)(256*256-1) // Max val of uint16 +#define MAX_RING_NAME_LENGTH (uint8_t)50 +#define UNDEFINED_DD_LEVEL (uint8_t)0xff + +// +// Declare assumptions - End +/////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +// TOR layout definitions - Begin +// + +// +// TOR header field (appears in top of every HW, SBE, CEN, OVRD, etc ring section) +// +typedef struct +{ + uint32_t magic; + uint8_t version; + ChipType_t chipType; // Value from ChipType enum + uint8_t ddLevel; // =0xff if MAGIC_HW, >0 all other MAGICs + uint8_t numDdLevels; // >0 if MAGIC_HW, =1 all other MAGICs + uint32_t size; // Size of the TOR ringSection. +} TorHeader_t; + +// +// Subsequent TOR fields (listed in order they appear in TOR ringSections) +// +typedef struct +{ + uint32_t offset; + uint32_t size; + uint8_t ddLevel; + uint8_t reserved[3]; +} TorDdBlock_t; + +typedef struct +{ + uint32_t offset; + uint32_t size; +} TorPpeBlock_t; + +typedef struct +{ + TorCpltOffset_t cmnOffset; + TorCpltOffset_t instOffset; +} TorCpltBlock_t; + +typedef uint16_t TorRingOffset_t; // Offset value to actual ring + +// +// TOR layout definitions - End +/////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +// Key TOR constants - Begin +// + +#define TOR_VERSION 4 + +// TOR Magic values for top-level TOR ringSection and sub-ringSections +enum TorMagicNum +{ + TOR_MAGIC = (uint32_t)0x544F52 , // "TOR" + TOR_MAGIC_HW = (uint32_t)0x544F5248, // "TORH" + TOR_MAGIC_SBE = (uint32_t)0x544F5242, // "TORB" + TOR_MAGIC_SGPE = (uint32_t)0x544F5247, // "TORG" + TOR_MAGIC_CME = (uint32_t)0x544F524D, // "TORM" + TOR_MAGIC_OVRD = (uint32_t)0x544F5252, // "TORR" + TOR_MAGIC_OVLY = (uint32_t)0x544F524C, // "TORL" + TOR_MAGIC_CEN = (uint32_t)0x544F524E, // "TORN" +}; + +// +// Key TOR constants - End +/////////////////////////////////////////////////////////////////////////////// -#define INVALID_RING_ID (RingId_t)0xffff -#define INVALID_RING_TYPE (RingType_t)0xff -#define INVALID_CHIP_TYPE (ChipType_t)0xff -#define INVALID_CHIPLET_TYPE (ChipletType_t)0xff // // Chip types and List to represent p9n, p9c, cen (centaur) @@ -102,17 +186,32 @@ typedef struct uint32_t scanScomAddress; } GenRingIdList; +// PPE types supported. Note that this enum also reflects the +// order with which they appear in the HW image's .rings section. +enum PpeType +{ + PT_SBE = 0x00, + PT_CME = 0x01, + PT_SGPE = 0x02, + NUM_PPE_TYPES = 0x03 +}; + +// Do NOT make changes to the values or order of this enum. Some user +// codes, like xip_tool, make assumptions about range and order. enum RingVariant { BASE = 0x00, CC = 0x01, RL = 0x02, - OVERRIDE = 0x03, //@FIXME We should remove this. Its own image now. + OVERRIDE = 0x03, OVERLAY = 0x04, //@FIXME Not supported. NUM_RING_VARIANTS = 0x05, NOT_VALID = 0xff }; +extern const char* ppeTypeName[]; +extern const char* ringVariantName[]; + typedef struct { RingVariant_t variant[3]; @@ -156,20 +255,68 @@ typedef struct // This structure is needed for mapping a RingID to it's corresponding name. // The names will be used by the build scripts when generating the TOR. -#ifndef __PPE__ -struct RingProperties_t +typedef struct { uint8_t iv_torOffSet; +#ifndef __PPE__ char iv_name[50]; - ChipletType_t iv_type; -}; -#else -struct RingProperties_t -{ - uint8_t iv_torOffSet; - ChipletType_t iv_type; -}; #endif + ChipletType_t iv_type; +} RingProperties_t; + + +// +// Universal infrastructure error codes +// +#define INFRASTRUCT_RC_SUCCESS 0 +#define INFRASTRUCT_RC_FAILURE 1 +#define INFRASTRUCT_RC_CODE_BUG 2 +#define INFRASTRUCT_RC_USER_ERROR 3 +#define INFRASTRUCT_RC_NOOF_CODES 5 // Do not use as RC code +// +// TOR specific error codes +// +#define TOR_SUCCESS INFRASTRUCT_RC_SUCCESS +#define TOR_FAILURE INFRASTRUCT_RC_FAILURE +#define TOR_CODE_BUG INFRASTRUCT_RC_CODE_BUG +#define TOR_USER_ERROR INFRASTRUCT_RC_USER_ERROR +#define TOR_INVALID_MAGIC_NUMBER INFRASTRUCT_RC_NOOF_CODES + 1 +#define TOR_INVALID_CHIPTYPE INFRASTRUCT_RC_NOOF_CODES + 3 +#define TOR_INVALID_CHIPLET INFRASTRUCT_RC_NOOF_CODES + 4 +#define TOR_INVALID_VARIANT INFRASTRUCT_RC_NOOF_CODES + 5 +#define TOR_INVALID_RING_ID INFRASTRUCT_RC_NOOF_CODES + 6 +#define TOR_INVALID_INSTANCE_ID INFRASTRUCT_RC_NOOF_CODES + 7 +#define TOR_INVALID_RING_BLOCK_TYPE INFRASTRUCT_RC_NOOF_CODES + 8 +#define TOR_UNSUPPORTED_RING_SECTION INFRASTRUCT_RC_NOOF_CODES + 9 +#define TOR_RING_NOT_FOUND INFRASTRUCT_RC_NOOF_CODES + 10 +#define TOR_AMBIGUOUS_API_PARMS INFRASTRUCT_RC_NOOF_CODES + 11 +#define TOR_SECTION_NOT_FOUND INFRASTRUCT_RC_NOOF_CODES + 12 +#define TOR_DD_LEVEL_NOT_FOUND INFRASTRUCT_RC_NOOF_CODES + 13 +#define TOR_OP_BUFFER_INVALID INFRASTRUCT_RC_NOOF_CODES + 14 +#define TOR_OP_BUFFER_SIZE_EXCEEDED INFRASTRUCT_RC_NOOF_CODES + 15 +#define TOR_IMAGE_DOES_NOT_SUPPORT_CME INFRASTRUCT_RC_NOOF_CODES + 16 +#define TOR_IMAGE_DOES_NOT_SUPPORT_SGPE INFRASTRUCT_RC_NOOF_CODES + 17 +#define TOR_IMAGE_DOES_NOT_SUPPORT_DD_LEVEL INFRASTRUCT_RC_NOOF_CODES + 18 +#define TOR_IMAGE_DOES_NOT_SUPPORT_PPE_LEVEL INFRASTRUCT_RC_NOOF_CODES + 19 +#define TOR_RING_AVAILABLE_IN_RINGSECTION INFRASTRUCT_RC_NOOF_CODES + 20 +#define TOR_BUFFER_TOO_SMALL INFRASTRUCT_RC_NOOF_CODES + 21 +#define TOR_TOO_MANY_DD_LEVELS INFRASTRUCT_RC_NOOF_CODES + 22 +#define TOR_OFFSET_TOO_BIG INFRASTRUCT_RC_NOOF_CODES + 23 + + +int ringid_get_noof_chiplets( ChipType_t i_chipType, + uint32_t i_torMagic, + uint8_t* o_numChiplets ); + +int ringid_get_properties( ChipType_t i_chipType, + uint32_t i_torMagic, + ChipletType_t i_chiplet, + ChipletData_t** o_chipletData, + GenRingIdList** o_ringIdListCommon, + GenRingIdList** o_ringIdListInstance, + RingVariantOrder** o_ringVariantOrder, + RingProperties_t** o_ringProps, + uint8_t* o_numVariants ); #endif // _COMMON_RINGID_H_ diff --git a/src/import/chips/p9/utils/imageProcs/p9_infrastruct_help.H b/src/import/chips/p9/utils/imageProcs/p9_infrastruct_help.H index 2e54efc8..61bc6857 100644 --- a/src/import/chips/p9/utils/imageProcs/p9_infrastruct_help.H +++ b/src/import/chips/p9/utils/imageProcs/p9_infrastruct_help.H @@ -53,14 +53,13 @@ const uint32_t MAX_HBBL_SIZE = 20 * 1024; // Max hbbl section siz const uint32_t MAX_NOOF_DD_LEVELS_IN_IMAGE = 20; //@FIXME: CMO: Aren't these defined somewhere else? -#define NUM_OF_CORES 24 -#define NUM_OF_CMES 12 -#define NUM_OF_QUADS 6 -#define CORES_PER_QUAD (NUM_OF_CORES/NUM_OF_QUADS) +#define NUM_OF_CORES (uint8_t)24 +#define NUM_OF_CMES (uint8_t)12 +#define NUM_OF_QUADS (uint8_t) 6 +#define CORES_PER_QUAD (NUM_OF_CORES/NUM_OF_QUADS) -#define INFRASTRUCT_RC_SUCCESS 0 -#define INFRASTRUCT_RC_CODE_BUG 1 -#define INFRASTRUCT_RC_INVALID_IMAGE_SECTION_TYPE 2 +#define INSTANCE_ID_MIN (uint8_t)0x01 +#define INSTANCE_ID_MAX (uint8_t)0x37 enum SYSPHASE { diff --git a/src/import/chips/p9/utils/imageProcs/p9_ringId.C b/src/import/chips/p9/utils/imageProcs/p9_ringId.C index 8356f8ed..b73b8c71 100644 --- a/src/import/chips/p9/utils/imageProcs/p9_ringId.C +++ b/src/import/chips/p9/utils/imageProcs/p9_ringId.C @@ -618,7 +618,7 @@ void P9_RID::ringid_get_chiplet_properties( } } -GenRingIdList* P9_RID::ringid_get_ring_properties(RingId_t i_ringId) +GenRingIdList* P9_RID::ringid_get_ring_list(RingId_t i_ringId) { ChipletData_t* l_cpltData; GenRingIdList* l_ringList[2]; // 0: common, 1: instance diff --git a/src/import/chips/p9/utils/imageProcs/p9_ringId.H b/src/import/chips/p9/utils/imageProcs/p9_ringId.H index 3b9cccb2..8f0a2588 100644 --- a/src/import/chips/p9/utils/imageProcs/p9_ringId.H +++ b/src/import/chips/p9/utils/imageProcs/p9_ringId.H @@ -37,6 +37,7 @@ #include #endif + enum CHIPLET_TYPE { PERV_TYPE, @@ -58,8 +59,8 @@ enum CHIPLET_TYPE SBE_NOOF_CHIPLETS }; -#define SGPE_NOOF_CHIPLETS 1 -#define CME_NOOF_CHIPLETS 1 +const ChipletType_t CME_NOOF_CHIPLETS = 1; +const ChipletType_t SGPE_NOOF_CHIPLETS = 1; namespace PERV { @@ -1233,8 +1234,7 @@ static const RingProperties_t RING_PROPERTIES[NUM_RING_IDS] = // Returns our own chiplet enum value for this ringId ChipletType_t -ringid_get_chiplet( - RingId_t i_ringId); +ringid_get_chiplet(RingId_t i_ringId); // Returns data structures defined for chiplet type // as determined by ringId @@ -1249,8 +1249,7 @@ ringid_get_chiplet_properties( // Returns properties of a ring as determined by ringId GenRingIdList* -ringid_get_ring_properties( - RingId_t i_ringId); +ringid_get_ring_list(RingId_t i_ringId); #endif diff --git a/src/import/chips/p9/utils/imageProcs/p9_tor.C b/src/import/chips/p9/utils/imageProcs/p9_tor.C index 33007852..ea454c0c 100644 --- a/src/import/chips/p9/utils/imageProcs/p9_tor.C +++ b/src/import/chips/p9/utils/imageProcs/p9_tor.C @@ -29,1080 +29,251 @@ #include #endif -// IMPORTANT notice on usage of io_RingType and io_instanceId arguments -// -// io_RingTyp -// ------------- -// While using tor_access_ring API, it is used as pass by reference -// While using tor_get_block_of_rings API, it is used as pass by value -// io_instanceId -// -------------- -// While using tor_access_ring API, it is used as pass by reference. -// While using tor_tor_get_block_of_rings and tor_get_single_ring API, -// it is used pass by value -// #include "p9_tor.H" -namespace P9_RID -{ -#include "p9_ringId.H" -} -namespace CEN_RID -{ -#include "cen_ringId.H" -} #include "p9_scan_compression.H" #include "p9_infrastruct_help.H" -// These strings must adhere precisely to the enum of PpeType. -const char* ppeTypeName[] = { "SBE", - "CME", - "SGPE" - }; - -// These strings must adhere precisely to the enum of RingVariant. -const char* ringVariantName[] = { "BASE", - "CC", - "RL", - "OVRD", - "OVLY" - }; - - /////////////////////////////////////////////////////////////////////////////////// // -// GET RING FROM SBE IMAGE FUNCTION +// GET RING FROM SECTION FUNCTION // -////////////////////////////////////////////////////////////////////////////////// -static -int get_ring_from_sbe_image( void* i_ringSection, // Ring section ptr - RingId_t i_ringId, // Ring ID - uint16_t i_ddLevelOffset, // DD level offset (wrt i_ringSection) - RingType_t& io_RingType, // Common, Instance - RingVariant_t i_RingVariant, // Base,CC, RL, Ovrd, Ovly - uint8_t& io_instanceId, // Instance ID - RingBlockType_t i_RingBlockType, // Single ring, Block - void** io_ringBlockPtr, // Output ring buffer - uint32_t& io_ringBlockSize, // Size of ring data - char* o_ringName, // Name of ring - uint32_t i_dbgl ) // Debug option -{ - int rc = TOR_SUCCESS; - uint32_t torMagic = 0xffffffff; - ChipType_t chipType = INVALID_CHIP_TYPE; - uint32_t tor_slot_no = 0; // TOR slot number (within a TOR chiplet section) - uint16_t dd_level_offset; // Local DD level offset, if any (wrt i_ringSection) - uint32_t acc_offset = 0; // Accumulating offset to next TOR offset - uint32_t ppe_offset = 0; // Local offset to where SBE PPE ring section starts - uint32_t ppe_cplt_offset = 0; // Local offset to where the pool of chiplets starts - uint32_t cplt_offset = 0; // Local offset to where a specific chiplet section starts - uint16_t ring_offset = 0; // Local offset to where SBE ring container/block starts - uint32_t ring_size = 0; // Size of whole ring container/block. - RingVariantOrder* ring_variant_order; - GenRingIdList* ring_id_list_common; - GenRingIdList* ring_id_list_instance; - ChipletData_t* l_cpltData; - uint8_t l_num_variant; - ChipletType_t numChiplets = 0; - const RingProperties_t* ringProperties; - - torMagic = be32toh( ((TorHeader_t*)i_ringSection)->magic ); - chipType = ((TorHeader_t*)i_ringSection)->chipType; - - // Calculate the offset (wrt start of ringSection) to the SBE PPE - // ring section. This offset, ppe_offset, will point to the - // TORB header of the SBE PPE ring section. - if (torMagic == TOR_MAGIC_HW) - { - dd_level_offset = i_ddLevelOffset; - ppe_offset = *(uint32_t*)((uint8_t*)i_ringSection + dd_level_offset); - ppe_offset = be32toh(ppe_offset); - numChiplets = P9_RID::SBE_NOOF_CHIPLETS; - ringProperties = &P9_RID::RING_PROPERTIES[0]; - } - else if (torMagic == TOR_MAGIC_SBE || - (torMagic == TOR_MAGIC_OVRD && (chipType == CT_P9N || chipType == CT_P9C)) || - torMagic == TOR_MAGIC_OVLY) - { - ppe_offset = 0; - dd_level_offset = 0; - numChiplets = P9_RID::SBE_NOOF_CHIPLETS; - ringProperties = &P9_RID::RING_PROPERTIES[0]; - } - else if (torMagic == TOR_MAGIC_CEN || - (torMagic == TOR_MAGIC_OVRD && chipType == CT_CEN)) - { - ppe_offset = 0; - dd_level_offset = 0; - numChiplets = CEN_RID::CEN_NOOF_CHIPLETS; - ringProperties = &CEN_RID::RING_PROPERTIES[0]; - } - else - { - MY_ERR("torMagic=0x%08x is not valid for SBE\n", torMagic); - return TOR_INVALID_MAGIC_NUMBER; - } - - // Calculate the offset (wrt start of ringSection) to where the - // pool of chiplet offsets begins in the SBE PPE ring section, - // which is right after the TORB header. - ppe_cplt_offset = ppe_offset + sizeof(TorHeader_t); - - // Looper for each SBE chiplet - for (ChipletType_t iCplt = 0; iCplt < numChiplets; iCplt++) - { - if (torMagic == TOR_MAGIC_CEN || - (torMagic == TOR_MAGIC_OVRD && chipType == CT_CEN)) - { - CEN_RID::ringid_get_chiplet_properties( - iCplt, - &l_cpltData, - &ring_id_list_common, - &ring_id_list_instance, - &ring_variant_order, - &l_num_variant); - } - else - { - P9_RID::ringid_get_chiplet_properties( - iCplt, - &l_cpltData, - &ring_id_list_common, - &ring_id_list_instance, - &ring_variant_order, - &l_num_variant); - } - - if (!ring_id_list_common && !ring_id_list_instance) - { - MY_ERR("Chiplet=%d is not valid for SBE. \n", iCplt); - return TOR_INVALID_CHIPLET; - } - - l_num_variant = (torMagic == TOR_MAGIC_OVRD || torMagic == TOR_MAGIC_OVLY) ? 1 : l_num_variant; - - if (i_dbgl > 1) - { - MY_INF(" No of CommonRing %d, No of InstanceRing %d, No of Variants %d \n", - l_cpltData->iv_num_common_rings, l_cpltData->iv_num_instance_rings, - l_num_variant); - } - - - // - // Sequentially walk the TOR slots within the chiplet's COMMON section - // - tor_slot_no = 0; - - for (uint8_t i = 0; i < l_cpltData->iv_num_common_rings ; i++) - { - for (uint8_t iVariant = 0; iVariant < l_num_variant ; iVariant++) - { - if (i_dbgl > 2) - { - MY_INF(" Ring %s Cplt common ring id %d Variant id %d\n", - (ring_id_list_common + i)->ringName, i, iVariant); - } - - if ( ( strcmp( (ring_id_list_common + i)->ringName, - ringProperties[i_ringId].iv_name) == 0 ) && - ( i_RingVariant == ring_variant_order->variant[iVariant] || - torMagic == TOR_MAGIC_OVRD || - torMagic == TOR_MAGIC_OVLY ) ) - { - strcpy(o_ringName, ringProperties[i_ringId].iv_name); - acc_offset = dd_level_offset + - ppe_cplt_offset + - iCplt * sizeof(TorPpeBlock_t); - cplt_offset = *(uint32_t*)( (uint8_t*)i_ringSection + - acc_offset ); - cplt_offset = be32toh(cplt_offset); - acc_offset = dd_level_offset + ppe_cplt_offset + cplt_offset; - ring_offset = *(uint16_t*)( (uint8_t*)i_ringSection + - acc_offset + - tor_slot_no * sizeof(ring_offset) ); - ring_offset = be16toh(ring_offset); - - if (i_RingBlockType == GET_SINGLE_RING) - { - acc_offset = dd_level_offset + - ppe_cplt_offset + - cplt_offset + - ring_offset; - ring_size = be16toh( ((CompressedScanData*) - ((uint8_t*)i_ringSection + acc_offset))->iv_size ); - io_RingType = COMMON_RING; - - if (ring_offset) - { - if (io_ringBlockSize == 0) - { - if (i_dbgl > 0) - { - MY_INF("\tio_ringBlockSize is zero. Returning required size.\n"); - } - - io_ringBlockSize = ring_size; - return 0; - } - - if (io_ringBlockSize < ring_size) - { - MY_ERR("\tio_ringBlockSize is less than required size.\n"); - return TOR_BUFFER_TOO_SMALL; - } - - if (i_dbgl > 0) - { - MY_INF(" Ring %s found in the SBE section \n", o_ringName); - } - - memcpy( (uint8_t*)(*io_ringBlockPtr), (uint8_t*)i_ringSection + acc_offset, - (size_t)ring_size); - - io_ringBlockSize = ring_size; - io_instanceId = (ring_id_list_common + i)->instanceIdMin; - - rc = TOR_RING_FOUND; - } - else - { - if (i_dbgl > 0) - { - MY_INF(" Ring %s not found in the SBE section \n", o_ringName); - } - - rc = TOR_RING_NOT_FOUND; - } - - if (i_dbgl > 0) - { - MY_INF(" Hex details (SBE) for Chiplet #%d: \n" - " DD number section's offset to DD level section = 0x%08x \n" - " DD level section's offset to PpeType = 0x%08x \n" - " PpeType section's offset to chiplet = 0x%08x \n" - " Chiplet section's offset to RS4 header = 0x%08x \n" - " Full offset to RS4 header = 0x%08x \n" - " Ring size = 0x%08x \n", - i, dd_level_offset, ppe_cplt_offset, cplt_offset, ring_offset, acc_offset, ring_size); - } - - return rc; - - } - else if (i_RingBlockType == PUT_SINGLE_RING) - { - if (ring_offset) - { - MY_ERR("Ring container is already present in the SBE section \n"); - return TOR_RING_AVAILABLE_IN_RINGSECTION; - } - - // Special [mis]use of io_ringBlockPtr and io_ringBlockSize: - // Put location of chiplet's common section into ringBlockPtr - memcpy( (uint8_t*)(*io_ringBlockPtr), &acc_offset, sizeof(acc_offset)); - // Put location of ring_offset slot into ringBlockSize - io_ringBlockSize = acc_offset + (tor_slot_no * sizeof(ring_offset)); - - return TOR_RING_FOUND; - } - else - { - MY_ERR("Ring block type (i_RingBlockType=%d) is not supported for SBE \n", i_RingBlockType); - return TOR_INVALID_RING_BLOCK_TYPE; - } - } - - tor_slot_no++; // Next TOR slot - } - } - - - // - // Sequentially walk the TOR slots within the chiplet's INSTANCE section - // - if (ring_id_list_instance) - { - - tor_slot_no = 0; - - for ( uint8_t i = (ring_id_list_instance + 0)->instanceIdMin; - i < (ring_id_list_instance + 0)->instanceIdMax + 1 ; i++ ) - { - for (uint8_t j = 0; j < l_cpltData->iv_num_instance_rings; j++) - { - for (uint8_t iVariant = 0; iVariant < l_num_variant ; iVariant++) - { - if (i_dbgl > 2) - { - MY_INF(" Ring name %s Cplt instance ring id %d Variant id %d Instance id %d\n", - (ring_id_list_instance + j)->ringName, j, iVariant, i); - } - - if (strcmp( (ring_id_list_instance + j)->ringName, - ringProperties[i_ringId].iv_name) == 0) - { - if ( io_instanceId >= (ring_id_list_instance + 0)->instanceIdMin - && io_instanceId <= (ring_id_list_instance + 0)->instanceIdMax ) - { - if (i == io_instanceId && i_RingVariant == ring_variant_order->variant[iVariant]) - { - strcpy(o_ringName, ringProperties[i_ringId].iv_name); - - acc_offset = dd_level_offset + - ppe_cplt_offset + - iCplt * sizeof(TorPpeBlock_t) + - sizeof(cplt_offset); // Jump to instance offset - cplt_offset = *(uint32_t*)( (uint8_t*)i_ringSection + - acc_offset ); - cplt_offset = be32toh(cplt_offset); - - acc_offset = cplt_offset + - dd_level_offset + - ppe_cplt_offset; - ring_offset = *(uint16_t*)( (uint8_t*)i_ringSection + - acc_offset + - tor_slot_no * sizeof(ring_offset) ); - ring_offset = be16toh(ring_offset); - - if (i_RingBlockType == GET_SINGLE_RING) - { - acc_offset = dd_level_offset + - ppe_cplt_offset + - cplt_offset + - ring_offset; - ring_size = be16toh( ((CompressedScanData*) - ((uint8_t*)i_ringSection + - acc_offset))->iv_size ); - io_RingType = INSTANCE_RING; - - if (ring_offset) - { - if (io_ringBlockSize == 0) - { - if (i_dbgl > 0) - { - MY_INF("\tio_ringBlockSize is zero. Returning required size.\n"); - } - - io_ringBlockSize = ring_size; - return 0; - } - - if (io_ringBlockSize < ring_size) - { - MY_ERR("\tio_ringBlockSize is less than required size.\n"); - return TOR_BUFFER_TOO_SMALL; - } - - if (i_dbgl > 0) - { - MY_INF(" ring container of %s is found in the SBE image container \n", - o_ringName); - } - - memcpy( (uint8_t*)(*io_ringBlockPtr), (uint8_t*)i_ringSection + acc_offset, - (size_t)ring_size); - - io_ringBlockSize = ring_size; - - if (i_dbgl > 0) - { - MY_INF(" After get_ring_from_sbe_image Size %d \n", io_ringBlockSize); - } - - rc = TOR_RING_FOUND; - } - else - { - if (i_dbgl > 0) - { - MY_INF(" Ring %s not found in SBE section \n", o_ringName); - } - - rc = TOR_RING_NOT_FOUND; - } - - if (i_dbgl > 0) - { - MY_INF(" Hex details (SBE) for Chiplet #%d: \n" - " DD number section's offset to DD level section = 0x%08x \n" - " DD level section's offset to PpeType = 0x%08x \n" - " PpeType section's offset to chiplet = 0x%08x \n" - " Chiplet section's offset to RS4 header = 0x%08x \n" - " Full offset to RS4 header = 0x%08x \n" - " Ring size = 0x%08x \n", - i, dd_level_offset, ppe_cplt_offset, cplt_offset, ring_offset, acc_offset, ring_size); - } - - return rc; - } - else if (i_RingBlockType == PUT_SINGLE_RING) - { - if (ring_offset) - { - MY_ERR("Ring container is already present in the SBE section \n"); - return TOR_RING_AVAILABLE_IN_RINGSECTION; - } - - // Special [mis]use of io_ringBlockPtr and io_ringBlockSize: - // Put location of chiplet's instance section into ringBlockPtr - memcpy( (uint8_t*)(*io_ringBlockPtr), &acc_offset, sizeof(acc_offset)); - // Put location of ring_offset slot into ringBlockSize - io_ringBlockSize = acc_offset + (tor_slot_no * sizeof(ring_offset)); - - return TOR_RING_FOUND; - } - else - { - MY_ERR("Ring block type (i_RingBlockType=%d) is not supported for SBE \n", i_RingBlockType); - return TOR_INVALID_RING_BLOCK_TYPE; - } - } - } - else - { - if (i_dbgl > 0) - { - MY_INF(" SBE ring instance ID %d is invalid, Valid ID is from %d to %d \n", - io_instanceId, (ring_id_list_instance + 0)->instanceIdMin, - (ring_id_list_instance + 0)->instanceIdMax); - } - - return TOR_INVALID_INSTANCE_ID; - } - } - - tor_slot_no++; - } - } - } - } // if (ring_id_list_instance) - } - - if (i_dbgl > 0) - { - MY_DBG("i_ringId=0x%x is an invalid ring ID for SBE\n", i_ringId); - } - - return TOR_INVALID_RING_ID; - -} // End of get_ring_from_sbe_image() - - - -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// -// GET RING FROM SGPE IMAGE FUNCTION -// -/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -static -int get_ring_from_sgpe_image ( void* i_ringSection, // Ring section ptr - RingId_t i_ringId, // Ring ID - uint16_t i_ddLevelOffset, // DD level offset - RingType_t& io_RingType, // Common, Instance - RingVariant_t i_RingVariant, // Base,CC, RL, Ovrd, Ovly - uint8_t& io_instanceId, // Instance ID - RingBlockType_t i_RingBlockType, // Single ring, Block - void** io_ringBlockPtr, // Output ring data buffer - uint32_t& io_ringBlockSize, // Size of ring data - char* o_ringName, // Name of ring - uint32_t i_dbgl ) // Debug option -{ - uint32_t torMagic; - uint32_t acc_offset = 0; // Accumulating offset to next TOR offset slot - uint32_t ring_offset = 0; - uint16_t chiplet_offset = 0; - uint32_t ringSize = 0; - int temp = (i_ddLevelOffset >> 2) + 4; // converting byte to word counter - uint32_t spge_offset = 0; - uint32_t ppe_cplt_offset = 0; // Local offset to where the pool of chiplets starts - - torMagic = be32toh( ((TorHeader_t*)i_ringSection)->magic ); - - // Calculate the offset (wrt start of ringSection) to the SGPE PPE - // ring section. This offset, inappropriately denoted "temp" here - // but which needs to be renamed to "ppe_offset" asap, will point - // to the TORG header of the SGPE PPE ring section. - if (torMagic == TOR_MAGIC_HW) - { - spge_offset = *((uint32_t*)i_ringSection + temp); //DD level offset index - temp = be32toh(spge_offset); - } - else if (torMagic == TOR_MAGIC_SGPE) - { - spge_offset = 0; - i_ddLevelOffset = 0; - temp = be32toh(spge_offset); - } - else - { - MY_ERR("torMagic=0x%08x is not valid for SGPE\n", torMagic); - return TOR_INVALID_MAGIC_NUMBER; - } - - // Calculate the offset (wrt start of ringSection) to where the - // pool of chiplet offsets begins in the SGPE PPE ring section, - // which is right after the TORG header. - ppe_cplt_offset = temp + sizeof(TorHeader_t); - - GenRingIdList* ring_id_list_common = NULL; - GenRingIdList* ring_id_list_instance = NULL; - uint8_t l_num_variant = P9_RID::EQ::g_chipletData.iv_num_ring_variants; - ring_id_list_common = (GenRingIdList*) P9_RID::EQ::RING_ID_LIST_COMMON; - ring_id_list_instance = (GenRingIdList*) P9_RID::EQ::RING_ID_LIST_INSTANCE; - - uint32_t local = 0; - - for (uint8_t i = 0; i < P9_RID::EQ::g_chipletData.iv_num_common_rings ; i++) - { - for (uint8_t j = 0; j < l_num_variant ; j++) - { - if (i_dbgl > 2) - { - MY_INF(" Ring %s Cplt common ring id %d Variant id %d\n", - (ring_id_list_common + i)->ringName, i, j); - } - - if ((strcmp( (ring_id_list_common + i)->ringName, - P9_RID::RING_PROPERTIES[i_ringId].iv_name) == 0) && ( i_RingVariant == j )) - { - strcpy(o_ringName, P9_RID::RING_PROPERTIES[i_ringId].iv_name); - uint32_t var = 0 + i_ddLevelOffset + ppe_cplt_offset; - int temp1 = var / sizeof(uint32_t); - ring_offset = *((uint32_t*)i_ringSection + temp1); - ring_offset = be32toh(ring_offset); - var = ring_offset + i_ddLevelOffset + ppe_cplt_offset; - temp1 = var / sizeof(uint16_t) + local; - chiplet_offset = *((uint16_t*)i_ringSection + temp1); - chiplet_offset = be16toh(chiplet_offset); - - if (i_RingBlockType == GET_SINGLE_RING) - { - var = ring_offset + chiplet_offset + i_ddLevelOffset + ppe_cplt_offset; - ringSize = be16toh( ((CompressedScanData*) - ((uint8_t*)i_ringSection + - var))->iv_size ); - io_RingType = COMMON_RING; - - if (chiplet_offset) - { - if (io_ringBlockSize == 0) - { - if (i_dbgl > 0) - { - MY_INF("\tio_ringBlockSize is zero. Returning required size.\n"); - } - - io_ringBlockSize = ringSize; - return 0; - } - - if (io_ringBlockSize < ringSize) - { - MY_ERR("\tio_ringBlockSize is less than required size.\n"); - return TOR_BUFFER_TOO_SMALL; - } - - if (i_dbgl > 0) - { - MY_INF(" Ring %s found in the SGPE section \n", o_ringName); - } - - memcpy( (uint8_t*)(*io_ringBlockPtr), (uint8_t*)i_ringSection + var, - (size_t)ringSize); - - io_ringBlockSize = ringSize; - io_instanceId = (ring_id_list_common + i)->instanceIdMin; - - if (i_dbgl > 0) - { - MY_INF(" Hex details (SGPE): Chiplet #%d offset 0x%08x local offset 0x%08x " \ - "ring offset 0x%08x start adr 0x%08x ringSize=0x%08x \n", - i, var, ppe_cplt_offset, ring_offset, chiplet_offset, ringSize); - } - - return TOR_RING_FOUND; - } - else - { - if (i_dbgl > 0) - { - MY_INF(" Ring %s not found in the SGPE section \n", o_ringName); - } - - return TOR_RING_NOT_FOUND; - } - } - else if (i_RingBlockType == PUT_SINGLE_RING) - { - if (chiplet_offset) - { - MY_ERR("Ring container is already present in the SGPE section \n"); - return TOR_RING_AVAILABLE_IN_RINGSECTION; - } - - acc_offset = var; - io_ringBlockSize = acc_offset + (local * RING_OFFSET_SIZE); - memcpy( (uint8_t*)(*io_ringBlockPtr), &acc_offset, sizeof(acc_offset)); - - return TOR_RING_FOUND; - } - else - { - MY_ERR("Ring block type (i_RingBlockType=%d) is not supported for SGPE \n", i_RingBlockType); - return TOR_INVALID_RING_BLOCK_TYPE; - } - } - - local++; - } - - } - - // Instance specific single ring extract loop - local = 0; - - for(uint8_t i = (ring_id_list_instance + 0)->instanceIdMin; - i < (ring_id_list_instance + 0)->instanceIdMax + 1 ; i++) - { - for (uint8_t j = 0; j < P9_RID::EQ::g_chipletData.iv_num_instance_rings; j++) - { - for(uint8_t k = 0; k < l_num_variant ; k++) - { - if (i_dbgl > 2) - { - MY_INF(" Ring name %s Cplt instance ring id %d Variant id %d", - (ring_id_list_instance + j)->ringName, j, k); - } - - if (strcmp( (ring_id_list_instance + j)->ringName, - P9_RID::RING_PROPERTIES[i_ringId].iv_name) == 0) - { - if ( io_instanceId >= (ring_id_list_instance + 0)->instanceIdMin - && io_instanceId <= (ring_id_list_instance + 0)->instanceIdMax ) - { - if ( i == io_instanceId && k == i_RingVariant ) - { - strcpy(o_ringName, P9_RID::RING_PROPERTIES[i_ringId].iv_name); - uint32_t var = CPLT_OFFSET_SIZE + i_ddLevelOffset + ppe_cplt_offset; - int temp1 = var / sizeof(uint32_t); - ring_offset = *((uint32_t*)i_ringSection + temp1); - ring_offset = be32toh(ring_offset); - var = ring_offset + i_ddLevelOffset + ppe_cplt_offset; - temp1 = var / sizeof(uint16_t) + local; - chiplet_offset = *((uint16_t*)i_ringSection + temp1); - chiplet_offset = be16toh(chiplet_offset); - - if (i_RingBlockType == GET_SINGLE_RING) - { - var = ring_offset + chiplet_offset + i_ddLevelOffset + ppe_cplt_offset; - ringSize = be16toh( ((CompressedScanData*) - ((uint8_t*)i_ringSection + - var))->iv_size ); - io_RingType = INSTANCE_RING; - - if (chiplet_offset) - { - if (io_ringBlockSize == 0) - { - if (i_dbgl > 0) - { - MY_INF("\tio_ringBlockSize is zero. Returning required size.\n"); - } - - io_ringBlockSize = ringSize; - return 0; - } - - if (io_ringBlockSize < ringSize) - { - MY_ERR("\tio_ringBlockSize is less than required size.\n"); - return TOR_BUFFER_TOO_SMALL; - } - - if (i_dbgl > 0) - { - MY_INF(" ring container of %s is found in the SGPE image container \n", - o_ringName); - } - - memcpy( (uint8_t*)(*io_ringBlockPtr), (uint8_t*)i_ringSection + var, - (size_t)ringSize); - - io_ringBlockSize = ringSize; - - if (i_dbgl > 0) - { - MY_INF(" After get_ring_from_sgpe_image Size %d \n", io_ringBlockSize); - } - - if (i_dbgl > 0) - { - MY_INF(" Hex details (SGPE): Chiplet #%d offset 0x%08x local offset 0x%08x " \ - "ring offset 0x%08x start adr 0x%08x ringSize=0x%08x \n", - i, var, ppe_cplt_offset, ring_offset, chiplet_offset, ringSize); - } - - return TOR_RING_FOUND; - } - else - { - if (i_dbgl > 0) - { - MY_INF(" ring container of %s is not found in the SGPE image container \n", - o_ringName); - } - - return TOR_RING_NOT_FOUND; - } - } - else if (i_RingBlockType == PUT_SINGLE_RING) - { - if (chiplet_offset) - { - MY_ERR("Ring container is already present in the SGPE section \n"); - return TOR_RING_AVAILABLE_IN_RINGSECTION; - } - - acc_offset = var; - io_ringBlockSize = acc_offset + (local * RING_OFFSET_SIZE); - memcpy( (uint8_t*)(*io_ringBlockPtr), &acc_offset, sizeof(acc_offset)); - - return TOR_RING_FOUND; - } - else - { - MY_ERR("Ring block type (i_RingBlockType=%d) is not supported for SGPE \n", i_RingBlockType); - return TOR_INVALID_RING_BLOCK_TYPE; - } - } - } - else - { - if (i_dbgl > 0) - { - MY_INF("SGPE ring instance ID %d is invalid, Valid ID is from %d to %d \n", - io_instanceId, (ring_id_list_instance + 0)->instanceIdMin, - (ring_id_list_instance + 0)->instanceIdMax); - } - - return TOR_INVALID_INSTANCE_ID; - } - } - - local++; - } - } - } - - return TOR_INVALID_RING_ID; - -} // End of get_ring_from_sgpe_image() - - - -///////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// -// GET RING FROM CME IMAGE FUNCTION -// -///////////////////////////////////////////////////////////////////////////////////////////////////////////////// -static -int get_ring_from_cme_image ( void* i_ringSection, // Ring section ptr - RingId_t i_ringId, // Ring ID - uint16_t i_ddLevelOffset, // DD level offset - RingType_t& io_RingType, // Common, Instance - RingVariant_t i_RingVariant, // Base,CC, RL, Ovrd, Ovly - uint8_t& io_instanceId, // instance ID - RingBlockType_t i_RingBlockType, // Single ring, Block - void** io_ringBlockPtr, // Output ring data buffer - uint32_t& io_ringBlockSize, // Size of ring data - char* o_ringName, // Name of ring - uint32_t i_dbgl ) // Debug option -{ - uint32_t torMagic; - uint32_t acc_offset = 0; // Accumulating offset to next TOR offset slot - uint32_t ring_offset = 0; - uint16_t chiplet_offset = 0; - uint32_t ringSize = 0; - int temp = (i_ddLevelOffset >> 2) + 2; // converting byte to word counter - uint32_t cme_offset = 0; - uint32_t ppe_cplt_offset = 0; // Local offset to where the pool of chiplets starts - - torMagic = be32toh( ((TorHeader_t*)i_ringSection)->magic ); - - if (torMagic == TOR_MAGIC_HW) - { - cme_offset = *((uint32_t*)i_ringSection + temp); //DD level offset index - temp = be32toh(cme_offset); - } - else if (torMagic == TOR_MAGIC_CME) - { - cme_offset = 0; - i_ddLevelOffset = 0; - temp = be32toh(cme_offset); - } - else - { - MY_ERR("torMagic=0x%08x is not valid for CME\n", torMagic); - return TOR_INVALID_MAGIC_NUMBER; - } - - // Calculate the offset (wrt start of ringSection) to where the - // pool of chiplet offsets begins in the CME PPE ring section, - // which is right after the TORC header. - ppe_cplt_offset = temp + sizeof(TorHeader_t); - - GenRingIdList* ring_id_list_common = NULL; - GenRingIdList* ring_id_list_instance = NULL; - uint8_t l_num_variant = P9_RID::EC::g_chipletData.iv_num_ring_variants; - ring_id_list_common = (GenRingIdList*) P9_RID::EC::RING_ID_LIST_COMMON; - ring_id_list_instance = (GenRingIdList*) P9_RID::EC::RING_ID_LIST_INSTANCE; - - uint32_t local = 0; - - for (uint8_t i = 0; i < P9_RID::EC::g_chipletData.iv_num_common_rings ; i++) - { - for (uint8_t j = 0; j < l_num_variant ; j++) - { - if (i_dbgl > 2) - { - MY_INF(" Ring %s Cplt common ring id %d Variant id %d\n", - (ring_id_list_common + i)->ringName, i, j); - } - - if ((strcmp( (ring_id_list_common + i)->ringName, - P9_RID::RING_PROPERTIES[i_ringId].iv_name) == 0) && ( i_RingVariant == j )) - { - strcpy(o_ringName, P9_RID::RING_PROPERTIES[i_ringId].iv_name); - uint32_t var = 0 + i_ddLevelOffset + ppe_cplt_offset; - int temp1 = var / sizeof(uint32_t); - ring_offset = *((uint32_t*)i_ringSection + temp1); - ring_offset = be32toh(ring_offset); - var = ring_offset + i_ddLevelOffset + ppe_cplt_offset; - temp1 = var / sizeof(uint16_t) + local; - chiplet_offset = *((uint16_t*)i_ringSection + temp1); - chiplet_offset = be16toh(chiplet_offset); - - if (i_RingBlockType == GET_SINGLE_RING) - { - var = ring_offset + chiplet_offset + i_ddLevelOffset + ppe_cplt_offset; - ringSize = be16toh( ((CompressedScanData*) - ((uint8_t*)i_ringSection + - var))->iv_size ); - io_RingType = COMMON_RING; - - if (chiplet_offset) - { - if (io_ringBlockSize == 0) - { - if (i_dbgl > 0) - { - MY_INF("\tio_ringBlockSize is zero. Returning required size.\n"); - } - - io_ringBlockSize = ringSize; - return 0; - } - - if (io_ringBlockSize < ringSize) - { - MY_ERR("\tio_ringBlockSize is less than required size.\n"); - return TOR_BUFFER_TOO_SMALL; - } - - if (i_dbgl > 0) - { - MY_INF(" Ring %s found in the CME section \n", o_ringName); - } - - memcpy( (uint8_t*)(*io_ringBlockPtr), (uint8_t*)i_ringSection + var, - (size_t)ringSize); - - io_ringBlockSize = ringSize; - io_instanceId = (ring_id_list_common + i)->instanceIdMin; - - if (i_dbgl > 0) - { - MY_INF(" Hex details (CME): Chiplet #%d offset 0x%08x local offset 0x%08x " \ - "ring offset 0x%08x start adr 0x%08x ringSize=0x%08x \n", - i, var, ppe_cplt_offset, ring_offset, chiplet_offset, ringSize); - } - - return TOR_RING_FOUND; - } - else - { - if (i_dbgl > 0) - { - MY_INF(" Ring %s not found in the CME section \n", o_ringName); - } - - return TOR_RING_NOT_FOUND; - } - } - else if (i_RingBlockType == PUT_SINGLE_RING) - { - if (chiplet_offset) - { - MY_ERR("Ring container is already present in the CME section \n"); - return TOR_RING_AVAILABLE_IN_RINGSECTION; - } +////////////////////////////////////////////////////////////////////////////////// +static +int get_ring_from_ring_section( void* i_ringSection, // Ring section ptr + RingId_t i_ringId, // Ring ID + RingVariant_t i_ringVariant, // Base,CC,RL (SBE,CME,SGPE only) + uint8_t& io_instanceId, // Instance ID + RingBlockType_t i_ringBlockType, // Single ring, Block + void** io_ringBlockPtr, // Output ring buffer + uint32_t& io_ringBlockSize, // Size of ring data + char* o_ringName, // Name of ring + uint32_t i_dbgl ) // Debug option +{ + int rc = TOR_SUCCESS; + uint8_t iInst, iRing, iVariant; + TorHeader_t* torHeader; + uint32_t torMagic; + uint8_t chipType; + TorCpltBlock_t* cpltBlock; + TorCpltOffset_t cpltOffset; // Offset from ringSection to chiplet section + TorRingOffset_t ringOffset; // Offset to actual ring container + uint32_t torSlotNum; // TOR slot number (within a chiplet section) + uint32_t ringSize; // Size of whole ring container/block. + RingVariantOrder* ringVariantOrder; + RingId_t numRings; + GenRingIdList* ringIdListCommon; + GenRingIdList* ringIdListInstance; + GenRingIdList* ringIdList; + uint8_t bInstCase = 0; + ChipletData_t* cpltData; + uint8_t numVariants; + ChipletType_t numChiplets; + RingProperties_t* ringProps; - acc_offset = var; - io_ringBlockSize = acc_offset + (local * RING_OFFSET_SIZE); - memcpy( (uint8_t*)(*io_ringBlockPtr), &acc_offset, sizeof(acc_offset)); + torHeader = (TorHeader_t*)i_ringSection; + torMagic = be32toh(torHeader->magic); + chipType = torHeader->chipType; - return TOR_RING_FOUND; - } - else - { - MY_ERR("Ring block type (i_RingBlockType=%d) is not supported for CME \n", i_RingBlockType); - return TOR_INVALID_RING_BLOCK_TYPE; - } - } + rc = ringid_get_noof_chiplets( chipType, + torMagic, + &numChiplets); - local++; - } + if (rc) + { + MY_ERR("ringid_get_noof_chiplets() failed w/rc=0x%08x\n", rc); + return rc; } - // Instance specific single ring extract loop - local = 0; - - for ( uint8_t i = (ring_id_list_instance + 0)->instanceIdMin; - i <= (ring_id_list_instance + 0)->instanceIdMax; - i++ ) + // + // Looper for each SBE chipleti + // + for (ChipletType_t iCplt = 0; iCplt < numChiplets; iCplt++) { - for (uint8_t j = 0; j < P9_RID::EC::g_chipletData.iv_num_instance_rings; j++) + rc = ringid_get_properties( chipType, + torMagic, + iCplt, + &cpltData, + &ringIdListCommon, + &ringIdListInstance, + &ringVariantOrder, + &ringProps, + &numVariants ); + + if (rc) { - for (uint8_t k = 0; k < l_num_variant ; k++) - { - if (i_dbgl > 2) - { - MY_INF(" Ring name %s Cplt instance ring id %d Variant id %d", - (ring_id_list_instance + j)->ringName, j, k); - } + MY_ERR("ringid_get_properties() failed w/rc=0x%08x\n", rc); + return rc; + } + + // + // Sequentially traverse ring offset slots within a chiplet's CMN or INST section + // + for ( bInstCase = 0; bInstCase <= 1; bInstCase++ ) + { + numRings = bInstCase ? cpltData->iv_num_instance_rings : cpltData->iv_num_common_rings; + ringIdList = bInstCase ? ringIdListInstance : ringIdListCommon; - if (strcmp( (ring_id_list_instance + j)->ringName, - P9_RID::RING_PROPERTIES[i_ringId].iv_name) == 0) + if (ringIdList) // Only proceed if chiplet has [Common/Instance] rings. + { + // Calc offset to chiplet's CMN or INST section, cpltOffset (steps 1-3) + // + // 1. Calc offset to TOR slot pointing to chiplet's COM or INST section + cpltOffset = sizeof(TorHeader_t) + + iCplt * sizeof(cpltBlock) + + bInstCase * sizeof(cpltBlock->cmnOffset); + // 2. Retrive offset, endian convert and make it relative to ring section origin + cpltOffset = *(uint32_t*)( (uint8_t*)i_ringSection + cpltOffset ); + cpltOffset = be32toh(cpltOffset); + // 3. Make offset relative to ring section origin + cpltOffset = sizeof(TorHeader_t) + cpltOffset; + + torSlotNum = 0; + + for ( iInst = ringIdList->instanceIdMin; + iInst <= ringIdList->instanceIdMax; + iInst++ ) { - if ( io_instanceId >= (ring_id_list_instance + 0)->instanceIdMin - && io_instanceId <= (ring_id_list_instance + 0)->instanceIdMax ) + for ( iRing = 0; iRing < numRings; iRing++ ) { - if ( i == io_instanceId && k == i_RingVariant ) + for ( iVariant = 0; iVariant < numVariants; iVariant++ ) { - strcpy(o_ringName, P9_RID::RING_PROPERTIES[i_ringId].iv_name); - uint32_t var = i_ddLevelOffset + ppe_cplt_offset + CPLT_OFFSET_SIZE; - int temp1 = var / CPLT_OFFSET_SIZE; - ring_offset = *((uint32_t*)i_ringSection + temp1); - ring_offset = be32toh(ring_offset); - var = ring_offset + i_ddLevelOffset + ppe_cplt_offset; - temp1 = var / sizeof(uint16_t) + local; - chiplet_offset = *((uint16_t*)i_ringSection + temp1); - chiplet_offset = be16toh(chiplet_offset); - - if (i_RingBlockType == GET_SINGLE_RING) + if ( strcmp( (ringIdList + iRing)->ringName, + ringProps[i_ringId].iv_name ) == 0 && + ( i_ringVariant == ringVariantOrder->variant[iVariant] || + numVariants == 1 ) && // If no variants, ignore Variant + ( !bInstCase || ( bInstCase && iInst == io_instanceId) ) ) { - var = ring_offset + chiplet_offset + i_ddLevelOffset + ppe_cplt_offset; - ringSize = be16toh( ((CompressedScanData*) - ((uint8_t*)i_ringSection + - var))->iv_size ); - io_RingType = INSTANCE_RING; + strcpy(o_ringName, (ringIdList + iRing)->ringName); - if (chiplet_offset) + // Calc offset to actual ring, ringOffset (steps 1-3) + // + // 1. Calc offset to TOR slot pointing to actual ring + ringOffset = cpltOffset + torSlotNum * sizeof(ringOffset); + // 2. Retrieve offset and endian convert + ringOffset = *(TorRingOffset_t*)( (uint8_t*)i_ringSection + ringOffset ); + ringOffset = be16toh(ringOffset); + + if (i_ringBlockType == GET_SINGLE_RING) { - if (io_ringBlockSize == 0) + ringSize = 0; + + if (ringOffset) { - if (i_dbgl > 0) + // 3. Make offset relative to ring section origin + ringOffset = cpltOffset + ringOffset; + + ringSize = be16toh( ((CompressedScanData*) + ((uint8_t*)i_ringSection + ringOffset))->iv_size ); + + if (io_ringBlockSize == 0) + { + if (i_dbgl > 0) + { + MY_DBG("io_ringBlockSize is zero. Returning required size.\n"); + } + + io_ringBlockSize = ringSize; + return TOR_SUCCESS; + } + + if (io_ringBlockSize < ringSize) { - MY_INF("\tio_ringBlockSize is zero. Returning required size.\n"); + MY_ERR("io_ringBlockSize is less than required size.\n"); + return TOR_BUFFER_TOO_SMALL; } - io_ringBlockSize = ringSize; + // Produce return parms + memcpy( *io_ringBlockPtr, (uint8_t*)i_ringSection + ringOffset, ringSize); + io_ringBlockSize = ringSize; + io_instanceId = (bInstCase) ? io_instanceId : (ringIdList + iRing)->instanceIdMin; - return TOR_SUCCESS; - } + if (i_dbgl > 0) + { + MY_DBG("Found a ring:\n" \ + " Name: %s\n" \ + " Blocksize: %d\n", + o_ringName, io_ringBlockSize); + } - if (io_ringBlockSize < ringSize) + rc = TOR_SUCCESS; + } + else { - MY_ERR("\tio_ringBlockSize is less than required size.\n"); + if (i_dbgl > 0) + { + MY_DBG("Ring %s was not found.\n", o_ringName); + } - return TOR_BUFFER_TOO_SMALL; + rc = TOR_RING_NOT_FOUND; } if (i_dbgl > 0) { - MY_INF(" Hex details (CME): Chiplet #%d offset 0x%08x local offset 0x%08x " \ - "ring offset 0x%08x start adr 0x%08x ringSize=0x%08x \n", - i, var, ppe_cplt_offset, ring_offset, chiplet_offset, ringSize); + MY_DBG("Details for chiplet ring index=%d: \n" + " Full offset to chiplet section = 0x%08x \n" + " Full offset to RS4 header = 0x%08x \n" + " Ring size = 0x%08x \n", + iRing, cpltOffset, ringOffset, ringSize); } - memcpy( (uint8_t*)(*io_ringBlockPtr), (uint8_t*)i_ringSection + var, - (size_t)ringSize); - - io_ringBlockSize = ringSize; - - if (i_dbgl > 0) - { - MY_INF(" After get_ring_from_cme_image Size %d \n", io_ringBlockSize); - } + return rc; - return TOR_RING_FOUND; } - else + else if (i_ringBlockType == PUT_SINGLE_RING) { - if (i_dbgl > 0) + if (ringOffset) { - MY_INF(" ring container of %s is not found in the CME image container \n", - o_ringName); + MY_ERR("Ring container is already present in image\n"); + return TOR_RING_AVAILABLE_IN_RINGSECTION; } - return TOR_RING_NOT_FOUND; + // Special [mis]use of io_ringBlockPtr and io_ringBlockSize: + // Put location of chiplet's CMN or INST section into ringBlockPtr + memcpy( *io_ringBlockPtr, &cpltOffset, sizeof(cpltOffset)); + // Put location of ringOffset slot into ringBlockSize + io_ringBlockSize = cpltOffset + (torSlotNum * sizeof(ringOffset)); + + return TOR_SUCCESS; } - } - else if (i_RingBlockType == PUT_SINGLE_RING) - { - if (chiplet_offset) + else { - MY_ERR("Ring container is already present in the CME section \n"); - - return TOR_RING_AVAILABLE_IN_RINGSECTION; + MY_ERR("Ring block type (i_ringBlockType=%d) is not supported\n", i_ringBlockType); + return TOR_INVALID_RING_BLOCK_TYPE; } - - acc_offset = var; - io_ringBlockSize = acc_offset + (local * RING_OFFSET_SIZE); - memcpy( (uint8_t*)(*io_ringBlockPtr), &acc_offset, sizeof(acc_offset)); - - return TOR_RING_FOUND; - } - else - { - MY_ERR("Ring block type (i_RingBlockType=%d) is not supported for CME \n", i_RingBlockType); - return TOR_INVALID_RING_BLOCK_TYPE; } - } - } - else - { - if (i_dbgl > 0) - { - MY_INF(" CME ring instance ID %d is invalid, Valid ID is from %d to %d \n", - io_instanceId, (ring_id_list_instance + 0)->instanceIdMin, - (ring_id_list_instance + 0)->instanceIdMax); - } - return TOR_INVALID_INSTANCE_ID; + torSlotNum++; // Next TOR ring slot + } } } - - local++; } - } + else // Since there's no Common/Instance rings, set RING_NOT_FOUND + { + // Note that if we get here, it's because the chiplet doesn't have either + // a Common or Instance rings. This happens e.g. for Centaur which has + // no Instance rings. And theoretically, it's possible to only have + // Instance rings and no Common rings, so accommodating that as well here. + if (i_dbgl > 0) + { + MY_DBG("Chiplet=%d has no CMN(%d) or INST(%d) section\n", + iCplt, (1 - bInstCase), bInstCase); + } + + rc = TOR_RING_NOT_FOUND; + + } // if (ringIdList) + } // for (bInstCase) + } // for (iCplt) + + if (i_dbgl > 0) + { + MY_DBG("i_ringId=0x%x is an invalid ring ID\n", i_ringId); } return TOR_INVALID_RING_ID; -} // End of get_ring_from_cme_image() +} // End of get_ring_from_ring_section() @@ -1114,11 +285,10 @@ int get_ring_from_cme_image ( void* i_ringSection, // Ring section int tor_access_ring( void* i_ringSection, // Ring section ptr RingId_t i_ringId, // Ring ID uint16_t i_ddLevel, // DD level - PpeType_t i_PpeType, // SBE, CME, SGPE - RingType_t& io_RingType, // Common, Instance - RingVariant_t i_RingVariant, // Base,CC, RL, Ovrd, Ovly + PpeType_t i_ppeType, // SBE, CME, SGPE + RingVariant_t i_ringVariant, // Base,CC,RL (SBE,CME,SGPE only) uint8_t& io_instanceId, // Instance ID - RingBlockType_t i_RingBlockType, // Single ring, Block + RingBlockType_t i_ringBlockType, // Single ring, Block void** io_ringBlockPtr, // Ring data buffer uint32_t& io_ringBlockSize, // Size of ring data char* o_ringName, // Ring name @@ -1128,17 +298,17 @@ int tor_access_ring( void* i_ringSection, // Ring section ptr uint32_t torMagic; TorHeader_t* torHeader; TorDdBlock_t* torDdBlock; - uint8_t bDdCheck = 0; - uint32_t ddLevelOffset = 0; uint32_t ddLevelCount = 0; - uint32_t ddLevel = 0; + uint32_t ddLevelOffset = 0; uint32_t ddBlockSize = 0; - uint32_t temp = 0; + void* ddBlockStart = NULL; + uint8_t bDdCheck = 0; + uint32_t ddLevel = 0; if (i_dbgl > 1) { - MY_INF("Entering tor_access_ring()... \n"); + MY_DBG("Entering tor_access_ring()...\n"); } torHeader = (TorHeader_t*)i_ringSection; @@ -1146,6 +316,7 @@ int tor_access_ring( void* i_ringSection, // Ring section ptr if (torMagic == TOR_MAGIC_HW) { + ddLevelCount = torHeader->numDdLevels; if (ddLevelCount > MAX_NOOF_DD_LEVELS_IN_IMAGE) @@ -1159,7 +330,7 @@ int tor_access_ring( void* i_ringSection, // Ring section ptr } else if (i_dbgl > 1) { - MY_INF("tor_access_ring(): No of DD levels: %d \n", ddLevelCount); + MY_DBG("tor_access_ring(): No of DD levels: %d \n", ddLevelCount); } for (uint8_t i = 0; i < ddLevelCount; i++) @@ -1168,20 +339,22 @@ int tor_access_ring( void* i_ringSection, // Ring section ptr sizeof(TorHeader_t) + i * sizeof(TorDdBlock_t) ); ddLevel = torDdBlock->ddLevel; - // Local ddLevelOffset + // Local ddLevelOffset (relative to where the DD blocks start) ddLevelOffset = be32toh(torDdBlock->offset); if (i_dbgl > 1) { - MY_INF( "tor_access_ring(): Local DD level offset: 0x%08x for DD level: 0x%x \n", - ddLevelOffset, ddLevel ); + MY_DBG("tor_access_ring(): Local DD level offset: 0x%08x for DD level: 0x%x \n", + ddLevelOffset, ddLevel ); } - if ( ddLevel == i_ddLevel) + if (ddLevel == i_ddLevel) { - // Convert to global ddLevelOffset - ddLevelOffset = ddLevelOffset + - sizeof(TorHeader_t); + // Calc ddBlockStart from origin of the ringSection to where + // the DD block's PPE block starts. + ddBlockStart = (void*)((uint8_t*)i_ringSection + + sizeof(TorHeader_t) + + ddLevelOffset); ddBlockSize = htobe32(torDdBlock->size); bDdCheck = 1; break; @@ -1197,365 +370,116 @@ int tor_access_ring( void* i_ringSection, // Ring section ptr return TOR_DD_LEVEL_NOT_FOUND; } - } - else if ( torMagic == TOR_MAGIC_SBE || - torMagic == TOR_MAGIC_OVRD || - torMagic == TOR_MAGIC_OVLY || - torMagic == TOR_MAGIC_CEN ) - { - if ( i_PpeType == PT_CME || i_PpeType == PT_SGPE - || i_RingBlockType == GET_DD_LEVEL_RINGS - || i_RingBlockType == GET_PPE_LEVEL_RINGS ) - { - MY_ERR("Ambiguity on input PARMS for calling SEEPROM Ring copy API. \n"); - return TOR_AMBIGUOUS_API_PARMS; - } - else - { - ddLevelOffset = sizeof(TorHeader_t); - ddBlockSize = 0; - } - } - else if (torMagic == TOR_MAGIC_CME) - { - if ( i_PpeType == PT_SBE || i_PpeType == PT_SGPE - || i_RingBlockType == GET_DD_LEVEL_RINGS - || i_RingBlockType == GET_PPE_LEVEL_RINGS ) - { - MY_ERR("Ambiguity on input PARMS for calling CME Ring copy API. \n"); - return TOR_AMBIGUOUS_API_PARMS; - } - else - { - ddLevelOffset = sizeof(TorHeader_t); - ddBlockSize = 0; - } - } - else if (torMagic == TOR_MAGIC_SGPE) - { - if ( i_PpeType == PT_SBE || i_PpeType == PT_CME - || i_RingBlockType == GET_DD_LEVEL_RINGS - || i_RingBlockType == GET_PPE_LEVEL_RINGS ) - { - MY_ERR("Ambiguity on input PARMS for calling SGPE Ring copy API. \n"); - return TOR_AMBIGUOUS_API_PARMS; - } - else - { - ddLevelOffset = sizeof(TorHeader_t); - ddBlockSize = 0; - } - } - else - { - if (i_dbgl > 0) - { - MY_ERR("torMagic=0x%08x is not valid\n", torMagic); - } - return TOR_INVALID_MAGIC_NUMBER; } - if (i_RingBlockType == GET_DD_LEVEL_RINGS) + if ( ( i_ringBlockType == GET_SINGLE_RING ) || // All Magics supported for GET + ( i_ringBlockType == PUT_SINGLE_RING && // Can only append to SBE,CME,SGPE + ( torMagic == TOR_MAGIC_SBE || + torMagic == TOR_MAGIC_CME || + torMagic == TOR_MAGIC_SGPE ) ) ) { - if (io_ringBlockSize == 0) - { - if (i_dbgl > 0) - { - MY_INF("\tio_ringBlockSize is zero. Returning required size.\n"); - } - - io_ringBlockSize = ddBlockSize; - return 0; - } - - if (io_ringBlockSize < ddBlockSize) - { - MY_ERR("\tio_ringBlockSize is less than required size.\n"); - return TOR_BUFFER_TOO_SMALL; - } - - memcpy( (uint8_t*)(*io_ringBlockPtr), - (uint8_t*)i_ringSection + ddLevelOffset, (size_t)ddBlockSize); - - if (i_dbgl > 1) + if ( torMagic == TOR_MAGIC_HW ) { - MY_INF( "TOR_ACCESS_RING(5): DD offset = %d DD level = %d DD block size = %d \n", - ddLevelOffset, ddLevel, ddBlockSize); + // Update i_ringSection: + // Extract the offset to the specified ppeType's ring section TOR header and update i_ringSection + TorPpeBlock_t* torPpeBlock; + torPpeBlock = (TorPpeBlock_t*)((uint8_t*)ddBlockStart + i_ppeType * sizeof(TorPpeBlock_t)); + i_ringSection = (void*)((uint8_t*)ddBlockStart + be32toh(torPpeBlock->offset)); } - io_ringBlockSize = ddBlockSize; + rc = get_ring_from_ring_section( i_ringSection, + i_ringId, + i_ringVariant, + io_instanceId, + i_ringBlockType, + io_ringBlockPtr, + io_ringBlockSize, + o_ringName, + i_dbgl ); - return TOR_RING_FOUND; + return rc; } - else if (i_RingBlockType == GET_PPE_LEVEL_RINGS) + else if ( i_ringBlockType == GET_DD_LEVEL_RINGS && + torMagic == TOR_MAGIC_HW ) { - uint32_t l_ppe_offset = 0; - uint32_t l_ppe_size = 0; - - if (i_PpeType == PT_SBE) + if (io_ringBlockSize >= ddBlockSize) { - temp = ddLevelOffset >> 2; - - if (i_dbgl > 1) - { - MY_INF( "TOR_ACCESS_RING(6): SBE PPE_LEVEL_RING COPY called ... \n"); - } + memcpy( (uint8_t*)(*io_ringBlockPtr), ddBlockStart, ddBlockSize ); + io_ringBlockSize = ddBlockSize; - l_ppe_offset = *((uint32_t*)i_ringSection + temp); - l_ppe_offset = be32toh(l_ppe_offset); - l_ppe_size = *((uint32_t*)i_ringSection + temp + 1 ); - l_ppe_size = be32toh(l_ppe_size); + return TOR_SUCCESS; } - else if (i_PpeType == PT_CME) + else if (io_ringBlockSize == 0) { - temp = (ddLevelOffset >> 2) + 2; - - if (i_dbgl > 1) + if (i_dbgl > 0) { - MY_INF( "TOR_ACCESS_RING(7): CME PPE_LEVEL_RING COPY called... \n"); + MY_DBG("io_ringBlockSize is zero. Returning required size.\n"); } - l_ppe_offset = *((uint32_t*)i_ringSection + temp); - l_ppe_offset = be32toh(l_ppe_offset); - l_ppe_size = *((uint32_t*)i_ringSection + temp + 1 ); - l_ppe_size = be32toh(l_ppe_size); - } - else if (i_PpeType == PT_SGPE) - { - - temp = (ddLevelOffset >> 2) + sizeof(uint32_t); - - if (i_dbgl > 1) - { - MY_INF( "TOR_ACCESS_RING(8): SPGE PPE_LEVEL_RING COPY called... \n"); - } + io_ringBlockSize = ddBlockSize; - l_ppe_offset = *((uint32_t*)i_ringSection + temp); - l_ppe_offset = be32toh(l_ppe_offset); - l_ppe_size = *((uint32_t*)i_ringSection + temp + 1 ); - l_ppe_size = be32toh(l_ppe_size); + return TOR_SUCCESS; } - - if (io_ringBlockSize == 0) + else { - if (i_dbgl > 0) - { - MY_INF("\tio_ringBlockSize is zero. Returning required size.\n"); - } - - io_ringBlockSize = l_ppe_size; - return 0; - } + MY_ERR("io_ringBlockSize is less than required size.\n"); - if (io_ringBlockSize < l_ppe_size) - { - MY_ERR("\tio_ringBlockSize is less than required size.\n"); return TOR_BUFFER_TOO_SMALL; } - - memcpy( (uint8_t*)(*io_ringBlockPtr), - (uint8_t*)i_ringSection + l_ppe_offset + ddLevelOffset, - (size_t)l_ppe_size); - io_ringBlockSize = l_ppe_size; - - return TOR_RING_FOUND; } - else if ( i_RingBlockType == GET_SINGLE_RING || - i_RingBlockType == PUT_SINGLE_RING ) + else if ( i_ringBlockType == GET_PPE_LEVEL_RINGS && + torMagic == TOR_MAGIC_HW && + (i_ppeType == PT_SBE || i_ppeType == PT_CME || i_ppeType == PT_SGPE) ) { - if ( i_PpeType == PT_SBE && - ( torMagic == TOR_MAGIC_HW || - torMagic == TOR_MAGIC_SBE || - torMagic == TOR_MAGIC_OVRD || - torMagic == TOR_MAGIC_OVLY || - torMagic == TOR_MAGIC_CEN ) ) - { - rc = get_ring_from_sbe_image( i_ringSection, - i_ringId, - ddLevelOffset, - io_RingType, - i_RingVariant, - io_instanceId, - i_RingBlockType, - io_ringBlockPtr, - io_ringBlockSize, - o_ringName, - i_dbgl ); - - if (rc) - { - if (i_dbgl > 0) - { - MY_ERR("get_ring_from_sbe_image failed w/rc=%d\n", rc); - } + TorPpeBlock_t* torPpeBlock; + uint32_t ppeSize; - return rc; - } - else - { - if (i_dbgl > 1) - { - MY_INF(" TOR_ACCESS_RING(10): After get_ring_from_sbe_image Size %d \n", - io_ringBlockSize ); - } + torPpeBlock = (TorPpeBlock_t*)((uint8_t*)ddBlockStart + i_ppeType * sizeof(TorPpeBlock_t)); + ppeSize = be32toh(torPpeBlock->size); - return TOR_RING_FOUND; - } - } - else if ( i_PpeType == PT_CME && - ( torMagic == TOR_MAGIC_HW || - torMagic == TOR_MAGIC_CME ) ) + if (io_ringBlockSize >= ppeSize) { - rc = get_ring_from_cme_image( i_ringSection, - i_ringId, - ddLevelOffset, - io_RingType, - i_RingVariant, - io_instanceId, - i_RingBlockType, - io_ringBlockPtr, - io_ringBlockSize, - o_ringName, - i_dbgl ); - - if (rc == TOR_RING_NOT_FOUND) - { - if (i_dbgl > 0) - { - MY_INF("\t After CME single ring call, %s ring container is not found \n", - P9_RID::RING_PROPERTIES[i_ringId].iv_name); - } - - return rc; - } - else if (rc == TOR_INVALID_INSTANCE_ID) - { - if (i_dbgl > 0) - { - MY_INF("\t After CME single ring call, Instance %d is invalid \n", - io_instanceId ); - } - - return rc; - } - else if (rc == TOR_RING_AVAILABLE_IN_RINGSECTION) - { - if (i_dbgl > 0) - { - MY_INF("\t After CME single ring call, Ring container is available in the image \n"); - } - - return rc; - } - else if (rc == TOR_INVALID_RING_ID) - { - if (i_dbgl > 0) - { - MY_INF("\t After CME single ring call, There is no TOR slot for %s %d\n", - P9_RID::RING_PROPERTIES[i_ringId].iv_name, i_ringId); - } - - return rc; - } - else - { - if (i_dbgl > 1) - { - MY_INF("TOR_ACCESS_RING(11): After get_ring_from_cme_image Size %d \n", - io_ringBlockSize ); - } + memcpy( (uint8_t*)(*io_ringBlockPtr), + (uint8_t*)ddBlockStart + be32toh(torPpeBlock->offset), + ppeSize ); + io_ringBlockSize = ppeSize; - return TOR_RING_FOUND; - } + return TOR_SUCCESS; } - else if ( i_PpeType == PT_SGPE && - ( torMagic == TOR_MAGIC_HW || - torMagic == TOR_MAGIC_SGPE ) ) + else if (io_ringBlockSize == 0) { - rc = get_ring_from_sgpe_image( i_ringSection, - i_ringId, - ddLevelOffset, - io_RingType, - i_RingVariant, - io_instanceId, - i_RingBlockType, - io_ringBlockPtr, - io_ringBlockSize, - o_ringName, - i_dbgl ); - - if (rc == TOR_RING_NOT_FOUND) - { - if (i_dbgl > 0) - { - MY_INF("\t After SGPE single ring call, %s ring container is not found \n", - P9_RID::RING_PROPERTIES[i_ringId].iv_name); - } - - return rc; - } - else if (rc == TOR_INVALID_INSTANCE_ID) - { - if (i_dbgl > 0) - { - MY_INF("\t After SGPE single ring call, Instance %d is invalid \n", - io_instanceId ); - } - - return rc; - } - else if (rc == TOR_RING_AVAILABLE_IN_RINGSECTION) + if (i_dbgl > 0) { - if (i_dbgl > 0) - { - MY_INF("\t After SGPE single ring call, Ring container is available in the image \n"); - } - - return rc; + MY_DBG("io_ringBlockSize is zero. Returning required size.\n"); } - else if (rc == TOR_INVALID_RING_ID) - { - if (i_dbgl > 0) - { - MY_INF("\t After SGPE single ring call, There is no TOR slot for %s %d\n", - P9_RID::RING_PROPERTIES[i_ringId].iv_name, i_ringId); - } - return rc; - } - else - { - if (i_dbgl > 1) - { - MY_INF("TOR_ACCESS_RING(12): After get_ring_from_sgpe_image Size %d \n", - io_ringBlockSize ); - } + io_ringBlockSize = ppeSize; - return TOR_RING_FOUND; - } + return TOR_SUCCESS; } else { - if (i_dbgl > 0) - { - MY_ERR("\t Unsupported combination of i_PpeType=%d and torMagic=0x%08x\n", - i_PpeType, torMagic); - } + MY_ERR("io_ringBlockSize is less than required size.\n"); - return TOR_AMBIGUOUS_API_PARMS; + return TOR_BUFFER_TOO_SMALL; } - } else { - MY_ERR("\t RingBlockType=0x%x is not supported. Caller error.\n", - i_RingBlockType); + MY_ERR("Ambiguity on input parms to tor_access_ring():\n" \ + " Possibly invalid torMagic (=0x%08x)\n" \ + " Possibly incompatible ringBlockType (=%d)\n" \ + " Possibly unsupported ppeType (=%d)\n" \ + " Note that we don't care about ppeType for non-HW TOR ring sections\n", + i_ringBlockType, torMagic, i_ppeType); - return TOR_INVALID_RING_BLOCK_TYPE; + return TOR_AMBIGUOUS_API_PARMS; } - return TOR_AMBIGUOUS_API_PARMS; + MY_ERR("Code bug in tor_access_ring(): Should never be here\n"); + + return TOR_CODE_BUG; } // End of tor_access_ring() @@ -1569,8 +493,8 @@ int tor_access_ring( void* i_ringSection, // Ring section ptr int tor_get_single_ring ( void* i_ringSection, // Ring section ptr uint16_t i_ddLevel, // DD level RingId_t i_ringId, // Ring ID - PpeType_t i_PpeType, // SBE, CME, SGPE - RingVariant_t i_RingVariant, // Base,CC, RL, Ovrd, Ovly + PpeType_t i_ppeType, // SBE, CME, SGPE + RingVariant_t i_ringVariant, // Base,CC,RL (SBE/CME/SGPE only) uint8_t i_instanceId, // Instance ID void** io_ringBlockPtr, // Output ring buffer uint32_t& io_ringBlockSize, // Size of ring data @@ -1578,22 +502,18 @@ int tor_get_single_ring ( void* i_ringSection, // Ring section ptr { uint32_t rc; - char i_ringName[25]; - //@FIXME: This should really be ALLRING. But it's not used as input. - RingType_t l_ringType; - l_ringType = COMMON_RING; + char i_ringName[MAX_RING_NAME_LENGTH]; if (i_dbgl > 1) { - MY_INF(" TOR_GET_SINGLE_RING1: function call \n"); + MY_DBG("Entering tor_get_single_ring()...\n"); } rc = tor_access_ring( i_ringSection, i_ringId, i_ddLevel, - i_PpeType, - l_ringType, - i_RingVariant, + i_ppeType, + i_ringVariant, i_instanceId, GET_SINGLE_RING, io_ringBlockPtr, @@ -1603,8 +523,7 @@ int tor_get_single_ring ( void* i_ringSection, // Ring section ptr if (i_dbgl > 1) { - MY_INF(" TOR_GET_SINGLE_RING(2): after tor_access_ring function, Size %d \n", - io_ringBlockSize ); + MY_DBG("Exiting tor_get_single_ring() (ringBlockSize=%d)...\n", io_ringBlockSize ); } return rc; @@ -1619,65 +538,77 @@ int tor_get_single_ring ( void* i_ringSection, // Ring section ptr /////////////////////////////////////////////////////////////////////////////////////// int tor_get_block_of_rings ( void* i_ringSection, // Ring section ptr uint16_t i_ddLevel, // DD level - PpeType_t i_PpeType, // SBE,CME,SGPE - RingType_t i_ringType, // Common, Instance - RingVariant_t i_RingVariant, // Base,CC, RL, Ovrd, Ovly - uint8_t i_instanceId, // Instance ID + PpeType_t i_ppeType, // SBE,CME,SGPE + RingVariant_t i_ringVariant, // Base,CC,RL void** io_ringBlockPtr, // Output ring buffer uint32_t& io_ringBlockSize, // Size of ring data uint32_t i_dbgl ) // Debug option { + uint32_t rc = 0; + uint8_t l_instanceId; + char i_ringName[MAX_RING_NAME_LENGTH]; + uint32_t torMagic; + ChipType_t chipType = UNDEFINED_CHIP_TYPE; + TorHeader_t* torHeader; + if (i_dbgl > 1) { - MY_INF(" TOR_GET_BLOCK_OF_RINGS(1): function call \n"); + MY_DBG("Entering tor_get_block_of_rings()...\n"); } - uint32_t rc = 0; - char i_ringName[25]; - - if (i_ringType == ALLRING && i_PpeType != NUM_PPE_TYPES) - { - // Get block of rings specific to a PPE type - rc = tor_access_ring( i_ringSection, - P9_RID::NUM_RING_IDS, - i_ddLevel, - i_PpeType, - i_ringType, - i_RingVariant, - i_instanceId, - GET_PPE_LEVEL_RINGS, - io_ringBlockPtr, - io_ringBlockSize, - i_ringName, - i_dbgl ); + torHeader = (TorHeader_t*)i_ringSection; + torMagic = be32toh(torHeader->magic); + chipType = torHeader->chipType; + + if ( torMagic == TOR_MAGIC_HW && chipType != CT_CEN ) + { + if (i_ppeType == NUM_PPE_TYPES) + { + // Get DD level block of rings + rc = tor_access_ring( i_ringSection, + UNDEFINED_RING_ID, + i_ddLevel, + i_ppeType, + i_ringVariant, + l_instanceId, + GET_DD_LEVEL_RINGS, + io_ringBlockPtr, + io_ringBlockSize, + i_ringName, + i_dbgl ); + } + else if (i_ppeType == PT_SBE || i_ppeType == PT_CME || i_ppeType == PT_SGPE) + { + // Get block of rings specific to a PPE type + rc = tor_access_ring( i_ringSection, + UNDEFINED_RING_ID, + i_ddLevel, + i_ppeType, + i_ringVariant, + l_instanceId, + GET_PPE_LEVEL_RINGS, + io_ringBlockPtr, + io_ringBlockSize, + i_ringName, + i_dbgl ); - } - else if (i_ringType == ALLRING && i_PpeType == NUM_PPE_TYPES) - { - // Get DD level block of rings - rc = tor_access_ring( i_ringSection, - P9_RID::NUM_RING_IDS, - i_ddLevel, - i_PpeType, - i_ringType, - i_RingVariant, - i_instanceId, - GET_DD_LEVEL_RINGS, - io_ringBlockPtr, - io_ringBlockSize, - i_ringName, - i_dbgl ); + } + else + { + MY_ERR("tor_get_block_of_rings(): Ambiguous API parameters\n"); + return TOR_AMBIGUOUS_API_PARMS; + } } else { - MY_ERR("TOR_GET_BLOCK_OF_RINGS(2): Wrong input params. Please check passing params\n"); - return TOR_AMBIGUOUS_API_PARMS; + MY_ERR("tor_get_block_of_rings(): Only the P9 HW ring section is supported. However, torMagic=0x%08x and chipType=%d\n", + torMagic, chipType); + return TOR_UNSUPPORTED_RING_SECTION; } if (i_dbgl > 1) { - MY_INF(" TOR_GET_SINGLE_RING(2): after tor_access_ring function, Size %d \n", - io_ringBlockSize ); + MY_DBG("Exiting tor_get_block_of_rings() (ringBlockSize=%d)...\n", io_ringBlockSize); } return rc; @@ -1696,15 +627,14 @@ int tor_append_ring( void* i_ringSection, // Ring section ptr void* i_ringBuffer, // Ring work buffer const uint32_t i_ringBufferSize, // Max size of ring work buffer RingId_t i_ringId, // Ring ID - PpeType_t i_PpeType, // SBE, CME, SGPE - RingType_t i_RingType, // Common, Instance - RingVariant_t i_RingVariant, // Base,CC, RL, Ovrd, Ovly + PpeType_t i_ppeType, // SBE, CME, SGPE + RingVariant_t i_ringVariant, // Base,CC,RL uint8_t i_instanceId, // Instance ID void* i_rs4Container, // RS4 ring container uint32_t i_dbgl ) // Debug option { uint32_t rc = 0; - char i_ringName[25]; + char i_ringName[MAX_RING_NAME_LENGTH]; uint32_t l_buf = 0; uint32_t* l_cpltSection = &l_buf; uint32_t l_ringBlockSize; @@ -1714,9 +644,8 @@ int tor_append_ring( void* i_ringSection, // Ring section ptr rc = tor_access_ring( i_ringSection, i_ringId, 0x00, - i_PpeType, - i_RingType, - i_RingVariant, + i_ppeType, + i_ringVariant, i_instanceId, PUT_SINGLE_RING, (void**)&l_cpltSection, // On return, contains offset (wrt ringSection) of diff --git a/src/import/chips/p9/utils/imageProcs/p9_tor.H b/src/import/chips/p9/utils/imageProcs/p9_tor.H index 6aa73b46..2a764c52 100644 --- a/src/import/chips/p9/utils/imageProcs/p9_tor.H +++ b/src/import/chips/p9/utils/imageProcs/p9_tor.H @@ -27,98 +27,6 @@ #include -#define MAX_TOR_RING_OFFSET (256*256-1) // Max value of 2Byte uint - -extern const char* ppeTypeName[]; -extern const char* ringVariantName[]; - -#define TOR_VERSION 3 - -// -// TOR Magic values for top-level TOR image and TOR sub-images -// -enum TorMagicNum -{ - TOR_MAGIC = (uint32_t)0x544F52 , // "TOR" - TOR_MAGIC_HW = (uint32_t)0x544F5248, // "TORH" - TOR_MAGIC_SBE = (uint32_t)0x544F5242, // "TORB" - TOR_MAGIC_SGPE = (uint32_t)0x544F5247, // "TORG" - TOR_MAGIC_CME = (uint32_t)0x544F524D, // "TORM" - TOR_MAGIC_OVRD = (uint32_t)0x544F5252, // "TORR" - TOR_MAGIC_OVLY = (uint32_t)0x544F524C, // "TORL" - TOR_MAGIC_CEN = (uint32_t)0x544F524E, // "TORN" -}; - -// -// TOR header field (appears in top of every HW, SBE, CEN, OVRD, etc ring section) -// -typedef struct -{ - uint32_t magic; - uint8_t version; - ChipType_t chipType; // Value from ChipType enum - uint8_t ddLevel; // =0xff if MAGIC_HW, >0 all other MAGICs - uint8_t numDdLevels; // >0 if MAGIC_HW, =1 all other MAGICs - uint32_t size; // Size of the TOR ringSection. -} TorHeader_t; - -#define UNDEFINED_DD_LEVEL (uint8_t)0xff - -// -// Subsequent TOR fields (listed in order they appear in TOR for easier understanding) -// -typedef struct -{ - uint32_t offset; - uint32_t size; - uint8_t ddLevel; - uint8_t reserved[3]; -} TorDdBlock_t; - -typedef struct -{ - uint32_t offset; - uint32_t size; -} TorPpeBlock_t; - -typedef struct -{ - uint32_t commonOffset; - uint32_t instanceOffset; -} TorCpltBlock_t; - -typedef uint16_t TorRingOffset_t; // Ring offset value in TOR offset slot - -//@FIXME Discard asap -typedef enum TorOffsetSize -{ - RING_OFFSET_SIZE = 2, - CPLT_OFFSET_SIZE = 4 -} TorOffsetSize_t; - -#define TOR_SUCCESS 0 -#define TOR_RING_FOUND 0 -#define TOR_RING_NOT_FOUND 1 -#define TOR_AMBIGUOUS_API_PARMS 2 -#define TOR_SECTION_NOT_FOUND 3 -#define TOR_DD_LEVEL_NOT_FOUND 4 -#define TOR_OP_BUFFER_INVALID 5 -#define TOR_OP_BUFFER_SIZE_EXCEEDED 6 -#define TOR_INVALID_RING_ID 7 -#define TOR_INVALID_INSTANCE_ID 8 -#define TOR_INVALID_CHIPLET 9 -#define TOR_INVALID_RING_BLOCK_TYPE 10 -#define TOR_INVALID_MAGIC_NUMBER 11 -#define TOR_IMAGE_DOES_NOT_SUPPORT_CME 12 -#define TOR_IMAGE_DOES_NOT_SUPPORT_SGPE 13 -#define TOR_IMAGE_DOES_NOT_SUPPORT_DD_LEVEL 14 -#define TOR_IMAGE_DOES_NOT_SUPPORT_PPE_LEVEL 15 -#define TOR_RING_AVAILABLE_IN_RINGSECTION 16 // Ring is already present -#define TOR_BUFFER_TOO_SMALL 17 -#define TOR_TOO_MANY_DD_LEVELS 18 -#define TOR_OFFSET_TOO_BIG 19 -#define TOR_INVALID_VARIANT 20 - // Different options to extract data using tor_access_ring API typedef enum RingBlockType { @@ -128,14 +36,6 @@ typedef enum RingBlockType PUT_SINGLE_RING = 0x03 } RingBlockType_t; -enum PpeType -{ - PT_SBE = 0x00, - PT_CME = 0x01, - PT_SGPE = 0x02, - NUM_PPE_TYPES = 0x03 -}; - /// /// **************************************************************************** /// Function declares. @@ -157,11 +57,6 @@ enum PpeType /// \param[in] i_PpeType A enum to indicate ppe type. They are SBE, CME /// and SGPE. It is used to decode TOR structure /// -/// \param[in/out] io_RingType A enum and passed by reference. Acts as input -/// paramfor extracting block of rings copy under Chiplet level. Acts as -/// outputparam to indicate type of single ring copied is whether common or -/// instance specific ring -/// /// \param[in] i_RingVariant A enum to indicate which variant type of /// requested for single ring extract. There are three major types. They are /// base, Cache contained and Risk level ring @@ -174,14 +69,12 @@ enum PpeType /// GET_SINGLE_RING indicates to extract single ring container. /// GET_DD_LEVEL_RINGS indicates to extract specific DD level TOR and rings /// GET_PPE_LEVEL_RINGS indcates to extract specific PPE level TOR and rings -/// GET_CPLT_LEVEL_RINGS indciates to extract specific chiplet ring type -/// TOR and rings /// PUT_SINGLE_RING indicates to extract ring absolute memory addres for -/// ringType start and ringTorSlot location +/// ringTorSlot location /// /// \param[in/out] io_ringBlockPtr A void pointer to pointer. Returns data /// which copied during extract ring operation and returns tor absolute address -/// where RingType offset slot is located while PUT_SINGLE_RING call. +/// where offset slot is located while PUT_SINGLE_RING call. /// Note:- Caller's responsibility for free() to avoid memory leak /// /// \param[in/out] io_ringBlockSize A variable. Returns size of data copied @@ -201,9 +94,8 @@ enum PpeType /// type info, \a i_ringVarint gives ring variant info and \a io_instance which /// gives chiplet instance specific while accessing instance specific ring and /// returns chiplet number while accessing common ring. On return, -/// \a io_ringBlockPtr contains RS4 container \a io_RingType contains which -/// ring type of ring requested and \a io_ringBlockSize contains size of the -/// data copied into io_ringBlockPtr. \a o_ringName returns ring string name. +/// \a io_ringBlockPtr contains RS4 container \a io_ringBlockSize contains size +/// of data copied into io_ringBlockPtr. \a o_ringName returns ring string name. /// /// GET_DD_LEVEL_RINGS (\a i_ringVariant) - traverse on \a i_ringSection /// buffer based on \a i_ddLevel which gives dd spec (used only for HW image @@ -219,13 +111,6 @@ enum PpeType /// \a io_ringBlockSize contains size of the data copied into io_ringBlockPtr. /// \a Other params are optional. This ringVariant works on HW image. /// -/// GET_CPLT_LEVEL_RINGS (\a i_ringVariant) - traverse on \a i_ringSection -/// buffer based on \a i_ppeType which gives ppe type info, \a i_ddLevel which gives -/// dd spec (used only for HW image/optional for other image) and \a io_RingType -/// which gives ring type info. On return, \a io_ringBlockPtr contains chiplet -/// specific ring type ring section and \a io_ringBlockSize contains size of -/// the data copied into io_ringBlockPtr. \a Other params are optional. -/// /// PUT_SINGLE_RING (\a i_ringVariant) - traverse on \a i_ringSection buffer /// based on \a i_ringId which gives ring info, \a i_ddLevel which gives dd spec /// (used only for HW image/optional for other image), i_ppeType which gives @@ -240,11 +125,10 @@ enum PpeType /// \retval 0 Success /// /// \retval non-0 See \ref TOR API RETURN errors -int tor_access_ring( void* i_ringSection, // Ring address Ptr any of .rings, .overrides and .overlays. +int tor_access_ring( void* i_ringSection, // Ring section ptr RingId_t i_ringId, // Unique ring ID uint16_t i_ddLevel, // DD level info PpeType_t i_PpeType, // PPE type : SBE, CME, etc - RingType_t& io_RingType, // 0: Common 1: Instance RingVariant_t i_RingVariant, // Base, Cache etc uint8_t& io_instanceId, // chiplet instance ID RingBlockType_t i_RingBlockType, // 0: single ring, 1: ring block @@ -316,15 +200,10 @@ int tor_get_single_ring ( void* i_ringSection, /// TOR API uses Ppe type to extract single ring or block of rings /// on either hw_image or SBE image /// -/// \param[in] i_RingType A enum and passed by reference. Acts as -/// input param for extracting block of rings copy under Chiplet level -/// /// \param[in] i_RingVariant A enum to indicate which variant type of /// requested for single ring extract. There are three major types. /// They are base, Cache contained and Risk level ring /// -/// \param[in] i_instanceId A variable to indicate chiplet instance ID -/// /// \param[in/out] io_ringBlockPtr A void point to pointer. Returns data /// which copied block of rings. Note: Caller's responsibility for free() /// to avoid memory leak @@ -335,7 +214,7 @@ int tor_get_single_ring ( void* i_ringSection, /// \param[in] - i_debug is debug statment params. Supports 0 to 3. /// /// This API contains wrapper on top of tor_access_ring API and supports -/// to copy block of rings in DD level, ppe level and ringType level. +/// to copy block of rings in DD level and PPE level rings. /// /// \retval 0 Success /// @@ -343,9 +222,7 @@ int tor_get_single_ring ( void* i_ringSection, int tor_get_block_of_rings ( void* i_ringSection, uint16_t i_ddLevel, PpeType_t i_PpeType, - RingType_t i_RingType, RingVariant_t i_RingVariant, - uint8_t i_instanceId, void** io_ringBlockPtr, uint32_t& io_ringBlockSize, uint32_t i_dbgl = 0 ); @@ -373,9 +250,6 @@ int tor_get_block_of_rings ( void* i_ringSection, /// \param[in] i_PpeType A enum to indicate ppe type. They are SBE, /// CME and SGPE. It is used to decode TOR structure /// -/// \param[in] i_RingType A enum to indicate ring type of ring whether -/// common or instance specific ring -/// /// \param[in] i_RingVariant A enum and used as input param to indicate /// which variant type of requested for single ring extract /// @@ -403,7 +277,6 @@ int tor_append_ring( void* i_ringSection, const uint32_t i_ringBufferSize, RingId_t i_ringId, PpeType_t i_ppeType, - RingType_t i_RingType, RingVariant_t i_RingVariant, uint8_t i_instanceId, void* i_rs4Container, diff --git a/src/import/chips/p9/xip/Makefile b/src/import/chips/p9/xip/Makefile index 2616633a..6a5204db 100644 --- a/src/import/chips/p9/xip/Makefile +++ b/src/import/chips/p9/xip/Makefile @@ -35,6 +35,7 @@ INCLUDES += -I. INCLUDES += -I../../../hwpf/fapi2/include/plat INCLUDES += -I../utils/imageProcs +INCLUDES += -I../../common/utils/imageProcs ifeq ($(PROJECT_NAME),sbe) XIP_FLAGS+=-D__PPE__ diff --git a/src/import/chips/p9/xip/p9_xip_tool.C b/src/import/chips/p9/xip/p9_xip_tool.C index f5317915..0a38fb46 100644 --- a/src/import/chips/p9/xip/p9_xip_tool.C +++ b/src/import/chips/p9/xip/p9_xip_tool.C @@ -43,10 +43,10 @@ #undef P9_XIP_TOOL_VERBOSE #include "p9_xip_image.h" +#include "common_ringId.H" #ifndef __PPE__ // Needed on ppe side to avoid having to include various APIs #include "p9_tor.H" #include "p9_scan_compression.H" -#include "p9_infrastruct_help.H" namespace P9_RID { #include "p9_ringId.H" @@ -56,7 +56,7 @@ namespace CEN_RID #include "cen_ringId.H" } #include -#include +#include "p9_dd_container.h" #include #endif #include "p9_infrastruct_help.H" @@ -1864,9 +1864,6 @@ TEST(void* io_image, const int i_argc, const char** i_argv) #ifndef __PPE__ // Needed on the ppe side to avoid TOR API -//@FIXME: This should be improved. Probably defined somewhere else. -#define CHIPLET_ID_MAX (uint8_t)0x37 - /// Function: dissectRingSectionTor() /// /// Brief: Dissects and summarizes content of a ring section. @@ -1887,12 +1884,11 @@ int dissectRingSectionTor( uint8_t* i_ringSection, uint32_t i; RingId_t numRingIds = 0; uint32_t torMagic = 0xffffffff; // Undefined value - ChipType_t chipType = 0xff; // Undefined value + ChipType_t chipType = UNDEFINED_CHIP_TYPE; // Undefined value uint32_t numDdLevels = 0; // Undefined value uint8_t iDdLevel, ddLevel = 0xff; // Undefined value PpeType_t ppeType; RingId_t ringId; - RingType_t ringType; RingVariant_t ringVariant; uint8_t instanceId; void* ringBlockPtr; @@ -2038,12 +2034,12 @@ int dissectRingSectionTor( uint8_t* i_ringSection, //-------------------- // Ring variant loop. - // - Base, cache, risk, override, overlay + // - Base, cache, risk or just "base" if no ring variant for (ringVariant = 0; ringVariant < OVERRIDE; ringVariant++) { - if ( (torMagic == TOR_MAGIC_OVRD && ringVariant != BASE) || - (torMagic == TOR_MAGIC_OVLY && ringVariant != BASE) || - (torMagic == TOR_MAGIC_CEN && ringVariant == CC) ) + if ((torMagic == TOR_MAGIC_OVRD && ringVariant != BASE) || + (torMagic == TOR_MAGIC_OVLY && ringVariant != BASE) || + (torMagic == TOR_MAGIC_CEN && ringVariant == CC)) { continue; } @@ -2053,13 +2049,19 @@ int dissectRingSectionTor( uint8_t* i_ringSection, for (ringId = 0; ringId < numRingIds; ringId++) { - ringType = 0xff; - //--------------------------- // Chiplet instance ID loop. - // - Only loop once if ringId is a common ring. - for (instanceId = 0; instanceId <= CHIPLET_ID_MAX && ringType != COMMON_RING; instanceId++) + // - Only loop once if ringId is a common ring. Determine this by + // comparing the returned value of instanceId in tor_access_ring() + // with the input value of instanceId, instanceInputId. + // - Start looping safely from 0 so that if instanceId is adjusted + // in tor_access_ring, i.e. in case it's an instance ring, it will + // return a non-zeor value for instanceId. + uint8_t instanceInputId; + + for (instanceId = 0; instanceId <= INSTANCE_ID_MAX; instanceId++) { + instanceInputId = instanceId; #ifdef P9_XIP_TOOL_VERBOSE fprintf( stderr, "Processing: " "DD=0x%02x " @@ -2075,7 +2077,6 @@ int dissectRingSectionTor( uint8_t* i_ringSection, ringId, ddLevel, ppeType, - ringType, // IO parm ringVariant, instanceId, // IO parm GET_SINGLE_RING, @@ -2086,7 +2087,7 @@ int dissectRingSectionTor( uint8_t* i_ringSection, // Gather ring details and print it. // - if (rc == TOR_RING_FOUND) + if (rc == TOR_SUCCESS) { if(bPrintHeader == true ) { @@ -2307,6 +2308,10 @@ int dissectRingSectionTor( uint8_t* i_ringSection, } while (cmskRingIteration); + if (instanceId != instanceInputId) + { + break; + } } else if (rc == TOR_RING_NOT_FOUND || rc == TOR_INVALID_INSTANCE_ID || @@ -2315,9 +2320,6 @@ int dissectRingSectionTor( uint8_t* i_ringSection, rc == TOR_AMBIGUOUS_API_PARMS || rc == TOR_INVALID_RING_ID) { -#ifdef P9_XIP_TOOL_VERBOSE - fprintf(stderr, "tor_access_ring() returned error code rc=%d\n", rc); -#endif // All these errors are acceptable in the context of xip_tool dissect. rc = INFRASTRUCT_RC_SUCCESS; } @@ -2332,14 +2334,6 @@ int dissectRingSectionTor( uint8_t* i_ringSection, exit(EXIT_FAILURE); } - if (rc && ringType == 255) - { - // So here we were unsuccessful in tor_access_ring and never even found a - // ring name match, or ring variant match, or chiplet match. So we can - // safely break the instanceId loop. - break; - } - } // End of for(instanceId) } // End of for(ringId) @@ -2818,9 +2812,6 @@ int check_sbe_ring_section_size( void* i_hwImage, P9XipSection l_ringsSection; - RingType_t l_ringType = ALLRING; - - uint8_t unused_parm = 0; void** l_blockPtr = NULL; uint32_t l_blockSize = 0; @@ -2847,9 +2838,7 @@ int check_sbe_ring_section_size( void* i_hwImage, rc = tor_get_block_of_rings( ringsSection, i_ddLevel, PT_SBE, - l_ringType, - BASE, - unused_parm, + NOT_VALID, l_blockPtr, l_blockSize); -- cgit v1.2.1