Blame view

drivers/parisc/dino.c 31 KB
2874c5fd2   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-or-later
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
4
5
6
7
8
  /*
  **	DINO manager
  **
  **	(c) Copyright 1999 Red Hat Software
  **	(c) Copyright 1999 SuSE GmbH
  **	(c) Copyright 1999,2000 Hewlett-Packard Company
  **	(c) Copyright 2000 Grant Grundler
544f44859   Helge Deller   parisc: Save some...
9
  **	(c) Copyright 2006-2019 Helge Deller
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
10
  **
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  **
  **	This module provides access to Dino PCI bus (config/IOport spaces)
  **	and helps manage Dino IRQ lines.
  **
  **	Dino interrupt handling is a bit complicated.
  **	Dino always writes to the broadcast EIR via irr0 for now.
  **	(BIG WARNING: using broadcast EIR is a really bad thing for SMP!)
  **	Only one processor interrupt is used for the 11 IRQ line 
  **	inputs to dino.
  **
  **	The different between Built-in Dino and Card-Mode
  **	dino is in chip initialization and pci device initialization.
  **
  **	Linux drivers can only use Card-Mode Dino if pci devices I/O port
  **	BARs are configured and used by the driver. Programming MMIO address 
  **	requires substantial knowledge of available Host I/O address ranges
  **	is currently not supported.  Port/Config accessor functions are the
  **	same. "BIOS" differences are handled within the existing routines.
  */
  
  /*	Changes :
  **	2001-06-14 : Clement Moyroud (moyroudc@esiee.fr)
  **		- added support for the integrated RS232. 	
  */
  
  /*
  ** TODO: create a virtual address for each Dino HPA.
  **       GSC code might be able to do this since IODC data tells us
  **       how many pages are used. PCI subsystem could (must?) do this
  **       for PCI drivers devices which implement/use MMIO registers.
  */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42
43
44
45
46
47
48
49
50
51
52
53
  #include <linux/delay.h>
  #include <linux/types.h>
  #include <linux/kernel.h>
  #include <linux/pci.h>
  #include <linux/init.h>
  #include <linux/ioport.h>
  #include <linux/slab.h>
  #include <linux/interrupt.h>	/* for struct irqaction */
  #include <linux/spinlock.h>	/* for spinlock_t and prototypes */
  
  #include <asm/pdc.h>
  #include <asm/page.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
54
55
56
57
  #include <asm/io.h>
  #include <asm/hardware.h>
  
  #include "gsc.h"
9b8eeab01   Christoph Hellwig   parisc: move inte...
58
  #include "iommu.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
  
  #undef DINO_DEBUG
  
  #ifdef DINO_DEBUG
  #define DBG(x...) printk(x)
  #else
  #define DBG(x...)
  #endif
  
  /*
  ** Config accessor functions only pass in the 8-bit bus number
  ** and not the 8-bit "PCI Segment" number. Each Dino will be
  ** assigned a PCI bus number based on "when" it's discovered.
  **
  ** The "secondary" bus number is set to this before calling
  ** pci_scan_bus(). If any PPB's are present, the scan will
  ** discover them and update the "secondary" and "subordinate"
  ** fields in Dino's pci_bus structure.
  **
  ** Changes in the configuration *will* result in a different
  ** bus number for each dino.
  */
f45adcf97   Matthew Wilcox   [PARISC] Fix Dino...
81
82
  #define is_card_dino(id)	((id)->hw_type == HPHW_A_DMA)
  #define is_cujo(id)		((id)->hversion == 0x682)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
  
  #define DINO_IAR0		0x004
  #define DINO_IODC_ADDR		0x008
  #define DINO_IODC_DATA_0	0x008
  #define DINO_IODC_DATA_1	0x008
  #define DINO_IRR0		0x00C
  #define DINO_IAR1		0x010
  #define DINO_IRR1		0x014
  #define DINO_IMR		0x018
  #define DINO_IPR		0x01C
  #define DINO_TOC_ADDR		0x020
  #define DINO_ICR		0x024
  #define DINO_ILR		0x028
  #define DINO_IO_COMMAND		0x030
  #define DINO_IO_STATUS		0x034
  #define DINO_IO_CONTROL		0x038
  #define DINO_IO_GSC_ERR_RESP	0x040
  #define DINO_IO_ERR_INFO	0x044
  #define DINO_IO_PCI_ERR_RESP	0x048
  #define DINO_IO_FBB_EN		0x05c
  #define DINO_IO_ADDR_EN		0x060
  #define DINO_PCI_ADDR		0x064
  #define DINO_CONFIG_DATA	0x068
  #define DINO_IO_DATA		0x06c
  #define DINO_MEM_DATA		0x070	/* Dino 3.x only */
  #define DINO_GSC2X_CONFIG	0x7b4
  #define DINO_GMASK		0x800
  #define DINO_PAMR		0x804
  #define DINO_PAPR		0x808
  #define DINO_DAMODE		0x80c
  #define DINO_PCICMD		0x810
  #define DINO_PCISTS		0x814
  #define DINO_MLTIM		0x81c
  #define DINO_BRDG_FEAT		0x820
  #define DINO_PCIROR		0x824
  #define DINO_PCIWOR		0x828
  #define DINO_TLTIM		0x830
  
  #define DINO_IRQS 11		/* bits 0-10 are architected */
  #define DINO_IRR_MASK	0x5ff	/* only 10 bits are implemented */
4d64c9f58   Helge Deller   [PARISC] Introduc...
123
  #define DINO_LOCAL_IRQS (DINO_IRQS+1)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
  
  #define DINO_MASK_IRQ(x)	(1<<(x))
  
  #define PCIINTA   0x001
  #define PCIINTB   0x002
  #define PCIINTC   0x004
  #define PCIINTD   0x008
  #define PCIINTE   0x010
  #define PCIINTF   0x020
  #define GSCEXTINT 0x040
  /* #define xxx       0x080 - bit 7 is "default" */
  /* #define xxx    0x100 - bit 8 not used */
  /* #define xxx    0x200 - bit 9 not used */
  #define RS232INT  0x400
  
  struct dino_device
  {
  	struct pci_hba_data	hba;	/* 'C' inheritance - must be first */
  	spinlock_t		dinosaur_pen;
  	unsigned long		txn_addr; /* EIR addr to generate interrupt */ 
  	u32			txn_data; /* EIR data assign to each dino */ 
  	u32 			imr;	  /* IRQ's which are enabled */ 
4d64c9f58   Helge Deller   [PARISC] Introduc...
146
  	int			global_irq[DINO_LOCAL_IRQS]; /* map IMR bit to global irq */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
147
148
149
150
  #ifdef DINO_DEBUG
  	unsigned int		dino_irr0; /* save most recent IRQ line stat */
  #endif
  };
e2fcabe0e   Christoph Hellwig   parisc/dino: use ...
151
152
153
154
  static inline struct dino_device *DINO_DEV(struct pci_hba_data *hba)
  {
  	return container_of(hba, struct dino_device, hba);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
155

5fa165910   Helge Deller   parisc: Disable H...
156
157
158
159
160
161
162
163
  /* Check if PCI device is behind a Card-mode Dino. */
  static int pci_dev_is_behind_card_dino(struct pci_dev *dev)
  {
  	struct dino_device *dino_dev;
  
  	dino_dev = DINO_DEV(parisc_walk_tree(dev->bus->bridge));
  	return is_card_dino(&dino_dev->hba.dev->id);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
  /*
   * Dino Configuration Space Accessor Functions
   */
  
  #define DINO_CFG_TOK(bus,dfn,pos) ((u32) ((bus)<<16 | (dfn)<<8 | (pos)))
  
  /*
   * keep the current highest bus count to assist in allocating busses.  This
   * tries to keep a global bus count total so that when we discover an 
   * entirely new bus, it can be given a unique bus number.
   */
  static int dino_current_bus = 0;
  
  static int dino_cfg_read(struct pci_bus *bus, unsigned int devfn, int where,
  		int size, u32 *val)
  {
  	struct dino_device *d = DINO_DEV(parisc_walk_tree(bus->bridge));
b918c62e0   Yinghai Lu   PCI: replace stru...
181
  	u32 local_bus = (bus->parent == NULL) ? 0 : bus->busn_res.start;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
182
183
184
  	u32 v = DINO_CFG_TOK(local_bus, devfn, where & ~3);
  	void __iomem *base_addr = d->hba.base_addr;
  	unsigned long flags;
a8043ecb1   Harvey Harrison   drivers/parisc: r...
185
186
  	DBG("%s: %p, %d, %d, %d
  ", __func__, base_addr, devfn, where,
92b919fe4   Matthew Wilcox   [PARISC] Update d...
187
  									size);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
  	spin_lock_irqsave(&d->dinosaur_pen, flags);
  
  	/* tell HW which CFG address */
  	__raw_writel(v, base_addr + DINO_PCI_ADDR);
  
  	/* generate cfg read cycle */
  	if (size == 1) {
  		*val = readb(base_addr + DINO_CONFIG_DATA + (where & 3));
  	} else if (size == 2) {
  		*val = readw(base_addr + DINO_CONFIG_DATA + (where & 2));
  	} else if (size == 4) {
  		*val = readl(base_addr + DINO_CONFIG_DATA);
  	}
  
  	spin_unlock_irqrestore(&d->dinosaur_pen, flags);
  	return 0;
  }
  
  /*
   * Dino address stepping "feature":
   * When address stepping, Dino attempts to drive the bus one cycle too soon
   * even though the type of cycle (config vs. MMIO) might be different. 
   * The read of Ven/Prod ID is harmless and avoids Dino's address stepping.
   */
  static int dino_cfg_write(struct pci_bus *bus, unsigned int devfn, int where,
  	int size, u32 val)
  {
  	struct dino_device *d = DINO_DEV(parisc_walk_tree(bus->bridge));
b918c62e0   Yinghai Lu   PCI: replace stru...
216
  	u32 local_bus = (bus->parent == NULL) ? 0 : bus->busn_res.start;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
217
218
219
  	u32 v = DINO_CFG_TOK(local_bus, devfn, where & ~3);
  	void __iomem *base_addr = d->hba.base_addr;
  	unsigned long flags;
a8043ecb1   Harvey Harrison   drivers/parisc: r...
220
221
  	DBG("%s: %p, %d, %d, %d
  ", __func__, base_addr, devfn, where,
92b919fe4   Matthew Wilcox   [PARISC] Update d...
222
  									size);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
  	spin_lock_irqsave(&d->dinosaur_pen, flags);
  
  	/* avoid address stepping feature */
  	__raw_writel(v & 0xffffff00, base_addr + DINO_PCI_ADDR);
  	__raw_readl(base_addr + DINO_CONFIG_DATA);
  
  	/* tell HW which CFG address */
  	__raw_writel(v, base_addr + DINO_PCI_ADDR);
  	/* generate cfg read cycle */
  	if (size == 1) {
  		writeb(val, base_addr + DINO_CONFIG_DATA + (where & 3));
  	} else if (size == 2) {
  		writew(val, base_addr + DINO_CONFIG_DATA + (where & 2));
  	} else if (size == 4) {
  		writel(val, base_addr + DINO_CONFIG_DATA);
  	}
  
  	spin_unlock_irqrestore(&d->dinosaur_pen, flags);
  	return 0;
  }
  
  static struct pci_ops dino_cfg_ops = {
  	.read =		dino_cfg_read,
  	.write =	dino_cfg_write,
  };
  
  
  /*
   * Dino "I/O Port" Space Accessor Functions
   *
   * Many PCI devices don't require use of I/O port space (eg Tulip,
   * NCR720) since they export the same registers to both MMIO and
   * I/O port space.  Performance is going to stink if drivers use
   * I/O port instead of MMIO.
   */
  
  #define DINO_PORT_IN(type, size, mask) \
  static u##size dino_in##size (struct pci_hba_data *d, u16 addr) \
  { \
  	u##size v; \
  	unsigned long flags; \
  	spin_lock_irqsave(&(DINO_DEV(d)->dinosaur_pen), flags); \
  	/* tell HW which IO Port address */ \
  	__raw_writel((u32) addr, d->base_addr + DINO_PCI_ADDR); \
  	/* generate I/O PORT read cycle */ \
  	v = read##type(d->base_addr+DINO_IO_DATA+(addr&mask)); \
  	spin_unlock_irqrestore(&(DINO_DEV(d)->dinosaur_pen), flags); \
  	return v; \
  }
  
  DINO_PORT_IN(b,  8, 3)
  DINO_PORT_IN(w, 16, 2)
  DINO_PORT_IN(l, 32, 0)
  
  #define DINO_PORT_OUT(type, size, mask) \
  static void dino_out##size (struct pci_hba_data *d, u16 addr, u##size val) \
  { \
  	unsigned long flags; \
  	spin_lock_irqsave(&(DINO_DEV(d)->dinosaur_pen), flags); \
  	/* tell HW which IO port address */ \
  	__raw_writel((u32) addr, d->base_addr + DINO_PCI_ADDR); \
  	/* generate cfg write cycle */ \
  	write##type(val, d->base_addr+DINO_IO_DATA+(addr&mask)); \
  	spin_unlock_irqrestore(&(DINO_DEV(d)->dinosaur_pen), flags); \
  }
  
  DINO_PORT_OUT(b,  8, 3)
  DINO_PORT_OUT(w, 16, 2)
  DINO_PORT_OUT(l, 32, 0)
df8e5bc6b   Adrian Bunk   parisc: drivers/p...
292
  static struct pci_port_ops dino_port_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
293
294
295
296
297
298
299
  	.inb	= dino_in8,
  	.inw	= dino_in16,
  	.inl	= dino_in32,
  	.outb	= dino_out8,
  	.outw	= dino_out16,
  	.outl	= dino_out32
  };
4c4231ea2   Thomas Gleixner   [PARISC] Convert ...
300
  static void dino_mask_irq(struct irq_data *d)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
301
  {
4c4231ea2   Thomas Gleixner   [PARISC] Convert ...
302
303
  	struct dino_device *dino_dev = irq_data_get_irq_chip_data(d);
  	int local_irq = gsc_find_local_irq(d->irq, dino_dev->global_irq, DINO_LOCAL_IRQS);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
304

04903c06b   Helge Deller   parisc: Show unha...
305
306
  	DBG(KERN_WARNING "%s(0x%px, %d)
  ", __func__, dino_dev, d->irq);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
307
308
309
310
311
  
  	/* Clear the matching bit in the IMR register */
  	dino_dev->imr &= ~(DINO_MASK_IRQ(local_irq));
  	__raw_writel(dino_dev->imr, dino_dev->hba.base_addr+DINO_IMR);
  }
4c4231ea2   Thomas Gleixner   [PARISC] Convert ...
312
  static void dino_unmask_irq(struct irq_data *d)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
313
  {
4c4231ea2   Thomas Gleixner   [PARISC] Convert ...
314
315
  	struct dino_device *dino_dev = irq_data_get_irq_chip_data(d);
  	int local_irq = gsc_find_local_irq(d->irq, dino_dev->global_irq, DINO_LOCAL_IRQS);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
316
  	u32 tmp;
04903c06b   Helge Deller   parisc: Show unha...
317
318
  	DBG(KERN_WARNING "%s(0x%px, %d)
  ", __func__, dino_dev, d->irq);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
  
  	/*
  	** clear pending IRQ bits
  	**
  	** This does NOT change ILR state!
  	** See comment below for ILR usage.
  	*/
  	__raw_readl(dino_dev->hba.base_addr+DINO_IPR);
  
  	/* set the matching bit in the IMR register */
  	dino_dev->imr |= DINO_MASK_IRQ(local_irq);	/* used in dino_isr() */
  	__raw_writel( dino_dev->imr, dino_dev->hba.base_addr+DINO_IMR);
  
  	/* Emulate "Level Triggered" Interrupt
  	** Basically, a driver is blowing it if the IRQ line is asserted
  	** while the IRQ is disabled.  But tulip.c seems to do that....
  	** Give 'em a kluge award and a nice round of applause!
  	**
  	** The gsc_write will generate an interrupt which invokes dino_isr().
  	** dino_isr() will read IPR and find nothing. But then catch this
  	** when it also checks ILR.
  	*/
  	tmp = __raw_readl(dino_dev->hba.base_addr+DINO_ILR);
  	if (tmp & DINO_MASK_IRQ(local_irq)) {
  		DBG(KERN_WARNING "%s(): IRQ asserted! (ILR 0x%x)
  ",
a8043ecb1   Harvey Harrison   drivers/parisc: r...
345
  				__func__, tmp);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
346
347
348
  		gsc_writel(dino_dev->txn_data, dino_dev->txn_addr);
  	}
  }
dfe075650   Thomas Gleixner   parisc: remove ob...
349
  static struct irq_chip dino_interrupt_type = {
4c4231ea2   Thomas Gleixner   [PARISC] Convert ...
350
351
352
  	.name		= "GSC-PCI",
  	.irq_unmask	= dino_unmask_irq,
  	.irq_mask	= dino_mask_irq,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
353
354
355
356
357
358
359
360
361
  };
  
  
  /*
   * Handle a Processor interrupt generated by Dino.
   *
   * ilr_loop counter is a kluge to prevent a "stuck" IRQ line from
   * wedging the CPU. Could be removed or made optional at some point.
   */
7d12e780e   David Howells   IRQ: Maintain reg...
362
  static irqreturn_t dino_isr(int irq, void *intr_dev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
  {
  	struct dino_device *dino_dev = intr_dev;
  	u32 mask;
  	int ilr_loop = 100;
  
  	/* read and acknowledge pending interrupts */
  #ifdef DINO_DEBUG
  	dino_dev->dino_irr0 =
  #endif
  	mask = __raw_readl(dino_dev->hba.base_addr+DINO_IRR0) & DINO_IRR_MASK;
  
  	if (mask == 0)
  		return IRQ_NONE;
  
  ilr_again:
  	do {
  		int local_irq = __ffs(mask);
  		int irq = dino_dev->global_irq[local_irq];
  		DBG(KERN_DEBUG "%s(%d, %p) mask 0x%x
  ",
a8043ecb1   Harvey Harrison   drivers/parisc: r...
383
  			__func__, irq, intr_dev, mask);
ba20085c2   Kyle McMartin   parisc: lay groun...
384
  		generic_handle_irq(irq);
35d8be9c5   Helge Deller   parisc: dino: Uti...
385
  		mask &= ~DINO_MASK_IRQ(local_irq);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
386
387
388
389
390
391
392
393
394
395
396
397
398
  	} while (mask);
  
  	/* Support for level triggered IRQ lines.
  	** 
  	** Dropping this support would make this routine *much* faster.
  	** But since PCI requires level triggered IRQ line to share lines...
  	** device drivers may assume lines are level triggered (and not
  	** edge triggered like EISA/ISA can be).
  	*/
  	mask = __raw_readl(dino_dev->hba.base_addr+DINO_ILR) & dino_dev->imr;
  	if (mask) {
  		if (--ilr_loop > 0)
  			goto ilr_again;
2e37787df   Helge Deller   parisc: Ratelimit...
399
400
  		pr_warn_ratelimited("Dino 0x%px: stuck interrupt %d
  ",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
401
  		       dino_dev->hba.base_addr, mask);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
  	}
  	return IRQ_HANDLED;
  }
  
  static void dino_assign_irq(struct dino_device *dino, int local_irq, int *irqp)
  {
  	int irq = gsc_assign_irq(&dino_interrupt_type, dino);
  	if (irq == NO_IRQ)
  		return;
  
  	*irqp = irq;
  	dino->global_irq[local_irq] = irq;
  }
  
  static void dino_choose_irq(struct parisc_device *dev, void *ctrl)
  {
  	int irq;
  	struct dino_device *dino = ctrl;
  
  	switch (dev->id.sversion) {
  		case 0x00084:	irq =  8; break; /* PS/2 */
  		case 0x0008c:	irq = 10; break; /* RS232 */
  		case 0x00096:	irq =  8; break; /* PS/2 */
  		default:	return;		 /* Unknown */
  	}
  
  	dino_assign_irq(dino, irq, &dev->irq);
  }
04d35d732   Helge Deller   [PARISC] Fix Cirr...
430
431
432
433
434
  
  /*
   * Cirrus 6832 Cardbus reports wrong irq on RDI Tadpole PARISC Laptop (deller@gmx.de)
   * (the irqs are off-by-one, not sure yet if this is a cirrus, dino-hardware or dino-driver problem...)
   */
0fe763c57   Greg Kroah-Hartman   Drivers: misc: re...
435
  static void quirk_cirrus_cardbus(struct pci_dev *dev)
04d35d732   Helge Deller   [PARISC] Fix Cirr...
436
437
438
439
440
441
442
443
  {
  	u8 new_irq = dev->irq - 1;
  	printk(KERN_INFO "PCI: Cirrus Cardbus IRQ fixup for %s, from %d to %d
  ",
  			pci_name(dev), dev->irq, new_irq);
  	dev->irq = new_irq;
  }
  DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_6832, quirk_cirrus_cardbus );
5fa165910   Helge Deller   parisc: Disable H...
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
  #ifdef CONFIG_TULIP
  static void pci_fixup_tulip(struct pci_dev *dev)
  {
  	if (!pci_dev_is_behind_card_dino(dev))
  		return;
  	if (!(pci_resource_flags(dev, 1) & IORESOURCE_MEM))
  		return;
  	pr_warn("%s: HP HSC-PCI Cards with card-mode Dino not yet supported.
  ",
  		pci_name(dev));
  	/* Disable this card by zeroing the PCI resources */
  	memset(&dev->resource[0], 0, sizeof(dev->resource[0]));
  	memset(&dev->resource[1], 0, sizeof(dev->resource[1]));
  }
  DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_DEC, PCI_ANY_ID, pci_fixup_tulip);
  #endif /* CONFIG_TULIP */
04d35d732   Helge Deller   [PARISC] Fix Cirr...
460

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
  static void __init
  dino_bios_init(void)
  {
  	DBG("dino_bios_init
  ");
  }
  
  /*
   * dino_card_setup - Set up the memory space for a Dino in card mode.
   * @bus: the bus under this dino
   *
   * Claim an 8MB chunk of unused IO space and call the generic PCI routines
   * to set up the addresses of the devices on this bus.
   */
  #define _8MB 0x00800000UL
  static void __init
  dino_card_setup(struct pci_bus *bus, void __iomem *base_addr)
  {
  	int i;
  	struct dino_device *dino_dev = DINO_DEV(parisc_walk_tree(bus->bridge));
  	struct resource *res;
  	char name[128];
  	int size;
  
  	res = &dino_dev->hba.lmmio_space;
  	res->flags = IORESOURCE_MEM;
  	size = scnprintf(name, sizeof(name), "Dino LMMIO (%s)", 
d4995244b   Kay Sievers   parisc: dino: str...
488
  			 dev_name(bus->bridge));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
489
490
491
492
493
494
495
496
497
498
  	res->name = kmalloc(size+1, GFP_KERNEL);
  	if(res->name)
  		strcpy((char *)res->name, name);
  	else
  		res->name = dino_dev->hba.lmmio_space.name;
  	
  
  	if (ccio_allocate_resource(dino_dev->hba.dev, res, _8MB,
  				F_EXTEND(0xf0000000UL) | _8MB,
  				F_EXTEND(0xffffffffUL) &~ _8MB, _8MB) < 0) {
0b79ca2a8   Bjorn Helgaas   parisc/PCI: Use l...
499
  		struct pci_dev *dev, *tmp;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
500
501
502
  
  		printk(KERN_ERR "Dino: cannot attach bus %s
  ",
d4995244b   Kay Sievers   parisc: dino: str...
503
  		       dev_name(bus->bridge));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
504
  		/* kill the bus, we can't do anything with it */
0b79ca2a8   Bjorn Helgaas   parisc/PCI: Use l...
505
  		list_for_each_entry_safe(dev, tmp, &bus->devices, bus_list) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
506
507
508
509
510
511
512
513
514
515
516
517
518
  			list_del(&dev->bus_list);
  		}
  			
  		return;
  	}
  	bus->resource[1] = res;
  	bus->resource[0] = &(dino_dev->hba.io_space);
  
  	/* Now tell dino what range it has */
  	for (i = 1; i < 31; i++) {
  		if (res->start == F_EXTEND(0xf0000000UL | (i * _8MB)))
  			break;
  	}
92b919fe4   Matthew Wilcox   [PARISC] Update d...
519
520
  	DBG("DINO GSC WRITE i=%d, start=%lx, dino addr = %p
  ",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
  	    i, res->start, base_addr + DINO_IO_ADDR_EN);
  	__raw_writel(1 << i, base_addr + DINO_IO_ADDR_EN);
  }
  
  static void __init
  dino_card_fixup(struct pci_dev *dev)
  {
  	u32 irq_pin;
  
  	/*
  	** REVISIT: card-mode PCI-PCI expansion chassis do exist.
  	**         Not sure they were ever productized.
  	**         Die here since we'll die later in dino_inb() anyway.
  	*/
  	if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) {
  		panic("Card-Mode Dino: PCI-PCI Bridge not supported
  ");
  	}
  
  	/*
  	** Set Latency Timer to 0xff (not a shared bus)
  	** Set CACHELINE_SIZE.
  	*/
  	dino_cfg_write(dev->bus, dev->devfn, 
  		       PCI_CACHE_LINE_SIZE, 2, 0xff00 | L1_CACHE_BYTES/4); 
  
  	/*
  	** Program INT_LINE for card-mode devices.
  	** The cards are hardwired according to this algorithm.
  	** And it doesn't matter if PPB's are present or not since
  	** the IRQ lines bypass the PPB.
  	**
  	** "-1" converts INTA-D (1-4) to PCIINTA-D (0-3) range.
  	** The additional "-1" adjusts for skewing the IRQ<->slot.
  	*/
  	dino_cfg_read(dev->bus, dev->devfn, PCI_INTERRUPT_PIN, 1, &irq_pin); 
f0e88af85   Bjorn Helgaas   PCI: parisc: use ...
557
  	dev->irq = pci_swizzle_interrupt_pin(dev, irq_pin) - 1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
558
559
560
561
562
563
564
565
566
567
568
569
570
571
  
  	/* Shouldn't really need to do this but it's in case someone tries
  	** to bypass PCI services and look at the card themselves.
  	*/
  	dino_cfg_write(dev->bus, dev->devfn, PCI_INTERRUPT_LINE, 1, dev->irq); 
  }
  
  /* The alignment contraints for PCI bridges under dino */
  #define DINO_BRIDGE_ALIGN 0x100000
  
  
  static void __init
  dino_fixup_bus(struct pci_bus *bus)
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
572
573
          struct pci_dev *dev;
          struct dino_device *dino_dev = DINO_DEV(parisc_walk_tree(bus->bridge));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
574

04903c06b   Helge Deller   parisc: Show unha...
575
576
  	DBG(KERN_WARNING "%s(0x%px) bus %d platform_data 0x%px
  ",
b918c62e0   Yinghai Lu   PCI: replace stru...
577
  	    __func__, bus, bus->busn_res.start,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
578
579
580
581
582
  	    bus->bridge->platform_data);
  
  	/* Firmware doesn't set up card-mode dino, so we have to */
  	if (is_card_dino(&dino_dev->hba.dev->id)) {
  		dino_card_setup(bus, dino_dev->hba.base_addr);
9785d646c   Grant Grundler   parisc: fix wrong...
583
  	} else if (bus->parent) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
584
  		int i;
237865f19   Bjorn Helgaas   PCI: Revert "PCI:...
585
  		pci_read_bridge_bases(bus);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
  		for(i = PCI_BRIDGE_RESOURCES; i < PCI_NUM_RESOURCES; i++) {
  			if((bus->self->resource[i].flags & 
  			    (IORESOURCE_IO | IORESOURCE_MEM)) == 0)
  				continue;
  			
  			if(bus->self->resource[i].flags & IORESOURCE_MEM) {
  				/* There's a quirk to alignment of
  				 * bridge memory resources: the start
  				 * is the alignment and start-end is
  				 * the size.  However, firmware will
  				 * have assigned start and end, so we
  				 * need to take this into account */
  				bus->self->resource[i].end = bus->self->resource[i].end - bus->self->resource[i].start + DINO_BRIDGE_ALIGN;
  				bus->self->resource[i].start = DINO_BRIDGE_ALIGN;
  				
  			}
  					
3fad9b8d5   Joe Perches   drivers/parisc: U...
603
604
  			DBG("DEBUG %s assigning %d [%pR]
  ",
d4995244b   Kay Sievers   parisc: dino: str...
605
  			    dev_name(&bus->self->dev), i,
3fad9b8d5   Joe Perches   drivers/parisc: U...
606
  			    &bus->self->resource[i]);
1e0deabd3   Helge Deller   parisc: dino.c - ...
607
  			WARN_ON(pci_assign_resource(bus->self, i));
3fad9b8d5   Joe Perches   drivers/parisc: U...
608
609
  			DBG("DEBUG %s after assign %d [%pR]
  ",
d4995244b   Kay Sievers   parisc: dino: str...
610
  			    dev_name(&bus->self->dev), i,
3fad9b8d5   Joe Perches   drivers/parisc: U...
611
  			    &bus->self->resource[i]);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
612
613
  		}
  	}
0b79ca2a8   Bjorn Helgaas   parisc/PCI: Use l...
614
  	list_for_each_entry(dev, &bus->devices, bus_list) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
615
616
617
618
619
620
621
  		if (is_card_dino(&dino_dev->hba.dev->id))
  			dino_card_fixup(dev);
  
  		/*
  		** P2PB's only have 2 BARs, no IRQs.
  		** I'd like to just ignore them for now.
  		*/
602c9c9a0   Helge Deller   parisc: Initializ...
622
623
  		if ((dev->class >> 8) == PCI_CLASS_BRIDGE_PCI)  {
  			pcibios_init_bridge(dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
624
  			continue;
602c9c9a0   Helge Deller   parisc: Initializ...
625
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
626

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
  		/* null out the ROM resource if there is one (we don't
  		 * care about an expansion rom on parisc, since it
  		 * usually contains (x86) bios code) */
  		dev->resource[PCI_ROM_RESOURCE].flags = 0;
  				
  		if(dev->irq == 255) {
  
  #define DINO_FIX_UNASSIGNED_INTERRUPTS
  #ifdef DINO_FIX_UNASSIGNED_INTERRUPTS
  
  			/* This code tries to assign an unassigned
  			 * interrupt.  Leave it disabled unless you
  			 * *really* know what you're doing since the
  			 * pin<->interrupt line mapping varies by bus
  			 * and machine */
  
  			u32 irq_pin;
  			
  			dino_cfg_read(dev->bus, dev->devfn, 
  				      PCI_INTERRUPT_PIN, 1, &irq_pin);
f0e88af85   Bjorn Helgaas   PCI: parisc: use ...
647
  			irq_pin = pci_swizzle_interrupt_pin(dev, irq_pin) - 1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
648
649
650
651
652
653
654
655
656
657
658
659
  			printk(KERN_WARNING "Device %s has undefined IRQ, "
  					"setting to %d
  ", pci_name(dev), irq_pin);
  			dino_cfg_write(dev->bus, dev->devfn, 
  				       PCI_INTERRUPT_LINE, 1, irq_pin);
  			dino_assign_irq(dino_dev, irq_pin, &dev->irq);
  #else
  			dev->irq = 65535;
  			printk(KERN_WARNING "Device %s has unassigned IRQ
  ", pci_name(dev));
  #endif
  		} else {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
660
661
662
663
664
  			/* Adjust INT_LINE for that busses region */
  			dino_assign_irq(dino_dev, dev->irq, &dev->irq);
  		}
  	}
  }
df8e5bc6b   Adrian Bunk   parisc: drivers/p...
665
  static struct pci_bios_ops dino_bios_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
666
667
668
669
670
671
672
673
674
675
676
677
  	.init		= dino_bios_init,
  	.fixup_bus	= dino_fixup_bus
  };
  
  
  /*
   *	Initialise a DINO controller chip
   */
  static void __init
  dino_card_init(struct dino_device *dino_dev)
  {
  	u32 brdg_feat = 0x00784e05;
92b919fe4   Matthew Wilcox   [PARISC] Update d...
678
679
680
681
682
683
684
685
  	unsigned long status;
  
  	status = __raw_readl(dino_dev->hba.base_addr+DINO_IO_STATUS);
  	if (status & 0x0000ff80) {
  		__raw_writel(0x00000005,
  				dino_dev->hba.base_addr+DINO_IO_COMMAND);
  		udelay(1);
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
  
  	__raw_writel(0x00000000, dino_dev->hba.base_addr+DINO_GMASK);
  	__raw_writel(0x00000001, dino_dev->hba.base_addr+DINO_IO_FBB_EN);
  	__raw_writel(0x00000000, dino_dev->hba.base_addr+DINO_ICR);
  
  #if 1
  /* REVISIT - should be a runtime check (eg if (CPU_IS_PCX_L) ...) */
  	/*
  	** PCX-L processors don't support XQL like Dino wants it.
  	** PCX-L2 ignore XQL signal and it doesn't matter.
  	*/
  	brdg_feat &= ~0x4;	/* UXQL */
  #endif
  	__raw_writel( brdg_feat, dino_dev->hba.base_addr+DINO_BRDG_FEAT);
  
  	/*
  	** Don't enable address decoding until we know which I/O range
  	** currently is available from the host. Only affects MMIO
  	** and not I/O port space.
  	*/
  	__raw_writel(0x00000000, dino_dev->hba.base_addr+DINO_IO_ADDR_EN);
  
  	__raw_writel(0x00000000, dino_dev->hba.base_addr+DINO_DAMODE);
  	__raw_writel(0x00222222, dino_dev->hba.base_addr+DINO_PCIROR);
  	__raw_writel(0x00222222, dino_dev->hba.base_addr+DINO_PCIWOR);
  
  	__raw_writel(0x00000040, dino_dev->hba.base_addr+DINO_MLTIM);
  	__raw_writel(0x00000080, dino_dev->hba.base_addr+DINO_IO_CONTROL);
  	__raw_writel(0x0000008c, dino_dev->hba.base_addr+DINO_TLTIM);
  
  	/* Disable PAMR before writing PAPR */
  	__raw_writel(0x0000007e, dino_dev->hba.base_addr+DINO_PAMR);
  	__raw_writel(0x0000007f, dino_dev->hba.base_addr+DINO_PAPR);
  	__raw_writel(0x00000000, dino_dev->hba.base_addr+DINO_PAMR);
  
  	/*
  	** Dino ERS encourages enabling FBB (0x6f).
  	** We can't until we know *all* devices below us can support it.
  	** (Something in device configuration header tells us).
  	*/
  	__raw_writel(0x0000004f, dino_dev->hba.base_addr+DINO_PCICMD);
  
  	/* Somewhere, the PCI spec says give devices 1 second
  	** to recover from the #RESET being de-asserted.
  	** Experience shows most devices only need 10ms.
  	** This short-cut speeds up booting significantly.
  	*/
  	mdelay(pci_post_reset_delay);
  }
  
  static int __init
  dino_bridge_init(struct dino_device *dino_dev, const char *name)
  {
  	unsigned long io_addr;
  	int result, i, count=0;
  	struct resource *res, *prevres = NULL;
  	/*
  	 * Decoding IO_ADDR_EN only works for Built-in Dino
  	 * since PDC has already initialized this.
  	 */
  
  	io_addr = __raw_readl(dino_dev->hba.base_addr + DINO_IO_ADDR_EN);
  	if (io_addr == 0) {
  		printk(KERN_WARNING "%s: No PCI devices enabled.
  ", name);
  		return -ENODEV;
  	}
  
  	res = &dino_dev->hba.lmmio_space;
  	for (i = 0; i < 32; i++) {
  		unsigned long start, end;
  
  		if((io_addr & (1 << i)) == 0)
  			continue;
5076c1586   Helge Deller   [PARISC] I/O-Spac...
760
  		start = F_EXTEND(0xf0000000UL) | (i << 23);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
  		end = start + 8 * 1024 * 1024 - 1;
  
  		DBG("DINO RANGE %d is at 0x%lx-0x%lx
  ", count,
  		    start, end);
  
  		if(prevres && prevres->end + 1 == start) {
  			prevres->end = end;
  		} else {
  			if(count >= DINO_MAX_LMMIO_RESOURCES) {
  				printk(KERN_ERR "%s is out of resource windows for range %d (0x%lx-0x%lx)
  ", name, count, start, end);
  				break;
  			}
  			prevres = res;
  			res->start = start;
  			res->end = end;
  			res->flags = IORESOURCE_MEM;
  			res->name = kmalloc(64, GFP_KERNEL);
  			if(res->name)
  				snprintf((char *)res->name, 64, "%s LMMIO %d",
  					 name, count);
  			res++;
  			count++;
  		}
  	}
  
  	res = &dino_dev->hba.lmmio_space;
  
  	for(i = 0; i < DINO_MAX_LMMIO_RESOURCES; i++) {
  		if(res[i].flags == 0)
  			break;
  
  		result = ccio_request_resource(dino_dev->hba.dev, &res[i]);
  		if (result < 0) {
c18b46089   Alexander Beregalov   parisc: drivers: ...
796
  			printk(KERN_ERR "%s: failed to claim PCI Bus address "
3fad9b8d5   Joe Perches   drivers/parisc: U...
797
798
  			       "space %d (%pR)!
  ", name, i, &res[i]);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
  			return result;
  		}
  	}
  	return 0;
  }
  
  static int __init dino_common_init(struct parisc_device *dev,
  		struct dino_device *dino_dev, const char *name)
  {
  	int status;
  	u32 eim;
  	struct gsc_irq gsc_irq;
  	struct resource *res;
  
  	pcibios_register_hba(&dino_dev->hba);
  
  	pci_bios = &dino_bios_ops;   /* used by pci_scan_bus() */
  	pci_port = &dino_port_ops;
  
  	/*
  	** Note: SMP systems can make use of IRR1/IAR1 registers
  	**   But it won't buy much performance except in very
  	**   specific applications/configurations. Note Dino
  	**   still only has 11 IRQ input lines - just map some of them
  	**   to a different processor.
  	*/
  	dev->irq = gsc_alloc_irq(&gsc_irq);
  	dino_dev->txn_addr = gsc_irq.txn_addr;
  	dino_dev->txn_data = gsc_irq.txn_data;
  	eim = ((u32) gsc_irq.txn_addr) | gsc_irq.txn_data;
  
  	/* 
  	** Dino needs a PA "IRQ" to get a processor's attention.
  	** arch/parisc/kernel/irq.c returns an EIRR bit.
  	*/
  	if (dev->irq < 0) {
  		printk(KERN_WARNING "%s: gsc_alloc_irq() failed
  ", name);
  		return 1;
  	}
  
  	status = request_irq(dev->irq, dino_isr, 0, name, dino_dev);
  	if (status) {
  		printk(KERN_WARNING "%s: request_irq() failed with %d
  ", 
  			name, status);
  		return 1;
  	}
  
  	/* Support the serial port which is sometimes attached on built-in
  	 * Dino / Cujo chips.
  	 */
  
  	gsc_fixup_irqs(dev, dino_dev, dino_choose_irq);
  
  	/*
  	** This enables DINO to generate interrupts when it sees
  	** any of its inputs *change*. Just asserting an IRQ
  	** before it's enabled (ie unmasked) isn't good enough.
  	*/
  	__raw_writel(eim, dino_dev->hba.base_addr+DINO_IAR0);
  
  	/*
  	** Some platforms don't clear Dino's IRR0 register at boot time.
  	** Reading will clear it now.
  	*/
  	__raw_readl(dino_dev->hba.base_addr+DINO_IRR0);
  
  	/* allocate I/O Port resource region */
  	res = &dino_dev->hba.io_space;
f45adcf97   Matthew Wilcox   [PARISC] Fix Dino...
869
  	if (!is_cujo(&dev->id)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
870
871
872
873
874
875
876
877
878
  		res->name = "Dino I/O Port";
  	} else {
  		res->name = "Cujo I/O Port";
  	}
  	res->start = HBA_PORT_BASE(dino_dev->hba.hba_num);
  	res->end = res->start + (HBA_PORT_SPACE_SIZE - 1);
  	res->flags = IORESOURCE_IO; /* do not mark it busy ! */
  	if (request_resource(&ioport_resource, res) < 0) {
  		printk(KERN_ERR "%s: request I/O Port region failed "
04903c06b   Helge Deller   parisc: Show unha...
879
880
  		       "0x%lx/%lx (hpa 0x%px)
  ",
c18b46089   Alexander Beregalov   parisc: drivers: ...
881
882
  		       name, (unsigned long)res->start, (unsigned long)res->end,
  		       dino_dev->hba.base_addr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
883
884
885
886
887
888
889
890
891
892
  		return 1;
  	}
  
  	return 0;
  }
  
  #define CUJO_RAVEN_ADDR		F_EXTEND(0xf1000000UL)
  #define CUJO_FIREHAWK_ADDR	F_EXTEND(0xf1604000UL)
  #define CUJO_RAVEN_BADPAGE	0x01003000UL
  #define CUJO_FIREHAWK_BADPAGE	0x01607000UL
544f44859   Helge Deller   parisc: Save some...
893
  static const char dino_vers[][4] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
894
895
896
897
898
  	"2.0",
  	"2.1",
  	"3.0",
  	"3.1"
  };
544f44859   Helge Deller   parisc: Save some...
899
  static const char cujo_vers[][4] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
900
901
902
903
904
905
906
907
908
909
910
  	"1.0",
  	"2.0"
  };
  
  void ccio_cujo20_fixup(struct parisc_device *dev, u32 iovp);
  
  /*
  ** Determine if dino should claim this chip (return 0) or not (return 1).
  ** If so, initialize the chip appropriately (card-mode vs bridge mode).
  ** Much of the initialization is common though.
  */
53f01bba4   Matthew Wilcox   [PARISC] Convert ...
911
  static int __init dino_probe(struct parisc_device *dev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
912
913
914
915
916
  {
  	struct dino_device *dino_dev;	// Dino specific control struct
  	const char *version = "unknown";
  	char *name;
  	int is_cujo = 0;
7590e500a   Bjorn Helgaas   parisc/PCI: dino:...
917
  	LIST_HEAD(resources);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
918
  	struct pci_bus *bus;
53f01bba4   Matthew Wilcox   [PARISC] Convert ...
919
  	unsigned long hpa = dev->hpa.start;
30aa80da4   Yinghai Lu   parisc/PCI: regis...
920
  	int max;
53f01bba4   Matthew Wilcox   [PARISC] Convert ...
921

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
922
923
924
925
  	name = "Dino";
  	if (is_card_dino(&dev->id)) {
  		version = "3.x (card mode)";
  	} else {
f45adcf97   Matthew Wilcox   [PARISC] Fix Dino...
926
  		if (!is_cujo(&dev->id)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
927
928
929
930
931
932
933
934
935
936
937
  			if (dev->id.hversion_rev < 4) {
  				version = dino_vers[dev->id.hversion_rev];
  			}
  		} else {
  			name = "Cujo";
  			is_cujo = 1;
  			if (dev->id.hversion_rev < 2) {
  				version = cujo_vers[dev->id.hversion_rev];
  			}
  		}
  	}
92b919fe4   Matthew Wilcox   [PARISC] Update d...
938
939
  	printk("%s version %s found at 0x%lx
  ", name, version, hpa);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
940

92b919fe4   Matthew Wilcox   [PARISC] Update d...
941
  	if (!request_mem_region(hpa, PAGE_SIZE, name)) {
3335f75a8   Hans Wennborg   parisc: dino: fix...
942
943
  		printk(KERN_ERR "DINO: Hey! Someone took my MMIO space (0x%lx)!
  ",
92b919fe4   Matthew Wilcox   [PARISC] Update d...
944
  			hpa);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
945
946
947
948
949
950
951
952
  		return 1;
  	}
  
  	/* Check for bugs */
  	if (is_cujo && dev->id.hversion_rev == 1) {
  #ifdef CONFIG_IOMMU_CCIO
  		printk(KERN_WARNING "Enabling Cujo 2.0 bug workaround
  ");
92b919fe4   Matthew Wilcox   [PARISC] Update d...
953
  		if (hpa == (unsigned long)CUJO_RAVEN_ADDR) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
954
  			ccio_cujo20_fixup(dev, CUJO_RAVEN_BADPAGE);
92b919fe4   Matthew Wilcox   [PARISC] Update d...
955
  		} else if (hpa == (unsigned long)CUJO_FIREHAWK_ADDR) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
956
957
  			ccio_cujo20_fixup(dev, CUJO_FIREHAWK_BADPAGE);
  		} else {
92b919fe4   Matthew Wilcox   [PARISC] Update d...
958
959
  			printk("Don't recognise Cujo at address 0x%lx, not enabling workaround
  ", hpa);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
  		}
  #endif
  	} else if (!is_cujo && !is_card_dino(&dev->id) &&
  			dev->id.hversion_rev < 3) {
  		printk(KERN_WARNING
  "The GSCtoPCI (Dino hrev %d) bus converter found may exhibit
  "
  "data corruption.  See Service Note Numbers: A4190A-01, A4191A-01.
  "
  "Systems shipped after Aug 20, 1997 will not exhibit this problem.
  "
  "Models affected: C180, C160, C160L, B160L, and B132L workstations.
  
  ",
  			dev->id.hversion_rev);
  /* REVISIT: why are C200/C240 listed in the README table but not
  **   "Models affected"? Could be an omission in the original literature.
  */
  	}
cb6fc18e9   Helge Deller   [PARISC] Use kzal...
979
  	dino_dev = kzalloc(sizeof(struct dino_device), GFP_KERNEL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
980
981
982
983
984
  	if (!dino_dev) {
  		printk("dino_init_chip - couldn't alloc dino_device
  ");
  		return 1;
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
985
  	dino_dev->hba.dev = dev;
4bdc0d676   Christoph Hellwig   remove ioremap_no...
986
  	dino_dev->hba.base_addr = ioremap(hpa, 4096);
409811603   Thomas Bogendoerfer   parisc: pci memor...
987
  	dino_dev->hba.lmmio_space_offset = PCI_F_EXTEND;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
988
989
990
991
992
993
994
995
996
997
998
999
1000
  	spin_lock_init(&dino_dev->dinosaur_pen);
  	dino_dev->hba.iommu = ccio_get_iommu(dev);
  
  	if (is_card_dino(&dev->id)) {
  		dino_card_init(dino_dev);
  	} else {
  		dino_bridge_init(dino_dev, name);
  	}
  
  	if (dino_common_init(dev, dino_dev, name))
  		return 1;
  
  	dev->dev.platform_data = dino_dev;
39c2462e1   Bjorn Helgaas   parisc/PCI: get r...
1001
1002
  	pci_add_resource_offset(&resources, &dino_dev->hba.io_space,
  				HBA_PORT_BASE(dino_dev->hba.hba_num));
7590e500a   Bjorn Helgaas   parisc/PCI: dino:...
1003
  	if (dino_dev->hba.lmmio_space.flags)
39c2462e1   Bjorn Helgaas   parisc/PCI: get r...
1004
1005
  		pci_add_resource_offset(&resources, &dino_dev->hba.lmmio_space,
  					dino_dev->hba.lmmio_space_offset);
7590e500a   Bjorn Helgaas   parisc/PCI: dino:...
1006
  	if (dino_dev->hba.elmmio_space.flags)
39c2462e1   Bjorn Helgaas   parisc/PCI: get r...
1007
1008
  		pci_add_resource_offset(&resources, &dino_dev->hba.elmmio_space,
  					dino_dev->hba.lmmio_space_offset);
7590e500a   Bjorn Helgaas   parisc/PCI: dino:...
1009
1010
  	if (dino_dev->hba.gmmio_space.flags)
  		pci_add_resource(&resources, &dino_dev->hba.gmmio_space);
30aa80da4   Yinghai Lu   parisc/PCI: regis...
1011
1012
1013
1014
  	dino_dev->hba.bus_num.start = dino_current_bus;
  	dino_dev->hba.bus_num.end = 255;
  	dino_dev->hba.bus_num.flags = IORESOURCE_BUS;
  	pci_add_resource(&resources, &dino_dev->hba.bus_num);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1015
1016
1017
1018
  	/*
  	** It's not used to avoid chicken/egg problems
  	** with configuration accessor functions.
  	*/
7590e500a   Bjorn Helgaas   parisc/PCI: dino:...
1019
1020
  	dino_dev->hba.hba_bus = bus = pci_create_root_bus(&dev->dev,
  			 dino_current_bus, &dino_cfg_ops, NULL, &resources);
c4e065762   Bjorn Helgaas   parisc/PCI: dino:...
1021
  	if (!bus) {
fed99b1e8   Grant Grundler   parisc: advertise...
1022
1023
  		printk(KERN_ERR "ERROR: failed to scan PCI bus on %s (duplicate bus number %d?)
  ",
d4995244b   Kay Sievers   parisc: dino: str...
1024
  		       dev_name(&dev->dev), dino_current_bus);
7590e500a   Bjorn Helgaas   parisc/PCI: dino:...
1025
  		pci_free_resource_list(&resources);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1026
1027
  		/* increment the bus number in case of duplicates */
  		dino_current_bus++;
c4e065762   Bjorn Helgaas   parisc/PCI: dino:...
1028
  		return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1029
  	}
c4e065762   Bjorn Helgaas   parisc/PCI: dino:...
1030

30aa80da4   Yinghai Lu   parisc/PCI: regis...
1031
1032
  	max = pci_scan_child_bus(bus);
  	pci_bus_update_busn_res_end(bus, max);
c4e065762   Bjorn Helgaas   parisc/PCI: dino:...
1033
1034
1035
1036
  
  	/* This code *depends* on scanning being single threaded
  	 * if it isn't, this global bus number count will fail
  	 */
30aa80da4   Yinghai Lu   parisc/PCI: regis...
1037
  	dino_current_bus = max + 1;
c4e065762   Bjorn Helgaas   parisc/PCI: dino:...
1038
1039
  	pci_bus_assign_resources(bus);
  	pci_bus_add_devices(bus);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
  	return 0;
  }
  
  /*
   * Normally, we would just test sversion.  But the Elroy PCI adapter has
   * the same sversion as Dino, so we have to check hversion as well.
   * Unfortunately, the J2240 PDC reports the wrong hversion for the first
   * Dino, so we have to test for Dino, Cujo and Dino-in-a-J2240.
   * For card-mode Dino, most machines report an sversion of 9D.  But 715
   * and 725 firmware misreport it as 0x08080 for no adequately explained
   * reason.
   */
cfe4fbfb2   Helge Deller   parisc: Fix secti...
1052
  static const struct parisc_device_id dino_tbl[] __initconst = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1053
1054
1055
1056
1057
1058
1059
  	{ HPHW_A_DMA, HVERSION_REV_ANY_ID, 0x004, 0x0009D },/* Card-mode Dino */
  	{ HPHW_A_DMA, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x08080 }, /* XXX */
  	{ HPHW_BRIDGE, HVERSION_REV_ANY_ID, 0x680, 0xa }, /* Bridge-mode Dino */
  	{ HPHW_BRIDGE, HVERSION_REV_ANY_ID, 0x682, 0xa }, /* Bridge-mode Cujo */
  	{ HPHW_BRIDGE, HVERSION_REV_ANY_ID, 0x05d, 0xa }, /* Dino in a J2240 */
  	{ 0, }
  };
cfe4fbfb2   Helge Deller   parisc: Fix secti...
1060
  static struct parisc_driver dino_driver __refdata = {
bdad1f836   Matthew Wilcox   [PARISC] Change t...
1061
  	.name =		"dino",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1062
  	.id_table =	dino_tbl,
bdad1f836   Matthew Wilcox   [PARISC] Change t...
1063
  	.probe =	dino_probe,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
  };
  
  /*
   * One time initialization to let the world know Dino is here.
   * This is the only routine which is NOT static.
   * Must be called exactly once before pci_init().
   */
  int __init dino_init(void)
  {
  	register_parisc_driver(&dino_driver);
  	return 0;
  }