1 #ifndef __ALPHA_WILDFIRE__H__
2 #define __ALPHA_WILDFIRE__H__
3 
4 #include <linux/types.h>
5 #include <asm/compiler.h>
6 
7 #define WILDFIRE_MAX_QBB	8	/* more than 8 requires other mods */
8 #define WILDFIRE_PCA_PER_QBB	4
9 #define WILDFIRE_IRQ_PER_PCA	64
10 
11 #define WILDFIRE_NR_IRQS \
12   (WILDFIRE_MAX_QBB * WILDFIRE_PCA_PER_QBB * WILDFIRE_IRQ_PER_PCA)
13 
14 extern unsigned char wildfire_hard_qbb_map[WILDFIRE_MAX_QBB];
15 extern unsigned char wildfire_soft_qbb_map[WILDFIRE_MAX_QBB];
16 #define QBB_MAP_EMPTY	0xff
17 
18 extern unsigned long wildfire_hard_qbb_mask;
19 extern unsigned long wildfire_soft_qbb_mask;
20 extern unsigned long wildfire_gp_mask;
21 extern unsigned long wildfire_hs_mask;
22 extern unsigned long wildfire_iop_mask;
23 extern unsigned long wildfire_ior_mask;
24 extern unsigned long wildfire_pca_mask;
25 extern unsigned long wildfire_cpu_mask;
26 extern unsigned long wildfire_mem_mask;
27 
28 #define WILDFIRE_QBB_EXISTS(qbbno) (wildfire_soft_qbb_mask & (1 << (qbbno)))
29 
30 #define WILDFIRE_MEM_EXISTS(qbbno) (wildfire_mem_mask & (0xf << ((qbbno) << 2)))
31 
32 #define WILDFIRE_PCA_EXISTS(qbbno, pcano) \
33 		(wildfire_pca_mask & (1 << (((qbbno) << 2) + (pcano))))
34 
35 typedef struct {
36 	volatile unsigned long csr __attribute__((aligned(64)));
37 } wildfire_64;
38 
39 typedef struct {
40 	volatile unsigned long csr __attribute__((aligned(256)));
41 } wildfire_256;
42 
43 typedef struct {
44 	volatile unsigned long csr __attribute__((aligned(2048)));
45 } wildfire_2k;
46 
47 typedef struct {
48 	wildfire_64	qsd_whami;
49 	wildfire_64	qsd_rev;
50 	wildfire_64	qsd_port_present;
51 	wildfire_64	qsd_port_active;
52 	wildfire_64	qsd_fault_ena;
53 	wildfire_64	qsd_cpu_int_ena;
54 	wildfire_64	qsd_mem_config;
55 	wildfire_64	qsd_err_sum;
56 	wildfire_64	ce_sum[4];
57 	wildfire_64	dev_init[4];
58 	wildfire_64	it_int[4];
59 	wildfire_64	ip_int[4];
60 	wildfire_64	uce_sum[4];
61 	wildfire_64	se_sum__non_dev_int[4];
62 	wildfire_64	scratch[4];
63 	wildfire_64	qsd_timer;
64 	wildfire_64	qsd_diag;
65 } wildfire_qsd;
66 
67 typedef struct {
68 	wildfire_256	qsd_whami;
69 	wildfire_256	__pad1;
70 	wildfire_256	ce_sum;
71 	wildfire_256	dev_init;
72 	wildfire_256	it_int;
73 	wildfire_256	ip_int;
74 	wildfire_256	uce_sum;
75 	wildfire_256	se_sum;
76 } wildfire_fast_qsd;
77 
78 typedef struct {
79 	wildfire_2k	qsa_qbb_id;
80 	wildfire_2k	__pad1;
81 	wildfire_2k	qsa_port_ena;
82 	wildfire_2k	qsa_scratch;
83 	wildfire_2k	qsa_config[5];
84 	wildfire_2k	qsa_ref_int;
85 	wildfire_2k	qsa_qbb_pop[2];
86 	wildfire_2k	qsa_dtag_fc;
87 	wildfire_2k	__pad2[3];
88 	wildfire_2k	qsa_diag;
89 	wildfire_2k	qsa_diag_lock[4];
90 	wildfire_2k	__pad3[11];
91 	wildfire_2k	qsa_cpu_err_sum;
92 	wildfire_2k	qsa_misc_err_sum;
93 	wildfire_2k	qsa_tmo_err_sum;
94 	wildfire_2k	qsa_err_ena;
95 	wildfire_2k	qsa_tmo_config;
96 	wildfire_2k	qsa_ill_cmd_err_sum;
97 	wildfire_2k	__pad4[26];
98 	wildfire_2k	qsa_busy_mask;
99 	wildfire_2k	qsa_arr_valid;
100 	wildfire_2k	__pad5[2];
101 	wildfire_2k	qsa_port_map[4];
102 	wildfire_2k	qsa_arr_addr[8];
103 	wildfire_2k	qsa_arr_mask[8];
104 } wildfire_qsa;
105 
106 typedef struct {
107 	wildfire_64	ioa_config;
108 	wildfire_64	iod_config;
109 	wildfire_64	iop_switch_credits;
110 	wildfire_64	__pad1;
111 	wildfire_64	iop_hose_credits;
112 	wildfire_64	__pad2[11];
113 	struct {
114 		wildfire_64	__pad3;
115 		wildfire_64	init;
116 	} iop_hose[4];
117 	wildfire_64	ioa_hose_0_ctrl;
118 	wildfire_64	iod_hose_0_ctrl;
119 	wildfire_64	ioa_hose_1_ctrl;
120 	wildfire_64	iod_hose_1_ctrl;
121 	wildfire_64	ioa_hose_2_ctrl;
122 	wildfire_64	iod_hose_2_ctrl;
123 	wildfire_64	ioa_hose_3_ctrl;
124 	wildfire_64	iod_hose_3_ctrl;
125 	struct {
126 		wildfire_64	target;
127 		wildfire_64	__pad4;
128 	} iop_dev_int[4];
129 
130 	wildfire_64	iop_err_int_target;
131 	wildfire_64	__pad5[7];
132 	wildfire_64	iop_qbb_err_sum;
133 	wildfire_64	__pad6;
134 	wildfire_64	iop_qbb_se_sum;
135 	wildfire_64	__pad7;
136 	wildfire_64	ioa_err_sum;
137 	wildfire_64	iod_err_sum;
138 	wildfire_64	__pad8[4];
139 	wildfire_64	ioa_diag_force_err;
140 	wildfire_64	iod_diag_force_err;
141 	wildfire_64	__pad9[4];
142 	wildfire_64	iop_diag_send_err_int;
143 	wildfire_64	__pad10[15];
144 	wildfire_64	ioa_scratch;
145 	wildfire_64	iod_scratch;
146 } wildfire_iop;
147 
148 typedef struct {
149 	wildfire_2k	gpa_qbb_map[4];
150 	wildfire_2k	gpa_mem_pop_map;
151 	wildfire_2k	gpa_scratch;
152 	wildfire_2k	gpa_diag;
153 	wildfire_2k	gpa_config_0;
154 	wildfire_2k	__pad1;
155 	wildfire_2k	gpa_init_id;
156 	wildfire_2k	gpa_config_2;
157 	/* not complete */
158 } wildfire_gp;
159 
160 typedef struct {
161 	wildfire_64	pca_what_am_i;
162 	wildfire_64	pca_err_sum;
163 	wildfire_64	pca_diag_force_err;
164 	wildfire_64	pca_diag_send_err_int;
165 	wildfire_64	pca_hose_credits;
166 	wildfire_64	pca_scratch;
167 	wildfire_64	pca_micro_addr;
168 	wildfire_64	pca_micro_data;
169 	wildfire_64	pca_pend_int;
170 	wildfire_64	pca_sent_int;
171 	wildfire_64	__pad1;
172 	wildfire_64	pca_stdio_edge_level;
173 	wildfire_64	__pad2[52];
174 	struct {
175 		wildfire_64	target;
176 		wildfire_64	enable;
177 	} pca_int[4];
178 	wildfire_64	__pad3[56];
179 	wildfire_64	pca_alt_sent_int[32];
180 } wildfire_pca;
181 
182 typedef struct {
183 	wildfire_64	ne_what_am_i;
184 	/* not complete */
185 } wildfire_ne;
186 
187 typedef struct {
188 	wildfire_64	fe_what_am_i;
189 	/* not complete */
190 } wildfire_fe;
191 
192 typedef struct {
193 	wildfire_64	pci_io_addr_ext;
194 	wildfire_64	pci_ctrl;
195 	wildfire_64	pci_err_sum;
196 	wildfire_64	pci_err_addr;
197 	wildfire_64	pci_stall_cnt;
198 	wildfire_64	pci_iack_special;
199 	wildfire_64	__pad1[2];
200 	wildfire_64	pci_pend_int;
201 	wildfire_64	pci_sent_int;
202 	wildfire_64	__pad2[54];
203 	struct {
204 		wildfire_64	wbase;
205 		wildfire_64	wmask;
206 		wildfire_64	tbase;
207 	} pci_window[4];
208 	wildfire_64	pci_flush_tlb;
209 	wildfire_64	pci_perf_mon;
210 } wildfire_pci;
211 
212 #define WILDFIRE_ENTITY_SHIFT		18
213 
214 #define WILDFIRE_GP_ENTITY		(0x10UL << WILDFIRE_ENTITY_SHIFT)
215 #define WILDFIRE_IOP_ENTITY		(0x08UL << WILDFIRE_ENTITY_SHIFT)
216 #define WILDFIRE_QSA_ENTITY		(0x04UL << WILDFIRE_ENTITY_SHIFT)
217 #define WILDFIRE_QSD_ENTITY_SLOW	(0x05UL << WILDFIRE_ENTITY_SHIFT)
218 #define WILDFIRE_QSD_ENTITY_FAST	(0x01UL << WILDFIRE_ENTITY_SHIFT)
219 
220 #define WILDFIRE_PCA_ENTITY(pca)	((0xc|(pca))<<WILDFIRE_ENTITY_SHIFT)
221 
222 #define WILDFIRE_BASE		(IDENT_ADDR | (1UL << 40))
223 
224 #define WILDFIRE_QBB_MASK	0x0fUL	/* for now, only 4 bits/16 QBBs */
225 
226 #define WILDFIRE_QBB(q)		((~((long)(q)) & WILDFIRE_QBB_MASK) << 36)
227 #define WILDFIRE_HOSE(h)	((long)(h) << 33)
228 
229 #define WILDFIRE_QBB_IO(q)	(WILDFIRE_BASE | WILDFIRE_QBB(q))
230 #define WILDFIRE_QBB_HOSE(q,h)	(WILDFIRE_QBB_IO(q) | WILDFIRE_HOSE(h))
231 
232 #define WILDFIRE_MEM(q,h)	(WILDFIRE_QBB_HOSE(q,h) | 0x000000000UL)
233 #define WILDFIRE_CONF(q,h)	(WILDFIRE_QBB_HOSE(q,h) | 0x1FE000000UL)
234 #define WILDFIRE_IO(q,h)	(WILDFIRE_QBB_HOSE(q,h) | 0x1FF000000UL)
235 
236 #define WILDFIRE_qsd(q) \
237  ((wildfire_qsd *)(WILDFIRE_QBB_IO(q)|WILDFIRE_QSD_ENTITY_SLOW|(((1UL<<13)-1)<<23)))
238 
239 #define WILDFIRE_fast_qsd() \
240  ((wildfire_fast_qsd *)(WILDFIRE_QBB_IO(0)|WILDFIRE_QSD_ENTITY_FAST|(((1UL<<13)-1)<<23)))
241 
242 #define WILDFIRE_qsa(q) \
243  ((wildfire_qsa *)(WILDFIRE_QBB_IO(q)|WILDFIRE_QSA_ENTITY|(((1UL<<13)-1)<<23)))
244 
245 #define WILDFIRE_iop(q) \
246  ((wildfire_iop *)(WILDFIRE_QBB_IO(q)|WILDFIRE_IOP_ENTITY|(((1UL<<13)-1)<<23)))
247 
248 #define WILDFIRE_gp(q) \
249  ((wildfire_gp *)(WILDFIRE_QBB_IO(q)|WILDFIRE_GP_ENTITY|(((1UL<<13)-1)<<23)))
250 
251 #define WILDFIRE_pca(q,pca) \
252  ((wildfire_pca *)(WILDFIRE_QBB_IO(q)|WILDFIRE_PCA_ENTITY(pca)|(((1UL<<13)-1)<<23)))
253 
254 #define WILDFIRE_ne(q,pca) \
255  ((wildfire_ne *)(WILDFIRE_QBB_IO(q)|WILDFIRE_PCA_ENTITY(pca)|(((1UL<<13)-1)<<23)|(1UL<<16)))
256 
257 #define WILDFIRE_fe(q,pca) \
258  ((wildfire_fe *)(WILDFIRE_QBB_IO(q)|WILDFIRE_PCA_ENTITY(pca)|(((1UL<<13)-1)<<23)|(3UL<<15)))
259 
260 #define WILDFIRE_pci(q,h) \
261  ((wildfire_pci *)(WILDFIRE_QBB_IO(q)|WILDFIRE_PCA_ENTITY(((h)&6)>>1)|((((h)&1)|2)<<16)|(((1UL<<13)-1)<<23)))
262 
263 #define WILDFIRE_IO_BIAS        WILDFIRE_IO(0,0)
264 #define WILDFIRE_MEM_BIAS       WILDFIRE_MEM(0,0) /* ??? */
265 
266 /* The IO address space is larger than 0xffff */
267 #define WILDFIRE_IO_SPACE	(8UL*1024*1024)
268 
269 #ifdef __KERNEL__
270 
271 #ifndef __EXTERN_INLINE
272 #define __EXTERN_INLINE static inline
273 #define __IO_EXTERN_INLINE
274 #endif
275 
276 #define vucp	volatile unsigned char *
277 #define vusp	volatile unsigned short *
278 #define vuip	volatile unsigned int *
279 #define vulp	volatile unsigned long *
280 
wildfire_inb(unsigned long addr)281 __EXTERN_INLINE u8 wildfire_inb(unsigned long addr)
282 {
283 	/* ??? I wish I could get rid of this.  But there's no ioremap
284 	   equivalent for I/O space.  PCI I/O can be forced into the
285 	   correct hose's I/O region, but that doesn't take care of
286 	   legacy ISA crap.  */
287 
288 	addr += WILDFIRE_IO_BIAS;
289 	return __kernel_ldbu(*(vucp)addr);
290 }
291 
wildfire_outb(u8 b,unsigned long addr)292 __EXTERN_INLINE void wildfire_outb(u8 b, unsigned long addr)
293 {
294 	addr += WILDFIRE_IO_BIAS;
295 	__kernel_stb(b, *(vucp)addr);
296 	mb();
297 }
298 
wildfire_inw(unsigned long addr)299 __EXTERN_INLINE u16 wildfire_inw(unsigned long addr)
300 {
301 	addr += WILDFIRE_IO_BIAS;
302 	return __kernel_ldwu(*(vusp)addr);
303 }
304 
wildfire_outw(u16 b,unsigned long addr)305 __EXTERN_INLINE void wildfire_outw(u16 b, unsigned long addr)
306 {
307 	addr += WILDFIRE_IO_BIAS;
308 	__kernel_stw(b, *(vusp)addr);
309 	mb();
310 }
311 
wildfire_inl(unsigned long addr)312 __EXTERN_INLINE u32 wildfire_inl(unsigned long addr)
313 {
314 	addr += WILDFIRE_IO_BIAS;
315 	return *(vuip)addr;
316 }
317 
wildfire_outl(u32 b,unsigned long addr)318 __EXTERN_INLINE void wildfire_outl(u32 b, unsigned long addr)
319 {
320 	addr += WILDFIRE_IO_BIAS;
321 	*(vuip)addr = b;
322 	mb();
323 }
324 
325 /*
326  * Memory functions.  all accesses are done through linear space.
327  */
328 
wildfire_ioremap(unsigned long addr,unsigned long size)329 __EXTERN_INLINE unsigned long wildfire_ioremap(unsigned long addr,
330 					       unsigned long size
331 					       __attribute__((unused)))
332 {
333 	return addr + WILDFIRE_MEM_BIAS;
334 }
335 
wildfire_iounmap(unsigned long addr)336 __EXTERN_INLINE void wildfire_iounmap(unsigned long addr)
337 {
338 	return;
339 }
340 
wildfire_is_ioaddr(unsigned long addr)341 __EXTERN_INLINE int wildfire_is_ioaddr(unsigned long addr)
342 {
343 	return addr >= WILDFIRE_BASE;
344 }
345 
wildfire_readb(unsigned long addr)346 __EXTERN_INLINE u8 wildfire_readb(unsigned long addr)
347 {
348 	return __kernel_ldbu(*(vucp)addr);
349 }
350 
wildfire_readw(unsigned long addr)351 __EXTERN_INLINE u16 wildfire_readw(unsigned long addr)
352 {
353 	return __kernel_ldwu(*(vusp)addr);
354 }
355 
wildfire_readl(unsigned long addr)356 __EXTERN_INLINE u32 wildfire_readl(unsigned long addr)
357 {
358 	return (*(vuip)addr) & 0xffffffff;
359 }
360 
wildfire_readq(unsigned long addr)361 __EXTERN_INLINE u64 wildfire_readq(unsigned long addr)
362 {
363 	return *(vulp)addr;
364 }
365 
wildfire_writeb(u8 b,unsigned long addr)366 __EXTERN_INLINE void wildfire_writeb(u8 b, unsigned long addr)
367 {
368 	__kernel_stb(b, *(vucp)addr);
369 }
370 
wildfire_writew(u16 b,unsigned long addr)371 __EXTERN_INLINE void wildfire_writew(u16 b, unsigned long addr)
372 {
373 	__kernel_stw(b, *(vusp)addr);
374 }
375 
wildfire_writel(u32 b,unsigned long addr)376 __EXTERN_INLINE void wildfire_writel(u32 b, unsigned long addr)
377 {
378 	*(vuip)addr = b;
379 }
380 
wildfire_writeq(u64 b,unsigned long addr)381 __EXTERN_INLINE void wildfire_writeq(u64 b, unsigned long addr)
382 {
383 	*(vulp)addr = b;
384 }
385 
386 #undef vucp
387 #undef vusp
388 #undef vuip
389 #undef vulp
390 
391 #ifdef __WANT_IO_DEF
392 
393 #define __inb(p)		wildfire_inb((unsigned long)(p))
394 #define __inw(p)		wildfire_inw((unsigned long)(p))
395 #define __inl(p)		wildfire_inl((unsigned long)(p))
396 #define __outb(x,p)		wildfire_outb((x),(unsigned long)(p))
397 #define __outw(x,p)		wildfire_outw((x),(unsigned long)(p))
398 #define __outl(x,p)		wildfire_outl((x),(unsigned long)(p))
399 #define __readb(a)		wildfire_readb((unsigned long)(a))
400 #define __readw(a)		wildfire_readw((unsigned long)(a))
401 #define __readl(a)		wildfire_readl((unsigned long)(a))
402 #define __readq(a)		wildfire_readq((unsigned long)(a))
403 #define __writeb(x,a)		wildfire_writeb((x),(unsigned long)(a))
404 #define __writew(x,a)		wildfire_writew((x),(unsigned long)(a))
405 #define __writel(x,a)		wildfire_writel((x),(unsigned long)(a))
406 #define __writeq(x,a)		wildfire_writeq((x),(unsigned long)(a))
407 #define __ioremap(a,s)		wildfire_ioremap((unsigned long)(a),(s))
408 #define __iounmap(a)		wildfire_iounmap((unsigned long)(a))
409 #define __is_ioaddr(a)		wildfire_is_ioaddr((unsigned long)(a))
410 
411 #define inb(p)			__inb(p)
412 #define inw(p)			__inw(p)
413 #define inl(p)			__inl(p)
414 #define outb(x,p)		__outb((x),(p))
415 #define outw(x,p)		__outw((x),(p))
416 #define outl(x,p)		__outl((x),(p))
417 #define __raw_readb(a)		__readb(a)
418 #define __raw_readw(a)		__readw(a)
419 #define __raw_readl(a)		__readl(a)
420 #define __raw_readq(a)		__readq(a)
421 #define __raw_writeb(v,a)	__writeb((v),(a))
422 #define __raw_writew(v,a)	__writew((v),(a))
423 #define __raw_writel(v,a)	__writel((v),(a))
424 #define __raw_writeq(v,a)	__writeq((v),(a))
425 
426 #endif /* __WANT_IO_DEF */
427 
428 #ifdef __IO_EXTERN_INLINE
429 #undef __EXTERN_INLINE
430 #undef __IO_EXTERN_INLINE
431 #endif
432 
433 #endif /* __KERNEL__ */
434 
435 #endif /* __ALPHA_WILDFIRE__H__ */
436