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

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

Introduce ioport8_t, ioport16_t and ioport32_t. These types are to be used with
pio_read_n() and pio_write_n() functions. This breaks everything.

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