Blame view

arch/parisc/kernel/pci.c 8.65 KB
071327ec9   Alexander Beregalov   parisc: remove CV...
1
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
4
5
6
7
8
9
10
   * This file is subject to the terms and conditions of the GNU General Public
   * License.  See the file "COPYING" in the main directory of this archive
   * for more details.
   *
   * Copyright (C) 1997, 1998 Ralf Baechle
   * Copyright (C) 1999 SuSE GmbH
   * Copyright (C) 1999-2001 Hewlett-Packard Company
   * Copyright (C) 1999-2001 Grant Grundler
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
11
12
13
14
15
  #include <linux/eisa.h>
  #include <linux/init.h>
  #include <linux/module.h>
  #include <linux/kernel.h>
  #include <linux/pci.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
16
17
18
19
  #include <linux/types.h>
  
  #include <asm/io.h>
  #include <asm/system.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  #include <asm/superio.h>
  
  #define DEBUG_RESOURCES 0
  #define DEBUG_CONFIG 0
  
  #if DEBUG_CONFIG
  # define DBGC(x...)	printk(KERN_DEBUG x)
  #else
  # define DBGC(x...)
  #endif
  
  
  #if DEBUG_RESOURCES
  #define DBG_RES(x...)	printk(KERN_DEBUG x)
  #else
  #define DBG_RES(x...)
  #endif
  
  /* To be used as: mdelay(pci_post_reset_delay);
   *
   * post_reset is the time the kernel should stall to prevent anyone from
   * accessing the PCI bus once #RESET is de-asserted. 
   * PCI spec somewhere says 1 second but with multi-PCI bus systems,
   * this makes the boot time much longer than necessary.
   * 20ms seems to work for all the HP PCI implementations to date.
   *
cb6fc18e9   Helge Deller   [PARISC] Use kzal...
46
   * #define pci_post_reset_delay 50
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
47
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
48

cb6fc18e9   Helge Deller   [PARISC] Use kzal...
49
50
  struct pci_port_ops *pci_port __read_mostly;
  struct pci_bios_ops *pci_bios __read_mostly;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
51

cb6fc18e9   Helge Deller   [PARISC] Use kzal...
52
  static int pci_hba_count __read_mostly;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
53
54
55
  
  /* parisc_pci_hba used by pci_port->in/out() ops to lookup bus data.  */
  #define PCI_HBA_MAX 32
2c9aadabf   Grant Grundler   [PARISC] Remove u...
56
  static struct pci_hba_data *parisc_pci_hba[PCI_HBA_MAX] __read_mostly;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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
123
124
  
  
  /********************************************************************
  **
  ** I/O port space support
  **
  *********************************************************************/
  
  /* EISA port numbers and PCI port numbers share the same interface.  Some
   * machines have both EISA and PCI adapters installed.  Rather than turn
   * pci_port into an array, we reserve bus 0 for EISA and call the EISA
   * routines if the access is to a port on bus 0.  We don't want to fix
   * EISA and ISA drivers which assume port space is <= 0xffff.
   */
  
  #ifdef CONFIG_EISA
  #define EISA_IN(size) if (EISA_bus && (b == 0)) return eisa_in##size(addr)
  #define EISA_OUT(size) if (EISA_bus && (b == 0)) return eisa_out##size(d, addr)
  #else
  #define EISA_IN(size)
  #define EISA_OUT(size)
  #endif
  
  #define PCI_PORT_IN(type, size) \
  u##size in##type (int addr) \
  { \
  	int b = PCI_PORT_HBA(addr); \
  	EISA_IN(size); \
  	if (!parisc_pci_hba[b]) return (u##size) -1; \
  	return pci_port->in##type(parisc_pci_hba[b], PCI_PORT_ADDR(addr)); \
  } \
  EXPORT_SYMBOL(in##type);
  
  PCI_PORT_IN(b,  8)
  PCI_PORT_IN(w, 16)
  PCI_PORT_IN(l, 32)
  
  
  #define PCI_PORT_OUT(type, size) \
  void out##type (u##size d, int addr) \
  { \
  	int b = PCI_PORT_HBA(addr); \
  	EISA_OUT(size); \
  	if (!parisc_pci_hba[b]) return; \
  	pci_port->out##type(parisc_pci_hba[b], PCI_PORT_ADDR(addr), d); \
  } \
  EXPORT_SYMBOL(out##type);
  
  PCI_PORT_OUT(b,  8)
  PCI_PORT_OUT(w, 16)
  PCI_PORT_OUT(l, 32)
  
  
  
  /*
   * BIOS32 replacement.
   */
  static int __init pcibios_init(void)
  {
  	if (!pci_bios)
  		return -1;
  
  	if (pci_bios->init) {
  		pci_bios->init();
  	} else {
  		printk(KERN_WARNING "pci_bios != NULL but init() is!
  ");
  	}
5fd4514bb   Carlos O'Donell   parisc: Set PCI C...
125
126
127
  
  	/* Set the CLS for PCI as early as possible. */
  	pci_cache_line_size = pci_dfl_cache_line_size;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
  	return 0;
  }
  
  
  /* Called from pci_do_scan_bus() *after* walking a bus but before walking PPBs. */
  void pcibios_fixup_bus(struct pci_bus *bus)
  {
  	if (pci_bios->fixup_bus) {
  		pci_bios->fixup_bus(bus);
  	} else {
  		printk(KERN_WARNING "pci_bios != NULL but fixup_bus() is!
  ");
  	}
  }
  
  
  char *pcibios_setup(char *str)
  {
  	return str;
  }
  
  /*
   * Called by pci_set_master() - a driver interface.
   *
   * Legacy PDC guarantees to set:
   *	Map Memory BAR's into PA IO space.
   *	Map Expansion ROM BAR into one common PA IO space per bus.
   *	Map IO BAR's into PCI IO space.
   *	Command (see below)
   *	Cache Line Size
   *	Latency Timer
   *	Interrupt Line
   *	PPB: secondary latency timer, io/mmio base/limit,
   *		bus numbers, bridge control
   *
   */
  void pcibios_set_master(struct pci_dev *dev)
  {
  	u8 lat;
  
  	/* If someone already mucked with this, don't touch it. */
  	pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lat);
  	if (lat >= 16) return;
  
  	/*
  	** HP generally has fewer devices on the bus than other architectures.
  	** upper byte is PCI_LATENCY_TIMER.
  	*/
  	pci_write_config_word(dev, PCI_CACHE_LINE_SIZE,
5fd4514bb   Carlos O'Donell   parisc: Set PCI C...
177
  			      (0x80 << 8) | pci_cache_line_size);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
  }
  
  
  void __init pcibios_init_bus(struct pci_bus *bus)
  {
  	struct pci_dev *dev = bus->self;
  	unsigned short bridge_ctl;
  
  	/* We deal only with pci controllers and pci-pci bridges. */
  	if (!dev || (dev->class >> 8) != PCI_CLASS_BRIDGE_PCI)
  		return;
  
  	/* PCI-PCI bridge - set the cache line and default latency
  	   (32) for primary and secondary buses. */
  	pci_write_config_byte(dev, PCI_SEC_LATENCY_TIMER, 32);
  
  	pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &bridge_ctl);
  	bridge_ctl |= PCI_BRIDGE_CTL_PARITY | PCI_BRIDGE_CTL_SERR;
  	pci_write_config_word(dev, PCI_BRIDGE_CONTROL, bridge_ctl);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
198
199
200
201
  /* called by drivers/pci/setup-bus.c:pci_setup_bridge().  */
  void __devinit pcibios_resource_to_bus(struct pci_dev *dev,
  		struct pci_bus_region *region, struct resource *res)
  {
7425ada2d   Kyle McMartin   [PARISC] Zap unus...
202
203
204
  #ifdef CONFIG_64BIT
  	struct pci_hba_data *hba = HBA_DATA(dev->bus->bridge->platform_data);
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
  
  	if (res->flags & IORESOURCE_IO) {
  		/*
  		** I/O space may see busnumbers here. Something
  		** in the form of 0xbbxxxx where bb is the bus num
  		** and xxxx is the I/O port space address.
  		** Remaining address translation are done in the
  		** PCI Host adapter specific code - ie dino_out8.
  		*/
  		region->start = PCI_PORT_ADDR(res->start);
  		region->end   = PCI_PORT_ADDR(res->end);
  	} else if (res->flags & IORESOURCE_MEM) {
  		/* Convert MMIO addr to PCI addr (undo global virtualization) */
  		region->start = PCI_BUS_ADDR(hba, res->start);
  		region->end   = PCI_BUS_ADDR(hba, res->end);
  	}
  
  	DBG_RES("pcibios_resource_to_bus(%02x %s [%lx,%lx])
  ",
7425ada2d   Kyle McMartin   [PARISC] Zap unus...
224
  		dev->bus->number, res->flags & IORESOURCE_IO ? "IO" : "MEM",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
225
  		region->start, region->end);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
226
  }
0f94c8e12   Dominik Brodowski   [PATCH] Add pcibi...
227
228
229
  void pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res,
  			      struct pci_bus_region *region)
  {
96629c0b1   Helge Deller   [PARISC] Clean up...
230
  #ifdef CONFIG_64BIT
7425ada2d   Kyle McMartin   [PARISC] Zap unus...
231
  	struct pci_hba_data *hba = HBA_DATA(dev->bus->bridge->platform_data);
96629c0b1   Helge Deller   [PARISC] Clean up...
232
  #endif
0f94c8e12   Dominik Brodowski   [PATCH] Add pcibi...
233
234
235
236
237
238
239
240
241
242
243
  
  	if (res->flags & IORESOURCE_MEM) {
  		res->start = PCI_HOST_ADDR(hba, region->start);
  		res->end = PCI_HOST_ADDR(hba, region->end);
  	}
  
  	if (res->flags & IORESOURCE_IO) {
  		res->start = region->start;
  		res->end = region->end;
  	}
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
244
245
  #ifdef CONFIG_HOTPLUG
  EXPORT_SYMBOL(pcibios_resource_to_bus);
0f94c8e12   Dominik Brodowski   [PATCH] Add pcibi...
246
  EXPORT_SYMBOL(pcibios_bus_to_resource);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
247
248
249
250
251
252
253
254
255
256
257
  #endif
  
  /*
   * pcibios align resources() is called every time generic PCI code
   * wants to generate a new address. The process of looking for
   * an available address, each candidate is first "aligned" and
   * then checked if the resource is available until a match is found.
   *
   * Since we are just checking candidates, don't use any fields other
   * than res->start.
   */
3b7a17fcd   Dominik Brodowski   resource/PCI: mar...
258
  resource_size_t pcibios_align_resource(void *data, const struct resource *res,
e31dd6e45   Greg Kroah-Hartman   [PATCH] 64bit res...
259
  				resource_size_t size, resource_size_t alignment)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
260
  {
b26b2d494   Dominik Brodowski   resource/PCI: ali...
261
  	resource_size_t mask, align, start = res->start;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
262
263
264
265
266
267
268
269
270
271
272
273
  
  	DBG_RES("pcibios_align_resource(%s, (%p) [%lx,%lx]/%x, 0x%lx, 0x%lx)
  ",
  		pci_name(((struct pci_dev *) data)),
  		res->parent, res->start, res->end,
  		(int) res->flags, size, alignment);
  
  	/* If it's not IO, then it's gotta be MEM */
  	align = (res->flags & IORESOURCE_IO) ? PCIBIOS_MIN_IO : PCIBIOS_MIN_MEM;
  
  	/* Align to largest of MIN or input size */
  	mask = max(alignment, align) - 1;
b26b2d494   Dominik Brodowski   resource/PCI: ali...
274
275
  	start += mask;
  	start &= ~mask;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
276

b26b2d494   Dominik Brodowski   resource/PCI: ali...
277
  	return start;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
278
279
280
281
282
283
284
285
286
287
288
289
290
  }
  
  
  /*
   * A driver is enabling the device.  We make sure that all the appropriate
   * bits are set to allow the device to operate as the driver is expecting.
   * We enable the port IO and memory IO bits if the device has any BARs of
   * that type, and we enable the PERR and SERR bits unconditionally.
   * Drivers that do not need parity (eg graphics and possibly networking)
   * can clear these bits if they want.
   */
  int pcibios_enable_device(struct pci_dev *dev, int mask)
  {
c9e9e0bfc   Bjorn Helgaas   PCI: parisc: use ...
291
292
  	int err;
  	u16 cmd, old_cmd;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
293

c9e9e0bfc   Bjorn Helgaas   PCI: parisc: use ...
294
295
296
  	err = pci_enable_resources(dev, mask);
  	if (err < 0)
  		return err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
297

c9e9e0bfc   Bjorn Helgaas   PCI: parisc: use ...
298
299
  	pci_read_config_word(dev, PCI_COMMAND, &cmd);
  	old_cmd = cmd;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
300
301
302
303
304
305
306
307
  
  	cmd |= (PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
  
  #if 0
  	/* If bridge/bus controller has FBB enabled, child must too. */
  	if (dev->bus->bridge_ctl & PCI_BRIDGE_CTL_FAST_BACK)
  		cmd |= PCI_COMMAND_FAST_BACK;
  #endif
c9e9e0bfc   Bjorn Helgaas   PCI: parisc: use ...
308
309
310
311
312
313
314
  
  	if (cmd != old_cmd) {
  		dev_info(&dev->dev, "enabling SERR and PARITY (%04x -> %04x)
  ",
  			old_cmd, cmd);
  		pci_write_config_word(dev, PCI_COMMAND, cmd);
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
  	return 0;
  }
  
  
  /* PA-RISC specific */
  void pcibios_register_hba(struct pci_hba_data *hba)
  {
  	if (pci_hba_count >= PCI_HBA_MAX) {
  		printk(KERN_ERR "PCI: Too many Host Bus Adapters
  ");
  		return;
  	}
  
  	parisc_pci_hba[pci_hba_count] = hba;
  	hba->hba_num = pci_hba_count++;
  }
  
  subsys_initcall(pcibios_init);