direct-io.hg

changeset 13502:fa5bc90a3cb7

[XEN] Convert between long-based and byte-based bitmap arrays.
Use this for conversion of the domctl_cpumap type on big-endian
systems.
Original patch from Jimi Xenidis <jimix@watson.ibm.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Fri Jan 19 14:24:28 2007 +0000 (2007-01-19)
parents 3157835b1d45
children cd532c9351fc
files xen/common/bitmap.c xen/common/domctl.c xen/include/xen/bitmap.h
line diff
     1.1 --- a/xen/common/bitmap.c	Fri Jan 19 13:43:17 2007 +0000
     1.2 +++ b/xen/common/bitmap.c	Fri Jan 19 14:24:28 2007 +0000
     1.3 @@ -10,6 +10,7 @@
     1.4  #include <xen/errno.h>
     1.5  #include <xen/bitmap.h>
     1.6  #include <xen/bitops.h>
     1.7 +#include <asm/byteorder.h>
     1.8  
     1.9  /*
    1.10   * bitmaps provide an array of bits, implemented using an an
    1.11 @@ -467,3 +468,53 @@ int bitmap_allocate_region(unsigned long
    1.12  	return 0;
    1.13  }
    1.14  EXPORT_SYMBOL(bitmap_allocate_region);
    1.15 +
    1.16 +#ifdef __BIG_ENDIAN
    1.17 +
    1.18 +void bitmap_long_to_byte(uint8_t *bp, const unsigned long *lp, int nbits)
    1.19 +{
    1.20 +	unsigned long l;
    1.21 +	int i, j, b;
    1.22 +
    1.23 +	for (i = 0, b = 0; nbits > 0; i++, b += sizeof(l)) {
    1.24 +		l = lp[i];
    1.25 +		for (j = 0; (j < sizeof(l)) && (nbits > 0); j++) {
    1.26 +			bp[b+j] = l;
    1.27 +			l >>= 8;
    1.28 +			nbits -= 8;
    1.29 +		}
    1.30 +	}
    1.31 +}
    1.32 +
    1.33 +void bitmap_byte_to_long(unsigned long *lp, const uint8_t *bp, int nbits)
    1.34 +{
    1.35 +	unsigned long l;
    1.36 +	int i, j, b;
    1.37 +
    1.38 +	for (i = 0, b = 0; nbits > 0; i++, b += sizeof(l)) {
    1.39 +		l = 0;
    1.40 +		for (j = 0; (j < sizeof(l)) && (nbits > 0); j++) {
    1.41 +			l <<= 8;
    1.42 +			l |= bp[b+j];
    1.43 +			nbits -= 8;
    1.44 +		}
    1.45 +		lp[i] = l;
    1.46 +	}
    1.47 +}
    1.48 +
    1.49 +#elif defined(__LITTLE_ENDIAN)
    1.50 +
    1.51 +void bitmap_long_to_byte(uint8_t *bp, const unsigned long *lp, int nbits)
    1.52 +{
    1.53 +	memcpy(bp, lp, (nbits+7)/8);
    1.54 +}
    1.55 +
    1.56 +void bitmap_byte_to_long(unsigned long *lp, const uint8_t *bp, int nbits)
    1.57 +{
    1.58 +	/* We may need to pad the final longword with zeroes. */
    1.59 +	if (nbits & (BITS_PER_LONG-1))
    1.60 +		lp[BITS_TO_LONGS(nbits)-1] = 0;
    1.61 +	memcpy(lp, bp, (nbits+7)/8);
    1.62 +}
    1.63 +
    1.64 +#endif
     2.1 --- a/xen/common/domctl.c	Fri Jan 19 13:43:17 2007 +0000
     2.2 +++ b/xen/common/domctl.c	Fri Jan 19 14:24:28 2007 +0000
     2.3 @@ -18,6 +18,7 @@
     2.4  #include <xen/console.h>
     2.5  #include <xen/iocap.h>
     2.6  #include <xen/guest_access.h>
     2.7 +#include <xen/bitmap.h>
     2.8  #ifdef CONFIG_COMPAT
     2.9  #include <xen/compat.h>
    2.10  #endif
    2.11 @@ -40,16 +41,17 @@ void cpumask_to_xenctl_cpumap(
    2.12  {
    2.13      unsigned int guest_bytes, copy_bytes, i;
    2.14      uint8_t zero = 0;
    2.15 +    uint8_t bytemap[(NR_CPUS + 7) / 8];
    2.16  
    2.17      if ( guest_handle_is_null(xenctl_cpumap->bitmap) )
    2.18          return;
    2.19  
    2.20      guest_bytes = (xenctl_cpumap->nr_cpus + 7) / 8;
    2.21 -    copy_bytes  = min_t(unsigned int, guest_bytes, (NR_CPUS + 7) / 8);
    2.22 +    copy_bytes  = min_t(unsigned int, guest_bytes, sizeof(bytemap));
    2.23  
    2.24 -    copy_to_guest(xenctl_cpumap->bitmap,
    2.25 -                  (uint8_t *)cpus_addr(*cpumask),
    2.26 -                  copy_bytes);
    2.27 +    bitmap_long_to_byte(bytemap, cpus_addr(*cpumask), NR_CPUS);
    2.28 +
    2.29 +    copy_to_guest(xenctl_cpumap->bitmap, &bytemap[0], copy_bytes);
    2.30  
    2.31      for ( i = copy_bytes; i < guest_bytes; i++ )
    2.32          copy_to_guest_offset(xenctl_cpumap->bitmap, i, &zero, 1);
    2.33 @@ -59,18 +61,19 @@ void xenctl_cpumap_to_cpumask(
    2.34      cpumask_t *cpumask, struct xenctl_cpumap *xenctl_cpumap)
    2.35  {
    2.36      unsigned int guest_bytes, copy_bytes;
    2.37 +    uint8_t bytemap[(NR_CPUS + 7) / 8];
    2.38  
    2.39      guest_bytes = (xenctl_cpumap->nr_cpus + 7) / 8;
    2.40 -    copy_bytes  = min_t(unsigned int, guest_bytes, (NR_CPUS + 7) / 8);
    2.41 +    copy_bytes  = min_t(unsigned int, guest_bytes, sizeof(bytemap));
    2.42  
    2.43      cpus_clear(*cpumask);
    2.44  
    2.45      if ( guest_handle_is_null(xenctl_cpumap->bitmap) )
    2.46          return;
    2.47  
    2.48 -    copy_from_guest((uint8_t *)cpus_addr(*cpumask),
    2.49 -                    xenctl_cpumap->bitmap,
    2.50 -                    copy_bytes);
    2.51 +    copy_from_guest(&bytemap[0], xenctl_cpumap->bitmap, copy_bytes);
    2.52 +
    2.53 +    bitmap_byte_to_long(cpus_addr(*cpumask), bytemap, NR_CPUS);
    2.54  }
    2.55  
    2.56  #endif /* COMPAT */
     3.1 --- a/xen/include/xen/bitmap.h	Fri Jan 19 13:43:17 2007 +0000
     3.2 +++ b/xen/include/xen/bitmap.h	Fri Jan 19 14:24:28 2007 +0000
     3.3 @@ -251,6 +251,9 @@ static inline void bitmap_shift_left(uns
     3.4  		__bitmap_shift_left(dst, src, n, nbits);
     3.5  }
     3.6  
     3.7 +void bitmap_long_to_byte(uint8_t *bp, const unsigned long *lp, int nbits);
     3.8 +void bitmap_byte_to_long(unsigned long *lp, const uint8_t *bp, int nbits);
     3.9 +
    3.10  #endif /* __ASSEMBLY__ */
    3.11  
    3.12  #endif /* __XEN_BITMAP_H */