-
Notifications
You must be signed in to change notification settings - Fork 8
/
pimon_charDev.h
155 lines (124 loc) · 5.96 KB
/
pimon_charDev.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/******************************************************************************\
* Native ESXi on Arm driver for hardware monitoring on the Raspberry Pi.
* Copyright (c) 2020 Tom Hebel
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
\******************************************************************************/
/*
* pimon_charDev.h --
*/
#ifndef PIMON_CHARDEV_H
#define PIMON_CHARDEV_H
/***********************************************************************/
#define VMKAPI_ONLY
#include "vmkapi.h"
#include "pimon.h"
/***********************************************************************/
#define PIMON_CHARDEV_BUFFER_SIZE 4096 /* Probably overkill */
#define PIMON_CHARDEV_POLL_TIMEOUT_US 1000000
/***********************************************************************/
/*
* Callbacks for gluing the char dev driver to the THX driver
*/
typedef VMK_ReturnStatus (*pimon_CharDevOpenCB_t)(vmk_CharDevFdAttr *attr);
typedef VMK_ReturnStatus (*pimon_CharDevCloseCB_t)(vmk_CharDevFdAttr *attr);
typedef VMK_ReturnStatus (*pimon_CharDevIoctlCB_t)(unsigned int cmd,
void *ioctlData,
vmk_ByteCount dataLen);
typedef VMK_ReturnStatus (*pimon_CharDevReadCB_t)(char *buffer,
vmk_ByteCount nbytes,
vmk_loff_t *ppos,
vmk_ByteCountSigned *nread);
typedef VMK_ReturnStatus (*pimon_CharDevWriteCB_t)(char *buffer,
vmk_ByteCount nbytes,
vmk_loff_t *ppos,
vmk_ByteCountSigned *nread);
typedef struct pimon_CharDevCallbacks_t {
pimon_CharDevOpenCB_t open;
pimon_CharDevCloseCB_t close;
pimon_CharDevIoctlCB_t ioctl;
pimon_CharDevReadCB_t read;
pimon_CharDevWriteCB_t write;
} pimon_CharDevCallbacks_t;
typedef struct pimon_CharDevPriv_t {
/* The size of the data being passed via ioctl */
vmk_ByteCount ioctlDataLen;
} pimon_CharDevPriv_t;
typedef struct pimon_CharDev_t {
vmk_Device vmkDevice;
vmk_CharDevRegData regData;
pimon_CharDevCallbacks_t devCBs;
} pimon_CharDev_t;
typedef struct pimon_CharFileData_t {
vmk_Lock lock;
char *data;
vmk_Bool timerPending;
vmk_Bool deathPending;
vmk_Timer timer;
vmk_int32 timeoutUS;
vmk_uint32 pollMask;
} pimon_CharFileData_t;
typedef struct pimon_CharDevProps_t {
vmk_Driver driverHandle;
vmk_BusType logicalBusType;
vmk_Device parentDevice;
pimon_CharDev_t *charDev;
pimon_CharDevPriv_t *privData;
vmk_uint32 logicalPort;
pimon_CharDevCallbacks_t *callbacks;
} pimon_CharDevProps_t;
/***********************************************************************/
VMK_ReturnStatus pimon_charDevInit(vmk_ModuleID moduleID,
vmk_HeapID heapID,
vmk_LogComponent logger);
VMK_ReturnStatus pimon_charDevRegister(pimon_CharDevProps_t *props);
VMK_ReturnStatus pimon_charVmkDevRemove(vmk_Device logicalDev);
VMK_ReturnStatus pimon_charDevAssoc(vmk_AddrCookie charDevPriv,
vmk_CharDevHandle charDevHandle);
VMK_ReturnStatus pimon_charDevDisassoc(vmk_AddrCookie charDevPriv);
VMK_ReturnStatus pimon_charDevOpen(vmk_CharDevFdAttr *attr);
VMK_ReturnStatus pimon_charDevClose(vmk_CharDevFdAttr *attr);
VMK_ReturnStatus pimon_charDevIoctl(vmk_CharDevFdAttr *attr,
vmk_uint32 cmd,
vmk_uintptr_t userData,
vmk_IoctlCallerSize callerSize,
vmk_int32 *result);
VMK_ReturnStatus pimon_charDevRead(vmk_CharDevFdAttr *attr,
char *buffer,
vmk_ByteCount nbytes,
vmk_loff_t *ppos,
vmk_ByteCountSigned *nread);
VMK_ReturnStatus pimon_charDevWrite(vmk_CharDevFdAttr *attr,
char *buffer,
vmk_ByteCount nbytes,
vmk_loff_t *ppos,
vmk_ByteCountSigned *nwritten);
VMK_ReturnStatus pimon_charDevIO(vmk_CharDevFdAttr *attr,
char *buffer,
vmk_ByteCount nbytes,
vmk_loff_t *ppos,
vmk_ByteCountSigned *ndone,
vmk_Bool isWrite);
VMK_ReturnStatus pimon_charDevPoll(vmk_CharDevFdAttr *attr,
vmk_PollContext pollCtx,
vmk_uint32 *pollMask);
void pimon_charDevTimerCB(vmk_TimerCookie data);
void pimon_charDevFileDestroy(pimon_CharFileData_t *fileData);
/***********************************************************************/
#endif /* PIMON_CHARDEV_H */