| 1 |
/* |
| 2 |
* Copyright (c) 2018, Intel Corporation |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
* copy of this software and associated documentation files (the "Software"), |
| 6 |
* to deal in the Software without restriction, including without limitation |
| 7 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 9 |
* Software is furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice shall be included |
| 12 |
* in all copies or substantial portions of the Software. |
| 13 |
* |
| 14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 |
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 21 |
*/ |
| 22 |
#ifndef __GPU_CMD_H__ |
| 23 |
#define __GPU_CMD_H__ |
| 24 |
|
| 25 |
#include <memory> |
| 26 |
#include <vector> |
| 27 |
#include "devconfig.h" |
| 28 |
#include "gtest/gtest.h" |
| 29 |
|
| 30 |
class GpuCmdInterface |
| 31 |
{ |
| 32 |
public: |
| 33 |
|
| 34 |
using pcmditf_t = std::shared_ptr<GpuCmdInterface>; |
| 35 |
|
| 36 |
virtual int32_t GetOpCode() const = 0; |
| 37 |
|
| 38 |
virtual void Validate(const void *p) const = 0; |
| 39 |
|
| 40 |
virtual ~GpuCmdInterface() { } |
| 41 |
}; |
| 42 |
|
| 43 |
template<typename _CmdType> |
| 44 |
class GpuCmd : public GpuCmdInterface |
| 45 |
{ |
| 46 |
public: |
| 47 |
|
| 48 |
using cmd_t = _CmdType; |
| 49 |
|
| 50 |
static void ExpectEqWithMask(uint32_t src, uint32_t dst, uint32_t msk = 0xffffffff) |
| 51 |
{ |
| 52 |
EXPECT_EQ(src & msk, dst & msk) << "Validating \"" << typeid(cmd_t).name() << "\" failed\n"; |
| 53 |
} |
| 54 |
|
| 55 |
static void ExpectEqOrZeroWithMask(uint32_t src, uint32_t dst, uint32_t msk = 0xffffffff) |
| 56 |
{ |
| 57 |
if (dst & msk) |
| 58 |
{ |
| 59 |
ExpectEqWithMask(src, dst, msk); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
static void CacheCheck1(uint32_t src, uint32_t dst) |
| 64 |
{ |
| 65 |
ExpectEqWithMask(src, dst, 0x7f); |
| 66 |
} |
| 67 |
|
| 68 |
static void CacheCheck2(uint32_t src, uint32_t dst) |
| 69 |
{ |
| 70 |
ExpectEqOrZeroWithMask(src, dst, 0x7f); |
| 71 |
} |
| 72 |
|
| 73 |
int32_t GetOpCode() const override |
| 74 |
{ |
| 75 |
return m_pCmd->DW0.Value; |
| 76 |
} |
| 77 |
|
| 78 |
void Validate(const void *p) const override |
| 79 |
{ |
| 80 |
auto pCmd = static_cast<const cmd_t *>(p); |
| 81 |
|
| 82 |
ValidateCachePolicy(pCmd); |
| 83 |
} |
| 84 |
|
| 85 |
protected: |
| 86 |
|
| 87 |
virtual void ValidateCachePolicy(const cmd_t *pCmd) const = 0; |
| 88 |
|
| 89 |
protected: |
| 90 |
|
| 91 |
std::shared_ptr<cmd_t> m_pCmd = std::make_shared<cmd_t>(); |
| 92 |
}; |
| 93 |
|
| 94 |
#endif // __GPU_CMD_H__ |