patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / arch / ia64 / sn / io / machvec / 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/sn/simulator.h>
13 #include <asm/sn/pda.h>
14 #include <asm/sn/sn_cpuid.h>
15 #include <asm/sn/sn2/shub_mmr.h>
16
17 /**
18  * sn_io_addr - convert an in/out port to an i/o address
19  * @port: port to convert
20  *
21  * Legacy in/out instructions are converted to ld/st instructions
22  * on IA64.  This routine will convert a port number into a valid 
23  * SN i/o address.  Used by sn_in*() and sn_out*().
24  */
25 void *
26 sn_io_addr(unsigned long port)
27 {
28         if (!IS_RUNNING_ON_SIMULATOR()) {
29                 /* On sn2, legacy I/O ports don't point at anything */
30                 if (port < 64*1024)
31                         return 0;
32                 return( (void *)  (port | __IA64_UNCACHED_OFFSET));
33         } else {
34                 /* but the simulator uses them... */
35                 unsigned long io_base;
36                 unsigned long addr;
37  
38                 /*
39                  * word align port, but need more than 10 bits
40                  * for accessing registers in bedrock local block
41                  * (so we don't do port&0xfff)
42                  */
43                 if ((port >= 0x1f0 && port <= 0x1f7) ||
44                         port == 0x3f6 || port == 0x3f7) {
45                         io_base = (0xc000000fcc000000 | ((unsigned long)get_nasid() << 38));
46                         addr = io_base | ((port >> 2) << 12) | (port & 0xfff);
47                 } else {
48                         addr = __ia64_get_io_port_base() | ((port >> 2) << 2);
49                 }
50                 return(void *) addr;
51         }
52 }
53
54 EXPORT_SYMBOL(sn_io_addr);
55
56 /**
57  * sn_mmiob - I/O space memory barrier
58  *
59  * Acts as a memory mapped I/O barrier for platforms that queue writes to 
60  * I/O space.  This ensures that subsequent writes to I/O space arrive after
61  * all previous writes.  For most ia64 platforms, this is a simple
62  * 'mf.a' instruction.  For other platforms, mmiob() may have to read
63  * a chipset register to ensure ordering.
64  *
65  * On SN2, we wait for the PIO_WRITE_STATUS SHub register to clear.
66  * See PV 871084 for details about the WAR about zero value.
67  *
68  */
69 void
70 sn_mmiob (void)
71 {
72         while ((((volatile unsigned long) (*pda->pio_write_status_addr)) & SH_PIO_WRITE_STATUS_0_PENDING_WRITE_COUNT_MASK) != 
73                                 SH_PIO_WRITE_STATUS_0_PENDING_WRITE_COUNT_MASK)
74                 cpu_relax();
75 }
76 EXPORT_SYMBOL(sn_mmiob);