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

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

Fix typo.

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