Home | History | Annotate | Line # | Download | only in xscale
i80321.c revision 1.2
      1  1.2  thorpej /*	$NetBSD: i80321.c,v 1.2 2002/05/16 01:01:34 thorpej Exp $	*/
      2  1.1  thorpej 
      3  1.1  thorpej /*
      4  1.1  thorpej  * Copyright (c) 2002 Wasabi Systems, Inc.
      5  1.1  thorpej  * All rights reserved.
      6  1.1  thorpej  *
      7  1.1  thorpej  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
      8  1.1  thorpej  *
      9  1.1  thorpej  * Redistribution and use in source and binary forms, with or without
     10  1.1  thorpej  * modification, are permitted provided that the following conditions
     11  1.1  thorpej  * are met:
     12  1.1  thorpej  * 1. Redistributions of source code must retain the above copyright
     13  1.1  thorpej  *    notice, this list of conditions and the following disclaimer.
     14  1.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     16  1.1  thorpej  *    documentation and/or other materials provided with the distribution.
     17  1.1  thorpej  * 3. All advertising materials mentioning features or use of this software
     18  1.1  thorpej  *    must display the following acknowledgement:
     19  1.1  thorpej  *	This product includes software developed for the NetBSD Project by
     20  1.1  thorpej  *	Wasabi Systems, Inc.
     21  1.1  thorpej  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  1.1  thorpej  *    or promote products derived from this software without specific prior
     23  1.1  thorpej  *    written permission.
     24  1.1  thorpej  *
     25  1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  1.1  thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.1  thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.1  thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  1.1  thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.1  thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.1  thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.1  thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.1  thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.1  thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.1  thorpej  * POSSIBILITY OF SUCH DAMAGE.
     36  1.1  thorpej  */
     37  1.1  thorpej 
     38  1.1  thorpej /*
     39  1.1  thorpej  * Autoconfiguration support for the Intel i80321 I/O Processor.
     40  1.1  thorpej  */
     41  1.1  thorpej 
     42  1.1  thorpej #include <sys/param.h>
     43  1.1  thorpej #include <sys/systm.h>
     44  1.1  thorpej #include <sys/device.h>
     45  1.1  thorpej 
     46  1.1  thorpej #include <machine/bus.h>
     47  1.1  thorpej 
     48  1.1  thorpej #include <arm/xscale/i80321reg.h>
     49  1.1  thorpej #include <arm/xscale/i80321var.h>
     50  1.1  thorpej 
     51  1.1  thorpej /*
     52  1.1  thorpej  * Statically-allocated bus_space stucture used to access the
     53  1.1  thorpej  * i80321's own registers.
     54  1.1  thorpej  */
     55  1.1  thorpej struct bus_space i80321_bs_tag;
     56  1.1  thorpej 
     57  1.1  thorpej /*
     58  1.1  thorpej  * There can be only one i80321, so we keep a global pointer to
     59  1.1  thorpej  * the softc, so board-specific code can use features of the
     60  1.1  thorpej  * i80321 without having to have a handle on the softc itself.
     61  1.1  thorpej  */
     62  1.1  thorpej struct i80321_softc *i80321_softc;
     63  1.1  thorpej 
     64  1.1  thorpej int	i80321_pcibus_print(void *, const char *);
     65  1.1  thorpej 
     66  1.1  thorpej /*
     67  1.1  thorpej  * i80321_attach:
     68  1.1  thorpej  *
     69  1.1  thorpej  *	Board-independent attach routine for the i80321.
     70  1.1  thorpej  */
     71  1.1  thorpej void
     72  1.1  thorpej i80321_attach(struct i80321_softc *sc)
     73  1.1  thorpej {
     74  1.1  thorpej 	struct pcibus_attach_args pba;
     75  1.1  thorpej 	pcireg_t preg;
     76  1.1  thorpej 
     77  1.1  thorpej 	i80321_softc = sc;
     78  1.1  thorpej 
     79  1.1  thorpej 	/*
     80  1.1  thorpej 	 * Slice off some useful subregion handles.
     81  1.1  thorpej 	 */
     82  1.1  thorpej 
     83  1.1  thorpej 	if (bus_space_subregion(sc->sc_st, sc->sc_sh, VERDE_ATU_BASE,
     84  1.1  thorpej 	    VERDE_ATU_SIZE, &sc->sc_atu_sh))
     85  1.1  thorpej 		panic("%s: unable to subregion ATU registers\n",
     86  1.1  thorpej 		    sc->sc_dev.dv_xname);
     87  1.1  thorpej 
     88  1.1  thorpej 	/* We expect the Memory Controller to be already sliced off. */
     89  1.1  thorpej 
     90  1.1  thorpej 	/*
     91  1.1  thorpej 	 * Program the Inbound windows.
     92  1.1  thorpej 	 */
     93  1.1  thorpej 	if (sc->sc_is_host) {
     94  1.1  thorpej 		bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
     95  1.1  thorpej 		    PCI_MAPREG_START, sc->sc_iwin[0].iwin_base_lo);
     96  1.1  thorpej 		bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
     97  1.1  thorpej 		    PCI_MAPREG_START + 0x04, sc->sc_iwin[0].iwin_base_hi);
     98  1.1  thorpej 	}
     99  1.1  thorpej 	bus_space_write_4(sc->sc_st, sc->sc_atu_sh, ATU_IALR0,
    100  1.1  thorpej 	    (0xffffffff - (sc->sc_iwin[0].iwin_size - 1)) & 0xffffffc0);
    101  1.1  thorpej 	bus_space_write_4(sc->sc_st, sc->sc_atu_sh, ATU_IATVR0,
    102  1.1  thorpej 	    sc->sc_iwin[0].iwin_xlate);
    103  1.1  thorpej 
    104  1.1  thorpej 	if (sc->sc_is_host) {
    105  1.1  thorpej 		bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
    106  1.1  thorpej 		    PCI_MAPREG_START + 0x08, sc->sc_iwin[1].iwin_base_lo);
    107  1.1  thorpej 		bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
    108  1.1  thorpej 		    PCI_MAPREG_START + 0x0c, sc->sc_iwin[1].iwin_base_hi);
    109  1.1  thorpej 	}
    110  1.1  thorpej 	bus_space_write_4(sc->sc_st, sc->sc_atu_sh, ATU_IALR1,
    111  1.1  thorpej 	    (0xffffffff - (sc->sc_iwin[1].iwin_size - 1)) & 0xffffffc0);
    112  1.1  thorpej 	/* no xlate for window 1 */
    113  1.1  thorpej 
    114  1.1  thorpej 	if (sc->sc_is_host) {
    115  1.1  thorpej 		bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
    116  1.1  thorpej 		    PCI_MAPREG_START + 0x10, sc->sc_iwin[2].iwin_base_lo);
    117  1.1  thorpej 		bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
    118  1.1  thorpej 		    PCI_MAPREG_START + 0x14, sc->sc_iwin[2].iwin_base_hi);
    119  1.1  thorpej 	}
    120  1.1  thorpej 	bus_space_write_4(sc->sc_st, sc->sc_atu_sh, ATU_IALR2,
    121  1.1  thorpej 	    (0xffffffff - (sc->sc_iwin[2].iwin_size - 1)) & 0xffffffc0);
    122  1.1  thorpej 	bus_space_write_4(sc->sc_st, sc->sc_atu_sh, ATU_IATVR2,
    123  1.1  thorpej 	    sc->sc_iwin[2].iwin_xlate);
    124  1.1  thorpej 
    125  1.1  thorpej 	if (sc->sc_is_host) {
    126  1.1  thorpej 		bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
    127  1.1  thorpej 		    ATU_IABAR3, sc->sc_iwin[3].iwin_base_lo);
    128  1.1  thorpej 		bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
    129  1.1  thorpej 		    ATU_IAUBAR3, sc->sc_iwin[3].iwin_base_hi);
    130  1.1  thorpej 	}
    131  1.1  thorpej 	bus_space_write_4(sc->sc_st, sc->sc_atu_sh, ATU_IALR3,
    132  1.1  thorpej 	    (0xffffffff - (sc->sc_iwin[3].iwin_size - 1)) & 0xffffffc0);
    133  1.1  thorpej 	bus_space_write_4(sc->sc_st, sc->sc_atu_sh, ATU_IATVR3,
    134  1.1  thorpej 	    sc->sc_iwin[3].iwin_xlate);
    135  1.1  thorpej 
    136  1.1  thorpej 	/*
    137  1.1  thorpej 	 * Mask (disable) the ATU interrupt sources.
    138  1.1  thorpej 	 * XXX May want to revisit this if we encounter
    139  1.1  thorpej 	 * XXX an application that wants it.
    140  1.1  thorpej 	 */
    141  1.1  thorpej 	bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
    142  1.1  thorpej 	    ATU_ATUIMR,
    143  1.1  thorpej 	    ATUIMR_IMW1BU|ATUIMR_ISCEM|ATUIMR_RSCEM|ATUIMR_PST|
    144  1.1  thorpej 	    ATUIMR_DPE|ATUIMR_P_SERR_ASRT|ATUIMR_PMA|ATUIMR_PTAM|
    145  1.1  thorpej 	    ATUIMR_PTAT|ATUIMR_PMPE);
    146  1.1  thorpej 
    147  1.1  thorpej 	/*
    148  1.1  thorpej 	 * Program the outbound windows.
    149  1.1  thorpej 	 */
    150  1.1  thorpej 	bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
    151  1.1  thorpej 	    ATU_OIOWTVR, sc->sc_ioout_xlate);
    152  1.1  thorpej 
    153  1.1  thorpej 	bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
    154  1.1  thorpej 	    ATU_OMWTVR0, sc->sc_owin[0].owin_xlate_lo);
    155  1.1  thorpej 	bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
    156  1.1  thorpej 	    ATU_OUMWTVR0, sc->sc_owin[0].owin_xlate_hi);
    157  1.1  thorpej 
    158  1.1  thorpej 	bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
    159  1.1  thorpej 	    ATU_OMWTVR1, sc->sc_owin[1].owin_xlate_lo);
    160  1.1  thorpej 	bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
    161  1.1  thorpej 	    ATU_OUMWTVR1, sc->sc_owin[1].owin_xlate_hi);
    162  1.1  thorpej 
    163  1.1  thorpej 	/*
    164  1.1  thorpej 	 * Set up the ATU configuration register.  All we do
    165  1.1  thorpej 	 * right now is enable Outbound Windows.
    166  1.1  thorpej 	 */
    167  1.1  thorpej 	bus_space_write_4(sc->sc_st, sc->sc_atu_sh, ATU_ATUCR,
    168  1.1  thorpej 	    ATUCR_OUT_EN);
    169  1.1  thorpej 
    170  1.1  thorpej 	/*
    171  1.1  thorpej 	 * Enable bus mastering, memory access, SERR, and parity
    172  1.1  thorpej 	 * checking on the ATU.
    173  1.1  thorpej 	 */
    174  1.1  thorpej 	if (sc->sc_is_host) {
    175  1.1  thorpej 		preg = bus_space_read_4(sc->sc_st, sc->sc_atu_sh,
    176  1.1  thorpej 		    PCI_COMMAND_STATUS_REG);
    177  1.1  thorpej 		preg |= PCI_COMMAND_MEM_ENABLE | PCI_COMMAND_MASTER_ENABLE |
    178  1.1  thorpej 		    PCI_COMMAND_PARITY_ENABLE | PCI_COMMAND_SERR_ENABLE;
    179  1.1  thorpej 		bus_space_write_4(sc->sc_st, sc->sc_atu_sh,
    180  1.1  thorpej 		    PCI_COMMAND_STATUS_REG, preg);
    181  1.1  thorpej 	}
    182  1.1  thorpej 
    183  1.1  thorpej 	/*
    184  1.1  thorpej 	 * Initialize the bus space and DMA tags and the PCI chipset tag.
    185  1.1  thorpej 	 */
    186  1.1  thorpej 	i80321_io_bs_init(&sc->sc_pci_iot, sc);
    187  1.1  thorpej 	i80321_mem_bs_init(&sc->sc_pci_memt, sc);
    188  1.1  thorpej 	i80321_pci_dma_init(&sc->sc_pci_dmat, sc);
    189  1.1  thorpej 	i80321_pci_init(&sc->sc_pci_chipset, sc);
    190  1.1  thorpej 
    191  1.1  thorpej 	/*
    192  1.1  thorpej 	 * Attach the PCI bus.
    193  1.1  thorpej 	 */
    194  1.1  thorpej 	preg = bus_space_read_4(sc->sc_st, sc->sc_atu_sh, ATU_PCIXSR);
    195  1.1  thorpej 	preg = PCIXSR_BUSNO(preg);
    196  1.1  thorpej 	if (preg == 0xff)
    197  1.1  thorpej 		preg = 0;
    198  1.1  thorpej 	pba.pba_busname = "pci";
    199  1.1  thorpej 	pba.pba_iot = &sc->sc_pci_iot;
    200  1.1  thorpej 	pba.pba_memt = &sc->sc_pci_memt;
    201  1.1  thorpej 	pba.pba_dmat = &sc->sc_pci_dmat;
    202  1.1  thorpej 	pba.pba_pc = &sc->sc_pci_chipset;
    203  1.1  thorpej 	pba.pba_bus = preg;
    204  1.2  thorpej 	pba.pba_bridgetag = NULL;
    205  1.1  thorpej 	pba.pba_intrswiz = 0;	/* XXX what if busno != 0? */
    206  1.1  thorpej 	pba.pba_intrtag = 0;
    207  1.1  thorpej 	pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED |
    208  1.1  thorpej 	    PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
    209  1.1  thorpej 	(void) config_found(&sc->sc_dev, &pba, i80321_pcibus_print);
    210  1.1  thorpej }
    211  1.1  thorpej 
    212  1.1  thorpej /*
    213  1.1  thorpej  * i80321_pcibus_print:
    214  1.1  thorpej  *
    215  1.1  thorpej  *	Autoconfiguration cfprint routine when attaching
    216  1.1  thorpej  *	to the "pcibus" attribute.
    217  1.1  thorpej  */
    218  1.1  thorpej int
    219  1.1  thorpej i80321_pcibus_print(void *aux, const char *pnp)
    220  1.1  thorpej {
    221  1.1  thorpej 	struct pcibus_attach_args *pba = aux;
    222  1.1  thorpej 
    223  1.1  thorpej 	if (pnp)
    224  1.1  thorpej 		printf("%s at %s", pba->pba_busname, pnp);
    225  1.1  thorpej 
    226  1.1  thorpej 	printf(" bus %d", pba->pba_bus);
    227  1.1  thorpej 
    228  1.1  thorpej 	return (UNCONF);
    229  1.1  thorpej }
    230