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