/home/lenb/linux-2.6 branch 'acpi-2.6.12'
[pandora-kernel.git] / arch / ia64 / sn / kernel / iomv.c
1 /* 
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 2000-2003 Silicon Graphics, Inc. All rights reserved.
7  */
8
9 #include <linux/module.h>
10 #include <asm/io.h>
11 #include <asm/delay.h>
12 #include <asm/vga.h>
13 #include <asm/sn/nodepda.h>
14 #include <asm/sn/simulator.h>
15 #include <asm/sn/pda.h>
16 #include <asm/sn/sn_cpuid.h>
17 #include <asm/sn/shub_mmr.h>
18
19 #define IS_LEGACY_VGA_IOPORT(p) \
20         (((p) >= 0x3b0 && (p) <= 0x3bb) || ((p) >= 0x3c0 && (p) <= 0x3df))
21
22 /**
23  * sn_io_addr - convert an in/out port to an i/o address
24  * @port: port to convert
25  *
26  * Legacy in/out instructions are converted to ld/st instructions
27  * on IA64.  This routine will convert a port number into a valid 
28  * SN i/o address.  Used by sn_in*() and sn_out*().
29  */
30 void *sn_io_addr(unsigned long port)
31 {
32         if (!IS_RUNNING_ON_SIMULATOR()) {
33                 if (IS_LEGACY_VGA_IOPORT(port))
34                         port += vga_console_iobase;
35                 /* On sn2, legacy I/O ports don't point at anything */
36                 if (port < (64 * 1024))
37                         return NULL;
38                 return ((void *)(port | __IA64_UNCACHED_OFFSET));
39         } else {
40                 /* but the simulator uses them... */
41                 unsigned long addr;
42
43                 /*
44                  * word align port, but need more than 10 bits
45                  * for accessing registers in bedrock local block
46                  * (so we don't do port&0xfff)
47                  */
48                 addr = (is_shub2() ? 0xc00000028c000000UL : 0xc0000087cc000000UL) | ((port >> 2) << 12);
49                 if ((port >= 0x1f0 && port <= 0x1f7) || port == 0x3f6 || port == 0x3f7)
50                         addr |= port;
51                 return (void *)addr;
52         }
53 }
54
55 EXPORT_SYMBOL(sn_io_addr);
56
57 /**
58  * __sn_mmiowb - I/O space memory barrier
59  *
60  * See include/asm-ia64/io.h and Documentation/DocBook/deviceiobook.tmpl
61  * for details.
62  *
63  * On SN2, we wait for the PIO_WRITE_STATUS SHub register to clear.
64  * See PV 871084 for details about the WAR about zero value.
65  *
66  */
67 void __sn_mmiowb(void)
68 {
69         volatile unsigned long *adr = pda->pio_write_status_addr;
70         unsigned long val = pda->pio_write_status_val;
71
72         while ((*adr & SH_PIO_WRITE_STATUS_PENDING_WRITE_COUNT_MASK) != val)
73                 cpu_relax();
74 }
75
76 EXPORT_SYMBOL(__sn_mmiowb);