Home | History | Annotate | Line # | Download | only in pci
dwlpx_pci.c revision 1.1
      1  1.1  cgd /*	$NetBSD: dwlpx_pci.c,v 1.1 1997/03/12 19:20:02 cgd Exp $	*/
      2  1.1  cgd 
      3  1.1  cgd /*
      4  1.1  cgd  * Copyright (c) 1997
      5  1.1  cgd  * Matthew Jacob
      6  1.1  cgd  * NASA AMES Research Center.
      7  1.1  cgd  * All rights reserved.
      8  1.1  cgd  *
      9  1.1  cgd  * Redistribution and use in source and binary forms, with or without
     10  1.1  cgd  * modification, are permitted provided that the following conditions
     11  1.1  cgd  * are met:
     12  1.1  cgd  * 1. Redistributions of source code must retain the above copyright
     13  1.1  cgd  *    notice immediately at the beginning of the file, without modification,
     14  1.1  cgd  *    this list of conditions, and the following disclaimer.
     15  1.1  cgd  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  cgd  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  cgd  *    documentation and/or other materials provided with the distribution.
     18  1.1  cgd  * 3. The name of the author may not be used to endorse or promote products
     19  1.1  cgd  *    derived from this software without specific prior written permission.
     20  1.1  cgd  *
     21  1.1  cgd  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     22  1.1  cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  1.1  cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  1.1  cgd  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
     25  1.1  cgd  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  1.1  cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  1.1  cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  1.1  cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  1.1  cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  1.1  cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  1.1  cgd  * SUCH DAMAGE.
     32  1.1  cgd  */
     33  1.1  cgd 
     34  1.1  cgd #include <sys/param.h>
     35  1.1  cgd #include <sys/systm.h>
     36  1.1  cgd #include <sys/kernel.h>
     37  1.1  cgd #include <sys/device.h>
     38  1.1  cgd #include <vm/vm.h>
     39  1.1  cgd 
     40  1.1  cgd #include <dev/pci/pcireg.h>
     41  1.1  cgd #include <dev/pci/pcivar.h>
     42  1.1  cgd #include <alpha/tlsb/tlsbreg.h>
     43  1.1  cgd #include <alpha/pci/dwlpxreg.h>
     44  1.1  cgd #include <alpha/pci/dwlpxvar.h>
     45  1.1  cgd 
     46  1.1  cgd /* #define	DO_SECONDARIES	1 */
     47  1.1  cgd 
     48  1.1  cgd #define	KV(_addr)	((caddr_t)ALPHA_PHYS_TO_K0SEG((_addr)))
     49  1.1  cgd 
     50  1.1  cgd void		dwlpx_attach_hook __P((struct device *, struct device *,
     51  1.1  cgd 		    struct pcibus_attach_args *));
     52  1.1  cgd int		dwlpx_bus_maxdevs __P((void *, int));
     53  1.1  cgd pcitag_t	dwlpx_make_tag __P((void *, int, int, int));
     54  1.1  cgd void		dwlpx_decompose_tag __P((void *, pcitag_t, int *, int *,
     55  1.1  cgd 		    int *));
     56  1.1  cgd pcireg_t	dwlpx_conf_read __P((void *, pcitag_t, int));
     57  1.1  cgd void		dwlpx_conf_write __P((void *, pcitag_t, int, pcireg_t));
     58  1.1  cgd 
     59  1.1  cgd void
     60  1.1  cgd dwlpx_pci_init(pc, v)
     61  1.1  cgd 	pci_chipset_tag_t pc;
     62  1.1  cgd 	void *v;
     63  1.1  cgd {
     64  1.1  cgd 	pc->pc_conf_v = v;
     65  1.1  cgd 	pc->pc_attach_hook = dwlpx_attach_hook;
     66  1.1  cgd 	pc->pc_bus_maxdevs = dwlpx_bus_maxdevs;
     67  1.1  cgd 	pc->pc_make_tag = dwlpx_make_tag;
     68  1.1  cgd 	pc->pc_decompose_tag = dwlpx_decompose_tag;
     69  1.1  cgd 	pc->pc_conf_read = dwlpx_conf_read;
     70  1.1  cgd 	pc->pc_conf_write = dwlpx_conf_write;
     71  1.1  cgd }
     72  1.1  cgd 
     73  1.1  cgd void
     74  1.1  cgd dwlpx_attach_hook(parent, self, pba)
     75  1.1  cgd 	struct device *parent, *self;
     76  1.1  cgd 	struct pcibus_attach_args *pba;
     77  1.1  cgd {
     78  1.1  cgd #if	0
     79  1.1  cgd 	struct dwlpx_config *ccp = pba->pba_pc->pc_conf_v;
     80  1.1  cgd 	printf("dwlpx_attach_hook for %s\n", ccp->cc_sc->dwlpx_dev.dv_xname);
     81  1.1  cgd #endif
     82  1.1  cgd }
     83  1.1  cgd 
     84  1.1  cgd int
     85  1.1  cgd dwlpx_bus_maxdevs(cpv, busno)
     86  1.1  cgd 	void *cpv;
     87  1.1  cgd 	int busno;
     88  1.1  cgd {
     89  1.1  cgd 	return DWLPX_MAXDEV;
     90  1.1  cgd }
     91  1.1  cgd 
     92  1.1  cgd pcitag_t
     93  1.1  cgd dwlpx_make_tag(cpv, b, d, f)
     94  1.1  cgd 	void *cpv;
     95  1.1  cgd 	int b, d, f;
     96  1.1  cgd {
     97  1.1  cgd 	pcitag_t tag;
     98  1.1  cgd 	int hpcdev, pci_idsel;
     99  1.1  cgd 
    100  1.1  cgd 	pci_idsel = (1 << ((d & 0x3) + 2));
    101  1.1  cgd 	hpcdev = d >> 2;
    102  1.1  cgd 	tag = (b << 24) | (hpcdev << 22) | (pci_idsel << 16) | (f << 13);
    103  1.1  cgd 	return (tag);
    104  1.1  cgd }
    105  1.1  cgd 
    106  1.1  cgd void
    107  1.1  cgd dwlpx_decompose_tag(cpv, tag, bp, dp, fp)
    108  1.1  cgd 	void *cpv;
    109  1.1  cgd 	pcitag_t tag;
    110  1.1  cgd 	int *bp, *dp, *fp;
    111  1.1  cgd {
    112  1.1  cgd 
    113  1.1  cgd 	if (bp != NULL)
    114  1.1  cgd 		*bp = (tag >> 24) & 0xff;
    115  1.1  cgd 	if (dp != NULL) {
    116  1.1  cgd 		int j, i = (tag >> 18) & 0xf;
    117  1.1  cgd 		j = -1;
    118  1.1  cgd 		while (i != 0) {
    119  1.1  cgd 			j++;
    120  1.1  cgd 			i >>= 1;
    121  1.1  cgd 		}
    122  1.1  cgd 		j += (((tag >> 22) & 3) << 2);
    123  1.1  cgd 		*dp = j;
    124  1.1  cgd 	}
    125  1.1  cgd 	if (fp != NULL)
    126  1.1  cgd 		*fp = (tag >> 13) & 0x7;
    127  1.1  cgd }
    128  1.1  cgd 
    129  1.1  cgd pcireg_t
    130  1.1  cgd dwlpx_conf_read(cpv, tag, offset)
    131  1.1  cgd 	void *cpv;
    132  1.1  cgd 	pcitag_t tag;
    133  1.1  cgd 	int offset;
    134  1.1  cgd {
    135  1.1  cgd 	struct dwlpx_config *ccp = cpv;
    136  1.1  cgd 	struct dwlpx_softc *sc;
    137  1.1  cgd 	pcireg_t *dp, data = (pcireg_t) -1;
    138  1.1  cgd 	unsigned long paddr;
    139  1.1  cgd 	int secondary, i, s = 0;
    140  1.1  cgd 	u_int32_t rvp;
    141  1.1  cgd 
    142  1.1  cgd 	if (ccp == NULL) {
    143  1.1  cgd 		panic("NULL ccp in dwlpx_conf_read\n");
    144  1.1  cgd 	}
    145  1.1  cgd 	sc = ccp->cc_sc;
    146  1.1  cgd 	secondary = tag >> 24;
    147  1.1  cgd 	if (secondary) {
    148  1.1  cgd #ifdef	DO_SECONDARIES
    149  1.1  cgd 		tag &= 0x1fffff;
    150  1.1  cgd 		tag |= (secondary << 21);
    151  1.1  cgd 
    152  1.1  cgd 		printf("read secondary %d reg %x (tag %x)",
    153  1.1  cgd 		    secondary, offset, tag);
    154  1.1  cgd #if	0
    155  1.1  cgd #endif
    156  1.1  cgd 
    157  1.1  cgd 		alpha_pal_draina();
    158  1.1  cgd 		s = splhigh();
    159  1.1  cgd 		/*
    160  1.1  cgd 		 * Set up HPCs for type 1 cycles.
    161  1.1  cgd 		 */
    162  1.1  cgd 		for (i = 0; i < sc->dwlpx_nhpc; i++) {
    163  1.1  cgd 			rvp = REGVAL(PCIA_CTL(i) + ccp->cc_sysbase) | 1;
    164  1.1  cgd 			alpha_mb();
    165  1.1  cgd 			REGVAL(PCIA_CTL(i) + ccp->cc_sysbase) = rvp;
    166  1.1  cgd 			alpha_mb();
    167  1.1  cgd 		}
    168  1.1  cgd #else
    169  1.1  cgd 		return (data);
    170  1.1  cgd #endif
    171  1.1  cgd 	}
    172  1.1  cgd 	paddr = (unsigned long) tag;
    173  1.1  cgd 	paddr |= DWLPX_PCI_CONF;
    174  1.1  cgd 	paddr |= ((unsigned long) ((offset >> 2) << 7));
    175  1.1  cgd 	paddr |= (((unsigned long) sc->dwlpx_hosenum) << 34);
    176  1.1  cgd 	paddr |= (((u_long) sc->dwlpx_node - 4) << 36);
    177  1.1  cgd 	paddr |= (1LL << 39);
    178  1.1  cgd 
    179  1.1  cgd 	dp = (pcireg_t *)KV(paddr);
    180  1.1  cgd 	if (badaddr(dp, sizeof (*dp)) == 0) {
    181  1.1  cgd 		data = *dp;
    182  1.1  cgd 	}
    183  1.1  cgd 	if (secondary) {
    184  1.1  cgd 		alpha_pal_draina();
    185  1.1  cgd 		for (i = 0; i < sc->dwlpx_nhpc; i++) {
    186  1.1  cgd 			rvp = REGVAL(PCIA_CTL(i) + ccp->cc_sysbase) & ~1;
    187  1.1  cgd 			alpha_mb();
    188  1.1  cgd 			REGVAL(PCIA_CTL(i) + ccp->cc_sysbase) = rvp;
    189  1.1  cgd 			alpha_mb();
    190  1.1  cgd 		}
    191  1.1  cgd 		(void) splx(s);
    192  1.1  cgd #ifdef	DO_SECONDARIES
    193  1.1  cgd 		printf("=%x\n", data);
    194  1.1  cgd #if	0
    195  1.1  cgd #endif
    196  1.1  cgd #endif
    197  1.1  cgd 	}
    198  1.1  cgd 	return (data);
    199  1.1  cgd }
    200  1.1  cgd 
    201  1.1  cgd void
    202  1.1  cgd dwlpx_conf_write(cpv, tag, offset, data)
    203  1.1  cgd 	void *cpv;
    204  1.1  cgd 	pcitag_t tag;
    205  1.1  cgd 	int offset;
    206  1.1  cgd 	pcireg_t data;
    207  1.1  cgd {
    208  1.1  cgd 	struct dwlpx_config *ccp = cpv;
    209  1.1  cgd 	struct dwlpx_softc *sc;
    210  1.1  cgd 	pcireg_t *dp;
    211  1.1  cgd 	unsigned long paddr;
    212  1.1  cgd 	int secondary, i, s = 0;
    213  1.1  cgd 	u_int32_t rvp;
    214  1.1  cgd 
    215  1.1  cgd 	if (ccp == NULL) {
    216  1.1  cgd 		panic("NULL ccp in dwlpx_conf_write\n");
    217  1.1  cgd 	}
    218  1.1  cgd 	sc = ccp->cc_sc;
    219  1.1  cgd 	secondary = tag >> 24;
    220  1.1  cgd 	if (secondary) {
    221  1.1  cgd 		tag &= 0x1fffff;
    222  1.1  cgd 		tag |= (secondary << 21);
    223  1.1  cgd 		printf("write secondary %d reg %x (tag %x) with %x\n",
    224  1.1  cgd 		    secondary, offset, tag, data);
    225  1.1  cgd #if	0
    226  1.1  cgd #endif
    227  1.1  cgd 
    228  1.1  cgd 		alpha_pal_draina();
    229  1.1  cgd 		s = splhigh();
    230  1.1  cgd 		/*
    231  1.1  cgd 		 * Set up HPCs for type 1 cycles.
    232  1.1  cgd 		 */
    233  1.1  cgd 		for (i = 0; i < sc->dwlpx_nhpc; i++) {
    234  1.1  cgd 			rvp = REGVAL(PCIA_CTL(i) + ccp->cc_sysbase) | 1;
    235  1.1  cgd 			alpha_mb();
    236  1.1  cgd 			REGVAL(PCIA_CTL(i) + ccp->cc_sysbase) = rvp;
    237  1.1  cgd 			alpha_mb();
    238  1.1  cgd 		}
    239  1.1  cgd 	}
    240  1.1  cgd 	paddr = (unsigned long) tag;
    241  1.1  cgd 	paddr |= DWLPX_PCI_CONF;
    242  1.1  cgd 	paddr |= ((unsigned long) ((offset >> 2) << 7));
    243  1.1  cgd 	paddr |= (((unsigned long) sc->dwlpx_hosenum) << 34);
    244  1.1  cgd 	paddr |= (((u_long) sc->dwlpx_node - 4) << 36);
    245  1.1  cgd 	paddr |= (1LL << 39);
    246  1.1  cgd 
    247  1.1  cgd 	dp = (pcireg_t *)KV(paddr);
    248  1.1  cgd 	*dp = data;
    249  1.1  cgd 	alpha_mb();
    250  1.1  cgd 	if (secondary) {
    251  1.1  cgd 		alpha_pal_draina();
    252  1.1  cgd 		for (i = 0; i < sc->dwlpx_nhpc; i++) {
    253  1.1  cgd 			rvp = REGVAL(PCIA_CTL(i) + ccp->cc_sysbase) & ~1;
    254  1.1  cgd 			alpha_mb();
    255  1.1  cgd 			REGVAL(PCIA_CTL(i) + ccp->cc_sysbase) = rvp;
    256  1.1  cgd 			alpha_mb();
    257  1.1  cgd 		}
    258  1.1  cgd 		(void) splx(s);
    259  1.1  cgd 	}
    260  1.1  cgd }
    261