1 /* $Id: starfire.c,v 1.10 2001/04/14 21:13:45 davem Exp $
2  * starfire.c: Starfire/E10000 support.
3  *
4  * Copyright (C) 1998 David S. Miller (davem@redhat.com)
5  * Copyright (C) 2000 Anton Blanchard (anton@samba.org)
6  */
7 
8 #include <linux/kernel.h>
9 #include <linux/slab.h>
10 
11 #include <asm/page.h>
12 #include <asm/oplib.h>
13 #include <asm/smp.h>
14 #include <asm/upa.h>
15 #include <asm/starfire.h>
16 
17 /*
18  * A few places around the kernel check this to see if
19  * they need to call us to do things in a Starfire specific
20  * way.
21  */
22 int this_is_starfire = 0;
23 
check_if_starfire(void)24 void check_if_starfire(void)
25 {
26 	int ssnode = prom_finddevice("/ssp-serial");
27 	if(ssnode != 0 && ssnode != -1)
28 		this_is_starfire = 1;
29 }
30 
starfire_cpu_setup(void)31 void starfire_cpu_setup(void)
32 {
33 	if (this_is_starfire) {
34 /*
35  * We do this in starfire_translate and xcall_deliver. When we fix our cpu
36  * arrays to support > 64 processors we can use the real upaid instead
37  * of the logical cpuid in __cpu_number_map etc, then we can get rid of
38  * the translations everywhere. - Anton
39  */
40 #if 0
41 		int i;
42 
43 		/*
44 		 * Now must fixup cpu MIDs.  OBP gave us a logical
45 		 * linear cpuid number, not the real upaid.
46 		 */
47 		for(i = 0; i < linux_num_cpus; i++) {
48 			unsigned int mid = linux_cpus[i].mid;
49 
50 			mid = (((mid & 0x3c) << 1) |
51 			       ((mid & 0x40) >> 4) |
52 			       (mid & 0x3));
53 
54 			linux_cpus[i].mid = mid;
55 		}
56 #endif
57 	}
58 }
59 
starfire_hard_smp_processor_id(void)60 int starfire_hard_smp_processor_id(void)
61 {
62 	return upa_readl(0x1fff40000d0UL);
63 }
64 
65 /*
66  * Each Starfire board has 32 registers which perform translation
67  * and delivery of traditional interrupt packets into the extended
68  * Starfire hardware format.  Essentially UPAID's now have 2 more
69  * bits than in all previous Sun5 systems.
70  */
71 struct starfire_irqinfo {
72 	unsigned long imap_slots[32];
73 	unsigned long tregs[32];
74 	struct starfire_irqinfo *next;
75 	int upaid, hwmid;
76 };
77 
78 static struct starfire_irqinfo *sflist = NULL;
79 
80 /* Beam me up Scott(McNeil)y... */
starfire_hookup(int upaid)81 void *starfire_hookup(int upaid)
82 {
83 	struct starfire_irqinfo *p;
84 	unsigned long treg_base, hwmid, i;
85 
86 	p = kmalloc(sizeof(*p), GFP_KERNEL);
87 	if(!p) {
88 		prom_printf("starfire_hookup: No memory, this is insane.\n");
89 		prom_halt();
90 	}
91 	treg_base = 0x100fc000000UL;
92 	hwmid = ((upaid & 0x3c) << 1) |
93 		((upaid & 0x40) >> 4) |
94 		(upaid & 0x3);
95 	p->hwmid = hwmid;
96 	treg_base += (hwmid << 33UL);
97 	treg_base += 0x200UL;
98 	for(i = 0; i < 32; i++) {
99 		p->imap_slots[i] = 0UL;
100 		p->tregs[i] = treg_base + (i * 0x10UL);
101 		/* Lets play it safe and not overwrite existing mappings */
102 		if (upa_readl(p->tregs[i]) != 0)
103 			p->imap_slots[i] = 0xdeadbeaf;
104 	}
105 	p->upaid = upaid;
106 	p->next = sflist;
107 	sflist = p;
108 
109 	return (void *) p;
110 }
111 
starfire_translate(unsigned long imap,unsigned int upaid)112 unsigned int starfire_translate(unsigned long imap,
113 				unsigned int upaid)
114 {
115 	struct starfire_irqinfo *p;
116 	unsigned int bus_hwmid;
117 	unsigned int i;
118 
119 	bus_hwmid = (((unsigned long)imap) >> 33) & 0x7f;
120 	for(p = sflist; p != NULL; p = p->next)
121 		if(p->hwmid == bus_hwmid)
122 			break;
123 	if(p == NULL) {
124 		prom_printf("XFIRE: Cannot find irqinfo for imap %016lx\n",
125 			    ((unsigned long)imap));
126 		prom_halt();
127 	}
128 	for(i = 0; i < 32; i++) {
129 		if(p->imap_slots[i] == imap ||
130 		   p->imap_slots[i] == 0UL)
131 			break;
132 	}
133 	if(i == 32) {
134 		printk("starfire_translate: Are you kidding me?\n");
135 		panic("Lucy in the sky....");
136 	}
137 	p->imap_slots[i] = imap;
138 
139 	/* map to real upaid */
140 	upaid = (((upaid & 0x3c) << 1) |
141 	       ((upaid & 0x40) >> 4) |
142 	       (upaid & 0x3));
143 
144 	upa_writel(upaid, p->tregs[i]);
145 
146 	return i;
147 }
148