1/**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, TX., USA
4 * All Rights Reserved.
5 * Copyright 2009 VMware, Inc., Palo Alto, CA., USA
6 * All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
18 * of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
23 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
24 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
25 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
26 * USE OR OTHER DEALINGS IN THE SOFTWARE.
27 *
28 **************************************************************************/
29/*
30 * Authors:
31 * Thomas Hellstr�m <thomas-at-tungstengraphics-dot-com>
32 */
33
34#ifndef _WSBM_DRIVER_H
35#define _WSBM_DRIVER_H
36#include <stdint.h>
37#include "wsbm_util.h"
38
39#define WSBM_MUTEX_SPACE 16
40#define WSBM_COND_SPACE  16
41
42struct _WsbmMutex
43{
44    struct _WsbmThreadFuncs *func;
45    unsigned long storage[WSBM_MUTEX_SPACE];
46};
47
48struct _WsbmCond
49{
50    struct _WsbmThreadFuncs *func;
51    unsigned long storage[WSBM_COND_SPACE];
52};
53
54struct _WsbmThreadFuncs
55{
56    int (*mutexInit) (struct _WsbmMutex *, struct _WsbmThreadFuncs *);
57    void (*mutexFree) (struct _WsbmMutex *);
58    void (*mutexLock) (struct _WsbmMutex *);
59    void (*mutexUnlock) (struct _WsbmMutex *);
60    int (*condInit) (struct _WsbmCond *, struct _WsbmThreadFuncs *);
61    void (*condFree) (struct _WsbmCond *);
62    void (*condWait) (struct _WsbmCond *, struct _WsbmMutex *);
63    void (*condBroadcast) (struct _WsbmCond *);
64};
65
66extern struct _WsbmThreadFuncs *wsbmCurThreadFunc;
67
68#define WSBM_MUTEX_INIT(_mutex)			\
69    wsbmThreadFuncs()->mutexInit(_mutex,wsbmThreadFuncs())
70#define WSBM_MUTEX_FREE(_mutex)		\
71    {						\
72	(_mutex)->func->mutexFree(_mutex);	\
73    }
74#define WSBM_MUTEX_LOCK(_mutex) \
75    (_mutex)->func->mutexLock(_mutex);
76#define WSBM_MUTEX_UNLOCK(_mutex) \
77    (_mutex)->func->mutexUnlock(_mutex);
78
79#define WSBM_COND_INIT(_mutex)			\
80    wsbmThreadFuncs()->condInit(_mutex, wsbmThreadFuncs())
81#define WSBM_COND_FREE(_cond)			\
82    {						\
83	(_cond)->func->condFree(_cond);		\
84    }
85#define WSBM_COND_WAIT(_cond, _mutex)		\
86    (_cond)->func->condWait(_cond, _mutex);
87#define WSBM_COND_BROADCAST(_cond)		\
88    (_cond)->func->condBroadcast(_cond);
89
90struct _WsbmVNodeFuncs
91{
92    struct _ValidateNode *(*alloc) (struct _WsbmVNodeFuncs *, int);
93    void (*free) (struct _ValidateNode *);
94    void (*clear) (struct _ValidateNode *);
95};
96
97extern struct _WsbmVNodeFuncs *wsbmCurVNodeFunc;
98
99struct _WsbmBufStorage;
100struct _WsbmKernelBuf;
101
102struct _ValidateNode
103{
104    uint32_t hash;
105    int type_id;
106    struct _WsbmListHead head;
107    struct _WsbmListHead hashHead;
108    int listItem;
109    uint64_t set_flags;
110    uint64_t clr_flags;
111    void *buf;
112    struct _WsbmVNodeFuncs *func;
113};
114
115static inline struct _WsbmVNodeFuncs *
116wsbmVNodeFuncs(void)
117{
118    return wsbmCurVNodeFunc;
119}
120
121static inline struct _WsbmThreadFuncs *
122wsbmThreadFuncs(void)
123{
124    return wsbmCurThreadFunc;
125}
126
127extern struct _WsbmThreadFuncs *wsbmNullThreadFuncs(void);
128
129extern struct _WsbmThreadFuncs *wsbmPThreadFuncs(void);
130
131#endif
132