2 * linux/arch/alpha/kernel/core_irongate.c
4 * Based on code written by David A. Rusling (david.rusling@reo.mts.dec.com).
6 * Copyright (C) 1999 Alpha Processor, Inc.,
7 * (David Daniel, Stig Telfer, Soohoon Lee)
9 * Code common to all IRONGATE core logic chips.
12 #include <linux/kernel.h>
13 #include <linux/types.h>
14 #include <linux/pci.h>
15 #include <linux/sched.h>
16 #include <linux/init.h>
18 #include <asm/ptrace.h>
19 #include <asm/system.h>
21 #include <asm/hwrpb.h>
23 #define __EXTERN_INLINE inline
25 #include <asm/core_irongate.h>
26 #undef __EXTERN_INLINE
31 #undef DEBUG_IRONGATE /* define to enable verbose Irongate debug */
34 * BIOS32-style PCI interface:
37 #define DEBUG_CONFIG 0
40 # define DBG_CFG(args) printk args
42 # define DBG_CFG(args)
47 * Given a bus, device, and function number, compute resulting
48 * configuration space address accordingly. It is therefore not safe
49 * to have concurrent invocations to configuration space access
50 * routines, but there really shouldn't be any need for this.
52 * addr[31:24] reserved
53 * addr[23:16] bus number (8 bits = 128 possible buses)
54 * addr[15:11] Device number (5 bits)
55 * addr[10: 8] function number
56 * addr[ 7: 2] register number
59 * if (bus = addr[23:16]) == 0
61 * type 0 config cycle:
62 * addr_on_pci[31:11] = id selection for device = addr[15:11]
63 * addr_on_pci[10: 2] = addr[10: 2] ???
64 * addr_on_pci[ 1: 0] = 00
66 * type 1 config cycle (pass on with no decoding):
67 * addr_on_pci[31:24] = 0
68 * addr_on_pci[23: 2] = addr[23: 2]
69 * addr_on_pci[ 1: 0] = 01
73 * The function number selects which function of a multi-function device
74 * (e.g., SCSI and Ethernet).
76 * The register selects a DWORD (32 bit) register offset. Hence it
77 * doesn't get shifted by 2 bits as we want to "drop" the bottom two
82 mk_conf_addr(struct pci_dev
*dev
, int where
, unsigned long *pci_addr
,
86 u8 bus
= dev
->bus
->number
;
87 u8 device_fn
= dev
->devfn
;
89 DBG_CFG(("mk_conf_addr(bus=%d ,device_fn=0x%x, where=0x%x, "
90 "pci_addr=0x%p, type1=0x%p)\n",
91 bus
, device_fn
, where
, pci_addr
, type1
));
95 addr
= (bus
<< 16) | (device_fn
<< 8) | where
;
96 addr
|= IRONGATE_CONF
;
99 DBG_CFG(("mk_conf_addr: returning pci_addr 0x%lx\n", addr
));
104 irongate_read_config_byte(struct pci_dev
*dev
, int where
, u8
*value
)
109 if (mk_conf_addr(dev
, where
, &addr
, &type1
))
110 return PCIBIOS_DEVICE_NOT_FOUND
;
112 *value
= __kernel_ldbu(*(vucp
)addr
);
113 return PCIBIOS_SUCCESSFUL
;
117 irongate_read_config_word(struct pci_dev
*dev
, int where
, u16
*value
)
122 if (mk_conf_addr(dev
, where
, &addr
, &type1
))
123 return PCIBIOS_DEVICE_NOT_FOUND
;
125 *value
= __kernel_ldwu(*(vusp
)addr
);
126 return PCIBIOS_SUCCESSFUL
;
130 irongate_read_config_dword(struct pci_dev
*dev
, int where
, u32
*value
)
135 if (mk_conf_addr(dev
, where
, &addr
, &type1
))
136 return PCIBIOS_DEVICE_NOT_FOUND
;
138 *value
= *(vuip
)addr
;
139 return PCIBIOS_SUCCESSFUL
;
143 irongate_write_config_byte(struct pci_dev
*dev
, int where
, u8 value
)
148 if (mk_conf_addr(dev
, where
, &addr
, &type1
))
149 return PCIBIOS_DEVICE_NOT_FOUND
;
151 __kernel_stb(value
, *(vucp
)addr
);
153 __kernel_ldbu(*(vucp
)addr
);
154 return PCIBIOS_SUCCESSFUL
;
158 irongate_write_config_word(struct pci_dev
*dev
, int where
, u16 value
)
163 if (mk_conf_addr(dev
, where
, &addr
, &type1
))
164 return PCIBIOS_DEVICE_NOT_FOUND
;
166 __kernel_stw(value
, *(vusp
)addr
);
168 __kernel_ldwu(*(vusp
)addr
);
169 return PCIBIOS_SUCCESSFUL
;
173 irongate_write_config_dword(struct pci_dev
*dev
, int where
, u32 value
)
178 if (mk_conf_addr(dev
, where
, &addr
, &type1
))
179 return PCIBIOS_DEVICE_NOT_FOUND
;
184 return PCIBIOS_SUCCESSFUL
;
188 struct pci_ops irongate_pci_ops
=
190 read_byte
: irongate_read_config_byte
,
191 read_word
: irongate_read_config_word
,
192 read_dword
: irongate_read_config_dword
,
193 write_byte
: irongate_write_config_byte
,
194 write_word
: irongate_write_config_word
,
195 write_dword
: irongate_write_config_dword
198 #ifdef DEBUG_IRONGATE
200 irongate_register_dump(const char *function_name
)
202 printk("%s: Irongate registers:\n"
204 "\tdev_vendor\t0x%08x\n"
205 "\tstat_cmd\t0x%08x\n"
206 "\tclass\t\t0x%08x\n"
207 "\tlatency\t\t0x%08x\n"
211 "\trsrvd0[0]\t0x%08x\n"
212 "\trsrvd0[1]\t0x%08x\n"
213 "\trsrvd0[2]\t0x%08x\n"
214 "\trsrvd0[3]\t0x%08x\n"
215 "\trsrvd0[4]\t0x%08x\n"
216 "\trsrvd0[5]\t0x%08x\n"
217 "\tcapptr\t\t0x%08x\n"
218 "\trsrvd1[0]\t0x%08x\n"
219 "\trsrvd1[1]\t0x%08x\n"
220 "\tbacsr10\t\t0x%08x\n"
221 "\tbacsr32\t\t0x%08x\n"
222 "\tbacsr54\t\t0x%08x\n"
223 "\trsrvd2[0]\t0x%08x\n"
224 "\tdrammap\t\t0x%08x\n"
225 "\tdramtm\t\t0x%08x\n"
226 "\tdramms\t\t0x%08x\n"
227 "\trsrvd3[0]\t0x%08x\n"
229 "\tbiusip\t\t0x%08x\n"
230 "\trsrvd4[0]\t0x%08x\n"
231 "\trsrvd4[1]\t0x%08x\n"
233 "\trsrvd5[0]\t0x%08x\n"
234 "\trsrvd5[1]\t0x%08x\n"
235 "\trsrvd5[2]\t0x%08x\n"
236 "\twhami\t\t0x%08x\n"
237 "\tpciarb\t\t0x%08x\n"
238 "\tpcicfg\t\t0x%08x\n"
239 "\trsrvd6[0]\t0x%08x\n"
240 "\trsrvd6[1]\t0x%08x\n"
241 "\trsrvd6[2]\t0x%08x\n"
242 "\trsrvd6[3]\t0x%08x\n"
243 "\trsrvd6[4]\t0x%08x\n"
244 "\tagpcap\t\t0x%08x\n"
245 "\tagpstat\t\t0x%08x\n"
246 "\tagpcmd\t\t0x%08x\n"
247 "\tagpva\t\t0x%08x\n"
248 "\tagpmode\t\t0x%08x\n"
251 "\tdev_vendor:\t0x%08x\n"
252 "\tcmd_status:\t0x%08x\n"
253 "\trevid_etc :\t0x%08x\n"
254 "\thtype_etc :\t0x%08x\n"
255 "\trsrvd0[0] :\t0x%08x\n"
256 "\trsrvd0[1] :\t0x%08x\n"
257 "\tbus_nmbers:\t0x%08x\n"
258 "\tio_baselim:\t0x%08x\n"
259 "\tmem_bselim:\t0x%08x\n"
260 "\tpf_baselib:\t0x%08x\n"
261 "\trsrvd1[0] :\t0x%08x\n"
262 "\trsrvd1[1] :\t0x%08x\n"
263 "\tio_baselim:\t0x%08x\n"
264 "\trsrvd2[0] :\t0x%08x\n"
265 "\trsrvd2[1] :\t0x%08x\n"
266 "\tinterrupt :\t0x%08x\n",
269 IRONGATE0
->dev_vendor
,
276 IRONGATE0
->rsrvd0
[0],
277 IRONGATE0
->rsrvd0
[1],
278 IRONGATE0
->rsrvd0
[2],
279 IRONGATE0
->rsrvd0
[3],
280 IRONGATE0
->rsrvd0
[4],
281 IRONGATE0
->rsrvd0
[5],
283 IRONGATE0
->rsrvd1
[0],
284 IRONGATE0
->rsrvd1
[1],
288 IRONGATE0
->rsrvd2
[0],
292 IRONGATE0
->rsrvd3
[0],
295 IRONGATE0
->rsrvd4
[0],
296 IRONGATE0
->rsrvd4
[1],
298 IRONGATE0
->rsrvd5
[0],
299 IRONGATE0
->rsrvd5
[1],
300 IRONGATE0
->rsrvd5
[2],
304 IRONGATE0
->rsrvd6
[0],
305 IRONGATE0
->rsrvd6
[1],
306 IRONGATE0
->rsrvd6
[2],
307 IRONGATE0
->rsrvd6
[3],
308 IRONGATE0
->rsrvd6
[4],
314 IRONGATE1
->dev_vendor
,
318 IRONGATE1
->rsrvd0
[0],
319 IRONGATE1
->rsrvd0
[1],
321 IRONGATE1
->io_baselim_regs
,
322 IRONGATE1
->mem_baselim
,
323 IRONGATE1
->pfmem_baselim
,
324 IRONGATE1
->rsrvd1
[0],
325 IRONGATE1
->rsrvd1
[1],
326 IRONGATE1
->io_baselim
,
327 IRONGATE1
->rsrvd2
[0],
328 IRONGATE1
->rsrvd2
[1],
329 IRONGATE1
->interrupt
);
332 #define irongate_register_dump(x)
336 irongate_pci_clr_err(void)
338 unsigned int nmi_ctl
=0;
339 unsigned int IRONGATE_jd
;
342 IRONGATE_jd
= IRONGATE0
->stat_cmd
;
343 printk("Iron stat_cmd %x\n", IRONGATE_jd
);
344 IRONGATE0
->stat_cmd
= IRONGATE_jd
; /* write again clears error bits */
346 IRONGATE_jd
= IRONGATE0
->stat_cmd
; /* re-read to force write */
348 IRONGATE_jd
= IRONGATE0
->dramms
;
349 printk("Iron dramms %x\n", IRONGATE_jd
);
350 IRONGATE0
->dramms
= IRONGATE_jd
; /* write again clears error bits */
352 IRONGATE_jd
= IRONGATE0
->dramms
; /* re-read to force write */
361 IRONGATE_jd
= IRONGATE0
->dramms
;
362 if (IRONGATE_jd
& 0x300) goto again
;
368 irongate_init_arch(void)
370 struct pci_controler
*hose
;
372 IRONGATE0
->stat_cmd
= IRONGATE0
->stat_cmd
& ~0x100;
373 irongate_pci_clr_err();
374 irongate_register_dump(__FUNCTION__
);
377 * Create our single hose.
380 pci_isa_hose
= hose
= alloc_pci_controler();
381 hose
->io_space
= &ioport_resource
;
382 hose
->mem_space
= &iomem_resource
;
385 /* This is for userland consumption. For some reason, the 40-bit
386 PIO bias that we use in the kernel through KSEG didn't work for
387 the page table based user mappings. So make sure we get the
389 hose
->sparse_mem_base
= 0;
390 hose
->sparse_io_base
= 0;
392 = (IRONGATE_MEM
& 0xffffffffff) | 0x80000000000;
394 = (IRONGATE_IO
& 0xffffffffff) | 0x80000000000;
396 hose
->sg_isa
= hose
->sg_pci
= NULL
;
397 __direct_map_base
= 0;
398 __direct_map_size
= 0xffffffff;