1 /*
2  * Copyright (C) 2018-2021 Intel Corporation
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  */
7 
8 #pragma once
9 #include "shared/source/helpers/constants.h"
10 
11 #include <memory>
12 
13 namespace NEO {
14 class GmmClientContext;
15 class OSInterface;
16 struct HardwareInfo;
17 
18 class GmmHelper {
19   public:
20     GmmHelper() = delete;
21     GmmHelper(OSInterface *osInterface, const HardwareInfo *hwInfo);
22     MOCKABLE_VIRTUAL ~GmmHelper();
23 
24     const HardwareInfo *getHardwareInfo();
25     uint32_t getMOCS(uint32_t type) const;
disableL3CacheForDebug()26     void disableL3CacheForDebug() { l3CacheForDebugDisabled = true; };
27 
28     static constexpr uint64_t maxPossiblePitch = (1ull << 31);
29 
canonize(uint64_t address)30     static uint64_t canonize(uint64_t address) {
31         return static_cast<int64_t>(address << (64 - GmmHelper::addressWidth)) >> (64 - GmmHelper::addressWidth);
32     }
33 
decanonize(uint64_t address)34     static uint64_t decanonize(uint64_t address) {
35         return (address & maxNBitValue(GmmHelper::addressWidth));
36     }
37 
38     GmmClientContext *getClientContext() const;
39 
40     static std::unique_ptr<GmmClientContext> (*createGmmContextWrapperFunc)(OSInterface *, HardwareInfo *);
41 
42   protected:
43     static uint32_t addressWidth;
44     const HardwareInfo *hwInfo = nullptr;
45     std::unique_ptr<GmmClientContext> gmmClientContext;
46     bool l3CacheForDebugDisabled = false;
47 };
48 } // namespace NEO
49