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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 76fca31 was a2a5529, checked in by Jakub Vana <jakub.vana@…>, 17 years ago

Support for serial port console on IA64 as a compensation for keyboard - based on SPARC ns16550 driver

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