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