aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mvp/pvtcpkm/comm.h
blob: 877731d8a48a9572e01f5dafa6ba0c4738d0535a (plain)
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
 * Linux 2.6.32 and later Kernel module for VMware MVP PVTCP Server
 *
 * Copyright (C) 2010-2012 VMware, Inc. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published by
 * the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; see the file COPYING.  If not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
#line 5

/**
 * @file
 *
 * @brief Communication functions based on queue pair transport APIs.
 *
 * Comm is a shared memory-based mechanism that facilitates the implementation
 * of kernel components that require host-to-guest, or guest-to-guest
 * communication.
 * This facility assumes the availability of a minimal shared memory queue pair
 * implementation, such as MVP queue pairs or VMCI queue pairs. The latter must
 * provide primitives for queue pair creation and destruction, and reading and
 * writing from/to queue pairs.
 * Comm assumes that the queue pair (transport) layer is not concerned with
 * multi-threading, locking or flow control, and does not require such features.
 */

#ifndef _COMM_H_
#define _COMM_H_

#define INCLUDE_ALLOW_MODULE
#define INCLUDE_ALLOW_PV
#define INCLUDE_ALLOW_GPL
#include "include_check.h"

#include "comm_os.h"
#include "comm_transp.h"


/* Default/maximum Comm timeouts (in milliseconds). */
#define COMM_MAX_TO 60000ULL
#define COMM_MAX_TO_UNINT (COMM_MAX_TO + 1)

#define COMM_OPF_SET_ERR(flags)   ((flags) |= 128)
#define COMM_OPF_CLEAR_ERR(flags) ((flags) &= 127)
#define COMM_OPF_TEST_ERR(flags)  ((flags) &  128)

#define COMM_OPF_SET_VAL(flags, val) ((flags) |= ((val) & 127))
#define COMM_OPF_GET_VAL(flags)      ((flags) & 127)

/**
 * Packet (header) structure.
 * NB: Do not change this structure, especially the first three fields; there
 *     will be consequences. It may be extended, but it's not recommended: all
 *     operations carry this header, so it's better kept in its minimal form.
 */

typedef struct CommPacket {
   unsigned int len;                        // Total length
   unsigned char flags;                     // Operation flags
   unsigned char opCode;                    // Operation to call
   unsigned short data16;                   // Auxiliary data
   unsigned long long data64;
   unsigned long long data64ex;
   union {
      struct {
         unsigned int data32;
         unsigned int data32ex;
      };
      unsigned long long data64ex2;
   };
} CommPacket;


/* Opaque structure representing a communication channel. */

struct CommChannelPriv;
typedef struct CommChannelPriv *CommChannel;


/* Input operations associated with a comm channel. */

typedef void (*CommOperationFunc)(CommChannel channel,
                                  void *state,
                                  CommPacket *packet,
                                  struct kvec *vec,
                                  unsigned int vecLen);


/* Helper macros */

#define COMM_DEFINE_OP(funcName) \
void                             \
funcName(CommChannel channel,    \
         void *state,            \
         CommPacket *packet,     \
         struct kvec *vec,       \
         unsigned int vecLen)


/* Comm-based implementations. */

typedef struct CommImpl {
   struct module *owner;
   int (*checkArgs)(CommTranspInitArgs *transpArgs);
   void *(*stateCtor)(CommChannel channel);
   void (*stateDtor)(void *state);
   void *(*dataAlloc)(unsigned int dataLen);
   void (*dataFree)(void *data);
   const CommOperationFunc *operations;
   void (*closeNtf)(void *closeNtfData,
                    const CommTranspInitArgs *transpArgs,
                    int inBH);
   void *closeNtfData;
   void (*activateNtf)(void *activateNtfData,
                       CommChannel channel);
   void *activateNtfData;
   unsigned long long openAtMillis;
   unsigned long long openTimeoutAtMillis;
   CommTranspID ntfCenterID;
} CommImpl;


int Comm_Init(unsigned int maxChannels);
int Comm_Finish(unsigned long long *timeoutMillis);
int Comm_RegisterImpl(const CommImpl *impl);
void Comm_UnregisterImpl(const CommImpl *impl);
int Comm_IsActive(CommChannel channel);
CommTranspInitArgs Comm_GetTranspInitArgs(CommChannel channel);
void *Comm_GetState(CommChannel channel);
int Comm_Dispatch(CommChannel channel);
unsigned int Comm_DispatchAll(void);
void Comm_Put(CommChannel channel);
void Comm_DispatchUnlock(CommChannel channel);
int Comm_Lock(CommChannel channel);
void Comm_Unlock(CommChannel channel);
int Comm_Zombify(CommChannel channel, int inBH);

int
Comm_Alloc(const CommTranspInitArgs *transpArgs,
           const CommImpl *impl,
           int inBH,
           CommChannel *newChannel);


int
Comm_Write(CommChannel channel,
           const CommPacket *packet,
           unsigned long long *timeoutMillis);

int
Comm_WriteVec(CommChannel channel,
              const CommPacket *packet,
              struct kvec **vec,
              unsigned int *vecLen,
              unsigned long long *timeoutMillis,
              unsigned int *iovOffset);

unsigned int Comm_RequestInlineEvents(CommChannel channel);
unsigned int Comm_ReleaseInlineEvents(CommChannel channel);

#endif // _COMM_H_