aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sparc64
diff options
context:
space:
mode:
Diffstat (limited to 'arch/sparc64')
-rw-r--r--arch/sparc64/Kconfig4
-rw-r--r--arch/sparc64/defconfig44
-rw-r--r--arch/sparc64/kernel/devices.c2
-rw-r--r--arch/sparc64/kernel/entry.S13
-rw-r--r--arch/sparc64/kernel/head.S30
-rw-r--r--arch/sparc64/kernel/irq.c1016
-rw-r--r--arch/sparc64/kernel/module.c5
-rw-r--r--arch/sparc64/kernel/pci.c38
-rw-r--r--arch/sparc64/kernel/pci_iommu.c4
-rw-r--r--arch/sparc64/kernel/pci_psycho.c81
-rw-r--r--arch/sparc64/kernel/pci_sabre.c99
-rw-r--r--arch/sparc64/kernel/pci_schizo.c192
-rw-r--r--arch/sparc64/kernel/pci_sun4v.c160
-rw-r--r--arch/sparc64/kernel/sbus.c47
-rw-r--r--arch/sparc64/kernel/setup.c23
-rw-r--r--arch/sparc64/kernel/smp.c51
-rw-r--r--arch/sparc64/kernel/sparc64_ksyms.c8
-rw-r--r--arch/sparc64/kernel/sun4v_ivec.S15
-rw-r--r--arch/sparc64/kernel/systbls.S8
-rw-r--r--arch/sparc64/kernel/time.c16
-rw-r--r--arch/sparc64/kernel/traps.c15
-rw-r--r--arch/sparc64/kernel/ttable.S10
-rw-r--r--arch/sparc64/lib/checksum.S5
-rw-r--r--arch/sparc64/lib/csum_copy.S5
24 files changed, 688 insertions, 1203 deletions
diff --git a/arch/sparc64/Kconfig b/arch/sparc64/Kconfig
index 43a66f5407f4..a7a111db25b2 100644
--- a/arch/sparc64/Kconfig
+++ b/arch/sparc64/Kconfig
@@ -87,6 +87,10 @@ config SYSVIPC_COMPAT
87 depends on COMPAT && SYSVIPC 87 depends on COMPAT && SYSVIPC
88 default y 88 default y
89 89
90config GENERIC_HARDIRQS
91 bool
92 default y
93
90menu "General machine setup" 94menu "General machine setup"
91 95
92config SMP 96config SMP
diff --git a/arch/sparc64/defconfig b/arch/sparc64/defconfig
index 1317380fa937..9da75f89fe2c 100644
--- a/arch/sparc64/defconfig
+++ b/arch/sparc64/defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.16 3# Linux kernel version: 2.6.17
4# Sun Apr 2 19:31:04 2006 4# Tue Jun 20 01:26:43 2006
5# 5#
6CONFIG_SPARC=y 6CONFIG_SPARC=y
7CONFIG_SPARC64=y 7CONFIG_SPARC64=y
@@ -87,6 +87,7 @@ CONFIG_DEFAULT_AS=y
87# CONFIG_DEFAULT_NOOP is not set 87# CONFIG_DEFAULT_NOOP is not set
88CONFIG_DEFAULT_IOSCHED="anticipatory" 88CONFIG_DEFAULT_IOSCHED="anticipatory"
89CONFIG_SYSVIPC_COMPAT=y 89CONFIG_SYSVIPC_COMPAT=y
90CONFIG_GENERIC_HARDIRQS=y
90 91
91# 92#
92# General machine setup 93# General machine setup
@@ -114,6 +115,7 @@ CONFIG_GENERIC_CALIBRATE_DELAY=y
114CONFIG_HUGETLB_PAGE_SIZE_4MB=y 115CONFIG_HUGETLB_PAGE_SIZE_4MB=y
115# CONFIG_HUGETLB_PAGE_SIZE_512K is not set 116# CONFIG_HUGETLB_PAGE_SIZE_512K is not set
116# CONFIG_HUGETLB_PAGE_SIZE_64K is not set 117# CONFIG_HUGETLB_PAGE_SIZE_64K is not set
118CONFIG_ARCH_SELECT_MEMORY_MODEL=y
117CONFIG_ARCH_SPARSEMEM_ENABLE=y 119CONFIG_ARCH_SPARSEMEM_ENABLE=y
118CONFIG_ARCH_SPARSEMEM_DEFAULT=y 120CONFIG_ARCH_SPARSEMEM_DEFAULT=y
119CONFIG_LARGE_ALLOCS=y 121CONFIG_LARGE_ALLOCS=y
@@ -182,6 +184,8 @@ CONFIG_INET_ESP=y
182CONFIG_INET_IPCOMP=y 184CONFIG_INET_IPCOMP=y
183CONFIG_INET_XFRM_TUNNEL=y 185CONFIG_INET_XFRM_TUNNEL=y
184CONFIG_INET_TUNNEL=y 186CONFIG_INET_TUNNEL=y
187CONFIG_INET_XFRM_MODE_TRANSPORT=y
188CONFIG_INET_XFRM_MODE_TUNNEL=y
185CONFIG_INET_DIAG=y 189CONFIG_INET_DIAG=y
186CONFIG_INET_TCP_DIAG=y 190CONFIG_INET_TCP_DIAG=y
187CONFIG_TCP_CONG_ADVANCED=y 191CONFIG_TCP_CONG_ADVANCED=y
@@ -197,6 +201,9 @@ CONFIG_TCP_CONG_HSTCP=m
197CONFIG_TCP_CONG_HYBLA=m 201CONFIG_TCP_CONG_HYBLA=m
198CONFIG_TCP_CONG_VEGAS=m 202CONFIG_TCP_CONG_VEGAS=m
199CONFIG_TCP_CONG_SCALABLE=m 203CONFIG_TCP_CONG_SCALABLE=m
204CONFIG_TCP_CONG_LP=m
205CONFIG_TCP_CONG_VENO=m
206CONFIG_TCP_CONG_COMPOUND=m
200CONFIG_IPV6=m 207CONFIG_IPV6=m
201CONFIG_IPV6_PRIVACY=y 208CONFIG_IPV6_PRIVACY=y
202CONFIG_IPV6_ROUTER_PREF=y 209CONFIG_IPV6_ROUTER_PREF=y
@@ -206,7 +213,10 @@ CONFIG_INET6_ESP=m
206CONFIG_INET6_IPCOMP=m 213CONFIG_INET6_IPCOMP=m
207CONFIG_INET6_XFRM_TUNNEL=m 214CONFIG_INET6_XFRM_TUNNEL=m
208CONFIG_INET6_TUNNEL=m 215CONFIG_INET6_TUNNEL=m
216CONFIG_INET6_XFRM_MODE_TRANSPORT=m
217CONFIG_INET6_XFRM_MODE_TUNNEL=m
209CONFIG_IPV6_TUNNEL=m 218CONFIG_IPV6_TUNNEL=m
219# CONFIG_NETWORK_SECMARK is not set
210# CONFIG_NETFILTER is not set 220# CONFIG_NETFILTER is not set
211 221
212# 222#
@@ -259,6 +269,7 @@ CONFIG_VLAN_8021Q=m
259# Network testing 269# Network testing
260# 270#
261CONFIG_NET_PKTGEN=m 271CONFIG_NET_PKTGEN=m
272CONFIG_NET_TCPPROBE=m
262# CONFIG_HAMRADIO is not set 273# CONFIG_HAMRADIO is not set
263# CONFIG_IRDA is not set 274# CONFIG_IRDA is not set
264# CONFIG_BT is not set 275# CONFIG_BT is not set
@@ -430,7 +441,6 @@ CONFIG_ISCSI_TCP=m
430# CONFIG_SCSI_INIA100 is not set 441# CONFIG_SCSI_INIA100 is not set
431# CONFIG_SCSI_SYM53C8XX_2 is not set 442# CONFIG_SCSI_SYM53C8XX_2 is not set
432# CONFIG_SCSI_IPR is not set 443# CONFIG_SCSI_IPR is not set
433# CONFIG_SCSI_QLOGIC_FC is not set
434# CONFIG_SCSI_QLOGIC_1280 is not set 444# CONFIG_SCSI_QLOGIC_1280 is not set
435# CONFIG_SCSI_QLOGICPTI is not set 445# CONFIG_SCSI_QLOGICPTI is not set
436# CONFIG_SCSI_QLA_FC is not set 446# CONFIG_SCSI_QLA_FC is not set
@@ -562,6 +572,7 @@ CONFIG_BNX2=m
562# CONFIG_CHELSIO_T1 is not set 572# CONFIG_CHELSIO_T1 is not set
563# CONFIG_IXGB is not set 573# CONFIG_IXGB is not set
564# CONFIG_S2IO is not set 574# CONFIG_S2IO is not set
575# CONFIG_MYRI10GE is not set
565 576
566# 577#
567# Token Ring devices 578# Token Ring devices
@@ -811,6 +822,7 @@ CONFIG_HWMON=y
811# Multimedia devices 822# Multimedia devices
812# 823#
813# CONFIG_VIDEO_DEV is not set 824# CONFIG_VIDEO_DEV is not set
825CONFIG_VIDEO_V4L2=y
814 826
815# 827#
816# Digital Video Broadcasting Devices 828# Digital Video Broadcasting Devices
@@ -1042,9 +1054,7 @@ CONFIG_USB_HIDDEV=y
1042# CONFIG_USB_ACECAD is not set 1054# CONFIG_USB_ACECAD is not set
1043# CONFIG_USB_KBTAB is not set 1055# CONFIG_USB_KBTAB is not set
1044# CONFIG_USB_POWERMATE is not set 1056# CONFIG_USB_POWERMATE is not set
1045# CONFIG_USB_MTOUCH is not set 1057# CONFIG_USB_TOUCHSCREEN is not set
1046# CONFIG_USB_ITMTOUCH is not set
1047# CONFIG_USB_EGALAX is not set
1048# CONFIG_USB_YEALINK is not set 1058# CONFIG_USB_YEALINK is not set
1049# CONFIG_USB_XPAD is not set 1059# CONFIG_USB_XPAD is not set
1050# CONFIG_USB_ATI_REMOTE is not set 1060# CONFIG_USB_ATI_REMOTE is not set
@@ -1115,6 +1125,14 @@ CONFIG_USB_HIDDEV=y
1115# CONFIG_NEW_LEDS is not set 1125# CONFIG_NEW_LEDS is not set
1116 1126
1117# 1127#
1128# LED drivers
1129#
1130
1131#
1132# LED Triggers
1133#
1134
1135#
1118# InfiniBand support 1136# InfiniBand support
1119# 1137#
1120# CONFIG_INFINIBAND is not set 1138# CONFIG_INFINIBAND is not set
@@ -1129,6 +1147,19 @@ CONFIG_USB_HIDDEV=y
1129# CONFIG_RTC_CLASS is not set 1147# CONFIG_RTC_CLASS is not set
1130 1148
1131# 1149#
1150# DMA Engine support
1151#
1152# CONFIG_DMA_ENGINE is not set
1153
1154#
1155# DMA Clients
1156#
1157
1158#
1159# DMA Devices
1160#
1161
1162#
1132# Misc Linux/SPARC drivers 1163# Misc Linux/SPARC drivers
1133# 1164#
1134CONFIG_SUN_OPENPROMIO=m 1165CONFIG_SUN_OPENPROMIO=m
@@ -1303,6 +1334,7 @@ CONFIG_DEBUG_BUGVERBOSE=y
1303# CONFIG_DEBUG_INFO is not set 1334# CONFIG_DEBUG_INFO is not set
1304CONFIG_DEBUG_FS=y 1335CONFIG_DEBUG_FS=y
1305# CONFIG_DEBUG_VM is not set 1336# CONFIG_DEBUG_VM is not set
1337# CONFIG_UNWIND_INFO is not set
1306CONFIG_FORCED_INLINING=y 1338CONFIG_FORCED_INLINING=y
1307# CONFIG_RCU_TORTURE_TEST is not set 1339# CONFIG_RCU_TORTURE_TEST is not set
1308# CONFIG_DEBUG_STACK_USAGE is not set 1340# CONFIG_DEBUG_STACK_USAGE is not set
diff --git a/arch/sparc64/kernel/devices.c b/arch/sparc64/kernel/devices.c
index 007e8922cd16..0dd95ae50e12 100644
--- a/arch/sparc64/kernel/devices.c
+++ b/arch/sparc64/kernel/devices.c
@@ -157,7 +157,7 @@ unsigned int sun4v_vdev_device_interrupt(unsigned int dev_node)
157 return 0; 157 return 0;
158 } 158 }
159 159
160 return sun4v_build_irq(sun4v_vdev_devhandle, irq, 5, 0); 160 return sun4v_build_irq(sun4v_vdev_devhandle, irq);
161} 161}
162 162
163static const char *cpu_mid_prop(void) 163static const char *cpu_mid_prop(void)
diff --git a/arch/sparc64/kernel/entry.S b/arch/sparc64/kernel/entry.S
index 6d0b3ed77a02..be85ce2a4ad9 100644
--- a/arch/sparc64/kernel/entry.S
+++ b/arch/sparc64/kernel/entry.S
@@ -22,6 +22,7 @@
22#include <asm/estate.h> 22#include <asm/estate.h>
23#include <asm/auxio.h> 23#include <asm/auxio.h>
24#include <asm/sfafsr.h> 24#include <asm/sfafsr.h>
25#include <asm/pil.h>
25 26
26#define curptr g6 27#define curptr g6
27 28
@@ -431,20 +432,16 @@ do_ivec:
431 membar #Sync 432 membar #Sync
432 433
433 sethi %hi(ivector_table), %g2 434 sethi %hi(ivector_table), %g2
434 sllx %g3, 5, %g3 435 sllx %g3, 3, %g3
435 or %g2, %lo(ivector_table), %g2 436 or %g2, %lo(ivector_table), %g2
436 add %g2, %g3, %g3 437 add %g2, %g3, %g3
437 ldub [%g3 + 0x04], %g4 /* pil */
438 mov 1, %g2
439 sllx %g2, %g4, %g2
440 sllx %g4, 2, %g4
441 438
442 TRAP_LOAD_IRQ_WORK(%g6, %g1) 439 TRAP_LOAD_IRQ_WORK(%g6, %g1)
443 440
444 lduw [%g6 + %g4], %g5 /* g5 = irq_work(cpu, pil) */ 441 lduw [%g6], %g5 /* g5 = irq_work(cpu) */
445 stw %g5, [%g3 + 0x00] /* bucket->irq_chain = g5 */ 442 stw %g5, [%g3 + 0x00] /* bucket->irq_chain = g5 */
446 stw %g3, [%g6 + %g4] /* irq_work(cpu, pil) = bucket */ 443 stw %g3, [%g6] /* irq_work(cpu) = bucket */
447 wr %g2, 0x0, %set_softint 444 wr %g0, 1 << PIL_DEVICE_IRQ, %set_softint
448 retry 445 retry
449do_ivec_xcall: 446do_ivec_xcall:
450 mov 0x50, %g1 447 mov 0x50, %g1
diff --git a/arch/sparc64/kernel/head.S b/arch/sparc64/kernel/head.S
index 3eadac5e171e..31c5892f5acc 100644
--- a/arch/sparc64/kernel/head.S
+++ b/arch/sparc64/kernel/head.S
@@ -10,6 +10,7 @@
10#include <linux/config.h> 10#include <linux/config.h>
11#include <linux/version.h> 11#include <linux/version.h>
12#include <linux/errno.h> 12#include <linux/errno.h>
13#include <linux/threads.h>
13#include <asm/thread_info.h> 14#include <asm/thread_info.h>
14#include <asm/asi.h> 15#include <asm/asi.h>
15#include <asm/pstate.h> 16#include <asm/pstate.h>
@@ -493,6 +494,35 @@ tlb_fixup_done:
493 call prom_init 494 call prom_init
494 mov %l7, %o0 ! OpenPROM cif handler 495 mov %l7, %o0 ! OpenPROM cif handler
495 496
497 /* Initialize current_thread_info()->cpu as early as possible.
498 * In order to do that accurately we have to patch up the get_cpuid()
499 * assembler sequences. And that, in turn, requires that we know
500 * if we are on a Starfire box or not. While we're here, patch up
501 * the sun4v sequences as well.
502 */
503 call check_if_starfire
504 nop
505 call per_cpu_patch
506 nop
507 call sun4v_patch
508 nop
509
510#ifdef CONFIG_SMP
511 call hard_smp_processor_id
512 nop
513 cmp %o0, NR_CPUS
514 blu,pt %xcc, 1f
515 nop
516 call boot_cpu_id_too_large
517 nop
518 /* Not reached... */
519
5201:
521#else
522 mov 0, %o0
523#endif
524 stb %o0, [%g6 + TI_CPU]
525
496 /* Off we go.... */ 526 /* Off we go.... */
497 call start_kernel 527 call start_kernel
498 nop 528 nop
diff --git a/arch/sparc64/kernel/irq.c b/arch/sparc64/kernel/irq.c
index 11e645c9ec50..a8c9dc8d1958 100644
--- a/arch/sparc64/kernel/irq.c
+++ b/arch/sparc64/kernel/irq.c
@@ -22,6 +22,7 @@
22#include <linux/proc_fs.h> 22#include <linux/proc_fs.h>
23#include <linux/seq_file.h> 23#include <linux/seq_file.h>
24#include <linux/bootmem.h> 24#include <linux/bootmem.h>
25#include <linux/irq.h>
25 26
26#include <asm/ptrace.h> 27#include <asm/ptrace.h>
27#include <asm/processor.h> 28#include <asm/processor.h>
@@ -42,10 +43,6 @@
42#include <asm/auxio.h> 43#include <asm/auxio.h>
43#include <asm/head.h> 44#include <asm/head.h>
44 45
45#ifdef CONFIG_SMP
46static void distribute_irqs(void);
47#endif
48
49/* UPA nodes send interrupt packet to UltraSparc with first data reg 46/* UPA nodes send interrupt packet to UltraSparc with first data reg
50 * value low 5 (7 on Starfire) bits holding the IRQ identifier being 47 * value low 5 (7 on Starfire) bits holding the IRQ identifier being
51 * delivered. We must translate this into a non-vector IRQ so we can 48 * delivered. We must translate this into a non-vector IRQ so we can
@@ -57,10 +54,29 @@ static void distribute_irqs(void);
57 * The IVEC handler does not need to act atomically, the PIL dispatch 54 * The IVEC handler does not need to act atomically, the PIL dispatch
58 * code uses CAS to get an atomic snapshot of the list and clear it 55 * code uses CAS to get an atomic snapshot of the list and clear it
59 * at the same time. 56 * at the same time.
57 *
58 * If you make changes to ino_bucket, please update hand coded assembler
59 * of the vectored interrupt trap handler(s) in entry.S and sun4v_ivec.S
60 */ 60 */
61struct ino_bucket {
62 /* Next handler in per-CPU IRQ worklist. We know that
63 * bucket pointers have the high 32-bits clear, so to
64 * save space we only store the bits we need.
65 */
66/*0x00*/unsigned int irq_chain;
61 67
68 /* Virtual interrupt number assigned to this INO. */
69/*0x04*/unsigned int virt_irq;
70};
71
72#define NUM_IVECS (IMAP_INR + 1)
62struct ino_bucket ivector_table[NUM_IVECS] __attribute__ ((aligned (SMP_CACHE_BYTES))); 73struct ino_bucket ivector_table[NUM_IVECS] __attribute__ ((aligned (SMP_CACHE_BYTES)));
63 74
75#define __irq_ino(irq) \
76 (((struct ino_bucket *)(unsigned long)(irq)) - &ivector_table[0])
77#define __bucket(irq) ((struct ino_bucket *)(unsigned long)(irq))
78#define __irq(bucket) ((unsigned int)(unsigned long)(bucket))
79
64/* This has to be in the main kernel image, it cannot be 80/* This has to be in the main kernel image, it cannot be
65 * turned into per-cpu data. The reason is that the main 81 * turned into per-cpu data. The reason is that the main
66 * kernel image is locked into the TLB and this structure 82 * kernel image is locked into the TLB and this structure
@@ -68,71 +84,82 @@ struct ino_bucket ivector_table[NUM_IVECS] __attribute__ ((aligned (SMP_CACHE_BY
68 * access to this structure takes a TLB miss it could cause 84 * access to this structure takes a TLB miss it could cause
69 * the 5-level sparc v9 trap stack to overflow. 85 * the 5-level sparc v9 trap stack to overflow.
70 */ 86 */
71struct irq_work_struct { 87#define irq_work(__cpu) &(trap_block[(__cpu)].irq_worklist)
72 unsigned int irq_worklists[16];
73};
74struct irq_work_struct __irq_work[NR_CPUS];
75#define irq_work(__cpu, __pil) &(__irq_work[(__cpu)].irq_worklists[(__pil)])
76 88
77static struct irqaction *irq_action[NR_IRQS+1]; 89static unsigned int virt_to_real_irq_table[NR_IRQS];
90static unsigned char virt_irq_cur = 1;
78 91
79/* This only synchronizes entities which modify IRQ handler 92static unsigned char virt_irq_alloc(unsigned int real_irq)
80 * state and some selected user-level spots that want to 93{
81 * read things in the table. IRQ handler processing orders 94 unsigned char ent;
82 * its' accesses such that no locking is needed. 95
83 */ 96 BUILD_BUG_ON(NR_IRQS >= 256);
84static DEFINE_SPINLOCK(irq_action_lock); 97
98 ent = virt_irq_cur;
99 if (ent >= NR_IRQS) {
100 printk(KERN_ERR "IRQ: Out of virtual IRQs.\n");
101 return 0;
102 }
103
104 virt_irq_cur = ent + 1;
105 virt_to_real_irq_table[ent] = real_irq;
106
107 return ent;
108}
109
110#if 0 /* Currently unused. */
111static unsigned char real_to_virt_irq(unsigned int real_irq)
112{
113 struct ino_bucket *bucket = __bucket(real_irq);
85 114
86static void register_irq_proc (unsigned int irq); 115 return bucket->virt_irq;
116}
117#endif
118
119static unsigned int virt_to_real_irq(unsigned char virt_irq)
120{
121 return virt_to_real_irq_table[virt_irq];
122}
87 123
88/* 124/*
89 * Upper 2b of irqaction->flags holds the ino. 125 * /proc/interrupts printing:
90 * irqaction->mask holds the smp affinity information.
91 */ 126 */
92#define put_ino_in_irqaction(action, irq) \
93 action->flags &= 0xffffffffffffUL; \
94 if (__bucket(irq) == &pil0_dummy_bucket) \
95 action->flags |= 0xdeadUL << 48; \
96 else \
97 action->flags |= __irq_ino(irq) << 48;
98#define get_ino_in_irqaction(action) (action->flags >> 48)
99
100#define put_smpaff_in_irqaction(action, smpaff) (action)->mask = (smpaff)
101#define get_smpaff_in_irqaction(action) ((action)->mask)
102 127
103int show_interrupts(struct seq_file *p, void *v) 128int show_interrupts(struct seq_file *p, void *v)
104{ 129{
130 int i = *(loff_t *) v, j;
131 struct irqaction * action;
105 unsigned long flags; 132 unsigned long flags;
106 int i = *(loff_t *) v;
107 struct irqaction *action;
108#ifdef CONFIG_SMP
109 int j;
110#endif
111 133
112 spin_lock_irqsave(&irq_action_lock, flags); 134 if (i == 0) {
113 if (i <= NR_IRQS) { 135 seq_printf(p, " ");
114 if (!(action = *(i + irq_action))) 136 for_each_online_cpu(j)
115 goto out_unlock; 137 seq_printf(p, "CPU%d ",j);
116 seq_printf(p, "%3d: ", i); 138 seq_putc(p, '\n');
139 }
140
141 if (i < NR_IRQS) {
142 spin_lock_irqsave(&irq_desc[i].lock, flags);
143 action = irq_desc[i].action;
144 if (!action)
145 goto skip;
146 seq_printf(p, "%3d: ",i);
117#ifndef CONFIG_SMP 147#ifndef CONFIG_SMP
118 seq_printf(p, "%10u ", kstat_irqs(i)); 148 seq_printf(p, "%10u ", kstat_irqs(i));
119#else 149#else
120 for_each_online_cpu(j) { 150 for_each_online_cpu(j)
121 seq_printf(p, "%10u ", 151 seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
122 kstat_cpu(j).irqs[i]);
123 }
124#endif 152#endif
125 seq_printf(p, " %s:%lx", action->name, 153 seq_printf(p, " %9s", irq_desc[i].handler->typename);
126 get_ino_in_irqaction(action)); 154 seq_printf(p, " %s", action->name);
127 for (action = action->next; action; action = action->next) { 155
128 seq_printf(p, ", %s:%lx", action->name, 156 for (action=action->next; action; action = action->next)
129 get_ino_in_irqaction(action)); 157 seq_printf(p, ", %s", action->name);
130 } 158
131 seq_putc(p, '\n'); 159 seq_putc(p, '\n');
160skip:
161 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
132 } 162 }
133out_unlock:
134 spin_unlock_irqrestore(&irq_action_lock, flags);
135
136 return 0; 163 return 0;
137} 164}
138 165
@@ -173,556 +200,365 @@ static unsigned int sun4u_compute_tid(unsigned long imap, unsigned long cpuid)
173 return tid; 200 return tid;
174} 201}
175 202
176/* Now these are always passed a true fully specified sun4u INO. */ 203struct irq_handler_data {
177void enable_irq(unsigned int irq) 204 unsigned long iclr;
178{ 205 unsigned long imap;
179 struct ino_bucket *bucket = __bucket(irq);
180 unsigned long imap, cpuid;
181
182 imap = bucket->imap;
183 if (imap == 0UL)
184 return;
185
186 preempt_disable();
187
188 /* This gets the physical processor ID, even on uniprocessor,
189 * so we can always program the interrupt target correctly.
190 */
191 cpuid = real_hard_smp_processor_id();
192
193 if (tlb_type == hypervisor) {
194 unsigned int ino = __irq_ino(irq);
195 int err;
196 206
197 err = sun4v_intr_settarget(ino, cpuid); 207 void (*pre_handler)(unsigned int, void *, void *);
198 if (err != HV_EOK) 208 void *pre_handler_arg1;
199 printk("sun4v_intr_settarget(%x,%lu): err(%d)\n", 209 void *pre_handler_arg2;
200 ino, cpuid, err); 210};
201 err = sun4v_intr_setenabled(ino, HV_INTR_ENABLED);
202 if (err != HV_EOK)
203 printk("sun4v_intr_setenabled(%x): err(%d)\n",
204 ino, err);
205 } else {
206 unsigned int tid = sun4u_compute_tid(imap, cpuid);
207
208 /* NOTE NOTE NOTE, IGN and INO are read-only, IGN is a product
209 * of this SYSIO's preconfigured IGN in the SYSIO Control
210 * Register, the hardware just mirrors that value here.
211 * However for Graphics and UPA Slave devices the full
212 * IMAP_INR field can be set by the programmer here.
213 *
214 * Things like FFB can now be handled via the new IRQ
215 * mechanism.
216 */
217 upa_writel(tid | IMAP_VALID, imap);
218 }
219
220 preempt_enable();
221}
222 211
223/* This now gets passed true ino's as well. */ 212static inline struct ino_bucket *virt_irq_to_bucket(unsigned int virt_irq)
224void disable_irq(unsigned int irq)
225{ 213{
226 struct ino_bucket *bucket = __bucket(irq); 214 unsigned int real_irq = virt_to_real_irq(virt_irq);
227 unsigned long imap; 215 struct ino_bucket *bucket = NULL;
228
229 imap = bucket->imap;
230 if (imap != 0UL) {
231 if (tlb_type == hypervisor) {
232 unsigned int ino = __irq_ino(irq);
233 int err;
234
235 err = sun4v_intr_setenabled(ino, HV_INTR_DISABLED);
236 if (err != HV_EOK)
237 printk("sun4v_intr_setenabled(%x): "
238 "err(%d)\n", ino, err);
239 } else {
240 u32 tmp;
241
242 /* NOTE: We do not want to futz with the IRQ clear registers
243 * and move the state to IDLE, the SCSI code does call
244 * disable_irq() to assure atomicity in the queue cmd
245 * SCSI adapter driver code. Thus we'd lose interrupts.
246 */
247 tmp = upa_readl(imap);
248 tmp &= ~IMAP_VALID;
249 upa_writel(tmp, imap);
250 }
251 }
252}
253 216
254/* The timer is the one "weird" interrupt which is generated by 217 if (likely(real_irq))
255 * the CPU %tick register and not by some normal vectored interrupt 218 bucket = __bucket(real_irq);
256 * source. To handle this special case, we use this dummy INO bucket.
257 */
258static struct irq_desc pil0_dummy_desc;
259static struct ino_bucket pil0_dummy_bucket = {
260 .irq_info = &pil0_dummy_desc,
261};
262 219
263static void build_irq_error(const char *msg, unsigned int ino, int pil, int inofixup, 220 return bucket;
264 unsigned long iclr, unsigned long imap,
265 struct ino_bucket *bucket)
266{
267 prom_printf("IRQ: INO %04x (%d:%016lx:%016lx) --> "
268 "(%d:%d:%016lx:%016lx), halting...\n",
269 ino, bucket->pil, bucket->iclr, bucket->imap,
270 pil, inofixup, iclr, imap);
271 prom_halt();
272} 221}
273 222
274unsigned int build_irq(int pil, int inofixup, unsigned long iclr, unsigned long imap) 223#ifdef CONFIG_SMP
224static int irq_choose_cpu(unsigned int virt_irq)
275{ 225{
276 struct ino_bucket *bucket; 226 cpumask_t mask = irq_affinity[virt_irq];
277 int ino; 227 int cpuid;
278 228
279 if (pil == 0) { 229 if (cpus_equal(mask, CPU_MASK_ALL)) {
280 if (iclr != 0UL || imap != 0UL) { 230 static int irq_rover;
281 prom_printf("Invalid dummy bucket for PIL0 (%lx:%lx)\n", 231 static DEFINE_SPINLOCK(irq_rover_lock);
282 iclr, imap); 232 unsigned long flags;
283 prom_halt();
284 }
285 return __irq(&pil0_dummy_bucket);
286 }
287 233
288 BUG_ON(tlb_type == hypervisor); 234 /* Round-robin distribution... */
235 do_round_robin:
236 spin_lock_irqsave(&irq_rover_lock, flags);
289 237
290 /* RULE: Both must be specified in all other cases. */ 238 while (!cpu_online(irq_rover)) {
291 if (iclr == 0UL || imap == 0UL) { 239 if (++irq_rover >= NR_CPUS)
292 prom_printf("Invalid build_irq %d %d %016lx %016lx\n", 240 irq_rover = 0;
293 pil, inofixup, iclr, imap); 241 }
294 prom_halt(); 242 cpuid = irq_rover;
295 } 243 do {
296 244 if (++irq_rover >= NR_CPUS)
297 ino = (upa_readl(imap) & (IMAP_IGN | IMAP_INO)) + inofixup; 245 irq_rover = 0;
298 if (ino > NUM_IVECS) { 246 } while (!cpu_online(irq_rover));
299 prom_printf("Invalid INO %04x (%d:%d:%016lx:%016lx)\n",
300 ino, pil, inofixup, iclr, imap);
301 prom_halt();
302 }
303 247
304 bucket = &ivector_table[ino]; 248 spin_unlock_irqrestore(&irq_rover_lock, flags);
305 if (bucket->flags & IBF_ACTIVE) 249 } else {
306 build_irq_error("IRQ: Trying to build active INO bucket.\n", 250 cpumask_t tmp;
307 ino, pil, inofixup, iclr, imap, bucket);
308 251
309 if (bucket->irq_info) { 252 cpus_and(tmp, cpu_online_map, mask);
310 if (bucket->imap != imap || bucket->iclr != iclr)
311 build_irq_error("IRQ: Trying to reinit INO bucket.\n",
312 ino, pil, inofixup, iclr, imap, bucket);
313 253
314 goto out; 254 if (cpus_empty(tmp))
315 } 255 goto do_round_robin;
316 256
317 bucket->irq_info = kzalloc(sizeof(struct irq_desc), GFP_ATOMIC); 257 cpuid = first_cpu(tmp);
318 if (!bucket->irq_info) {
319 prom_printf("IRQ: Error, kmalloc(irq_desc) failed.\n");
320 prom_halt();
321 } 258 }
322 259
323 /* Ok, looks good, set it up. Don't touch the irq_chain or 260 return cpuid;
324 * the pending flag.
325 */
326 bucket->imap = imap;
327 bucket->iclr = iclr;
328 bucket->pil = pil;
329 bucket->flags = 0;
330
331out:
332 return __irq(bucket);
333} 261}
334 262#else
335unsigned int sun4v_build_irq(u32 devhandle, unsigned int devino, int pil, unsigned char flags) 263static int irq_choose_cpu(unsigned int virt_irq)
336{ 264{
337 struct ino_bucket *bucket; 265 return real_hard_smp_processor_id();
338 unsigned long sysino; 266}
267#endif
339 268
340 sysino = sun4v_devino_to_sysino(devhandle, devino); 269static void sun4u_irq_enable(unsigned int virt_irq)
270{
271 irq_desc_t *desc = irq_desc + virt_irq;
272 struct irq_handler_data *data = desc->handler_data;
341 273
342 bucket = &ivector_table[sysino]; 274 if (likely(data)) {
275 unsigned long cpuid, imap;
276 unsigned int tid;
343 277
344 /* Catch accidental accesses to these things. IMAP/ICLR handling 278 cpuid = irq_choose_cpu(virt_irq);
345 * is done by hypervisor calls on sun4v platforms, not by direct 279 imap = data->imap;
346 * register accesses.
347 *
348 * But we need to make them look unique for the disable_irq() logic
349 * in free_irq().
350 */
351 bucket->imap = ~0UL - sysino;
352 bucket->iclr = ~0UL - sysino;
353 280
354 bucket->pil = pil; 281 tid = sun4u_compute_tid(imap, cpuid);
355 bucket->flags = flags;
356 282
357 bucket->irq_info = kzalloc(sizeof(struct irq_desc), GFP_ATOMIC); 283 upa_writel(tid | IMAP_VALID, imap);
358 if (!bucket->irq_info) {
359 prom_printf("IRQ: Error, kmalloc(irq_desc) failed.\n");
360 prom_halt();
361 } 284 }
362
363 return __irq(bucket);
364} 285}
365 286
366static void atomic_bucket_insert(struct ino_bucket *bucket) 287static void sun4u_irq_disable(unsigned int virt_irq)
367{ 288{
368 unsigned long pstate; 289 irq_desc_t *desc = irq_desc + virt_irq;
369 unsigned int *ent; 290 struct irq_handler_data *data = desc->handler_data;
370 291
371 __asm__ __volatile__("rdpr %%pstate, %0" : "=r" (pstate)); 292 if (likely(data)) {
372 __asm__ __volatile__("wrpr %0, %1, %%pstate" 293 unsigned long imap = data->imap;
373 : : "r" (pstate), "i" (PSTATE_IE)); 294 u32 tmp = upa_readl(imap);
374 ent = irq_work(smp_processor_id(), bucket->pil);
375 bucket->irq_chain = *ent;
376 *ent = __irq(bucket);
377 __asm__ __volatile__("wrpr %0, 0x0, %%pstate" : : "r" (pstate));
378}
379 295
380static int check_irq_sharing(int pil, unsigned long irqflags) 296 tmp &= ~IMAP_VALID;
381{ 297 upa_writel(tmp, imap);
382 struct irqaction *action, *tmp;
383
384 action = *(irq_action + pil);
385 if (action) {
386 if ((action->flags & SA_SHIRQ) && (irqflags & SA_SHIRQ)) {
387 for (tmp = action; tmp->next; tmp = tmp->next)
388 ;
389 } else {
390 return -EBUSY;
391 }
392 } 298 }
393 return 0;
394} 299}
395 300
396static void append_irq_action(int pil, struct irqaction *action) 301static void sun4u_irq_end(unsigned int virt_irq)
397{ 302{
398 struct irqaction **pp = irq_action + pil; 303 irq_desc_t *desc = irq_desc + virt_irq;
304 struct irq_handler_data *data = desc->handler_data;
399 305
400 while (*pp) 306 if (likely(data))
401 pp = &((*pp)->next); 307 upa_writel(ICLR_IDLE, data->iclr);
402 *pp = action;
403} 308}
404 309
405static struct irqaction *get_action_slot(struct ino_bucket *bucket) 310static void sun4v_irq_enable(unsigned int virt_irq)
406{ 311{
407 struct irq_desc *desc = bucket->irq_info; 312 struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
408 int max_irq, i; 313 unsigned int ino = bucket - &ivector_table[0];
409 314
410 max_irq = 1; 315 if (likely(bucket)) {
411 if (bucket->flags & IBF_PCI) 316 unsigned long cpuid;
412 max_irq = MAX_IRQ_DESC_ACTION; 317 int err;
413 for (i = 0; i < max_irq; i++) {
414 struct irqaction *p = &desc->action[i];
415 u32 mask = (1 << i);
416 318
417 if (desc->action_active_mask & mask) 319 cpuid = irq_choose_cpu(virt_irq);
418 continue;
419 320
420 desc->action_active_mask |= mask; 321 err = sun4v_intr_settarget(ino, cpuid);
421 return p; 322 if (err != HV_EOK)
323 printk("sun4v_intr_settarget(%x,%lu): err(%d)\n",
324 ino, cpuid, err);
325 err = sun4v_intr_setenabled(ino, HV_INTR_ENABLED);
326 if (err != HV_EOK)
327 printk("sun4v_intr_setenabled(%x): err(%d)\n",
328 ino, err);
422 } 329 }
423 return NULL;
424} 330}
425 331
426int request_irq(unsigned int irq, irqreturn_t (*handler)(int, void *, struct pt_regs *), 332static void sun4v_irq_disable(unsigned int virt_irq)
427 unsigned long irqflags, const char *name, void *dev_id)
428{ 333{
429 struct irqaction *action; 334 struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
430 struct ino_bucket *bucket = __bucket(irq); 335 unsigned int ino = bucket - &ivector_table[0];
431 unsigned long flags;
432 int pending = 0;
433
434 if (unlikely(!handler))
435 return -EINVAL;
436
437 if (unlikely(!bucket->irq_info))
438 return -ENODEV;
439
440 if ((bucket != &pil0_dummy_bucket) && (irqflags & SA_SAMPLE_RANDOM)) {
441 /*
442 * This function might sleep, we want to call it first,
443 * outside of the atomic block. In SA_STATIC_ALLOC case,
444 * random driver's kmalloc will fail, but it is safe.
445 * If already initialized, random driver will not reinit.
446 * Yes, this might clear the entropy pool if the wrong
447 * driver is attempted to be loaded, without actually
448 * installing a new handler, but is this really a problem,
449 * only the sysadmin is able to do this.
450 */
451 rand_initialize_irq(irq);
452 }
453
454 spin_lock_irqsave(&irq_action_lock, flags);
455
456 if (check_irq_sharing(bucket->pil, irqflags)) {
457 spin_unlock_irqrestore(&irq_action_lock, flags);
458 return -EBUSY;
459 }
460 336
461 action = get_action_slot(bucket); 337 if (likely(bucket)) {
462 if (!action) { 338 int err;
463 spin_unlock_irqrestore(&irq_action_lock, flags);
464 return -ENOMEM;
465 }
466 339
467 bucket->flags |= IBF_ACTIVE; 340 err = sun4v_intr_setenabled(ino, HV_INTR_DISABLED);
468 pending = 0; 341 if (err != HV_EOK)
469 if (bucket != &pil0_dummy_bucket) { 342 printk("sun4v_intr_setenabled(%x): "
470 pending = bucket->pending; 343 "err(%d)\n", ino, err);
471 if (pending)
472 bucket->pending = 0;
473 } 344 }
345}
474 346
475 action->handler = handler; 347static void sun4v_irq_end(unsigned int virt_irq)
476 action->flags = irqflags; 348{
477 action->name = name; 349 struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
478 action->next = NULL; 350 unsigned int ino = bucket - &ivector_table[0];
479 action->dev_id = dev_id;
480 put_ino_in_irqaction(action, irq);
481 put_smpaff_in_irqaction(action, CPU_MASK_NONE);
482
483 append_irq_action(bucket->pil, action);
484 351
485 enable_irq(irq); 352 if (likely(bucket)) {
353 int err;
486 354
487 /* We ate the IVEC already, this makes sure it does not get lost. */ 355 err = sun4v_intr_setstate(ino, HV_INTR_STATE_IDLE);
488 if (pending) { 356 if (err != HV_EOK)
489 atomic_bucket_insert(bucket); 357 printk("sun4v_intr_setstate(%x): "
490 set_softint(1 << bucket->pil); 358 "err(%d)\n", ino, err);
491 } 359 }
360}
492 361
493 spin_unlock_irqrestore(&irq_action_lock, flags); 362static void run_pre_handler(unsigned int virt_irq)
494 363{
495 if (bucket != &pil0_dummy_bucket) 364 struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
496 register_irq_proc(__irq_ino(irq)); 365 irq_desc_t *desc = irq_desc + virt_irq;
366 struct irq_handler_data *data = desc->handler_data;
497 367
498#ifdef CONFIG_SMP 368 if (likely(data->pre_handler)) {
499 distribute_irqs(); 369 data->pre_handler(__irq_ino(__irq(bucket)),
500#endif 370 data->pre_handler_arg1,
501 return 0; 371 data->pre_handler_arg2);
372 }
502} 373}
503 374
504EXPORT_SYMBOL(request_irq); 375static struct hw_interrupt_type sun4u_irq = {
376 .typename = "sun4u",
377 .enable = sun4u_irq_enable,
378 .disable = sun4u_irq_disable,
379 .end = sun4u_irq_end,
380};
505 381
506static struct irqaction *unlink_irq_action(unsigned int irq, void *dev_id) 382static struct hw_interrupt_type sun4u_irq_ack = {
507{ 383 .typename = "sun4u+ack",
508 struct ino_bucket *bucket = __bucket(irq); 384 .enable = sun4u_irq_enable,
509 struct irqaction *action, **pp; 385 .disable = sun4u_irq_disable,
386 .ack = run_pre_handler,
387 .end = sun4u_irq_end,
388};
510 389
511 pp = irq_action + bucket->pil; 390static struct hw_interrupt_type sun4v_irq = {
512 action = *pp; 391 .typename = "sun4v",
513 if (unlikely(!action)) 392 .enable = sun4v_irq_enable,
514 return NULL; 393 .disable = sun4v_irq_disable,
394 .end = sun4v_irq_end,
395};
515 396
516 if (unlikely(!action->handler)) { 397static struct hw_interrupt_type sun4v_irq_ack = {
517 printk("Freeing free IRQ %d\n", bucket->pil); 398 .typename = "sun4v+ack",
518 return NULL; 399 .enable = sun4v_irq_enable,
519 } 400 .disable = sun4v_irq_disable,
401 .ack = run_pre_handler,
402 .end = sun4v_irq_end,
403};
520 404
521 while (action && action->dev_id != dev_id) { 405void irq_install_pre_handler(int virt_irq,
522 pp = &action->next; 406 void (*func)(unsigned int, void *, void *),
523 action = *pp; 407 void *arg1, void *arg2)
524 } 408{
409 irq_desc_t *desc = irq_desc + virt_irq;
410 struct irq_handler_data *data = desc->handler_data;
525 411
526 if (likely(action)) 412 data->pre_handler = func;
527 *pp = action->next; 413 data->pre_handler_arg1 = arg1;
414 data->pre_handler_arg2 = arg2;
528 415
529 return action; 416 desc->handler = (desc->handler == &sun4u_irq ?
417 &sun4u_irq_ack : &sun4v_irq_ack);
530} 418}
531 419
532void free_irq(unsigned int irq, void *dev_id) 420unsigned int build_irq(int inofixup, unsigned long iclr, unsigned long imap)
533{ 421{
534 struct irqaction *action;
535 struct ino_bucket *bucket; 422 struct ino_bucket *bucket;
536 unsigned long flags; 423 struct irq_handler_data *data;
424 irq_desc_t *desc;
425 int ino;
537 426
538 spin_lock_irqsave(&irq_action_lock, flags); 427 BUG_ON(tlb_type == hypervisor);
539 428
540 action = unlink_irq_action(irq, dev_id); 429 ino = (upa_readl(imap) & (IMAP_IGN | IMAP_INO)) + inofixup;
430 bucket = &ivector_table[ino];
431 if (!bucket->virt_irq) {
432 bucket->virt_irq = virt_irq_alloc(__irq(bucket));
433 irq_desc[bucket->virt_irq].handler = &sun4u_irq;
434 }
541 435
542 spin_unlock_irqrestore(&irq_action_lock, flags); 436 desc = irq_desc + bucket->virt_irq;
437 if (unlikely(desc->handler_data))
438 goto out;
543 439
544 if (unlikely(!action)) 440 data = kzalloc(sizeof(struct irq_handler_data), GFP_ATOMIC);
545 return; 441 if (unlikely(!data)) {
442 prom_printf("IRQ: kzalloc(irq_handler_data) failed.\n");
443 prom_halt();
444 }
445 desc->handler_data = data;
546 446
547 synchronize_irq(irq); 447 data->imap = imap;
448 data->iclr = iclr;
548 449
549 spin_lock_irqsave(&irq_action_lock, flags); 450out:
451 return bucket->virt_irq;
452}
550 453
551 bucket = __bucket(irq); 454unsigned int sun4v_build_irq(u32 devhandle, unsigned int devino)
552 if (bucket != &pil0_dummy_bucket) { 455{
553 struct irq_desc *desc = bucket->irq_info; 456 struct ino_bucket *bucket;
554 int ent, i; 457 struct irq_handler_data *data;
458 unsigned long sysino;
459 irq_desc_t *desc;
555 460
556 for (i = 0; i < MAX_IRQ_DESC_ACTION; i++) { 461 BUG_ON(tlb_type != hypervisor);
557 struct irqaction *p = &desc->action[i];
558 462
559 if (p == action) { 463 sysino = sun4v_devino_to_sysino(devhandle, devino);
560 desc->action_active_mask &= ~(1 << i); 464 bucket = &ivector_table[sysino];
561 break; 465 if (!bucket->virt_irq) {
562 } 466 bucket->virt_irq = virt_irq_alloc(__irq(bucket));
563 } 467 irq_desc[bucket->virt_irq].handler = &sun4v_irq;
468 }
564 469
565 if (!desc->action_active_mask) { 470 desc = irq_desc + bucket->virt_irq;
566 unsigned long imap = bucket->imap; 471 if (unlikely(desc->handler_data))
567 472 goto out;
568 /* This unique interrupt source is now inactive. */
569 bucket->flags &= ~IBF_ACTIVE;
570
571 /* See if any other buckets share this bucket's IMAP
572 * and are still active.
573 */
574 for (ent = 0; ent < NUM_IVECS; ent++) {
575 struct ino_bucket *bp = &ivector_table[ent];
576 if (bp != bucket &&
577 bp->imap == imap &&
578 (bp->flags & IBF_ACTIVE) != 0)
579 break;
580 }
581 473
582 /* Only disable when no other sub-irq levels of 474 data = kzalloc(sizeof(struct irq_handler_data), GFP_ATOMIC);
583 * the same IMAP are active. 475 if (unlikely(!data)) {
584 */ 476 prom_printf("IRQ: kzalloc(irq_handler_data) failed.\n");
585 if (ent == NUM_IVECS) 477 prom_halt();
586 disable_irq(irq);
587 }
588 } 478 }
479 desc->handler_data = data;
589 480
590 spin_unlock_irqrestore(&irq_action_lock, flags); 481 /* Catch accidental accesses to these things. IMAP/ICLR handling
591} 482 * is done by hypervisor calls on sun4v platforms, not by direct
483 * register accesses.
484 */
485 data->imap = ~0UL;
486 data->iclr = ~0UL;
592 487
593EXPORT_SYMBOL(free_irq); 488out:
489 return bucket->virt_irq;
490}
594 491
595#ifdef CONFIG_SMP 492void hw_resend_irq(struct hw_interrupt_type *handler, unsigned int virt_irq)
596void synchronize_irq(unsigned int irq)
597{ 493{
598 struct ino_bucket *bucket = __bucket(irq); 494 struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
599 495 unsigned long pstate;
600#if 0 496 unsigned int *ent;
601 /* The following is how I wish I could implement this. 497
602 * Unfortunately the ICLR registers are read-only, you can 498 __asm__ __volatile__("rdpr %%pstate, %0" : "=r" (pstate));
603 * only write ICLR_foo values to them. To get the current 499 __asm__ __volatile__("wrpr %0, %1, %%pstate"
604 * IRQ status you would need to get at the IRQ diag registers 500 : : "r" (pstate), "i" (PSTATE_IE));
605 * in the PCI/SBUS controller and the layout of those vary 501 ent = irq_work(smp_processor_id());
606 * from one controller to the next, sigh... -DaveM 502 bucket->irq_chain = *ent;
607 */ 503 *ent = __irq(bucket);
608 unsigned long iclr = bucket->iclr; 504 set_softint(1 << PIL_DEVICE_IRQ);
609 505 __asm__ __volatile__("wrpr %0, 0x0, %%pstate" : : "r" (pstate));
610 while (1) {
611 u32 tmp = upa_readl(iclr);
612
613 if (tmp == ICLR_TRANSMIT ||
614 tmp == ICLR_PENDING) {
615 cpu_relax();
616 continue;
617 }
618 break;
619 }
620#else
621 /* So we have to do this with a INPROGRESS bit just like x86. */
622 while (bucket->flags & IBF_INPROGRESS)
623 cpu_relax();
624#endif
625} 506}
626#endif /* CONFIG_SMP */
627 507
628static void process_bucket(int irq, struct ino_bucket *bp, struct pt_regs *regs) 508void ack_bad_irq(unsigned int virt_irq)
629{ 509{
630 struct irq_desc *desc = bp->irq_info; 510 struct ino_bucket *bucket = virt_irq_to_bucket(virt_irq);
631 unsigned char flags = bp->flags; 511 unsigned int ino = 0xdeadbeef;
632 u32 action_mask, i;
633 int random;
634 512
635 bp->flags |= IBF_INPROGRESS; 513 if (bucket)
514 ino = bucket - &ivector_table[0];
636 515
637 if (unlikely(!(flags & IBF_ACTIVE))) { 516 printk(KERN_CRIT "Unexpected IRQ from ino[%x] virt_irq[%u]\n",
638 bp->pending = 1; 517 ino, virt_irq);
639 goto out; 518}
640 }
641
642 if (desc->pre_handler)
643 desc->pre_handler(bp,
644 desc->pre_handler_arg1,
645 desc->pre_handler_arg2);
646 519
647 action_mask = desc->action_active_mask; 520#ifndef CONFIG_SMP
648 random = 0; 521extern irqreturn_t timer_interrupt(int, void *, struct pt_regs *);
649 for (i = 0; i < MAX_IRQ_DESC_ACTION; i++) {
650 struct irqaction *p = &desc->action[i];
651 u32 mask = (1 << i);
652 522
653 if (!(action_mask & mask)) 523void timer_irq(int irq, struct pt_regs *regs)
654 continue; 524{
525 unsigned long clr_mask = 1 << irq;
526 unsigned long tick_mask = tick_ops->softint_mask;
655 527
656 action_mask &= ~mask; 528 if (get_softint() & tick_mask) {
529 irq = 0;
530 clr_mask = tick_mask;
531 }
532 clear_softint(clr_mask);
657 533
658 if (p->handler(__irq(bp), p->dev_id, regs) == IRQ_HANDLED) 534 irq_enter();
659 random |= p->flags;
660 535
661 if (!action_mask) 536 kstat_this_cpu.irqs[0]++;
662 break; 537 timer_interrupt(irq, NULL, regs);
663 }
664 if (bp->pil != 0) {
665 if (tlb_type == hypervisor) {
666 unsigned int ino = __irq_ino(bp);
667 int err;
668
669 err = sun4v_intr_setstate(ino, HV_INTR_STATE_IDLE);
670 if (err != HV_EOK)
671 printk("sun4v_intr_setstate(%x): "
672 "err(%d)\n", ino, err);
673 } else {
674 upa_writel(ICLR_IDLE, bp->iclr);
675 }
676 538
677 /* Test and add entropy */ 539 irq_exit();
678 if (random & SA_SAMPLE_RANDOM)
679 add_interrupt_randomness(irq);
680 }
681out:
682 bp->flags &= ~IBF_INPROGRESS;
683} 540}
541#endif
684 542
685void handler_irq(int irq, struct pt_regs *regs) 543void handler_irq(int irq, struct pt_regs *regs)
686{ 544{
687 struct ino_bucket *bp; 545 struct ino_bucket *bucket;
688 int cpu = smp_processor_id();
689
690#ifndef CONFIG_SMP
691 /*
692 * Check for TICK_INT on level 14 softint.
693 */
694 {
695 unsigned long clr_mask = 1 << irq;
696 unsigned long tick_mask = tick_ops->softint_mask;
697 546
698 if ((irq == 14) && (get_softint() & tick_mask)) {
699 irq = 0;
700 clr_mask = tick_mask;
701 }
702 clear_softint(clr_mask);
703 }
704#else
705 clear_softint(1 << irq); 547 clear_softint(1 << irq);
706#endif
707 548
708 irq_enter(); 549 irq_enter();
709 kstat_this_cpu.irqs[irq]++;
710 550
711 /* Sliiiick... */ 551 /* Sliiiick... */
712#ifndef CONFIG_SMP 552 bucket = __bucket(xchg32(irq_work(smp_processor_id()), 0));
713 bp = ((irq != 0) ? 553 while (bucket) {
714 __bucket(xchg32(irq_work(cpu, irq), 0)) : 554 struct ino_bucket *next = __bucket(bucket->irq_chain);
715 &pil0_dummy_bucket);
716#else
717 bp = __bucket(xchg32(irq_work(cpu, irq), 0));
718#endif
719 while (bp) {
720 struct ino_bucket *nbp = __bucket(bp->irq_chain);
721 555
722 bp->irq_chain = 0; 556 bucket->irq_chain = 0;
723 process_bucket(irq, bp, regs); 557 __do_IRQ(bucket->virt_irq, regs);
724 bp = nbp; 558
559 bucket = next;
725 } 560 }
561
726 irq_exit(); 562 irq_exit();
727} 563}
728 564
@@ -787,81 +623,6 @@ main_interrupt:
787EXPORT_SYMBOL(sparc_floppy_irq); 623EXPORT_SYMBOL(sparc_floppy_irq);
788#endif 624#endif
789 625
790/* We really don't need these at all on the Sparc. We only have
791 * stubs here because they are exported to modules.
792 */
793unsigned long probe_irq_on(void)
794{
795 return 0;
796}
797
798EXPORT_SYMBOL(probe_irq_on);
799
800int probe_irq_off(unsigned long mask)
801{
802 return 0;
803}
804
805EXPORT_SYMBOL(probe_irq_off);
806
807#ifdef CONFIG_SMP
808static int retarget_one_irq(struct irqaction *p, int goal_cpu)
809{
810 struct ino_bucket *bucket = get_ino_in_irqaction(p) + ivector_table;
811
812 while (!cpu_online(goal_cpu)) {
813 if (++goal_cpu >= NR_CPUS)
814 goal_cpu = 0;
815 }
816
817 if (tlb_type == hypervisor) {
818 unsigned int ino = __irq_ino(bucket);
819
820 sun4v_intr_settarget(ino, goal_cpu);
821 sun4v_intr_setenabled(ino, HV_INTR_ENABLED);
822 } else {
823 unsigned long imap = bucket->imap;
824 unsigned int tid = sun4u_compute_tid(imap, goal_cpu);
825
826 upa_writel(tid | IMAP_VALID, imap);
827 }
828
829 do {
830 if (++goal_cpu >= NR_CPUS)
831 goal_cpu = 0;
832 } while (!cpu_online(goal_cpu));
833
834 return goal_cpu;
835}
836
837/* Called from request_irq. */
838static void distribute_irqs(void)
839{
840 unsigned long flags;
841 int cpu, level;
842
843 spin_lock_irqsave(&irq_action_lock, flags);
844 cpu = 0;
845
846 /*
847 * Skip the timer at [0], and very rare error/power intrs at [15].
848 * Also level [12], it causes problems on Ex000 systems.
849 */
850 for (level = 1; level < NR_IRQS; level++) {
851 struct irqaction *p = irq_action[level];
852
853 if (level == 12)
854 continue;
855
856 while(p) {
857 cpu = retarget_one_irq(p, cpu);
858 p = p->next;
859 }
860 }
861 spin_unlock_irqrestore(&irq_action_lock, flags);
862}
863#endif
864
865struct sun5_timer { 626struct sun5_timer {
866 u64 count0; 627 u64 count0;
867 u64 limit0; 628 u64 limit0;
@@ -929,7 +690,7 @@ void init_irqwork_curcpu(void)
929{ 690{
930 int cpu = hard_smp_processor_id(); 691 int cpu = hard_smp_processor_id();
931 692
932 memset(__irq_work + cpu, 0, sizeof(struct irq_work_struct)); 693 trap_block[cpu].irq_worklist = 0;
933} 694}
934 695
935static void __cpuinit register_one_mondo(unsigned long paddr, unsigned long type) 696static void __cpuinit register_one_mondo(unsigned long paddr, unsigned long type)
@@ -1037,6 +798,10 @@ void __cpuinit sun4v_init_mondo_queues(int use_bootmem, int cpu, int alloc, int
1037 } 798 }
1038} 799}
1039 800
801static struct irqaction timer_irq_action = {
802 .name = "timer",
803};
804
1040/* Only invoked on boot processor. */ 805/* Only invoked on boot processor. */
1041void __init init_IRQ(void) 806void __init init_IRQ(void)
1042{ 807{
@@ -1064,109 +829,6 @@ void __init init_IRQ(void)
1064 : /* No outputs */ 829 : /* No outputs */
1065 : "i" (PSTATE_IE) 830 : "i" (PSTATE_IE)
1066 : "g1"); 831 : "g1");
1067}
1068 832
1069static struct proc_dir_entry * root_irq_dir; 833 irq_desc[0].action = &timer_irq_action;
1070static struct proc_dir_entry * irq_dir [NUM_IVECS];
1071
1072#ifdef CONFIG_SMP
1073
1074static int irq_affinity_read_proc (char *page, char **start, off_t off,
1075 int count, int *eof, void *data)
1076{
1077 struct ino_bucket *bp = ivector_table + (long)data;
1078 struct irq_desc *desc = bp->irq_info;
1079 struct irqaction *ap = desc->action;
1080 cpumask_t mask;
1081 int len;
1082
1083 mask = get_smpaff_in_irqaction(ap);
1084 if (cpus_empty(mask))
1085 mask = cpu_online_map;
1086
1087 len = cpumask_scnprintf(page, count, mask);
1088 if (count - len < 2)
1089 return -EINVAL;
1090 len += sprintf(page + len, "\n");
1091 return len;
1092}
1093
1094static inline void set_intr_affinity(int irq, cpumask_t hw_aff)
1095{
1096 struct ino_bucket *bp = ivector_table + irq;
1097 struct irq_desc *desc = bp->irq_info;
1098 struct irqaction *ap = desc->action;
1099
1100 /* Users specify affinity in terms of hw cpu ids.
1101 * As soon as we do this, handler_irq() might see and take action.
1102 */
1103 put_smpaff_in_irqaction(ap, hw_aff);
1104
1105 /* Migration is simply done by the next cpu to service this
1106 * interrupt.
1107 */
1108}
1109
1110static int irq_affinity_write_proc (struct file *file, const char __user *buffer,
1111 unsigned long count, void *data)
1112{
1113 int irq = (long) data, full_count = count, err;
1114 cpumask_t new_value;
1115
1116 err = cpumask_parse(buffer, count, new_value);
1117
1118 /*
1119 * Do not allow disabling IRQs completely - it's a too easy
1120 * way to make the system unusable accidentally :-) At least
1121 * one online CPU still has to be targeted.
1122 */
1123 cpus_and(new_value, new_value, cpu_online_map);
1124 if (cpus_empty(new_value))
1125 return -EINVAL;
1126
1127 set_intr_affinity(irq, new_value);
1128
1129 return full_count;
1130} 834}
1131
1132#endif
1133
1134#define MAX_NAMELEN 10
1135
1136static void register_irq_proc (unsigned int irq)
1137{
1138 char name [MAX_NAMELEN];
1139
1140 if (!root_irq_dir || irq_dir[irq])
1141 return;
1142
1143 memset(name, 0, MAX_NAMELEN);
1144 sprintf(name, "%x", irq);
1145
1146 /* create /proc/irq/1234 */
1147 irq_dir[irq] = proc_mkdir(name, root_irq_dir);
1148
1149#ifdef CONFIG_SMP
1150 /* XXX SMP affinity not supported on starfire yet. */
1151 if (this_is_starfire == 0) {
1152 struct proc_dir_entry *entry;
1153
1154 /* create /proc/irq/1234/smp_affinity */
1155 entry = create_proc_entry("smp_affinity", 0600, irq_dir[irq]);
1156
1157 if (entry) {
1158 entry->nlink = 1;
1159 entry->data = (void *)(long)irq;
1160 entry->read_proc = irq_affinity_read_proc;
1161 entry->write_proc = irq_affinity_write_proc;
1162 }
1163 }
1164#endif
1165}
1166
1167void init_irq_proc (void)
1168{
1169 /* create /proc/irq */
1170 root_irq_dir = proc_mkdir("irq", NULL);
1171}
1172
diff --git a/arch/sparc64/kernel/module.c b/arch/sparc64/kernel/module.c
index 6c83e372f75d..579871527699 100644
--- a/arch/sparc64/kernel/module.c
+++ b/arch/sparc64/kernel/module.c
@@ -143,6 +143,11 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
143 location[3] = v >> 0; 143 location[3] = v >> 0;
144 break; 144 break;
145 145
146 case R_SPARC_DISP32:
147 v -= (Elf64_Addr) location;
148 *loc32 = v;
149 break;
150
146 case R_SPARC_WDISP30: 151 case R_SPARC_WDISP30:
147 v -= (Elf64_Addr) location; 152 v -= (Elf64_Addr) location;
148 *loc32 = (*loc32 & ~0x3fffffff) | 153 *loc32 = (*loc32 & ~0x3fffffff) |
diff --git a/arch/sparc64/kernel/pci.c b/arch/sparc64/kernel/pci.c
index f97ddeb105ac..9472580a4319 100644
--- a/arch/sparc64/kernel/pci.c
+++ b/arch/sparc64/kernel/pci.c
@@ -47,12 +47,6 @@ struct pci_controller_info *pci_controller_root = NULL;
47/* Each PCI controller found gets a unique index. */ 47/* Each PCI controller found gets a unique index. */
48int pci_num_controllers = 0; 48int pci_num_controllers = 0;
49 49
50/* At boot time the user can give the kernel a command
51 * line option which controls if and how PCI devices
52 * are reordered at PCI bus probing time.
53 */
54int pci_device_reorder = 0;
55
56volatile int pci_poke_in_progress; 50volatile int pci_poke_in_progress;
57volatile int pci_poke_cpu = -1; 51volatile int pci_poke_cpu = -1;
58volatile int pci_poke_faulted; 52volatile int pci_poke_faulted;
@@ -316,27 +310,6 @@ static void __init pci_scan_each_controller_bus(void)
316 p->scan_bus(p); 310 p->scan_bus(p);
317} 311}
318 312
319/* Reorder the pci_dev chain, so that onboard devices come first
320 * and then come the pluggable cards.
321 */
322static void __init pci_reorder_devs(void)
323{
324 struct list_head *pci_onboard = &pci_devices;
325 struct list_head *walk = pci_onboard->next;
326
327 while (walk != pci_onboard) {
328 struct pci_dev *pdev = pci_dev_g(walk);
329 struct list_head *walk_next = walk->next;
330
331 if (pdev->irq && (__irq_ino(pdev->irq) & 0x20)) {
332 list_del(walk);
333 list_add(walk, pci_onboard);
334 }
335
336 walk = walk_next;
337 }
338}
339
340extern void clock_probe(void); 313extern void clock_probe(void);
341extern void power_init(void); 314extern void power_init(void);
342 315
@@ -348,9 +321,6 @@ static int __init pcibios_init(void)
348 321
349 pci_scan_each_controller_bus(); 322 pci_scan_each_controller_bus();
350 323
351 if (pci_device_reorder)
352 pci_reorder_devs();
353
354 isa_init(); 324 isa_init();
355 ebus_init(); 325 ebus_init();
356 clock_probe(); 326 clock_probe();
@@ -441,14 +411,6 @@ EXPORT_SYMBOL(pcibios_bus_to_resource);
441 411
442char * __init pcibios_setup(char *str) 412char * __init pcibios_setup(char *str)
443{ 413{
444 if (!strcmp(str, "onboardfirst")) {
445 pci_device_reorder = 1;
446 return NULL;
447 }
448 if (!strcmp(str, "noreorder")) {
449 pci_device_reorder = 0;
450 return NULL;
451 }
452 return str; 414 return str;
453} 415}
454 416
diff --git a/arch/sparc64/kernel/pci_iommu.c b/arch/sparc64/kernel/pci_iommu.c
index 8efbc139769d..82e5455134c6 100644
--- a/arch/sparc64/kernel/pci_iommu.c
+++ b/arch/sparc64/kernel/pci_iommu.c
@@ -218,7 +218,7 @@ static inline void iommu_free_ctx(struct pci_iommu *iommu, int ctx)
218 * DMA for PCI device PDEV. Return non-NULL cpu-side address if 218 * DMA for PCI device PDEV. Return non-NULL cpu-side address if
219 * successful and set *DMA_ADDRP to the PCI side dma address. 219 * successful and set *DMA_ADDRP to the PCI side dma address.
220 */ 220 */
221static void *pci_4u_alloc_consistent(struct pci_dev *pdev, size_t size, dma_addr_t *dma_addrp) 221static void *pci_4u_alloc_consistent(struct pci_dev *pdev, size_t size, dma_addr_t *dma_addrp, gfp_t gfp)
222{ 222{
223 struct pcidev_cookie *pcp; 223 struct pcidev_cookie *pcp;
224 struct pci_iommu *iommu; 224 struct pci_iommu *iommu;
@@ -232,7 +232,7 @@ static void *pci_4u_alloc_consistent(struct pci_dev *pdev, size_t size, dma_addr
232 if (order >= 10) 232 if (order >= 10)
233 return NULL; 233 return NULL;
234 234
235 first_page = __get_free_pages(GFP_ATOMIC, order); 235 first_page = __get_free_pages(gfp, order);
236 if (first_page == 0UL) 236 if (first_page == 0UL)
237 return NULL; 237 return NULL;
238 memset((char *)first_page, 0, PAGE_SIZE << order); 238 memset((char *)first_page, 0, PAGE_SIZE << order);
diff --git a/arch/sparc64/kernel/pci_psycho.c b/arch/sparc64/kernel/pci_psycho.c
index d17878b145c2..24db22aa9728 100644
--- a/arch/sparc64/kernel/pci_psycho.c
+++ b/arch/sparc64/kernel/pci_psycho.c
@@ -276,82 +276,13 @@ static unsigned long __onboard_imap_off[] = {
276 ((ino & 0x20) ? (PSYCHO_ICLR_SCSI + (((ino) & 0x1f) << 3)) : \ 276 ((ino & 0x20) ? (PSYCHO_ICLR_SCSI + (((ino) & 0x1f) << 3)) : \
277 (PSYCHO_ICLR_A_SLOT0 + (((ino) & 0x1f)<<3))) 277 (PSYCHO_ICLR_A_SLOT0 + (((ino) & 0x1f)<<3)))
278 278
279/* PCI PSYCHO INO number to Sparc PIL level. */
280static unsigned char psycho_pil_table[] = {
281/*0x00*/0, 0, 0, 0, /* PCI A slot 0 Int A, B, C, D */
282/*0x04*/0, 0, 0, 0, /* PCI A slot 1 Int A, B, C, D */
283/*0x08*/0, 0, 0, 0, /* PCI A slot 2 Int A, B, C, D */
284/*0x0c*/0, 0, 0, 0, /* PCI A slot 3 Int A, B, C, D */
285/*0x10*/0, 0, 0, 0, /* PCI B slot 0 Int A, B, C, D */
286/*0x14*/0, 0, 0, 0, /* PCI B slot 1 Int A, B, C, D */
287/*0x18*/0, 0, 0, 0, /* PCI B slot 2 Int A, B, C, D */
288/*0x1c*/0, 0, 0, 0, /* PCI B slot 3 Int A, B, C, D */
289/*0x20*/5, /* SCSI */
290/*0x21*/5, /* Ethernet */
291/*0x22*/8, /* Parallel Port */
292/*0x23*/13, /* Audio Record */
293/*0x24*/14, /* Audio Playback */
294/*0x25*/15, /* PowerFail */
295/*0x26*/5, /* second SCSI */
296/*0x27*/11, /* Floppy */
297/*0x28*/5, /* Spare Hardware */
298/*0x29*/9, /* Keyboard */
299/*0x2a*/5, /* Mouse */
300/*0x2b*/12, /* Serial */
301/*0x2c*/10, /* Timer 0 */
302/*0x2d*/11, /* Timer 1 */
303/*0x2e*/15, /* Uncorrectable ECC */
304/*0x2f*/15, /* Correctable ECC */
305/*0x30*/15, /* PCI Bus A Error */
306/*0x31*/15, /* PCI Bus B Error */
307/*0x32*/15, /* Power Management */
308};
309
310static int psycho_ino_to_pil(struct pci_dev *pdev, unsigned int ino)
311{
312 int ret;
313
314 ret = psycho_pil_table[ino];
315 if (ret == 0 && pdev == NULL) {
316 ret = 5;
317 } else if (ret == 0) {
318 switch ((pdev->class >> 16) & 0xff) {
319 case PCI_BASE_CLASS_STORAGE:
320 ret = 5;
321 break;
322
323 case PCI_BASE_CLASS_NETWORK:
324 ret = 6;
325 break;
326
327 case PCI_BASE_CLASS_DISPLAY:
328 ret = 9;
329 break;
330
331 case PCI_BASE_CLASS_MULTIMEDIA:
332 case PCI_BASE_CLASS_MEMORY:
333 case PCI_BASE_CLASS_BRIDGE:
334 case PCI_BASE_CLASS_SERIAL:
335 ret = 10;
336 break;
337
338 default:
339 ret = 5;
340 break;
341 };
342 }
343
344 return ret;
345}
346
347static unsigned int psycho_irq_build(struct pci_pbm_info *pbm, 279static unsigned int psycho_irq_build(struct pci_pbm_info *pbm,
348 struct pci_dev *pdev, 280 struct pci_dev *pdev,
349 unsigned int ino) 281 unsigned int ino)
350{ 282{
351 struct ino_bucket *bucket;
352 unsigned long imap, iclr; 283 unsigned long imap, iclr;
353 unsigned long imap_off, iclr_off; 284 unsigned long imap_off, iclr_off;
354 int pil, inofixup = 0; 285 int inofixup = 0;
355 286
356 ino &= PCI_IRQ_INO; 287 ino &= PCI_IRQ_INO;
357 if (ino < PSYCHO_ONBOARD_IRQ_BASE) { 288 if (ino < PSYCHO_ONBOARD_IRQ_BASE) {
@@ -367,11 +298,6 @@ static unsigned int psycho_irq_build(struct pci_pbm_info *pbm,
367 } 298 }
368 299
369 /* Now build the IRQ bucket. */ 300 /* Now build the IRQ bucket. */
370 pil = psycho_ino_to_pil(pdev, ino);
371
372 if (PIL_RESERVED(pil))
373 BUG();
374
375 imap = pbm->controller_regs + imap_off; 301 imap = pbm->controller_regs + imap_off;
376 imap += 4; 302 imap += 4;
377 303
@@ -382,10 +308,7 @@ static unsigned int psycho_irq_build(struct pci_pbm_info *pbm,
382 if ((ino & 0x20) == 0) 308 if ((ino & 0x20) == 0)
383 inofixup = ino & 0x03; 309 inofixup = ino & 0x03;
384 310
385 bucket = __bucket(build_irq(pil, inofixup, iclr, imap)); 311 return build_irq(inofixup, iclr, imap);
386 bucket->flags |= IBF_PCI;
387
388 return __irq(bucket);
389} 312}
390 313
391/* PSYCHO error handling support. */ 314/* PSYCHO error handling support. */
diff --git a/arch/sparc64/kernel/pci_sabre.c b/arch/sparc64/kernel/pci_sabre.c
index f67bb7f078cf..b7d997b55f0a 100644
--- a/arch/sparc64/kernel/pci_sabre.c
+++ b/arch/sparc64/kernel/pci_sabre.c
@@ -523,78 +523,6 @@ static unsigned long __onboard_imap_off[] = {
523 ((ino & 0x20) ? (SABRE_ICLR_SCSI + (((ino) & 0x1f) << 3)) : \ 523 ((ino & 0x20) ? (SABRE_ICLR_SCSI + (((ino) & 0x1f) << 3)) : \
524 (SABRE_ICLR_A_SLOT0 + (((ino) & 0x1f)<<3))) 524 (SABRE_ICLR_A_SLOT0 + (((ino) & 0x1f)<<3)))
525 525
526/* PCI SABRE INO number to Sparc PIL level. */
527static unsigned char sabre_pil_table[] = {
528/*0x00*/0, 0, 0, 0, /* PCI A slot 0 Int A, B, C, D */
529/*0x04*/0, 0, 0, 0, /* PCI A slot 1 Int A, B, C, D */
530/*0x08*/0, 0, 0, 0, /* PCI A slot 2 Int A, B, C, D */
531/*0x0c*/0, 0, 0, 0, /* PCI A slot 3 Int A, B, C, D */
532/*0x10*/0, 0, 0, 0, /* PCI B slot 0 Int A, B, C, D */
533/*0x14*/0, 0, 0, 0, /* PCI B slot 1 Int A, B, C, D */
534/*0x18*/0, 0, 0, 0, /* PCI B slot 2 Int A, B, C, D */
535/*0x1c*/0, 0, 0, 0, /* PCI B slot 3 Int A, B, C, D */
536/*0x20*/5, /* SCSI */
537/*0x21*/5, /* Ethernet */
538/*0x22*/8, /* Parallel Port */
539/*0x23*/13, /* Audio Record */
540/*0x24*/14, /* Audio Playback */
541/*0x25*/15, /* PowerFail */
542/*0x26*/5, /* second SCSI */
543/*0x27*/11, /* Floppy */
544/*0x28*/5, /* Spare Hardware */
545/*0x29*/9, /* Keyboard */
546/*0x2a*/5, /* Mouse */
547/*0x2b*/12, /* Serial */
548/*0x2c*/10, /* Timer 0 */
549/*0x2d*/11, /* Timer 1 */
550/*0x2e*/15, /* Uncorrectable ECC */
551/*0x2f*/15, /* Correctable ECC */
552/*0x30*/15, /* PCI Bus A Error */
553/*0x31*/15, /* PCI Bus B Error */
554/*0x32*/15, /* Power Management */
555};
556
557static int sabre_ino_to_pil(struct pci_dev *pdev, unsigned int ino)
558{
559 int ret;
560
561 if (pdev &&
562 pdev->vendor == PCI_VENDOR_ID_SUN &&
563 pdev->device == PCI_DEVICE_ID_SUN_RIO_USB)
564 return 9;
565
566 ret = sabre_pil_table[ino];
567 if (ret == 0 && pdev == NULL) {
568 ret = 5;
569 } else if (ret == 0) {
570 switch ((pdev->class >> 16) & 0xff) {
571 case PCI_BASE_CLASS_STORAGE:
572 ret = 5;
573 break;
574
575 case PCI_BASE_CLASS_NETWORK:
576 ret = 6;
577 break;
578
579 case PCI_BASE_CLASS_DISPLAY:
580 ret = 9;
581 break;
582
583 case PCI_BASE_CLASS_MULTIMEDIA:
584 case PCI_BASE_CLASS_MEMORY:
585 case PCI_BASE_CLASS_BRIDGE:
586 case PCI_BASE_CLASS_SERIAL:
587 ret = 10;
588 break;
589
590 default:
591 ret = 5;
592 break;
593 };
594 }
595 return ret;
596}
597
598/* When a device lives behind a bridge deeper in the PCI bus topology 526/* When a device lives behind a bridge deeper in the PCI bus topology
599 * than APB, a special sequence must run to make sure all pending DMA 527 * than APB, a special sequence must run to make sure all pending DMA
600 * transfers at the time of IRQ delivery are visible in the coherency 528 * transfers at the time of IRQ delivery are visible in the coherency
@@ -602,7 +530,7 @@ static int sabre_ino_to_pil(struct pci_dev *pdev, unsigned int ino)
602 * side of the non-APB bridge, then perform a read of Sabre's DMA 530 * side of the non-APB bridge, then perform a read of Sabre's DMA
603 * write-sync register. 531 * write-sync register.
604 */ 532 */
605static void sabre_wsync_handler(struct ino_bucket *bucket, void *_arg1, void *_arg2) 533static void sabre_wsync_handler(unsigned int ino, void *_arg1, void *_arg2)
606{ 534{
607 struct pci_dev *pdev = _arg1; 535 struct pci_dev *pdev = _arg1;
608 unsigned long sync_reg = (unsigned long) _arg2; 536 unsigned long sync_reg = (unsigned long) _arg2;
@@ -616,10 +544,10 @@ static unsigned int sabre_irq_build(struct pci_pbm_info *pbm,
616 struct pci_dev *pdev, 544 struct pci_dev *pdev,
617 unsigned int ino) 545 unsigned int ino)
618{ 546{
619 struct ino_bucket *bucket;
620 unsigned long imap, iclr; 547 unsigned long imap, iclr;
621 unsigned long imap_off, iclr_off; 548 unsigned long imap_off, iclr_off;
622 int pil, inofixup = 0; 549 int inofixup = 0;
550 int virt_irq;
623 551
624 ino &= PCI_IRQ_INO; 552 ino &= PCI_IRQ_INO;
625 if (ino < SABRE_ONBOARD_IRQ_BASE) { 553 if (ino < SABRE_ONBOARD_IRQ_BASE) {
@@ -635,11 +563,6 @@ static unsigned int sabre_irq_build(struct pci_pbm_info *pbm,
635 } 563 }
636 564
637 /* Now build the IRQ bucket. */ 565 /* Now build the IRQ bucket. */
638 pil = sabre_ino_to_pil(pdev, ino);
639
640 if (PIL_RESERVED(pil))
641 BUG();
642
643 imap = pbm->controller_regs + imap_off; 566 imap = pbm->controller_regs + imap_off;
644 imap += 4; 567 imap += 4;
645 568
@@ -650,23 +573,23 @@ static unsigned int sabre_irq_build(struct pci_pbm_info *pbm,
650 if ((ino & 0x20) == 0) 573 if ((ino & 0x20) == 0)
651 inofixup = ino & 0x03; 574 inofixup = ino & 0x03;
652 575
653 bucket = __bucket(build_irq(pil, inofixup, iclr, imap)); 576 virt_irq = build_irq(inofixup, iclr, imap);
654 bucket->flags |= IBF_PCI;
655 577
656 if (pdev) { 578 if (pdev) {
657 struct pcidev_cookie *pcp = pdev->sysdata; 579 struct pcidev_cookie *pcp = pdev->sysdata;
658 580
659 if (pdev->bus->number != pcp->pbm->pci_first_busno) { 581 if (pdev->bus->number != pcp->pbm->pci_first_busno) {
660 struct pci_controller_info *p = pcp->pbm->parent; 582 struct pci_controller_info *p = pcp->pbm->parent;
661 struct irq_desc *d = bucket->irq_info;
662 583
663 d->pre_handler = sabre_wsync_handler; 584 irq_install_pre_handler(virt_irq,
664 d->pre_handler_arg1 = pdev; 585 sabre_wsync_handler,
665 d->pre_handler_arg2 = (void *) 586 pdev,
666 p->pbm_A.controller_regs + SABRE_WRSYNC; 587 (void *)
588 p->pbm_A.controller_regs +
589 SABRE_WRSYNC);
667 } 590 }
668 } 591 }
669 return __irq(bucket); 592 return virt_irq;
670} 593}
671 594
672/* SABRE error handling support. */ 595/* SABRE error handling support. */
diff --git a/arch/sparc64/kernel/pci_schizo.c b/arch/sparc64/kernel/pci_schizo.c
index 7fe4de03ac2e..cc662e915d32 100644
--- a/arch/sparc64/kernel/pci_schizo.c
+++ b/arch/sparc64/kernel/pci_schizo.c
@@ -232,105 +232,10 @@ static unsigned long schizo_iclr_offset(unsigned long ino)
232 return SCHIZO_ICLR_BASE + (ino * 8UL); 232 return SCHIZO_ICLR_BASE + (ino * 8UL);
233} 233}
234 234
235/* PCI SCHIZO INO number to Sparc PIL level. This table only matters for 235static void tomatillo_wsync_handler(unsigned int ino, void *_arg1, void *_arg2)
236 * INOs which will not have an associated PCI device struct, ie. onboard
237 * EBUS devices and PCI controller internal error interrupts.
238 */
239static unsigned char schizo_pil_table[] = {
240/*0x00*/0, 0, 0, 0, /* PCI slot 0 Int A, B, C, D */
241/*0x04*/0, 0, 0, 0, /* PCI slot 1 Int A, B, C, D */
242/*0x08*/0, 0, 0, 0, /* PCI slot 2 Int A, B, C, D */
243/*0x0c*/0, 0, 0, 0, /* PCI slot 3 Int A, B, C, D */
244/*0x10*/0, 0, 0, 0, /* PCI slot 4 Int A, B, C, D */
245/*0x14*/0, 0, 0, 0, /* PCI slot 5 Int A, B, C, D */
246/*0x18*/5, /* SCSI */
247/*0x19*/5, /* second SCSI */
248/*0x1a*/0, /* UNKNOWN */
249/*0x1b*/0, /* UNKNOWN */
250/*0x1c*/8, /* Parallel */
251/*0x1d*/5, /* Ethernet */
252/*0x1e*/8, /* Firewire-1394 */
253/*0x1f*/9, /* USB */
254/*0x20*/13, /* Audio Record */
255/*0x21*/14, /* Audio Playback */
256/*0x22*/12, /* Serial */
257/*0x23*/5, /* EBUS I2C */
258/*0x24*/10, /* RTC Clock */
259/*0x25*/11, /* Floppy */
260/*0x26*/0, /* UNKNOWN */
261/*0x27*/0, /* UNKNOWN */
262/*0x28*/0, /* UNKNOWN */
263/*0x29*/0, /* UNKNOWN */
264/*0x2a*/10, /* UPA 1 */
265/*0x2b*/10, /* UPA 2 */
266/*0x2c*/0, /* UNKNOWN */
267/*0x2d*/0, /* UNKNOWN */
268/*0x2e*/0, /* UNKNOWN */
269/*0x2f*/0, /* UNKNOWN */
270/*0x30*/15, /* Uncorrectable ECC */
271/*0x31*/15, /* Correctable ECC */
272/*0x32*/15, /* PCI Bus A Error */
273/*0x33*/15, /* PCI Bus B Error */
274/*0x34*/15, /* Safari Bus Error */
275/*0x35*/0, /* Reserved */
276/*0x36*/0, /* Reserved */
277/*0x37*/0, /* Reserved */
278/*0x38*/0, /* Reserved for NewLink */
279/*0x39*/0, /* Reserved for NewLink */
280/*0x3a*/0, /* Reserved for NewLink */
281/*0x3b*/0, /* Reserved for NewLink */
282/*0x3c*/0, /* Reserved for NewLink */
283/*0x3d*/0, /* Reserved for NewLink */
284/*0x3e*/0, /* Reserved for NewLink */
285/*0x3f*/0, /* Reserved for NewLink */
286};
287
288static int schizo_ino_to_pil(struct pci_dev *pdev, unsigned int ino)
289{
290 int ret;
291
292 if (pdev &&
293 pdev->vendor == PCI_VENDOR_ID_SUN &&
294 pdev->device == PCI_DEVICE_ID_SUN_RIO_USB)
295 return 9;
296
297 ret = schizo_pil_table[ino];
298 if (ret == 0 && pdev == NULL) {
299 ret = 5;
300 } else if (ret == 0) {
301 switch ((pdev->class >> 16) & 0xff) {
302 case PCI_BASE_CLASS_STORAGE:
303 ret = 5;
304 break;
305
306 case PCI_BASE_CLASS_NETWORK:
307 ret = 6;
308 break;
309
310 case PCI_BASE_CLASS_DISPLAY:
311 ret = 9;
312 break;
313
314 case PCI_BASE_CLASS_MULTIMEDIA:
315 case PCI_BASE_CLASS_MEMORY:
316 case PCI_BASE_CLASS_BRIDGE:
317 case PCI_BASE_CLASS_SERIAL:
318 ret = 10;
319 break;
320
321 default:
322 ret = 5;
323 break;
324 };
325 }
326
327 return ret;
328}
329
330static void tomatillo_wsync_handler(struct ino_bucket *bucket, void *_arg1, void *_arg2)
331{ 236{
332 unsigned long sync_reg = (unsigned long) _arg2; 237 unsigned long sync_reg = (unsigned long) _arg2;
333 u64 mask = 1UL << (__irq_ino(__irq(bucket)) & IMAP_INO); 238 u64 mask = 1UL << (ino & IMAP_INO);
334 u64 val; 239 u64 val;
335 int limit; 240 int limit;
336 241
@@ -365,30 +270,33 @@ static void tomatillo_wsync_handler(struct ino_bucket *bucket, void *_arg1, void
365 } 270 }
366} 271}
367 272
273static unsigned long schizo_ino_to_iclr(struct pci_pbm_info *pbm,
274 unsigned int ino)
275{
276 ino &= PCI_IRQ_INO;
277 return pbm->pbm_regs + schizo_iclr_offset(ino) + 4;
278}
279
280static unsigned long schizo_ino_to_imap(struct pci_pbm_info *pbm,
281 unsigned int ino)
282{
283 ino &= PCI_IRQ_INO;
284 return pbm->pbm_regs + schizo_imap_offset(ino) + 4;
285}
286
368static unsigned int schizo_irq_build(struct pci_pbm_info *pbm, 287static unsigned int schizo_irq_build(struct pci_pbm_info *pbm,
369 struct pci_dev *pdev, 288 struct pci_dev *pdev,
370 unsigned int ino) 289 unsigned int ino)
371{ 290{
372 struct ino_bucket *bucket;
373 unsigned long imap, iclr; 291 unsigned long imap, iclr;
374 unsigned long imap_off, iclr_off; 292 int ign_fixup;
375 int pil, ign_fixup; 293 int virt_irq;
376 294
377 ino &= PCI_IRQ_INO; 295 ino &= PCI_IRQ_INO;
378 imap_off = schizo_imap_offset(ino);
379 296
380 /* Now build the IRQ bucket. */ 297 /* Now build the IRQ bucket. */
381 pil = schizo_ino_to_pil(pdev, ino); 298 imap = schizo_ino_to_imap(pbm, ino);
382 299 iclr = schizo_ino_to_iclr(pbm, ino);
383 if (PIL_RESERVED(pil))
384 BUG();
385
386 imap = pbm->pbm_regs + imap_off;
387 imap += 4;
388
389 iclr_off = schizo_iclr_offset(ino);
390 iclr = pbm->pbm_regs + iclr_off;
391 iclr += 4;
392 300
393 /* On Schizo, no inofixup occurs. This is because each 301 /* On Schizo, no inofixup occurs. This is because each
394 * INO has it's own IMAP register. On Psycho and Sabre 302 * INO has it's own IMAP register. On Psycho and Sabre
@@ -405,19 +313,17 @@ static unsigned int schizo_irq_build(struct pci_pbm_info *pbm,
405 ign_fixup = (1 << 6); 313 ign_fixup = (1 << 6);
406 } 314 }
407 315
408 bucket = __bucket(build_irq(pil, ign_fixup, iclr, imap)); 316 virt_irq = build_irq(ign_fixup, iclr, imap);
409 bucket->flags |= IBF_PCI;
410 317
411 if (pdev && pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO) { 318 if (pdev && pbm->chip_type == PBM_CHIP_TYPE_TOMATILLO) {
412 struct irq_desc *p = bucket->irq_info; 319 irq_install_pre_handler(virt_irq,
413 320 tomatillo_wsync_handler,
414 p->pre_handler = tomatillo_wsync_handler; 321 ((pbm->chip_version <= 4) ?
415 p->pre_handler_arg1 = ((pbm->chip_version <= 4) ? 322 (void *) 1 : (void *) 0),
416 (void *) 1 : (void *) 0); 323 (void *) pbm->sync_reg);
417 p->pre_handler_arg2 = (void *) pbm->sync_reg;
418 } 324 }
419 325
420 return __irq(bucket); 326 return virt_irq;
421} 327}
422 328
423/* SCHIZO error handling support. */ 329/* SCHIZO error handling support. */
@@ -458,7 +364,6 @@ struct pci_pbm_info *pbm_for_ino(struct pci_controller_info *p, u32 ino)
458static void schizo_clear_other_err_intr(struct pci_controller_info *p, int irq) 364static void schizo_clear_other_err_intr(struct pci_controller_info *p, int irq)
459{ 365{
460 struct pci_pbm_info *pbm; 366 struct pci_pbm_info *pbm;
461 struct ino_bucket *bucket;
462 unsigned long iclr; 367 unsigned long iclr;
463 368
464 /* Do not clear the interrupt for the other PCI bus. 369 /* Do not clear the interrupt for the other PCI bus.
@@ -476,11 +381,11 @@ static void schizo_clear_other_err_intr(struct pci_controller_info *p, int irq)
476 else 381 else
477 pbm = &p->pbm_A; 382 pbm = &p->pbm_A;
478 383
479 irq = schizo_irq_build(pbm, NULL, 384 schizo_irq_build(pbm, NULL,
480 (pbm->portid << 6) | (irq & IMAP_INO)); 385 (pbm->portid << 6) | (irq & IMAP_INO));
481 bucket = __bucket(irq);
482 iclr = bucket->iclr;
483 386
387 iclr = schizo_ino_to_iclr(pbm,
388 (pbm->portid << 6) | (irq & IMAP_INO));
484 upa_writel(ICLR_IDLE, iclr); 389 upa_writel(ICLR_IDLE, iclr);
485} 390}
486 391
@@ -1225,7 +1130,6 @@ static void tomatillo_register_error_handlers(struct pci_controller_info *p)
1225{ 1130{
1226 struct pci_pbm_info *pbm; 1131 struct pci_pbm_info *pbm;
1227 unsigned int irq; 1132 unsigned int irq;
1228 struct ino_bucket *bucket;
1229 u64 tmp, err_mask, err_no_mask; 1133 u64 tmp, err_mask, err_no_mask;
1230 1134
1231 /* Build IRQs and register handlers. */ 1135 /* Build IRQs and register handlers. */
@@ -1237,8 +1141,7 @@ static void tomatillo_register_error_handlers(struct pci_controller_info *p)
1237 pbm->name); 1141 pbm->name);
1238 prom_halt(); 1142 prom_halt();
1239 } 1143 }
1240 bucket = __bucket(irq); 1144 tmp = upa_readl(schizo_ino_to_imap(pbm, (pbm->portid << 6) | SCHIZO_UE_INO));
1241 tmp = upa_readl(bucket->imap);
1242 upa_writel(tmp, (pbm->pbm_regs + 1145 upa_writel(tmp, (pbm->pbm_regs +
1243 schizo_imap_offset(SCHIZO_UE_INO) + 4)); 1146 schizo_imap_offset(SCHIZO_UE_INO) + 4));
1244 1147
@@ -1250,8 +1153,7 @@ static void tomatillo_register_error_handlers(struct pci_controller_info *p)
1250 pbm->name); 1153 pbm->name);
1251 prom_halt(); 1154 prom_halt();
1252 } 1155 }
1253 bucket = __bucket(irq); 1156 tmp = upa_readl(schizo_ino_to_imap(pbm, (pbm->portid << 6) | SCHIZO_CE_INO));
1254 tmp = upa_readl(bucket->imap);
1255 upa_writel(tmp, (pbm->pbm_regs + 1157 upa_writel(tmp, (pbm->pbm_regs +
1256 schizo_imap_offset(SCHIZO_CE_INO) + 4)); 1158 schizo_imap_offset(SCHIZO_CE_INO) + 4));
1257 1159
@@ -1264,8 +1166,8 @@ static void tomatillo_register_error_handlers(struct pci_controller_info *p)
1264 pbm->name); 1166 pbm->name);
1265 prom_halt(); 1167 prom_halt();
1266 } 1168 }
1267 bucket = __bucket(irq); 1169 tmp = upa_readl(schizo_ino_to_imap(pbm, ((pbm->portid << 6) |
1268 tmp = upa_readl(bucket->imap); 1170 SCHIZO_PCIERR_A_INO)));
1269 upa_writel(tmp, (pbm->pbm_regs + 1171 upa_writel(tmp, (pbm->pbm_regs +
1270 schizo_imap_offset(SCHIZO_PCIERR_A_INO) + 4)); 1172 schizo_imap_offset(SCHIZO_PCIERR_A_INO) + 4));
1271 1173
@@ -1278,8 +1180,8 @@ static void tomatillo_register_error_handlers(struct pci_controller_info *p)
1278 pbm->name); 1180 pbm->name);
1279 prom_halt(); 1181 prom_halt();
1280 } 1182 }
1281 bucket = __bucket(irq); 1183 tmp = upa_readl(schizo_ino_to_imap(pbm, ((pbm->portid << 6) |
1282 tmp = upa_readl(bucket->imap); 1184 SCHIZO_PCIERR_B_INO)));
1283 upa_writel(tmp, (pbm->pbm_regs + 1185 upa_writel(tmp, (pbm->pbm_regs +
1284 schizo_imap_offset(SCHIZO_PCIERR_B_INO) + 4)); 1186 schizo_imap_offset(SCHIZO_PCIERR_B_INO) + 4));
1285 1187
@@ -1291,8 +1193,8 @@ static void tomatillo_register_error_handlers(struct pci_controller_info *p)
1291 pbm->name); 1193 pbm->name);
1292 prom_halt(); 1194 prom_halt();
1293 } 1195 }
1294 bucket = __bucket(irq); 1196 tmp = upa_readl(schizo_ino_to_imap(pbm, ((pbm->portid << 6) |
1295 tmp = upa_readl(bucket->imap); 1197 SCHIZO_SERR_INO)));
1296 upa_writel(tmp, (pbm->pbm_regs + 1198 upa_writel(tmp, (pbm->pbm_regs +
1297 schizo_imap_offset(SCHIZO_SERR_INO) + 4)); 1199 schizo_imap_offset(SCHIZO_SERR_INO) + 4));
1298 1200
@@ -1363,7 +1265,6 @@ static void schizo_register_error_handlers(struct pci_controller_info *p)
1363{ 1265{
1364 struct pci_pbm_info *pbm; 1266 struct pci_pbm_info *pbm;
1365 unsigned int irq; 1267 unsigned int irq;
1366 struct ino_bucket *bucket;
1367 u64 tmp, err_mask, err_no_mask; 1268 u64 tmp, err_mask, err_no_mask;
1368 1269
1369 /* Build IRQs and register handlers. */ 1270 /* Build IRQs and register handlers. */
@@ -1375,8 +1276,7 @@ static void schizo_register_error_handlers(struct pci_controller_info *p)
1375 pbm->name); 1276 pbm->name);
1376 prom_halt(); 1277 prom_halt();
1377 } 1278 }
1378 bucket = __bucket(irq); 1279 tmp = upa_readl(schizo_ino_to_imap(pbm, (pbm->portid << 6) | SCHIZO_UE_INO));
1379 tmp = upa_readl(bucket->imap);
1380 upa_writel(tmp, (pbm->pbm_regs + schizo_imap_offset(SCHIZO_UE_INO) + 4)); 1280 upa_writel(tmp, (pbm->pbm_regs + schizo_imap_offset(SCHIZO_UE_INO) + 4));
1381 1281
1382 pbm = pbm_for_ino(p, SCHIZO_CE_INO); 1282 pbm = pbm_for_ino(p, SCHIZO_CE_INO);
@@ -1387,8 +1287,7 @@ static void schizo_register_error_handlers(struct pci_controller_info *p)
1387 pbm->name); 1287 pbm->name);
1388 prom_halt(); 1288 prom_halt();
1389 } 1289 }
1390 bucket = __bucket(irq); 1290 tmp = upa_readl(schizo_ino_to_imap(pbm, (pbm->portid << 6) | SCHIZO_CE_INO));
1391 tmp = upa_readl(bucket->imap);
1392 upa_writel(tmp, (pbm->pbm_regs + schizo_imap_offset(SCHIZO_CE_INO) + 4)); 1291 upa_writel(tmp, (pbm->pbm_regs + schizo_imap_offset(SCHIZO_CE_INO) + 4));
1393 1292
1394 pbm = pbm_for_ino(p, SCHIZO_PCIERR_A_INO); 1293 pbm = pbm_for_ino(p, SCHIZO_PCIERR_A_INO);
@@ -1399,8 +1298,7 @@ static void schizo_register_error_handlers(struct pci_controller_info *p)
1399 pbm->name); 1298 pbm->name);
1400 prom_halt(); 1299 prom_halt();
1401 } 1300 }
1402 bucket = __bucket(irq); 1301 tmp = upa_readl(schizo_ino_to_imap(pbm, (pbm->portid << 6) | SCHIZO_PCIERR_A_INO));
1403 tmp = upa_readl(bucket->imap);
1404 upa_writel(tmp, (pbm->pbm_regs + schizo_imap_offset(SCHIZO_PCIERR_A_INO) + 4)); 1302 upa_writel(tmp, (pbm->pbm_regs + schizo_imap_offset(SCHIZO_PCIERR_A_INO) + 4));
1405 1303
1406 pbm = pbm_for_ino(p, SCHIZO_PCIERR_B_INO); 1304 pbm = pbm_for_ino(p, SCHIZO_PCIERR_B_INO);
@@ -1411,8 +1309,7 @@ static void schizo_register_error_handlers(struct pci_controller_info *p)
1411 pbm->name); 1309 pbm->name);
1412 prom_halt(); 1310 prom_halt();
1413 } 1311 }
1414 bucket = __bucket(irq); 1312 tmp = upa_readl(schizo_ino_to_imap(pbm, (pbm->portid << 6) | SCHIZO_PCIERR_B_INO));
1415 tmp = upa_readl(bucket->imap);
1416 upa_writel(tmp, (pbm->pbm_regs + schizo_imap_offset(SCHIZO_PCIERR_B_INO) + 4)); 1313 upa_writel(tmp, (pbm->pbm_regs + schizo_imap_offset(SCHIZO_PCIERR_B_INO) + 4));
1417 1314
1418 pbm = pbm_for_ino(p, SCHIZO_SERR_INO); 1315 pbm = pbm_for_ino(p, SCHIZO_SERR_INO);
@@ -1423,8 +1320,7 @@ static void schizo_register_error_handlers(struct pci_controller_info *p)
1423 pbm->name); 1320 pbm->name);
1424 prom_halt(); 1321 prom_halt();
1425 } 1322 }
1426 bucket = __bucket(irq); 1323 tmp = upa_readl(schizo_ino_to_imap(pbm, (pbm->portid << 6) | SCHIZO_SERR_INO));
1427 tmp = upa_readl(bucket->imap);
1428 upa_writel(tmp, (pbm->pbm_regs + schizo_imap_offset(SCHIZO_SERR_INO) + 4)); 1324 upa_writel(tmp, (pbm->pbm_regs + schizo_imap_offset(SCHIZO_SERR_INO) + 4));
1429 1325
1430 /* Enable UE and CE interrupts for controller. */ 1326 /* Enable UE and CE interrupts for controller. */
diff --git a/arch/sparc64/kernel/pci_sun4v.c b/arch/sparc64/kernel/pci_sun4v.c
index 9e94db2573a2..5419480edf41 100644
--- a/arch/sparc64/kernel/pci_sun4v.c
+++ b/arch/sparc64/kernel/pci_sun4v.c
@@ -154,7 +154,7 @@ static void pci_arena_free(struct pci_iommu_arena *arena, unsigned long base, un
154 __clear_bit(i, arena->map); 154 __clear_bit(i, arena->map);
155} 155}
156 156
157static void *pci_4v_alloc_consistent(struct pci_dev *pdev, size_t size, dma_addr_t *dma_addrp) 157static void *pci_4v_alloc_consistent(struct pci_dev *pdev, size_t size, dma_addr_t *dma_addrp, gfp_t gfp)
158{ 158{
159 struct pcidev_cookie *pcp; 159 struct pcidev_cookie *pcp;
160 struct pci_iommu *iommu; 160 struct pci_iommu *iommu;
@@ -169,7 +169,7 @@ static void *pci_4v_alloc_consistent(struct pci_dev *pdev, size_t size, dma_addr
169 169
170 npages = size >> IO_PAGE_SHIFT; 170 npages = size >> IO_PAGE_SHIFT;
171 171
172 first_page = __get_free_pages(GFP_ATOMIC, order); 172 first_page = __get_free_pages(gfp, order);
173 if (unlikely(first_page == 0UL)) 173 if (unlikely(first_page == 0UL))
174 return NULL; 174 return NULL;
175 175
@@ -599,18 +599,128 @@ struct pci_iommu_ops pci_sun4v_iommu_ops = {
599 599
600/* SUN4V PCI configuration space accessors. */ 600/* SUN4V PCI configuration space accessors. */
601 601
602static inline int pci_sun4v_out_of_range(struct pci_pbm_info *pbm, unsigned int bus, unsigned int device, unsigned int func) 602struct pdev_entry {
603 struct pdev_entry *next;
604 u32 devhandle;
605 unsigned int bus;
606 unsigned int device;
607 unsigned int func;
608};
609
610#define PDEV_HTAB_SIZE 16
611#define PDEV_HTAB_MASK (PDEV_HTAB_SIZE - 1)
612static struct pdev_entry *pdev_htab[PDEV_HTAB_SIZE];
613
614static inline unsigned int pdev_hashfn(u32 devhandle, unsigned int bus, unsigned int device, unsigned int func)
603{ 615{
604 if (bus == pbm->pci_first_busno) { 616 unsigned int val;
605 if (device == 0 && func == 0) 617
606 return 0; 618 val = (devhandle ^ (devhandle >> 4));
607 return 1; 619 val ^= bus;
620 val ^= device;
621 val ^= func;
622
623 return val & PDEV_HTAB_MASK;
624}
625
626static int pdev_htab_add(u32 devhandle, unsigned int bus, unsigned int device, unsigned int func)
627{
628 struct pdev_entry *p = kmalloc(sizeof(*p), GFP_KERNEL);
629 struct pdev_entry **slot;
630
631 if (!p)
632 return -ENOMEM;
633
634 slot = &pdev_htab[pdev_hashfn(devhandle, bus, device, func)];
635 p->next = *slot;
636 *slot = p;
637
638 p->devhandle = devhandle;
639 p->bus = bus;
640 p->device = device;
641 p->func = func;
642
643 return 0;
644}
645
646/* Recursively descend into the OBP device tree, rooted at toplevel_node,
647 * looking for a PCI device matching bus and devfn.
648 */
649static int obp_find(struct linux_prom_pci_registers *pregs, int toplevel_node, unsigned int bus, unsigned int devfn)
650{
651 toplevel_node = prom_getchild(toplevel_node);
652
653 while (toplevel_node != 0) {
654 int ret = obp_find(pregs, toplevel_node, bus, devfn);
655
656 if (ret != 0)
657 return ret;
658
659 ret = prom_getproperty(toplevel_node, "reg", (char *) pregs,
660 sizeof(*pregs) * PROMREG_MAX);
661 if (ret == 0 || ret == -1)
662 goto next_sibling;
663
664 if (((pregs[0].phys_hi >> 16) & 0xff) == bus &&
665 ((pregs[0].phys_hi >> 8) & 0xff) == devfn)
666 break;
667
668 next_sibling:
669 toplevel_node = prom_getsibling(toplevel_node);
608 } 670 }
609 671
672 return toplevel_node;
673}
674
675static int pdev_htab_populate(struct pci_pbm_info *pbm)
676{
677 struct linux_prom_pci_registers pr[PROMREG_MAX];
678 u32 devhandle = pbm->devhandle;
679 unsigned int bus;
680
681 for (bus = pbm->pci_first_busno; bus <= pbm->pci_last_busno; bus++) {
682 unsigned int devfn;
683
684 for (devfn = 0; devfn < 256; devfn++) {
685 unsigned int device = PCI_SLOT(devfn);
686 unsigned int func = PCI_FUNC(devfn);
687
688 if (obp_find(pr, pbm->prom_node, bus, devfn)) {
689 int err = pdev_htab_add(devhandle, bus,
690 device, func);
691 if (err)
692 return err;
693 }
694 }
695 }
696
697 return 0;
698}
699
700static struct pdev_entry *pdev_find(u32 devhandle, unsigned int bus, unsigned int device, unsigned int func)
701{
702 struct pdev_entry *p;
703
704 p = pdev_htab[pdev_hashfn(devhandle, bus, device, func)];
705 while (p) {
706 if (p->devhandle == devhandle &&
707 p->bus == bus &&
708 p->device == device &&
709 p->func == func)
710 break;
711
712 p = p->next;
713 }
714
715 return p;
716}
717
718static inline int pci_sun4v_out_of_range(struct pci_pbm_info *pbm, unsigned int bus, unsigned int device, unsigned int func)
719{
610 if (bus < pbm->pci_first_busno || 720 if (bus < pbm->pci_first_busno ||
611 bus > pbm->pci_last_busno) 721 bus > pbm->pci_last_busno)
612 return 1; 722 return 1;
613 return 0; 723 return pdev_find(pbm->devhandle, bus, device, func) == NULL;
614} 724}
615 725
616static int pci_sun4v_read_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn, 726static int pci_sun4v_read_pci_cfg(struct pci_bus *bus_dev, unsigned int devfn,
@@ -733,38 +843,8 @@ static unsigned int pci_sun4v_irq_build(struct pci_pbm_info *pbm,
733 unsigned int devino) 843 unsigned int devino)
734{ 844{
735 u32 devhandle = pbm->devhandle; 845 u32 devhandle = pbm->devhandle;
736 int pil;
737
738 pil = 5;
739 if (pdev) {
740 switch ((pdev->class >> 16) & 0xff) {
741 case PCI_BASE_CLASS_STORAGE:
742 pil = 5;
743 break;
744
745 case PCI_BASE_CLASS_NETWORK:
746 pil = 6;
747 break;
748
749 case PCI_BASE_CLASS_DISPLAY:
750 pil = 9;
751 break;
752 846
753 case PCI_BASE_CLASS_MULTIMEDIA: 847 return sun4v_build_irq(devhandle, devino);
754 case PCI_BASE_CLASS_MEMORY:
755 case PCI_BASE_CLASS_BRIDGE:
756 case PCI_BASE_CLASS_SERIAL:
757 pil = 10;
758 break;
759
760 default:
761 pil = 5;
762 break;
763 };
764 }
765 BUG_ON(PIL_RESERVED(pil));
766
767 return sun4v_build_irq(devhandle, devino, pil, IBF_PCI);
768} 848}
769 849
770static void pci_sun4v_base_address_update(struct pci_dev *pdev, int resource) 850static void pci_sun4v_base_address_update(struct pci_dev *pdev, int resource)
@@ -1063,6 +1143,8 @@ static void pci_sun4v_pbm_init(struct pci_controller_info *p, int prom_node, u32
1063 1143
1064 pci_sun4v_get_bus_range(pbm); 1144 pci_sun4v_get_bus_range(pbm);
1065 pci_sun4v_iommu_init(pbm); 1145 pci_sun4v_iommu_init(pbm);
1146
1147 pdev_htab_populate(pbm);
1066} 1148}
1067 1149
1068void sun4v_pci_init(int node, char *model_name) 1150void sun4v_pci_init(int node, char *model_name)
diff --git a/arch/sparc64/kernel/sbus.c b/arch/sparc64/kernel/sbus.c
index 1d6ffdeabd4c..8812417247d4 100644
--- a/arch/sparc64/kernel/sbus.c
+++ b/arch/sparc64/kernel/sbus.c
@@ -691,36 +691,6 @@ void sbus_set_sbus64(struct sbus_dev *sdev, int bursts)
691 upa_writeq(val, cfg_reg); 691 upa_writeq(val, cfg_reg);
692} 692}
693 693
694/* SBUS SYSIO INO number to Sparc PIL level. */
695static unsigned char sysio_ino_to_pil[] = {
696 0, 5, 5, 7, 5, 7, 8, 9, /* SBUS slot 0 */
697 0, 5, 5, 7, 5, 7, 8, 9, /* SBUS slot 1 */
698 0, 5, 5, 7, 5, 7, 8, 9, /* SBUS slot 2 */
699 0, 5, 5, 7, 5, 7, 8, 9, /* SBUS slot 3 */
700 5, /* Onboard SCSI */
701 5, /* Onboard Ethernet */
702/*XXX*/ 8, /* Onboard BPP */
703 0, /* Bogon */
704 13, /* Audio */
705/*XXX*/15, /* PowerFail */
706 0, /* Bogon */
707 0, /* Bogon */
708 12, /* Zilog Serial Channels (incl. Keyboard/Mouse lines) */
709 11, /* Floppy */
710 0, /* Spare Hardware (bogon for now) */
711 0, /* Keyboard (bogon for now) */
712 0, /* Mouse (bogon for now) */
713 0, /* Serial (bogon for now) */
714 0, 0, /* Bogon, Bogon */
715 10, /* Timer 0 */
716 11, /* Timer 1 */
717 0, 0, /* Bogon, Bogon */
718 15, /* Uncorrectable SBUS Error */
719 15, /* Correctable SBUS Error */
720 15, /* SBUS Error */
721/*XXX*/ 0, /* Power Management (bogon for now) */
722};
723
724/* INO number to IMAP register offset for SYSIO external IRQ's. 694/* INO number to IMAP register offset for SYSIO external IRQ's.
725 * This should conform to both Sunfire/Wildfire server and Fusion 695 * This should conform to both Sunfire/Wildfire server and Fusion
726 * desktop designs. 696 * desktop designs.
@@ -812,21 +782,12 @@ unsigned int sbus_build_irq(void *buscookie, unsigned int ino)
812 struct sbus_iommu *iommu = sbus->iommu; 782 struct sbus_iommu *iommu = sbus->iommu;
813 unsigned long reg_base = iommu->sbus_control_reg - 0x2000UL; 783 unsigned long reg_base = iommu->sbus_control_reg - 0x2000UL;
814 unsigned long imap, iclr; 784 unsigned long imap, iclr;
815 int pil, sbus_level = 0; 785 int sbus_level = 0;
816
817 pil = sysio_ino_to_pil[ino];
818 if (!pil) {
819 printk("sbus_irq_build: Bad SYSIO INO[%x]\n", ino);
820 panic("Bad SYSIO IRQ translations...");
821 }
822
823 if (PIL_RESERVED(pil))
824 BUG();
825 786
826 imap = sysio_irq_offsets[ino]; 787 imap = sysio_irq_offsets[ino];
827 if (imap == ((unsigned long)-1)) { 788 if (imap == ((unsigned long)-1)) {
828 prom_printf("get_irq_translations: Bad SYSIO INO[%x] cpu[%d]\n", 789 prom_printf("get_irq_translations: Bad SYSIO INO[%x]\n",
829 ino, pil); 790 ino);
830 prom_halt(); 791 prom_halt();
831 } 792 }
832 imap += reg_base; 793 imap += reg_base;
@@ -860,7 +821,7 @@ unsigned int sbus_build_irq(void *buscookie, unsigned int ino)
860 821
861 iclr += ((unsigned long)sbus_level - 1UL) * 8UL; 822 iclr += ((unsigned long)sbus_level - 1UL) * 8UL;
862 } 823 }
863 return build_irq(pil, sbus_level, iclr, imap); 824 return build_irq(sbus_level, iclr, imap);
864} 825}
865 826
866/* Error interrupt handling. */ 827/* Error interrupt handling. */
diff --git a/arch/sparc64/kernel/setup.c b/arch/sparc64/kernel/setup.c
index 005167f82419..9cf1c88cd774 100644
--- a/arch/sparc64/kernel/setup.c
+++ b/arch/sparc64/kernel/setup.c
@@ -220,7 +220,7 @@ char reboot_command[COMMAND_LINE_SIZE];
220 220
221static struct pt_regs fake_swapper_regs = { { 0, }, 0, 0, 0, 0 }; 221static struct pt_regs fake_swapper_regs = { { 0, }, 0, 0, 0, 0 };
222 222
223static void __init per_cpu_patch(void) 223void __init per_cpu_patch(void)
224{ 224{
225 struct cpuid_patch_entry *p; 225 struct cpuid_patch_entry *p;
226 unsigned long ver; 226 unsigned long ver;
@@ -280,7 +280,7 @@ static void __init per_cpu_patch(void)
280 } 280 }
281} 281}
282 282
283static void __init sun4v_patch(void) 283void __init sun4v_patch(void)
284{ 284{
285 struct sun4v_1insn_patch_entry *p1; 285 struct sun4v_1insn_patch_entry *p1;
286 struct sun4v_2insn_patch_entry *p2; 286 struct sun4v_2insn_patch_entry *p2;
@@ -315,6 +315,15 @@ static void __init sun4v_patch(void)
315 } 315 }
316} 316}
317 317
318#ifdef CONFIG_SMP
319void __init boot_cpu_id_too_large(int cpu)
320{
321 prom_printf("Serious problem, boot cpu id (%d) >= NR_CPUS (%d)\n",
322 cpu, NR_CPUS);
323 prom_halt();
324}
325#endif
326
318void __init setup_arch(char **cmdline_p) 327void __init setup_arch(char **cmdline_p)
319{ 328{
320 /* Initialize PROM console and command line. */ 329 /* Initialize PROM console and command line. */
@@ -332,16 +341,6 @@ void __init setup_arch(char **cmdline_p)
332 conswitchp = &prom_con; 341 conswitchp = &prom_con;
333#endif 342#endif
334 343
335 /* Work out if we are starfire early on */
336 check_if_starfire();
337
338 /* Now we know enough to patch the get_cpuid sequences
339 * used by trap code.
340 */
341 per_cpu_patch();
342
343 sun4v_patch();
344
345 boot_flags_init(*cmdline_p); 344 boot_flags_init(*cmdline_p);
346 345
347 idprom_init(); 346 idprom_init();
diff --git a/arch/sparc64/kernel/smp.c b/arch/sparc64/kernel/smp.c
index 90eaca3ec9a6..f03d52d0b88d 100644
--- a/arch/sparc64/kernel/smp.c
+++ b/arch/sparc64/kernel/smp.c
@@ -1264,7 +1264,6 @@ void __init smp_tick_init(void)
1264 boot_cpu_id = hard_smp_processor_id(); 1264 boot_cpu_id = hard_smp_processor_id();
1265 current_tick_offset = timer_tick_offset; 1265 current_tick_offset = timer_tick_offset;
1266 1266
1267 cpu_set(boot_cpu_id, cpu_online_map);
1268 prof_counter(boot_cpu_id) = prof_multiplier(boot_cpu_id) = 1; 1267 prof_counter(boot_cpu_id) = prof_multiplier(boot_cpu_id) = 1;
1269} 1268}
1270 1269
@@ -1288,6 +1287,40 @@ int setup_profiling_timer(unsigned int multiplier)
1288 return 0; 1287 return 0;
1289} 1288}
1290 1289
1290static void __init smp_tune_scheduling(void)
1291{
1292 int instance, node;
1293 unsigned int def, smallest = ~0U;
1294
1295 def = ((tlb_type == hypervisor) ?
1296 (3 * 1024 * 1024) :
1297 (4 * 1024 * 1024));
1298
1299 instance = 0;
1300 while (!cpu_find_by_instance(instance, &node, NULL)) {
1301 unsigned int val;
1302
1303 val = prom_getintdefault(node, "ecache-size", def);
1304 if (val < smallest)
1305 smallest = val;
1306
1307 instance++;
1308 }
1309
1310 /* Any value less than 256K is nonsense. */
1311 if (smallest < (256U * 1024U))
1312 smallest = 256 * 1024;
1313
1314 max_cache_size = smallest;
1315
1316 if (smallest < 1U * 1024U * 1024U)
1317 printk(KERN_INFO "Using max_cache_size of %uKB\n",
1318 smallest / 1024U);
1319 else
1320 printk(KERN_INFO "Using max_cache_size of %uMB\n",
1321 smallest / 1024U / 1024U);
1322}
1323
1291/* Constrain the number of cpus to max_cpus. */ 1324/* Constrain the number of cpus to max_cpus. */
1292void __init smp_prepare_cpus(unsigned int max_cpus) 1325void __init smp_prepare_cpus(unsigned int max_cpus)
1293{ 1326{
@@ -1323,6 +1356,7 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
1323 } 1356 }
1324 1357
1325 smp_store_cpu_info(boot_cpu_id); 1358 smp_store_cpu_info(boot_cpu_id);
1359 smp_tune_scheduling();
1326} 1360}
1327 1361
1328/* Set this up early so that things like the scheduler can init 1362/* Set this up early so that things like the scheduler can init
@@ -1345,18 +1379,6 @@ void __init smp_setup_cpu_possible_map(void)
1345 1379
1346void __devinit smp_prepare_boot_cpu(void) 1380void __devinit smp_prepare_boot_cpu(void)
1347{ 1381{
1348 int cpu = hard_smp_processor_id();
1349
1350 if (cpu >= NR_CPUS) {
1351 prom_printf("Serious problem, boot cpu id >= NR_CPUS\n");
1352 prom_halt();
1353 }
1354
1355 current_thread_info()->cpu = cpu;
1356 __local_per_cpu_offset = __per_cpu_offset(cpu);
1357
1358 cpu_set(smp_processor_id(), cpu_online_map);
1359 cpu_set(smp_processor_id(), phys_cpu_present_map);
1360} 1382}
1361 1383
1362int __devinit __cpu_up(unsigned int cpu) 1384int __devinit __cpu_up(unsigned int cpu)
@@ -1433,4 +1455,7 @@ void __init setup_per_cpu_areas(void)
1433 1455
1434 for (i = 0; i < NR_CPUS; i++, ptr += size) 1456 for (i = 0; i < NR_CPUS; i++, ptr += size)
1435 memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start); 1457 memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start);
1458
1459 /* Setup %g5 for the boot cpu. */
1460 __local_per_cpu_offset = __per_cpu_offset(smp_processor_id());
1436} 1461}
diff --git a/arch/sparc64/kernel/sparc64_ksyms.c b/arch/sparc64/kernel/sparc64_ksyms.c
index 62d8a99271ea..4ac35dd2088b 100644
--- a/arch/sparc64/kernel/sparc64_ksyms.c
+++ b/arch/sparc64/kernel/sparc64_ksyms.c
@@ -125,9 +125,6 @@ EXPORT_SYMBOL(__write_lock);
125EXPORT_SYMBOL(__write_unlock); 125EXPORT_SYMBOL(__write_unlock);
126EXPORT_SYMBOL(__write_trylock); 126EXPORT_SYMBOL(__write_trylock);
127 127
128/* Hard IRQ locking */
129EXPORT_SYMBOL(synchronize_irq);
130
131#if defined(CONFIG_MCOUNT) 128#if defined(CONFIG_MCOUNT)
132extern void _mcount(void); 129extern void _mcount(void);
133EXPORT_SYMBOL(_mcount); 130EXPORT_SYMBOL(_mcount);
@@ -175,10 +172,6 @@ EXPORT_SYMBOL(set_bit);
175EXPORT_SYMBOL(clear_bit); 172EXPORT_SYMBOL(clear_bit);
176EXPORT_SYMBOL(change_bit); 173EXPORT_SYMBOL(change_bit);
177 174
178EXPORT_SYMBOL(ivector_table);
179EXPORT_SYMBOL(enable_irq);
180EXPORT_SYMBOL(disable_irq);
181
182EXPORT_SYMBOL(__flushw_user); 175EXPORT_SYMBOL(__flushw_user);
183 176
184EXPORT_SYMBOL(tlb_type); 177EXPORT_SYMBOL(tlb_type);
@@ -297,7 +290,6 @@ EXPORT_SYMBOL(svr4_getcontext);
297EXPORT_SYMBOL(svr4_setcontext); 290EXPORT_SYMBOL(svr4_setcontext);
298EXPORT_SYMBOL(compat_sys_ioctl); 291EXPORT_SYMBOL(compat_sys_ioctl);
299EXPORT_SYMBOL(sparc32_open); 292EXPORT_SYMBOL(sparc32_open);
300EXPORT_SYMBOL(sys_close);
301#endif 293#endif
302 294
303/* Special internal versions of library functions. */ 295/* Special internal versions of library functions. */
diff --git a/arch/sparc64/kernel/sun4v_ivec.S b/arch/sparc64/kernel/sun4v_ivec.S
index b49a68bdda43..49703c3c5769 100644
--- a/arch/sparc64/kernel/sun4v_ivec.S
+++ b/arch/sparc64/kernel/sun4v_ivec.S
@@ -5,6 +5,7 @@
5 5
6#include <asm/cpudata.h> 6#include <asm/cpudata.h>
7#include <asm/intr_queue.h> 7#include <asm/intr_queue.h>
8#include <asm/pil.h>
8 9
9 .text 10 .text
10 .align 32 11 .align 32
@@ -102,23 +103,17 @@ sun4v_dev_mondo:
102 103
103 /* Get &ivector_table[IVEC] into %g4. */ 104 /* Get &ivector_table[IVEC] into %g4. */
104 sethi %hi(ivector_table), %g4 105 sethi %hi(ivector_table), %g4
105 sllx %g3, 5, %g3 106 sllx %g3, 3, %g3
106 or %g4, %lo(ivector_table), %g4 107 or %g4, %lo(ivector_table), %g4
107 add %g4, %g3, %g4 108 add %g4, %g3, %g4
108 109
109 /* Load IRQ %pil into %g5. */
110 ldub [%g4 + 0x04], %g5
111
112 /* Insert ivector_table[] entry into __irq_work[] queue. */ 110 /* Insert ivector_table[] entry into __irq_work[] queue. */
113 sllx %g5, 2, %g3 111 lduw [%g1], %g2 /* g2 = irq_work(cpu) */
114 lduw [%g1 + %g3], %g2 /* g2 = irq_work(cpu, pil) */
115 stw %g2, [%g4 + 0x00] /* bucket->irq_chain = g2 */ 112 stw %g2, [%g4 + 0x00] /* bucket->irq_chain = g2 */
116 stw %g4, [%g1 + %g3] /* irq_work(cpu, pil) = bucket */ 113 stw %g4, [%g1] /* irq_work(cpu) = bucket */
117 114
118 /* Signal the interrupt by setting (1 << pil) in %softint. */ 115 /* Signal the interrupt by setting (1 << pil) in %softint. */
119 mov 1, %g2 116 wr %g0, 1 << PIL_DEVICE_IRQ, %set_softint
120 sllx %g2, %g5, %g2
121 wr %g2, 0x0, %set_softint
122 117
123sun4v_dev_mondo_queue_empty: 118sun4v_dev_mondo_queue_empty:
124 retry 119 retry
diff --git a/arch/sparc64/kernel/systbls.S b/arch/sparc64/kernel/systbls.S
index d4b39cd30310..1136fc465e37 100644
--- a/arch/sparc64/kernel/systbls.S
+++ b/arch/sparc64/kernel/systbls.S
@@ -78,8 +78,9 @@ sys_call_table32:
78 .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid 78 .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
79/*280*/ .word sys32_tee, sys_add_key, sys_request_key, sys_keyctl, compat_sys_openat 79/*280*/ .word sys32_tee, sys_add_key, sys_request_key, sys_keyctl, compat_sys_openat
80 .word sys_mkdirat, sys_mknodat, sys_fchownat, compat_sys_futimesat, compat_sys_fstatat64 80 .word sys_mkdirat, sys_mknodat, sys_fchownat, compat_sys_futimesat, compat_sys_fstatat64
81/*285*/ .word sys_unlinkat, sys_renameat, sys_linkat, sys_symlinkat, sys_readlinkat 81/*290*/ .word sys_unlinkat, sys_renameat, sys_linkat, sys_symlinkat, sys_readlinkat
82 .word sys_fchmodat, sys_faccessat, compat_sys_pselect6, compat_sys_ppoll, sys_unshare 82 .word sys_fchmodat, sys_faccessat, compat_sys_pselect6, compat_sys_ppoll, sys_unshare
83/*300*/ .word compat_sys_set_robust_list, compat_sys_get_robust_list
83 84
84#endif /* CONFIG_COMPAT */ 85#endif /* CONFIG_COMPAT */
85 86
@@ -147,8 +148,9 @@ sys_call_table:
147 .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid 148 .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
148/*280*/ .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat 149/*280*/ .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
149 .word sys_mkdirat, sys_mknodat, sys_fchownat, sys_futimesat, sys_fstatat64 150 .word sys_mkdirat, sys_mknodat, sys_fchownat, sys_futimesat, sys_fstatat64
150/*285*/ .word sys_unlinkat, sys_renameat, sys_linkat, sys_symlinkat, sys_readlinkat 151/*290*/ .word sys_unlinkat, sys_renameat, sys_linkat, sys_symlinkat, sys_readlinkat
151 .word sys_fchmodat, sys_faccessat, sys_pselect6, sys_ppoll, sys_unshare 152 .word sys_fchmodat, sys_faccessat, sys_pselect6, sys_ppoll, sys_unshare
153/*300*/ .word sys_set_robust_list, sys_get_robust_list
152 154
153#if defined(CONFIG_SUNOS_EMUL) || defined(CONFIG_SOLARIS_EMUL) || \ 155#if defined(CONFIG_SUNOS_EMUL) || defined(CONFIG_SOLARIS_EMUL) || \
154 defined(CONFIG_SOLARIS_EMUL_MODULE) 156 defined(CONFIG_SOLARIS_EMUL_MODULE)
@@ -261,5 +263,5 @@ sunos_sys_table:
261/*290*/ .word sunos_nosys, sunos_nosys, sunos_nosys 263/*290*/ .word sunos_nosys, sunos_nosys, sunos_nosys
262 .word sunos_nosys, sunos_nosys, sunos_nosys 264 .word sunos_nosys, sunos_nosys, sunos_nosys
263 .word sunos_nosys, sunos_nosys, sunos_nosys 265 .word sunos_nosys, sunos_nosys, sunos_nosys
264 .word sunos_nosys 266 .word sunos_nosys, sunos_nosys, sunos_nosys
265#endif 267#endif
diff --git a/arch/sparc64/kernel/time.c b/arch/sparc64/kernel/time.c
index e55b5c6ece02..0f00a99927e9 100644
--- a/arch/sparc64/kernel/time.c
+++ b/arch/sparc64/kernel/time.c
@@ -457,7 +457,7 @@ static inline void timer_check_rtc(void)
457 } 457 }
458} 458}
459 459
460static irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs * regs) 460irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs * regs)
461{ 461{
462 unsigned long ticks, compare, pstate; 462 unsigned long ticks, compare, pstate;
463 463
@@ -1020,19 +1020,9 @@ static unsigned long sparc64_init_timers(void)
1020 return clock; 1020 return clock;
1021} 1021}
1022 1022
1023static void sparc64_start_timers(irqreturn_t (*cfunc)(int, void *, struct pt_regs *)) 1023static void sparc64_start_timers(void)
1024{ 1024{
1025 unsigned long pstate; 1025 unsigned long pstate;
1026 int err;
1027
1028 /* Register IRQ handler. */
1029 err = request_irq(build_irq(0, 0, 0UL, 0UL), cfunc, 0,
1030 "timer", NULL);
1031
1032 if (err) {
1033 prom_printf("Serious problem, cannot register TICK_INT\n");
1034 prom_halt();
1035 }
1036 1026
1037 /* Guarantee that the following sequences execute 1027 /* Guarantee that the following sequences execute
1038 * uninterrupted. 1028 * uninterrupted.
@@ -1116,7 +1106,7 @@ void __init time_init(void)
1116 /* Now that the interpolator is registered, it is 1106 /* Now that the interpolator is registered, it is
1117 * safe to start the timer ticking. 1107 * safe to start the timer ticking.
1118 */ 1108 */
1119 sparc64_start_timers(timer_interrupt); 1109 sparc64_start_timers();
1120 1110
1121 timer_ticks_per_nsec_quotient = 1111 timer_ticks_per_nsec_quotient =
1122 (((NSEC_PER_SEC << SPARC64_NSEC_PER_CYC_SHIFT) + 1112 (((NSEC_PER_SEC << SPARC64_NSEC_PER_CYC_SHIFT) +
diff --git a/arch/sparc64/kernel/traps.c b/arch/sparc64/kernel/traps.c
index 2793a5d82380..5059cbd4feee 100644
--- a/arch/sparc64/kernel/traps.c
+++ b/arch/sparc64/kernel/traps.c
@@ -1797,7 +1797,9 @@ static const char *sun4v_err_type_to_str(u32 type)
1797 }; 1797 };
1798} 1798}
1799 1799
1800static void sun4v_log_error(struct sun4v_error_entry *ent, int cpu, const char *pfx, atomic_t *ocnt) 1800extern void __show_regs(struct pt_regs * regs);
1801
1802static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent, int cpu, const char *pfx, atomic_t *ocnt)
1801{ 1803{
1802 int cnt; 1804 int cnt;
1803 1805
@@ -1830,6 +1832,8 @@ static void sun4v_log_error(struct sun4v_error_entry *ent, int cpu, const char *
1830 pfx, 1832 pfx,
1831 ent->err_raddr, ent->err_size, ent->err_cpu); 1833 ent->err_raddr, ent->err_size, ent->err_cpu);
1832 1834
1835 __show_regs(regs);
1836
1833 if ((cnt = atomic_read(ocnt)) != 0) { 1837 if ((cnt = atomic_read(ocnt)) != 0) {
1834 atomic_set(ocnt, 0); 1838 atomic_set(ocnt, 0);
1835 wmb(); 1839 wmb();
@@ -1862,7 +1866,7 @@ void sun4v_resum_error(struct pt_regs *regs, unsigned long offset)
1862 1866
1863 put_cpu(); 1867 put_cpu();
1864 1868
1865 sun4v_log_error(&local_copy, cpu, 1869 sun4v_log_error(regs, &local_copy, cpu,
1866 KERN_ERR "RESUMABLE ERROR", 1870 KERN_ERR "RESUMABLE ERROR",
1867 &sun4v_resum_oflow_cnt); 1871 &sun4v_resum_oflow_cnt);
1868} 1872}
@@ -1910,7 +1914,7 @@ void sun4v_nonresum_error(struct pt_regs *regs, unsigned long offset)
1910 } 1914 }
1911#endif 1915#endif
1912 1916
1913 sun4v_log_error(&local_copy, cpu, 1917 sun4v_log_error(regs, &local_copy, cpu,
1914 KERN_EMERG "NON-RESUMABLE ERROR", 1918 KERN_EMERG "NON-RESUMABLE ERROR",
1915 &sun4v_nonresum_oflow_cnt); 1919 &sun4v_nonresum_oflow_cnt);
1916 1920
@@ -2200,7 +2204,6 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
2200void die_if_kernel(char *str, struct pt_regs *regs) 2204void die_if_kernel(char *str, struct pt_regs *regs)
2201{ 2205{
2202 static int die_counter; 2206 static int die_counter;
2203 extern void __show_regs(struct pt_regs * regs);
2204 extern void smp_report_regs(void); 2207 extern void smp_report_regs(void);
2205 int count = 0; 2208 int count = 0;
2206 2209
@@ -2541,7 +2544,9 @@ void __init trap_init(void)
2541 (TRAP_PER_CPU_TSB_HUGE != 2544 (TRAP_PER_CPU_TSB_HUGE !=
2542 offsetof(struct trap_per_cpu, tsb_huge)) || 2545 offsetof(struct trap_per_cpu, tsb_huge)) ||
2543 (TRAP_PER_CPU_TSB_HUGE_TEMP != 2546 (TRAP_PER_CPU_TSB_HUGE_TEMP !=
2544 offsetof(struct trap_per_cpu, tsb_huge_temp))) 2547 offsetof(struct trap_per_cpu, tsb_huge_temp)) ||
2548 (TRAP_PER_CPU_IRQ_WORKLIST !=
2549 offsetof(struct trap_per_cpu, irq_worklist)))
2545 trap_per_cpu_offsets_are_bolixed_dave(); 2550 trap_per_cpu_offsets_are_bolixed_dave();
2546 2551
2547 if ((TSB_CONFIG_TSB != 2552 if ((TSB_CONFIG_TSB !=
diff --git a/arch/sparc64/kernel/ttable.S b/arch/sparc64/kernel/ttable.S
index 5d901519db55..ee45ca2d7a04 100644
--- a/arch/sparc64/kernel/ttable.S
+++ b/arch/sparc64/kernel/ttable.S
@@ -58,13 +58,11 @@ tl0_irq2: BTRAP(0x42)
58tl0_irq3: BTRAP(0x43) 58tl0_irq3: BTRAP(0x43)
59tl0_irq4: BTRAP(0x44) 59tl0_irq4: BTRAP(0x44)
60#endif 60#endif
61tl0_irq5: TRAP_IRQ(handler_irq, 5) TRAP_IRQ(handler_irq, 6) 61tl0_irq5: TRAP_IRQ(handler_irq, 5)
62tl0_irq7: TRAP_IRQ(handler_irq, 7) TRAP_IRQ(handler_irq, 8) 62tl0_irq6: BTRAP(0x46) BTRAP(0x47) BTRAP(0x48) BTRAP(0x49)
63tl0_irq9: TRAP_IRQ(handler_irq, 9) TRAP_IRQ(handler_irq, 10) 63tl0_irq10: BTRAP(0x4a) BTRAP(0x4b) BTRAP(0x4c) BTRAP(0x4d)
64tl0_irq11: TRAP_IRQ(handler_irq, 11) TRAP_IRQ(handler_irq, 12)
65tl0_irq13: TRAP_IRQ(handler_irq, 13)
66#ifndef CONFIG_SMP 64#ifndef CONFIG_SMP
67tl0_irq14: TRAP_IRQ(handler_irq, 14) 65tl0_irq14: TRAP_IRQ(timer_irq, 14)
68#else 66#else
69tl0_irq14: TICK_SMP_IRQ 67tl0_irq14: TICK_SMP_IRQ
70#endif 68#endif
diff --git a/arch/sparc64/lib/checksum.S b/arch/sparc64/lib/checksum.S
index ba9cd3ccc2b2..1d230f693dc4 100644
--- a/arch/sparc64/lib/checksum.S
+++ b/arch/sparc64/lib/checksum.S
@@ -165,8 +165,9 @@ csum_partial_end_cruft:
165 sll %g1, 8, %g1 165 sll %g1, 8, %g1
166 or %o5, %g1, %o4 166 or %o5, %g1, %o4
167 167
1681: add %o2, %o4, %o2 1681: addcc %o2, %o4, %o2
169 addc %g0, %o2, %o2
169 170
170csum_partial_finish: 171csum_partial_finish:
171 retl 172 retl
172 mov %o2, %o0 173 srl %o2, 0, %o0
diff --git a/arch/sparc64/lib/csum_copy.S b/arch/sparc64/lib/csum_copy.S
index 71af48839064..e566c770a0f6 100644
--- a/arch/sparc64/lib/csum_copy.S
+++ b/arch/sparc64/lib/csum_copy.S
@@ -221,11 +221,12 @@ FUNC_NAME: /* %o0=src, %o1=dst, %o2=len, %o3=sum */
221 sll %g1, 8, %g1 221 sll %g1, 8, %g1
222 or %o5, %g1, %o4 222 or %o5, %g1, %o4
223 223
2241: add %o3, %o4, %o3 2241: addcc %o3, %o4, %o3
225 addc %g0, %o3, %o3
225 226
22670: 22770:
227 retl 228 retl
228 mov %o3, %o0 229 srl %o3, 0, %o0
229 230
23095: mov 0, GLOBAL_SPARE 23195: mov 0, GLOBAL_SPARE
231 brlez,pn %o2, 4f 232 brlez,pn %o2, 4f