Commit | Line | Data |
---|---|---|
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 | ||
454f18a9 BP |
28 | |
29 | /* Defines */ | |
30 | ||
ab057781 | 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 |
40 | typedef struct _DLIST_ENTRY { |
41 | struct _DLIST_ENTRY *Flink; | |
42 | struct _DLIST_ENTRY *Blink; | |
43 | } DLIST_ENTRY; | |
44 | ||
454f18a9 BP |
45 | |
46 | /* Other types */ | |
47 | ||
48 | /* typedef unsigned char GUID[16]; */ | |
ab057781 | 49 | |
06d2e318 BP |
50 | typedef void (*PFN_TIMER_CALLBACK)(void* context); |
51 | ||
52 | ||
ab057781 HJ |
53 | typedef struct { |
54 | unsigned char Data[16]; | |
55 | } GUID; | |
56 | ||
aedb444a BP |
57 | struct osd_waitevent { |
58 | int condition; | |
59 | wait_queue_head_t event; | |
60 | }; | |
61 | ||
06d2e318 BP |
62 | struct osd_timer { |
63 | struct timer_list timer; | |
64 | PFN_TIMER_CALLBACK callback; | |
65 | void* context; | |
66 | }; | |
aedb444a | 67 | |
ab057781 HJ |
68 | |
69 | ||
70 | #ifdef __x86_64__ | |
71 | ||
72 | #define RDMSR(reg, v) { \ | |
4d643114 | 73 | u32 h, l; \ |
ab057781 HJ |
74 | __asm__ __volatile__("rdmsr" \ |
75 | : "=a" (l), "=d" (h) \ | |
76 | : "c" (reg)); \ | |
59471438 | 77 | v = (((u64)h) << 32) | l; \ |
ab057781 HJ |
78 | } |
79 | ||
80 | #define WRMSR(reg, v) { \ | |
4d643114 | 81 | u32 h, l; \ |
59471438 GKH |
82 | l = (u32)(((u64)(v)) & 0xFFFFFFFF); \ |
83 | h = (u32)((((u64)(v)) >> 32) & 0xFFFFFFFF); \ | |
ab057781 HJ |
84 | __asm__ __volatile__("wrmsr" \ |
85 | : /* no outputs */ \ | |
86 | : "c" (reg), "a" (l), "d" (h)); \ | |
87 | } | |
88 | ||
89 | #else | |
90 | ||
91 | #define RDMSR(reg, v) \ | |
92 | __asm__ __volatile__("rdmsr" \ | |
93 | : "=A" (v) \ | |
94 | : "c" (reg)) | |
95 | ||
96 | #define WRMSR(reg, v) \ | |
97 | __asm__ __volatile__("wrmsr" \ | |
98 | : /* no outputs */ \ | |
59471438 | 99 | : "c" (reg), "A" ((u64)v)) |
ab057781 HJ |
100 | |
101 | #endif | |
102 | ||
103 | ||
104 | static inline void do_cpuid(unsigned int op, unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx) | |
105 | { | |
106 | __asm__ __volatile__("cpuid" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) : "0" (op), "c" (ecx)); | |
107 | } | |
108 | ||
454f18a9 BP |
109 | |
110 | /* Osd routines */ | |
111 | ||
ab057781 HJ |
112 | extern int InterlockedIncrement(int *val); |
113 | extern int InterlockedDecrement(int *val); | |
114 | extern int InterlockedCompareExchange(int *val, int new, int curr); | |
115 | ||
ab057781 HJ |
116 | extern void* VirtualAllocExec(unsigned int size); |
117 | extern void VirtualFree(void* VirtAddr); | |
118 | ||
119 | extern void* PageAlloc(unsigned int count); | |
120 | extern void PageFree(void* page, unsigned int count); | |
121 | ||
122 | extern void* MemMapIO(unsigned long phys, unsigned long size); | |
123 | extern void MemUnmapIO(void* virt); | |
124 | ||
06d2e318 BP |
125 | extern struct osd_timer *TimerCreate(PFN_TIMER_CALLBACK pfnTimerCB, void* context); |
126 | extern void TimerClose(struct osd_timer *t); | |
127 | extern int TimerStop(struct osd_timer *t); | |
128 | extern void TimerStart(struct osd_timer *t, u32 expirationInUs); | |
ab057781 | 129 | |
aedb444a | 130 | extern struct osd_waitevent *WaitEventCreate(void); |
aedb444a BP |
131 | extern void WaitEventSet(struct osd_waitevent *waitEvent); |
132 | extern int WaitEventWait(struct osd_waitevent *waitEvent); | |
ab057781 | 133 | |
aedb444a BP |
134 | /* If >0, waitEvent got signaled. If ==0, timeout. If < 0, error */ |
135 | extern int WaitEventWaitEx(struct osd_waitevent *waitEvent, u32 TimeoutInMs); | |
ab057781 | 136 | |
ab057781 HJ |
137 | |
138 | #define GetVirtualAddress Physical2LogicalAddr | |
c4b0bc94 | 139 | void* Physical2LogicalAddr(unsigned long PhysAddr); |
ab057781 HJ |
140 | |
141 | #define GetPhysicalAddress Logical2PhysicalAddr | |
c4b0bc94 | 142 | unsigned long Logical2PhysicalAddr(void * LogicalAddr); |
ab057781 | 143 | |
c4b0bc94 | 144 | unsigned long Virtual2Physical(void * VirtAddr); |
ab057781 HJ |
145 | |
146 | void* PageMapVirtualAddress(unsigned long Pfn); | |
147 | void PageUnmapVirtualAddress(void* VirtAddr); | |
148 | ||
149 | ||
de65a384 BP |
150 | int osd_schedule_callback(struct workqueue_struct *wq, |
151 | void (*func)(void *), | |
152 | void *data); | |
ab057781 | 153 | |
454f18a9 | 154 | #endif /* _OSD_H_ */ |