2 * linux/arch/alpha/kernel/core_titan.c
4 * Code common to all TITAN core logic chips.
7 #include <linux/config.h>
8 #include <linux/kernel.h>
9 #include <linux/types.h>
10 #include <linux/pci.h>
11 #include <linux/sched.h>
12 #include <linux/init.h>
14 #include <asm/ptrace.h>
15 #include <asm/system.h>
18 #define __EXTERN_INLINE inline
20 #include <asm/core_titan.h>
21 #undef __EXTERN_INLINE
26 unsigned TITAN_agp
= 0;
30 unsigned long wsba
[4];
33 } saved_pachip_port
[4];
36 * BIOS32-style PCI interface:
39 #define DEBUG_MCHECK 0 /* 0 = minimum, 1 = debug, 2 = dump+dump */
40 #define DEBUG_CONFIG 0
43 # define DBG_CFG(args) printk args
45 # define DBG_CFG(args)
49 * Given a bus, device, and function number, compute resulting
50 * configuration space address
51 * accordingly. It is therefore not safe to have concurrent
52 * invocations to configuration space access routines, but there
53 * really shouldn't be any need for this.
55 * Note that all config space accesses use Type 1 address format.
57 * Note also that type 1 is determined by non-zero bus number.
61 * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1
62 * 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
63 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
64 * | | | | | | | | | | |B|B|B|B|B|B|B|B|D|D|D|D|D|F|F|F|R|R|R|R|R|R|0|1|
65 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
68 * 23:16 bus number (8 bits = 128 possible buses)
69 * 15:11 Device number (5 bits)
70 * 10:8 function number
74 * The function number selects which function of a multi-function device
75 * (e.g., SCSI and Ethernet).
77 * The register selects a DWORD (32 bit) register offset. Hence it
78 * doesn't get shifted by 2 bits as we want to "drop" the bottom two
83 mk_conf_addr(struct pci_dev
*dev
, int where
, unsigned long *pci_addr
,
86 struct pci_controler
*hose
= dev
->sysdata
;
88 u8 bus
= dev
->bus
->number
;
89 u8 device_fn
= dev
->devfn
;
91 DBG_CFG(("mk_conf_addr(bus=%d ,device_fn=0x%x, where=0x%x, "
92 "pci_addr=0x%p, type1=0x%p)\n",
93 bus
, device_fn
, where
, pci_addr
, type1
));
95 if (hose
->first_busno
== dev
->bus
->number
)
99 addr
= (bus
<< 16) | (device_fn
<< 8) | where
;
100 addr
|= hose
->config_space_base
;
103 DBG_CFG(("mk_conf_addr: returning pci_addr 0x%lx\n", addr
));
108 titan_read_config_byte(struct pci_dev
*dev
, int where
, u8
*value
)
113 if (mk_conf_addr(dev
, where
, &addr
, &type1
))
114 return PCIBIOS_DEVICE_NOT_FOUND
;
116 *value
= __kernel_ldbu(*(vucp
)addr
);
117 return PCIBIOS_SUCCESSFUL
;
121 titan_read_config_word(struct pci_dev
*dev
, int where
, u16
*value
)
126 if (mk_conf_addr(dev
, where
, &addr
, &type1
))
127 return PCIBIOS_DEVICE_NOT_FOUND
;
129 *value
= __kernel_ldwu(*(vusp
)addr
);
130 return PCIBIOS_SUCCESSFUL
;
134 titan_read_config_dword(struct pci_dev
*dev
, int where
, u32
*value
)
139 if (mk_conf_addr(dev
, where
, &addr
, &type1
))
140 return PCIBIOS_DEVICE_NOT_FOUND
;
142 *value
= *(vuip
)addr
;
143 return PCIBIOS_SUCCESSFUL
;
147 titan_write_config_byte(struct pci_dev
*dev
, int where
, u8 value
)
152 if (mk_conf_addr(dev
, where
, &addr
, &type1
))
153 return PCIBIOS_DEVICE_NOT_FOUND
;
155 __kernel_stb(value
, *(vucp
)addr
);
157 __kernel_ldbu(*(vucp
)addr
);
158 return PCIBIOS_SUCCESSFUL
;
162 titan_write_config_word(struct pci_dev
*dev
, int where
, u16 value
)
167 if (mk_conf_addr(dev
, where
, &addr
, &type1
))
168 return PCIBIOS_DEVICE_NOT_FOUND
;
170 __kernel_stw(value
, *(vusp
)addr
);
172 __kernel_ldwu(*(vusp
)addr
);
173 return PCIBIOS_SUCCESSFUL
;
177 titan_write_config_dword(struct pci_dev
*dev
, int where
, u32 value
)
182 if (mk_conf_addr(dev
, where
, &addr
, &type1
))
183 return PCIBIOS_DEVICE_NOT_FOUND
;
188 return PCIBIOS_SUCCESSFUL
;
191 struct pci_ops titan_pci_ops
=
193 read_byte
: titan_read_config_byte
,
194 read_word
: titan_read_config_word
,
195 read_dword
: titan_read_config_dword
,
196 write_byte
: titan_write_config_byte
,
197 write_word
: titan_write_config_word
,
198 write_dword
: titan_write_config_dword
203 titan_pci_tbi(struct pci_controler
*hose
, dma_addr_t start
, dma_addr_t end
)
205 titan_pachip
*pachip
=
206 (hose
->index
& 1) ? TITAN_pachip1
: TITAN_pachip0
;
207 titan_pachip_port
*port
;
208 volatile unsigned long *csr
;
211 /* Get the right hose */
212 port
= &pachip
->g_port
;
214 port
= &pachip
->a_port
;
216 /* We can invalidate up to 8 tlb entries in a go. The flush
217 matches against <31:16> in the pci address. */
218 csr
= &port
->port_specific
.g
.gtlbia
.csr
;
219 if (((start
^ end
) & 0xffff0000) == 0)
220 csr
= &port
->port_specific
.g
.gtlbiv
.csr
;
222 /* For TBIA, it doesn't matter what value we write. For TBI,
223 it's the shifted tag bits. */
224 value
= (start
& 0xffff0000) >> 12;
232 #define FN __FUNCTION__
235 titan_query_agp(titan_pachip_port
*port
)
237 union TPAchipPCTL pctl
;
240 pctl
.pctl_q_whole
= port
->pctl
.csr
;
242 return pctl
.pctl_r_bits
.apctl_v_agp_present
;
246 titan_init_agp(titan_pachip_port
*port
, struct pci_controler
*hose
)
248 union TPAchipPCTL pctl
;
250 if (!titan_query_agp(port
))
253 printk("AGP present on hose %d\n", hose
->index
);
256 pctl
.pctl_q_whole
= port
->pctl
.csr
;
259 pctl
.pctl_r_bits
.apctl_v_agp_en
= 1; /* enable AGP */
260 pctl
.pctl_r_bits
.apctl_v_agp_lp_rd
= 0;
261 pctl
.pctl_r_bits
.apctl_v_agp_hp_rd
= 0;
263 port
->pctl
.csr
= pctl
.pctl_q_whole
;
265 TITAN_agp
|= 1 << hose
->index
;
267 #ifdef CONFIG_VGA_HOSE
268 /* is a graphics card on the AGP? (always device 5) */
270 __kernel_ldwu(*(vusp
)(hose
->config_space_base
+ 0x280a)) ==
271 PCI_CLASS_DISPLAY_VGA
)
277 titan_init_one_pachip_port(titan_pachip_port
*port
, int index
)
279 struct pci_controler
*hose
;
281 hose
= alloc_pci_controler();
284 hose
->io_space
= alloc_resource();
285 hose
->mem_space
= alloc_resource();
287 /* This is for userland consumption. For some reason, the 40-bit
288 PIO bias that we use in the kernel through KSEG didn't work for
289 the page table based user mappings. So make sure we get the
291 hose
->sparse_mem_base
= 0;
292 hose
->sparse_io_base
= 0;
294 = (TITAN_MEM(index
) & 0xffffffffff) | 0x80000000000;
296 = (TITAN_IO(index
) & 0xffffffffff) | 0x80000000000;
298 hose
->config_space_base
= TITAN_CONF(index
);
301 hose
->io_space
->start
= TITAN_IO(index
) - TITAN_IO_BIAS
;
302 hose
->io_space
->end
= hose
->io_space
->start
+ TITAN_IO_SPACE
- 1;
303 hose
->io_space
->name
= pci_io_names
[index
];
304 hose
->io_space
->flags
= IORESOURCE_IO
;
306 hose
->mem_space
->start
= TITAN_MEM(index
) - TITAN_MEM_BIAS
;
307 hose
->mem_space
->end
= hose
->mem_space
->start
+ 0xffffffff;
308 hose
->mem_space
->name
= pci_mem_names
[index
];
309 hose
->mem_space
->flags
= IORESOURCE_MEM
;
311 if (request_resource(&ioport_resource
, hose
->io_space
) < 0)
312 printk(KERN_ERR
"Failed to request IO on hose %d\n", index
);
313 if (request_resource(&iomem_resource
, hose
->mem_space
) < 0)
314 printk(KERN_ERR
"Failed to request MEM on hose %d\n", index
);
316 /* It's safe to call this for both G-Ports and A-Ports */
317 titan_init_agp(port
, hose
);
320 * Save the existing PCI window translations. SRM will
321 * need them when we go to reboot.
323 saved_pachip_port
[index
].wsba
[0] = port
->wsba
[0].csr
;
324 saved_pachip_port
[index
].wsm
[0] = port
->wsm
[0].csr
;
325 saved_pachip_port
[index
].tba
[0] = port
->tba
[0].csr
;
327 saved_pachip_port
[index
].wsba
[1] = port
->wsba
[1].csr
;
328 saved_pachip_port
[index
].wsm
[1] = port
->wsm
[1].csr
;
329 saved_pachip_port
[index
].tba
[1] = port
->tba
[1].csr
;
331 saved_pachip_port
[index
].wsba
[2] = port
->wsba
[2].csr
;
332 saved_pachip_port
[index
].wsm
[2] = port
->wsm
[2].csr
;
333 saved_pachip_port
[index
].tba
[2] = port
->tba
[2].csr
;
335 saved_pachip_port
[index
].wsba
[3] = port
->wsba
[3].csr
;
336 saved_pachip_port
[index
].wsm
[3] = port
->wsm
[3].csr
;
337 saved_pachip_port
[index
].tba
[3] = port
->tba
[3].csr
;
340 * Set up the PCI to main memory translation windows.
342 * Note: Window 3 on Titan is Scatter-Gather ONLY
344 * Window 0 is scatter-gather 8MB at 8MB (for isa)
345 * Window 1 is direct access 1GB at 1GB
346 * Window 2 is direct access 1GB at 2GB
347 * Window 3 is scatter-gather 128MB at 3GB
348 * ??? We ought to scale window 3 memory.
350 * We must actually use 2 windows to direct-map the 2GB space,
351 * because of an idiot-syncrasy of the CYPRESS chip. It may
352 * respond to a PCI bus address in the last 1MB of the 4GB
355 hose
->sg_isa
= iommu_arena_new(hose
, 0x00800000, 0x00800000, 0);
356 hose
->sg_isa
->align_entry
= 8; /* 64KB for ISA */
358 hose
->sg_pci
= iommu_arena_new(hose
, 0xc0000000, 0x08000000, 0);
359 hose
->sg_pci
->align_entry
= 4; /* Titan caches 4 PTEs at a time */
361 __direct_map_base
= 0x40000000;
362 __direct_map_size
= 0x80000000;
364 port
->wsba
[0].csr
= hose
->sg_isa
->dma_base
| 3;
365 port
->wsm
[0].csr
= (hose
->sg_isa
->size
- 1) & 0xfff00000;
366 port
->tba
[0].csr
= virt_to_phys(hose
->sg_isa
->ptes
);
368 port
->wsba
[1].csr
= 0x40000000 | 1;
369 port
->wsm
[1].csr
= (0x40000000 - 1) & 0xfff00000;
370 port
->tba
[1].csr
= 0;
372 port
->wsba
[2].csr
= 0x80000000 | 1;
373 port
->wsm
[2].csr
= (0x40000000 - 1) & 0xfff00000;
374 port
->tba
[2].csr
= 0x40000000;
376 port
->wsba
[3].csr
= hose
->sg_pci
->dma_base
| 3;
377 port
->wsm
[3].csr
= (hose
->sg_pci
->size
- 1) & 0xfff00000;
378 port
->tba
[3].csr
= virt_to_phys(hose
->sg_pci
->ptes
);
380 titan_pci_tbi(hose
, 0, -1);
384 titan_init_pachips(titan_pachip
*pachip0
, titan_pachip
*pachip1
)
386 int pchip1_present
= TITAN_cchip
->csc
.csr
& 1L<<14;
388 /* Init the ports in hose order... */
389 titan_init_one_pachip_port(&pachip0
->g_port
, 0); /* hose 0 */
391 titan_init_one_pachip_port(&pachip1
->g_port
, 1);/* hose 1 */
392 titan_init_one_pachip_port(&pachip0
->a_port
, 2); /* hose 2 */
394 titan_init_one_pachip_port(&pachip1
->a_port
, 3);/* hose 3 */
398 titan_init_arch(void)
401 printk("%s: titan_init_arch()\n", FN
);
402 printk("%s: CChip registers:\n", FN
);
403 printk("%s: CSR_CSC 0x%lx\n", FN
, TITAN_cchip
->csc
.csr
);
404 printk("%s: CSR_MTR 0x%lx\n", FN
, TITAN_cchip
->mtr
.csr
);
405 printk("%s: CSR_MISC 0x%lx\n", FN
, TITAN_cchip
->misc
.csr
);
406 printk("%s: CSR_DIM0 0x%lx\n", FN
, TITAN_cchip
->dim0
.csr
);
407 printk("%s: CSR_DIM1 0x%lx\n", FN
, TITAN_cchip
->dim1
.csr
);
408 printk("%s: CSR_DIR0 0x%lx\n", FN
, TITAN_cchip
->dir0
.csr
);
409 printk("%s: CSR_DIR1 0x%lx\n", FN
, TITAN_cchip
->dir1
.csr
);
410 printk("%s: CSR_DRIR 0x%lx\n", FN
, TITAN_cchip
->drir
.csr
);
412 printk("%s: DChip registers:\n", FN
);
413 printk("%s: CSR_DSC 0x%lx\n", FN
, TITAN_dchip
->dsc
.csr
);
414 printk("%s: CSR_STR 0x%lx\n", FN
, TITAN_dchip
->str
.csr
);
415 printk("%s: CSR_DREV 0x%lx\n", FN
, TITAN_dchip
->drev
.csr
);
418 boot_cpuid
= __hard_smp_processor_id();
420 /* With multiple PCI busses, we play with I/O as physical addrs. */
421 ioport_resource
.end
= ~0UL;
422 iomem_resource
.end
= ~0UL;
424 /* Init the PA chip(s) */
425 titan_init_pachips(TITAN_pachip0
, TITAN_pachip1
);
429 titan_kill_one_pachip_port(titan_pachip_port
*port
, int index
)
431 port
->wsba
[0].csr
= saved_pachip_port
[index
].wsba
[0];
432 port
->wsm
[0].csr
= saved_pachip_port
[index
].wsm
[0];
433 port
->tba
[0].csr
= saved_pachip_port
[index
].tba
[0];
435 port
->wsba
[1].csr
= saved_pachip_port
[index
].wsba
[1];
436 port
->wsm
[1].csr
= saved_pachip_port
[index
].wsm
[1];
437 port
->tba
[1].csr
= saved_pachip_port
[index
].tba
[1];
439 port
->wsba
[2].csr
= saved_pachip_port
[index
].wsba
[2];
440 port
->wsm
[2].csr
= saved_pachip_port
[index
].wsm
[2];
441 port
->tba
[2].csr
= saved_pachip_port
[index
].tba
[2];
443 port
->wsba
[3].csr
= saved_pachip_port
[index
].wsba
[3];
444 port
->wsm
[3].csr
= saved_pachip_port
[index
].wsm
[3];
445 port
->tba
[3].csr
= saved_pachip_port
[index
].tba
[3];
449 titan_kill_pachips(titan_pachip
*pachip0
, titan_pachip
*pachip1
)
451 int pchip1_present
= TITAN_cchip
->csc
.csr
& 1L<<14;
453 if (pchip1_present
) {
454 titan_kill_one_pachip_port(&pachip0
->g_port
, 1);
455 titan_kill_one_pachip_port(&pachip0
->a_port
, 3);
457 titan_kill_one_pachip_port(&pachip0
->g_port
, 0);
458 titan_kill_one_pachip_port(&pachip0
->a_port
, 2);
462 titan_kill_arch(int mode
)
464 titan_kill_pachips(TITAN_pachip0
, TITAN_pachip1
);
468 titan_pci_clr_err_1(titan_pachip
*pachip
)
472 jd
= pachip
->g_port
.port_specific
.g
.gperror
.csr
;
473 pachip
->g_port
.port_specific
.g
.gperror
.csr
= jd
;
475 pachip
->g_port
.port_specific
.g
.gperror
.csr
;
479 titan_pci_clr_err(void)
481 titan_pci_clr_err_1(TITAN_pachip0
);
483 if (TITAN_cchip
->csc
.csr
& 1L<<14)
484 titan_pci_clr_err_1(TITAN_pachip1
);
488 titan_machine_check(unsigned long vector
, unsigned long la_ptr
,
489 struct pt_regs
* regs
)
491 /* clear error before any reporting. */
498 process_mcheck_info(vector
, la_ptr
, regs
, "TITAN",
499 mcheck_expected(smp_processor_id()));