~n-muench/ubuntu/oneiric/open-vm-tools/open-vm-tools.fix-836277

« back to all changes in this revision

Viewing changes to lib/include/vm_atomic.h

  • Committer: Evan Broder
  • Date: 2010-03-21 23:26:53 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: broder@mit.edu-20100321232653-5a57r7v7ch4o6byv
Merging shared upstream rev into target branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
//#define FAKE_ATOMIC /* defined if true atomic not needed */
41
41
 
42
42
#define INCLUDE_ALLOW_USERLEVEL
43
 
#define INCLUDE_ALLOW_VMMEXT
 
43
 
44
44
#define INCLUDE_ALLOW_MODULE
45
45
#define INCLUDE_ALLOW_VMMON
46
46
#define INCLUDE_ALLOW_VMKDRIVERS
66
66
} Atomic_uint64 ALIGNED(8);
67
67
 
68
68
#ifdef __arm__
69
 
#ifndef NOT_IMPLEMENTED
70
 
#error NOT_IMPLEMENTED undefined
71
 
#endif
72
69
#ifdef __GNUC__
73
70
EXTERN Atomic_uint32 atomicLocked64bit;
74
71
#ifndef FAKE_ATOMIC
84
81
    * use SWP-based spin-lock.
85
82
    */
86
83
#if !defined(__linux__)
87
 
#define __kernel_cmpxchg(x, y, z) NOT_IMPLEMENTED()
 
84
#define __kernel_cmpxchg(x, y, z) _fn__kernel_cmpxchgNotImplementedOnNonLinuxARM
88
85
#else
89
86
   typedef int (__kernel_cmpxchg_t)(uint32 oldVal,
90
87
                                    uint32 newVal,
620
617
#define Atomic_And32 Atomic_And
621
618
 
622
619
 
623
 
#if defined(__x86_64__)
624
 
/*
625
 
 *-----------------------------------------------------------------------------
626
 
 *
627
 
 * Atomic_And64 --
628
 
 *
629
 
 *      Atomic read, bitwise AND with a value, write.
630
 
 *
631
 
 * Results:
632
 
 *      None
633
 
 *
634
 
 * Side effects:
635
 
 *      None
636
 
 *
637
 
 *-----------------------------------------------------------------------------
638
 
 */
639
 
 
640
 
static INLINE void
641
 
Atomic_And64(Atomic_uint64 *var, // IN
642
 
             uint64 val)         // IN
643
 
{
644
 
#if defined(__GNUC__)
645
 
   /* Checked against the AMD manual and GCC --hpreg */
646
 
   __asm__ __volatile__(
647
 
      "lock; andq %1, %0"
648
 
      : "+m" (var->value)
649
 
      : "ri" (val)
650
 
      : "cc"
651
 
   );
652
 
   AtomicEpilogue();
653
 
#elif defined _MSC_VER
654
 
   _InterlockedAnd64((__int64 *)&var->value, (__int64)val);
655
 
#else
656
 
#error No compiler defined for Atomic_And64
657
 
#endif
658
 
}
659
 
#endif
660
 
 
661
 
 
662
620
/*
663
621
 *-----------------------------------------------------------------------------
664
622
 *
721
679
#define Atomic_Or32 Atomic_Or
722
680
 
723
681
 
724
 
#if defined(__x86_64__)
725
 
/*
726
 
 *-----------------------------------------------------------------------------
727
 
 *
728
 
 * Atomic_Or64 --
729
 
 *
730
 
 *      Atomic read, bitwise OR with a value, write.
731
 
 *
732
 
 * Results:
733
 
 *      None
734
 
 *
735
 
 * Side effects:
736
 
 *      None
737
 
 *
738
 
 *-----------------------------------------------------------------------------
739
 
 */
740
 
 
741
 
static INLINE void
742
 
Atomic_Or64(Atomic_uint64 *var, // IN
743
 
            uint64 val)         // IN
744
 
{
745
 
#if defined(__GNUC__)
746
 
   /* Checked against the AMD manual and GCC --hpreg */
747
 
   __asm__ __volatile__(
748
 
      "lock; orq %1, %0"
749
 
      : "+m" (var->value)
750
 
      : "ri" (val)
751
 
      : "cc"
752
 
   );
753
 
   AtomicEpilogue();
754
 
#elif defined _MSC_VER
755
 
   _InterlockedOr64((__int64 *)&var->value, (__int64)val);
756
 
#else
757
 
#error No compiler defined for Atomic_Or64
758
 
#endif
759
 
}
760
 
#endif
761
 
 
762
 
 
763
682
/*
764
683
 *-----------------------------------------------------------------------------
765
684
 *
1598
1517
 */
1599
1518
 
1600
1519
#ifdef __arm__
1601
 
#define Atomic_CMPXCHG64(x, y, z) NOT_IMPLEMENTED()
 
1520
#define Atomic_CMPXCHG64(x, y, z) _fnAtomic_CMPXCHG64_NotImplementedOnARM
1602
1521
#else // __arm__
1603
1522
#if defined(__GNUC__) && __GNUC__ < 3
1604
1523
static Bool
1787
1706
 
1788
1707
#ifdef __arm__
1789
1708
 
1790
 
#define Atomic_Read64(x)          NOT_IMPLEMENTED()
1791
 
#define Atomic_FetchAndAdd64(x,y) NOT_IMPLEMENTED()
1792
 
#define Atomic_FetchAndInc64(x)   NOT_IMPLEMENTED()
1793
 
#define Atomic_FetchAndDec64(x)   NOT_IMPLEMENTED()
1794
 
#define Atomic_Inc64(x)           NOT_IMPLEMENTED()
1795
 
#define Atomic_Dec64(x)           NOT_IMPLEMENTED()
1796
 
#define Atomic_ReadWrite64(x,y)   NOT_IMPLEMENTED()
1797
 
#define Atomic_Write64(x,y)       NOT_IMPLEMENTED()
 
1709
#define Atomic_Read64(x)          _fnAtomic_Read64_NotImplementedOnARM
 
1710
#define Atomic_FetchAndAdd64(x,y) _fnAtomic_FetchAndAdd64_NotImplementedOnARM
 
1711
#define Atomic_FetchAndInc64(x)   _fnAtomic_FetchAndInc64_NotImplementedOnARM
 
1712
#define Atomic_FetchAndDec64(x)   _fnAtomic_FetchAndDec64_NotImplementedOnARM
 
1713
#define Atomic_Inc64(x)           _fnAtomic_Inc64_NotImplementedOnARM
 
1714
#define Atomic_Dec64(x)           _fnAtomic_Dec64_NotImplementedOnARM
 
1715
#define Atomic_ReadWrite64(x,y)   _fnAtomic_ReadWrite64_NotImplementedOnARM
 
1716
#define Atomic_Write64(x,y)       _fnAtomic_Write64_NotImplementedOnARM
 
1717
#define Atomic_And64(x)           _fnAtomic_And64_NotImplementedOnARM
 
1718
#define Atomic_Or64(x)            _fnAtomic_Or64_NotImplementedOnARM
1798
1719
 
1799
1720
#else // __arm__
1800
1721
 
2095
2016
   (void)Atomic_ReadWrite64(var, val);
2096
2017
#endif
2097
2018
}
 
2019
 
 
2020
 
 
2021
/*
 
2022
 *-----------------------------------------------------------------------------
 
2023
 *
 
2024
 * Atomic_Or64 --
 
2025
 *
 
2026
 *      Atomic read, bitwise OR with a 64-bit value, write.
 
2027
 *
 
2028
 * Results:
 
2029
 *      None
 
2030
 *
 
2031
 * Side effects:
 
2032
 *      None
 
2033
 *
 
2034
 *-----------------------------------------------------------------------------
 
2035
 */
 
2036
 
 
2037
static INLINE void
 
2038
Atomic_Or64(Atomic_uint64 *var, // IN
 
2039
            uint64 val)         // IN
 
2040
{
 
2041
#if defined(__x86_64__)
 
2042
#if defined(__GNUC__)
 
2043
   /* Checked against the AMD manual and GCC --hpreg */
 
2044
   __asm__ __volatile__(
 
2045
      "lock; orq %1, %0"
 
2046
      : "+m" (var->value)
 
2047
      : "ri" (val)
 
2048
      : "cc"
 
2049
   );
 
2050
   AtomicEpilogue();
 
2051
#elif defined _MSC_VER
 
2052
   _InterlockedOr64((__int64 *)&var->value, (__int64)val);
 
2053
#else
 
2054
#error No compiler defined for Atomic_Or64
 
2055
#endif
 
2056
#else // __x86_64__
 
2057
   uint64 oldVal;
 
2058
   uint64 newVal;
 
2059
   do {
 
2060
      oldVal = var->value;
 
2061
      newVal = oldVal | val;
 
2062
   } while (!Atomic_CMPXCHG64(var, &oldVal, &newVal));
 
2063
#endif
 
2064
}
 
2065
 
 
2066
 
 
2067
/*
 
2068
 *-----------------------------------------------------------------------------
 
2069
 *
 
2070
 * Atomic_And64 --
 
2071
 *
 
2072
 *      Atomic read, bitwise AND with a 64-bit value, write.
 
2073
 *
 
2074
 * Results:
 
2075
 *      None
 
2076
 *
 
2077
 * Side effects:
 
2078
 *      None
 
2079
 *
 
2080
 *-----------------------------------------------------------------------------
 
2081
 */
 
2082
 
 
2083
static INLINE void
 
2084
Atomic_And64(Atomic_uint64 *var, // IN
 
2085
             uint64 val)         // IN
 
2086
{
 
2087
#if defined(__x86_64__)
 
2088
#if defined(__GNUC__)
 
2089
   /* Checked against the AMD manual and GCC --hpreg */
 
2090
   __asm__ __volatile__(
 
2091
      "lock; andq %1, %0"
 
2092
      : "+m" (var->value)
 
2093
      : "ri" (val)
 
2094
      : "cc"
 
2095
   );
 
2096
   AtomicEpilogue();
 
2097
#elif defined _MSC_VER
 
2098
   _InterlockedAnd64((__int64 *)&var->value, (__int64)val);
 
2099
#else
 
2100
#error No compiler defined for Atomic_And64
 
2101
#endif
 
2102
#else // __x86_64__
 
2103
   uint64 oldVal;
 
2104
   uint64 newVal;
 
2105
   do {
 
2106
      oldVal = var->value;
 
2107
      newVal = oldVal & val;
 
2108
   } while (!Atomic_CMPXCHG64(var, &oldVal, &newVal));
 
2109
#endif
 
2110
}
 
2111
 
2098
2112
#endif // __arm__
2099
2113
 
2100
2114