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

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

Serialize after the RSM instruction in pk_disable().

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