ia64/xen-unstable

changeset 15756:c98c707a07a8

xencomm: Fix for code style.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Tue Aug 14 16:32:49 2007 +0100 (2007-08-14)
parents 3db3c4868568
children 256160ff19b7
files xen/common/xencomm.c xen/include/xen/xencomm.h
line diff
     1.1 --- a/xen/common/xencomm.c	Tue Aug 14 16:01:34 2007 +0100
     1.2 +++ b/xen/common/xencomm.c	Tue Aug 14 16:32:49 2007 +0100
     1.3 @@ -26,43 +26,35 @@
     1.4  #include <public/xen.h>
     1.5  #include <public/xencomm.h>
     1.6  
     1.7 -
     1.8  #undef DEBUG
     1.9  #ifdef DEBUG
    1.10 -static int xencomm_debug = 1; /* extremely verbose */
    1.11 +#define xc_dprintk(f, a...) printk("[xencomm]" f , ## a)
    1.12  #else
    1.13 -#define xencomm_debug 0
    1.14 +#define xc_dprintk(f, a...) ((void)0)
    1.15  #endif
    1.16  
    1.17  static void*
    1.18  xencomm_maddr_to_vaddr(unsigned long maddr)
    1.19  {
    1.20 -    if (maddr == 0)
    1.21 -        return NULL;
    1.22 -    
    1.23 -    return maddr_to_virt(maddr);
    1.24 +    return maddr ? maddr_to_virt(maddr) : NULL;
    1.25  }
    1.26  
    1.27  static unsigned long
    1.28 -xencomm_inline_from_guest(void *to, const void *from, unsigned int n,
    1.29 -        unsigned int skip)
    1.30 +xencomm_inline_from_guest(
    1.31 +    void *to, const void *from, unsigned int n, unsigned int skip)
    1.32  {
    1.33 -    unsigned long src_paddr = xencomm_inline_addr(from);
    1.34 +    unsigned long src_paddr = xencomm_inline_addr(from) + skip;
    1.35  
    1.36 -    src_paddr += skip;
    1.37 -
    1.38 -    while (n > 0) {
    1.39 -        unsigned int chunksz;
    1.40 +    while ( n > 0 )
    1.41 +    {
    1.42 +        unsigned int chunksz, bytes;
    1.43          unsigned long src_maddr;
    1.44 -        unsigned int bytes;
    1.45  
    1.46          chunksz = PAGE_SIZE - (src_paddr % PAGE_SIZE);
    1.47 -
    1.48 -        bytes = min(chunksz, n);
    1.49 +        bytes   = min(chunksz, n);
    1.50  
    1.51          src_maddr = paddr_to_maddr(src_paddr);
    1.52 -        if (xencomm_debug)
    1.53 -            printk("%lx[%d] -> %lx\n", src_maddr, bytes, (unsigned long)to);
    1.54 +        xc_dprintk("%lx[%d] -> %lx\n", src_maddr, bytes, (unsigned long)to);
    1.55          memcpy(to, maddr_to_virt(src_maddr), bytes);
    1.56          src_paddr += bytes;
    1.57          to += bytes;
    1.58 @@ -86,37 +78,40 @@ xencomm_inline_from_guest(void *to, cons
    1.59   * On success, this will be zero.
    1.60   */
    1.61  unsigned long
    1.62 -xencomm_copy_from_guest(void *to, const void *from, unsigned int n,
    1.63 -        unsigned int skip)
    1.64 +xencomm_copy_from_guest(
    1.65 +    void *to, const void *from, unsigned int n, unsigned int skip)
    1.66  {
    1.67      struct xencomm_desc *desc;
    1.68      unsigned int from_pos = 0;
    1.69      unsigned int to_pos = 0;
    1.70      unsigned int i = 0;
    1.71  
    1.72 -    if (xencomm_is_inline(from))
    1.73 +    if ( xencomm_is_inline(from) )
    1.74          return xencomm_inline_from_guest(to, from, n, skip);
    1.75  
    1.76 -    /* first we need to access the descriptor */
    1.77 +    /* First we need to access the descriptor. */
    1.78      desc = (struct xencomm_desc *)
    1.79          xencomm_maddr_to_vaddr(paddr_to_maddr((unsigned long)from));
    1.80 -    if (desc == NULL)
    1.81 +    if ( desc == NULL )
    1.82          return n;
    1.83  
    1.84 -    if (desc->magic != XENCOMM_MAGIC) {
    1.85 +    if ( desc->magic != XENCOMM_MAGIC )
    1.86 +    {
    1.87          printk("%s: error: %p magic was 0x%x\n",
    1.88                 __func__, desc, desc->magic);
    1.89          return n;
    1.90      }
    1.91  
    1.92 -    /* iterate through the descriptor, copying up to a page at a time */
    1.93 -    while ((to_pos < n) && (i < desc->nr_addrs)) {
    1.94 +    /* Iterate through the descriptor, copying up to a page at a time. */
    1.95 +    while ( (to_pos < n) && (i < desc->nr_addrs) )
    1.96 +    {
    1.97          unsigned long src_paddr = desc->address[i];
    1.98          unsigned int pgoffset;
    1.99          unsigned int chunksz;
   1.100          unsigned int chunk_skip;
   1.101  
   1.102 -        if (src_paddr == XENCOMM_INVALID) {
   1.103 +        if ( src_paddr == XENCOMM_INVALID )
   1.104 +        {
   1.105              i++;
   1.106              continue;
   1.107          }
   1.108 @@ -129,17 +124,17 @@ xencomm_copy_from_guest(void *to, const 
   1.109          chunksz -= chunk_skip;
   1.110          skip -= chunk_skip;
   1.111  
   1.112 -        if (skip == 0 && chunksz > 0) {
   1.113 +        if ( (skip == 0) && (chunksz > 0) )
   1.114 +        {
   1.115              unsigned long src_maddr;
   1.116              unsigned long dest = (unsigned long)to + to_pos;
   1.117              unsigned int bytes = min(chunksz, n - to_pos);
   1.118  
   1.119              src_maddr = paddr_to_maddr(src_paddr + chunk_skip);
   1.120 -            if (src_maddr == 0)
   1.121 +            if ( src_maddr == 0 )
   1.122                  return n - to_pos;
   1.123  
   1.124 -            if (xencomm_debug)
   1.125 -                printk("%lx[%d] -> %lx\n", src_maddr, bytes, dest);
   1.126 +            xc_dprintk("%lx[%d] -> %lx\n", src_maddr, bytes, dest);
   1.127              memcpy((void *)dest, maddr_to_virt(src_maddr), bytes);
   1.128              from_pos += bytes;
   1.129              to_pos += bytes;
   1.130 @@ -152,32 +147,28 @@ xencomm_copy_from_guest(void *to, const 
   1.131  }
   1.132  
   1.133  static unsigned long
   1.134 -xencomm_inline_to_guest(void *to, const void *from, unsigned int n,
   1.135 -        unsigned int skip)
   1.136 +xencomm_inline_to_guest(
   1.137 +    void *to, const void *from, unsigned int n, unsigned int skip)
   1.138  {
   1.139 -    unsigned long dest_paddr = xencomm_inline_addr(to);
   1.140 +    unsigned long dest_paddr = xencomm_inline_addr(to) + skip;
   1.141  
   1.142 -    dest_paddr += skip;
   1.143 -
   1.144 -    while (n > 0) {
   1.145 -        unsigned int chunksz;
   1.146 +    while ( n > 0 )
   1.147 +    {
   1.148 +        unsigned int chunksz, bytes;
   1.149          unsigned long dest_maddr;
   1.150 -        unsigned int bytes;
   1.151  
   1.152          chunksz = PAGE_SIZE - (dest_paddr % PAGE_SIZE);
   1.153 -
   1.154 -        bytes = min(chunksz, n);
   1.155 +        bytes   = min(chunksz, n);
   1.156  
   1.157          dest_maddr = paddr_to_maddr(dest_paddr);
   1.158 -        if (xencomm_debug)
   1.159 -            printk("%lx[%d] -> %lx\n", (unsigned long)from, bytes, dest_maddr);
   1.160 +        xc_dprintk("%lx[%d] -> %lx\n", (unsigned long)from, bytes, dest_maddr);
   1.161          memcpy(maddr_to_virt(dest_maddr), (void *)from, bytes);
   1.162          dest_paddr += bytes;
   1.163          from += bytes;
   1.164          n -= bytes;
   1.165      }
   1.166  
   1.167 -    /* Always successful.  */
   1.168 +    /* Always successful. */
   1.169      return 0;
   1.170  }
   1.171  
   1.172 @@ -194,36 +185,37 @@ xencomm_inline_to_guest(void *to, const 
   1.173   * On success, this will be zero.
   1.174   */
   1.175  unsigned long
   1.176 -xencomm_copy_to_guest(void *to, const void *from, unsigned int n,
   1.177 -        unsigned int skip)
   1.178 +xencomm_copy_to_guest(
   1.179 +    void *to, const void *from, unsigned int n, unsigned int skip)
   1.180  {
   1.181      struct xencomm_desc *desc;
   1.182      unsigned int from_pos = 0;
   1.183      unsigned int to_pos = 0;
   1.184      unsigned int i = 0;
   1.185  
   1.186 -    if (xencomm_is_inline(to))
   1.187 +    if ( xencomm_is_inline(to) )
   1.188          return xencomm_inline_to_guest(to, from, n, skip);
   1.189  
   1.190 -    /* first we need to access the descriptor */
   1.191 +    /* First we need to access the descriptor. */
   1.192      desc = (struct xencomm_desc *)
   1.193          xencomm_maddr_to_vaddr(paddr_to_maddr((unsigned long)to));
   1.194 -    if (desc == NULL)
   1.195 +    if ( desc == NULL )
   1.196          return n;
   1.197  
   1.198 -    if (desc->magic != XENCOMM_MAGIC) {
   1.199 +    if ( desc->magic != XENCOMM_MAGIC )
   1.200 +    {
   1.201          printk("%s error: %p magic was 0x%x\n", __func__, desc, desc->magic);
   1.202          return n;
   1.203      }
   1.204  
   1.205 -    /* iterate through the descriptor, copying up to a page at a time */
   1.206 -    while ((from_pos < n) && (i < desc->nr_addrs)) {
   1.207 +    /* Iterate through the descriptor, copying up to a page at a time. */
   1.208 +    while ( (from_pos < n) && (i < desc->nr_addrs) )
   1.209 +    {
   1.210          unsigned long dest_paddr = desc->address[i];
   1.211 -        unsigned int pgoffset;
   1.212 -        unsigned int chunksz;
   1.213 -        unsigned int chunk_skip;
   1.214 +        unsigned int pgoffset, chunksz, chunk_skip;
   1.215  
   1.216 -        if (dest_paddr == XENCOMM_INVALID) {
   1.217 +        if ( dest_paddr == XENCOMM_INVALID )
   1.218 +        {
   1.219              i++;
   1.220              continue;
   1.221          }
   1.222 @@ -236,17 +228,17 @@ xencomm_copy_to_guest(void *to, const vo
   1.223          chunksz -= chunk_skip;
   1.224          skip -= chunk_skip;
   1.225  
   1.226 -        if (skip == 0 && chunksz > 0) {
   1.227 +        if ( (skip == 0) && (chunksz > 0) )
   1.228 +        {
   1.229              unsigned long dest_maddr;
   1.230              unsigned long source = (unsigned long)from + from_pos;
   1.231              unsigned int bytes = min(chunksz, n - from_pos);
   1.232  
   1.233              dest_maddr = paddr_to_maddr(dest_paddr + chunk_skip);
   1.234 -            if (dest_maddr == 0)
   1.235 +            if ( dest_maddr == 0 )
   1.236                  return n - from_pos;
   1.237  
   1.238 -            if (xencomm_debug)
   1.239 -                printk("%lx[%d] -> %lx\n", source, bytes, dest_maddr);
   1.240 +            xc_dprintk("%lx[%d] -> %lx\n", source, bytes, dest_maddr);
   1.241              memcpy(maddr_to_virt(dest_maddr), (void *)source, bytes);
   1.242              from_pos += bytes;
   1.243              to_pos += bytes;
   1.244 @@ -271,28 +263,29 @@ int xencomm_add_offset(void **handle, un
   1.245      struct xencomm_desc *desc;
   1.246      int i = 0;
   1.247  
   1.248 -    if (xencomm_is_inline(*handle))
   1.249 +    if ( xencomm_is_inline(*handle) )
   1.250          return xencomm_inline_add_offset(handle, bytes);
   1.251  
   1.252 -    /* first we need to access the descriptor */
   1.253 +    /* First we need to access the descriptor. */
   1.254      desc = (struct xencomm_desc *)
   1.255          xencomm_maddr_to_vaddr(paddr_to_maddr((unsigned long)*handle));
   1.256 -    if (desc == NULL)
   1.257 +    if ( desc == NULL )
   1.258          return -1;
   1.259  
   1.260 -    if (desc->magic != XENCOMM_MAGIC) {
   1.261 +    if ( desc->magic != XENCOMM_MAGIC )
   1.262 +    {
   1.263          printk("%s error: %p magic was 0x%x\n", __func__, desc, desc->magic);
   1.264          return -1;
   1.265      }
   1.266  
   1.267 -    /* iterate through the descriptor incrementing addresses */
   1.268 -    while ((bytes > 0) && (i < desc->nr_addrs)) {
   1.269 +    /* Iterate through the descriptor incrementing addresses. */
   1.270 +    while ( (bytes > 0) && (i < desc->nr_addrs) )
   1.271 +    {
   1.272          unsigned long dest_paddr = desc->address[i];
   1.273 -        unsigned int pgoffset;
   1.274 -        unsigned int chunksz;
   1.275 -        unsigned int chunk_skip;
   1.276 +        unsigned int pgoffset, chunksz, chunk_skip;
   1.277  
   1.278 -        if (dest_paddr == XENCOMM_INVALID) {
   1.279 +        if ( dest_paddr == XENCOMM_INVALID )
   1.280 +        {
   1.281              i++;
   1.282              continue;
   1.283          }
   1.284 @@ -301,16 +294,15 @@ int xencomm_add_offset(void **handle, un
   1.285          chunksz = PAGE_SIZE - pgoffset;
   1.286  
   1.287          chunk_skip = min(chunksz, bytes);
   1.288 -        if (chunk_skip == chunksz) {
   1.289 -            /* exhausted this page */
   1.290 -            desc->address[i] = XENCOMM_INVALID;
   1.291 -        } else {
   1.292 +        if ( chunk_skip == chunksz )
   1.293 +            desc->address[i] = XENCOMM_INVALID; /* exchausted this page */
   1.294 +        else
   1.295              desc->address[i] += chunk_skip;
   1.296 -        }
   1.297          bytes -= chunk_skip;
   1.298  
   1.299          i++;
   1.300      }
   1.301 +
   1.302      return 0;
   1.303  }
   1.304  
   1.305 @@ -319,18 +311,17 @@ int xencomm_handle_is_null(void *handle)
   1.306      struct xencomm_desc *desc;
   1.307      int i;
   1.308  
   1.309 -    if (xencomm_is_inline(handle))
   1.310 +    if ( xencomm_is_inline(handle) )
   1.311          return xencomm_inline_addr(handle) == 0;
   1.312  
   1.313      desc = (struct xencomm_desc *)
   1.314          xencomm_maddr_to_vaddr(paddr_to_maddr((unsigned long)handle));
   1.315 -    if (desc == NULL)
   1.316 +    if ( desc == NULL )
   1.317          return 1;
   1.318  
   1.319 -    for (i = 0; i < desc->nr_addrs; i++)
   1.320 -        if (desc->address[i] != XENCOMM_INVALID)
   1.321 +    for ( i = 0; i < desc->nr_addrs; i++ )
   1.322 +        if ( desc->address[i] != XENCOMM_INVALID )
   1.323              return 0;
   1.324  
   1.325      return 1;
   1.326  }
   1.327 -
     2.1 --- a/xen/include/xen/xencomm.h	Tue Aug 14 16:01:34 2007 +0100
     2.2 +++ b/xen/include/xen/xencomm.h	Tue Aug 14 16:32:49 2007 +0100
     2.3 @@ -23,13 +23,12 @@
     2.4  
     2.5  #include <public/xen.h>
     2.6  
     2.7 -extern unsigned long xencomm_copy_to_guest(void *to, const void *from,
     2.8 -        unsigned int len, unsigned int skip); 
     2.9 -extern unsigned long xencomm_copy_from_guest(void *to, const void *from,
    2.10 -        unsigned int len, unsigned int skip); 
    2.11 -extern int xencomm_add_offset(void **handle, unsigned int bytes);
    2.12 -extern int xencomm_handle_is_null(void *ptr);
    2.13 -
    2.14 +unsigned long xencomm_copy_to_guest(
    2.15 +    void *to, const void *from, unsigned int len, unsigned int skip); 
    2.16 +unsigned long xencomm_copy_from_guest(
    2.17 +    void *to, const void *from, unsigned int len, unsigned int skip); 
    2.18 +int xencomm_add_offset(void **handle, unsigned int bytes);
    2.19 +int xencomm_handle_is_null(void *ptr);
    2.20  
    2.21  static inline int xencomm_is_inline(const void *handle)
    2.22  {
    2.23 @@ -39,7 +38,7 @@ static inline int xencomm_is_inline(cons
    2.24  
    2.25  static inline unsigned long xencomm_inline_addr(const void *handle)
    2.26  {
    2.27 -	return (unsigned long)handle & ~XENCOMM_INLINE_FLAG;
    2.28 +    return (unsigned long)handle & ~XENCOMM_INLINE_FLAG;
    2.29  }
    2.30  
    2.31  /* Is the guest handle a NULL reference? */