blob: 4aa4f301d56d5a63aa114830b23328eefc034476 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 *
John Keller8ea60912006-10-04 16:49:25 -05006 * Copyright (C) 2000-2003, 2006 Silicon Graphics, Inc. All rights reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 */
8
9#include <linux/module.h>
John Keller8ea60912006-10-04 16:49:25 -050010#include <linux/acpi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <asm/io.h>
12#include <asm/delay.h>
Mark Maulea9f9de72005-04-26 08:01:00 -070013#include <asm/vga.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <asm/sn/nodepda.h>
15#include <asm/sn/simulator.h>
16#include <asm/sn/pda.h>
17#include <asm/sn/sn_cpuid.h>
18#include <asm/sn/shub_mmr.h>
John Keller8ea60912006-10-04 16:49:25 -050019#include <asm/sn/acpi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Mark Maulea9f9de72005-04-26 08:01:00 -070021#define IS_LEGACY_VGA_IOPORT(p) \
22 (((p) >= 0x3b0 && (p) <= 0x3bb) || ((p) >= 0x3c0 && (p) <= 0x3df))
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024/**
25 * sn_io_addr - convert an in/out port to an i/o address
26 * @port: port to convert
27 *
28 * Legacy in/out instructions are converted to ld/st instructions
29 * on IA64. This routine will convert a port number into a valid
30 * SN i/o address. Used by sn_in*() and sn_out*().
31 */
32void *sn_io_addr(unsigned long port)
33{
34 if (!IS_RUNNING_ON_SIMULATOR()) {
Mark Maulea9f9de72005-04-26 08:01:00 -070035 if (IS_LEGACY_VGA_IOPORT(port))
John Keller8ea60912006-10-04 16:49:25 -050036 return (__ia64_mk_io_addr(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 /* On sn2, legacy I/O ports don't point at anything */
38 if (port < (64 * 1024))
39 return NULL;
John Keller8ea60912006-10-04 16:49:25 -050040 if (SN_ACPI_BASE_SUPPORT())
41 return (__ia64_mk_io_addr(port));
42 else
43 return ((void *)(port | __IA64_UNCACHED_OFFSET));
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 } else {
45 /* but the simulator uses them... */
46 unsigned long addr;
47
48 /*
49 * word align port, but need more than 10 bits
50 * for accessing registers in bedrock local block
51 * (so we don't do port&0xfff)
52 */
53 addr = (is_shub2() ? 0xc00000028c000000UL : 0xc0000087cc000000UL) | ((port >> 2) << 12);
54 if ((port >= 0x1f0 && port <= 0x1f7) || port == 0x3f6 || port == 0x3f7)
55 addr |= port;
56 return (void *)addr;
57 }
58}
59
60EXPORT_SYMBOL(sn_io_addr);
61
62/**
63 * __sn_mmiowb - I/O space memory barrier
64 *
65 * See include/asm-ia64/io.h and Documentation/DocBook/deviceiobook.tmpl
66 * for details.
67 *
68 * On SN2, we wait for the PIO_WRITE_STATUS SHub register to clear.
69 * See PV 871084 for details about the WAR about zero value.
70 *
71 */
72void __sn_mmiowb(void)
73{
74 volatile unsigned long *adr = pda->pio_write_status_addr;
75 unsigned long val = pda->pio_write_status_val;
76
77 while ((*adr & SH_PIO_WRITE_STATUS_PENDING_WRITE_COUNT_MASK) != val)
78 cpu_relax();
79}
80
81EXPORT_SYMBOL(__sn_mmiowb);