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