Home | History | Annotate | Line # | Download | only in pci
apecs_pci.c revision 1.12
      1 /* $NetBSD: apecs_pci.c,v 1.12 1997/04/07 05:46:48 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>		/* Pull in config options headers */
     31 
     32 #include <sys/param.h>
     33 #include <sys/systm.h>
     34 #include <sys/kernel.h>
     35 #include <sys/device.h>
     36 #include <vm/vm.h>
     37 
     38 #include <dev/pci/pcireg.h>
     39 #include <dev/pci/pcivar.h>
     40 #include <alpha/pci/apecsreg.h>
     41 #include <alpha/pci/apecsvar.h>
     42 
     43 void		apecs_attach_hook __P((struct device *, struct device *,
     44 		    struct pcibus_attach_args *));
     45 int		apecs_bus_maxdevs __P((void *, int));
     46 pcitag_t	apecs_make_tag __P((void *, int, int, int));
     47 void		apecs_decompose_tag __P((void *, pcitag_t, int *, int *,
     48 		    int *));
     49 pcireg_t	apecs_conf_read __P((void *, pcitag_t, int));
     50 void		apecs_conf_write __P((void *, pcitag_t, int, pcireg_t));
     51 
     52 void
     53 apecs_pci_init(pc, v)
     54 	pci_chipset_tag_t pc;
     55 	void *v;
     56 {
     57 
     58 	pc->pc_conf_v = v;
     59 	pc->pc_attach_hook = apecs_attach_hook;
     60 	pc->pc_bus_maxdevs = apecs_bus_maxdevs;
     61 	pc->pc_make_tag = apecs_make_tag;
     62 	pc->pc_decompose_tag = apecs_decompose_tag;
     63 	pc->pc_conf_read = apecs_conf_read;
     64 	pc->pc_conf_write = apecs_conf_write;
     65 }
     66 
     67 void
     68 apecs_attach_hook(parent, self, pba)
     69 	struct device *parent, *self;
     70 	struct pcibus_attach_args *pba;
     71 {
     72 }
     73 
     74 int
     75 apecs_bus_maxdevs(cpv, busno)
     76 	void *cpv;
     77 	int busno;
     78 {
     79 
     80 	return 32;
     81 }
     82 
     83 pcitag_t
     84 apecs_make_tag(cpv, b, d, f)
     85 	void *cpv;
     86 	int b, d, f;
     87 {
     88 
     89 	return (b << 16) | (d << 11) | (f << 8);
     90 }
     91 
     92 void
     93 apecs_decompose_tag(cpv, tag, bp, dp, fp)
     94 	void *cpv;
     95 	pcitag_t tag;
     96 	int *bp, *dp, *fp;
     97 {
     98 
     99 	if (bp != NULL)
    100 		*bp = (tag >> 16) & 0xff;
    101 	if (dp != NULL)
    102 		*dp = (tag >> 11) & 0x1f;
    103 	if (fp != NULL)
    104 		*fp = (tag >> 8) & 0x7;
    105 }
    106 
    107 pcireg_t
    108 apecs_conf_read(cpv, tag, offset)
    109 	void *cpv;
    110 	pcitag_t tag;
    111 	int offset;
    112 {
    113 	struct apecs_config *acp = cpv;
    114 	pcireg_t *datap, data;
    115 	int s, secondary, ba;
    116 	int32_t old_haxr2;					/* XXX */
    117 
    118 #ifdef DIAGNOSTIC
    119 	s = 0;					/* XXX gcc -Wuninitialized */
    120 	old_haxr2 = 0;				/* XXX gcc -Wuninitialized */
    121 #endif
    122 
    123 	/* secondary if bus # != 0 */
    124 	pci_decompose_tag(&acp->ac_pc, tag, &secondary, 0, 0);
    125 	if (secondary) {
    126 		s = splhigh();
    127 		old_haxr2 = REGVAL(EPIC_HAXR2);
    128 		alpha_mb();
    129 		REGVAL(EPIC_HAXR2) = old_haxr2 | 0x1;
    130 		alpha_mb();
    131 	}
    132 
    133 	datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(APECS_PCI_CONF |
    134 	    tag << 5UL |					/* XXX */
    135 	    (offset & ~0x03) << 5 |				/* XXX */
    136 	    0 << 5 |						/* XXX */
    137 	    0x3 << 3);						/* XXX */
    138 	data = (pcireg_t)-1;
    139 	if (!(ba = badaddr(datap, sizeof *datap)))
    140 		data = *datap;
    141 
    142 	if (secondary) {
    143 		alpha_mb();
    144 		REGVAL(EPIC_HAXR2) = old_haxr2;
    145 		alpha_mb();
    146 		splx(s);
    147 	}
    148 
    149 #if 0
    150 	printf("apecs_conf_read: tag 0x%lx, reg 0x%lx -> %x @ %p%s\n", tag, reg,
    151 	    data, datap, ba ? " (badaddr)" : "");
    152 #endif
    153 
    154 	return data;
    155 }
    156 
    157 void
    158 apecs_conf_write(cpv, tag, offset, data)
    159 	void *cpv;
    160 	pcitag_t tag;
    161 	int offset;
    162 	pcireg_t data;
    163 {
    164 	struct apecs_config *acp = cpv;
    165 	pcireg_t *datap;
    166 	int s, secondary;
    167 	int32_t old_haxr2;					/* XXX */
    168 
    169 #ifdef DIAGNOSTIC
    170 	s = 0;					/* XXX gcc -Wuninitialized */
    171 	old_haxr2 = 0;				/* XXX gcc -Wuninitialized */
    172 #endif
    173 
    174 	/* secondary if bus # != 0 */
    175 	pci_decompose_tag(&acp->ac_pc, tag, &secondary, 0, 0);
    176 	if (secondary) {
    177 		s = splhigh();
    178 		old_haxr2 = REGVAL(EPIC_HAXR2);
    179 		alpha_mb();
    180 		REGVAL(EPIC_HAXR2) = old_haxr2 | 0x1;
    181 		alpha_mb();
    182 	}
    183 
    184 	datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(APECS_PCI_CONF |
    185 	    tag << 5UL |					/* XXX */
    186 	    (offset & ~0x03) << 5 |				/* XXX */
    187 	    0 << 5 |						/* XXX */
    188 	    0x3 << 3);						/* XXX */
    189 	*datap = data;
    190 
    191 	if (secondary) {
    192 		alpha_mb();
    193 		REGVAL(EPIC_HAXR2) = old_haxr2;
    194 		alpha_mb();
    195 		splx(s);
    196 	}
    197 
    198 #if 0
    199 	printf("apecs_conf_write: tag 0x%lx, reg 0x%lx -> 0x%x @ %p\n", tag,
    200 	    reg, data, datap);
    201 #endif
    202 }
    203