2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2025-04-11 13:23:40 +00:00
|
|
|
* Copyright (C) 2019-2025 Intel Corporation
|
2018-09-18 09:11:08 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
*/
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/gmm_helper/gmm_helper.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2022-05-17 19:04:23 +00:00
|
|
|
#include "shared/source/debug_settings/debug_settings_manager.h"
|
2022-11-25 07:53:05 +00:00
|
|
|
#include "shared/source/execution_environment/root_device_environment.h"
|
2021-06-28 17:36:16 +00:00
|
|
|
#include "shared/source/gmm_helper/client_context/gmm_client_context.h"
|
2023-01-02 16:19:30 +00:00
|
|
|
#include "shared/source/helpers/basic_math.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/helpers/debug_helpers.h"
|
2023-02-01 16:23:01 +00:00
|
|
|
#include "shared/source/helpers/gfx_core_helper.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/helpers/hw_info.h"
|
|
|
|
|
#include "shared/source/memory_manager/graphics_allocation.h"
|
2024-05-27 09:27:22 +00:00
|
|
|
#include "shared/source/os_interface/product_helper.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2019-12-24 13:51:39 +01:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2018-07-23 12:23:48 +02:00
|
|
|
|
2019-12-04 12:36:16 +01:00
|
|
|
GmmClientContext *GmmHelper::getClientContext() const {
|
|
|
|
|
return gmmClientContext.get();
|
2018-07-23 12:23:48 +02:00
|
|
|
}
|
|
|
|
|
|
2018-07-27 13:59:39 +02:00
|
|
|
const HardwareInfo *GmmHelper::getHardwareInfo() {
|
2022-12-19 18:41:13 +00:00
|
|
|
return rootDeviceEnvironment.getHardwareInfo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const RootDeviceEnvironment &GmmHelper::getRootDeviceEnvironment() const {
|
|
|
|
|
return rootDeviceEnvironment;
|
2018-07-27 13:59:39 +02:00
|
|
|
}
|
|
|
|
|
|
2020-02-04 12:13:57 +01:00
|
|
|
uint32_t GmmHelper::getMOCS(uint32_t type) const {
|
2023-11-30 08:32:25 +00:00
|
|
|
if (allResourcesUncached || (debugManager.flags.ForceAllResourcesUncached.get() == true)) {
|
2021-12-07 15:32:00 +00:00
|
|
|
type = GMM_RESOURCE_USAGE_OCL_BUFFER_CACHELINE_MISALIGNED;
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-11 13:23:40 +00:00
|
|
|
if (this->rootDeviceEnvironment.getProductHelper().deferMOCSToPatIndex()) {
|
2024-05-27 09:27:22 +00:00
|
|
|
return 0u;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-23 12:23:48 +02:00
|
|
|
MEMORY_OBJECT_CONTROL_STATE mocs = gmmClientContext->cachePolicyGetMemoryObject(nullptr, static_cast<GMM_RESOURCE_USAGE_TYPE>(type));
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
return static_cast<uint32_t>(mocs.DwordValue);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-23 14:13:06 +00:00
|
|
|
void GmmHelper::applyMocsEncryptionBit(uint32_t &index) {
|
2023-11-30 08:32:25 +00:00
|
|
|
if (debugManager.flags.ForceStatelessMocsEncryptionBit.get() == 1) {
|
2022-09-23 14:13:06 +00:00
|
|
|
index |= 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-19 18:41:13 +00:00
|
|
|
GmmHelper::GmmHelper(const RootDeviceEnvironment &rootDeviceEnvironmentArg) : rootDeviceEnvironment(rootDeviceEnvironmentArg) {
|
|
|
|
|
auto hwInfo = getHardwareInfo();
|
2019-12-24 13:51:39 +01:00
|
|
|
auto hwInfoAddressWidth = Math::log2(hwInfo->capabilityTable.gpuAddressSpace + 1);
|
2022-06-08 08:23:02 +00:00
|
|
|
addressWidth = std::max(hwInfoAddressWidth, 48u);
|
2020-11-27 14:26:12 +01:00
|
|
|
|
2022-11-25 07:53:05 +00:00
|
|
|
gmmClientContext = GmmHelper::createGmmContextWrapperFunc(rootDeviceEnvironment);
|
2019-10-15 15:05:47 +02:00
|
|
|
UNRECOVERABLE_IF(!gmmClientContext);
|
2018-07-03 10:00:12 +02:00
|
|
|
}
|
2019-10-15 15:05:47 +02:00
|
|
|
|
2023-07-03 09:44:27 +00:00
|
|
|
uint64_t GmmHelper::canonize(uint64_t address) const {
|
2022-06-08 08:23:02 +00:00
|
|
|
return static_cast<int64_t>(address << (64 - addressWidth)) >> (64 - addressWidth);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-03 09:44:27 +00:00
|
|
|
uint64_t GmmHelper::decanonize(uint64_t address) const {
|
2022-06-08 08:23:02 +00:00
|
|
|
return (address & maxNBitValue(addressWidth));
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-23 15:32:23 +00:00
|
|
|
bool GmmHelper::isValidCanonicalGpuAddress(uint64_t address) {
|
2022-04-25 19:34:32 +00:00
|
|
|
auto decanonizedAddress = this->decanonize(address);
|
2022-04-29 13:28:15 +00:00
|
|
|
auto canonizedAddress = this->canonize(decanonizedAddress);
|
2021-12-23 15:32:23 +00:00
|
|
|
|
|
|
|
|
if (address == canonizedAddress) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-15 15:05:47 +02:00
|
|
|
GmmHelper::~GmmHelper() = default;
|
|
|
|
|
|
2021-06-28 17:36:16 +00:00
|
|
|
decltype(GmmHelper::createGmmContextWrapperFunc) GmmHelper::createGmmContextWrapperFunc = GmmClientContext::create<GmmClientContext>;
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|