win-pvdrivers

changeset 322:60f47a81dbcc

properly attribute code taken from Xen header
author Andy Grover <andy.grover@oracle.com>
date Thu Jun 19 15:17:04 2008 -0700 (2008-06-19)
parents e4411b37b9a9
children c9b0dee6dfdd
files xenpci/hypercall_x86_mingw.h
line diff
     1.1 --- a/xenpci/hypercall_x86_mingw.h	Wed Jun 18 11:02:34 2008 -0700
     1.2 +++ b/xenpci/hypercall_x86_mingw.h	Thu Jun 19 15:17:04 2008 -0700
     1.3 @@ -1,139 +1,142 @@
     1.4 -/*
     1.5 -PV Drivers for Windows Xen HVM Domains
     1.6 -Copyright (C) 2007 James Harper
     1.7 -
     1.8 -This program is free software; you can redistribute it and/or
     1.9 -modify it under the terms of the GNU General Public License
    1.10 -as published by the Free Software Foundation; either version 2
    1.11 -of the License, or (at your option) any later version.
    1.12 -
    1.13 -This program is distributed in the hope that it will be useful,
    1.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.16 -GNU General Public License for more details.
    1.17 -
    1.18 -You should have received a copy of the GNU General Public License
    1.19 -along with this program; if not, write to the Free Software
    1.20 -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    1.21 -*/
    1.22 -
    1.23 -#define __STR(x) #x
    1.24 -#define STR(x) __STR(x)
    1.25 -
    1.26 -#define HYPERCALL_STR(name)					\
    1.27 -	"mov $xpdd->hypercall_stubs,%%eax; "				\
    1.28 -	"add $("STR(__HYPERVISOR_##name)" * 32),%%eax; "	\
    1.29 -	"call *%%eax"
    1.30 -
    1.31 -#define _hypercall2(type, name, a1, a2)                         \
    1.32 -({                                                              \
    1.33 -        long __res, __ign1, __ign2;                             \
    1.34 -        asm volatile (                                          \
    1.35 -                HYPERCALL_STR(name)                             \
    1.36 -                : "=a" (__res), "=b" (__ign1), "=c" (__ign2)    \
    1.37 -                : "1" ((long)(a1)), "2" ((long)(a2))            \
    1.38 -                : "memory" );                                   \
    1.39 -        (type)__res;                                            \
    1.40 -})
    1.41 -
    1.42 -#define _hypercall3(type, name, a1, a2, a3)			\
    1.43 -({								\
    1.44 -	long __res, __ign1, __ign2, __ign3;			\
    1.45 -	asm volatile (						\
    1.46 -		HYPERCALL_STR(name)				\
    1.47 -		: "=a" (__res), "=b" (__ign1), "=c" (__ign2), 	\
    1.48 -		"=d" (__ign3)					\
    1.49 -		: "1" ((long)(a1)), "2" ((long)(a2)),		\
    1.50 -		"3" ((long)(a3))				\
    1.51 -		: "memory" );					\
    1.52 -	(type)__res;						\
    1.53 -})
    1.54 -
    1.55 -#define _hypercall4(type, name, a1, a2, a3, a4)			\
    1.56 -({								\
    1.57 -	long __res, __ign1, __ign2, __ign3, __ign4;		\
    1.58 -	asm volatile (						\
    1.59 -		HYPERCALL_STR(name)				\
    1.60 -		: "=a" (__res), "=b" (__ign1), "=c" (__ign2),	\
    1.61 -		"=d" (__ign3), "=S" (__ign4)			\
    1.62 -		: "1" ((long)(a1)), "2" ((long)(a2)),		\
    1.63 -		"3" ((long)(a3)), "4" ((long)(a4))		\
    1.64 -		: "memory" );					\
    1.65 -	(type)__res;						\
    1.66 -})
    1.67 -
    1.68 -static inline void cpuid(int op, unsigned int *eax, unsigned int *ebx,
    1.69 -                         unsigned int *ecx, unsigned int *edx)
    1.70 -{
    1.71 -  __asm__("cpuid"
    1.72 -          : "=a" (*eax),
    1.73 -            "=b" (*ebx),
    1.74 -            "=c" (*ecx),
    1.75 -            "=d" (*edx)
    1.76 -          : "0" (op));
    1.77 -}
    1.78 -
    1.79 -static __inline void __cpuid(uint32_t output[4], uint32_t op)
    1.80 -{
    1.81 -  cpuid(op, &output[0], &output[1], &output[2], &output[3]);
    1.82 -}
    1.83 -
    1.84 -static __inline void __writemsr(uint32_t msr, uint64_t value)
    1.85 -{
    1.86 -  uint32_t hi, lo;
    1.87 -  hi = value >> 32;
    1.88 -  lo = value & 0xFFFFFFFF;
    1.89 -
    1.90 -  __asm__ __volatile__("wrmsr" \
    1.91 -                       : /* no outputs */ \
    1.92 -                       : "c" (msr), "a" (lo), "d" (hi));
    1.93 -}
    1.94 -
    1.95 -static __inline int
    1.96 -HYPERVISOR_memory_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
    1.97 -{
    1.98 -  return _hypercall2(int, memory_op, cmd, arg);
    1.99 -}
   1.100 -
   1.101 -static __inline int
   1.102 -HYPERVISOR_sched_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
   1.103 -{
   1.104 -  return _hypercall2(int, sched_op, cmd, arg);
   1.105 -}
   1.106 -
   1.107 -static __inline int
   1.108 -HYPERVISOR_xen_version(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
   1.109 -{
   1.110 -  return _hypercall2(int, xen_version, cmd, arg);
   1.111 -}
   1.112 -
   1.113 -static __inline int
   1.114 -HYPERVISOR_grant_table_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *uop, unsigned int count)
   1.115 -{
   1.116 -	return _hypercall3(int, grant_table_op, cmd, uop, count);
   1.117 -}
   1.118 -
   1.119 -static __inline int
   1.120 -HYPERVISOR_mmu_update(PXENPCI_DEVICE_DATA xpdd, mmu_update_t *req, int count, int *success_count, domid_t domid)
   1.121 -{
   1.122 -	return _hypercall4(int, mmu_update, req, count, success_count, domid);
   1.123 -}
   1.124 -
   1.125 -static __inline int
   1.126 -HYPERVISOR_console_io(PXENPCI_DEVICE_DATA xpdd, int cmd, int count, char *string)
   1.127 -{
   1.128 -	return _hypercall3(int, console_io, cmd, count, string);
   1.129 -}
   1.130 -
   1.131 -static __inline int
   1.132 -HYPERVISOR_hvm_op(PXENPCI_DEVICE_DATA xpdd, int op, struct xen_hvm_param *arg)
   1.133 -{
   1.134 -  return _hypercall2(unsigned long, hvm_op, op, arg);
   1.135 -}
   1.136 -
   1.137 -static __inline int
   1.138 -HYPERVISOR_event_channel_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
   1.139 -{
   1.140 -	return _hypercall2(int, event_channel_op, cmd, arg);
   1.141 -}
   1.142 -
   1.143 +/* Code/license from Xen's include/asm/hypercall.h: */
   1.144 +/*
   1.145 + * Copyright (c) 2002-2004, K A Fraser
   1.146 + * 
   1.147 + * This program is free software; you can redistribute it and/or
   1.148 + * modify it under the terms of the GNU General Public License version 2
   1.149 + * as published by the Free Software Foundation; or, when distributed
   1.150 + * separately from the Linux kernel or incorporated into other
   1.151 + * software packages, subject to the following license:
   1.152 + * 
   1.153 + * Permission is hereby granted, free of charge, to any person obtaining a copy
   1.154 + * of this source file (the "Software"), to deal in the Software without
   1.155 + * restriction, including without limitation the rights to use, copy, modify,
   1.156 + * merge, publish, distribute, sublicense, and/or sell copies of the Software,
   1.157 + * and to permit persons to whom the Software is furnished to do so, subject to
   1.158 + * the following conditions:
   1.159 + * 
   1.160 + * The above copyright notice and this permission notice shall be included in
   1.161 + * all copies or substantial portions of the Software.
   1.162 + */
   1.163 +/* Also Copyright (C) 2008 Andy Grover */
   1.164 +
   1.165 +#define __STR(x) #x
   1.166 +#define STR(x) __STR(x)
   1.167 +
   1.168 +#define HYPERCALL_STR(name)					\
   1.169 +	"mov $xpdd->hypercall_stubs,%%eax; "				\
   1.170 +	"add $("STR(__HYPERVISOR_##name)" * 32),%%eax; "	\
   1.171 +	"call *%%eax"
   1.172 +
   1.173 +#define _hypercall2(type, name, a1, a2)                         \
   1.174 +({                                                              \
   1.175 +        long __res, __ign1, __ign2;                             \
   1.176 +        asm volatile (                                          \
   1.177 +                HYPERCALL_STR(name)                             \
   1.178 +                : "=a" (__res), "=b" (__ign1), "=c" (__ign2)    \
   1.179 +                : "1" ((long)(a1)), "2" ((long)(a2))            \
   1.180 +                : "memory" );                                   \
   1.181 +        (type)__res;                                            \
   1.182 +})
   1.183 +
   1.184 +#define _hypercall3(type, name, a1, a2, a3)			\
   1.185 +({								\
   1.186 +	long __res, __ign1, __ign2, __ign3;			\
   1.187 +	asm volatile (						\
   1.188 +		HYPERCALL_STR(name)				\
   1.189 +		: "=a" (__res), "=b" (__ign1), "=c" (__ign2), 	\
   1.190 +		"=d" (__ign3)					\
   1.191 +		: "1" ((long)(a1)), "2" ((long)(a2)),		\
   1.192 +		"3" ((long)(a3))				\
   1.193 +		: "memory" );					\
   1.194 +	(type)__res;						\
   1.195 +})
   1.196 +
   1.197 +#define _hypercall4(type, name, a1, a2, a3, a4)			\
   1.198 +({								\
   1.199 +	long __res, __ign1, __ign2, __ign3, __ign4;		\
   1.200 +	asm volatile (						\
   1.201 +		HYPERCALL_STR(name)				\
   1.202 +		: "=a" (__res), "=b" (__ign1), "=c" (__ign2),	\
   1.203 +		"=d" (__ign3), "=S" (__ign4)			\
   1.204 +		: "1" ((long)(a1)), "2" ((long)(a2)),		\
   1.205 +		"3" ((long)(a3)), "4" ((long)(a4))		\
   1.206 +		: "memory" );					\
   1.207 +	(type)__res;						\
   1.208 +})
   1.209 +
   1.210 +static inline void cpuid(int op, unsigned int *eax, unsigned int *ebx,
   1.211 +                         unsigned int *ecx, unsigned int *edx)
   1.212 +{
   1.213 +  __asm__("cpuid"
   1.214 +          : "=a" (*eax),
   1.215 +            "=b" (*ebx),
   1.216 +            "=c" (*ecx),
   1.217 +            "=d" (*edx)
   1.218 +          : "0" (op));
   1.219 +}
   1.220 +
   1.221 +static __inline void __cpuid(uint32_t output[4], uint32_t op)
   1.222 +{
   1.223 +  cpuid(op, &output[0], &output[1], &output[2], &output[3]);
   1.224 +}
   1.225 +
   1.226 +static __inline void __writemsr(uint32_t msr, uint64_t value)
   1.227 +{
   1.228 +  uint32_t hi, lo;
   1.229 +  hi = value >> 32;
   1.230 +  lo = value & 0xFFFFFFFF;
   1.231 +
   1.232 +  __asm__ __volatile__("wrmsr" \
   1.233 +                       : /* no outputs */ \
   1.234 +                       : "c" (msr), "a" (lo), "d" (hi));
   1.235 +}
   1.236 +
   1.237 +static __inline int
   1.238 +HYPERVISOR_memory_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
   1.239 +{
   1.240 +  return _hypercall2(int, memory_op, cmd, arg);
   1.241 +}
   1.242 +
   1.243 +static __inline int
   1.244 +HYPERVISOR_sched_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
   1.245 +{
   1.246 +  return _hypercall2(int, sched_op, cmd, arg);
   1.247 +}
   1.248 +
   1.249 +static __inline int
   1.250 +HYPERVISOR_xen_version(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
   1.251 +{
   1.252 +  return _hypercall2(int, xen_version, cmd, arg);
   1.253 +}
   1.254 +
   1.255 +static __inline int
   1.256 +HYPERVISOR_grant_table_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *uop, unsigned int count)
   1.257 +{
   1.258 +	return _hypercall3(int, grant_table_op, cmd, uop, count);
   1.259 +}
   1.260 +
   1.261 +static __inline int
   1.262 +HYPERVISOR_mmu_update(PXENPCI_DEVICE_DATA xpdd, mmu_update_t *req, int count, int *success_count, domid_t domid)
   1.263 +{
   1.264 +	return _hypercall4(int, mmu_update, req, count, success_count, domid);
   1.265 +}
   1.266 +
   1.267 +static __inline int
   1.268 +HYPERVISOR_console_io(PXENPCI_DEVICE_DATA xpdd, int cmd, int count, char *string)
   1.269 +{
   1.270 +	return _hypercall3(int, console_io, cmd, count, string);
   1.271 +}
   1.272 +
   1.273 +static __inline int
   1.274 +HYPERVISOR_hvm_op(PXENPCI_DEVICE_DATA xpdd, int op, struct xen_hvm_param *arg)
   1.275 +{
   1.276 +  return _hypercall2(unsigned long, hvm_op, op, arg);
   1.277 +}
   1.278 +
   1.279 +static __inline int
   1.280 +HYPERVISOR_event_channel_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
   1.281 +{
   1.282 +	return _hypercall2(int, event_channel_op, cmd, arg);
   1.283 +}
   1.284 +