[b0bf501] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2005 Jakub Jermar
|
---|
[b0bf501] | 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
[e86a849a] | 29 | /** @addtogroup ia64
|
---|
[b45c443] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
[06e1e95] | 35 | #ifndef KERN_ia64_ATOMIC_H_
|
---|
| 36 | #define KERN_ia64_ATOMIC_H_
|
---|
[b0bf501] | 37 |
|
---|
[7038f55] | 38 | static inline uint64_t test_and_set(atomic_t *val)
|
---|
| 39 | {
|
---|
[59e4864] | 40 | uint64_t v;
|
---|
| 41 |
|
---|
| 42 | asm volatile (
|
---|
[e86a849a] | 43 | "movl %[v] = 0x1;;\n"
|
---|
| 44 | "xchg8 %[v] = %[count], %[v];;\n"
|
---|
| 45 | : [v] "=r" (v),
|
---|
| 46 | [count] "+m" (val->count)
|
---|
[59e4864] | 47 | );
|
---|
| 48 |
|
---|
| 49 | return v;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
[7038f55] | 52 | static inline void atomic_lock_arch(atomic_t *val)
|
---|
| 53 | {
|
---|
| 54 | do {
|
---|
| 55 | while (val->count)
|
---|
| 56 | ;
|
---|
| 57 | } while (test_and_set(val));
|
---|
| 58 | }
|
---|
[59e4864] | 59 |
|
---|
[8b4d6cb] | 60 | static inline void atomic_inc(atomic_t *val)
|
---|
| 61 | {
|
---|
[e86a849a] | 62 | long v;
|
---|
| 63 |
|
---|
| 64 | asm volatile (
|
---|
| 65 | "fetchadd8.rel %[v] = %[count], 1\n"
|
---|
| 66 | : [v] "=r" (v),
|
---|
| 67 | [count] "+m" (val->count)
|
---|
| 68 | );
|
---|
[8b4d6cb] | 69 | }
|
---|
| 70 |
|
---|
| 71 | static inline void atomic_dec(atomic_t *val)
|
---|
| 72 | {
|
---|
[e86a849a] | 73 | long v;
|
---|
| 74 |
|
---|
| 75 | asm volatile (
|
---|
| 76 | "fetchadd8.rel %[v] = %[count], -1\n"
|
---|
| 77 | : [v] "=r" (v),
|
---|
| 78 | [count] "+m" (val->count)
|
---|
| 79 | );
|
---|
[8b4d6cb] | 80 | }
|
---|
[73a4bab] | 81 |
|
---|
[8b4d6cb] | 82 | static inline long atomic_preinc(atomic_t *val)
|
---|
| 83 | {
|
---|
[e86a849a] | 84 | long v;
|
---|
| 85 |
|
---|
| 86 | asm volatile (
|
---|
| 87 | "fetchadd8.rel %[v] = %[count], 1\n"
|
---|
| 88 | : [v] "=r" (v),
|
---|
| 89 | [count] "+m" (val->count)
|
---|
| 90 | );
|
---|
| 91 |
|
---|
| 92 | return (v + 1);
|
---|
[8b4d6cb] | 93 | }
|
---|
[73a4bab] | 94 |
|
---|
[8b4d6cb] | 95 | static inline long atomic_predec(atomic_t *val)
|
---|
| 96 | {
|
---|
[e86a849a] | 97 | long v;
|
---|
| 98 |
|
---|
| 99 | asm volatile (
|
---|
| 100 | "fetchadd8.rel %[v] = %[count], -1\n"
|
---|
| 101 | : [v] "=r" (v),
|
---|
| 102 | [count] "+m" (val->count)
|
---|
| 103 | );
|
---|
| 104 |
|
---|
| 105 | return (v - 1);
|
---|
[8b4d6cb] | 106 | }
|
---|
| 107 |
|
---|
| 108 | static inline long atomic_postinc(atomic_t *val)
|
---|
| 109 | {
|
---|
[e86a849a] | 110 | long v;
|
---|
| 111 |
|
---|
| 112 | asm volatile (
|
---|
| 113 | "fetchadd8.rel %[v] = %[count], 1\n"
|
---|
| 114 | : [v] "=r" (v),
|
---|
| 115 | [count] "+m" (val->count)
|
---|
| 116 | );
|
---|
| 117 |
|
---|
| 118 | return v;
|
---|
[8b4d6cb] | 119 | }
|
---|
| 120 |
|
---|
| 121 | static inline long atomic_postdec(atomic_t *val)
|
---|
| 122 | {
|
---|
[e86a849a] | 123 | long v;
|
---|
| 124 |
|
---|
| 125 | asm volatile (
|
---|
| 126 | "fetchadd8.rel %[v] = %[count], -1\n"
|
---|
| 127 | : [v] "=r" (v),
|
---|
| 128 | [count] "+m" (val->count)
|
---|
| 129 | );
|
---|
| 130 |
|
---|
| 131 | return v;
|
---|
[8b4d6cb] | 132 | }
|
---|
[59e07c91] | 133 |
|
---|
[b0bf501] | 134 | #endif
|
---|
[b45c443] | 135 |
|
---|
[06e1e95] | 136 | /** @}
|
---|
[b45c443] | 137 | */
|
---|