Home | History | Annotate | Line # | Download | only in footbridge
footbridge.c revision 1.2.6.9
      1  1.2.6.9  thorpej /*	$NetBSD: footbridge.c,v 1.2.6.9 2003/01/03 16:41:08 thorpej Exp $	*/
      2  1.2.6.2  nathanw 
      3  1.2.6.2  nathanw /*
      4  1.2.6.2  nathanw  * Copyright (c) 1997,1998 Mark Brinicombe.
      5  1.2.6.2  nathanw  * Copyright (c) 1997,1998 Causality Limited
      6  1.2.6.2  nathanw  * All rights reserved.
      7  1.2.6.2  nathanw  *
      8  1.2.6.2  nathanw  * Redistribution and use in source and binary forms, with or without
      9  1.2.6.2  nathanw  * modification, are permitted provided that the following conditions
     10  1.2.6.2  nathanw  * are met:
     11  1.2.6.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     12  1.2.6.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     13  1.2.6.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.2.6.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     15  1.2.6.2  nathanw  *    documentation and/or other materials provided with the distribution.
     16  1.2.6.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     17  1.2.6.2  nathanw  *    must display the following acknowledgement:
     18  1.2.6.2  nathanw  *	This product includes software developed by Mark Brinicombe
     19  1.2.6.2  nathanw  *	for the NetBSD Project.
     20  1.2.6.2  nathanw  * 4. The name of the company nor the name of the author may be used to
     21  1.2.6.2  nathanw  *    endorse or promote products derived from this software without specific
     22  1.2.6.2  nathanw  *    prior written permission.
     23  1.2.6.2  nathanw  *
     24  1.2.6.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
     25  1.2.6.2  nathanw  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     26  1.2.6.2  nathanw  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     27  1.2.6.2  nathanw  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     28  1.2.6.2  nathanw  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     29  1.2.6.2  nathanw  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     30  1.2.6.2  nathanw  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  1.2.6.2  nathanw  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  1.2.6.2  nathanw  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  1.2.6.2  nathanw  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  1.2.6.2  nathanw  * SUCH DAMAGE.
     35  1.2.6.2  nathanw  */
     36  1.2.6.2  nathanw 
     37  1.2.6.2  nathanw #include <sys/param.h>
     38  1.2.6.2  nathanw #include <sys/systm.h>
     39  1.2.6.2  nathanw #include <sys/kernel.h>
     40  1.2.6.2  nathanw #include <sys/conf.h>
     41  1.2.6.2  nathanw #include <sys/malloc.h>
     42  1.2.6.2  nathanw #include <sys/device.h>
     43  1.2.6.2  nathanw 
     44  1.2.6.2  nathanw #include <dev/pci/pcivar.h>
     45  1.2.6.2  nathanw #define _ARM32_BUS_DMA_PRIVATE
     46  1.2.6.2  nathanw #include <machine/bus.h>
     47  1.2.6.2  nathanw #include <machine/intr.h>
     48  1.2.6.2  nathanw 
     49  1.2.6.5  nathanw #include <arm/cpuconf.h>
     50  1.2.6.2  nathanw #include <arm/cpufunc.h>
     51  1.2.6.2  nathanw 
     52  1.2.6.2  nathanw #include <arm/footbridge/footbridgevar.h>
     53  1.2.6.2  nathanw #include <arm/footbridge/dc21285reg.h>
     54  1.2.6.2  nathanw #include <arm/footbridge/dc21285mem.h>
     55  1.2.6.3  nathanw #include <arm/footbridge/footbridge.h>
     56  1.2.6.3  nathanw 
     57  1.2.6.2  nathanw /*
     58  1.2.6.2  nathanw  * DC21285 'Footbridge' device
     59  1.2.6.2  nathanw  *
     60  1.2.6.2  nathanw  * This probes and attaches the footbridge device
     61  1.2.6.2  nathanw  * It then configures any children
     62  1.2.6.2  nathanw  */
     63  1.2.6.2  nathanw 
     64  1.2.6.2  nathanw /* Declare prototypes */
     65  1.2.6.2  nathanw 
     66  1.2.6.2  nathanw static int footbridge_match	__P((struct device *parent, struct cfdata *cf,
     67  1.2.6.2  nathanw 	                             void *aux));
     68  1.2.6.2  nathanw static void footbridge_attach	__P((struct device *parent, struct device *self,
     69  1.2.6.2  nathanw         	                     void *aux));
     70  1.2.6.2  nathanw static int footbridge_print	__P((void *aux, const char *pnp));
     71  1.2.6.2  nathanw static int footbridge_intr	__P((void *arg));
     72  1.2.6.2  nathanw 
     73  1.2.6.2  nathanw /* Driver and attach structures */
     74  1.2.6.7  nathanw CFATTACH_DECL(footbridge, sizeof(struct footbridge_softc),
     75  1.2.6.7  nathanw     footbridge_match, footbridge_attach, NULL, NULL);
     76  1.2.6.2  nathanw 
     77  1.2.6.2  nathanw /* Various bus space tags */
     78  1.2.6.2  nathanw extern struct bus_space footbridge_bs_tag;
     79  1.2.6.2  nathanw extern void footbridge_create_io_bs_tag(bus_space_tag_t t, void *cookie);
     80  1.2.6.2  nathanw extern void footbridge_create_mem_bs_tag(bus_space_tag_t t, void *cookie);
     81  1.2.6.2  nathanw struct bus_space footbridge_csr_tag;
     82  1.2.6.2  nathanw struct bus_space footbridge_pci_io_bs_tag;
     83  1.2.6.2  nathanw struct bus_space footbridge_pci_mem_bs_tag;
     84  1.2.6.2  nathanw extern struct arm32_pci_chipset footbridge_pci_chipset;
     85  1.2.6.2  nathanw extern struct arm32_bus_dma_tag footbridge_pci_bus_dma_tag;
     86  1.2.6.2  nathanw 
     87  1.2.6.2  nathanw /* Used in footbridge_clock.c */
     88  1.2.6.2  nathanw struct footbridge_softc *clock_sc;
     89  1.2.6.2  nathanw 
     90  1.2.6.2  nathanw /* Set to non-zero to enable verbose reporting of footbridge system ints */
     91  1.2.6.2  nathanw int footbridge_intr_report = 0;
     92  1.2.6.2  nathanw 
     93  1.2.6.2  nathanw int footbridge_found;
     94  1.2.6.2  nathanw 
     95  1.2.6.2  nathanw void
     96  1.2.6.2  nathanw footbridge_pci_bs_tag_init(void)
     97  1.2.6.2  nathanw {
     98  1.2.6.2  nathanw 	/* Set up the PCI bus tags */
     99  1.2.6.2  nathanw 	footbridge_create_io_bs_tag(&footbridge_pci_io_bs_tag,
    100  1.2.6.2  nathanw 	    (void *)DC21285_PCI_IO_VBASE);
    101  1.2.6.2  nathanw 	footbridge_create_mem_bs_tag(&footbridge_pci_mem_bs_tag,
    102  1.2.6.2  nathanw 	    (void *)DC21285_PCI_MEM_BASE);
    103  1.2.6.2  nathanw }
    104  1.2.6.2  nathanw 
    105  1.2.6.2  nathanw /*
    106  1.2.6.2  nathanw  * int footbridgeprint(void *aux, const char *name)
    107  1.2.6.2  nathanw  *
    108  1.2.6.2  nathanw  * print configuration info for children
    109  1.2.6.2  nathanw  */
    110  1.2.6.2  nathanw 
    111  1.2.6.2  nathanw static int
    112  1.2.6.2  nathanw footbridge_print(aux, pnp)
    113  1.2.6.2  nathanw 	void *aux;
    114  1.2.6.2  nathanw 	const char *pnp;
    115  1.2.6.2  nathanw {
    116  1.2.6.2  nathanw 	union footbridge_attach_args *fba = aux;
    117  1.2.6.2  nathanw 
    118  1.2.6.2  nathanw 	if (pnp)
    119  1.2.6.9  thorpej 		aprint_normal("%s at %s", fba->fba_name, pnp);
    120  1.2.6.2  nathanw 	if (strcmp(fba->fba_name, "pci") == 0)
    121  1.2.6.9  thorpej 		aprint_normal(" bus %d", fba->fba_pba.pba_bus);
    122  1.2.6.2  nathanw 	return(UNCONF);
    123  1.2.6.2  nathanw }
    124  1.2.6.2  nathanw 
    125  1.2.6.2  nathanw /*
    126  1.2.6.2  nathanw  * int footbridge_match(struct device *parent, struct cfdata *cf, void *aux)
    127  1.2.6.2  nathanw  *
    128  1.2.6.2  nathanw  * Just return ok for this if it is device 0
    129  1.2.6.2  nathanw  */
    130  1.2.6.2  nathanw 
    131  1.2.6.2  nathanw static int
    132  1.2.6.2  nathanw footbridge_match(parent, cf, aux)
    133  1.2.6.2  nathanw 	struct device *parent;
    134  1.2.6.2  nathanw 	struct cfdata *cf;
    135  1.2.6.2  nathanw 	void *aux;
    136  1.2.6.2  nathanw {
    137  1.2.6.2  nathanw 	if (footbridge_found)
    138  1.2.6.2  nathanw 		return(0);
    139  1.2.6.2  nathanw 	return(1);
    140  1.2.6.2  nathanw }
    141  1.2.6.2  nathanw 
    142  1.2.6.2  nathanw 
    143  1.2.6.2  nathanw /*
    144  1.2.6.2  nathanw  * void footbridge_attach(struct device *parent, struct device *dev, void *aux)
    145  1.2.6.2  nathanw  *
    146  1.2.6.2  nathanw  */
    147  1.2.6.2  nathanw 
    148  1.2.6.2  nathanw static void
    149  1.2.6.2  nathanw footbridge_attach(parent, self, aux)
    150  1.2.6.2  nathanw 	struct device *parent;
    151  1.2.6.2  nathanw 	struct device *self;
    152  1.2.6.2  nathanw 	void *aux;
    153  1.2.6.2  nathanw {
    154  1.2.6.2  nathanw 	struct footbridge_softc *sc = (struct footbridge_softc *)self;
    155  1.2.6.2  nathanw 	union footbridge_attach_args fba;
    156  1.2.6.2  nathanw 	int vendor, device, rev;
    157  1.2.6.2  nathanw 
    158  1.2.6.2  nathanw 	/* There can only be 1 footbridge. */
    159  1.2.6.2  nathanw 	footbridge_found = 1;
    160  1.2.6.2  nathanw 
    161  1.2.6.2  nathanw 	clock_sc = sc;
    162  1.2.6.2  nathanw 
    163  1.2.6.2  nathanw 	sc->sc_iot = &footbridge_bs_tag;
    164  1.2.6.2  nathanw 
    165  1.2.6.2  nathanw 	/* Map the Footbridge */
    166  1.2.6.2  nathanw 	if (bus_space_map(sc->sc_iot, DC21285_ARMCSR_VBASE,
    167  1.2.6.2  nathanw 	     DC21285_ARMCSR_VSIZE, 0, &sc->sc_ioh))
    168  1.2.6.7  nathanw 		panic("%s: Cannot map registers", self->dv_xname);
    169  1.2.6.2  nathanw 
    170  1.2.6.2  nathanw 	/* Read the ID to make sure it is what we think it is */
    171  1.2.6.2  nathanw 	vendor = bus_space_read_2(sc->sc_iot, sc->sc_ioh, VENDOR_ID);
    172  1.2.6.2  nathanw 	device = bus_space_read_2(sc->sc_iot, sc->sc_ioh, DEVICE_ID);
    173  1.2.6.2  nathanw 	rev = bus_space_read_1(sc->sc_iot, sc->sc_ioh, REVISION);
    174  1.2.6.2  nathanw 	if (vendor != DC21285_VENDOR_ID && device != DC21285_DEVICE_ID)
    175  1.2.6.7  nathanw 		panic("%s: Unrecognised ID", self->dv_xname);
    176  1.2.6.2  nathanw 
    177  1.2.6.2  nathanw 	printf(": DC21285 rev %d\n", rev);
    178  1.2.6.2  nathanw 
    179  1.2.6.2  nathanw 	/* Disable all interrupts from the footbridge */
    180  1.2.6.2  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, IRQ_ENABLE_CLEAR, 0xffffffff);
    181  1.2.6.2  nathanw 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, FIQ_ENABLE_CLEAR, 0xffffffff);
    182  1.2.6.2  nathanw 
    183  1.2.6.2  nathanw /*	bus_space_write_4(sc->sc_iot, sc->sc_ioh, 0x18, 0x40000000);*/
    184  1.2.6.2  nathanw 
    185  1.2.6.2  nathanw 	/* Install a generic handler to catch a load of system interrupts */
    186  1.2.6.8  nathanw 	sc->sc_serr_ih = footbridge_intr_claim(IRQ_SERR, IPL_HIGH,
    187  1.2.6.2  nathanw 	    "serr", footbridge_intr, sc);
    188  1.2.6.8  nathanw 	sc->sc_sdram_par_ih = footbridge_intr_claim(IRQ_SDRAM_PARITY, IPL_HIGH,
    189  1.2.6.2  nathanw 	    "sdram parity", footbridge_intr, sc);
    190  1.2.6.8  nathanw 	sc->sc_data_par_ih = footbridge_intr_claim(IRQ_DATA_PARITY, IPL_HIGH,
    191  1.2.6.2  nathanw 	    "data parity", footbridge_intr, sc);
    192  1.2.6.8  nathanw 	sc->sc_master_abt_ih = footbridge_intr_claim(IRQ_MASTER_ABORT, IPL_HIGH,
    193  1.2.6.2  nathanw 	    "mast abt", footbridge_intr, sc);
    194  1.2.6.8  nathanw 	sc->sc_target_abt_ih = footbridge_intr_claim(IRQ_TARGET_ABORT, IPL_HIGH,
    195  1.2.6.2  nathanw 	    "targ abt", footbridge_intr, sc);
    196  1.2.6.8  nathanw 	sc->sc_parity_ih = footbridge_intr_claim(IRQ_PARITY, IPL_HIGH,
    197  1.2.6.2  nathanw 	    "parity", footbridge_intr, sc);
    198  1.2.6.8  nathanw 
    199  1.2.6.2  nathanw 	/* Set up the PCI bus tags */
    200  1.2.6.2  nathanw 	footbridge_create_io_bs_tag(&footbridge_pci_io_bs_tag,
    201  1.2.6.2  nathanw 	    (void *)DC21285_PCI_IO_VBASE);
    202  1.2.6.2  nathanw 	footbridge_create_mem_bs_tag(&footbridge_pci_mem_bs_tag,
    203  1.2.6.2  nathanw 	    (void *)DC21285_PCI_MEM_BASE);
    204  1.2.6.2  nathanw 
    205  1.2.6.6  nathanw 	/* calibrate the delay loop */
    206  1.2.6.6  nathanw 	calibrate_delay();
    207  1.2.6.2  nathanw 	/* Attach the PCI bus */
    208  1.2.6.2  nathanw 	fba.fba_pba.pba_busname = "pci";
    209  1.2.6.2  nathanw 	fba.fba_pba.pba_pc = &footbridge_pci_chipset;
    210  1.2.6.2  nathanw 	fba.fba_pba.pba_iot = &footbridge_pci_io_bs_tag;
    211  1.2.6.2  nathanw 	fba.fba_pba.pba_memt = &footbridge_pci_mem_bs_tag;
    212  1.2.6.2  nathanw 	fba.fba_pba.pba_dmat = &footbridge_pci_bus_dma_tag;
    213  1.2.6.2  nathanw 	fba.fba_pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
    214  1.2.6.2  nathanw 	fba.fba_pba.pba_bus = 0;
    215  1.2.6.6  nathanw 	fba.fba_pba.pba_bridgetag = NULL;
    216  1.2.6.2  nathanw 	config_found(self, &fba.fba_pba, footbridge_print);
    217  1.2.6.2  nathanw 
    218  1.2.6.2  nathanw 	/* Attach a time-of-day clock device */
    219  1.2.6.2  nathanw 	fba.fba_tca.ta_name = "todclock";
    220  1.2.6.2  nathanw 	fba.fba_tca.ta_rtc_arg = NULL;
    221  1.2.6.2  nathanw 	fba.fba_tca.ta_rtc_write = NULL;
    222  1.2.6.2  nathanw 	fba.fba_tca.ta_rtc_read = NULL;
    223  1.2.6.2  nathanw 	fba.fba_tca.ta_flags = TODCLOCK_FLAG_FAKE;
    224  1.2.6.2  nathanw 	config_found(self, &fba.fba_tca, footbridge_print);
    225  1.2.6.2  nathanw 
    226  1.2.6.2  nathanw 	/* Attach uart device */
    227  1.2.6.2  nathanw 	fba.fba_fca.fca_name = "fcom";
    228  1.2.6.2  nathanw 	fba.fba_fca.fca_iot = sc->sc_iot;
    229  1.2.6.2  nathanw 	fba.fba_fca.fca_ioh = sc->sc_ioh;
    230  1.2.6.2  nathanw 	fba.fba_fca.fca_rx_irq = IRQ_SERIAL_RX;
    231  1.2.6.2  nathanw 	fba.fba_fca.fca_tx_irq = IRQ_SERIAL_TX;
    232  1.2.6.2  nathanw 	config_found(self, &fba.fba_fca, footbridge_print);
    233  1.2.6.6  nathanw 
    234  1.2.6.2  nathanw 	/* Setup fast SA110 cache clean area */
    235  1.2.6.2  nathanw #ifdef CPU_SA110
    236  1.2.6.2  nathanw 	if (cputype == CPU_ID_SA110)
    237  1.2.6.2  nathanw 		footbridge_sa110_cc_setup();
    238  1.2.6.2  nathanw #endif	/* CPU_SA110 */
    239  1.2.6.2  nathanw 
    240  1.2.6.2  nathanw }
    241  1.2.6.2  nathanw 
    242  1.2.6.2  nathanw /* Generic footbridge interrupt handler */
    243  1.2.6.2  nathanw 
    244  1.2.6.2  nathanw int
    245  1.2.6.2  nathanw footbridge_intr(arg)
    246  1.2.6.2  nathanw 	void *arg;
    247  1.2.6.2  nathanw {
    248  1.2.6.2  nathanw 	struct footbridge_softc *sc = arg;
    249  1.2.6.2  nathanw 	u_int ctrl, intr;
    250  1.2.6.2  nathanw 
    251  1.2.6.2  nathanw 	/*
    252  1.2.6.2  nathanw 	 * Read the footbridge control register and check for
    253  1.2.6.2  nathanw 	 * SERR and parity errors
    254  1.2.6.2  nathanw 	 */
    255  1.2.6.2  nathanw 	ctrl = bus_space_read_4(sc->sc_iot, sc->sc_ioh, SA_CONTROL);
    256  1.2.6.2  nathanw 	intr = ctrl & (RECEIVED_SERR | SA_SDRAM_PARITY_ERROR |
    257  1.2.6.2  nathanw 	    PCI_SDRAM_PARITY_ERROR | DMA_SDRAM_PARITY_ERROR);
    258  1.2.6.2  nathanw 	if (intr) {
    259  1.2.6.2  nathanw 		/* Report the interrupt if reporting is enabled */
    260  1.2.6.2  nathanw 		if (footbridge_intr_report)
    261  1.2.6.2  nathanw 			printf("footbridge_intr: ctrl=%08x\n", intr);
    262  1.2.6.2  nathanw 		/* Clear the interrupt state */
    263  1.2.6.2  nathanw 		bus_space_write_4(sc->sc_iot, sc->sc_ioh, SA_CONTROL,
    264  1.2.6.2  nathanw 		    ctrl | intr);
    265  1.2.6.2  nathanw 	}
    266  1.2.6.2  nathanw 	/*
    267  1.2.6.2  nathanw 	 * Read the PCI status register and check for errors
    268  1.2.6.2  nathanw 	 */
    269  1.2.6.2  nathanw 	ctrl = bus_space_read_4(sc->sc_iot, sc->sc_ioh, PCI_COMMAND_STATUS_REG);
    270  1.2.6.2  nathanw 	intr = ctrl & (PCI_STATUS_PARITY_ERROR | PCI_STATUS_MASTER_TARGET_ABORT
    271  1.2.6.2  nathanw 	    | PCI_STATUS_MASTER_ABORT | PCI_STATUS_SPECIAL_ERROR
    272  1.2.6.2  nathanw 	    | PCI_STATUS_PARITY_DETECT);
    273  1.2.6.2  nathanw 	if (intr) {
    274  1.2.6.2  nathanw 		/* Report the interrupt if reporting is enabled */
    275  1.2.6.2  nathanw 		if (footbridge_intr_report)
    276  1.2.6.2  nathanw 			printf("footbridge_intr: pcistat=%08x\n", intr);
    277  1.2.6.2  nathanw 		/* Clear the interrupt state */
    278  1.2.6.2  nathanw 		bus_space_write_4(sc->sc_iot, sc->sc_ioh,
    279  1.2.6.2  nathanw 		    PCI_COMMAND_STATUS_REG, ctrl | intr);
    280  1.2.6.2  nathanw 	}
    281  1.2.6.2  nathanw 	return(0);
    282  1.2.6.2  nathanw }
    283  1.2.6.2  nathanw 
    284  1.2.6.2  nathanw /* End of footbridge.c */
    285