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