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