source: mainline/kernel/arch/ia64/include/asm.h@ 1924bd43

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

Make ia64 PIO functions usable with memory-mapped registers.

  • Property mode set to 100644
File size: 8.9 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>
[d99c1d2]40#include <typedefs.h>
[0259524]41#include <arch/register.h>
[7a0359b]42#include <trace.h>
[361635c]43
[5bda2f3e]44#define IA64_IOSPACE_ADDRESS 0xE001000000000000ULL
[2a06e2f]45
[86a34d3e]46#define IO_SPACE_BOUNDARY ((void *) (64 * 1024))
47
[7a0359b]48NO_TRACE static inline void pio_write_8(ioport8_t *port, uint8_t v)
[2a06e2f]49{
[86a34d3e]50 if (port < (ioport8_t *) IO_SPACE_BOUNDARY) {
51 uintptr_t prt = (uintptr_t) port;
[5bda2f3e]52
[86a34d3e]53 *((ioport8_t *) (IA64_IOSPACE_ADDRESS +
54 ((prt & 0xfff) | ((prt >> 2) << 12)))) = v;
55 } else {
56 *port = v;
57 }
[5bda2f3e]58
59 asm volatile (
60 "mf\n"
61 ::: "memory"
62 );
[2a06e2f]63}
64
[7a0359b]65NO_TRACE static inline void pio_write_16(ioport16_t *port, uint16_t v)
[756f475]66{
[86a34d3e]67 if (port < (ioport16_t *) IO_SPACE_BOUNDARY) {
68 uintptr_t prt = (uintptr_t) port;
[5bda2f3e]69
[86a34d3e]70 *((ioport16_t *) (IA64_IOSPACE_ADDRESS +
71 ((prt & 0xfff) | ((prt >> 2) << 12)))) = v;
72 } else {
73 *port = v;
74 }
[5bda2f3e]75
76 asm volatile (
77 "mf\n"
78 ::: "memory"
79 );
[756f475]80}
81
[7a0359b]82NO_TRACE static inline void pio_write_32(ioport32_t *port, uint32_t v)
[756f475]83{
[86a34d3e]84 if (port < (ioport32_t *) IO_SPACE_BOUNDARY) {
85 uintptr_t prt = (uintptr_t) port;
[5bda2f3e]86
[86a34d3e]87 *((ioport32_t *) (IA64_IOSPACE_ADDRESS +
88 ((prt & 0xfff) | ((prt >> 2) << 12)))) = v;
89 } else {
90 *port = v;
91 }
[5bda2f3e]92
93 asm volatile (
94 "mf\n"
95 ::: "memory"
96 );
[756f475]97}
98
[7a0359b]99NO_TRACE static inline uint8_t pio_read_8(ioport8_t *port)
[2a06e2f]100{
[86a34d3e]101 uint8_t v;
102
[5bda2f3e]103 asm volatile (
104 "mf\n"
105 ::: "memory"
106 );
[86a34d3e]107
108 if (port < (ioport8_t *) IO_SPACE_BOUNDARY) {
109 uintptr_t prt = (uintptr_t) port;
110
111 v = *((ioport8_t *) (IA64_IOSPACE_ADDRESS +
112 ((prt & 0xfff) | ((prt >> 2) << 12))));
113 } else {
114 v = *port;
115 }
[5bda2f3e]116
[86a34d3e]117 return v;
[756f475]118}
119
[7a0359b]120NO_TRACE static inline uint16_t pio_read_16(ioport16_t *port)
[756f475]121{
[86a34d3e]122 uint16_t v;
123
[5bda2f3e]124 asm volatile (
125 "mf\n"
126 ::: "memory"
127 );
[86a34d3e]128
129 if (port < (ioport16_t *) IO_SPACE_BOUNDARY) {
130 uintptr_t prt = (uintptr_t) port;
131
132 v = *((ioport16_t *) (IA64_IOSPACE_ADDRESS +
133 ((prt & 0xfff) | ((prt >> 2) << 12))));
134 } else {
135 v = *port;
136 }
[5bda2f3e]137
[86a34d3e]138 return v;
[756f475]139}
140
[7a0359b]141NO_TRACE static inline uint32_t pio_read_32(ioport32_t *port)
[756f475]142{
[86a34d3e]143 uint32_t v;
[5bda2f3e]144
145 asm volatile (
146 "mf\n"
147 ::: "memory"
148 );
149
[86a34d3e]150 if (port < (ioport32_t *) IO_SPACE_BOUNDARY) {
151 uintptr_t prt = (uintptr_t) port;
152
153 v = *((ioport32_t *) (IA64_IOSPACE_ADDRESS +
154 ((prt & 0xfff) | ((prt >> 2) << 12))));
155 } else {
156 v = *port;
157 }
158
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.