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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a2f42e5 was 02ee69da, checked in by Adam Hraska <adam.hraska+hos@…>, 13 years ago

Added missing include from sparc64/barrier.h. Fixes build on sparc64.

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