source: mainline/kernel/arch/ia64/include/asm.h@ 52e020b

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 52e020b was 314f3a3c, checked in by Jakub Jermar <jakub@…>, 14 years ago

Make sure mf.a is issued after each PIO.

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