Skip to content

Commit

Permalink
Consume CXL TSP lib in EMU.
Browse files Browse the repository at this point in the history
Signed-off-by: Jiewen Yao <[email protected]>
  • Loading branch information
jyao1 committed Sep 18, 2024
1 parent de48a53 commit 44e8181
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,9 @@ endif()
add_subdirectory(library/cxl_ide_km_requester_lib)
add_subdirectory(library/cxl_ide_km_responder_lib)
add_subdirectory(library/cxl_ide_km_device_lib_sample)
add_subdirectory(library/cxl_tsp_requester_lib)
add_subdirectory(library/cxl_tsp_responder_lib)
add_subdirectory(library/cxl_tsp_device_lib_sample)
add_subdirectory(library/spdm_transport_tcp_lib)

if(NOT TOOLCHAIN STREQUAL "ARM_DS2022")
Expand Down
2 changes: 2 additions & 0 deletions spdm_emu/spdm_requester_emu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ set(spdm_requester_emu_LIBRARY
pci_ide_km_requester_lib
pci_tdisp_requester_lib
cxl_ide_km_requester_lib
cxl_tsp_requester_lib
platform_lib
)

Expand All @@ -74,6 +75,7 @@ if((TOOLCHAIN STREQUAL "KLEE") OR (TOOLCHAIN STREQUAL "CBMC"))
$<TARGET_OBJECTS:pci_ide_km_requester_lib>
$<TARGET_OBJECTS:pci_tdisp_requester_lib>
$<TARGET_OBJECTS:cxl_ide_km_requester_lib>
$<TARGET_OBJECTS:cxl_tsp_requester_lib>
$<TARGET_OBJECTS:platform_lib>
)
else()
Expand Down
1 change: 1 addition & 0 deletions spdm_emu/spdm_requester_emu/spdm_requester_emu.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "library/pci_ide_km_requester_lib.h"
#include "library/pci_tdisp_requester_lib.h"
#include "library/cxl_ide_km_requester_lib.h"
#include "library/cxl_tsp_requester_lib.h"

#include "os_include.h"
#include "stdio.h"
Expand Down
146 changes: 146 additions & 0 deletions spdm_emu/spdm_requester_emu/spdm_requester_pci_doe.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,147 @@ libspdm_return_t cxl_ide_km_process_session_message(void *spdm_context, uint32_t
return LIBSPDM_STATUS_SUCCESS;
}

libspdm_return_t cxl_tsp_process_session_message(void *spdm_context, uint32_t session_id)
{
libspdm_return_t status;
libcxltsp_device_capabilities_t device_capabilities;
libcxltsp_device_configuration_t device_configuration;
libcxltsp_device_2nd_session_info_t device_2nd_session_info;
libcxltsp_device_configuration_t current_device_configuration;
uint8_t current_tsp_state;
size_t index;
uint8_t configuration_report_buffer[LIBCXLTSP_CONFIGURATION_REPORT_MAX_SIZE];
uint32_t configuration_report_size;
cxl_tsp_target_configuration_report_t *configuration_report;

status = cxl_tsp_get_version (m_pci_doe_context, spdm_context, &session_id);
if (LIBSPDM_STATUS_IS_ERROR(status)) {
return status;
}
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "cxl_tsp_get_version done\n"));

libspdm_zero_mem (&device_capabilities, sizeof(device_capabilities));
status = cxl_tsp_get_capabilities (m_pci_doe_context, spdm_context, &session_id,
&device_capabilities);
if (LIBSPDM_STATUS_IS_ERROR(status)) {
return status;
}
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "device_capabilities:\n"));
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, " memory_encryption_features_supported - 0x%04x\n",
device_capabilities.memory_encryption_features_supported));
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, " memory_encryption_algorithms_supported - 0x%08x\n",
device_capabilities.memory_encryption_algorithms_supported));
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, " memory_encryption_number_of_range_based_keys - 0x%04x\n",
device_capabilities.memory_encryption_number_of_range_based_keys));
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, " te_state_change_and_access_control_features_supported - 0x%04x\n",
device_capabilities.te_state_change_and_access_control_features_supported));
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, " supported_explicit_oob_te_state_granularity - 0x%08x\n",
device_capabilities.supported_explicit_oob_te_state_granularity));
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, " supported_explicit_ib_te_state_granularity - 0x%08x\n",
device_capabilities.supported_explicit_ib_te_state_granularity));
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, " configuration_features_supported - 0x%04x\n",
device_capabilities.configuration_features_supported));
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, " number_of_ckids - 0x%08x\n",
device_capabilities.number_of_ckids));
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, " number_of_secondary_sessions - 0x%02x\n",
device_capabilities.number_of_secondary_sessions));

libspdm_zero_mem (&device_configuration, sizeof(device_configuration));
device_configuration.memory_encryption_features_enable =
CXL_TSP_MEMORY_ENCRYPTION_FEATURES_ENABLE_ENCRYPTION;
device_configuration.memory_encryption_algorithm_select =
CXL_TSP_MEMORY_ENCRYPTION_ALGORITHMS_AES_XTS_256;
device_configuration.te_state_change_and_access_control_features_enable =
CXL_TSP_TE_STATE_CHANGE_AND_ACCESS_CONTROL_FEATURES_READ_ACCESS_CONTROL |
CXL_TSP_TE_STATE_CHANGE_AND_ACCESS_CONTROL_FEATURES_IMPLICIT_TE_STATE_CHANGE |
CXL_TSP_TE_STATE_CHANGE_AND_ACCESS_CONTROL_FEATURES_EXPLICIT_IB_TE_STATE_CHANGE;
device_configuration.explicit_oob_te_state_granularity = 0;
device_configuration.configuration_features_enable =
CXL_TSP_CONFIGURATION_FEATURES_ENABLE_LOCKED_TARGET_FW_UPDATE;
device_configuration.ckid_base = 0;
device_configuration.number_of_ckids = 0;
device_configuration.explicit_ib_te_state_granularity_entry[0].te_state_granularity = 0;
device_configuration.explicit_ib_te_state_granularity_entry[0].length_index = 0;
device_configuration.explicit_ib_te_state_granularity_entry[1].length_index = 0xFF;
device_configuration.explicit_ib_te_state_granularity_entry[2].length_index = 0xFF;
device_configuration.explicit_ib_te_state_granularity_entry[3].length_index = 0xFF;
device_configuration.explicit_ib_te_state_granularity_entry[4].length_index = 0xFF;
device_configuration.explicit_ib_te_state_granularity_entry[5].length_index = 0xFF;
device_configuration.explicit_ib_te_state_granularity_entry[6].length_index = 0xFF;
device_configuration.explicit_ib_te_state_granularity_entry[7].length_index = 0xFF;
libspdm_zero_mem (&device_2nd_session_info, sizeof(device_2nd_session_info));
device_2nd_session_info.configuration_validity_flags = 0x0;
status = cxl_tsp_set_configuration (m_pci_doe_context, spdm_context, &session_id,
&device_configuration, &device_2nd_session_info);
if (LIBSPDM_STATUS_IS_ERROR(status)) {
return status;
}
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "cxl_tsp_set_configuration done\n"));

libspdm_zero_mem (&current_device_configuration, sizeof(current_device_configuration));
current_tsp_state = CXL_TSP_STATE_CONFIG_UNLOCKED;
status = cxl_tsp_get_configuration (m_pci_doe_context, spdm_context, &session_id,
&current_device_configuration, &current_tsp_state);
if (LIBSPDM_STATUS_IS_ERROR(status)) {
return status;
}
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "current_device_configuration:\n"));
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, " memory_encryption_features_enable - 0x%04x\n",
current_device_configuration.memory_encryption_features_enable));
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, " memory_encryption_algorithm_select - 0x%08x\n",
current_device_configuration.memory_encryption_algorithm_select));
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, " te_state_change_and_access_control_features_enable - 0x%04x\n",
current_device_configuration.te_state_change_and_access_control_features_enable));
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, " explicit_oob_te_state_granularity - 0x%08x\n",
current_device_configuration.explicit_oob_te_state_granularity));
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, " configuration_features_enable - 0x%04x\n",
current_device_configuration.configuration_features_enable));
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, " ckid_base - 0x%08x\n",
current_device_configuration.ckid_base));
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, " number_of_ckids - 0x%08x\n",
current_device_configuration.number_of_ckids));
for (index = 0; index < LIBSPDM_ARRAY_SIZE(current_device_configuration.explicit_ib_te_state_granularity_entry); index++) {
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, " explicit_ib_te_state_granularity_entry[%d]:\n", index));
#ifdef _MSC_VER
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, " te_state_granularity - 0x%016I64x\n",
current_device_configuration.explicit_ib_te_state_granularity_entry[index].te_state_granularity));
#else
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, " te_state_granularity - 0x%016llx\n",
current_device_configuration.explicit_ib_te_state_granularity_entry[index].te_state_granularity));
#endif
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, " number_of_ckids - 0x%02x\n",
current_device_configuration.explicit_ib_te_state_granularity_entry[index].length_index));
}
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "current_tsp_state - 0x%02x\n", current_tsp_state));

configuration_report_size = sizeof(configuration_report_buffer);
status = cxl_tsp_get_configuration_report (
m_pci_doe_context, spdm_context, &session_id,
configuration_report_buffer, &configuration_report_size);
if (LIBSPDM_STATUS_IS_ERROR(status)) {
return status;
}
configuration_report = (cxl_tsp_target_configuration_report_t *)configuration_report_buffer;
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "configuration_report:\n"));
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, " valid_tsp_report_fields - 0x%02x\n", configuration_report->valid_tsp_report_fields));

status = cxl_tsp_lock_configuration (m_pci_doe_context, spdm_context, &session_id);
if (LIBSPDM_STATUS_IS_ERROR(status)) {
return status;
}
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "cxl_tsp_lock_configuration done\n"));

current_tsp_state = CXL_TSP_STATE_CONFIG_UNLOCKED;
status = cxl_tsp_get_configuration (m_pci_doe_context, spdm_context, &session_id,
NULL, &current_tsp_state);
if (LIBSPDM_STATUS_IS_ERROR(status)) {
return status;
}
LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "current_tsp_state - 0x%02x\n", current_tsp_state));

return LIBSPDM_STATUS_SUCCESS;
}

libspdm_return_t pci_doe_process_session_message(void *spdm_context, uint32_t session_id)
{
libspdm_return_t status;
Expand All @@ -398,5 +539,10 @@ libspdm_return_t pci_doe_process_session_message(void *spdm_context, uint32_t se
return status;
}

status = cxl_tsp_process_session_message (spdm_context, session_id);
if (LIBSPDM_STATUS_IS_ERROR(status)) {
return status;
}

return LIBSPDM_STATUS_SUCCESS;
}
4 changes: 4 additions & 0 deletions spdm_emu/spdm_responder_emu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ set(spdm_responder_emu_LIBRARY
pci_tdisp_device_lib_sample
cxl_ide_km_responder_lib
cxl_ide_km_device_lib_sample
cxl_tsp_responder_lib
cxl_tsp_device_lib_sample
platform_lib
)

Expand Down Expand Up @@ -77,6 +79,8 @@ if((TOOLCHAIN STREQUAL "KLEE") OR (TOOLCHAIN STREQUAL "CBMC"))
$<TARGET_OBJECTS:pci_tdisp_device_lib_sample>
$<TARGET_OBJECTS:cxl_ide_km_responder_lib>
$<TARGET_OBJECTS:cxl_ide_km_device_lib_sample>
$<TARGET_OBJECTS:cxl_tsp_responder_lib>
$<TARGET_OBJECTS:cxl_tsp_device_lib_sample>
$<TARGET_OBJECTS:platform_lib>
)
else()
Expand Down
1 change: 1 addition & 0 deletions spdm_emu/spdm_responder_emu/spdm_responder_emu.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "library/pci_ide_km_responder_lib.h"
#include "library/pci_tdisp_responder_lib.h"
#include "library/cxl_ide_km_responder_lib.h"
#include "library/cxl_tsp_responder_lib.h"

#include "os_include.h"
#include <stdio.h>
Expand Down
7 changes: 7 additions & 0 deletions spdm_emu/spdm_responder_emu/spdm_responder_pci_doe.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,12 @@ libspdm_return_t pci_doe_init_responder()
if (LIBSPDM_STATUS_IS_ERROR(status)) {
return status;
}
status = pci_doe_register_vendor_response_func (
m_pci_doe_context,
SPDM_REGISTRY_ID_PCISIG, SPDM_VENDOR_ID_CXL,
CXL_PROTOCOL_ID_TSP, cxl_tsp_get_response);
if (LIBSPDM_STATUS_IS_ERROR(status)) {
return status;
}
return LIBSPDM_STATUS_SUCCESS;
}

0 comments on commit 44e8181

Please sign in to comment.