source: mainline/kernel/arch/ia64/include/arch/asm.h@ 8addb24a

ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 8addb24a was 8addb24a, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 3 years ago

Turn spin look hint into a function

  • Property mode set to 100644
File size: 8.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 kernel_ia64
30 * @{
31 */
32/** @file
33 */
34
35#ifndef KERN_ia64_ASM_H_
36#define KERN_ia64_ASM_H_
37
38#include <config.h>
39#include <typedefs.h>
40#include <arch/register.h>
41#include <arch/legacyio.h>
42#include <trace.h>
43
44#define IO_SPACE_BOUNDARY ((void *) (64 * 1024))
45
46_NO_TRACE static inline void cpu_spin_hint(void)
47{
48}
49
50/** Map the I/O port address to a legacy I/O address. */
51_NO_TRACE static inline uintptr_t p2a(volatile void *p)
52{
53 uintptr_t prt = (uintptr_t) p;
54
55 return legacyio_virt_base + (((prt >> 2) << 12) | (prt & 0xfff));
56}
57
58_NO_TRACE static inline void pio_write_8(ioport8_t *port, uint8_t v)
59{
60 if (port < (ioport8_t *) IO_SPACE_BOUNDARY)
61 *((ioport8_t *) p2a(port)) = v;
62 else
63 *port = v;
64
65 asm volatile (
66 "mf\n"
67 "mf.a\n"
68 ::: "memory"
69 );
70}
71
72_NO_TRACE static inline void pio_write_16(ioport16_t *port, uint16_t v)
73{
74 if (port < (ioport16_t *) IO_SPACE_BOUNDARY)
75 *((ioport16_t *) p2a(port)) = v;
76 else
77 *port = v;
78
79 asm volatile (
80 "mf\n"
81 "mf.a\n"
82 ::: "memory"
83 );
84}
85
86_NO_TRACE static inline void pio_write_32(ioport32_t *port, uint32_t v)
87{
88 if (port < (ioport32_t *) IO_SPACE_BOUNDARY)
89 *((ioport32_t *) p2a(port)) = v;
90 else
91 *port = v;
92
93 asm volatile (
94 "mf\n"
95 "mf.a\n"
96 ::: "memory"
97 );
98}
99
100_NO_TRACE static inline uint8_t pio_read_8(ioport8_t *port)
101{
102 uint8_t v;
103
104 asm volatile (
105 "mf\n"
106 ::: "memory"
107 );
108
109 if (port < (ioport8_t *) IO_SPACE_BOUNDARY)
110 v = *((ioport8_t *) p2a(port));
111 else
112 v = *port;
113
114 asm volatile (
115 "mf.a\n"
116 ::: "memory"
117 );
118
119 return v;
120}
121
122_NO_TRACE static inline uint16_t pio_read_16(ioport16_t *port)
123{
124 uint16_t v;
125
126 asm volatile (
127 "mf\n"
128 ::: "memory"
129 );
130
131 if (port < (ioport16_t *) IO_SPACE_BOUNDARY)
132 v = *((ioport16_t *) p2a(port));
133 else
134 v = *port;
135
136 asm volatile (
137 "mf.a\n"
138 ::: "memory"
139 );
140
141 return v;
142}
143
144_NO_TRACE static inline uint32_t pio_read_32(ioport32_t *port)
145{
146 uint32_t v;
147
148 asm volatile (
149 "mf\n"
150 ::: "memory"
151 );
152
153 if (port < (ioport32_t *) IO_SPACE_BOUNDARY)
154 v = *((ioport32_t *) p2a(port));
155 else
156 v = *port;
157
158 asm volatile (
159 "mf.a\n"
160 ::: "memory"
161 );
162
163 return v;
164}
165
166/** Return Processor State Register.
167 *
168 * @return PSR.
169 *
170 */
171_NO_TRACE static inline uint64_t psr_read(void)
172{
173 uint64_t v;
174
175 asm volatile (
176 "mov %[value] = psr\n"
177 : [value] "=r" (v)
178 );
179
180 return v;
181}
182
183/** Read IVA (Interruption Vector Address).
184 *
185 * @return Return location of interruption vector table.
186 *
187 */
188_NO_TRACE static inline uint64_t iva_read(void)
189{
190 uint64_t v;
191
192 asm volatile (
193 "mov %[value] = cr.iva\n"
194 : [value] "=r" (v)
195 );
196
197 return v;
198}
199
200/** Write IVA (Interruption Vector Address) register.
201 *
202 * @param v New location of interruption vector table.
203 *
204 */
205_NO_TRACE static inline void iva_write(uint64_t v)
206{
207 asm volatile (
208 "mov cr.iva = %[value]\n"
209 :: [value] "r" (v)
210 );
211}
212
213/** Read IVR (External Interrupt Vector Register).
214 *
215 * @return Highest priority, pending, unmasked external
216 * interrupt vector.
217 *
218 */
219_NO_TRACE static inline uint64_t ivr_read(void)
220{
221 uint64_t v;
222
223 asm volatile (
224 "mov %[value] = cr.ivr\n"
225 : [value] "=r" (v)
226 );
227
228 return v;
229}
230
231_NO_TRACE static inline uint64_t cr64_read(void)
232{
233 uint64_t v;
234
235 asm volatile (
236 "mov %[value] = cr64\n"
237 : [value] "=r" (v)
238 );
239
240 return v;
241}
242
243/** Write ITC (Interval Timer Counter) register.
244 *
245 * @param v New counter value.
246 *
247 */
248_NO_TRACE static inline void itc_write(uint64_t v)
249{
250 asm volatile (
251 "mov ar.itc = %[value]\n"
252 :: [value] "r" (v)
253 );
254}
255
256/** Read ITC (Interval Timer Counter) register.
257 *
258 * @return Current counter value.
259 *
260 */
261_NO_TRACE static inline uint64_t itc_read(void)
262{
263 uint64_t v;
264
265 asm volatile (
266 "mov %[value] = ar.itc\n"
267 : [value] "=r" (v)
268 );
269
270 return v;
271}
272
273/** Write ITM (Interval Timer Match) register.
274 *
275 * @param v New match value.
276 *
277 */
278_NO_TRACE static inline void itm_write(uint64_t v)
279{
280 asm volatile (
281 "mov cr.itm = %[value]\n"
282 :: [value] "r" (v)
283 );
284}
285
286/** Read ITM (Interval Timer Match) register.
287 *
288 * @return Match value.
289 *
290 */
291_NO_TRACE static inline uint64_t itm_read(void)
292{
293 uint64_t v;
294
295 asm volatile (
296 "mov %[value] = cr.itm\n"
297 : [value] "=r" (v)
298 );
299
300 return v;
301}
302
303/** Read ITV (Interval Timer Vector) register.
304 *
305 * @return Current vector and mask bit.
306 *
307 */
308_NO_TRACE static inline uint64_t itv_read(void)
309{
310 uint64_t v;
311
312 asm volatile (
313 "mov %[value] = cr.itv\n"
314 : [value] "=r" (v)
315 );
316
317 return v;
318}
319
320/** Write ITV (Interval Timer Vector) register.
321 *
322 * @param v New vector and mask bit.
323 *
324 */
325_NO_TRACE static inline void itv_write(uint64_t v)
326{
327 asm volatile (
328 "mov cr.itv = %[value]\n"
329 :: [value] "r" (v)
330 );
331}
332
333/** Write EOI (End Of Interrupt) register.
334 *
335 * @param v This value is ignored.
336 *
337 */
338_NO_TRACE static inline void eoi_write(uint64_t v)
339{
340 asm volatile (
341 "mov cr.eoi = %[value]\n"
342 :: [value] "r" (v)
343 );
344}
345
346/** Read TPR (Task Priority Register).
347 *
348 * @return Current value of TPR.
349 *
350 */
351_NO_TRACE static inline uint64_t tpr_read(void)
352{
353 uint64_t v;
354
355 asm volatile (
356 "mov %[value] = cr.tpr\n"
357 : [value] "=r" (v)
358 );
359
360 return v;
361}
362
363/** Write TPR (Task Priority Register).
364 *
365 * @param v New value of TPR.
366 *
367 */
368_NO_TRACE static inline void tpr_write(uint64_t v)
369{
370 asm volatile (
371 "mov cr.tpr = %[value]\n"
372 :: [value] "r" (v)
373 );
374}
375
376/** Disable interrupts.
377 *
378 * Disable interrupts and return previous
379 * value of PSR.
380 *
381 * @return Old interrupt priority level.
382 *
383 */
384_NO_TRACE static ipl_t interrupts_disable(void)
385{
386 uint64_t v;
387
388 asm volatile (
389 "mov %[value] = psr\n"
390 "rsm %[mask]\n"
391 : [value] "=r" (v)
392 : [mask] "i" (PSR_I_MASK)
393 );
394
395 return (ipl_t) v;
396}
397
398/** Enable interrupts.
399 *
400 * Enable interrupts and return previous
401 * value of PSR.
402 *
403 * @return Old interrupt priority level.
404 *
405 */
406_NO_TRACE static ipl_t interrupts_enable(void)
407{
408 uint64_t v;
409
410 asm volatile (
411 "mov %[value] = psr\n"
412 "ssm %[mask]\n"
413 ";;\n"
414 "srlz.d\n"
415 : [value] "=r" (v)
416 : [mask] "i" (PSR_I_MASK)
417 );
418
419 return (ipl_t) v;
420}
421
422/** Restore interrupt priority level.
423 *
424 * Restore PSR.
425 *
426 * @param ipl Saved interrupt priority level.
427 *
428 */
429_NO_TRACE static inline void interrupts_restore(ipl_t ipl)
430{
431 if (ipl & PSR_I_MASK)
432 (void) interrupts_enable();
433 else
434 (void) interrupts_disable();
435}
436
437/** Return interrupt priority level.
438 *
439 * @return PSR.
440 *
441 */
442_NO_TRACE static inline ipl_t interrupts_read(void)
443{
444 return (ipl_t) psr_read();
445}
446
447/** Check interrupts state.
448 *
449 * @return True if interrupts are disabled.
450 *
451 */
452_NO_TRACE static inline bool interrupts_disabled(void)
453{
454 return !(psr_read() & PSR_I_MASK);
455}
456
457/** Disable protection key checking. */
458_NO_TRACE static inline void pk_disable(void)
459{
460 asm volatile (
461 "rsm %[mask]\n"
462 ";;\n"
463 "srlz.d\n"
464 :: [mask] "i" (PSR_PK_MASK)
465 );
466}
467
468extern void cpu_halt(void) __attribute__((noreturn));
469extern void cpu_sleep(void);
470extern void asm_delay_loop(uint32_t t);
471
472extern void switch_to_userspace(uintptr_t, uintptr_t, uintptr_t, uintptr_t,
473 uint64_t, uint64_t);
474
475#endif
476
477/** @}
478 */
Note: See TracBrowser for help on using the repository browser.