blob: 29e536dafbae2bbed55815ec50f2b6694f8c676c [file] [log] [blame]
Vadim Iosevichd50ea462017-03-30 16:19:08 +03001/*
2 * Copyright (c) 2017, The Linux Foundation. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
Vadim Iosevich20d50d82017-09-19 11:38:15 +030030#ifndef _11AD_DRIVER_API_H_
31#define _11AD_DRIVER_API_H_
Vadim Iosevichd50ea462017-03-30 16:19:08 +030032
33#include <string>
34#include <set>
Vadim Iosevich20d50d82017-09-19 11:38:15 +030035#include <vector>
36#include <sstream>
Vadim Ioseviche76832c2017-11-05 09:09:14 +020037#include <unordered_map>
Vadim Iosevichd50ea462017-03-30 16:19:08 +030038
39#include "OperatingSystemConstants.h"
Vadim Iosevich20d50d82017-09-19 11:38:15 +030040#include "Definitions.h"
Vadim Ioseviche76832c2017-11-05 09:09:14 +020041#include "DebugLogger.h"
42#include "Utils.h"
Vadim Iosevichd50ea462017-03-30 16:19:08 +030043
44using namespace std;
45
46class DriverAPI
47{
48public:
Vadim Ioseviche76832c2017-11-05 09:09:14 +020049 DriverAPI(string interfaceName): m_interfaceName(interfaceName)
Vadim Iosevichd50ea462017-03-30 16:19:08 +030050 {
Vadim Iosevichd50ea462017-03-30 16:19:08 +030051 }
Vadim Ioseviche76832c2017-11-05 09:09:14 +020052
53 virtual ~DriverAPI() {}
Vadim Iosevichd50ea462017-03-30 16:19:08 +030054
55 // Base access functions (to be implemented by specific device)
Vadim Iosevich20d50d82017-09-19 11:38:15 +030056 virtual bool Read(DWORD address, DWORD& value) { return false; }
57 virtual bool ReadBlock(DWORD addr, DWORD blockSize, vector<DWORD>& values) { return false; }
Vadim Ioseviche76832c2017-11-05 09:09:14 +020058 virtual bool ReadBlock(DWORD addr, DWORD blockSize, char *arrBlock) { return false; } // blockSize in bytes
Vadim Iosevich20d50d82017-09-19 11:38:15 +030059 virtual bool Write(DWORD address, DWORD value) { return false; }
60 virtual bool WriteBlock(DWORD addr, vector<DWORD> values) { return false; };
Vadim Ioseviche76832c2017-11-05 09:09:14 +020061 virtual bool WriteBlock(DWORD address, DWORD blockSize, const char *valuesToWrite) { return false; }
Vadim Iosevichd50ea462017-03-30 16:19:08 +030062
Vadim Iosevich20d50d82017-09-19 11:38:15 +030063 // PMC functions
64 virtual bool AllocPmc(unsigned descSize, unsigned descNum, std::string& outMessage) { return false; }
65 virtual bool DeallocPmc(std::string& outMessage) { return false; }
66 virtual bool CreatePmcFile(unsigned refNumber, std::string& outMessage) { return false; }
67 virtual bool FindPmcFile(unsigned refNumber, std::string& outMessage) { return false; }
Vadim Iosevich40679a12017-06-06 14:24:07 +030068
Vadim Ioseviche76832c2017-11-05 09:09:14 +020069 virtual bool IsOpen(void) { return false; }
Vadim Iosevich20d50d82017-09-19 11:38:15 +030070 virtual bool Open() { return false; }
71 virtual bool ReOpen() { return false; };
Vadim Iosevich40679a12017-06-06 14:24:07 +030072 virtual bool DriverControl(uint32_t Id,
Vadim Ioseviche76832c2017-11-05 09:09:14 +020073 const void *inBuf, uint32_t inBufSize,
74 void *outBuf, uint32_t outBufSize, DWORD* pLastError = nullptr) { return false; }
Vadim Iosevich20d50d82017-09-19 11:38:15 +030075 virtual void Close() {}
Vadim Iosevichd50ea462017-03-30 16:19:08 +030076
Vadim Iosevich20d50d82017-09-19 11:38:15 +030077 virtual int GetDriverMode(int &currentState) { return false; }
78 virtual bool SetDriverMode(int newState, int &oldState) { return false; }
Vadim Iosevichd50ea462017-03-30 16:19:08 +030079
Vadim Ioseviche76832c2017-11-05 09:09:14 +020080 virtual bool RegisterDriverControlEvents() { return false; }
81
Vadim Iosevich20d50d82017-09-19 11:38:15 +030082 virtual void Reset() {}; // interface reset
83
84 const string& GetInterfaceName() const
85 {
86 return m_interfaceName;
87 }
Vadim Iosevichd50ea462017-03-30 16:19:08 +030088
Vadim Ioseviche76832c2017-11-05 09:09:14 +020089 bool IsValid()
90 {
91 DWORD value;
92 if (!Read(BAUD_RATE_REGISTER, value)) return false;
93 return IsValidInternal();
94 }
95
Vadim Iosevichd50ea462017-03-30 16:19:08 +030096protected:
Vadim Ioseviche76832c2017-11-05 09:09:14 +020097
98 const string m_interfaceName;
99
100 // Enumeration for commands sent through DriverControl (translating from it to the appropriate command per OS)
101 // Note: It is a contract with DmTools and the Driver, order is important!
102 enum DRIVER_COMMAND
103 {
104 DRIVER_CMD_FW_WMI,
105 DRIVER_CMD_GENERIC_COMMAND,
106 DRIVER_GET_DRIVER_STATISTICS
107 };
108
109 std::unordered_map<DRIVER_COMMAND, uint32_t, hash<int>> m_driverCommandToIoctlMap;
110
111 virtual void InsertDriverCommandsToMap() {}
112
113private:
114
115 virtual bool IsValidInternal() { return true; }
Vadim Iosevichd50ea462017-03-30 16:19:08 +0300116};
117
118
Vadim Ioseviche76832c2017-11-05 09:09:14 +0200119#endif //_11AD_DRIVER_API_H_