source: mainline/kernel/arch/sparc64/include/barrier.h@ 2277e03

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 2277e03 was c0699467, checked in by Martin Decky <martin@…>, 14 years ago

do not provide general access to kernel headers from uspace, only allow specific headers to be accessed or shared
externalize headers which serve as kernel/uspace API/ABI into a special tree

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2 * Copyright (c) 2005 Jakub Jermar
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
29/** @addtogroup sparc64
30 * @{
31 */
32/** @file
33 */
34
35#ifndef KERN_sparc64_BARRIER_H_
36#define KERN_sparc64_BARRIER_H_
37
38#include <trace.h>
39
40/*
41 * Our critical section barriers are prepared for the weakest RMO memory model.
42 */
43#define CS_ENTER_BARRIER() \
44 asm volatile ( \
45 "membar #LoadLoad | #LoadStore\n" \
46 ::: "memory" \
47 )
48
49#define CS_LEAVE_BARRIER() \
50 asm volatile ( \
51 "membar #StoreStore\n" \
52 "membar #LoadStore\n" \
53 ::: "memory" \
54 )
55
56#define memory_barrier() \
57 asm volatile ( \
58 "membar #LoadLoad | #StoreStore\n" \
59 ::: "memory" \
60 )
61
62#define read_barrier() \
63 asm volatile ( \
64 "membar #LoadLoad\n" \
65 ::: "memory" \
66 )
67
68#define write_barrier() \
69 asm volatile ( \
70 "membar #StoreStore\n" \
71 ::: "memory" \
72 )
73
74#define flush(a) \
75 asm volatile ( \
76 "flush %[reg]\n" \
77 :: [reg] "r" ((a)) \
78 : "memory" \
79 )
80
81/** Flush Instruction pipeline. */
82NO_TRACE static inline void flush_pipeline(void)
83{
84 uint64_t pc;
85
86 /*
87 * The FLUSH instruction takes address parameter.
88 * As such, it may trap if the address is not found in DTLB.
89 *
90 * The entire kernel text is mapped by a locked ITLB and
91 * DTLB entries. Therefore, when this function is called,
92 * the %pc register will always be in the range mapped by
93 * DTLB.
94 *
95 */
96
97 asm volatile (
98 "rd %%pc, %[pc]\n"
99 "flush %[pc]\n"
100 : [pc] "=&r" (pc)
101 );
102}
103
104/** Memory Barrier instruction. */
105NO_TRACE static inline void membar(void)
106{
107 asm volatile (
108 "membar #Sync\n"
109 );
110}
111
112#if defined (US)
113
114#define FLUSH_INVAL_MIN 4
115
116#define smc_coherence(a) \
117 do { \
118 write_barrier(); \
119 flush((a)); \
120 } while (0)
121
122#define smc_coherence_block(a, l) \
123 do { \
124 unsigned long i; \
125 write_barrier(); \
126 \
127 for (i = 0; i < (l); i += FLUSH_INVAL_MIN) \
128 flush((void *)(a) + i); \
129 } while (0)
130
131#elif defined (US3)
132
133#define smc_coherence(a) \
134 do { \
135 write_barrier(); \
136 flush_pipeline(); \
137 } while (0)
138
139#define smc_coherence_block(a, l) \
140 do { \
141 write_barrier(); \
142 flush_pipeline(); \
143 } while (0)
144
145#endif /* defined(US3) */
146
147#endif
148
149/** @}
150 */
Note: See TracBrowser for help on using the repository browser.