Home | History | Annotate | Line # | Download | only in pci
cia_pci.c revision 1.7
      1 /*	$NetBSD: cia_pci.c,v 1.7 1996/11/23 06:46:50 cgd Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
      5  * All rights reserved.
      6  *
      7  * Author: Chris G. Demetriou
      8  *
      9  * Permission to use, copy, modify and distribute this software and
     10  * its documentation is hereby granted, provided that both the copyright
     11  * notice and this permission notice appear in all copies of the
     12  * software, derivative works or modified versions, and any portions
     13  * thereof, and that both notices appear in supporting documentation.
     14  *
     15  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18  *
     19  * Carnegie Mellon requests users of this software to return to
     20  *
     21  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22  *  School of Computer Science
     23  *  Carnegie Mellon University
     24  *  Pittsburgh PA 15213-3890
     25  *
     26  * any improvements or extensions that they make and grant Carnegie the
     27  * rights to redistribute these changes.
     28  */
     29 
     30 #include <sys/param.h>
     31 #include <sys/systm.h>
     32 #include <sys/kernel.h>
     33 #include <sys/device.h>
     34 #include <vm/vm.h>
     35 
     36 #include <dev/pci/pcireg.h>
     37 #include <dev/pci/pcivar.h>
     38 #include <alpha/pci/ciareg.h>
     39 #include <alpha/pci/ciavar.h>
     40 
     41 #include <machine/rpb.h>	/* XXX for eb164 CIA firmware workarounds. */
     42 #include "dec_eb164.h"		/* XXX for eb164 CIA firmware workarounds. */
     43 
     44 void		cia_attach_hook __P((struct device *, struct device *,
     45 		    struct pcibus_attach_args *));
     46 int		cia_bus_maxdevs __P((void *, int));
     47 pcitag_t	cia_make_tag __P((void *, int, int, int));
     48 void		cia_decompose_tag __P((void *, pcitag_t, int *, int *,
     49 		    int *));
     50 pcireg_t	cia_conf_read __P((void *, pcitag_t, int));
     51 void		cia_conf_write __P((void *, pcitag_t, int, pcireg_t));
     52 
     53 void
     54 cia_pci_init(pc, v)
     55 	pci_chipset_tag_t pc;
     56 	void *v;
     57 {
     58 
     59 	pc->pc_conf_v = v;
     60 	pc->pc_attach_hook = cia_attach_hook;
     61 	pc->pc_bus_maxdevs = cia_bus_maxdevs;
     62 	pc->pc_make_tag = cia_make_tag;
     63 	pc->pc_decompose_tag = cia_decompose_tag;
     64 	pc->pc_conf_read = cia_conf_read;
     65 	pc->pc_conf_write = cia_conf_write;
     66 }
     67 
     68 void
     69 cia_attach_hook(parent, self, pba)
     70 	struct device *parent, *self;
     71 	struct pcibus_attach_args *pba;
     72 {
     73 }
     74 
     75 int
     76 cia_bus_maxdevs(cpv, busno)
     77 	void *cpv;
     78 	int busno;
     79 {
     80 
     81 	return 32;
     82 }
     83 
     84 pcitag_t
     85 cia_make_tag(cpv, b, d, f)
     86 	void *cpv;
     87 	int b, d, f;
     88 {
     89 
     90 	return (b << 16) | (d << 11) | (f << 8);
     91 }
     92 
     93 void
     94 cia_decompose_tag(cpv, tag, bp, dp, fp)
     95 	void *cpv;
     96 	pcitag_t tag;
     97 	int *bp, *dp, *fp;
     98 {
     99 
    100 	if (bp != NULL)
    101 		*bp = (tag >> 16) & 0xff;
    102 	if (dp != NULL)
    103 		*dp = (tag >> 11) & 0x1f;
    104 	if (fp != NULL)
    105 		*fp = (tag >> 8) & 0x7;
    106 }
    107 
    108 pcireg_t
    109 cia_conf_read(cpv, tag, offset)
    110 	void *cpv;
    111 	pcitag_t tag;
    112 	int offset;
    113 {
    114 	struct cia_config *ccp = cpv;
    115 	pcireg_t *datap, data;
    116 	int s, secondary, ba;
    117 	int32_t old_haxr2;					/* XXX */
    118 #if NDEC_EB164
    119 	extern int cputype;					/* XXX */
    120 #endif
    121 
    122 #ifdef DIAGNOSTIC
    123 	s = 0;					/* XXX gcc -Wuninitialized */
    124 	old_haxr2 = 0;				/* XXX gcc -Wuninitialized */
    125 #endif
    126 
    127 #if NDEC_EB164
    128 	/*
    129 	 * Some (apparently-common) revisions of EB164 firmware do the
    130 	 * Wrong thing with PCI master aborts, which are caused by
    131 	 * accesing the configuration space of devices that don't
    132 	 * exist (for example).
    133 	 *
    134 	 * On EB164's we clear the CIA error register's PCI master
    135 	 * abort bit before touching PCI configuration space and
    136 	 * check it afterwards.  If it indicates a master abort,
    137 	 * the device wasn't there so we return 0xffffffff.
    138 	 */
    139 	if (cputype == ST_EB164) {
    140 		/* clear the PCI master abort bit in CIA error register */
    141 		REGVAL(CIA_CSR_CIA_ERR) = 0x00000080;		/* XXX */
    142 		alpha_mb();
    143 		alpha_pal_draina();
    144 	}
    145 #endif
    146 
    147 	/* secondary if bus # != 0 */
    148 	pci_decompose_tag(&ccp->cc_pc, tag, &secondary, 0, 0);
    149 	if (secondary) {
    150 		s = splhigh();
    151 		old_haxr2 = REGVAL(CIA_CSRS + 0x480);		/* XXX */
    152 		alpha_mb();
    153 		REGVAL(CIA_CSRS + 0x480) = old_haxr2 | 0x1;	/* XXX */
    154 		alpha_mb();
    155 	}
    156 
    157 	datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(CIA_PCI_CONF |
    158 	    tag << 5UL |					/* XXX */
    159 	    (offset & ~0x03) << 5 |				/* XXX */
    160 	    0 << 5 |						/* XXX */
    161 	    0x3 << 3);						/* XXX */
    162 	data = (pcireg_t)-1;
    163 	if (!(ba = badaddr(datap, sizeof *datap)))
    164 		data = *datap;
    165 
    166 	if (secondary) {
    167 		alpha_mb();
    168 		REGVAL(CIA_CSRS + 0x480) = old_haxr2;		/* XXX */
    169 		alpha_mb();
    170 		splx(s);
    171 	}
    172 
    173 #if NDEC_EB164
    174 	if (cputype == ST_EB164) {
    175 		alpha_pal_draina();
    176 		/* check CIA error register for PCI master abort */
    177 		if (REGVAL(CIA_CSR_CIA_ERR) & 0x00000080) {	/* XXX */
    178 			ba = 1;
    179 			data = 0xffffffff;
    180 		}
    181 	}
    182 #endif
    183 
    184 #if 0
    185 	printf("cia_conf_read: tag 0x%lx, reg 0x%lx -> %x @ %p%s\n", tag, reg,
    186 	    data, datap, ba ? " (badaddr)" : "");
    187 #endif
    188 
    189 	return data;
    190 }
    191 
    192 void
    193 cia_conf_write(cpv, tag, offset, data)
    194 	void *cpv;
    195 	pcitag_t tag;
    196 	int offset;
    197 	pcireg_t data;
    198 {
    199 	struct cia_config *ccp = cpv;
    200 	pcireg_t *datap;
    201 	int s, secondary;
    202 	int32_t old_haxr2;					/* XXX */
    203 
    204 #ifdef DIAGNOSTIC
    205 	s = 0;					/* XXX gcc -Wuninitialized */
    206 	old_haxr2 = 0;				/* XXX gcc -Wuninitialized */
    207 #endif
    208 
    209 	/* secondary if bus # != 0 */
    210 	pci_decompose_tag(&ccp->cc_pc, tag, &secondary, 0, 0);
    211 	if (secondary) {
    212 		s = splhigh();
    213 		old_haxr2 = REGVAL(CIA_CSRS + 0x480);		/* XXX */
    214 		alpha_mb();
    215 		REGVAL(CIA_CSRS + 0x480) = old_haxr2 | 0x1;	/* XXX */
    216 		alpha_mb();
    217 	}
    218 
    219 	datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(CIA_PCI_CONF |
    220 	    tag << 5UL |					/* XXX */
    221 	    (offset & ~0x03) << 5 |				/* XXX */
    222 	    0 << 5 |						/* XXX */
    223 	    0x3 << 3);						/* XXX */
    224 	*datap = data;
    225 
    226 	if (secondary) {
    227 		alpha_mb();
    228 		REGVAL(CIA_CSRS + 0x480) = old_haxr2;		/* XXX */
    229 		alpha_mb();
    230 		splx(s);
    231 	}
    232 
    233 #if 0
    234 	printf("cia_conf_write: tag 0x%lx, reg 0x%lx -> 0x%x @ %p\n", tag,
    235 	    reg, data, datap);
    236 #endif
    237 }
    238