Staging: hv: osd: remove MemFree wrapper
[deliverable/linux.git] / drivers / staging / hv / include / osd.h
CommitLineData
ab057781
HJ
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
ab057781 32
ab057781
HJ
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
ab057781
HJ
37#define LOWORD(dw) ((unsigned short) (dw))
38#define HIWORD(dw) ((unsigned short) (((unsigned int) (dw) >> 16) & 0xFFFF))
39
ab057781
HJ
40typedef struct _DLIST_ENTRY {
41 struct _DLIST_ENTRY *Flink;
42 struct _DLIST_ENTRY *Blink;
43} DLIST_ENTRY;
44
ab057781
HJ
45//
46// Other types
47//
ab057781 48//typedef unsigned char GUID[16];
ab057781 49typedef void* HANDLE;
ab057781 50
ab057781
HJ
51typedef struct {
52 unsigned char Data[16];
53} GUID;
54
55typedef void (*PFN_WORKITEM_CALLBACK)(void* context);
56typedef void (*PFN_TIMER_CALLBACK)(void* context);
57
58
59#ifdef __x86_64__
60
61#define RDMSR(reg, v) { \
4d643114 62 u32 h, l; \
ab057781
HJ
63 __asm__ __volatile__("rdmsr" \
64 : "=a" (l), "=d" (h) \
65 : "c" (reg)); \
59471438 66 v = (((u64)h) << 32) | l; \
ab057781
HJ
67}
68
69#define WRMSR(reg, v) { \
4d643114 70 u32 h, l; \
59471438
GKH
71 l = (u32)(((u64)(v)) & 0xFFFFFFFF); \
72 h = (u32)((((u64)(v)) >> 32) & 0xFFFFFFFF); \
ab057781
HJ
73 __asm__ __volatile__("wrmsr" \
74 : /* no outputs */ \
75 : "c" (reg), "a" (l), "d" (h)); \
76}
77
78#else
79
80#define RDMSR(reg, v) \
81 __asm__ __volatile__("rdmsr" \
82 : "=A" (v) \
83 : "c" (reg))
84
85#define WRMSR(reg, v) \
86 __asm__ __volatile__("wrmsr" \
87 : /* no outputs */ \
59471438 88 : "c" (reg), "A" ((u64)v))
ab057781
HJ
89
90#endif
91
92
93static inline void do_cpuid(unsigned int op, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx)
94{
95 __asm__ __volatile__("cpuid" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) : "0" (op), "c" (ecx));
96}
97
98//
99// Osd routines
100//
101extern void LogMsg(const char *fmt, ...);
102
103extern void BitSet(unsigned int* addr, int value);
104extern void BitClear(unsigned int* addr, int value);
105extern int BitTest(unsigned int* addr, int value);
106extern int BitTestAndClear(unsigned int* addr, int value);
107extern int BitTestAndSet(unsigned int* addr, int value);
108
109extern int InterlockedIncrement(int *val);
110extern int InterlockedDecrement(int *val);
111extern int InterlockedCompareExchange(int *val, int new, int curr);
112
113extern void Sleep(unsigned long usecs);
114
115extern void* VirtualAllocExec(unsigned int size);
116extern void VirtualFree(void* VirtAddr);
117
118extern void* PageAlloc(unsigned int count);
119extern void PageFree(void* page, unsigned int count);
120
121extern void* MemMapIO(unsigned long phys, unsigned long size);
122extern void MemUnmapIO(void* virt);
123
e20f683b 124extern void MemoryFence(void);
ab057781
HJ
125
126extern HANDLE TimerCreate(PFN_TIMER_CALLBACK pfnTimerCB, void* context);
127extern void TimerClose(HANDLE hTimer);
128extern int TimerStop(HANDLE hTimer);
4d643114 129extern void TimerStart(HANDLE hTimer, u32 expirationInUs);
45635d97 130extern size_t GetTickCount(void);
ab057781
HJ
131
132extern HANDLE WaitEventCreate(void);
133extern void WaitEventClose(HANDLE hWait);
134extern void WaitEventSet(HANDLE hWait);
135extern int WaitEventWait(HANDLE hWait);
136
137// If >0, hWait got signaled. If ==0, timeout. If < 0, error
4d643114 138extern int WaitEventWaitEx(HANDLE hWait, u32 TimeoutInMs);
ab057781
HJ
139
140extern HANDLE SpinlockCreate(void);
141extern void SpinlockClose(HANDLE hSpin);
142extern void SpinlockAcquire(HANDLE hSpin);
143extern void SpinlockRelease(HANDLE hSpin);
144
145
146#define GetVirtualAddress Physical2LogicalAddr
c4b0bc94 147void* Physical2LogicalAddr(unsigned long PhysAddr);
ab057781
HJ
148
149#define GetPhysicalAddress Logical2PhysicalAddr
c4b0bc94 150unsigned long Logical2PhysicalAddr(void * LogicalAddr);
ab057781 151
c4b0bc94 152unsigned long Virtual2Physical(void * VirtAddr);
ab057781
HJ
153
154void* PageMapVirtualAddress(unsigned long Pfn);
155void PageUnmapVirtualAddress(void* VirtAddr);
156
157
158extern HANDLE WorkQueueCreate(char* name);
159extern void WorkQueueClose(HANDLE hWorkQueue);
160extern int WorkQueueQueueWorkItem(HANDLE hWorkQueue, PFN_WORKITEM_CALLBACK workItem, void* context);
161
162extern void QueueWorkItem(PFN_WORKITEM_CALLBACK workItem, void* context);
163
164#endif // _OSD_H_
This page took 0.033669 seconds and 5 git commands to generate.