Home | History | Annotate | Line # | Download | only in pci
cia_pci.c revision 1.11
      1 /* $NetBSD: cia_pci.c,v 1.11 1997/04/07 23:40:31 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 <machine/options.h>		/* Config options headers */
     31 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     32 
     33 __KERNEL_RCSID(0, "$NetBSD: cia_pci.c,v 1.11 1997/04/07 23:40:31 cgd Exp $");
     34 
     35 #include <sys/param.h>
     36 #include <sys/systm.h>
     37 #include <sys/kernel.h>
     38 #include <sys/device.h>
     39 #include <vm/vm.h>
     40 
     41 #include <dev/pci/pcireg.h>
     42 #include <dev/pci/pcivar.h>
     43 #include <alpha/pci/ciareg.h>
     44 #include <alpha/pci/ciavar.h>
     45 
     46 #include <machine/rpb.h>	/* XXX for eb164 CIA firmware workarounds. */
     47 
     48 void		cia_attach_hook __P((struct device *, struct device *,
     49 		    struct pcibus_attach_args *));
     50 int		cia_bus_maxdevs __P((void *, int));
     51 pcitag_t	cia_make_tag __P((void *, int, int, int));
     52 void		cia_decompose_tag __P((void *, pcitag_t, int *, int *,
     53 		    int *));
     54 pcireg_t	cia_conf_read __P((void *, pcitag_t, int));
     55 void		cia_conf_write __P((void *, pcitag_t, int, pcireg_t));
     56 
     57 void
     58 cia_pci_init(pc, v)
     59 	pci_chipset_tag_t pc;
     60 	void *v;
     61 {
     62 
     63 	pc->pc_conf_v = v;
     64 	pc->pc_attach_hook = cia_attach_hook;
     65 	pc->pc_bus_maxdevs = cia_bus_maxdevs;
     66 	pc->pc_make_tag = cia_make_tag;
     67 	pc->pc_decompose_tag = cia_decompose_tag;
     68 	pc->pc_conf_read = cia_conf_read;
     69 	pc->pc_conf_write = cia_conf_write;
     70 }
     71 
     72 void
     73 cia_attach_hook(parent, self, pba)
     74 	struct device *parent, *self;
     75 	struct pcibus_attach_args *pba;
     76 {
     77 }
     78 
     79 int
     80 cia_bus_maxdevs(cpv, busno)
     81 	void *cpv;
     82 	int busno;
     83 {
     84 
     85 	return 32;
     86 }
     87 
     88 pcitag_t
     89 cia_make_tag(cpv, b, d, f)
     90 	void *cpv;
     91 	int b, d, f;
     92 {
     93 
     94 	return (b << 16) | (d << 11) | (f << 8);
     95 }
     96 
     97 void
     98 cia_decompose_tag(cpv, tag, bp, dp, fp)
     99 	void *cpv;
    100 	pcitag_t tag;
    101 	int *bp, *dp, *fp;
    102 {
    103 
    104 	if (bp != NULL)
    105 		*bp = (tag >> 16) & 0xff;
    106 	if (dp != NULL)
    107 		*dp = (tag >> 11) & 0x1f;
    108 	if (fp != NULL)
    109 		*fp = (tag >> 8) & 0x7;
    110 }
    111 
    112 pcireg_t
    113 cia_conf_read(cpv, tag, offset)
    114 	void *cpv;
    115 	pcitag_t tag;
    116 	int offset;
    117 {
    118 	struct cia_config *ccp = cpv;
    119 	pcireg_t *datap, data;
    120 	int s, secondary, ba;
    121 	int32_t old_haxr2;					/* XXX */
    122 #ifdef DEC_EB164
    123 	extern int cputype;					/* XXX */
    124 #endif
    125 
    126 #ifdef DIAGNOSTIC
    127 	s = 0;					/* XXX gcc -Wuninitialized */
    128 	old_haxr2 = 0;				/* XXX gcc -Wuninitialized */
    129 #endif
    130 
    131 #ifdef DEC_EB164
    132 	/*
    133 	 * Some (apparently-common) revisions of EB164 firmware do the
    134 	 * Wrong thing with PCI master aborts, which are caused by
    135 	 * accesing the configuration space of devices that don't
    136 	 * exist (for example).
    137 	 *
    138 	 * On EB164's we clear the CIA error register's PCI master
    139 	 * abort bit before touching PCI configuration space and
    140 	 * check it afterwards.  If it indicates a master abort,
    141 	 * the device wasn't there so we return 0xffffffff.
    142 	 */
    143 	if (cputype == ST_EB164) {
    144 		/* clear the PCI master abort bit in CIA error register */
    145 		REGVAL(CIA_CSR_CIA_ERR) = 0x00000080;		/* XXX */
    146 		alpha_mb();
    147 		alpha_pal_draina();
    148 	}
    149 #endif
    150 
    151 	/* secondary if bus # != 0 */
    152 	pci_decompose_tag(&ccp->cc_pc, tag, &secondary, 0, 0);
    153 	if (secondary) {
    154 		s = splhigh();
    155 		old_haxr2 = REGVAL(CIA_CSRS + 0x480);		/* XXX */
    156 		alpha_mb();
    157 		REGVAL(CIA_CSRS + 0x480) = old_haxr2 | 0x1;	/* XXX */
    158 		alpha_mb();
    159 	}
    160 
    161 	datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(CIA_PCI_CONF |
    162 	    tag << 5UL |					/* XXX */
    163 	    (offset & ~0x03) << 5 |				/* XXX */
    164 	    0 << 5 |						/* XXX */
    165 	    0x3 << 3);						/* XXX */
    166 	data = (pcireg_t)-1;
    167 	if (!(ba = badaddr(datap, sizeof *datap)))
    168 		data = *datap;
    169 
    170 	if (secondary) {
    171 		alpha_mb();
    172 		REGVAL(CIA_CSRS + 0x480) = old_haxr2;		/* XXX */
    173 		alpha_mb();
    174 		splx(s);
    175 	}
    176 
    177 #ifdef DEC_EB164
    178 	if (cputype == ST_EB164) {
    179 		alpha_pal_draina();
    180 		/* check CIA error register for PCI master abort */
    181 		if (REGVAL(CIA_CSR_CIA_ERR) & 0x00000080) {	/* XXX */
    182 			ba = 1;
    183 			data = 0xffffffff;
    184 		}
    185 	}
    186 #endif
    187 
    188 #if 0
    189 	printf("cia_conf_read: tag 0x%lx, reg 0x%lx -> %x @ %p%s\n", tag, reg,
    190 	    data, datap, ba ? " (badaddr)" : "");
    191 #endif
    192 
    193 	return data;
    194 }
    195 
    196 void
    197 cia_conf_write(cpv, tag, offset, data)
    198 	void *cpv;
    199 	pcitag_t tag;
    200 	int offset;
    201 	pcireg_t data;
    202 {
    203 	struct cia_config *ccp = cpv;
    204 	pcireg_t *datap;
    205 	int s, secondary;
    206 	int32_t old_haxr2;					/* XXX */
    207 
    208 #ifdef DIAGNOSTIC
    209 	s = 0;					/* XXX gcc -Wuninitialized */
    210 	old_haxr2 = 0;				/* XXX gcc -Wuninitialized */
    211 #endif
    212 
    213 	/* secondary if bus # != 0 */
    214 	pci_decompose_tag(&ccp->cc_pc, tag, &secondary, 0, 0);
    215 	if (secondary) {
    216 		s = splhigh();
    217 		old_haxr2 = REGVAL(CIA_CSRS + 0x480);		/* XXX */
    218 		alpha_mb();
    219 		REGVAL(CIA_CSRS + 0x480) = old_haxr2 | 0x1;	/* XXX */
    220 		alpha_mb();
    221 	}
    222 
    223 	datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(CIA_PCI_CONF |
    224 	    tag << 5UL |					/* XXX */
    225 	    (offset & ~0x03) << 5 |				/* XXX */
    226 	    0 << 5 |						/* XXX */
    227 	    0x3 << 3);						/* XXX */
    228 	*datap = data;
    229 
    230 	if (secondary) {
    231 		alpha_mb();
    232 		REGVAL(CIA_CSRS + 0x480) = old_haxr2;		/* XXX */
    233 		alpha_mb();
    234 		splx(s);
    235 	}
    236 
    237 #if 0
    238 	printf("cia_conf_write: tag 0x%lx, reg 0x%lx -> 0x%x @ %p\n", tag,
    239 	    reg, data, datap);
    240 #endif
    241 }
    242