2.5.70 update
[linux-flexiantxendom0-3.2.10.git] / arch / ia64 / sn / kernel / sn1 / 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-2002 Silicon Graphics, Inc. All rights reserved.
7  */
8
9 #include <linux/pci.h>
10 #include <asm/io.h>
11 #include <asm/sn/simulator.h>
12 #include <asm/delay.h>
13 #include <asm/sn/pda.h>
14
15 /**
16  * sn_io_addr - convert an in/out port to an i/o address
17  * @port: port to convert
18  *
19  * Legacy in/out instructions are converted to ld/st instructions
20  * on IA64.  This routine will convert a port number into a valid 
21  * SN i/o address.  Used by sn_in*() and sn_out*().
22  */
23 void *
24 sn_io_addr(unsigned long port)
25 {
26         if (!IS_RUNNING_ON_SIMULATOR()) {
27                 return( (void *)  (port | __IA64_UNCACHED_OFFSET));
28         } else {
29                 unsigned long io_base;
30                 unsigned long addr;
31  
32                 /*
33                  * word align port, but need more than 10 bits
34                  * for accessing registers in bedrock local block
35                  * (so we don't do port&0xfff)
36                  */
37                 if ((port >= 0x1f0 && port <= 0x1f7) ||
38                         port == 0x3f6 || port == 0x3f7) {
39                         io_base = __IA64_UNCACHED_OFFSET | 0x00000FFFFC000000;
40                         addr = io_base | ((port >> 2) << 12) | (port & 0xfff);
41                 } else {
42                         addr = __ia64_get_io_port_base() | ((port >> 2) << 2);
43                 }
44                 return(void *) addr;
45         }
46 }
47
48 /**
49  * sn1_mmiob - I/O space memory barrier
50  *
51  * Acts as a memory mapped I/O barrier for platforms that queue writes to 
52  * I/O space.  This ensures that subsequent writes to I/O space arrive after
53  * all previous writes.  For most ia64 platforms, this is a simple
54  * 'mf.a' instruction.  For other platforms, mmiob() may have to read
55  * a chipset register to ensure ordering.
56  *
57  * On SN1, we wait for the PIO_WRITE_STATUS Bedrock register to clear.
58  */
59 void
60 sn1_mmiob (void)
61 {
62         (volatile unsigned long) (*pda.bedrock_rev_id);
63         while (!(volatile unsigned long) (*pda.pio_write_status_addr))
64                 udelay(5);
65 }