linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: dave.martin@linaro.org (Dave Martin)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH-WIP 01/13] xen/arm: use r12 to pass the hypercall number to the hypervisor
Date: Mon, 27 Feb 2012 17:53:27 +0000	[thread overview]
Message-ID: <20120227175327.GA2023@linaro.org> (raw)
In-Reply-To: <1330019314-20865-1-git-send-email-stefano.stabellini@eu.citrix.com>

On Thu, Feb 23, 2012 at 05:48:22PM +0000, Stefano Stabellini wrote:
> We need a register to pass the hypercall number because we might not
> know it at compile time and HVC only takes an immediate argument.
> 
> Among the available registers r12 seems to be the best choice because it
> is defined as "intra-procedure call scratch register".

This would be massively simplified if you didn't try to inline the HVC.
Does it really need to be inline?

> 
> Use the ISS to pass an hypervisor specific tag.
> 
> Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> CC: kvm at vger.kernel.org
> ---
>  arch/arm/include/asm/xen/hypercall.h |   87 +++++++++++++++++++---------------
>  1 files changed, 48 insertions(+), 39 deletions(-)
> 
> diff --git a/arch/arm/include/asm/xen/hypercall.h b/arch/arm/include/asm/xen/hypercall.h
> index 404e63f0..04eba1c 100644
> --- a/arch/arm/include/asm/xen/hypercall.h
> +++ b/arch/arm/include/asm/xen/hypercall.h
> @@ -33,13 +33,17 @@
>  #ifndef _ASM_ARM_XEN_HYPERCALL_H
>  #define _ASM_ARM_XEN_HYPERCALL_H
>  
> -#define __HVC_IMM(name)	"( " #name " & 0xf) + "	  \
> -			    "((" #name " << 4) & 0xfff00)"
> +#include <xen/interface/xen.h>
> +#include <asm/errno.h>
>  
> -#define ____HYPERCALL(name) ".word 0xe1400070 + " __HVC_IMM(name)
> -#define __HYPERCALL(name) ____HYPERCALL(__HYPERVISOR_##name)
> +#define XEN_HYPERCALL_TAG  "0XEA1"
> +
> +#define __HVC_IMM(tag)	"( " tag " & 0xf) + "	  \
> +			    "((" tag " << 4) & 0xfff00)"
> +#define __HYPERCALL ".word 0xe1400070 + " __HVC_IMM(XEN_HYPERCALL_TAG)

Please, do not do this.  It won't work in Thumb, where the encodings are
different.

It is reasonable to expect anyone building Xen to have reasonably new
tools, you you can justifiably use

AFLAGS_thisfile.o := -Wa,-march=armv7-a+virt

in the Makefile and just use the hvc instruction directly.


Of course, this is only practical if the HVC invocation is not inlined.
If we can't avoid macro-ising HVC, we should do it globally, not locally
to the Xen code.  That way we at least keep all the horror in one place.

Cheers
---Dave

>  
>  #define __HYPERCALL_RETREG	"r0"
> +#define __HYPERCALL_NUMBER	"r12"
>  #define __HYPERCALL_ARG1REG	"r0"
>  #define __HYPERCALL_ARG2REG	"r1"
>  #define __HYPERCALL_ARG3REG	"r2"
> @@ -48,30 +52,32 @@
>  
>  #define __HYPERCALL_DECLS						\
>  	register unsigned long __res  asm(__HYPERCALL_RETREG);		\
> +	register unsigned long __num  asm(__HYPERCALL_NUMBER) = __num; \
>  	register unsigned long __arg1 asm(__HYPERCALL_ARG1REG) = __arg1; \
>  	register unsigned long __arg2 asm(__HYPERCALL_ARG2REG) = __arg2; \
>  	register unsigned long __arg3 asm(__HYPERCALL_ARG3REG) = __arg3; \
>  	register unsigned long __arg4 asm(__HYPERCALL_ARG4REG) = __arg4; \
>  	register unsigned long __arg5 asm(__HYPERCALL_ARG5REG) = __arg5;
>  
> -#define __HYPERCALL_0PARAM	"=r" (__res)
> +#define __HYPERCALL_0PARAM	"=r" (__res), "+r" (__num)
>  #define __HYPERCALL_1PARAM	__HYPERCALL_0PARAM, "+r" (__arg1)
>  #define __HYPERCALL_2PARAM	__HYPERCALL_1PARAM, "+r" (__arg2)
>  #define __HYPERCALL_3PARAM	__HYPERCALL_2PARAM, "+r" (__arg3)
>  #define __HYPERCALL_4PARAM	__HYPERCALL_3PARAM, "+r" (__arg4)
>  #define __HYPERCALL_5PARAM	__HYPERCALL_4PARAM, "+r" (__arg5)
>  
> -#define __HYPERCALL_0ARG()
> -#define __HYPERCALL_1ARG(a1)						\
> -	__HYPERCALL_0ARG()		__arg1 = (unsigned long)(a1);
> -#define __HYPERCALL_2ARG(a1,a2)						\
> -	__HYPERCALL_1ARG(a1)		__arg2 = (unsigned long)(a2);
> -#define __HYPERCALL_3ARG(a1,a2,a3)					\
> -	__HYPERCALL_2ARG(a1,a2)		__arg3 = (unsigned long)(a3);
> -#define __HYPERCALL_4ARG(a1,a2,a3,a4)					\
> -	__HYPERCALL_3ARG(a1,a2,a3)	__arg4 = (unsigned long)(a4);
> -#define __HYPERCALL_5ARG(a1,a2,a3,a4,a5)				\
> -	__HYPERCALL_4ARG(a1,a2,a3,a4)	__arg5 = (unsigned long)(a5);
> +#define __HYPERCALL_0ARG(hypercall)						\
> +	__num = (unsigned long)hypercall;
> +#define __HYPERCALL_1ARG(hypercall,a1)						\
> +	__HYPERCALL_0ARG(hypercall)		__arg1 = (unsigned long)(a1);
> +#define __HYPERCALL_2ARG(hypercall,a1,a2)						\
> +	__HYPERCALL_1ARG(hypercall,a1)		__arg2 = (unsigned long)(a2);
> +#define __HYPERCALL_3ARG(hypercall,a1,a2,a3)					\
> +	__HYPERCALL_2ARG(hypercall,a1,a2)		__arg3 = (unsigned long)(a3);
> +#define __HYPERCALL_4ARG(hypercall,a1,a2,a3,a4)					\
> +	__HYPERCALL_3ARG(hypercall,a1,a2,a3)	__arg4 = (unsigned long)(a4);
> +#define __HYPERCALL_5ARG(hypercall,a1,a2,a3,a4,a5)				\
> +	__HYPERCALL_4ARG(hypercall,a1,a2,a3,a4)	__arg5 = (unsigned long)(a5);
>  
>  #define __HYPERCALL_CLOBBER5	"memory"
>  #define __HYPERCALL_CLOBBER4	__HYPERCALL_CLOBBER5, __HYPERCALL_ARG5REG
> @@ -80,102 +86,105 @@
>  #define __HYPERCALL_CLOBBER1	__HYPERCALL_CLOBBER2, __HYPERCALL_ARG2REG
>  #define __HYPERCALL_CLOBBER0	__HYPERCALL_CLOBBER1, __HYPERCALL_ARG1REG
>  
> -#define _hypercall0(type, name)						\
> +#define _hypercall0(type, hypercall)						\
>  ({									\
>  	__HYPERCALL_DECLS;						\
> -	__HYPERCALL_0ARG();						\
> -	asm volatile (__HYPERCALL(name)					\
> +	__HYPERCALL_0ARG(hypercall);						\
> +	asm volatile (__HYPERCALL					\
>  		      : __HYPERCALL_0PARAM				\
>  		      : 						\
>  		      : __HYPERCALL_CLOBBER0);				\
>  	(type)__res;							\
>  })
>  
> -#define _hypercall1(type, name, a1)					\
> +#define _hypercall1(type, hypercall, a1)					\
>  ({									\
>  	__HYPERCALL_DECLS;						\
> -	__HYPERCALL_1ARG(a1);						\
> -	asm volatile (__HYPERCALL(name)					\
> +	__HYPERCALL_1ARG(hypercall, a1);						\
> +	asm volatile (__HYPERCALL					\
>  		      : __HYPERCALL_1PARAM				\
>  		      : 						\
>  		      : __HYPERCALL_CLOBBER1);				\
>  	(type)__res;							\
>  })
>  
> -#define _hypercall2(type, name, a1, a2)					\
> +#define _hypercall2(type, hypercall, a1, a2)					\
>  ({									\
>  	__HYPERCALL_DECLS;						\
> -	__HYPERCALL_2ARG(a1, a2);					\
> -	asm volatile (__HYPERCALL(name)					\
> +	__HYPERCALL_2ARG(hypercall, a1, a2);					\
> +	asm volatile (__HYPERCALL					\
>  		      : __HYPERCALL_2PARAM				\
>  		      : 						\
>  		      : __HYPERCALL_CLOBBER2);				\
>  	(type)__res;							\
>  })
>  
> -#define _hypercall3(type, name, a1, a2, a3)				\
> +#define _hypercall3(type, hypercall, a1, a2, a3)				\
>  ({									\
>  	__HYPERCALL_DECLS;						\
> -	__HYPERCALL_3ARG(a1, a2, a3);					\
> -	asm volatile (__HYPERCALL(name)					\
> +	__HYPERCALL_3ARG(hypercall, a1, a2, a3);					\
> +	asm volatile (__HYPERCALL					\
>  		      : __HYPERCALL_3PARAM				\
>  		      : 						\
>  		      : __HYPERCALL_CLOBBER3);				\
>  	(type)__res;							\
>  })
>  
> -#define _hypercall4(type, name, a1, a2, a3, a4)				\
> +#define _hypercall4(type, hypercall, a1, a2, a3, a4)				\
>  ({									\
>  	__HYPERCALL_DECLS;						\
> -	__HYPERCALL_4ARG(a1, a2, a3, a4);				\
> -	asm volatile (__HYPERCALL(name)					\
> +	__HYPERCALL_4ARG(hypercall, a1, a2, a3, a4);				\
> +	asm volatile (__HYPERCALL					\
>  		      : __HYPERCALL_4PARAM				\
>  		      : 						\
>  		      : __HYPERCALL_CLOBBER4);				\
>  	(type)__res;							\
>  })
>  
> -#define _hypercall5(type, name, a1, a2, a3, a4, a5)			\
> +#define _hypercall5(type, hypercall, a1, a2, a3, a4, a5)			\
>  ({									\
>  	__HYPERCALL_DECLS;						\
> -	__HYPERCALL_5ARG(a1, a2, a3, a4, a5);				\
> -	asm volatile (__HYPERCALL(name)					\
> +	__HYPERCALL_5ARG(hypercall, a1, a2, a3, a4, a5);				\
> +	asm volatile (__HYPERCALL					\
>  		      : __HYPERCALL_5PARAM				\
>  		      : 						\
>  		      : __HYPERCALL_CLOBBER5);				\
>  	(type)__res;							\
>  })
>  
> +#define HYPERCALL(name) \
> +	(__HYPERVISOR_##name)
> +
>  /* -- Hypercall definitions go below -- */
>  
>  static inline int
>  HYPERVISOR_xen_version(int cmd, void *arg)
>  {
> -	return _hypercall2(int, xen_version, cmd, arg);
> +	return _hypercall2(int, HYPERCALL(xen_version), cmd, arg);
>  }
>  
>  static inline int
>  HYPERVISOR_console_io(int cmd, int count, char *str)
>  {
> -	return _hypercall3(int, console_io, cmd, count, str);
> +	return _hypercall3(int, HYPERCALL(console_io), cmd, count, str);
>  }
>  
>  static inline int
>  HYPERVISOR_grant_table_op(unsigned int cmd, void *uop, unsigned int count)
>  {
> -	return _hypercall3(int, grant_table_op, cmd, uop, count);
> +	return _hypercall3(int, HYPERCALL(grant_table_op), cmd, uop, count);
>  }
>  
>  static inline int
>  HYPERVISOR_sched_op(int cmd, void *arg)
>  {
> -	return _hypercall2(int, sched_op, cmd, arg);
> +	return _hypercall2(int, HYPERCALL(sched_op), cmd, arg);
>  }
>  
>  static inline int
>  HYPERVISOR_event_channel_op(int cmd, void *arg)
>  {
> -	return _hypercall2(int, event_channel_op, cmd, arg);
> +	return _hypercall2(int, HYPERCALL(event_channel_op), cmd, arg);
>  }
>  
>  #endif /* _ASM_ARM_XEN_HYPERCALL_H */
> -- 
> 1.7.2.5
> 
> 
> _______________________________________________
> linaro-dev mailing list
> linaro-dev at lists.linaro.org
> http://lists.linaro.org/mailman/listinfo/linaro-dev

  parent reply	other threads:[~2012-02-27 17:53 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-23 17:47 [PATCH-WIP 00/13] xen/arm: receive Xen events and initialize xenbus Stefano Stabellini
2012-02-23 17:48 ` [PATCH-WIP 01/13] xen/arm: use r12 to pass the hypercall number to the hypervisor Stefano Stabellini
2012-02-27 16:27   ` Ian Campbell
2012-02-27 18:03     ` Dave Martin
2012-02-27 19:33       ` Ian Campbell
2012-02-28 10:20         ` Dave Martin
2012-02-28 10:48           ` Ian Campbell
2012-02-28 12:28             ` Stefano Stabellini
2012-02-29  9:34               ` Dave Martin
2012-02-29  9:56                 ` Ian Campbell
2012-02-29 11:47                   ` Dave Martin
2012-02-29 12:58                   ` Dave Martin
2012-02-29 14:44                     ` Ian Campbell
2012-03-01  9:35                       ` Dave Martin
2012-03-01 10:12                       ` Russell King - ARM Linux
2012-03-02 21:19                       ` Nicolas Pitre
2012-02-29 14:52                     ` Stefano Stabellini
2012-03-01  9:51                       ` Dave Martin
2012-03-01 10:10                     ` Russell King - ARM Linux
2012-03-01 10:27                       ` Dave Martin
2012-03-01 10:35                         ` Russell King - ARM Linux
2012-03-01 12:12                           ` Stefano Stabellini
2012-03-02 21:15                     ` Nicolas Pitre
2012-03-08  9:58                       ` Richard Earnshaw
2012-03-08 12:17                         ` Dave Martin
2012-03-08 17:21                         ` Nicolas Pitre
2012-03-08 18:47                           ` Richard Earnshaw
2012-03-09 15:58                             ` Dave Martin
2012-03-09 16:20                               ` Nicolas Pitre
2012-03-09 17:38                                 ` Richard Earnshaw
2012-02-27 21:05     ` Peter Maydell
2012-02-28 10:12       ` Ian Campbell
2012-02-27 17:53   ` Dave Martin [this message]
2012-02-27 19:48     ` Ian Campbell
2012-02-28  9:46       ` Dave Martin
2012-02-28 10:07         ` Ian Campbell
2012-02-28 12:21         ` Stefano Stabellini
2012-02-23 17:48 ` [PATCH-WIP 02/13] xen/arm: introduce privcmp, physdev_op and memory_op hypercalls Stefano Stabellini
2012-02-23 17:48 ` [PATCH-WIP 03/13] xen/arm: mmu.h and page.h related definitions Stefano Stabellini
2012-02-23 17:48 ` [PATCH-WIP 04/13] xen/arm: sync_bitops Stefano Stabellini
2012-02-23 17:48 ` [PATCH-WIP 05/13] xen/arm: empty implementation of grant_table arch specific functions Stefano Stabellini
2012-02-23 17:48 ` [PATCH-WIP 06/13] xen/arm: missing includes Stefano Stabellini
2012-02-23 17:48 ` [PATCH-WIP 07/13] xen/arm: receive xen events on arm Stefano Stabellini
2012-02-24 11:12   ` David Vrabel
2012-02-24 12:23     ` Stefano Stabellini
2012-02-23 17:48 ` [PATCH-WIP 08/13] xen/arm: fix arm xen guest handle definitions Stefano Stabellini
2012-02-23 17:48 ` [PATCH-WIP 09/13] xen/arm: shared_info and start_info Stefano Stabellini
2012-02-23 17:48 ` [PATCH-WIP 10/13] xen/arm: empty implementation of xen_remap_domain_mfn_range Stefano Stabellini
2012-02-23 17:48 ` [PATCH-WIP 11/13] xen/arm: Introduce xen_pfn_t for pfn and mfn types Stefano Stabellini
2012-02-23 17:48 ` [PATCH-WIP 12/13] xen/arm: compile and run xenbus Stefano Stabellini
2012-02-23 17:48 ` [PATCH-WIP 13/13] xen/arm: compile grant-table features events and xenbus, do not compile pci Stefano Stabellini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120227175327.GA2023@linaro.org \
    --to=dave.martin@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).