2 * linux/arch/alpha/kernel/core_pyxis.c
4 * Based on code written by David A Rusling (david.rusling@reo.mts.dec.com).
6 * Code common to all PYXIS core logic chips.
9 #include <linux/config.h>
10 #include <linux/kernel.h>
11 #include <linux/types.h>
12 #include <linux/pci.h>
13 #include <linux/sched.h>
14 #include <linux/init.h>
16 #include <asm/ptrace.h>
17 #include <asm/system.h>
20 #define __EXTERN_INLINE inline
22 #include <asm/core_pyxis.h>
23 #undef __EXTERN_INLINE
29 /* NOTE: Herein are back-to-back mb instructions. They are magic.
30 One plausible explanation is that the I/O controller does not properly
31 handle the system transaction. Another involves timing. Ho hum. */
34 * BIOS32-style PCI interface:
37 #define DEBUG_CONFIG 0
40 # define DBG_CNF(args) printk args
42 # define DBG_CNF(args)
47 * Given a bus, device, and function number, compute resulting
48 * configuration space address and setup the PYXIS_HAXR2 register
49 * accordingly. It is therefore not safe to have concurrent
50 * invocations to configuration space access routines, but there
51 * really shouldn't be any need for this.
55 * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1
56 * 3 2|1 0 9 8|7 6 5 4|3 2 1 0|9 8 7 6|5 4 3 2|1 0 9 8|7 6 5 4|3 2 1 0
57 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
58 * | | |D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|D|F|F|F|R|R|R|R|R|R|0|0|
59 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
61 * 31:11 Device select bit.
62 * 10:8 Function number
67 * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1
68 * 3 2|1 0 9 8|7 6 5 4|3 2 1 0|9 8 7 6|5 4 3 2|1 0 9 8|7 6 5 4|3 2 1 0
69 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
70 * | | | | | | | | | | |B|B|B|B|B|B|B|B|D|D|D|D|D|F|F|F|R|R|R|R|R|R|0|1|
71 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
74 * 23:16 bus number (8 bits = 128 possible buses)
75 * 15:11 Device number (5 bits)
76 * 10:8 function number
80 * The function number selects which function of a multi-function device
81 * (e.g., SCSI and Ethernet).
83 * The register selects a DWORD (32 bit) register offset. Hence it
84 * doesn't get shifted by 2 bits as we want to "drop" the bottom two
89 mk_conf_addr(struct pci_dev
*dev
, int where
, unsigned long *pci_addr
,
92 u8 bus
= dev
->bus
->number
;
93 u8 device_fn
= dev
->devfn
;
95 *type1
= (bus
== 0) ? 0 : 1;
96 *pci_addr
= (bus
<< 16) | (device_fn
<< 8) | (where
);
98 DBG_CNF(("mk_conf_addr(bus=%d ,device_fn=0x%x, where=0x%x,"
99 " returning address 0x%p\n"
100 bus
, device_fn
, where
, *pci_addr
));
106 conf_read(unsigned long addr
, unsigned char type1
)
109 unsigned int stat0
, value
, temp
;
110 unsigned int pyxis_cfg
= 0;
112 __save_and_cli(flags
); /* avoid getting hit by machine check */
114 /* Reset status register to avoid losing errors. */
115 stat0
= *(vuip
)PYXIS_ERR
;
116 *(vuip
)PYXIS_ERR
= stat0
; mb();
117 temp
= *(vuip
)PYXIS_ERR
; /* re-read to force write */
119 /* If Type1 access, must set PYXIS CFG. */
121 pyxis_cfg
= *(vuip
)PYXIS_CFG
;
122 *(vuip
)PYXIS_CFG
= (pyxis_cfg
& ~3L) | 1; mb();
123 temp
= *(vuip
)PYXIS_CFG
; /* re-read to force write */
128 mcheck_expected(0) = 1;
132 /* Access configuration space. */
137 if (mcheck_taken(0)) {
142 mcheck_expected(0) = 0;
145 /* If Type1 access, must reset IOC CFG so normal IO space ops work. */
147 *(vuip
)PYXIS_CFG
= pyxis_cfg
& ~3L; mb();
148 temp
= *(vuip
)PYXIS_CFG
; /* re-read to force write */
151 __restore_flags(flags
);
153 DBG_CNF(("conf_read(addr=0x%lx, type1=%d) = %#x\n",
154 addr
, type1
, value
));
160 conf_write(unsigned long addr
, unsigned int value
, unsigned char type1
)
163 unsigned int stat0
, temp
;
164 unsigned int pyxis_cfg
= 0;
166 __save_and_cli(flags
); /* avoid getting hit by machine check */
168 /* Reset status register to avoid losing errors. */
169 stat0
= *(vuip
)PYXIS_ERR
;
170 *(vuip
)PYXIS_ERR
= stat0
; mb();
171 temp
= *(vuip
)PYXIS_ERR
; /* re-read to force write */
173 /* If Type1 access, must set PYXIS CFG. */
175 pyxis_cfg
= *(vuip
)PYXIS_CFG
;
176 *(vuip
)PYXIS_CFG
= (pyxis_cfg
& ~3L) | 1; mb();
177 temp
= *(vuip
)PYXIS_CFG
; /* re-read to force write */
182 mcheck_expected(0) = 1;
186 /* Access configuration space. */
189 temp
= *(vuip
)addr
; /* read back to force the write */
190 mcheck_expected(0) = 0;
193 /* If Type1 access, must reset IOC CFG so normal IO space ops work. */
195 *(vuip
)PYXIS_CFG
= pyxis_cfg
& ~3L; mb();
196 temp
= *(vuip
)PYXIS_CFG
; /* re-read to force write */
199 __restore_flags(flags
);
201 DBG_CNF(("conf_write(addr=%#lx, value=%#x, type1=%d)\n",
202 addr
, value
, type1
));
206 pyxis_read_config_byte(struct pci_dev
*dev
, int where
, u8
*value
)
208 unsigned long addr
, pci_addr
;
211 if (mk_conf_addr(dev
, where
, &pci_addr
, &type1
))
212 return PCIBIOS_DEVICE_NOT_FOUND
;
214 addr
= (pci_addr
<< 5) + 0x00 + PYXIS_CONF
;
215 *value
= conf_read(addr
, type1
) >> ((where
& 3) * 8);
216 return PCIBIOS_SUCCESSFUL
;
220 pyxis_read_config_word(struct pci_dev
*dev
, int where
, u16
*value
)
222 unsigned long addr
, pci_addr
;
225 if (mk_conf_addr(dev
, where
, &pci_addr
, &type1
))
226 return PCIBIOS_DEVICE_NOT_FOUND
;
228 addr
= (pci_addr
<< 5) + 0x08 + PYXIS_CONF
;
229 *value
= conf_read(addr
, type1
) >> ((where
& 3) * 8);
230 return PCIBIOS_SUCCESSFUL
;
234 pyxis_read_config_dword(struct pci_dev
*dev
, int where
, u32
*value
)
236 unsigned long addr
, pci_addr
;
239 if (mk_conf_addr(dev
, where
, &pci_addr
, &type1
))
240 return PCIBIOS_DEVICE_NOT_FOUND
;
242 addr
= (pci_addr
<< 5) + 0x18 + PYXIS_CONF
;
243 *value
= conf_read(addr
, type1
);
244 return PCIBIOS_SUCCESSFUL
;
248 pyxis_write_config(struct pci_dev
*dev
, int where
, u32 value
, long mask
)
250 unsigned long addr
, pci_addr
;
253 if (mk_conf_addr(dev
, where
, &pci_addr
, &type1
))
254 return PCIBIOS_DEVICE_NOT_FOUND
;
256 addr
= (pci_addr
<< 5) + mask
+ PYXIS_CONF
;
257 conf_write(addr
, value
<< ((where
& 3) * 8), type1
);
258 return PCIBIOS_SUCCESSFUL
;
262 pyxis_write_config_byte(struct pci_dev
*dev
, int where
, u8 value
)
264 return pyxis_write_config(dev
, where
, value
, 0x00);
268 pyxis_write_config_word(struct pci_dev
*dev
, int where
, u16 value
)
270 return pyxis_write_config(dev
, where
, value
, 0x08);
274 pyxis_write_config_dword(struct pci_dev
*dev
, int where
, u32 value
)
276 return pyxis_write_config(dev
, where
, value
, 0x18);
279 struct pci_ops pyxis_pci_ops
=
281 read_byte
: pyxis_read_config_byte
,
282 read_word
: pyxis_read_config_word
,
283 read_dword
: pyxis_read_config_dword
,
284 write_byte
: pyxis_write_config_byte
,
285 write_word
: pyxis_write_config_word
,
286 write_dword
: pyxis_write_config_dword
290 pyxis_init_arch(unsigned long *mem_start
, unsigned long *mem_end
)
292 struct pci_controler
*hose
;
296 printk("pyxis_init: PYXIS_ERR_MASK 0x%x\n", *(vuip
)PYXIS_ERR_MASK
);
297 printk("pyxis_init: PYXIS_ERR 0x%x\n", *(vuip
)PYXIS_ERR
);
298 printk("pyxis_init: PYXIS_INT_REQ 0x%lx\n", *(vulp
)PYXIS_INT_REQ
);
299 printk("pyxis_init: PYXIS_INT_MASK 0x%lx\n", *(vulp
)PYXIS_INT_MASK
);
300 printk("pyxis_init: PYXIS_INT_ROUTE 0x%lx\n", *(vulp
)PYXIS_INT_ROUTE
);
301 printk("pyxis_init: PYXIS_INT_HILO 0x%lx\n", *(vulp
)PYXIS_INT_HILO
);
302 printk("pyxis_init: PYXIS_INT_CNFG 0x%x\n", *(vuip
)PYXIS_INT_CNFG
);
303 printk("pyxis_init: PYXIS_RT_COUNT 0x%lx\n", *(vulp
)PYXIS_RT_COUNT
);
307 * Set up error reporting. Make sure CPU_PE is OFF in the mask.
309 temp
= *(vuip
)PYXIS_ERR_MASK
;
311 *(vuip
)PYXIS_ERR_MASK
= temp
; mb();
312 temp
= *(vuip
)PYXIS_ERR_MASK
; /* re-read to force write */
314 temp
= *(vuip
)PYXIS_ERR
;
315 temp
|= 0x180; /* master/target abort */
316 *(vuip
)PYXIS_ERR
= temp
; mb();
317 temp
= *(vuip
)PYXIS_ERR
; /* re-read to force write */
320 * Set up the PCI->physical memory translation windows.
321 * For now, windows 2 and 3 are disabled. In the future, we may
322 * want to use them to do scatter/gather DMA.
324 * Window 0 goes at 2 GB and is 1 GB large.
325 * Window 1 goes at 3 GB and is 1 GB large.
328 *(vuip
)PYXIS_W0_BASE
= PYXIS_DMA_WIN0_BASE_DEFAULT
| 1U;
329 *(vuip
)PYXIS_W0_MASK
= (PYXIS_DMA_WIN0_SIZE_DEFAULT
- 1) & 0xfff00000U
;
330 *(vuip
)PYXIS_T0_BASE
= PYXIS_DMA_WIN0_TRAN_DEFAULT
>> 2;
332 *(vuip
)PYXIS_W1_BASE
= PYXIS_DMA_WIN1_BASE_DEFAULT
| 1U;
333 *(vuip
)PYXIS_W1_MASK
= (PYXIS_DMA_WIN1_SIZE_DEFAULT
- 1) & 0xfff00000U
;
334 *(vuip
)PYXIS_T1_BASE
= PYXIS_DMA_WIN1_TRAN_DEFAULT
>> 2;
336 *(vuip
)PYXIS_W2_BASE
= 0x0;
337 *(vuip
)PYXIS_W3_BASE
= 0x0;
341 * Next, clear the PYXIS_CFG register, which gets used
342 * for PCI Config Space accesses. That is the way
343 * we want to use it, and we do not want to depend on
344 * what ARC or SRM might have left behind...
347 unsigned int pyxis_cfg
, temp
;
348 pyxis_cfg
= *(vuip
)PYXIS_CFG
; mb();
349 if (pyxis_cfg
!= 0) {
351 printk("PYXIS_init: CFG was 0x%x\n", pyxis_cfg
);
353 *(vuip
)PYXIS_CFG
= 0; mb();
354 temp
= *(vuip
)PYXIS_CFG
; /* re-read to force write */
359 *(vuip
)PYXIS_HAE_MEM
= 0U; mb();
360 *(vuip
)PYXIS_HAE_MEM
; /* re-read to force write */
361 *(vuip
)PYXIS_HAE_IO
= 0; mb();
362 *(vuip
)PYXIS_HAE_IO
; /* re-read to force write */
365 * Finally, check that the PYXIS_CTRL1 has IOA_BEN set for
366 * enabling byte/word PCI bus space(s) access.
370 ctrl1
= *(vuip
) PYXIS_CTRL1
;
373 printk("PYXIS_init: enabling byte/word PCI space\n");
375 *(vuip
) PYXIS_CTRL1
= ctrl1
| 1; mb();
376 ctrl1
= *(vuip
)PYXIS_CTRL1
; /* re-read */
381 * Create our single hose.
384 hose
= alloc_pci_controler(mem_start
);
385 hose
->io_space
= &ioport_resource
;
386 hose
->mem_space
= &iomem_resource
;
387 hose
->config_space
= PYXIS_CONF
;
392 pyxis_pci_clr_err(void)
395 *(vuip
)PYXIS_ERR
= 0x0180;
397 *(vuip
)PYXIS_ERR
; /* re-read to force write */
401 pyxis_machine_check(unsigned long vector
, unsigned long la_ptr
,
402 struct pt_regs
* regs
)
404 /* Clear the error before reporting anything. */
412 process_mcheck_info(vector
, la_ptr
, regs
, "PYXIS", mcheck_expected(0));