3 * Copyright (c) 2009, Microsoft Corporation.
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.
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
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.
19 * Haiyang Zhang <haiyangz@microsoft.com>
20 * Hank Janssen <hjanssen@microsoft.com>
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 )
37 #define LOWORD(dw) ((unsigned short) (dw))
38 #define HIWORD(dw) ((unsigned short) (((unsigned int) (dw) >> 16) & 0xFFFF))
40 typedef struct _DLIST_ENTRY {
41 struct _DLIST_ENTRY *Flink;
42 struct _DLIST_ENTRY *Blink;
48 /* typedef unsigned char GUID[16]; */
50 typedef void (*PFN_TIMER_CALLBACK)(void* context);
54 unsigned char Data[16];
57 struct osd_waitevent {
59 wait_queue_head_t event;
63 struct timer_list timer;
64 PFN_TIMER_CALLBACK callback;
72 #define RDMSR(reg, v) { \
74 __asm__ __volatile__("rdmsr" \
75 : "=a" (l), "=d" (h) \
77 v = (((u64)h) << 32) | l; \
80 #define WRMSR(reg, v) { \
82 l = (u32)(((u64)(v)) & 0xFFFFFFFF); \
83 h = (u32)((((u64)(v)) >> 32) & 0xFFFFFFFF); \
84 __asm__ __volatile__("wrmsr" \
86 : "c" (reg), "a" (l), "d" (h)); \
91 #define RDMSR(reg, v) \
92 __asm__ __volatile__("rdmsr" \
96 #define WRMSR(reg, v) \
97 __asm__ __volatile__("wrmsr" \
99 : "c" (reg), "A" ((u64)v))
104 static inline void do_cpuid(unsigned int op, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx)
106 __asm__ __volatile__("cpuid" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) : "0" (op), "c" (ecx));
112 extern void BitSet(unsigned int* addr, int value);
113 extern void BitClear(unsigned int* addr, int value);
114 extern int BitTest(unsigned int* addr, int value);
115 extern int BitTestAndClear(unsigned int* addr, int value);
116 extern int BitTestAndSet(unsigned int* addr, int value);
118 extern int InterlockedIncrement(int *val);
119 extern int InterlockedDecrement(int *val);
120 extern int InterlockedCompareExchange(int *val, int new, int curr);
122 extern void* VirtualAllocExec(unsigned int size);
123 extern void VirtualFree(void* VirtAddr);
125 extern void* PageAlloc(unsigned int count);
126 extern void PageFree(void* page, unsigned int count);
128 extern void* MemMapIO(unsigned long phys, unsigned long size);
129 extern void MemUnmapIO(void* virt);
131 extern struct osd_timer *TimerCreate(PFN_TIMER_CALLBACK pfnTimerCB, void* context);
132 extern void TimerClose(struct osd_timer *t);
133 extern int TimerStop(struct osd_timer *t);
134 extern void TimerStart(struct osd_timer *t, u32 expirationInUs);
136 extern struct osd_waitevent *WaitEventCreate(void);
137 extern void WaitEventSet(struct osd_waitevent *waitEvent);
138 extern int WaitEventWait(struct osd_waitevent *waitEvent);
140 /* If >0, waitEvent got signaled. If ==0, timeout. If < 0, error */
141 extern int WaitEventWaitEx(struct osd_waitevent *waitEvent, u32 TimeoutInMs);
144 #define GetVirtualAddress Physical2LogicalAddr
145 void* Physical2LogicalAddr(unsigned long PhysAddr);
147 #define GetPhysicalAddress Logical2PhysicalAddr
148 unsigned long Logical2PhysicalAddr(void * LogicalAddr);
150 unsigned long Virtual2Physical(void * VirtAddr);
152 void* PageMapVirtualAddress(unsigned long Pfn);
153 void PageUnmapVirtualAddress(void* VirtAddr);
156 int osd_schedule_callback(struct workqueue_struct *wq,
157 void (*func)(void *),