Home | History | Annotate | Line # | Download | only in pci
lca.c revision 1.37
      1  1.37   thorpej /* $NetBSD: lca.c,v 1.37 2002/05/16 01:01:32 thorpej Exp $ */
      2  1.35   thorpej 
      3  1.35   thorpej /*-
      4  1.35   thorpej  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5  1.35   thorpej  * All rights reserved.
      6  1.35   thorpej  *
      7  1.35   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8  1.35   thorpej  * by Jason R. Thorpe.
      9  1.35   thorpej  *
     10  1.35   thorpej  * Redistribution and use in source and binary forms, with or without
     11  1.35   thorpej  * modification, are permitted provided that the following conditions
     12  1.35   thorpej  * are met:
     13  1.35   thorpej  * 1. Redistributions of source code must retain the above copyright
     14  1.35   thorpej  *    notice, this list of conditions and the following disclaimer.
     15  1.35   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.35   thorpej  *    notice, this list of conditions and the following disclaimer in the
     17  1.35   thorpej  *    documentation and/or other materials provided with the distribution.
     18  1.35   thorpej  * 3. All advertising materials mentioning features or use of this software
     19  1.35   thorpej  *    must display the following acknowledgement:
     20  1.35   thorpej  *	This product includes software developed by the NetBSD
     21  1.35   thorpej  *	Foundation, Inc. and its contributors.
     22  1.35   thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.35   thorpej  *    contributors may be used to endorse or promote products derived
     24  1.35   thorpej  *    from this software without specific prior written permission.
     25  1.35   thorpej  *
     26  1.35   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.35   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.35   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.35   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.35   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.35   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.35   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.35   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.35   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.35   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.35   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     37  1.35   thorpej  */
     38   1.1       cgd 
     39   1.1       cgd /*
     40   1.4       cgd  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
     41   1.1       cgd  * All rights reserved.
     42   1.1       cgd  *
     43   1.3       cgd  * Authors: Jeffrey Hsu and Chris G. Demetriou
     44   1.1       cgd  *
     45   1.1       cgd  * Permission to use, copy, modify and distribute this software and
     46   1.1       cgd  * its documentation is hereby granted, provided that both the copyright
     47   1.1       cgd  * notice and this permission notice appear in all copies of the
     48   1.1       cgd  * software, derivative works or modified versions, and any portions
     49   1.1       cgd  * thereof, and that both notices appear in supporting documentation.
     50   1.1       cgd  *
     51   1.1       cgd  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     52   1.1       cgd  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     53   1.1       cgd  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     54   1.1       cgd  *
     55   1.1       cgd  * Carnegie Mellon requests users of this software to return to
     56   1.1       cgd  *
     57   1.1       cgd  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     58   1.1       cgd  *  School of Computer Science
     59   1.1       cgd  *  Carnegie Mellon University
     60   1.1       cgd  *  Pittsburgh PA 15213-3890
     61   1.1       cgd  *
     62   1.1       cgd  * any improvements or extensions that they make and grant Carnegie the
     63   1.1       cgd  * rights to redistribute these changes.
     64   1.1       cgd  */
     65  1.17       cgd 
     66  1.25   thorpej #include "opt_dec_axppci_33.h"
     67  1.31   thorpej #include "opt_dec_alphabook1.h"
     68  1.32   thorpej #include "opt_dec_eb66.h"
     69  1.24   thorpej 
     70  1.18       cgd #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     71  1.18       cgd 
     72  1.37   thorpej __KERNEL_RCSID(0, "$NetBSD: lca.c,v 1.37 2002/05/16 01:01:32 thorpej Exp $");
     73   1.1       cgd 
     74   1.1       cgd #include <sys/param.h>
     75   1.1       cgd #include <sys/systm.h>
     76   1.1       cgd #include <sys/kernel.h>
     77   1.1       cgd #include <sys/malloc.h>
     78   1.1       cgd #include <sys/device.h>
     79  1.36       mrg 
     80  1.36       mrg #include <uvm/uvm_extern.h>
     81   1.1       cgd 
     82   1.1       cgd #include <machine/autoconf.h>
     83   1.1       cgd #include <machine/rpb.h>
     84  1.35   thorpej #include <machine/sysarch.h>
     85   1.1       cgd 
     86   1.1       cgd #include <dev/isa/isareg.h>
     87   1.1       cgd #include <dev/isa/isavar.h>
     88   1.1       cgd 
     89   1.1       cgd #include <dev/pci/pcireg.h>
     90   1.1       cgd #include <dev/pci/pcivar.h>
     91   1.1       cgd #include <alpha/pci/lcareg.h>
     92   1.1       cgd #include <alpha/pci/lcavar.h>
     93  1.16       cgd #ifdef DEC_AXPPCI_33
     94   1.7       cgd #include <alpha/pci/pci_axppci_33.h>
     95   1.7       cgd #endif
     96  1.30   thorpej #ifdef DEC_ALPHABOOK1
     97  1.30   thorpej #include <alpha/pci/pci_alphabook1.h>
     98  1.30   thorpej #endif
     99  1.32   thorpej #ifdef DEC_EB66
    100  1.32   thorpej #include <alpha/pci/pci_eb66.h>
    101  1.32   thorpej #endif
    102   1.1       cgd 
    103  1.14       cgd int	lcamatch __P((struct device *, struct cfdata *, void *));
    104   1.1       cgd void	lcaattach __P((struct device *, struct device *, void *));
    105   1.1       cgd 
    106   1.2   thorpej struct cfattach lca_ca = {
    107   1.3       cgd 	sizeof(struct lca_softc), lcamatch, lcaattach,
    108   1.2   thorpej };
    109   1.2   thorpej 
    110  1.26   thorpej extern struct cfdriver lca_cd;
    111   1.1       cgd 
    112   1.8       cgd static int	lcaprint __P((void *, const char *pnp));
    113   1.1       cgd 
    114  1.35   thorpej int	lca_bus_get_window __P((int, int,
    115  1.35   thorpej 	    struct alpha_bus_space_translation *));
    116  1.35   thorpej 
    117   1.1       cgd /* There can be only one. */
    118   1.1       cgd int lcafound;
    119   1.1       cgd struct lca_config lca_configuration;
    120   1.1       cgd 
    121   1.1       cgd int
    122   1.1       cgd lcamatch(parent, match, aux)
    123   1.1       cgd 	struct device *parent;
    124  1.14       cgd 	struct cfdata *match;
    125  1.14       cgd 	void *aux;
    126   1.1       cgd {
    127  1.28   thorpej 	struct mainbus_attach_args *ma = aux;
    128   1.1       cgd 
    129   1.1       cgd 	/* Make sure that we're looking for a LCA. */
    130  1.28   thorpej 	if (strcmp(ma->ma_name, lca_cd.cd_name) != 0)
    131   1.1       cgd 		return (0);
    132   1.1       cgd 
    133   1.1       cgd 	if (lcafound)
    134   1.1       cgd 		return (0);
    135   1.1       cgd 
    136   1.1       cgd 	return (1);
    137   1.1       cgd }
    138   1.1       cgd 
    139   1.1       cgd /*
    140   1.1       cgd  * Set up the chipset's function pointers.
    141   1.1       cgd  */
    142   1.1       cgd void
    143  1.13       cgd lca_init(lcp, mallocsafe)
    144   1.1       cgd 	struct lca_config *lcp;
    145  1.13       cgd 	int mallocsafe;
    146   1.1       cgd {
    147   1.1       cgd 
    148   1.1       cgd 	/*
    149  1.13       cgd 	 * The LCA HAE register is WRITE-ONLY, so we can't tell where
    150  1.13       cgd 	 * the second sparse window is actually mapped.  Therefore,
    151  1.13       cgd 	 * we have to guess where it is.  This seems to be the normal
    152  1.13       cgd 	 * address.
    153  1.13       cgd 	 */
    154  1.13       cgd 	lcp->lc_s_mem_w2_masked_base = 0x80000000;
    155  1.13       cgd 
    156  1.13       cgd 	if (!lcp->lc_initted) {
    157  1.13       cgd 		/* don't do these twice since they set up extents */
    158  1.21   thorpej 		lca_bus_io_init(&lcp->lc_iot, lcp);
    159  1.21   thorpej 		lca_bus_mem_init(&lcp->lc_memt, lcp);
    160  1.35   thorpej 
    161  1.35   thorpej 		/*
    162  1.35   thorpej 		 * We have 1 I/O window and 3 MEM windows.
    163  1.35   thorpej 		 */
    164  1.35   thorpej 		alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_IO] = 1;
    165  1.35   thorpej 		alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_MEM] = 3;
    166  1.35   thorpej 		alpha_bus_get_window = lca_bus_get_window;
    167  1.13       cgd 	}
    168  1.13       cgd 	lcp->lc_mallocsafe = mallocsafe;
    169  1.13       cgd 
    170   1.3       cgd 	lca_pci_init(&lcp->lc_pc, lcp);
    171  1.35   thorpej 	alpha_pci_chipset = &lcp->lc_pc;
    172   1.1       cgd 
    173   1.5       cgd 	/*
    174   1.5       cgd 	 * Refer to ``DECchip 21066 and DECchip 21068 Alpha AXP Microprocessors
    175   1.5       cgd 	 * Hardware Reference Manual''.
    176   1.5       cgd 	 * ...
    177   1.5       cgd 	 */
    178   1.5       cgd 
    179   1.5       cgd 	/*
    180   1.5       cgd 	 * According to section 6.4.1, all bits of the IOC_HAE register are
    181   1.5       cgd 	 * undefined after reset.  Bits <31:27> are write-only.  However, we
    182   1.5       cgd 	 * cannot blindly set it to zero.  The serial ROM code that initializes
    183   1.5       cgd 	 * the PCI devices' address spaces, allocates sparse memory blocks in
    184   1.5       cgd 	 * the range that must use the IOC_HAE register for address translation,
    185   1.5       cgd 	 * and sets this register accordingly (see section 6.4.14).
    186   1.5       cgd 	 *
    187   1.5       cgd 	 *	IOC_HAE left AS IS.
    188   1.5       cgd 	 */
    189   1.1       cgd 
    190   1.5       cgd 	/* According to section 6.4.2, all bits of the IOC_CONF register are
    191   1.5       cgd 	 * undefined after reset.  Bits <1:0> are write-only.  Set them to
    192   1.5       cgd 	 * 0x00 for PCI Type 0 configuration access.
    193   1.5       cgd 	 *
    194   1.5       cgd 	 *	IOC_CONF set to ZERO.
    195   1.5       cgd 	 */
    196  1.20   thorpej 	REGVAL64(LCA_IOC_CONF) = 0;
    197   1.1       cgd 
    198  1.13       cgd 	lcp->lc_initted = 1;
    199   1.1       cgd }
    200   1.1       cgd 
    201   1.1       cgd void
    202   1.1       cgd lcaattach(parent, self, aux)
    203   1.1       cgd 	struct device *parent, *self;
    204   1.1       cgd 	void *aux;
    205   1.1       cgd {
    206   1.1       cgd 	struct lca_softc *sc = (struct lca_softc *)self;
    207   1.1       cgd 	struct lca_config *lcp;
    208   1.3       cgd 	struct pcibus_attach_args pba;
    209   1.1       cgd 
    210   1.1       cgd 	/* note that we've attached the chipset; can't have 2 LCAs. */
    211   1.1       cgd 	/* Um, not sure about this.  XXX JH */
    212   1.1       cgd 	lcafound = 1;
    213   1.1       cgd 
    214   1.1       cgd 	/*
    215   1.1       cgd 	 * set up the chipset's info; done once at console init time
    216  1.20   thorpej 	 * (maybe), but we must do it twice to take care of things
    217  1.20   thorpej 	 * that need to use memory allocation.
    218   1.1       cgd 	 */
    219   1.1       cgd 	lcp = sc->sc_lcp = &lca_configuration;
    220  1.13       cgd 	lca_init(lcp, 1);
    221   1.1       cgd 
    222   1.1       cgd 	/* XXX print chipset information */
    223  1.10  christos 	printf("\n");
    224  1.29   thorpej 
    225  1.29   thorpej 	lca_dma_init(lcp);
    226   1.1       cgd 
    227  1.33       cgd 	switch (cputype) {
    228  1.16       cgd #ifdef DEC_AXPPCI_33
    229   1.1       cgd 	case ST_DEC_AXPPCI_33:
    230   1.3       cgd 		pci_axppci_33_pickintr(lcp);
    231  1.30   thorpej 		break;
    232  1.30   thorpej #endif
    233  1.30   thorpej #ifdef DEC_ALPHABOOK1
    234  1.30   thorpej 	case ST_ALPHABOOK1:
    235  1.30   thorpej 		pci_alphabook1_pickintr(lcp);
    236  1.32   thorpej 		break;
    237  1.32   thorpej #endif
    238  1.32   thorpej #ifdef DEC_EB66
    239  1.32   thorpej 	case ST_EB66:
    240  1.32   thorpej 		pci_eb66_pickintr(lcp);
    241   1.1       cgd 		break;
    242   1.1       cgd #endif
    243  1.12       cgd 
    244   1.1       cgd 	default:
    245   1.1       cgd 		panic("lcaattach: shouldn't be here, really...");
    246   1.1       cgd 	}
    247   1.1       cgd 
    248   1.3       cgd 	pba.pba_busname = "pci";
    249  1.22   thorpej 	pba.pba_iot = &lcp->lc_iot;
    250  1.22   thorpej 	pba.pba_memt = &lcp->lc_memt;
    251  1.27   thorpej 	pba.pba_dmat =
    252  1.27   thorpej 	    alphabus_dma_get_tag(&lcp->lc_dmat_direct, ALPHA_BUS_PCI);
    253   1.3       cgd 	pba.pba_pc = &lcp->lc_pc;
    254   1.3       cgd 	pba.pba_bus = 0;
    255  1.37   thorpej 	pba.pba_bridgetag = NULL;
    256  1.34   thorpej 	pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED |
    257  1.34   thorpej 	    PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
    258   1.3       cgd 	config_found(self, &pba, lcaprint);
    259   1.1       cgd }
    260   1.1       cgd 
    261   1.1       cgd static int
    262   1.1       cgd lcaprint(aux, pnp)
    263   1.1       cgd 	void *aux;
    264   1.8       cgd 	const char *pnp;
    265   1.1       cgd {
    266  1.13       cgd 	register struct pcibus_attach_args *pba = aux;
    267   1.1       cgd 
    268   1.1       cgd 	/* only PCIs can attach to LCAes; easy. */
    269   1.1       cgd 	if (pnp)
    270  1.10  christos 		printf("%s at %s", pba->pba_busname, pnp);
    271  1.10  christos 	printf(" bus %d", pba->pba_bus);
    272   1.1       cgd 	return (UNCONF);
    273  1.35   thorpej }
    274  1.35   thorpej 
    275  1.35   thorpej int
    276  1.35   thorpej lca_bus_get_window(type, window, abst)
    277  1.35   thorpej 	int type, window;
    278  1.35   thorpej 	struct alpha_bus_space_translation *abst;
    279  1.35   thorpej {
    280  1.35   thorpej 	struct lca_config *lcp = &lca_configuration;
    281  1.35   thorpej 	bus_space_tag_t st;
    282  1.35   thorpej 
    283  1.35   thorpej 	switch (type) {
    284  1.35   thorpej 	case ALPHA_BUS_TYPE_PCI_IO:
    285  1.35   thorpej 		st = &lcp->lc_iot;
    286  1.35   thorpej 		break;
    287  1.35   thorpej 
    288  1.35   thorpej 	case ALPHA_BUS_TYPE_PCI_MEM:
    289  1.35   thorpej 		st = &lcp->lc_memt;
    290  1.35   thorpej 		break;
    291  1.35   thorpej 
    292  1.35   thorpej 	default:
    293  1.35   thorpej 		panic("lca_bus_get_window");
    294  1.35   thorpej 	}
    295  1.35   thorpej 
    296  1.35   thorpej 	return (alpha_bus_space_get_window(st, window, abst));
    297   1.1       cgd }
    298