VirtualBox

source: vbox/trunk/src/VBox/Additions/linux/x11include/7.1/xorg/compiler.h@ 4997

Last change on this file since 4997 was 1207, checked in by vboxsync, 18 years ago

Cleaned up EOL style and uppercase names

  • Property svn:eol-style set to native
File size: 52.7 KB
Line 
1/* $XFree86: xc/programs/Xserver/hw/xfree86/common/compiler.h,v 3.106 2004/02/02 03:55:28 dawes Exp $ */
2/*
3 * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
4 *
5 * Permission to use, copy, modify, distribute, and sell this software and its
6 * documentation for any purpose is hereby granted without fee, provided that
7 * the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the name of Thomas Roell not be used in
10 * advertising or publicity pertaining to distribution of the software without
11 * specific, written prior permission. Thomas Roell makes no representations
12 * about the suitability of this software for any purpose. It is provided
13 * "as is" without express or implied warranty.
14 *
15 * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17 * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
19 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21 * PERFORMANCE OF THIS SOFTWARE.
22 *
23 */
24/*
25 * Copyright (c) 1994-2003 by The XFree86 Project, Inc.
26 *
27 * Permission is hereby granted, free of charge, to any person obtaining a
28 * copy of this software and associated documentation files (the "Software"),
29 * to deal in the Software without restriction, including without limitation
30 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
31 * and/or sell copies of the Software, and to permit persons to whom the
32 * Software is furnished to do so, subject to the following conditions:
33 *
34 * The above copyright notice and this permission notice shall be included in
35 * all copies or substantial portions of the Software.
36 *
37 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
40 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
41 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
42 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
43 * OTHER DEALINGS IN THE SOFTWARE.
44 *
45 * Except as contained in this notice, the name of the copyright holder(s)
46 * and author(s) shall not be used in advertising or otherwise to promote
47 * the sale, use or other dealings in this Software without prior written
48 * authorization from the copyright holder(s) and author(s).
49 */
50
51/* $XConsortium: compiler.h /main/16 1996/10/25 15:38:34 kaleb $ */
52
53#ifndef _COMPILER_H
54
55# define _COMPILER_H
56
57#if defined(__SUNPRO_C)
58# define DO_PROTOTYPES
59#endif
60
61/* Allow drivers to use the GCC-supported __inline__ and/or __inline. */
62# ifndef __inline__
63# if defined(__GNUC__)
64 /* gcc has __inline__ */
65# elif defined(__HIGHC__)
66# define __inline__ _Inline
67# else
68# define __inline__ /**/
69# endif
70# endif /* __inline__ */
71# ifndef __inline
72# if defined(__GNUC__)
73 /* gcc has __inline */
74# elif defined(__HIGHC__)
75# define __inline _Inline
76# else
77# define __inline /**/
78# endif
79# endif /* __inline */
80
81# if defined(IODEBUG) && defined(__GNUC__)
82# define outb RealOutb
83# define outw RealOutw
84# define outl RealOutl
85# define inb RealInb
86# define inw RealInw
87# define inl RealInl
88# endif
89
90# if defined(QNX4) /* Do this for now to keep Watcom happy */
91# define outb outp
92# define outw outpw
93# define outl outpd
94# define inb inp
95# define inw inpw
96# define inl inpd
97
98/* Define the ffs function for inlining */
99extern int ffs(unsigned long);
100# pragma aux ffs_ = \
101 "bsf edx, eax" \
102 "jnz bits_set" \
103 "xor eax, eax" \
104 "jmp exit1" \
105 "bits_set:" \
106 "mov eax, edx" \
107 "inc eax" \
108 "exit1:" \
109 __parm [eax] \
110 __modify [eax edx] \
111 __value [eax] \
112 ;
113# endif
114
115# if defined(__SUNPRO_C)
116# define DO_PROTOTYPES
117# endif
118
119# if defined(NO_INLINE) || defined(DO_PROTOTYPES)
120
121# if !defined(__arm__)
122# if !defined(__sparc__) && !defined(__arm32__) \
123 && !(defined(__alpha__) && defined(linux)) \
124 && !(defined(__ia64__) && defined(linux)) \
125
126extern void outb(unsigned short, unsigned char);
127extern void outw(unsigned short, unsigned short);
128extern void outl(unsigned short, unsigned int);
129extern unsigned int inb(unsigned short);
130extern unsigned int inw(unsigned short);
131extern unsigned int inl(unsigned short);
132
133# else /* __sparc__, __arm32__, __alpha__*/
134
135extern void outb(unsigned long, unsigned char);
136extern void outw(unsigned long, unsigned short);
137extern void outl(unsigned long, unsigned int);
138extern unsigned int inb(unsigned long);
139extern unsigned int inw(unsigned long);
140extern unsigned int inl(unsigned long);
141
142# endif /* __sparc__, __arm32__, __alpha__ */
143# endif /* __arm__ */
144
145extern unsigned long ldq_u(unsigned long *);
146extern unsigned long ldl_u(unsigned int *);
147extern unsigned long ldw_u(unsigned short *);
148extern void stq_u(unsigned long, unsigned long *);
149extern void stl_u(unsigned long, unsigned int *);
150extern void stw_u(unsigned long, unsigned short *);
151extern void mem_barrier(void);
152extern void write_mem_barrier(void);
153extern void stl_brx(unsigned long, volatile unsigned char *, int);
154extern void stw_brx(unsigned short, volatile unsigned char *, int);
155extern unsigned long ldl_brx(volatile unsigned char *, int);
156extern unsigned short ldw_brx(volatile unsigned char *, int);
157
158# endif
159
160# ifndef NO_INLINE
161# ifdef __GNUC__
162# if (defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)) && (defined(__alpha__))
163
164# ifdef linux
165/* for Linux on Alpha, we use the LIBC _inx/_outx routines */
166/* note that the appropriate setup via "ioperm" needs to be done */
167/* *before* any inx/outx is done. */
168
169extern void (*_alpha_outb)(char val, unsigned long port);
170static __inline__ void
171outb(unsigned long port, unsigned char val)
172{
173 _alpha_outb(val, port);
174}
175
176extern void (*_alpha_outw)(short val, unsigned long port);
177static __inline__ void
178outw(unsigned long port, unsigned short val)
179{
180 _alpha_outw(val, port);
181}
182
183extern void (*_alpha_outl)(int val, unsigned long port);
184static __inline__ void
185outl(unsigned long port, unsigned int val)
186{
187 _alpha_outl(val, port);
188}
189
190extern unsigned int (*_alpha_inb)(unsigned long port);
191static __inline__ unsigned int
192inb(unsigned long port)
193{
194 return _alpha_inb(port);
195}
196
197extern unsigned int (*_alpha_inw)(unsigned long port);
198static __inline__ unsigned int
199inw(unsigned long port)
200{
201 return _alpha_inw(port);
202}
203
204extern unsigned int (*_alpha_inl)(unsigned long port);
205static __inline__ unsigned int
206inl(unsigned long port)
207{
208 return _alpha_inl(port);
209}
210
211# endif /* linux */
212
213# if (defined(__FreeBSD__) || defined(__OpenBSD__)) \
214 && !defined(DO_PROTOTYPES)
215
216/* for FreeBSD and OpenBSD on Alpha, we use the libio (resp. libalpha) */
217/* inx/outx routines */
218/* note that the appropriate setup via "ioperm" needs to be done */
219/* *before* any inx/outx is done. */
220
221extern void outb(unsigned int port, unsigned char val);
222extern void outw(unsigned int port, unsigned short val);
223extern void outl(unsigned int port, unsigned int val);
224extern unsigned char inb(unsigned int port);
225extern unsigned short inw(unsigned int port);
226extern unsigned int inl(unsigned int port);
227
228# endif /* (__FreeBSD__ || __OpenBSD__ ) && !DO_PROTOTYPES */
229
230
231#if defined(__NetBSD__)
232#include <machine/pio.h>
233#endif /* __NetBSD__ */
234
235/*
236 * inline functions to do unaligned accesses
237 * from linux/include/asm-alpha/unaligned.h
238 */
239
240/*
241 * EGCS 1.1 knows about arbitrary unaligned loads. Define some
242 * packed structures to talk about such things with.
243 */
244
245struct __una_u64 { unsigned long x __attribute__((packed)); };
246struct __una_u32 { unsigned int x __attribute__((packed)); };
247struct __una_u16 { unsigned short x __attribute__((packed)); };
248
249/*
250 * Elemental unaligned loads
251 */
252/* let's try making these things static */
253
254static __inline__ unsigned long ldq_u(unsigned long * r11)
255{
256# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
257 const struct __una_u64 *ptr = (const struct __una_u64 *) r11;
258 return ptr->x;
259# else
260 unsigned long r1,r2;
261 __asm__("ldq_u %0,%3\n\t"
262 "ldq_u %1,%4\n\t"
263 "extql %0,%2,%0\n\t"
264 "extqh %1,%2,%1"
265 :"=&r" (r1), "=&r" (r2)
266 :"r" (r11),
267 "m" (*r11),
268 "m" (*(const unsigned long *)(7+(char *) r11)));
269 return r1 | r2;
270# endif
271}
272
273static __inline__ unsigned long ldl_u(unsigned int * r11)
274{
275# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
276 const struct __una_u32 *ptr = (const struct __una_u32 *) r11;
277 return ptr->x;
278# else
279 unsigned long r1,r2;
280 __asm__("ldq_u %0,%3\n\t"
281 "ldq_u %1,%4\n\t"
282 "extll %0,%2,%0\n\t"
283 "extlh %1,%2,%1"
284 :"=&r" (r1), "=&r" (r2)
285 :"r" (r11),
286 "m" (*r11),
287 "m" (*(const unsigned long *)(3+(char *) r11)));
288 return r1 | r2;
289# endif
290}
291
292static __inline__ unsigned long ldw_u(unsigned short * r11)
293{
294# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
295 const struct __una_u16 *ptr = (const struct __una_u16 *) r11;
296 return ptr->x;
297# else
298 unsigned long r1,r2;
299 __asm__("ldq_u %0,%3\n\t"
300 "ldq_u %1,%4\n\t"
301 "extwl %0,%2,%0\n\t"
302 "extwh %1,%2,%1"
303 :"=&r" (r1), "=&r" (r2)
304 :"r" (r11),
305 "m" (*r11),
306 "m" (*(const unsigned long *)(1+(char *) r11)));
307 return r1 | r2;
308# endif
309}
310
311/*
312 * Elemental unaligned stores
313 */
314
315static __inline__ void stq_u(unsigned long r5, unsigned long * r11)
316{
317# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
318 struct __una_u64 *ptr = (struct __una_u64 *) r11;
319 ptr->x = r5;
320# else
321 unsigned long r1,r2,r3,r4;
322
323 __asm__("ldq_u %3,%1\n\t"
324 "ldq_u %2,%0\n\t"
325 "insqh %6,%7,%5\n\t"
326 "insql %6,%7,%4\n\t"
327 "mskqh %3,%7,%3\n\t"
328 "mskql %2,%7,%2\n\t"
329 "bis %3,%5,%3\n\t"
330 "bis %2,%4,%2\n\t"
331 "stq_u %3,%1\n\t"
332 "stq_u %2,%0"
333 :"=m" (*r11),
334 "=m" (*(unsigned long *)(7+(char *) r11)),
335 "=&r" (r1), "=&r" (r2), "=&r" (r3), "=&r" (r4)
336 :"r" (r5), "r" (r11));
337# endif
338}
339
340static __inline__ void stl_u(unsigned long r5, unsigned int * r11)
341{
342# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
343 struct __una_u32 *ptr = (struct __una_u32 *) r11;
344 ptr->x = r5;
345# else
346 unsigned long r1,r2,r3,r4;
347
348 __asm__("ldq_u %3,%1\n\t"
349 "ldq_u %2,%0\n\t"
350 "inslh %6,%7,%5\n\t"
351 "insll %6,%7,%4\n\t"
352 "msklh %3,%7,%3\n\t"
353 "mskll %2,%7,%2\n\t"
354 "bis %3,%5,%3\n\t"
355 "bis %2,%4,%2\n\t"
356 "stq_u %3,%1\n\t"
357 "stq_u %2,%0"
358 :"=m" (*r11),
359 "=m" (*(unsigned long *)(3+(char *) r11)),
360 "=&r" (r1), "=&r" (r2), "=&r" (r3), "=&r" (r4)
361 :"r" (r5), "r" (r11));
362# endif
363}
364
365static __inline__ void stw_u(unsigned long r5, unsigned short * r11)
366{
367# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
368 struct __una_u16 *ptr = (struct __una_u16 *) r11;
369 ptr->x = r5;
370# else
371 unsigned long r1,r2,r3,r4;
372
373 __asm__("ldq_u %3,%1\n\t"
374 "ldq_u %2,%0\n\t"
375 "inswh %6,%7,%5\n\t"
376 "inswl %6,%7,%4\n\t"
377 "mskwh %3,%7,%3\n\t"
378 "mskwl %2,%7,%2\n\t"
379 "bis %3,%5,%3\n\t"
380 "bis %2,%4,%2\n\t"
381 "stq_u %3,%1\n\t"
382 "stq_u %2,%0"
383 :"=m" (*r11),
384 "=m" (*(unsigned long *)(1+(char *) r11)),
385 "=&r" (r1), "=&r" (r2), "=&r" (r3), "=&r" (r4)
386 :"r" (r5), "r" (r11));
387# endif
388}
389
390/* to flush the I-cache before jumping to code which just got loaded */
391# define PAL_imb 134
392# define istream_mem_barrier() \
393 __asm__ __volatile__("call_pal %0 #imb" : : "i" (PAL_imb) : "memory")
394# define mem_barrier() __asm__ __volatile__("mb" : : : "memory")
395# ifdef __ELF__
396# define write_mem_barrier() __asm__ __volatile__("wmb" : : : "memory")
397# else /* ECOFF gas 2.6 doesn't know "wmb" :-( */
398# define write_mem_barrier() mem_barrier()
399# endif
400
401
402# elif defined(linux) && defined(__ia64__)
403
404# include <inttypes.h>
405
406# include <sys/io.h>
407
408struct __una_u64 { uint64_t x __attribute__((packed)); };
409struct __una_u32 { uint32_t x __attribute__((packed)); };
410struct __una_u16 { uint16_t x __attribute__((packed)); };
411
412static __inline__ unsigned long
413__uldq (const unsigned long * r11)
414{
415 const struct __una_u64 *ptr = (const struct __una_u64 *) r11;
416 return ptr->x;
417}
418
419static __inline__ unsigned long
420__uldl (const unsigned int * r11)
421{
422 const struct __una_u32 *ptr = (const struct __una_u32 *) r11;
423 return ptr->x;
424}
425
426static __inline__ unsigned long
427__uldw (const unsigned short * r11)
428{
429 const struct __una_u16 *ptr = (const struct __una_u16 *) r11;
430 return ptr->x;
431}
432
433static __inline__ void
434__ustq (unsigned long r5, unsigned long * r11)
435{
436 struct __una_u64 *ptr = (struct __una_u64 *) r11;
437 ptr->x = r5;
438}
439
440static __inline__ void
441__ustl (unsigned long r5, unsigned int * r11)
442{
443 struct __una_u32 *ptr = (struct __una_u32 *) r11;
444 ptr->x = r5;
445}
446
447static __inline__ void
448__ustw (unsigned long r5, unsigned short * r11)
449{
450 struct __una_u16 *ptr = (struct __una_u16 *) r11;
451 ptr->x = r5;
452}
453
454# define ldq_u(p) __uldq(p)
455# define ldl_u(p) __uldl(p)
456# define ldw_u(p) __uldw(p)
457# define stq_u(v,p) __ustq(v,p)
458# define stl_u(v,p) __ustl(v,p)
459# define stw_u(v,p) __ustw(v,p)
460
461# ifndef __INTEL_COMPILER
462# define mem_barrier() __asm__ __volatile__ ("mf" ::: "memory")
463# define write_mem_barrier() __asm__ __volatile__ ("mf" ::: "memory")
464# else
465# include "ia64intrin.h"
466# define mem_barrier() __mf()
467# define write_mem_barrier() __mf()
468# endif
469
470/*
471 * This is overkill, but for different reasons depending on where it is used.
472 * This is thus general enough to be used everywhere cache flushes are needed.
473 * It doesn't handle memory access serialisation by other processors, though.
474 */
475# ifndef __INTEL_COMPILER
476# define ia64_flush_cache(Addr) \
477 __asm__ __volatile__ ( \
478 "fc.i %0;;;" \
479 "sync.i;;;" \
480 "mf;;;" \
481 "srlz.i;;;" \
482 :: "r"(Addr) : "memory")
483# else
484# define ia64_flush_cache(Addr) { \
485 __fc(Addr);\
486 __synci();\
487 __mf();\
488 __isrlz();\
489 }
490# endif
491# undef outb
492# undef outw
493# undef outl
494# undef inb
495# undef inw
496# undef inl
497extern void outb(unsigned long port, unsigned char val);
498extern void outw(unsigned long port, unsigned short val);
499extern void outl(unsigned long port, unsigned int val);
500extern unsigned int inb(unsigned long port);
501extern unsigned int inw(unsigned long port);
502extern unsigned int inl(unsigned long port);
503
504# elif defined(linux) && defined(__amd64__)
505
506# include <inttypes.h>
507
508# define ldq_u(p) (*((unsigned long *)(p)))
509# define ldl_u(p) (*((unsigned int *)(p)))
510# define ldw_u(p) (*((unsigned short *)(p)))
511# define stq_u(v,p) (*(unsigned long *)(p)) = (v)
512# define stl_u(v,p) (*(unsigned int *)(p)) = (v)
513# define stw_u(v,p) (*(unsigned short *)(p)) = (v)
514
515# define mem_barrier() \
516 __asm__ __volatile__ ("lock; addl $0,0(%%rsp)": : :"memory")
517# define write_mem_barrier() \
518 __asm__ __volatile__ ("": : :"memory")
519
520
521static __inline__ void
522outb(unsigned short port, unsigned char val)
523{
524 __asm__ __volatile__("outb %0,%1" : :"a" (val), "d" (port));
525}
526
527
528static __inline__ void
529outw(unsigned short port, unsigned short val)
530{
531 __asm__ __volatile__("outw %0,%1" : :"a" (val), "d" (port));
532}
533
534static __inline__ void
535outl(unsigned short port, unsigned int val)
536{
537 __asm__ __volatile__("outl %0,%1" : :"a" (val), "d" (port));
538}
539
540static __inline__ unsigned int
541inb(unsigned short port)
542{
543 unsigned char ret;
544 __asm__ __volatile__("inb %1,%0" :
545 "=a" (ret) :
546 "d" (port));
547 return ret;
548}
549
550static __inline__ unsigned int
551inw(unsigned short port)
552{
553 unsigned short ret;
554 __asm__ __volatile__("inw %1,%0" :
555 "=a" (ret) :
556 "d" (port));
557 return ret;
558}
559
560static __inline__ unsigned int
561inl(unsigned short port)
562{
563 unsigned int ret;
564 __asm__ __volatile__("inl %1,%0" :
565 "=a" (ret) :
566 "d" (port));
567 return ret;
568}
569
570# elif (defined(linux) || defined(Lynx) || defined(sun) || defined(__OpenBSD__) || defined(__FreeBSD__)) && defined(__sparc__)
571
572# if !defined(Lynx)
573# ifndef ASI_PL
574# define ASI_PL 0x88
575# endif
576
577# define barrier() __asm__ __volatile__(".word 0x8143e00a": : :"memory")
578
579static __inline__ void
580outb(unsigned long port, unsigned char val)
581{
582 __asm__ __volatile__("stba %0, [%1] %2"
583 : /* No outputs */
584 : "r" (val), "r" (port), "i" (ASI_PL));
585 barrier();
586}
587
588static __inline__ void
589outw(unsigned long port, unsigned short val)
590{
591 __asm__ __volatile__("stha %0, [%1] %2"
592 : /* No outputs */
593 : "r" (val), "r" (port), "i" (ASI_PL));
594 barrier();
595}
596
597static __inline__ void
598outl(unsigned long port, unsigned int val)
599{
600 __asm__ __volatile__("sta %0, [%1] %2"
601 : /* No outputs */
602 : "r" (val), "r" (port), "i" (ASI_PL));
603 barrier();
604}
605
606static __inline__ unsigned int
607inb(unsigned long port)
608{
609 unsigned int ret;
610 __asm__ __volatile__("lduba [%1] %2, %0"
611 : "=r" (ret)
612 : "r" (port), "i" (ASI_PL));
613 return ret;
614}
615
616static __inline__ unsigned int
617inw(unsigned long port)
618{
619 unsigned int ret;
620 __asm__ __volatile__("lduha [%1] %2, %0"
621 : "=r" (ret)
622 : "r" (port), "i" (ASI_PL));
623 return ret;
624}
625
626static __inline__ unsigned int
627inl(unsigned long port)
628{
629 unsigned int ret;
630 __asm__ __volatile__("lda [%1] %2, %0"
631 : "=r" (ret)
632 : "r" (port), "i" (ASI_PL));
633 return ret;
634}
635
636static __inline__ unsigned char
637xf86ReadMmio8(__volatile__ void *base, const unsigned long offset)
638{
639 unsigned long addr = ((unsigned long)base) + offset;
640 unsigned char ret;
641
642 __asm__ __volatile__("lduba [%1] %2, %0"
643 : "=r" (ret)
644 : "r" (addr), "i" (ASI_PL));
645 return ret;
646}
647
648static __inline__ unsigned short
649xf86ReadMmio16Be(__volatile__ void *base, const unsigned long offset)
650{
651 unsigned long addr = ((unsigned long)base) + offset;
652 unsigned short ret;
653
654 __asm__ __volatile__("lduh [%1], %0"
655 : "=r" (ret)
656 : "r" (addr));
657 return ret;
658}
659
660static __inline__ unsigned short
661xf86ReadMmio16Le(__volatile__ void *base, const unsigned long offset)
662{
663 unsigned long addr = ((unsigned long)base) + offset;
664 unsigned short ret;
665
666 __asm__ __volatile__("lduha [%1] %2, %0"
667 : "=r" (ret)
668 : "r" (addr), "i" (ASI_PL));
669 return ret;
670}
671
672static __inline__ unsigned int
673xf86ReadMmio32Be(__volatile__ void *base, const unsigned long offset)
674{
675 unsigned long addr = ((unsigned long)base) + offset;
676 unsigned int ret;
677
678 __asm__ __volatile__("ld [%1], %0"
679 : "=r" (ret)
680 : "r" (addr));
681 return ret;
682}
683
684static __inline__ unsigned int
685xf86ReadMmio32Le(__volatile__ void *base, const unsigned long offset)
686{
687 unsigned long addr = ((unsigned long)base) + offset;
688 unsigned int ret;
689
690 __asm__ __volatile__("lda [%1] %2, %0"
691 : "=r" (ret)
692 : "r" (addr), "i" (ASI_PL));
693 return ret;
694}
695
696static __inline__ void
697xf86WriteMmio8(__volatile__ void *base, const unsigned long offset,
698 const unsigned int val)
699{
700 unsigned long addr = ((unsigned long)base) + offset;
701
702 __asm__ __volatile__("stba %0, [%1] %2"
703 : /* No outputs */
704 : "r" (val), "r" (addr), "i" (ASI_PL));
705 barrier();
706}
707
708static __inline__ void
709xf86WriteMmio16Be(__volatile__ void *base, const unsigned long offset,
710 const unsigned int val)
711{
712 unsigned long addr = ((unsigned long)base) + offset;
713
714 __asm__ __volatile__("sth %0, [%1]"
715 : /* No outputs */
716 : "r" (val), "r" (addr));
717 barrier();
718}
719
720static __inline__ void
721xf86WriteMmio16Le(__volatile__ void *base, const unsigned long offset,
722 const unsigned int val)
723{
724 unsigned long addr = ((unsigned long)base) + offset;
725
726 __asm__ __volatile__("stha %0, [%1] %2"
727 : /* No outputs */
728 : "r" (val), "r" (addr), "i" (ASI_PL));
729 barrier();
730}
731
732static __inline__ void
733xf86WriteMmio32Be(__volatile__ void *base, const unsigned long offset,
734 const unsigned int val)
735{
736 unsigned long addr = ((unsigned long)base) + offset;
737
738 __asm__ __volatile__("st %0, [%1]"
739 : /* No outputs */
740 : "r" (val), "r" (addr));
741 barrier();
742}
743
744static __inline__ void
745xf86WriteMmio32Le(__volatile__ void *base, const unsigned long offset,
746 const unsigned int val)
747{
748 unsigned long addr = ((unsigned long)base) + offset;
749
750 __asm__ __volatile__("sta %0, [%1] %2"
751 : /* No outputs */
752 : "r" (val), "r" (addr), "i" (ASI_PL));
753 barrier();
754}
755
756static __inline__ void
757xf86WriteMmio8NB(__volatile__ void *base, const unsigned long offset,
758 const unsigned int val)
759{
760 unsigned long addr = ((unsigned long)base) + offset;
761
762 __asm__ __volatile__("stba %0, [%1] %2"
763 : /* No outputs */
764 : "r" (val), "r" (addr), "i" (ASI_PL));
765}
766
767static __inline__ void
768xf86WriteMmio16BeNB(__volatile__ void *base, const unsigned long offset,
769 const unsigned int val)
770{
771 unsigned long addr = ((unsigned long)base) + offset;
772
773 __asm__ __volatile__("sth %0, [%1]"
774 : /* No outputs */
775 : "r" (val), "r" (addr));
776}
777
778static __inline__ void
779xf86WriteMmio16LeNB(__volatile__ void *base, const unsigned long offset,
780 const unsigned int val)
781{
782 unsigned long addr = ((unsigned long)base) + offset;
783
784 __asm__ __volatile__("stha %0, [%1] %2"
785 : /* No outputs */
786 : "r" (val), "r" (addr), "i" (ASI_PL));
787}
788
789static __inline__ void
790xf86WriteMmio32BeNB(__volatile__ void *base, const unsigned long offset,
791 const unsigned int val)
792{
793 unsigned long addr = ((unsigned long)base) + offset;
794
795 __asm__ __volatile__("st %0, [%1]"
796 : /* No outputs */
797 : "r" (val), "r" (addr));
798}
799
800static __inline__ void
801xf86WriteMmio32LeNB(__volatile__ void *base, const unsigned long offset,
802 const unsigned int val)
803{
804 unsigned long addr = ((unsigned long)base) + offset;
805
806 __asm__ __volatile__("sta %0, [%1] %2"
807 : /* No outputs */
808 : "r" (val), "r" (addr), "i" (ASI_PL));
809}
810
811# endif /* !Lynx */
812
813/*
814 * EGCS 1.1 knows about arbitrary unaligned loads. Define some
815 * packed structures to talk about such things with.
816 */
817
818# if defined(__arch64__) || defined(__sparcv9)
819struct __una_u64 { unsigned long x __attribute__((packed)); };
820# endif
821struct __una_u32 { unsigned int x __attribute__((packed)); };
822struct __una_u16 { unsigned short x __attribute__((packed)); };
823
824static __inline__ unsigned long ldq_u(unsigned long *p)
825{
826# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
827# if defined(__arch64__) || defined(__sparcv9)
828 const struct __una_u64 *ptr = (const struct __una_u64 *) p;
829# else
830 const struct __una_u32 *ptr = (const struct __una_u32 *) p;
831# endif
832 return ptr->x;
833# else
834 unsigned long ret;
835 memmove(&ret, p, sizeof(*p));
836 return ret;
837# endif
838}
839
840static __inline__ unsigned long ldl_u(unsigned int *p)
841{
842# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
843 const struct __una_u32 *ptr = (const struct __una_u32 *) p;
844 return ptr->x;
845# else
846 unsigned int ret;
847 memmove(&ret, p, sizeof(*p));
848 return ret;
849# endif
850}
851
852static __inline__ unsigned long ldw_u(unsigned short *p)
853{
854# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
855 const struct __una_u16 *ptr = (const struct __una_u16 *) p;
856 return ptr->x;
857# else
858 unsigned short ret;
859 memmove(&ret, p, sizeof(*p));
860 return ret;
861# endif
862}
863
864static __inline__ void stq_u(unsigned long val, unsigned long *p)
865{
866# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
867# if defined(__arch64__) || defined(__sparcv9)
868 struct __una_u64 *ptr = (struct __una_u64 *) p;
869# else
870 struct __una_u32 *ptr = (struct __una_u32 *) p;
871# endif
872 ptr->x = val;
873# else
874 unsigned long tmp = val;
875 memmove(p, &tmp, sizeof(*p));
876# endif
877}
878
879static __inline__ void stl_u(unsigned long val, unsigned int *p)
880{
881# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
882 struct __una_u32 *ptr = (struct __una_u32 *) p;
883 ptr->x = val;
884# else
885 unsigned int tmp = val;
886 memmove(p, &tmp, sizeof(*p));
887# endif
888}
889
890static __inline__ void stw_u(unsigned long val, unsigned short *p)
891{
892# if defined(__GNUC__) && ((__GNUC__ > 2) || (__GNUC_MINOR__ >= 91))
893 struct __una_u16 *ptr = (struct __una_u16 *) p;
894 ptr->x = val;
895# else
896 unsigned short tmp = val;
897 memmove(p, &tmp, sizeof(*p));
898# endif
899}
900
901# define mem_barrier() /* XXX: nop for now */
902# define write_mem_barrier() /* XXX: nop for now */
903
904# elif defined(__mips__) || (defined(__arm32__) && !defined(__linux__))
905# ifdef __arm32__
906# define PORT_SIZE long
907# else
908# define PORT_SIZE short
909# endif
910
911unsigned int IOPortBase; /* Memory mapped I/O port area */
912
913static __inline__ void
914outb(unsigned PORT_SIZE port, unsigned char val)
915{
916 *(volatile unsigned char*)(((unsigned PORT_SIZE)(port))+IOPortBase) = val;
917}
918
919static __inline__ void
920outw(unsigned PORT_SIZE port, unsigned short val)
921{
922 *(volatile unsigned short*)(((unsigned PORT_SIZE)(port))+IOPortBase) = val;
923}
924
925static __inline__ void
926outl(unsigned PORT_SIZE port, unsigned int val)
927{
928 *(volatile unsigned int*)(((unsigned PORT_SIZE)(port))+IOPortBase) = val;
929}
930
931static __inline__ unsigned int
932inb(unsigned PORT_SIZE port)
933{
934 return *(volatile unsigned char*)(((unsigned PORT_SIZE)(port))+IOPortBase);
935}
936
937static __inline__ unsigned int
938inw(unsigned PORT_SIZE port)
939{
940 return *(volatile unsigned short*)(((unsigned PORT_SIZE)(port))+IOPortBase);
941}
942
943static __inline__ unsigned int
944inl(unsigned PORT_SIZE port)
945{
946 return *(volatile unsigned int*)(((unsigned PORT_SIZE)(port))+IOPortBase);
947}
948
949
950# if defined(__mips__)
951static __inline__ unsigned long ldq_u(unsigned long * r11)
952{
953 unsigned long r1;
954 __asm__("lwr %0,%2\n\t"
955 "lwl %0,%3\n\t"
956 :"=&r" (r1)
957 :"r" (r11),
958 "m" (*r11),
959 "m" (*(unsigned long *)(3+(char *) r11)));
960 return r1;
961}
962
963static __inline__ unsigned long ldl_u(unsigned int * r11)
964{
965 unsigned long r1;
966 __asm__("lwr %0,%2\n\t"
967 "lwl %0,%3\n\t"
968 :"=&r" (r1)
969 :"r" (r11),
970 "m" (*r11),
971 "m" (*(unsigned long *)(3+(char *) r11)));
972 return r1;
973}
974
975static __inline__ unsigned long ldw_u(unsigned short * r11)
976{
977 unsigned long r1;
978 __asm__("lwr %0,%2\n\t"
979 "lwl %0,%3\n\t"
980 :"=&r" (r1)
981 :"r" (r11),
982 "m" (*r11),
983 "m" (*(unsigned long *)(1+(char *) r11)));
984 return r1;
985}
986
987# ifdef linux /* don't mess with other OSs */
988
989/*
990 * EGCS 1.1 knows about arbitrary unaligned loads (and we don't support older
991 * versions anyway. Define some packed structures to talk about such things
992 * with.
993 */
994
995struct __una_u32 { unsigned int x __attribute__((packed)); };
996struct __una_u16 { unsigned short x __attribute__((packed)); };
997
998static __inline__ void stw_u(unsigned long val, unsigned short *p)
999{
1000 struct __una_u16 *ptr = (struct __una_u16 *) p;
1001 ptr->x = val;
1002}
1003
1004static __inline__ void stl_u(unsigned long val, unsigned int *p)
1005{
1006 struct __una_u32 *ptr = (struct __una_u32 *) p;
1007 ptr->x = val;
1008}
1009
1010# if X_BYTE_ORDER == X_BIG_ENDIAN
1011static __inline__ unsigned int
1012xf86ReadMmio32Be(__volatile__ void *base, const unsigned long offset)
1013{
1014 unsigned long addr = ((unsigned long)base) + offset;
1015 unsigned int ret;
1016
1017 __asm__ __volatile__("lw %0, 0(%1)"
1018 : "=r" (ret)
1019 : "r" (addr));
1020 return ret;
1021}
1022
1023static __inline__ void
1024xf86WriteMmio32Be(__volatile__ void *base, const unsigned long offset,
1025 const unsigned int val)
1026{
1027 unsigned long addr = ((unsigned long)base) + offset;
1028
1029 __asm__ __volatile__("sw %0, 0(%1)"
1030 : /* No outputs */
1031 : "r" (val), "r" (addr));
1032}
1033# endif
1034
1035# define mem_barrier() \
1036 __asm__ __volatile__( \
1037 "# prevent instructions being moved around\n\t" \
1038 ".set\tnoreorder\n\t" \
1039 "# 8 nops to fool the R4400 pipeline\n\t" \
1040 "nop;nop;nop;nop;nop;nop;nop;nop\n\t" \
1041 ".set\treorder" \
1042 : /* no output */ \
1043 : /* no input */ \
1044 : "memory")
1045# define write_mem_barrier() mem_barrier()
1046
1047# else /* !linux */
1048
1049# define stq_u(v,p) stl_u(v,p)
1050# define stl_u(v,p) (*(unsigned char *)(p)) = (v); \
1051 (*(unsigned char *)(p)+1) = ((v) >> 8); \
1052 (*(unsigned char *)(p)+2) = ((v) >> 16); \
1053 (*(unsigned char *)(p)+3) = ((v) >> 24)
1054
1055# define stw_u(v,p) (*(unsigned char *)(p)) = (v); \
1056 (*(unsigned char *)(p)+1) = ((v) >> 8)
1057
1058# define mem_barrier() /* NOP */
1059# endif /* !linux */
1060# endif /* __mips__ */
1061
1062# if defined(__arm32__)
1063# define ldq_u(p) (*((unsigned long *)(p)))
1064# define ldl_u(p) (*((unsigned int *)(p)))
1065# define ldw_u(p) (*((unsigned short *)(p)))
1066# define stq_u(v,p) (*(unsigned long *)(p)) = (v)
1067# define stl_u(v,p) (*(unsigned int *)(p)) = (v)
1068# define stw_u(v,p) (*(unsigned short *)(p)) = (v)
1069# define mem_barrier() /* NOP */
1070# define write_mem_barrier() /* NOP */
1071# endif /* __arm32__ */
1072
1073# elif (defined(Lynx) || defined(linux) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__)) && defined(__powerpc__)
1074
1075# ifndef MAP_FAILED
1076# define MAP_FAILED ((void *)-1)
1077# endif
1078
1079extern volatile unsigned char *ioBase;
1080
1081#if defined(linux) && defined(__powerpc64__)
1082# include <asm/memory.h>
1083#endif /* defined(linux) && defined(__powerpc64__) */
1084#ifndef eieio /* We deal with arch-specific eieio() routines above... */
1085# define eieio() __asm__ __volatile__ ("eieio" ::: "memory")
1086#endif /* eieio */
1087
1088static __inline__ unsigned char
1089xf86ReadMmio8(__volatile__ void *base, const unsigned long offset)
1090{
1091 register unsigned char val;
1092 __asm__ __volatile__(
1093 "lbzx %0,%1,%2\n\t"
1094 "eieio"
1095 : "=r" (val)
1096 : "b" (base), "r" (offset),
1097 "m" (*((volatile unsigned char *)base+offset)));
1098 return val;
1099}
1100
1101static __inline__ unsigned short
1102xf86ReadMmio16Be(__volatile__ void *base, const unsigned long offset)
1103{
1104 register unsigned short val;
1105 __asm__ __volatile__(
1106 "lhzx %0,%1,%2\n\t"
1107 "eieio"
1108 : "=r" (val)
1109 : "b" (base), "r" (offset),
1110 "m" (*((volatile unsigned char *)base+offset)));
1111 return val;
1112}
1113
1114static __inline__ unsigned short
1115xf86ReadMmio16Le(__volatile__ void *base, const unsigned long offset)
1116{
1117 register unsigned short val;
1118 __asm__ __volatile__(
1119 "lhbrx %0,%1,%2\n\t"
1120 "eieio"
1121 : "=r" (val)
1122 : "b" (base), "r" (offset),
1123 "m" (*((volatile unsigned char *)base+offset)));
1124 return val;
1125}
1126
1127static __inline__ unsigned int
1128xf86ReadMmio32Be(__volatile__ void *base, const unsigned long offset)
1129{
1130 register unsigned int val;
1131 __asm__ __volatile__(
1132 "lwzx %0,%1,%2\n\t"
1133 "eieio"
1134 : "=r" (val)
1135 : "b" (base), "r" (offset),
1136 "m" (*((volatile unsigned char *)base+offset)));
1137 return val;
1138}
1139
1140static __inline__ unsigned int
1141xf86ReadMmio32Le(__volatile__ void *base, const unsigned long offset)
1142{
1143 register unsigned int val;
1144 __asm__ __volatile__(
1145 "lwbrx %0,%1,%2\n\t"
1146 "eieio"
1147 : "=r" (val)
1148 : "b" (base), "r" (offset),
1149 "m" (*((volatile unsigned char *)base+offset)));
1150 return val;
1151}
1152
1153static __inline__ void
1154xf86WriteMmioNB8(__volatile__ void *base, const unsigned long offset,
1155 const unsigned char val)
1156{
1157 __asm__ __volatile__(
1158 "stbx %1,%2,%3\n\t"
1159 : "=m" (*((volatile unsigned char *)base+offset))
1160 : "r" (val), "b" (base), "r" (offset));
1161}
1162
1163static __inline__ void
1164xf86WriteMmioNB16Le(__volatile__ void *base, const unsigned long offset,
1165 const unsigned short val)
1166{
1167 __asm__ __volatile__(
1168 "sthbrx %1,%2,%3\n\t"
1169 : "=m" (*((volatile unsigned char *)base+offset))
1170 : "r" (val), "b" (base), "r" (offset));
1171}
1172
1173static __inline__ void
1174xf86WriteMmioNB16Be(__volatile__ void *base, const unsigned long offset,
1175 const unsigned short val)
1176{
1177 __asm__ __volatile__(
1178 "sthx %1,%2,%3\n\t"
1179 : "=m" (*((volatile unsigned char *)base+offset))
1180 : "r" (val), "b" (base), "r" (offset));
1181}
1182
1183static __inline__ void
1184xf86WriteMmioNB32Le(__volatile__ void *base, const unsigned long offset,
1185 const unsigned int val)
1186{
1187 __asm__ __volatile__(
1188 "stwbrx %1,%2,%3\n\t"
1189 : "=m" (*((volatile unsigned char *)base+offset))
1190 : "r" (val), "b" (base), "r" (offset));
1191}
1192
1193static __inline__ void
1194xf86WriteMmioNB32Be(__volatile__ void *base, const unsigned long offset,
1195 const unsigned int val)
1196{
1197 __asm__ __volatile__(
1198 "stwx %1,%2,%3\n\t"
1199 : "=m" (*((volatile unsigned char *)base+offset))
1200 : "r" (val), "b" (base), "r" (offset));
1201}
1202
1203static __inline__ void
1204xf86WriteMmio8(__volatile__ void *base, const unsigned long offset,
1205 const unsigned char val)
1206{
1207 xf86WriteMmioNB8(base, offset, val);
1208 eieio();
1209}
1210
1211static __inline__ void
1212xf86WriteMmio16Le(__volatile__ void *base, const unsigned long offset,
1213 const unsigned short val)
1214{
1215 xf86WriteMmioNB16Le(base, offset, val);
1216 eieio();
1217}
1218
1219static __inline__ void
1220xf86WriteMmio16Be(__volatile__ void *base, const unsigned long offset,
1221 const unsigned short val)
1222{
1223 xf86WriteMmioNB16Be(base, offset, val);
1224 eieio();
1225}
1226
1227static __inline__ void
1228xf86WriteMmio32Le(__volatile__ void *base, const unsigned long offset,
1229 const unsigned int val)
1230{
1231 xf86WriteMmioNB32Le(base, offset, val);
1232 eieio();
1233}
1234
1235static __inline__ void
1236xf86WriteMmio32Be(__volatile__ void *base, const unsigned long offset,
1237 const unsigned int val)
1238{
1239 xf86WriteMmioNB32Be(base, offset, val);
1240 eieio();
1241}
1242
1243
1244static __inline__ void
1245outb(unsigned short port, unsigned char value)
1246{
1247 if(ioBase == MAP_FAILED) return;
1248 xf86WriteMmio8((void *)ioBase, port, value);
1249}
1250
1251static __inline__ void
1252outw(unsigned short port, unsigned short value)
1253{
1254 if(ioBase == MAP_FAILED) return;
1255 xf86WriteMmio16Le((void *)ioBase, port, value);
1256}
1257
1258static __inline__ void
1259outl(unsigned short port, unsigned int value)
1260{
1261 if(ioBase == MAP_FAILED) return;
1262 xf86WriteMmio32Le((void *)ioBase, port, value);
1263}
1264
1265static __inline__ unsigned int
1266inb(unsigned short port)
1267{
1268 if(ioBase == MAP_FAILED) return 0;
1269 return xf86ReadMmio8((void *)ioBase, port);
1270}
1271
1272static __inline__ unsigned int
1273inw(unsigned short port)
1274{
1275 if(ioBase == MAP_FAILED) return 0;
1276 return xf86ReadMmio16Le((void *)ioBase, port);
1277}
1278
1279static __inline__ unsigned int
1280inl(unsigned short port)
1281{
1282 if(ioBase == MAP_FAILED) return 0;
1283 return xf86ReadMmio32Le((void *)ioBase, port);
1284}
1285
1286# define ldq_u(p) ldl_u(p)
1287# define ldl_u(p) ((*(unsigned char *)(p)) | \
1288 (*((unsigned char *)(p)+1)<<8) | \
1289 (*((unsigned char *)(p)+2)<<16) | \
1290 (*((unsigned char *)(p)+3)<<24))
1291# define ldw_u(p) ((*(unsigned char *)(p)) | \
1292 (*((unsigned char *)(p)+1)<<8))
1293
1294# define stq_u(v,p) stl_u(v,p)
1295# define stl_u(v,p) (*(unsigned char *)(p)) = (v); \
1296 (*((unsigned char *)(p)+1)) = ((v) >> 8); \
1297 (*((unsigned char *)(p)+2)) = ((v) >> 16); \
1298 (*((unsigned char *)(p)+3)) = ((v) >> 24)
1299# define stw_u(v,p) (*(unsigned char *)(p)) = (v); \
1300 (*((unsigned char *)(p)+1)) = ((v) >> 8)
1301
1302# define mem_barrier() eieio()
1303# define write_mem_barrier() eieio()
1304
1305#elif defined(__arm__) && defined(__linux__)
1306
1307#define ldq_u(p) (*((unsigned long *)(p)))
1308#define ldl_u(p) (*((unsigned int *)(p)))
1309#define ldw_u(p) (*((unsigned short *)(p)))
1310#define stq_u(v,p) (*(unsigned long *)(p)) = (v)
1311#define stl_u(v,p) (*(unsigned int *)(p)) = (v)
1312#define stw_u(v,p) (*(unsigned short *)(p)) = (v)
1313#define mem_barrier() /* NOP */
1314#define write_mem_barrier() /* NOP */
1315
1316/* for Linux on ARM, we use the LIBC inx/outx routines */
1317/* note that the appropriate setup via "ioperm" needs to be done */
1318/* *before* any inx/outx is done. */
1319
1320#include <sys/io.h>
1321
1322static __inline__ void
1323xf_outb(unsigned short port, unsigned char val)
1324{
1325 outb(val, port);
1326}
1327
1328static __inline__ void
1329xf_outw(unsigned short port, unsigned short val)
1330{
1331 outw(val, port);
1332}
1333
1334static __inline__ void
1335xf_outl(unsigned short port, unsigned int val)
1336{
1337 outl(val, port);
1338}
1339
1340#define outb xf_outb
1341#define outw xf_outw
1342#define outl xf_outl
1343
1344#define arm_flush_cache(addr) \
1345do { \
1346 register unsigned long _beg __asm ("a1") = (unsigned long) (addr); \
1347 register unsigned long _end __asm ("a2") = (unsigned long) (addr) + 4;\
1348 register unsigned long _flg __asm ("a3") = 0; \
1349 __asm __volatile ("swi 0x9f0002 @ sys_cacheflush" \
1350 : "=r" (_beg) \
1351 : "0" (_beg), "r" (_end), "r" (_flg)); \
1352} while (0)
1353
1354# else /* ix86 */
1355
1356# define ldq_u(p) (*((unsigned long *)(p)))
1357# define ldl_u(p) (*((unsigned int *)(p)))
1358# define ldw_u(p) (*((unsigned short *)(p)))
1359# define stq_u(v,p) (*(unsigned long *)(p)) = (v)
1360# define stl_u(v,p) (*(unsigned int *)(p)) = (v)
1361# define stw_u(v,p) (*(unsigned short *)(p)) = (v)
1362# define mem_barrier() /* NOP */
1363# define write_mem_barrier() /* NOP */
1364
1365# if !defined(__SUNPRO_C)
1366# if !defined(FAKEIT) && !defined(__mc68000__) && !defined(__arm__) && !defined(__sh__) && !defined(__hppa__)
1367# ifdef GCCUSESGAS
1368
1369/*
1370 * If gcc uses gas rather than the native assembler, the syntax of these
1371 * inlines has to be different. DHD
1372 */
1373
1374static __inline__ void
1375outb(unsigned short port, unsigned char val)
1376{
1377 __asm__ __volatile__("outb %0,%1" : :"a" (val), "d" (port));
1378}
1379
1380
1381static __inline__ void
1382outw(unsigned short port, unsigned short val)
1383{
1384 __asm__ __volatile__("outw %0,%1" : :"a" (val), "d" (port));
1385}
1386
1387static __inline__ void
1388outl(unsigned short port, unsigned int val)
1389{
1390 __asm__ __volatile__("outl %0,%1" : :"a" (val), "d" (port));
1391}
1392
1393static __inline__ unsigned int
1394inb(unsigned short port)
1395{
1396 unsigned char ret;
1397 __asm__ __volatile__("inb %1,%0" :
1398 "=a" (ret) :
1399 "d" (port));
1400 return ret;
1401}
1402
1403static __inline__ unsigned int
1404inw(unsigned short port)
1405{
1406 unsigned short ret;
1407 __asm__ __volatile__("inw %1,%0" :
1408 "=a" (ret) :
1409 "d" (port));
1410 return ret;
1411}
1412
1413static __inline__ unsigned int
1414inl(unsigned short port)
1415{
1416 unsigned int ret;
1417 __asm__ __volatile__("inl %1,%0" :
1418 "=a" (ret) :
1419 "d" (port));
1420 return ret;
1421}
1422
1423# else /* GCCUSESGAS */
1424
1425static __inline__ void
1426outb(unsigned short port, unsigned char val)
1427{
1428 __asm__ __volatile__("out%B0 (%1)" : :"a" (val), "d" (port));
1429}
1430
1431static __inline__ void
1432outw(unsigned short port, unsigned short val)
1433{
1434 __asm__ __volatile__("out%W0 (%1)" : :"a" (val), "d" (port));
1435}
1436
1437static __inline__ void
1438outl(unsigned short port, unsigned int val)
1439{
1440 __asm__ __volatile__("out%L0 (%1)" : :"a" (val), "d" (port));
1441}
1442
1443static __inline__ unsigned int
1444inb(unsigned short port)
1445{
1446 unsigned char ret;
1447 __asm__ __volatile__("in%B0 (%1)" :
1448 "=a" (ret) :
1449 "d" (port));
1450 return ret;
1451}
1452
1453static __inline__ unsigned int
1454inw(unsigned short port)
1455{
1456 unsigned short ret;
1457 __asm__ __volatile__("in%W0 (%1)" :
1458 "=a" (ret) :
1459 "d" (port));
1460 return ret;
1461}
1462
1463static __inline__ unsigned int
1464inl(unsigned short port)
1465{
1466 unsigned int ret;
1467 __asm__ __volatile__("in%L0 (%1)" :
1468 "=a" (ret) :
1469 "d" (port));
1470 return ret;
1471}
1472
1473# endif /* GCCUSESGAS */
1474
1475# else /* !defined(FAKEIT) && !defined(__mc68000__) && !defined(__arm__) && !defined(__sh__) && !defined(__hppa__)*/
1476
1477static __inline__ void
1478outb(unsigned short port, unsigned char val)
1479{
1480}
1481
1482static __inline__ void
1483outw(unsigned short port, unsigned short val)
1484{
1485}
1486
1487static __inline__ void
1488outl(unsigned short port, unsigned int val)
1489{
1490}
1491
1492static __inline__ unsigned int
1493inb(unsigned short port)
1494{
1495 return 0;
1496}
1497
1498static __inline__ unsigned int
1499inw(unsigned short port)
1500{
1501 return 0;
1502}
1503
1504static __inline__ unsigned int
1505inl(unsigned short port)
1506{
1507 return 0;
1508}
1509
1510# endif /* FAKEIT */
1511# endif /* __SUNPRO_C */
1512
1513# endif /* ix86 */
1514
1515# elif defined(__powerpc__) /* && !__GNUC__ */
1516/*
1517 * NON-GCC PowerPC - Presumed to be PowerMAX OS for now
1518 */
1519# ifndef PowerMAX_OS
1520# error - Non-gcc PowerPC and !PowerMAXOS ???
1521# endif
1522
1523# define PPCIO_DEBUG 0
1524# define PPCIO_INLINE 1
1525# define USE_ABS_MACRO 1
1526/*
1527 * Use compiler intrinsics to access certain PPC machine instructions
1528 */
1529# define eieio() __inst_eieio()
1530# define stw_brx(val,base,ndx) __inst_sthbrx(val,base,ndx)
1531# define stl_brx(val,base,ndx) __inst_stwbrx(val,base,ndx)
1532# define ldw_brx(base,ndx) __inst_lhbrx(base,ndx)
1533# define ldl_brx(base,ndx) __inst_lwbrx(base,ndx)
1534
1535# define ldq_u(p) (*((unsigned long long *)(p)))
1536# define ldl_u(p) (*((unsigned long *)(p)))
1537# define ldw_u(p) (*((unsigned short *)(p)))
1538# define stq_u(v,p) (*(unsigned long long *)(p)) = (v)
1539# define stl_u(v,p) (*(unsigned long *)(p)) = (v)
1540# define stw_u(v,p) (*(unsigned short *)(p)) = (v)
1541# define mem_barrier() eieio()
1542# define write_mem_barrier() eieio()
1543
1544extern volatile unsigned char *ioBase;
1545
1546# if !defined(abs) && defined(USE_ABS_MACRO)
1547# define abs(x) ((x) >= 0 ? (x) : -(x))
1548# endif
1549
1550# undef inb
1551# undef inw
1552# undef inl
1553# undef outb
1554# undef outw
1555# undef outl
1556
1557# if PPCIO_DEBUG
1558
1559extern void debug_outb(unsigned int a, unsigned char b, int line, char *file);
1560extern void debug_outw(unsigned int a, unsigned short w, int line, char *file);
1561extern void debug_outl(unsigned int a, unsigned int l, int line, char *file);
1562extern unsigned char debug_inb(unsigned int a, int line, char *file);
1563extern unsigned short debug_inw(unsigned int a, int line, char *file);
1564extern unsigned int debug_inl(unsigned int a, int line, char *file);
1565
1566# define outb(a,b) debug_outb(a,b, __LINE__, __FILE__)
1567# define outw(a,w) debug_outw(a,w, __LINE__, __FILE__)
1568# define outl(a,l) debug_outl(a,l, __LINE__, __FILE__)
1569# define inb(a) debug_inb(a, __LINE__, __FILE__)
1570# define inw(a) debug_inw(a, __LINE__, __FILE__)
1571# define inl(a) debug_inl(a, __LINE__, __FILE__)
1572
1573# else /* !PPCIO_DEBUG */
1574
1575extern unsigned char inb(unsigned int a);
1576extern unsigned short inw(unsigned int a);
1577extern unsigned int inl(unsigned int a);
1578
1579# if PPCIO_INLINE
1580
1581# define outb(a,b) \
1582 (*((volatile unsigned char *)(ioBase + (a))) = (b), eieio())
1583# define outw(a,w) (stw_brx((w),ioBase,(a)), eieio())
1584# define outl(a,l) (stl_brx((l),ioBase,(a)), eieio())
1585
1586# else /* !PPCIO_INLINE */
1587
1588extern void outb(unsigned int a, unsigned char b);
1589extern void outw(unsigned int a, unsigned short w);
1590extern void outl(unsigned int a, unsigned int l);
1591
1592# endif /* PPCIO_INLINE */
1593
1594# endif /* !PPCIO_DEBUG */
1595
1596# else /* !GNUC && !PPC */
1597# if !defined(QNX4)
1598# if defined(__STDC__) && (__STDC__ == 1)
1599# ifndef asm
1600# define asm __asm
1601# endif
1602# endif
1603# ifndef SCO325
1604# if defined(__UNIXWARE__)
1605# if defined(IN_MODULE)
1606# /* avoid including <sys/types.h> for <sys/inline.h> on UnixWare */
1607# define ushort unsigned short
1608# define ushort_t unsigned short
1609# define ulong unsigned long
1610# define ulong_t unsigned long
1611# define uint_t unsigned int
1612# define uchar_t unsigned char
1613# else
1614# include <sys/types.h>
1615# endif /* IN_MODULE */
1616# endif /* __UNIXWARE__ */
1617# if !defined(sgi) && !defined(__SUNPRO_C)
1618# include <sys/inline.h>
1619# endif
1620# else
1621# include "scoasm.h"
1622# endif
1623# if (!defined(__HIGHC__) && !defined(sgi) && !defined(__SUNPRO_C)) || \
1624 defined(__USLC__)
1625# pragma asm partial_optimization outl
1626# pragma asm partial_optimization outw
1627# pragma asm partial_optimization outb
1628# pragma asm partial_optimization inl
1629# pragma asm partial_optimization inw
1630# pragma asm partial_optimization inb
1631# endif
1632# endif
1633# define ldq_u(p) (*((unsigned long *)(p)))
1634# define ldl_u(p) (*((unsigned int *)(p)))
1635# define ldw_u(p) (*((unsigned short *)(p)))
1636# define stq_u(v,p) (*(unsigned long *)(p)) = (v)
1637# define stl_u(v,p) (*(unsigned int *)(p)) = (v)
1638# define stw_u(v,p) (*(unsigned short *)(p)) = (v)
1639# define mem_barrier() /* NOP */
1640# define write_mem_barrier() /* NOP */
1641# endif /* __GNUC__ */
1642
1643# if defined(QNX4)
1644# include <sys/types.h>
1645extern unsigned inb(unsigned port);
1646extern unsigned inw(unsigned port);
1647extern unsigned inl(unsigned port);
1648extern void outb(unsigned port, unsigned val);
1649extern void outw(unsigned port, unsigned val);
1650extern void outl(unsigned port, unsigned val);
1651# endif /* QNX4 */
1652
1653# if defined(IODEBUG) && defined(__GNUC__)
1654# undef inb
1655# undef inw
1656# undef inl
1657# undef outb
1658# undef outw
1659# undef outl
1660# define inb(a) __extension__ ({unsigned char __c=RealInb(a); ErrorF("inb(0x%03x) = 0x%02x\t@ line %4d, file %s\n", a, __c, __LINE__, __FILE__);__c;})
1661# define inw(a) __extension__ ({unsigned short __c=RealInw(a); ErrorF("inw(0x%03x) = 0x%04x\t@ line %4d, file %s\n", a, __c, __LINE__, __FILE__);__c;})
1662# define inl(a) __extension__ ({unsigned int __c=RealInl(a); ErrorF("inl(0x%03x) = 0x%08x\t@ line %4d, file %s\n", a, __c, __LINE__, __FILE__);__c;})
1663
1664# define outb(a,b) (ErrorF("outb(0x%03x, 0x%02x)\t@ line %4d, file %s\n", a, b, __LINE__, __FILE__),RealOutb(a,b))
1665# define outw(a,b) (ErrorF("outw(0x%03x, 0x%04x)\t@ line %4d, file %s\n", a, b, __LINE__, __FILE__),RealOutw(a,b))
1666# define outl(a,b) (ErrorF("outl(0x%03x, 0x%08x)\t@ line %4d, file %s\n", a, b, __LINE__, __FILE__),RealOutl(a,b))
1667# endif
1668
1669# endif /* NO_INLINE */
1670
1671# ifdef __alpha__
1672/* entry points for Mmio memory access routines */
1673extern int (*xf86ReadMmio8)(void *, unsigned long);
1674extern int (*xf86ReadMmio16)(void *, unsigned long);
1675# ifndef STANDALONE_MMIO
1676extern int (*xf86ReadMmio32)(void *, unsigned long);
1677# else
1678/* Some DRI 3D drivers need MMIO_IN32. */
1679static __inline__ int
1680xf86ReadMmio32(void *Base, unsigned long Offset)
1681{
1682 __asm__ __volatile__("mb" : : : "memory");
1683 return *(volatile unsigned int*)((unsigned long)Base+(Offset));
1684}
1685# endif
1686extern void (*xf86WriteMmio8)(int, void *, unsigned long);
1687extern void (*xf86WriteMmio16)(int, void *, unsigned long);
1688extern void (*xf86WriteMmio32)(int, void *, unsigned long);
1689extern void (*xf86WriteMmioNB8)(int, void *, unsigned long);
1690extern void (*xf86WriteMmioNB16)(int, void *, unsigned long);
1691extern void (*xf86WriteMmioNB32)(int, void *, unsigned long);
1692extern void xf86JensenMemToBus(char *, long, long, int);
1693extern void xf86JensenBusToMem(char *, char *, unsigned long, int);
1694extern void xf86SlowBCopyFromBus(unsigned char *, unsigned char *, int);
1695extern void xf86SlowBCopyToBus(unsigned char *, unsigned char *, int);
1696
1697/* Some macros to hide the system dependencies for MMIO accesses */
1698/* Changed to kill noise generated by gcc's -Wcast-align */
1699# define MMIO_IN8(base, offset) (*xf86ReadMmio8)(base, offset)
1700# define MMIO_IN16(base, offset) (*xf86ReadMmio16)(base, offset)
1701# ifndef STANDALONE_MMIO
1702# define MMIO_IN32(base, offset) (*xf86ReadMmio32)(base, offset)
1703# else
1704# define MMIO_IN32(base, offset) xf86ReadMmio32(base, offset)
1705# endif
1706
1707# if defined (JENSEN_SUPPORT)
1708# define MMIO_OUT32(base, offset, val) \
1709 (*xf86WriteMmio32)((CARD32)(val), base, offset)
1710# define MMIO_ONB32(base, offset, val) \
1711 (*xf86WriteMmioNB32)((CARD32)(val), base, offset)
1712# else
1713# define MMIO_OUT32(base, offset, val) \
1714 do { \
1715 write_mem_barrier(); \
1716 *(volatile CARD32 *)(void *)(((CARD8*)(base)) + (offset)) = (val); \
1717 } while (0)
1718# define MMIO_ONB32(base, offset, val) \
1719 *(volatile CARD32 *)(void *)(((CARD8*)(base)) + (offset)) = (val)
1720# endif
1721
1722# define MMIO_OUT8(base, offset, val) \
1723 (*xf86WriteMmio8)((CARD8)(val), base, offset)
1724# define MMIO_OUT16(base, offset, val) \
1725 (*xf86WriteMmio16)((CARD16)(val), base, offset)
1726# define MMIO_ONB8(base, offset, val) \
1727 (*xf86WriteMmioNB8)((CARD8)(val), base, offset)
1728# define MMIO_ONB16(base, offset, val) \
1729 (*xf86WriteMmioNB16)((CARD16)(val), base, offset)
1730# define MMIO_MOVE32(base, offset, val) \
1731 MMIO_OUT32(base, offset, val)
1732
1733# elif defined(__powerpc__)
1734 /*
1735 * we provide byteswapping and no byteswapping functions here
1736 * with byteswapping as default,
1737 * drivers that don't need byteswapping should define PPC_MMIO_IS_BE
1738 */
1739# define MMIO_IN8(base, offset) xf86ReadMmio8(base, offset)
1740# define MMIO_OUT8(base, offset, val) \
1741 xf86WriteMmio8(base, offset, (CARD8)(val))
1742# define MMIO_ONB8(base, offset, val) \
1743 xf86WriteMmioNB8(base, offset, (CARD8)(val))
1744
1745# if defined(PPC_MMIO_IS_BE) /* No byteswapping */
1746# define MMIO_IN16(base, offset) xf86ReadMmio16Be(base, offset)
1747# define MMIO_IN32(base, offset) xf86ReadMmio32Be(base, offset)
1748# define MMIO_OUT16(base, offset, val) \
1749 xf86WriteMmio16Be(base, offset, (CARD16)(val))
1750# define MMIO_OUT32(base, offset, val) \
1751 xf86WriteMmio32Be(base, offset, (CARD32)(val))
1752# define MMIO_ONB16(base, offset, val) \
1753 xf86WriteMmioNB16Be(base, offset, (CARD16)(val))
1754# define MMIO_ONB32(base, offset, val) \
1755 xf86WriteMmioNB32Be(base, offset, (CARD32)(val))
1756# else /* byteswapping is the default */
1757# define MMIO_IN16(base, offset) xf86ReadMmio16Le(base, offset)
1758# define MMIO_IN32(base, offset) xf86ReadMmio32Le(base, offset)
1759# define MMIO_OUT16(base, offset, val) \
1760 xf86WriteMmio16Le(base, offset, (CARD16)(val))
1761# define MMIO_OUT32(base, offset, val) \
1762 xf86WriteMmio32Le(base, offset, (CARD32)(val))
1763# define MMIO_ONB16(base, offset, val) \
1764 xf86WriteMmioNB16Le(base, offset, (CARD16)(val))
1765# define MMIO_ONB32(base, offset, val) \
1766 xf86WriteMmioNB32Le(base, offset, (CARD32)(val))
1767# endif
1768
1769# define MMIO_MOVE32(base, offset, val) \
1770 xf86WriteMmio32Be(base, offset, (CARD32)(val))
1771
1772static __inline__ void ppc_flush_icache(char *addr)
1773{
1774 __asm__ volatile (
1775 "dcbf 0,%0;"
1776 "sync;"
1777 "icbi 0,%0;"
1778 "sync;"
1779 "isync;"
1780 : : "r"(addr) : "memory");
1781}
1782
1783# elif defined(__sparc__) || defined(sparc)
1784 /*
1785 * Like powerpc, we provide byteswapping and no byteswapping functions
1786 * here with byteswapping as default, drivers that don't need byteswapping
1787 * should define SPARC_MMIO_IS_BE (perhaps create a generic macro so that we
1788 * do not need to use PPC_MMIO_IS_BE and the sparc one in all the same places
1789 * of drivers?).
1790 */
1791# define MMIO_IN8(base, offset) xf86ReadMmio8(base, offset)
1792# define MMIO_OUT8(base, offset, val) \
1793 xf86WriteMmio8(base, offset, (CARD8)(val))
1794# define MMIO_ONB8(base, offset, val) \
1795 xf86WriteMmio8NB(base, offset, (CARD8)(val))
1796
1797# if defined(SPARC_MMIO_IS_BE) /* No byteswapping */
1798# define MMIO_IN16(base, offset) xf86ReadMmio16Be(base, offset)
1799# define MMIO_IN32(base, offset) xf86ReadMmio32Be(base, offset)
1800# define MMIO_OUT16(base, offset, val) \
1801 xf86WriteMmio16Be(base, offset, (CARD16)(val))
1802# define MMIO_OUT32(base, offset, val) \
1803 xf86WriteMmio32Be(base, offset, (CARD32)(val))
1804# define MMIO_ONB16(base, offset, val) \
1805 xf86WriteMmio16BeNB(base, offset, (CARD16)(val))
1806# define MMIO_ONB32(base, offset, val) \
1807 xf86WriteMmio32BeNB(base, offset, (CARD32)(val))
1808# else /* byteswapping is the default */
1809# define MMIO_IN16(base, offset) xf86ReadMmio16Le(base, offset)
1810# define MMIO_IN32(base, offset) xf86ReadMmio32Le(base, offset)
1811# define MMIO_OUT16(base, offset, val) \
1812 xf86WriteMmio16Le(base, offset, (CARD16)(val))
1813# define MMIO_OUT32(base, offset, val) \
1814 xf86WriteMmio32Le(base, offset, (CARD32)(val))
1815# define MMIO_ONB16(base, offset, val) \
1816 xf86WriteMmio16LeNB(base, offset, (CARD16)(val))
1817# define MMIO_ONB32(base, offset, val) \
1818 xf86WriteMmio32LeNB(base, offset, (CARD32)(val))
1819# endif
1820
1821# define MMIO_MOVE32(base, offset, val) \
1822 xf86WriteMmio32Be(base, offset, (CARD32)(val))
1823
1824# else /* !__alpha__ && !__powerpc__ && !__sparc__ */
1825
1826# define MMIO_IN8(base, offset) \
1827 *(volatile CARD8 *)(((CARD8*)(base)) + (offset))
1828# define MMIO_IN16(base, offset) \
1829 *(volatile CARD16 *)(void *)(((CARD8*)(base)) + (offset))
1830# define MMIO_IN32(base, offset) \
1831 *(volatile CARD32 *)(void *)(((CARD8*)(base)) + (offset))
1832# define MMIO_OUT8(base, offset, val) \
1833 *(volatile CARD8 *)(((CARD8*)(base)) + (offset)) = (val)
1834# define MMIO_OUT16(base, offset, val) \
1835 *(volatile CARD16 *)(void *)(((CARD8*)(base)) + (offset)) = (val)
1836# define MMIO_OUT32(base, offset, val) \
1837 *(volatile CARD32 *)(void *)(((CARD8*)(base)) + (offset)) = (val)
1838# define MMIO_ONB8(base, offset, val) MMIO_OUT8(base, offset, val)
1839# define MMIO_ONB16(base, offset, val) MMIO_OUT16(base, offset, val)
1840# define MMIO_ONB32(base, offset, val) MMIO_OUT32(base, offset, val)
1841
1842# define MMIO_MOVE32(base, offset, val) MMIO_OUT32(base, offset, val)
1843
1844# endif /* __alpha__ */
1845
1846/*
1847 * With Intel, the version in os-support/misc/SlowBcopy.s is used.
1848 * This avoids port I/O during the copy (which causes problems with
1849 * some hardware).
1850 */
1851# ifdef __alpha__
1852# define slowbcopy_tobus(src,dst,count) xf86SlowBCopyToBus(src,dst,count)
1853# define slowbcopy_frombus(src,dst,count) xf86SlowBCopyFromBus(src,dst,count)
1854# else /* __alpha__ */
1855# define slowbcopy_tobus(src,dst,count) xf86SlowBcopy(src,dst,count)
1856# define slowbcopy_frombus(src,dst,count) xf86SlowBcopy(src,dst,count)
1857# endif /* __alpha__ */
1858
1859#endif /* _COMPILER_H */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette