All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
cpu.h
Go to the documentation of this file.
1 /*
2  * OpenVirtualization:
3  * For additional details and support contact [email protected].
4  * Additional documentation can be found at www.openvirtualization.org
5  *
6  * Copyright (C) 2011 SierraWare
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  *
22  * Header for cpu info implementation
23  */
24 
25 #ifndef __CPU_ARCH__CPU_H__
26 #define __CPU_ARCH__CPU_H__
27 
28 #include <sw_types.h>
29 
30 #define CACHELINE_SIZE 32
31 
32 
33 #define __asmeq(x, y) ".ifnc " x "," y " ; .err ; .endif\n\t"
34 
35 
36 #define SCTLR_M 0x00000001 /* MMU bit */
37 #define SCTLR_C (1 << 2) /* Dcache enable */
38 #define SCTLR_I (1 << 12) /* Icache enable */
39 #define SCTLR_Z (1 << 11) /* Branch prediction enable */
40 
41 #define isb() __asm__ __volatile__("ISB")
42 #define dmb() __asm__ __volatile__("DMB")
43 #define dsb() __asm__ __volatile__("DSB")
44 
52 #define nop() __asm__ __volatile__("mov\tr0,r0\t@ nop\n\t");
53 
57 #define get_mpid() ({ u32 rval; asm volatile(\
58  " mrc p15, 0, %0, c0, c0, 5\n\t" \
59  : "=r" (rval) : : "memory", "cc"); rval;})
60 
63 #define read_sctlr() ({ u32 rval; asm volatile(\
64  " mrc p15, 0, %0, c1, c0, 0\n\t" \
65  : "=r" (rval) : : "memory", "cc"); rval;})
66 
70 #define write_sctlr(val) ({ asm volatile(\
71  " mcr p15, 0, %0, c1, c0, 0\n\t" \
72  " isb \n\t" \
73  :: "r" ((val)) : "memory", "cc");})
74 
78 #define read_dfsr() ({ u32 rval; asm volatile(\
79  " mrc p15, 0, %0, c5, c0, 0\n\t" \
80  : "=r" (rval) : : "memory", "cc"); rval;})
81 
85 #define read_dfar() ({ u32 rval; asm volatile(\
86  " mrc p15, 0, %0, c6, c0, 0\n\t" \
87  : "=r" (rval) : : "memory", "cc"); rval;})
88 
92 #define read_ifsr() ({ u32 rval; asm volatile(\
93  " mrc p15, 0, %0, c5, c0, 1\n\t" \
94  : "=r" (rval) : : "memory", "cc"); rval;})
95 
99 #define read_ifar() ({ u32 rval; asm volatile(\
100  " mrc p15, 0, %0, c6, c0, 2\n\t" \
101  : "=r" (rval) : : "memory", "cc"); rval;})
102 
106 #define read_vbar() ({ u32 rval; asm volatile(\
107  " mrc p15, 0, %0, c12, c0, 0\n\t" \
108  : "=r" (rval) : : "memory", "cc"); rval;})
109 
113 #define clear_icache() ({ asm volatile(\
114  " mcr p15, 0, r0, c7, c5, 0\n\t" \
115  ::: "memory", "cc");})
116 
120 #define inv_branch_predict() ({ asm volatile(\
121  " mcr p15, 0, r0, c7, c5, 6\n\t" \
122  ::: "memory", "cc");})
123 
127 #define get_ttbcr() ({ u32 rval; asm volatile(\
128  " mrc p15, 0, %0, c2, c0, 0\n\t" \
129  : "=r" (rval) : : "memory", "cc"); rval;})
130 
134 #define set_ttbcr(val) ({ asm volatile(\
135  " mcr p15, 0, %0, c2, c0, 0\n\t" \
136  :: "r" ((val)) : "memory", "cc");})
137 
141 #define read_domain() ({ u32 rval; asm volatile(\
142  " mrc p15, 0, %0, c3, c0, 0\n\t" \
143  : "=r" (rval) : : "memory", "cc"); rval;})
144 
148 #define write_domain(val) ({ asm volatile(\
149  " mcr p15, 0, %0, c3, c0, 0\n\t" \
150  :: "r" ((val)) : "memory", "cc");})
151 
155 #define read_ttbr0() ({ u32 rval; asm volatile(\
156  " mrc p15, 0, %0, c2, c0, 0\n\t" \
157  : "=r" (rval) : : "memory", "cc"); rval;})
158 
162 #define write_ttbr0(val) asm volatile(\
163  " mcr p15, 0, %0, c2, c0, 0\n\t" \
164  :: "r" ((val)) : "memory", "cc")
165 
169 #define read_ttbr1() ({ u32 rval; asm volatile(\
170  " mrc p15, 0, %0, c2, c0, 1\n\t" \
171  : "=r" (rval) : : "memory", "cc"); rval;})
172 
176 #define write_ttbr1(val) asm volatile(\
177  " mcr p15, 0, %0, c2, c0, 1\n\t" \
178  :: "r" ((val)) : "memory", "cc")
179 
180 
185 #define read_thread_id() ({u32 rval; asm volatile(\
186  "mrc p15, 0, %0, c13, c0, 4\n\t" \
187  : "=r" (rval) : : "memory", "cc"); rval;})
188 
193 #define write_thread_id(val) asm volatile(\
194  "mcr p15, 0, %0, c13, c0, 4\n\t" \
195  :: "r" ((val)) : "memory" , "cc")
196 
201 #define infinite_idle_loop() \
202  { \
203  while (TRUE) \
204  { \
205  __asm__ __volatile__ ("WFI"); \
206  } \
207  }
208 
209 
213 void icache_enable(void);
214 
218 void icache_disable(void);
219 
223 void dcache_enable(void);
224 
228 void dcache_disable(void);
229 
233 void enable_l1_cache(void);
234 
238 void disable_l1_cache(void);
239 
246 
252 void cpu_irq_restore(irq_flags_t flags);
253 
257 void cpu_wait_for_irq(void);
261 void clear_data_cache(void);
262 
268 u32 get_cpu_id(void);
269 
273 void enable_branch_prediction(void);
274 
278 void arm_irq_enable(void);
279 
283 void arm_irq_disable(void);
284 
288 void emulate_timer_irq(void);
289 
290 
296 void emulate_swi_handler(int swi_id);
297 
301 void data_memory_barrier(void);
302 
306 void data_sync_barrier(void);
307 
311 void instruction_sync_barrier(void);
312 
316 void start_secondary_core(void);
317 
318 #endif