diff options
Diffstat (limited to 'src')
4 files changed, 321 insertions, 405 deletions
diff --git a/src/import/chips/p9/procedures/hwp/customize/p9_xip_customize.C b/src/import/chips/p9/procedures/hwp/customize/p9_xip_customize.C index cb50b073e..a3bb7d4d0 100644 --- a/src/import/chips/p9/procedures/hwp/customize/p9_xip_customize.C +++ b/src/import/chips/p9/procedures/hwp/customize/p9_xip_customize.C @@ -185,7 +185,8 @@ fapi2::ReturnCode _fetch_and_insert_vpd_rings( // listed in ring_identification.C: One for each of the two EX, even and odd. // Each of these two rings have the same [EQ] chipletId encoded in their // iv_chipletId (current RS4 header) or iv_scanAddress (next gen RS4 header). - // They are distinguished by their even-odd bits in iv_scanSelect as follows: + // They are distinguished by their even-odd bits in iv_scanAddress and so + // for each EQ chipletId there's two EX rings to be accommodated. if (i_ring.vpdRingClass == VPD_RING_CLASS_EX_INS) { l_ringsPerChipletId = 2; @@ -413,25 +414,8 @@ fapi2::ReturnCode _fetch_and_insert_vpd_rings( } else { - - //@TODO: Temporary fix to convert VPD RS4 container format to - // to RingLayout format. Remove/replace in connection - // with RS4 header shrinkage (RTC158101) - uint32_t i; - - for (i = 0; i < l_vpdRingSize; i++) - { - *(((uint8_t*)i_vpdRing) + l_vpdRingSize - 1 + sizeof(P9_TOR::RingLayout_t) - i) = - *(((uint8_t*)i_vpdRing) + l_vpdRingSize - 1 - i); - } - - uint32_t l_sizeOfThisRing = l_vpdRingSize + sizeof(P9_TOR::RingLayout_t); - ((P9_TOR::RingLayout_t*)i_vpdRing)->sizeOfThis = htobe32(l_sizeOfThisRing); - ((P9_TOR::RingLayout_t*)i_vpdRing)->sizeOfCmsk = 0; - ((P9_TOR::RingLayout_t*)i_vpdRing)->sizeOfMeta = 0; - // Checking for potential image overflow BEFORE appending the ring. - if ( (io_ringSectionSize + l_sizeOfThisRing) > i_maxRingSectionSize ) + if ( (io_ringSectionSize + l_vpdRingSize) > i_maxRingSectionSize ) { //@TODO: We can't update bootCoreMask until RTC158106. So for now // we're simply returning the requested bootCoreMask. Thus, @@ -444,7 +428,7 @@ fapi2::ReturnCode _fetch_and_insert_vpd_rings( fapi2::XIPC_IMAGE_WOULD_OVERFLOW(). set_CHIP_TARGET(i_proc_target). set_CURRENT_RING_SECTION_SIZE(io_ringSectionSize). - set_SIZE_OF_THIS_RING(l_sizeOfThisRing). + set_SIZE_OF_THIS_RING(l_vpdRingSize). set_MAX_RING_SECTION_SIZE(i_maxRingSectionSize). set_RING_ID(i_ring.ringId). set_CHIPLET_ID(l_chipletId). @@ -478,7 +462,7 @@ fapi2::ReturnCode _fetch_and_insert_vpd_rings( l_chipletTorId, // Chiplet instance TOR Index i_vpdRing ); // The VPD RS4 ring container - if (l_rc == TOR_APPEND_RING_DONE) + if (l_rc == TOR_SUCCESS) { FAPI_INF("Successfully added VPD ring: (ringId,evenOdd,chipletId)=(0x%02X,0x%X,0x%02X)", i_ring.ringId, l_evenOdd, l_chipletId); @@ -508,7 +492,7 @@ fapi2::ReturnCode _fetch_and_insert_vpd_rings( l_chipletTorId, // Chiplet instance ID i_vpdRing ); // The VPD RS4 ring container - if (l_rc == TOR_APPEND_RING_DONE) + if (l_rc == TOR_SUCCESS) { FAPI_INF("Successfully added VPD ring: (ringId,evenOdd,chipletId)=(0x%02X,0x%X,0x%02X)", i_ring.ringId, l_evenOdd, l_chipletId); @@ -540,7 +524,7 @@ fapi2::ReturnCode _fetch_and_insert_vpd_rings( l_chipletTorId, // Chiplet instance ID i_vpdRing ); // The VPD RS4 ring container - if (l_rc == TOR_APPEND_RING_DONE) + if (l_rc == TOR_SUCCESS) { FAPI_INF("Successfully added VPD ring: (ringId,evenOdd,chipletId)=(0x%02X,0x%X,0x%02X)", i_ring.ringId, l_evenOdd, l_chipletId); diff --git a/src/import/chips/p9/utils/imageProcs/p9_scan_compression.C b/src/import/chips/p9/utils/imageProcs/p9_scan_compression.C index 80f0f052c..f1eb529d8 100644 --- a/src/import/chips/p9/utils/imageProcs/p9_scan_compression.C +++ b/src/import/chips/p9/utils/imageProcs/p9_scan_compression.C @@ -33,13 +33,11 @@ /// the current state of the ring and the desired final state of the ring. /// /// Both the data to be compressed and the final compressed data are treated -/// as strings of 4-bit nibbles. When packaged in the scan data structure -/// however the compressed string must begin on an 8-byte boundary and is -/// always read 8 bytes at a time. In the scan data structure the compressed -/// strings are also padded with 0x0 nibbles to the next even multiple of 8 -/// bytes. The compressed string consists of control nibbles and data nibbles. -/// The string format includes a special control/data sequence that marks the -/// end of the string and the final bits of scan data. +/// as strings of 4-bit nibbles. In the scan data structure the compressed +/// strings are padded with 0x0 nibbles to the next even multiple of 2 for +/// convenience. The compressed string consists of control nibbles and data +/// nibbles. The string format includes a special control/data sequence that +/// marks the end of the string and the final bits of scan data. /// /// Special control/data sequences have been been added for RS4v2 to /// store pairs of care mask nibble and data nibble. This enhancement @@ -602,15 +600,15 @@ rs4_max_compressed_bytes(uint32_t nibbles) bytes = ((nibbles + 1) / 2); // nibbles rounded up to full bytes bytes += sizeof(CompressedScanData); // plus rs4 header - bytes = ((bytes + 7) / 8) * 8; // rounded up to multiple of 8 bytes + bytes = ((bytes + 1) / 2) * 2; // rounded up to multiple of 2 bytes return bytes; } // We always require the worst-case amount of memory including the header and -// any rounding required to guarantee that the data size is a multiple of 8 -// bytes. The final image size is also rounded up to a multiple of 8 bytes. +// any rounding required to guarantee that the data size is a multiple of 2 +// bytes. The final image size is also rounded up to a multiple of 2 bytes. // // Returns a scan compression return code. @@ -659,7 +657,7 @@ _rs4_compress(CompressedScanData* io_rs4, // We always allocate the worst-case amount of memory including the header // and any rounding required to guarantee that the allocated length is a -// multiple of 8 bytes. The final size is also rounded up to a multiple of 8 +// multiple of 2 bytes. The final size is also rounded up to a multiple of 2 // bytes. // // Returns a scan compression return code. diff --git a/src/import/chips/p9/utils/imageProcs/p9_tor.C b/src/import/chips/p9/utils/imageProcs/p9_tor.C index aa8ef343d..c76fb8800 100644 --- a/src/import/chips/p9/utils/imageProcs/p9_tor.C +++ b/src/import/chips/p9/utils/imageProcs/p9_tor.C @@ -39,6 +39,7 @@ #include "p9_ringId.H" #include "p9_tor.H" #include "p9_xip_image.h" +#include "p9_scan_compression.H" #include "p9_infrastruct_help.H" namespace P9_TOR @@ -65,50 +66,56 @@ const char* ringVariantName[] = { "BASE", // ////////////////////////////////////////////////////////////////////////////////// static -int get_ring_from_sbe_image ( void* i_ringSection, // Ring section ptr - uint64_t i_magic, // Image Magic Number - RingID i_ringId, // Ring ID - uint16_t i_ddLevel, // DD level - 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 get_ring_from_sbe_image( void* i_ringSection, // Ring section ptr + uint64_t i_magic, // Image Magic Number + RingID 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 { - uint32_t acc_offset = 0; // Accumulating offset to next TOR offset slot - uint32_t ring_offset = 0; - uint16_t chiplet_offset = 0; - uint32_t next_ring_offset = 0; - uint32_t ringSize = 0; - int temp = i_ddLevel >> 2; // converting byte to word counter - uint32_t* deltaRingRS4_4B; - uint32_t sbe_offset = 0; + int rc = TOR_SUCCESS; RingVariantOrder* ring_variant_order = NULL; + 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 section starts + uint32_t cplt_offset = 0; // Local offset to where SBE 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. if (i_magic == P9_XIP_MAGIC_HW) { - sbe_offset = *((uint32_t*)i_ringSection + temp); //DD level offset index - temp = htobe32(sbe_offset); + dd_level_offset = i_ddLevelOffset; + ppe_offset = *(uint32_t*)((uint8_t*)i_ringSection + dd_level_offset); + ppe_offset = htobe32(ppe_offset); } else if (i_magic == P9_XIP_MAGIC_SEEPROM) { - sbe_offset = 0; - i_ddLevel = 0; - temp = htobe32(sbe_offset); + ppe_offset = 0; + dd_level_offset = 0; + ppe_offset = htobe32(ppe_offset); + } + else + { + MY_ERR("Magic number i_magic=0x%016lX is not valid for SBE\n", (uintptr_t)i_magic); + return TOR_INVALID_MAGIC_NUMBER; } // Looper for each SBE chiplet - for(int l = 0; l < SBE_NOOF_CHIPLETS; l++) + for(int iCplt = 0; iCplt < SBE_NOOF_CHIPLETS; iCplt++) { GenRingIdList* ring_id_list_common = NULL; GenRingIdList* ring_id_list_instance = NULL; CHIPLET_DATA l_cpltData; uint8_t l_num_variant = 1; - switch (l) + switch (iCplt) { case PERV_CPLT : l_cpltData = PERV::g_pervData; @@ -206,7 +213,6 @@ int get_ring_from_sbe_image ( void* i_ringSection, // Ring section ring_variant_order = (RingVariantOrder*) PCI0::RING_VARIANT_ORDER; break; - case PCI1_CPLT : l_cpltData = PCI1::g_pci1Data; l_num_variant = (uint8_t)sizeof(PCI1::RingVariants) / sizeof(uint16_t); @@ -240,7 +246,7 @@ int get_ring_from_sbe_image ( void* i_ringSection, // Ring section break; default : - MY_ERR("Chiplet=%d is not valid. \n", l); + MY_ERR("Chiplet=%d is not valid for SBE. \n", iCplt); return TOR_INVALID_CHIPLET; } @@ -253,43 +259,51 @@ int get_ring_from_sbe_image ( void* i_ringSection, // Ring section l_num_variant); } - uint32_t local = 0; + + // + // 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 j = 0; j < l_num_variant ; j++) + for (uint8_t iVariant = 0; iVariant < l_num_variant ; iVariant++) { if (i_dbgl > 2) { - MY_INF(" Ring name %s Cplt Common ring id %d Variant id %d", - (ring_id_list_common + i)->ringName, i, j); + 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, RING_PROPERTIES[i_ringId].iv_name) == 0) - && ( i_RingVariant == ring_variant_order->variant[j] + && ( i_RingVariant == ring_variant_order->variant[iVariant] || (i_RingVariant == OVERRIDE && i_magic == P9_XIP_MAGIC_SEEPROM))) { strcpy(o_ringName, RING_PROPERTIES[i_ringId].iv_name); - uint32_t var = l * sizeof(TorPpeBlock_t) + i_ddLevel + temp; - int temp1 = var / sizeof(uint32_t); - ring_offset = *((uint32_t*)i_ringSection + temp1); - ring_offset = htobe32(ring_offset); - var = ring_offset + i_ddLevel + temp; - temp1 = var / sizeof(uint16_t) + local; - chiplet_offset = *((uint16_t*)i_ringSection + temp1); - chiplet_offset = htobe16(chiplet_offset); + + acc_offset = dd_level_offset + ppe_offset + iCplt * sizeof(TorPpeBlock_t); + cplt_offset = *(uint32_t*)( (uint8_t*)i_ringSection + + acc_offset ); + cplt_offset = htobe32(cplt_offset); + + acc_offset = dd_level_offset + ppe_offset + cplt_offset; + ring_offset = *(uint16_t*)( (uint8_t*)i_ringSection + + acc_offset + + tor_slot_no * sizeof(ring_offset) ); + ring_offset = htobe16(ring_offset); if (i_RingBlockType == GET_SINGLE_RING) { - var = ring_offset + (chiplet_offset - sizeof(TorPpeBlock_t)) + i_ddLevel + temp; - temp1 = var / sizeof(uint32_t); - next_ring_offset = *((uint32_t*)i_ringSection + temp1); - next_ring_offset = htobe32(next_ring_offset); - ringSize = next_ring_offset; + acc_offset = dd_level_offset + + ppe_offset + + cplt_offset + + ring_offset; + ring_size = htobe16( ((CompressedScanData*) + ((uint8_t*)i_ringSection + acc_offset))->iv_size ); io_RingType = COMMON; - if (chiplet_offset) + if (ring_offset) { if (io_ringBlockSize == 0) { @@ -298,11 +312,11 @@ int get_ring_from_sbe_image ( void* i_ringSection, // Ring section MY_INF("\tio_ringBlockSize is zero. Returning required size.\n"); } - io_ringBlockSize = ringSize; + io_ringBlockSize = ring_size; return 0; } - if (io_ringBlockSize < ringSize) + if (io_ringBlockSize < ring_size) { MY_ERR("\tio_ringBlockSize is less than required size.\n"); return TOR_BUFFER_TOO_SMALL; @@ -310,119 +324,124 @@ int get_ring_from_sbe_image ( void* i_ringSection, // Ring section if (i_dbgl > 0) { - MY_INF(" ring container of %s is found in the SBE image container \n", - o_ringName); + MY_INF(" Ring %s found in the SBE section \n", o_ringName); } - memcpy( (uint8_t*)(*io_ringBlockPtr), (uint8_t*)i_ringSection + var, - (size_t)ringSize); + memcpy( (uint8_t*)(*io_ringBlockPtr), (uint8_t*)i_ringSection + acc_offset, + (size_t)ring_size); - io_ringBlockSize = ringSize; + io_ringBlockSize = ring_size; io_instanceId = (ring_id_list_common + i)->instanceIdMin; - - if (i_dbgl > 0) - { - MY_INF(" After get_ring_from_sbe_image Size %d \n", io_ringBlockSize); - } - - if (i_dbgl > 1) - { - MY_INF("Hex details Chiplet offset 0x%08x local offset 0x%08x " \ - "ring offset 0x%08x start adr 0x%08x size 0x%08x size 0x%08x \n", - var, temp, ring_offset, chiplet_offset, next_ring_offset, ringSize); - MY_INF("Chiplet %d ChipletRing TOR offset %d %d %d Size %d %d \t\n", - i, ring_offset, chiplet_offset, next_ring_offset, ringSize, temp); - } - - if (i_dbgl > 2) - { - deltaRingRS4_4B = (uint32_t*)(*io_ringBlockPtr); - - for (uint32_t m = 0; m < ringSize / sizeof(uint32_t); m++) - { - MY_INF("compressed data %d --- %08x \t", m, htobe32(deltaRingRS4_4B[m])); - } - - MY_INF("\n"); - } - - return TOR_RING_FOUND; + rc = TOR_RING_FOUND; } else { if (i_dbgl > 0) { - MY_INF(" ring container of %s is not found in the SBE image container \n", - o_ringName); + MY_INF(" Ring %s not found in the SBE section \n", o_ringName); } - return TOR_RING_NOT_FOUND; + 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_offset, cplt_offset, ring_offset, acc_offset, ring_size); + } + + return rc; + } else if (i_RingBlockType == PUT_SINGLE_RING) { - if (chiplet_offset) + if (ring_offset) { MY_ERR("Ring container is already present in the SBE section \n"); return TOR_RING_AVAILABLE_IN_RINGSECTION; } - acc_offset = var; - io_ringBlockSize = acc_offset + (local * RING_OFFSET_SIZE); + // 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; + } } - local++; + tor_slot_no++; // Next TOR slot } } - local = 0; - for(uint8_t i = (ring_id_list_instance + 0)->instanceIdMin; - i < (ring_id_list_instance + 0)->instanceIdMax + 1 ; i++) + // + // Sequentially walk the TOR slots within the chiplet's INSTANCE section + // + 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 k = 0; k < l_num_variant ; k++) + 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, k, i); + (ring_id_list_instance + j)->ringName, j, iVariant, i); } - if (strcmp( (ring_id_list_instance + j)->ringName, - RING_PROPERTIES[i_ringId].iv_name) == 0) + if (strcmp( (ring_id_list_instance + j)->ringName, + RING_PROPERTIES[i_ringId].iv_name) == 0) { if ( io_instanceId >= (ring_id_list_instance + 0)->instanceIdMin - && io_instanceId <= (ring_id_list_instance + 0)->instanceIdMax) + && io_instanceId <= (ring_id_list_instance + 0)->instanceIdMax ) { - if ( i == io_instanceId && i_RingVariant == ring_variant_order->variant[k] ) + if (i == io_instanceId && i_RingVariant == ring_variant_order->variant[iVariant]) { strcpy(o_ringName, RING_PROPERTIES[i_ringId].iv_name); - uint32_t var = l * sizeof(TorPpeBlock_t) + i_ddLevel + temp + CPLT_OFFSET_SIZE; - int temp1 = var / sizeof(uint32_t); - ring_offset = *((uint32_t*)i_ringSection + temp1); - ring_offset = htobe32(ring_offset); - var = ring_offset + i_ddLevel + temp; - temp1 = var / sizeof(uint16_t) + local; - chiplet_offset = *((uint16_t*)i_ringSection + temp1); - chiplet_offset = htobe16(chiplet_offset); + + acc_offset = dd_level_offset + + ppe_offset + + iCplt * sizeof(TorPpeBlock_t) + + sizeof(cplt_offset); // Jump to instance offset + cplt_offset = *(uint32_t*)( (uint8_t*)i_ringSection + + acc_offset ); + cplt_offset = htobe32(cplt_offset); + + acc_offset = cplt_offset + dd_level_offset + ppe_offset; + ring_offset = *(uint16_t*)( (uint8_t*)i_ringSection + + acc_offset + + tor_slot_no * sizeof(ring_offset) ); + ring_offset = htobe16(ring_offset); if (i_RingBlockType == GET_SINGLE_RING) { - var = ring_offset + (chiplet_offset - sizeof(TorPpeBlock_t)) + i_ddLevel + temp; - temp1 = var / sizeof(uint32_t); - next_ring_offset = *((uint32_t*)i_ringSection + temp1); - next_ring_offset = htobe32(next_ring_offset); - ringSize = next_ring_offset; + acc_offset = dd_level_offset + + ppe_offset + + cplt_offset + + ring_offset; + ring_size = htobe16( ((CompressedScanData*) + ((uint8_t*)i_ringSection + + acc_offset))->iv_size ); io_RingType = INSTANCE; - if (chiplet_offset) + if (ring_offset) { if (io_ringBlockSize == 0) { @@ -431,11 +450,11 @@ int get_ring_from_sbe_image ( void* i_ringSection, // Ring section MY_INF("\tio_ringBlockSize is zero. Returning required size.\n"); } - io_ringBlockSize = ringSize; + io_ringBlockSize = ring_size; return 0; } - if (io_ringBlockSize < ringSize) + if (io_ringBlockSize < ring_size) { MY_ERR("\tio_ringBlockSize is less than required size.\n"); return TOR_BUFFER_TOO_SMALL; @@ -447,85 +466,83 @@ int get_ring_from_sbe_image ( void* i_ringSection, // Ring section o_ringName); } - memcpy( (uint8_t*)(*io_ringBlockPtr), (uint8_t*)i_ringSection + var, - (size_t)ringSize); + memcpy( (uint8_t*)(*io_ringBlockPtr), (uint8_t*)i_ringSection + acc_offset, + (size_t)ring_size); - io_ringBlockSize = ringSize; + io_ringBlockSize = ring_size; if (i_dbgl > 0) { MY_INF(" After get_ring_from_sbe_image Size %d \n", io_ringBlockSize); } - if (i_dbgl > 1) - { - MY_INF(" 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x \n", - var, temp, ring_offset, chiplet_offset, next_ring_offset, ringSize); - MY_INF("Chiplet %d ChipletRing TOR offset %d %d %d Size %d %d \t\n", - i, ring_offset, chiplet_offset, next_ring_offset, ringSize, temp); - } - - if (i_dbgl > 2) - { - deltaRingRS4_4B = (uint32_t*)(*io_ringBlockPtr); - - for (uint32_t m = 0; m < ringSize / sizeof(uint32_t); m++) - { - MY_INF("compressed data %d --- %08x \t", - m, htobe32(deltaRingRS4_4B[m])); - } - - MY_INF("\n"); - } - - return TOR_RING_FOUND; + rc = TOR_RING_FOUND; } else { if (i_dbgl > 0) { - MY_INF(" ring container of %s is not found in the SBE image container \n", - o_ringName); + MY_INF(" Ring %s not found in SBE section \n", o_ringName); } - return TOR_RING_NOT_FOUND; + 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_offset, cplt_offset, ring_offset, acc_offset, ring_size); } + + return rc; } else if (i_RingBlockType == PUT_SINGLE_RING) { - if (chiplet_offset) + if (ring_offset) { MY_ERR("Ring container is already present in the SBE section \n"); return TOR_RING_AVAILABLE_IN_RINGSECTION; } - acc_offset = var; - io_ringBlockSize = acc_offset + (local * RING_OFFSET_SIZE); + // 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 { MY_ERR(" 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; } } - local++; + tor_slot_no++; } - } - } - } + MY_ERR("i_ringId=0x%x is an invalid ring ID for SBE", i_ringId); + return TOR_INVALID_RING_ID; } // End of get_ring_from_sbe_image() @@ -541,7 +558,7 @@ static int get_ring_from_sgpe_image ( void* i_ringSection, // Ring section ptr uint64_t i_magic, // Image Magic Number RingID i_ringId, // Ring ID - uint16_t i_ddLevel, // DD level details + 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 @@ -554,10 +571,8 @@ int get_ring_from_sgpe_image ( void* i_ringSection, // Ring sectio uint32_t acc_offset = 0; // Accumulating offset to next TOR offset slot uint32_t ring_offset = 0; uint16_t chiplet_offset = 0; - uint32_t next_ring_offset = 0; uint32_t ringSize = 0; - int temp = (i_ddLevel >> 2) + 4; // converting byte to word counter - uint32_t* deltaRingRS4_4B; + int temp = (i_ddLevelOffset >> 2) + 4; // converting byte to word counter uint32_t spge_offset = 0; if (i_magic == P9_XIP_MAGIC_HW) @@ -568,7 +583,7 @@ int get_ring_from_sgpe_image ( void* i_ringSection, // Ring sectio else if (i_magic == P9_XIP_MAGIC_SGPE) { spge_offset = 0; - i_ddLevel = 0; + i_ddLevelOffset = 0; temp = htobe32(spge_offset); } @@ -586,7 +601,7 @@ int get_ring_from_sgpe_image ( void* i_ringSection, // Ring sectio { if (i_dbgl > 2) { - MY_INF(" Ring name %s Cplt Common ring id %d Variant id %d", + MY_INF(" Ring %s Cplt common ring id %d Variant id %d\n", (ring_id_list_common + i)->ringName, i, j); } @@ -594,22 +609,21 @@ int get_ring_from_sgpe_image ( void* i_ringSection, // Ring sectio RING_PROPERTIES[i_ringId].iv_name) == 0) && ( i_RingVariant == j )) { strcpy(o_ringName, RING_PROPERTIES[i_ringId].iv_name); - uint32_t var = 0 + i_ddLevel + temp; + uint32_t var = 0 + i_ddLevelOffset + temp; int temp1 = var / sizeof(uint32_t); ring_offset = *((uint32_t*)i_ringSection + temp1); ring_offset = htobe32(ring_offset); - var = ring_offset + i_ddLevel + temp; + var = ring_offset + i_ddLevelOffset + temp; temp1 = var / sizeof(uint16_t) + local; chiplet_offset = *((uint16_t*)i_ringSection + temp1); chiplet_offset = htobe16(chiplet_offset); if (i_RingBlockType == GET_SINGLE_RING) { - var = ring_offset + (chiplet_offset - sizeof(TorPpeBlock_t)) + i_ddLevel + temp; - temp1 = var / sizeof(uint32_t); - next_ring_offset = *((uint32_t*)i_ringSection + temp1); - next_ring_offset = htobe32(next_ring_offset); - ringSize = next_ring_offset; + var = ring_offset + chiplet_offset + i_ddLevelOffset + temp; + ringSize = htobe16( ((CompressedScanData*) + ((uint8_t*)i_ringSection + + var))->iv_size ); io_RingType = COMMON; if (chiplet_offset) @@ -633,8 +647,7 @@ int get_ring_from_sgpe_image ( void* i_ringSection, // Ring sectio if (i_dbgl > 0) { - MY_INF(" ring container of %s is found in the SGPE image container && ring offset %d \n", - o_ringName, chiplet_offset); + MY_INF(" Ring %s found in the SGPE section \n", o_ringName); } memcpy( (uint8_t*)(*io_ringBlockPtr), (uint8_t*)i_ringSection + var, @@ -645,28 +658,9 @@ int get_ring_from_sgpe_image ( void* i_ringSection, // Ring sectio if (i_dbgl > 0) { - MY_INF(" After get_ring_from_sgpe_image Size %d \n", io_ringBlockSize); - } - - if (i_dbgl > 1) - { - MY_INF("Hex details Chiplet offset 0x%08x local offset 0x%08x " \ - "ring offset 0x%08x start adr 0x%08x size 0x%08x size 0x%08x \n", - var, temp, ring_offset, chiplet_offset, next_ring_offset, ringSize); - MY_INF("Chiplet %d ChipletRing TOR offset %d %d %d Size %d %d \t\n", - i, ring_offset, chiplet_offset, next_ring_offset, ringSize, temp); - } - - if (i_dbgl > 2) - { - deltaRingRS4_4B = (uint32_t*)(*io_ringBlockPtr); - - for (uint32_t m = 0; m < ringSize / sizeof(uint32_t); m++) - { - MY_INF("compressed data %d --- %08x \t", m, htobe32(deltaRingRS4_4B[m])); - } - - MY_INF("\n"); + 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, temp, ring_offset, chiplet_offset, ringSize); } return TOR_RING_FOUND; @@ -675,8 +669,7 @@ int get_ring_from_sgpe_image ( void* i_ringSection, // Ring sectio { if (i_dbgl > 0) { - MY_INF(" ring container of %s is not found in the SGPE image container \n", - o_ringName); + MY_INF(" Ring %s not found in the SGPE section \n", o_ringName); } return TOR_RING_NOT_FOUND; @@ -696,6 +689,11 @@ int get_ring_from_sgpe_image ( void* i_ringSection, // Ring sectio 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++; @@ -728,22 +726,21 @@ int get_ring_from_sgpe_image ( void* i_ringSection, // Ring sectio if ( i == io_instanceId && k == i_RingVariant ) { strcpy(o_ringName, RING_PROPERTIES[i_ringId].iv_name); - uint32_t var = CPLT_OFFSET_SIZE + i_ddLevel + temp; + uint32_t var = CPLT_OFFSET_SIZE + i_ddLevelOffset + temp; int temp1 = var / sizeof(uint32_t); ring_offset = *((uint32_t*)i_ringSection + temp1); ring_offset = htobe32(ring_offset); - var = ring_offset + i_ddLevel + temp; + var = ring_offset + i_ddLevelOffset + temp; temp1 = var / sizeof(uint16_t) + local; chiplet_offset = *((uint16_t*)i_ringSection + temp1); chiplet_offset = htobe16(chiplet_offset); if (i_RingBlockType == GET_SINGLE_RING) { - var = ring_offset + (chiplet_offset - sizeof(TorPpeBlock_t)) + i_ddLevel + temp; - temp1 = var / sizeof(uint32_t); - next_ring_offset = *((uint32_t*)i_ringSection + temp1); - next_ring_offset = htobe32(next_ring_offset); - ringSize = next_ring_offset; + var = ring_offset + chiplet_offset + i_ddLevelOffset + temp; + ringSize = htobe16( ((CompressedScanData*) + ((uint8_t*)i_ringSection + + var))->iv_size ); io_RingType = INSTANCE; if (chiplet_offset) @@ -781,24 +778,11 @@ int get_ring_from_sgpe_image ( void* i_ringSection, // Ring sectio MY_INF(" After get_ring_from_sgpe_image Size %d \n", io_ringBlockSize); } - if (i_dbgl > 1) - { - MY_INF(" 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x \n", - var, temp, ring_offset, chiplet_offset, next_ring_offset, ringSize); - MY_INF("Chiplet %d ChipletRing TOR offset %d %d %d Size %d %d \t\n", - i, ring_offset, chiplet_offset, next_ring_offset, ringSize, temp); - } - - if (i_dbgl > 2) + if (i_dbgl > 0) { - deltaRingRS4_4B = (uint32_t*)(*io_ringBlockPtr); - - for (uint32_t m = 0; m < ringSize / sizeof(uint32_t); m++) - { - MY_INF("compressed data %d --- %08x \t", m, htobe32(deltaRingRS4_4B[m])); - } - - MY_INF("\n"); + 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, temp, ring_offset, chiplet_offset, ringSize); } return TOR_RING_FOUND; @@ -828,6 +812,11 @@ int get_ring_from_sgpe_image ( void* i_ringSection, // Ring sectio 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 @@ -859,7 +848,7 @@ static int get_ring_from_cme_image ( void* i_ringSection, // Ring section ptr uint64_t i_magic, // Image Magic Number RingID i_ringId, // Ring ID - uint16_t i_ddLevel, // DD level + 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 @@ -872,10 +861,8 @@ int get_ring_from_cme_image ( void* i_ringSection, // Ring section uint32_t acc_offset = 0; // Accumulating offset to next TOR offset slot uint32_t ring_offset = 0; uint16_t chiplet_offset = 0; - uint32_t next_ring_offset = 0; uint32_t ringSize = 0; - int temp = (i_ddLevel >> 2) + 2; // converting byte to word counter - uint32_t* deltaRingRS4_4B; + int temp = (i_ddLevelOffset >> 2) + 2; // converting byte to word counter uint32_t cme_offset = 0; if (i_magic == P9_XIP_MAGIC_HW) @@ -886,7 +873,7 @@ int get_ring_from_cme_image ( void* i_ringSection, // Ring section else if (i_magic == P9_XIP_MAGIC_CME) { cme_offset = 0; - i_ddLevel = 0; + i_ddLevelOffset = 0; temp = htobe32(cme_offset); } @@ -904,7 +891,7 @@ int get_ring_from_cme_image ( void* i_ringSection, // Ring section { if (i_dbgl > 2) { - MY_INF(" Ring name %s Cplt Common ring id %d Variant id %d", + MY_INF(" Ring %s Cplt common ring id %d Variant id %d\n", (ring_id_list_common + i)->ringName, i, j); } @@ -912,22 +899,21 @@ int get_ring_from_cme_image ( void* i_ringSection, // Ring section RING_PROPERTIES[i_ringId].iv_name) == 0) && ( i_RingVariant == j )) { strcpy(o_ringName, RING_PROPERTIES[i_ringId].iv_name); - uint32_t var = 0 + i_ddLevel + temp; + uint32_t var = 0 + i_ddLevelOffset + temp; int temp1 = var / sizeof(uint32_t); ring_offset = *((uint32_t*)i_ringSection + temp1); ring_offset = htobe32(ring_offset); - var = ring_offset + i_ddLevel + temp; + var = ring_offset + i_ddLevelOffset + temp; temp1 = var / sizeof(uint16_t) + local; chiplet_offset = *((uint16_t*)i_ringSection + temp1); chiplet_offset = htobe16(chiplet_offset); if (i_RingBlockType == GET_SINGLE_RING) { - var = ring_offset + (chiplet_offset - sizeof(TorPpeBlock_t)) + i_ddLevel + temp; - temp1 = var / sizeof(uint32_t); - next_ring_offset = *((uint32_t*)i_ringSection + temp1); - next_ring_offset = htobe32(next_ring_offset); - ringSize = next_ring_offset; + var = ring_offset + chiplet_offset + i_ddLevelOffset + temp; + ringSize = htobe16( ((CompressedScanData*) + ((uint8_t*)i_ringSection + + var))->iv_size ); io_RingType = COMMON; if (chiplet_offset) @@ -951,8 +937,7 @@ int get_ring_from_cme_image ( void* i_ringSection, // Ring section if (i_dbgl > 0) { - MY_INF(" ring container of %s is found in the CME image container \n", - o_ringName); + MY_INF(" Ring %s found in the CME section \n", o_ringName); } memcpy( (uint8_t*)(*io_ringBlockPtr), (uint8_t*)i_ringSection + var, @@ -963,28 +948,9 @@ int get_ring_from_cme_image ( void* i_ringSection, // Ring section if (i_dbgl > 0) { - MY_INF(" After get_ring_from_cme_image Size %d \n", io_ringBlockSize); - } - - if (i_dbgl > 1) - { - MY_INF("Hex details Chiplet offset 0x%08x local offset 0x%08x " \ - "ring offset 0x%08x start adr 0x%08x size 0x%08x size 0x%08x \n", - var, temp, ring_offset, chiplet_offset, next_ring_offset, ringSize); - MY_INF("Chiplet %d ChipletRing TOR offset %d %d %d Size %d %d \t\n", - i, ring_offset, chiplet_offset, next_ring_offset, ringSize, temp); - } - - if (i_dbgl > 2) - { - deltaRingRS4_4B = (uint32_t*)(*io_ringBlockPtr); - - for (uint32_t m = 0; m < ringSize / sizeof(uint32_t); m++) - { - MY_INF("compressed data %d --- %08x \t", m, htobe32(deltaRingRS4_4B[m])); - } - - MY_INF("\n"); + 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, temp, ring_offset, chiplet_offset, ringSize); } return TOR_RING_FOUND; @@ -993,8 +959,7 @@ int get_ring_from_cme_image ( void* i_ringSection, // Ring section { if (i_dbgl > 0) { - MY_INF(" ring container of %s is not found in the CME image container \n", - o_ringName); + MY_INF(" Ring %s not found in the CME section \n", o_ringName); } return TOR_RING_NOT_FOUND; @@ -1014,6 +979,11 @@ int get_ring_from_cme_image ( void* i_ringSection, // Ring section 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; + } } local++; @@ -1049,22 +1019,21 @@ int get_ring_from_cme_image ( void* i_ringSection, // Ring section if ( i == io_instanceId && k == i_RingVariant ) { strcpy(o_ringName, RING_PROPERTIES[i_ringId].iv_name); - uint32_t var = z * CPLT_OFFSET_SIZE + i_ddLevel + temp + CPLT_OFFSET_SIZE; + uint32_t var = z * CPLT_OFFSET_SIZE + i_ddLevelOffset + temp + CPLT_OFFSET_SIZE; int temp1 = var / CPLT_OFFSET_SIZE; ring_offset = *((uint32_t*)i_ringSection + temp1); ring_offset = htobe32(ring_offset); - var = ring_offset + i_ddLevel + temp; + var = ring_offset + i_ddLevelOffset + temp; temp1 = var / sizeof(uint16_t) + local; chiplet_offset = *((uint16_t*)i_ringSection + temp1); chiplet_offset = htobe16(chiplet_offset); if (i_RingBlockType == GET_SINGLE_RING) { - var = ring_offset + (chiplet_offset - sizeof(TorPpeBlock_t)) + i_ddLevel + temp; - temp1 = var / sizeof(uint32_t); - next_ring_offset = *((uint32_t*)i_ringSection + temp1); - next_ring_offset = htobe32(next_ring_offset); - ringSize = next_ring_offset; + var = ring_offset + chiplet_offset + i_ddLevelOffset + temp; + ringSize = htobe16( ((CompressedScanData*) + ((uint8_t*)i_ringSection + + var))->iv_size ); io_RingType = INSTANCE; if (chiplet_offset) @@ -1088,10 +1057,9 @@ int get_ring_from_cme_image ( void* i_ringSection, // Ring section if (i_dbgl > 0) { - MY_INF(" ring container of %s is found in the CME image container %d %d \n", - o_ringName, chiplet_offset, ringSize); - MY_INF(" 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x \n", - var, temp, ring_offset, chiplet_offset, next_ring_offset, ringSize); + 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, temp, ring_offset, chiplet_offset, ringSize); } memcpy( (uint8_t*)(*io_ringBlockPtr), (uint8_t*)i_ringSection + var, @@ -1106,22 +1074,10 @@ int get_ring_from_cme_image ( void* i_ringSection, // Ring section if (i_dbgl > 1) { - MY_INF(" 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x \n", - var, temp, ring_offset, chiplet_offset, next_ring_offset, ringSize); - MY_INF("Chiplet %d ChipletRing TOR offset %d %d %d Size %d %d \t\n", - i, ring_offset, chiplet_offset, next_ring_offset, ringSize, temp); - } - - if (i_dbgl > 2) - { - deltaRingRS4_4B = (uint32_t*)(*io_ringBlockPtr); - - for (uint32_t m = 0; m < ringSize / sizeof(uint32_t); m++) - { - MY_INF("compressed data %d --- %08x \t", m, htobe32(deltaRingRS4_4B[m])); - } - - MY_INF("\n"); + MY_INF(" 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x \n", + var, temp, ring_offset, chiplet_offset, ringSize); + MY_INF("Chiplet %d ChipletRing TOR offset %d %d Size %d %d \t\n", + i, ring_offset, chiplet_offset, ringSize, temp); } return TOR_RING_FOUND; @@ -1151,6 +1107,11 @@ int get_ring_from_cme_image ( void* i_ringSection, // Ring section 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 @@ -1236,7 +1197,7 @@ int tor_access_ring( void* i_ringSection, // Ring section ptr if (i_dbgl > 1) { - MY_INF( "tor_access_ring(): DD level offset: 0x%08x DD level: 0x%x \n", + MY_INF( "tor_access_ring(): Local DD level offset: 0x%08x for DD level: 0x%x \n", ddLevelOffset, ddLevel ); } @@ -1915,43 +1876,9 @@ int tor_access_ring( void* i_ringSection, // Ring section ptr o_ringName, i_dbgl); - if (rc == TOR_RING_NOT_FOUND) + if (rc) { - if (i_dbgl > 0) - { - MY_INF("\t After SBE single ring call, %s ring container is not found \n", - RING_PROPERTIES[i_ringId].iv_name); - } - - return rc; - } - else if (rc == TOR_INVALID_INSTANCE_ID) - { - if (i_dbgl > 0) - { - MY_INF("\t After SBE 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 SBE 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 SBE single ring call, There is no TOR slot for %s %d\n", - RING_PROPERTIES[i_ringId].iv_name, i_ringId); - } - + MY_ERR("get_ring_from_sbe_image failed w/rc=%d\n", rc); return rc; } else @@ -2271,7 +2198,8 @@ int tor_get_block_of_rings ( void* i_ringSection, // Ring section // /////////////////////////////////////////////////////////////////////////////////////// int tor_append_ring( void* i_ringSection, // Ring section ptr - uint32_t& io_ringSectionSize, // Max size of ring section buffer + uint32_t& io_ringSectionSize, // In: Exact size of ring section. + // Out: Updated size of ring section. void* i_ringBuffer, // Ring work buffer const uint32_t i_ringBufferSize, // Max size of ring work buffer RingID i_ringId, // Ring ID @@ -2284,12 +2212,12 @@ int tor_append_ring( void* i_ringSection, // Ring section ptr { uint32_t rc = 0; char i_ringName[25]; - uint32_t l_ringTypeBuf = 0; - uint32_t* l_ringTypeStart = &l_ringTypeBuf; + uint32_t l_buf = 0; + uint32_t* l_cpltSection = &l_buf; uint8_t l_instanceId = i_instanceId; RingType_t l_RingType = i_RingType; uint32_t l_ringBlockSize; - uint16_t l_ringOffsetAddr16; + uint16_t l_ringOffset16; uint64_t l_magic; uint32_t l_torOffsetSlot; @@ -2297,17 +2225,17 @@ int tor_append_ring( void* i_ringSection, // Ring section ptr { l_magic = P9_XIP_MAGIC_SEEPROM; } - else if (i_PpeType == CME ) // Assign i_magic variant as CME image + else if (i_PpeType == CME) // Assign i_magic variant as CME image { l_magic = P9_XIP_MAGIC_CME; } - else if (i_PpeType == SGPE ) // Assign i_magic variant as SGPE image + else if (i_PpeType == SGPE) // Assign i_magic variant as SGPE image { l_magic = P9_XIP_MAGIC_SGPE; } else { - MY_ERR("TOR_APPEND_RING(2): i_PpeType=%d is an unsupported PPE type\n", i_PpeType); + MY_ERR("PPE type (i_PpeType=%d) is not supported \n", i_PpeType); return TOR_AMBIGUOUS_API_PARMS; } @@ -2320,42 +2248,51 @@ int tor_append_ring( void* i_ringSection, // Ring section ptr i_RingVariant, l_instanceId, PUT_SINGLE_RING, - (void**)&l_ringTypeStart, // On return, contains absolute offset addr where RingType starts in TOR - l_torOffsetSlot, // On return, contains absolute offset addr where TOR offset slot is located + (void**)&l_cpltSection, // On return, contains offset (wrt ringSection) of + // chiplet section's common or instance section + l_torOffsetSlot, // On return, contains offset (wrt ringSection) of + // TOR offset slot i_ringName, i_dbgl); if (rc) { - MY_ERR("\tTOR_APPEND_RING(3): Failure on tor_access_ring function call ...\n"); + MY_ERR("tor_access_ring() failed w/rc=0x%x \n", rc); return rc; } if (i_dbgl > 1) { - MY_INF(" TOR_APPEND_RING(4): Ring offset address %d \n", - l_torOffsetSlot ); + MY_INF(" TOR offset slot for ring address %d \n", l_torOffsetSlot ); } - // Current ring offset address contains old rs4 image starting address. - // When tor_append_ring gets new RS4 ring data. It is appended at end of the - // .rings section and new ring pointer location is updated at ring offset address - l_ringOffsetAddr16 = (uint16_t)(*l_ringTypeStart); - l_ringOffsetAddr16 = io_ringSectionSize - l_ringOffsetAddr16; - l_ringOffsetAddr16 = htobe16(l_ringOffsetAddr16 + sizeof(RingLayout_t)); - memcpy( (uint8_t*)i_ringSection + l_torOffsetSlot, &l_ringOffsetAddr16, - sizeof(l_ringOffsetAddr16)); - - // Attaching RS4 image at end of the ring section - // reading first 4 byte of rs4_container which carries size of ring container - // memcpy appends rs4_container at end of the .rings section. - l_ringBlockSize = ((RingLayout_t*)i_rs4Container)->sizeOfThis; - l_ringBlockSize = htobe32(l_ringBlockSize); - memcpy( (uint8_t*)i_ringSection + io_ringSectionSize, (uint8_t*)i_rs4Container, - (size_t)l_ringBlockSize); + // Explanation to the following: + // tor_append_ring() appends a ring to the end of ringSection. The offset value to + // that ring is wrt the beginning of the chiplet's TOR section. Below we calculate + // the offset value and put it into the TOR slot. But first, check that the offset + // value can be contained within the 2B of the TOR slot. + if ( (io_ringSectionSize - *l_cpltSection) <= MAX_TOR_RING_OFFSET ) + { + l_ringOffset16 = htobe16(io_ringSectionSize - *l_cpltSection); + memcpy( (uint8_t*)i_ringSection + l_torOffsetSlot, + &l_ringOffset16, sizeof(l_ringOffset16) ); + } + else + { + MY_ERR("Code bug: TOR ring offset (=0x%x) exceeds MAX_TOR_RING_OFFSET (=0x%x)", + io_ringSectionSize - *l_cpltSection, MAX_TOR_RING_OFFSET); + return TOR_OFFSET_TOO_BIG; + } + + // Now append the ring to the end of ringSection. + l_ringBlockSize = htobe16( ((CompressedScanData*)i_rs4Container)->iv_size ); + memcpy( (uint8_t*)i_ringSection + io_ringSectionSize, + (uint8_t*)i_rs4Container, (size_t)l_ringBlockSize); + + // Update the ringSectionSize io_ringSectionSize += l_ringBlockSize; - return TOR_APPEND_RING_DONE; + return TOR_SUCCESS; } diff --git a/src/import/chips/p9/utils/imageProcs/p9_tor.H b/src/import/chips/p9/utils/imageProcs/p9_tor.H index 0ce738836..c6fc1368d 100644 --- a/src/import/chips/p9/utils/imageProcs/p9_tor.H +++ b/src/import/chips/p9/utils/imageProcs/p9_tor.H @@ -28,20 +28,15 @@ #include "p9_ring_id.h" #include "p9_ringId.H" +#define MAX_TOR_RING_OFFSET (256*256-1) // Max value of 2Byte uint + namespace P9_TOR { extern const char* ppeTypeName[]; extern const char* ringVariantName[]; -#define TOR_VERSION 1 - -typedef struct -{ - uint32_t sizeOfThis; - uint16_t sizeOfCmsk; - uint16_t sizeOfMeta; // Exact size of meta data. Arbitrary size. Not null terminated -} RingLayout_t; +#define TOR_VERSION 2 typedef struct { @@ -63,26 +58,28 @@ typedef struct typedef uint16_t TorRingOffset_t; // Ring offset value in TOR offset slot +#define TOR_SUCCESS 0 #define TOR_RING_FOUND 0 #define TOR_RING_BLOCKS_FOUND 0 -#define TOR_APPEND_RING_DONE 0 #define TOR_RING_NOT_FOUND 1 -#define TOR_INVALID_RING_ID 2 -#define TOR_AMBIGUOUS_API_PARMS 3 -#define TOR_SECTION_NOT_FOUND 4 -#define TOR_DD_LEVEL_NOT_FOUND 5 -#define TOR_OP_BUFFER_INVALID 6 -#define TOR_OP_BUFFER_SIZE_EXCEEDED 7 +#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_IMAGE_DOES_NOT_SUPPORT_CME 10 -#define TOR_IMAGE_DOES_NOT_SUPPORT_SGPE 11 -#define TOR_IMAGE_DOES_NOT_SUPPORT_DD_LEVEL 12 -#define TOR_IMAGE_DOES_NOT_SUPPORT_PPE_LEVEL 13 -#define TOR_RING_AVAILABLE_IN_RINGSECTION 14 // Ring is already present -#define TOR_BUFFER_TOO_SMALL 15 -#define TOR_TOO_MANY_DD_LEVELS 16 - +#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 // Different options to extract data using tor_access_ring API typedef enum RingBlockType @@ -387,8 +384,8 @@ int tor_get_block_of_rings ( void* i_ringSection, /// It contains details of p9 Ring which is used for scanning operation. /// TOR API supports SEEPROM image format. /// -/// \param[in/out] io_ringSectionSize A value to indicate actual size of -/// i_ringSection data passed in as input On return, updated size of section. +/// \param[in/out] io_ringSectionSize In: Exact size of i_ringSection. +/// Out: Updated size of i_ringSection. /// Note: Caller manages this buffer and must make sure the RS4 ring fits /// before making this call /// |