1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
/*
* Copyright (C) 2024-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "level_zero/sysman/source/api/vf_management/sysman_vf_management.h"
#include "level_zero/sysman/source/api/vf_management/sysman_os_vf.h"
#include "level_zero/sysman/source/api/vf_management/sysman_vf_imp.h"
namespace L0 {
namespace Sysman {
VfManagementHandleContext::~VfManagementHandleContext() {
handleList.clear();
}
void VfManagementHandleContext::createHandle(uint32_t vfId) {
std::unique_ptr<VfManagement> pVf = std::make_unique<VfImp>(pOsSysman, vfId);
handleList.push_back(std::move(pVf));
}
ze_result_t VfManagementHandleContext::init() {
uint32_t enabledVfNum = OsVf::getNumEnabledVfs(pOsSysman);
for (uint32_t vfIndex = 1; vfIndex <= enabledVfNum; vfIndex++) {
createHandle(vfIndex);
}
return ZE_RESULT_SUCCESS;
}
ze_result_t VfManagementHandleContext::vfManagementGet(uint32_t *pCount, zes_vf_handle_t *phVfManagement) {
std::call_once(initVfManagementOnce, [this]() {
this->init();
});
uint32_t handleListSize = static_cast<uint32_t>(handleList.size());
uint32_t numToCopy = std::min(*pCount, handleListSize);
if (0 == *pCount || *pCount > handleListSize) {
*pCount = handleListSize;
return ZE_RESULT_SUCCESS;
}
if (nullptr != phVfManagement) {
for (uint32_t i = 0; i < numToCopy; i++) {
phVfManagement[i] = handleList[i]->toVfManagementHandle();
}
}
return ZE_RESULT_SUCCESS;
}
} // namespace Sysman
} // namespace L0
|