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

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

Get rid of kernel static non-identity mappings on ia64.

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