aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mvp/mvpkm/comm_os.h
blob: cf858f6843dff422e749dfb2d649ca6b50d1e472 (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
/*
 * Linux 2.6.32 and later Kernel module for VMware MVP Hypervisor Support
 *
 * 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 Cross-platform base type definitions and function declarations.
 *         Includes OS-specific base type definitions and function declarations.
 */

#ifndef	_COMM_OS_H_
#define	_COMM_OS_H_

/* For-ever timeout constant (in milliseconds). */
#define COMM_OS_4EVER_TO ((unsigned long long)(~0UL >> 1))

/* Condition function prototype. Returns 1: true, 0: false, < 0: error code. */
typedef int (*CommOSWaitConditionFunc)(void *arg1, void *arg2);

/* Dispatch function prototype. Called by input (dispatch) kernel threads. */
typedef unsigned int (*CommOSDispatchFunc)(void);

/* Module initialization and exit callback functions. */
extern int  (*commOSModInit)(void *args);
extern void (*commOSModExit)(void);

/* Macro to assign Init and Exit callbacks. */
#define COMM_OS_MOD_INIT(init, exit)        \
   int (*commOSModInit)(void *args) = init; \
   void (*commOSModExit)(void) = exit


/*
 * OS-specific implementations must provide the following:
 *    1. Types:
 *       CommOSAtomic
 *       CommOSSpinlock
 *       CommOSMutex
 *       CommOSWaitQueue
 *       CommOSWork
 *       CommOSWorkFunc
 *       CommOSList
 *       CommOSModule
 *       struct kvec
 *
 *    2. Definition, initializers:
 *       CommOSSpinlock_Define()
 *
 *    3. Functions:
 *       void CommOS_Debug(const char *format, ...);
 *       void CommOS_Log(const char *format, ...);
 *       void CommOS_WriteAtomic(CommOSAtomic *atomic, int val);
 *       int CommOS_ReadAtomic(CommOSAtomic *atomic);
 *       int CommOS_AddReturnAtomic(CommOSAtomic *atomic, int val);
 *       int CommOS_SubReturnAtomic(CommOSAtomic *atomic, int val);
 *       void CommOS_SpinlockInit(CommOSSpinlock *lock);
 *       void CommOS_SpinLockBH(CommOSSpinlock *lock);
 *       int CommOS_SpinTrylockBH(CommOSSpinlock *lock);
 *       void CommOS_SpinUnlockBH(CommOSSpinlock *lock);
 *       void CommOS_SpinLock(CommOSSpinlock *lock);
 *       int CommOS_SpinTrylock(CommOSSpinlock *lock);
 *       void CommOS_SpinUnlock(CommOSSpinlock *lock);
 *       void CommOS_MutexInit(CommOSMutex *mutex);
 *       void CommOS_MutexLock(CommOSMutex *mutex);
 *       int CommOS_MutexLockUninterruptible(CommOSMutex *mutex);
 *       int CommOS_MutexTrylock(CommOSMutex *mutex);
 *       void CommOS_MutexUnlock(CommOSMutex *mutex);
 *       void CommOS_WaitQueueInit(CommOSWaitQueue *wq);
 *       CommOS_DoWait(CommOSWaitQueue *wq,
 *                     CommOSWaitConditionFunc cond,
 *                     void *condArg1,
 *                     void *condArg2,
 *                     unsigned long long *timeoutMillis,
 *                     int interruptible);
 *       int CommOS_Wait(CommOSWaitQueue *wq,
 *                       CommOSWaitConditionFunc func,
 *                       void *funcArg1,
 *                       void *funcArg2,
 *                       unsigned long long *timeoutMillis);
 *       int CommOS_WaitUninterruptible(CommOSWaitQueue *wq,
 *                                      CommOSWaitConditionFunc func,
 *                                      void *funcArg1,
 *                                      void *funcArg2,
 *                                      unsigned long long *timeoutMillis);
 *       void CommOS_WakeUp(CommOSWaitQueue *wq);
 *       void *CommOS_KmallocNoSleep(unsigned int size);
 *       void *CommOS_Kmalloc(unsigned int size);
 *       void CommOS_Kfree(void *arg);
 *       void CommOS_Yield(void);
 *       unsigned long long CommOS_GetCurrentMillis(void);
 *       void CommOS_ListInit(CommOSList *list);
 *       int CommOS_ListEmpty(CommOSList *list);
 *       void CommOS_ListAdd(CommOSList *list, CommOSList *listElem);
 *       void CommOS_ListAddTail(CommOSList *list, CommOSList *listElem);
 *       void int CommOS_ListDel(CommOSList *listElem);
 *       Macros:
 *          CommOS_ListForEach(*list, *item, itemListFieldName);
 *          CommOS_ListForEachSafe(*list, *item, *tmp, itemListFieldName);
 *       void CommOS_ListSplice(CommOSList *list, CommOSList *listToAdd);
 *       void CommOS_ListSpliceTail(CommOSList *list, CommOSList *listToAdd);
 *       CommOSModule CommOS_ModuleSelf(void);
 *       int CommOS_ModuleGet(CommOSModule module);
 *       void CommOS_ModulePut(CommOSModule module);
 *       void CommOS_MemBarrier(void);
 *
 *    These cannot be defined here: a) non-pointer type definitions need size
 *    information, and b) functions may or may not be inlined, or macros may
 *    be used instead.
 */


#ifdef __linux__
#include "comm_os_linux.h"
#else
#error "Unsupported OS"
#endif

/* Functions to start and stop the dispatch and aio kernel threads. */
void CommOS_StopIO(void);
void CommOS_ScheduleDisp(void);
void CommOS_InitWork(CommOSWork *work, CommOSWorkFunc func);
int CommOS_ScheduleAIOWork(CommOSWork *work);
void CommOS_FlushAIOWork(CommOSWork *work);

int
CommOS_StartIO(const char *dispatchTaskName,
               CommOSDispatchFunc dispatchHandler,
               unsigned int interval,
               unsigned int maxCycles,
               const char *aioTaskName);


#endif  /* _COMM_OS_H_ */