2009-07-13 22:19:28 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009, Microsoft Corporation.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope 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; if not, write to the Free Software Foundation, Inc., 59 Temple
|
|
|
|
* Place - Suite 330, Boston, MA 02111-1307 USA.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Haiyang Zhang <haiyangz@microsoft.com>
|
|
|
|
* Hank Janssen <hjanssen@microsoft.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _OSD_H_
|
|
|
|
#define _OSD_H_
|
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
|
|
|
|
/* Defines */
|
|
|
|
|
2009-07-13 22:19:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define ALIGN_UP(value, align) ( ((value) & (align-1))? ( ((value) + (align-1)) & ~(align-1) ): (value) )
|
|
|
|
#define ALIGN_DOWN(value, align) ( (value) & ~(align-1) )
|
|
|
|
#define NUM_PAGES_SPANNED(addr, len) ( (ALIGN_UP(addr+len, PAGE_SIZE) - ALIGN_DOWN(addr, PAGE_SIZE)) >> PAGE_SHIFT )
|
|
|
|
|
|
|
|
#define LOWORD(dw) ((unsigned short) (dw))
|
|
|
|
#define HIWORD(dw) ((unsigned short) (((unsigned int) (dw) >> 16) & 0xFFFF))
|
|
|
|
|
|
|
|
typedef struct _DLIST_ENTRY {
|
|
|
|
struct _DLIST_ENTRY *Flink;
|
|
|
|
struct _DLIST_ENTRY *Blink;
|
|
|
|
} DLIST_ENTRY;
|
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
|
|
|
|
/* Other types */
|
|
|
|
|
|
|
|
/* typedef unsigned char GUID[16]; */
|
2009-07-13 22:19:28 +00:00
|
|
|
typedef void* HANDLE;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
unsigned char Data[16];
|
|
|
|
} GUID;
|
|
|
|
|
|
|
|
typedef void (*PFN_WORKITEM_CALLBACK)(void* context);
|
|
|
|
typedef void (*PFN_TIMER_CALLBACK)(void* context);
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __x86_64__
|
|
|
|
|
|
|
|
#define RDMSR(reg, v) { \
|
2009-07-14 22:09:36 +00:00
|
|
|
u32 h, l; \
|
2009-07-13 22:19:28 +00:00
|
|
|
__asm__ __volatile__("rdmsr" \
|
|
|
|
: "=a" (l), "=d" (h) \
|
|
|
|
: "c" (reg)); \
|
2009-07-14 22:10:26 +00:00
|
|
|
v = (((u64)h) << 32) | l; \
|
2009-07-13 22:19:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define WRMSR(reg, v) { \
|
2009-07-14 22:09:36 +00:00
|
|
|
u32 h, l; \
|
2009-07-14 22:10:26 +00:00
|
|
|
l = (u32)(((u64)(v)) & 0xFFFFFFFF); \
|
|
|
|
h = (u32)((((u64)(v)) >> 32) & 0xFFFFFFFF); \
|
2009-07-13 22:19:28 +00:00
|
|
|
__asm__ __volatile__("wrmsr" \
|
|
|
|
: /* no outputs */ \
|
|
|
|
: "c" (reg), "a" (l), "d" (h)); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define RDMSR(reg, v) \
|
|
|
|
__asm__ __volatile__("rdmsr" \
|
|
|
|
: "=A" (v) \
|
|
|
|
: "c" (reg))
|
|
|
|
|
|
|
|
#define WRMSR(reg, v) \
|
|
|
|
__asm__ __volatile__("wrmsr" \
|
|
|
|
: /* no outputs */ \
|
2009-07-14 22:10:26 +00:00
|
|
|
: "c" (reg), "A" ((u64)v))
|
2009-07-13 22:19:28 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
static inline void do_cpuid(unsigned int op, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx)
|
|
|
|
{
|
|
|
|
__asm__ __volatile__("cpuid" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) : "0" (op), "c" (ecx));
|
|
|
|
}
|
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
|
|
|
|
/* Osd routines */
|
|
|
|
|
2009-07-13 22:19:28 +00:00
|
|
|
extern void BitSet(unsigned int* addr, int value);
|
|
|
|
extern void BitClear(unsigned int* addr, int value);
|
|
|
|
extern int BitTest(unsigned int* addr, int value);
|
|
|
|
extern int BitTestAndClear(unsigned int* addr, int value);
|
|
|
|
extern int BitTestAndSet(unsigned int* addr, int value);
|
|
|
|
|
|
|
|
extern int InterlockedIncrement(int *val);
|
|
|
|
extern int InterlockedDecrement(int *val);
|
|
|
|
extern int InterlockedCompareExchange(int *val, int new, int curr);
|
|
|
|
|
|
|
|
extern void* VirtualAllocExec(unsigned int size);
|
|
|
|
extern void VirtualFree(void* VirtAddr);
|
|
|
|
|
|
|
|
extern void* PageAlloc(unsigned int count);
|
|
|
|
extern void PageFree(void* page, unsigned int count);
|
|
|
|
|
|
|
|
extern void* MemMapIO(unsigned long phys, unsigned long size);
|
|
|
|
extern void MemUnmapIO(void* virt);
|
|
|
|
|
|
|
|
extern HANDLE TimerCreate(PFN_TIMER_CALLBACK pfnTimerCB, void* context);
|
|
|
|
extern void TimerClose(HANDLE hTimer);
|
|
|
|
extern int TimerStop(HANDLE hTimer);
|
2009-07-14 22:09:36 +00:00
|
|
|
extern void TimerStart(HANDLE hTimer, u32 expirationInUs);
|
2009-07-13 22:19:28 +00:00
|
|
|
|
|
|
|
extern HANDLE WaitEventCreate(void);
|
|
|
|
extern void WaitEventClose(HANDLE hWait);
|
|
|
|
extern void WaitEventSet(HANDLE hWait);
|
|
|
|
extern int WaitEventWait(HANDLE hWait);
|
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
/* If >0, hWait got signaled. If ==0, timeout. If < 0, error */
|
2009-07-14 22:09:36 +00:00
|
|
|
extern int WaitEventWaitEx(HANDLE hWait, u32 TimeoutInMs);
|
2009-07-13 22:19:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define GetVirtualAddress Physical2LogicalAddr
|
2009-07-14 22:12:46 +00:00
|
|
|
void* Physical2LogicalAddr(unsigned long PhysAddr);
|
2009-07-13 22:19:28 +00:00
|
|
|
|
|
|
|
#define GetPhysicalAddress Logical2PhysicalAddr
|
2009-07-14 22:12:46 +00:00
|
|
|
unsigned long Logical2PhysicalAddr(void * LogicalAddr);
|
2009-07-13 22:19:28 +00:00
|
|
|
|
2009-07-14 22:12:46 +00:00
|
|
|
unsigned long Virtual2Physical(void * VirtAddr);
|
2009-07-13 22:19:28 +00:00
|
|
|
|
|
|
|
void* PageMapVirtualAddress(unsigned long Pfn);
|
|
|
|
void PageUnmapVirtualAddress(void* VirtAddr);
|
|
|
|
|
|
|
|
|
2009-07-27 20:47:45 +00:00
|
|
|
extern struct workqueue_struct *WorkQueueCreate(char* name);
|
|
|
|
extern void WorkQueueClose(struct workqueue_struct *hWorkQueue);
|
|
|
|
extern int WorkQueueQueueWorkItem(struct workqueue_struct *hWorkQueue,
|
|
|
|
PFN_WORKITEM_CALLBACK workItem,
|
|
|
|
void *context);
|
2009-07-13 22:19:28 +00:00
|
|
|
|
|
|
|
extern void QueueWorkItem(PFN_WORKITEM_CALLBACK workItem, void* context);
|
|
|
|
|
2009-07-27 20:47:24 +00:00
|
|
|
#endif /* _OSD_H_ */
|