]> Pileus Git - ~andy/linux/blob - drivers/staging/hv/include/osd.h
Staging: hv: remove UNUSED_VAR usage
[~andy/linux] / drivers / staging / hv / include / osd.h
1 /*
2  *
3  * Copyright (c) 2009, Microsoft Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms and conditions of the GNU General Public License,
7  * version 2, as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16  * Place - Suite 330, Boston, MA 02111-1307 USA.
17  *
18  * Authors:
19  *   Haiyang Zhang <haiyangz@microsoft.com>
20  *   Hank Janssen  <hjanssen@microsoft.com>
21  *
22  */
23
24
25 #ifndef _OSD_H_
26 #define _OSD_H_
27
28 //
29 // Defines
30 //
31
32
33 #define ALIGN_UP(value, align)                  ( ((value) & (align-1))? ( ((value) + (align-1)) & ~(align-1) ): (value) )
34 #define ALIGN_DOWN(value, align)                ( (value) & ~(align-1) )
35 #define NUM_PAGES_SPANNED(addr, len)    ( (ALIGN_UP(addr+len, PAGE_SIZE) - ALIGN_DOWN(addr, PAGE_SIZE)) >> PAGE_SHIFT )
36
37 #define LOWORD(dw)              ((unsigned short) (dw))
38 #define HIWORD(dw)              ((unsigned short) (((unsigned int) (dw) >> 16) & 0xFFFF))
39
40 #define FIELD_OFFSET(t, f)    ((unsigned int)(unsigned long)&(((t *)0)->f))
41
42 #ifdef FALSE
43 #undef FALSE
44 #endif
45 #define FALSE 0
46
47 #ifdef TRUE
48 #undef TRUE
49 #endif
50 #define TRUE  1
51
52 #ifndef NULL
53 #define NULL  (void *)0
54 #endif
55
56 typedef struct _DLIST_ENTRY {
57    struct _DLIST_ENTRY *Flink;
58    struct _DLIST_ENTRY *Blink;
59 } DLIST_ENTRY;
60
61 //
62 // Other types
63 //
64 //typedef unsigned char         GUID[16];
65 typedef void*                           HANDLE;
66
67 typedef struct {
68         unsigned char   Data[16];
69 } GUID;
70
71 typedef void (*PFN_WORKITEM_CALLBACK)(void* context);
72 typedef void (*PFN_TIMER_CALLBACK)(void* context);
73
74
75 #ifdef __x86_64__
76
77 #define RDMSR(reg, v) {                                                        \
78     u32 h, l;                                                                 \
79      __asm__ __volatile__("rdmsr"                                                               \
80     : "=a" (l), "=d" (h)                                                       \
81     : "c" (reg));                                                              \
82     v = (((u64)h) << 32) | l;                                                         \
83 }
84
85 #define WRMSR(reg, v) {                                                        \
86     u32 h, l;                                                               \
87     l = (u32)(((u64)(v)) & 0xFFFFFFFF);                                  \
88     h = (u32)((((u64)(v)) >> 32) & 0xFFFFFFFF);                          \
89      __asm__ __volatile__("wrmsr"                                              \
90     : /* no outputs */                                                         \
91     : "c" (reg), "a" (l), "d" (h));                                            \
92 }
93
94 #else
95
96 #define RDMSR(reg, v)                                                                  \
97      __asm__ __volatile__("rdmsr"                                                  \
98     : "=A" (v)                                                                         \
99     : "c" (reg))
100
101 #define WRMSR(reg, v)                                                                  \
102      __asm__ __volatile__("wrmsr"                                                  \
103     : /* no outputs */                                                                     \
104     : "c" (reg), "A" ((u64)v))
105
106 #endif
107
108
109 static inline void do_cpuid(unsigned int op, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx)
110 {
111         __asm__ __volatile__("cpuid" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) : "0" (op), "c" (ecx));
112 }
113
114 //
115 // Osd routines
116 //
117 extern void LogMsg(const char *fmt, ...);
118
119 extern void BitSet(unsigned int* addr, int value);
120 extern void BitClear(unsigned int* addr, int value);
121 extern int BitTest(unsigned int* addr, int value);
122 extern int BitTestAndClear(unsigned int* addr, int value);
123 extern int BitTestAndSet(unsigned int* addr, int value);
124
125 extern int InterlockedIncrement(int *val);
126 extern int InterlockedDecrement(int *val);
127 extern int InterlockedCompareExchange(int *val, int new, int curr);
128
129 extern void Sleep(unsigned long usecs);
130
131 extern void* VirtualAllocExec(unsigned int size);
132 extern void VirtualFree(void* VirtAddr);
133
134 extern void* PageAlloc(unsigned int count);
135 extern void PageFree(void* page, unsigned int count);
136
137 extern void* MemMapIO(unsigned long phys, unsigned long size);
138 extern void MemUnmapIO(void* virt);
139
140 extern void* MemAlloc(unsigned int size);
141 extern void* MemAllocZeroed(unsigned int size);
142 extern void* MemAllocAtomic(unsigned int size);
143 extern void MemFree(void* buf);
144 extern void MemoryFence(void);
145
146 extern HANDLE TimerCreate(PFN_TIMER_CALLBACK pfnTimerCB, void* context);
147 extern void TimerClose(HANDLE hTimer);
148 extern int TimerStop(HANDLE hTimer);
149 extern void TimerStart(HANDLE hTimer, u32 expirationInUs);
150 extern size_t GetTickCount(void);
151
152 extern HANDLE WaitEventCreate(void);
153 extern void WaitEventClose(HANDLE hWait);
154 extern void WaitEventSet(HANDLE hWait);
155 extern int      WaitEventWait(HANDLE hWait);
156
157 // If >0, hWait got signaled. If ==0, timeout. If < 0, error
158 extern int      WaitEventWaitEx(HANDLE hWait, u32 TimeoutInMs);
159
160 extern HANDLE SpinlockCreate(void);
161 extern void SpinlockClose(HANDLE hSpin);
162 extern void SpinlockAcquire(HANDLE hSpin);
163 extern void     SpinlockRelease(HANDLE hSpin);
164
165
166 #define GetVirtualAddress Physical2LogicalAddr
167 void* Physical2LogicalAddr(unsigned long PhysAddr);
168
169 #define GetPhysicalAddress Logical2PhysicalAddr
170 unsigned long Logical2PhysicalAddr(void * LogicalAddr);
171
172 unsigned long Virtual2Physical(void * VirtAddr);
173
174 void* PageMapVirtualAddress(unsigned long Pfn);
175 void PageUnmapVirtualAddress(void* VirtAddr);
176
177
178 extern HANDLE WorkQueueCreate(char* name);
179 extern void WorkQueueClose(HANDLE hWorkQueue);
180 extern int WorkQueueQueueWorkItem(HANDLE hWorkQueue, PFN_WORKITEM_CALLBACK workItem, void* context);
181
182 extern void QueueWorkItem(PFN_WORKITEM_CALLBACK workItem, void* context);
183
184 #endif // _OSD_H_