Home | History | Annotate | Line # | Download | only in ixp12x0
ixp12x0.c revision 1.6
      1  1.5  thorpej /*	$NetBSD: ixp12x0.c,v 1.6 2003/02/17 20:51:52 ichiro Exp $ */
      2  1.1   ichiro /*
      3  1.6   ichiro  * Copyright (c) 2002, 2003
      4  1.1   ichiro  *	Ichiro FUKUHARA <ichiro (at) ichiro.org>.
      5  1.1   ichiro  * All rights reserved.
      6  1.1   ichiro  *
      7  1.1   ichiro  * Redistribution and use in source and binary forms, with or without
      8  1.1   ichiro  * modification, are permitted provided that the following conditions
      9  1.1   ichiro  * are met:
     10  1.1   ichiro  * 1. Redistributions of source code must retain the above copyright
     11  1.1   ichiro  *    notice, this list of conditions and the following disclaimer.
     12  1.1   ichiro  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1   ichiro  *    notice, this list of conditions and the following disclaimer in the
     14  1.1   ichiro  *    documentation and/or other materials provided with the distribution.
     15  1.1   ichiro  * 3. All advertising materials mentioning features or use of this software
     16  1.1   ichiro  *    must display the following acknowledgement:
     17  1.1   ichiro  *	This product includes software developed by Ichiro FUKUHARA.
     18  1.1   ichiro  * 4. The name of the company nor the name of the author may be used to
     19  1.1   ichiro  *    endorse or promote products derived from this software without specific
     20  1.1   ichiro  *    prior written permission.
     21  1.1   ichiro  *
     22  1.1   ichiro  * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR
     23  1.1   ichiro  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  1.1   ichiro  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.1   ichiro  * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR
     26  1.1   ichiro  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  1.1   ichiro  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  1.1   ichiro  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  1.1   ichiro  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  1.1   ichiro  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  1.1   ichiro  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  1.1   ichiro  * SUCH DAMAGE.
     33  1.1   ichiro  */
     34  1.1   ichiro 
     35  1.1   ichiro #include <sys/param.h>
     36  1.1   ichiro #include <sys/systm.h>
     37  1.1   ichiro #include <sys/device.h>
     38  1.1   ichiro #include <uvm/uvm.h>
     39  1.1   ichiro 
     40  1.1   ichiro #include <machine/bus.h>
     41  1.1   ichiro 
     42  1.1   ichiro #include <arm/ixp12x0/ixp12x0reg.h>
     43  1.1   ichiro #include <arm/ixp12x0/ixp12x0var.h>
     44  1.1   ichiro #include <arm/ixp12x0/ixp12x0_pcireg.h>
     45  1.1   ichiro 
     46  1.1   ichiro int ixp12x0_pcibus_print(void *, const char *);
     47  1.1   ichiro 
     48  1.1   ichiro static struct ixp12x0_softc *ixp12x0_softc;
     49  1.1   ichiro 
     50  1.1   ichiro void
     51  1.1   ichiro ixp12x0_attach(sc)
     52  1.1   ichiro 	struct ixp12x0_softc *sc;
     53  1.1   ichiro {
     54  1.1   ichiro 	struct pcibus_attach_args pba;
     55  1.1   ichiro 	pcireg_t reg;
     56  1.1   ichiro 
     57  1.1   ichiro 	ixp12x0_softc = sc;
     58  1.1   ichiro 
     59  1.1   ichiro 	printf("\n");
     60  1.1   ichiro 	/*
     61  1.1   ichiro 	 * Subregion for PCI Configuration Spase Registers
     62  1.1   ichiro 	 */
     63  1.6   ichiro 	if (bus_space_subregion(sc->sc_iot, sc->sc_ioh,
     64  1.6   ichiro 		IXP12X0_PCI_VBASE - IXP12X0_IO_VBASE,
     65  1.6   ichiro 		IXP12X0_PCI_SIZE, &sc->sc_pci_ioh))
     66  1.6   ichiro 			panic("%s: unable to subregion PCI registers",
     67  1.6   ichiro 			       sc->sc_dev.dv_xname);
     68  1.6   ichiro 
     69  1.6   ichiro 	if (bus_space_subregion(sc->sc_iot, sc->sc_ioh,
     70  1.6   ichiro 		IXP12X0_PCI_TYPE0_VBASE - IXP12X0_IO_VBASE,
     71  1.6   ichiro 		IXP12X0_PCI_TYPE0_SIZE, &sc->sc_conf0_ioh))
     72  1.6   ichiro 			panic("%s: unable to subregion PCI Configutation 0\n",
     73  1.6   ichiro 			       sc->sc_dev.dv_xname);
     74  1.6   ichiro 
     75  1.6   ichiro 	if (bus_space_subregion(sc->sc_iot, sc->sc_ioh,
     76  1.6   ichiro 		IXP12X0_PCI_TYPE1_VBASE - IXP12X0_IO_VBASE,
     77  1.6   ichiro 		IXP12X0_PCI_TYPE1_SIZE, &sc->sc_conf1_ioh))
     78  1.6   ichiro 			panic("%s: unable to subregion PCI Configutation 1\n",
     79  1.6   ichiro 			       sc->sc_dev.dv_xname);
     80  1.1   ichiro 	/*
     81  1.1   ichiro 	 * PCI bus reset
     82  1.1   ichiro 	 */
     83  1.6   ichiro 	/* disable PCI command */
     84  1.6   ichiro 	bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
     85  1.6   ichiro 		PCI_COMMAND_STATUS_REG, 0xffff0000);
     86  1.2   ichiro 	/* XXX assert PCI reset Mode */
     87  1.1   ichiro 	reg = bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh,
     88  1.1   ichiro 		SA_CONTROL) &~ SA_CONTROL_PNR;
     89  1.1   ichiro 	bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
     90  1.1   ichiro 		SA_CONTROL, reg);
     91  1.1   ichiro 	DELAY(10);
     92  1.1   ichiro 
     93  1.1   ichiro 	/* XXX Disable door bell and outbound interrupt */
     94  1.1   ichiro 	bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
     95  1.1   ichiro 		PCI_CAP_PTR, 0xc);
     96  1.1   ichiro 	/* Disable door bell int to PCI */
     97  1.1   ichiro 	bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
     98  1.2   ichiro 		DBELL_PCI_MASK, 0x0);
     99  1.1   ichiro 	/* Disable door bell int to SA-core */
    100  1.1   ichiro 	bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
    101  1.2   ichiro 		DBELL_SA_MASK, 0x0);
    102  1.1   ichiro 
    103  1.6   ichiro 	/*  We setup a 1:1 memory map of bus<->physical addresses */
    104  1.1   ichiro 	bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
    105  1.6   ichiro 		PCI_ADDR_EXT,
    106  1.6   ichiro 		PCI_ADDR_EXT_PMSA(IXP12X0_PCI_MEM_HWBASE));
    107  1.1   ichiro 
    108  1.2   ichiro 	/* XXX Negate PCI reset */
    109  1.1   ichiro 	reg = bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh,
    110  1.1   ichiro 		SA_CONTROL) | SA_CONTROL_PNR;
    111  1.1   ichiro 	bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
    112  1.1   ichiro 		SA_CONTROL, reg);
    113  1.1   ichiro 	DELAY(10);
    114  1.1   ichiro 	/*
    115  1.1   ichiro 	 * specify window size of memory access and SDRAM.
    116  1.1   ichiro 	 */
    117  1.6   ichiro 	bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh, IXP_PCI_MEM_BAR,
    118  1.6   ichiro 		IXP1200_PCI_MEM_BAR & IXP_PCI_MEM_BAR_MASK);
    119  1.1   ichiro 
    120  1.6   ichiro 	bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh, IXP_PCI_IO_BAR,
    121  1.6   ichiro 		IXP1200_PCI_IO_BAR & IXP_PCI_IO_BAR_MASK);
    122  1.1   ichiro 
    123  1.6   ichiro 	bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh, IXP_PCI_DRAM_BAR,
    124  1.6   ichiro 		IXP1200_PCI_DRAM_BAR & IXP_PCI_DRAM_BAR_MASK);
    125  1.1   ichiro 
    126  1.1   ichiro 	bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
    127  1.1   ichiro 		CSR_BASE_ADDR_MASK, CSR_BASE_ADDR_MASK_1M);
    128  1.1   ichiro 	bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
    129  1.1   ichiro 		DRAM_BASE_ADDR_MASK, DRAM_BASE_ADDR_MASK_256MB);
    130  1.1   ichiro 
    131  1.6   ichiro #ifdef PCI_DEBUG
    132  1.6   ichiro 	printf("IXP_PCI_MEM_BAR = 0x%08x\nIXP_PCI_IO_BAR = 0x%08x\nIXP_PCI_DRAM_BAR = 0x%08x\nPCI_ADDR_EXT = 0x%08x\nCSR_BASE_ADDR_MASK = 0x%08x\nDRAM_BASE_ADDR_MASK = 0x%08x\n",
    133  1.1   ichiro 	bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, IXP_PCI_MEM_BAR),
    134  1.1   ichiro 	bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, IXP_PCI_IO_BAR),
    135  1.1   ichiro 	bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, IXP_PCI_DRAM_BAR),
    136  1.6   ichiro 	bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, PCI_ADDR_EXT),
    137  1.6   ichiro 	bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, CSR_BASE_ADDR_MASK),
    138  1.1   ichiro 	bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, DRAM_BASE_ADDR_MASK));
    139  1.1   ichiro #endif
    140  1.1   ichiro 	/* Initialize complete */
    141  1.1   ichiro 	reg = bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh,
    142  1.1   ichiro 		SA_CONTROL) | 0x1;
    143  1.1   ichiro 	bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
    144  1.1   ichiro 		SA_CONTROL, reg);
    145  1.1   ichiro #if DEBUG
    146  1.1   ichiro 	printf("SA_CONTROL = 0x%08x\n",
    147  1.1   ichiro 		bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, SA_CONTROL));
    148  1.1   ichiro #endif
    149  1.1   ichiro 	/*
    150  1.1   ichiro 	 * Enable bus mastering and I/O,memory access
    151  1.1   ichiro 	 */
    152  1.1   ichiro 	/* host only */
    153  1.1   ichiro 	reg = bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh,
    154  1.1   ichiro 		PCI_COMMAND_STATUS_REG) |
    155  1.1   ichiro 		PCI_COMMAND_IO_ENABLE | PCI_COMMAND_MEM_ENABLE |
    156  1.6   ichiro 		PCI_COMMAND_PARITY_ENABLE | PCI_COMMAND_SERR_ENABLE |
    157  1.1   ichiro 		PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_INVALIDATE_ENABLE;
    158  1.1   ichiro 	bus_space_write_4(sc->sc_iot, sc->sc_pci_ioh,
    159  1.1   ichiro 		PCI_COMMAND_STATUS_REG, reg);
    160  1.6   ichiro #ifdef PCI_DEBUG
    161  1.1   ichiro 	printf("PCI_COMMAND_STATUS_REG = 0x%08x\n",
    162  1.1   ichiro 		bus_space_read_4(sc->sc_iot, sc->sc_pci_ioh, PCI_COMMAND_STATUS_REG));
    163  1.1   ichiro #endif
    164  1.1   ichiro 	/*
    165  1.1   ichiro 	 * Initialize the bus space and DMA tags and the PCI chipset tag.
    166  1.1   ichiro 	 */
    167  1.1   ichiro 	ixp12x0_io_bs_init(&sc->ia_pci_iot, sc);
    168  1.1   ichiro 	ixp12x0_mem_bs_init(&sc->ia_pci_memt, sc);
    169  1.1   ichiro 	ixp12x0_pci_init(&sc->ia_pci_chipset, sc);
    170  1.6   ichiro 
    171  1.6   ichiro 	/*
    172  1.6   ichiro 	 * Initialize the DMA tags.
    173  1.6   ichiro 	 */
    174  1.6   ichiro 	ixp12x0_pci_dma_init(sc);
    175  1.1   ichiro 
    176  1.1   ichiro 	/*
    177  1.1   ichiro 	 * Attach the PCI bus.
    178  1.1   ichiro 	 */
    179  1.1   ichiro 	pba.pba_busname = "pci";
    180  1.1   ichiro 	pba.pba_pc = &sc->ia_pci_chipset;
    181  1.1   ichiro 	pba.pba_iot = &sc->ia_pci_iot;
    182  1.1   ichiro 	pba.pba_memt = &sc->ia_pci_memt;
    183  1.1   ichiro 	pba.pba_dmat = &sc->ia_pci_dmat;
    184  1.1   ichiro 	pba.pba_bus = 0;	/* bus number = 0 */
    185  1.1   ichiro 	pba.pba_intrswiz = 0;	/* XXX */
    186  1.1   ichiro 	pba.pba_intrtag = 0;
    187  1.1   ichiro 	pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED |
    188  1.1   ichiro 		PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
    189  1.1   ichiro 	(void) config_found(&sc->sc_dev, &pba, ixp12x0_pcibus_print);
    190  1.1   ichiro }
    191  1.1   ichiro 
    192  1.1   ichiro int
    193  1.1   ichiro ixp12x0_pcibus_print(void *aux, const char *pnp)
    194  1.1   ichiro {
    195  1.1   ichiro 	struct pcibus_attach_args *pba = aux;
    196  1.1   ichiro 
    197  1.1   ichiro 	if (pnp)
    198  1.5  thorpej 		aprint_normal("%s at %s", pba->pba_busname, pnp);
    199  1.1   ichiro 
    200  1.5  thorpej 	aprint_normal(" bus %d", pba->pba_bus);
    201  1.1   ichiro 
    202  1.1   ichiro 	return (UNCONF);
    203  1.1   ichiro }
    204  1.1   ichiro 
    205  1.1   ichiro /*
    206  1.1   ichiro  * IXP12x0 specific I/O registers mapping table
    207  1.1   ichiro  */
    208  1.1   ichiro static struct pmap_ent	map_tbl_ixp12x0[] = {
    209  1.1   ichiro 	{ "StrongARM System and Peripheral Registers",
    210  1.1   ichiro 	  IXP12X0_SYS_VBASE, IXP12X0_SYS_HWBASE,
    211  1.1   ichiro 	  IXP12X0_SYS_SIZE,
    212  1.1   ichiro 	  VM_PROT_READ|VM_PROT_WRITE,
    213  1.1   ichiro 	  PTE_NOCACHE, },
    214  1.1   ichiro 
    215  1.1   ichiro 	{ "PCI Registers Accessible Through StrongARM Core",
    216  1.1   ichiro 	  IXP12X0_PCI_VBASE, IXP12X0_PCI_HWBASE,
    217  1.1   ichiro 	  IXP12X0_PCI_SIZE,
    218  1.1   ichiro 	  VM_PROT_READ|VM_PROT_WRITE,
    219  1.1   ichiro 	  PTE_NOCACHE, },
    220  1.1   ichiro 
    221  1.1   ichiro 	{ "PCI Registers Accessible Through I/O Cycle Access",
    222  1.1   ichiro 	  IXP12X0_PCI_IO_VBASE, IXP12X0_PCI_IO_HWBASE,
    223  1.1   ichiro 	  IXP12X0_PCI_IO_SIZE,
    224  1.1   ichiro 	  VM_PROT_READ|VM_PROT_WRITE,
    225  1.1   ichiro 	  PTE_NOCACHE, },
    226  1.1   ichiro 
    227  1.1   ichiro 	{ "PCI Registers Accessible Through Memory Cycle Access",
    228  1.4   ichiro 	  IXP12X0_PCI_MEM_VBASE, IXP12X0_PCI_MEM_HWBASE,
    229  1.1   ichiro 	  IXP12X0_PCI_MEM_SIZE,
    230  1.1   ichiro 	  VM_PROT_READ|VM_PROT_WRITE,
    231  1.1   ichiro 	  PTE_NOCACHE, },
    232  1.1   ichiro 
    233  1.1   ichiro 	{ "PCI Type0 Configuration Space",
    234  1.4   ichiro 	  IXP12X0_PCI_TYPE0_VBASE, IXP12X0_PCI_TYPE0_HWBASE,
    235  1.6   ichiro 	  IXP12X0_PCI_TYPE0_SIZE,
    236  1.1   ichiro 	  VM_PROT_READ|VM_PROT_WRITE,
    237  1.1   ichiro 	  PTE_NOCACHE, },
    238  1.1   ichiro 
    239  1.1   ichiro 	{ "PCI Type1 Configuration Space",
    240  1.4   ichiro 	  IXP12X0_PCI_TYPE1_VBASE, IXP12X0_PCI_TYPE1_HWBASE,
    241  1.6   ichiro 	  IXP12X0_PCI_TYPE1_SIZE,
    242  1.1   ichiro 	  VM_PROT_READ|VM_PROT_WRITE,
    243  1.1   ichiro 	  PTE_NOCACHE, },
    244  1.1   ichiro 
    245  1.1   ichiro 	{ NULL, 0, 0, 0, 0, 0 },
    246  1.1   ichiro };
    247  1.1   ichiro 
    248  1.1   ichiro /*
    249  1.1   ichiro  * mapping virtual memories
    250  1.1   ichiro  */
    251  1.1   ichiro void
    252  1.1   ichiro ixp12x0_pmap_chunk_table(vaddr_t l1pt, struct pmap_ent* m)
    253  1.1   ichiro {
    254  1.1   ichiro 	int loop;
    255  1.1   ichiro 
    256  1.1   ichiro 	loop = 0;
    257  1.1   ichiro 	while (m[loop].msg) {
    258  1.1   ichiro 		printf("mapping %s...\n", m[loop].msg);
    259  1.1   ichiro 		pmap_map_chunk(l1pt, m[loop].va, m[loop].pa,
    260  1.1   ichiro 			       m[loop].sz, m[loop].prot, m[loop].cache);
    261  1.1   ichiro 		++loop;
    262  1.1   ichiro 	}
    263  1.1   ichiro }
    264  1.1   ichiro 
    265  1.1   ichiro /*
    266  1.1   ichiro  * mapping I/O registers
    267  1.1   ichiro  */
    268  1.1   ichiro void
    269  1.1   ichiro ixp12x0_pmap_io_reg(vaddr_t l1pt)
    270  1.1   ichiro {
    271  1.1   ichiro 	ixp12x0_pmap_chunk_table(l1pt, map_tbl_ixp12x0);
    272  1.1   ichiro }
    273  1.1   ichiro 
    274  1.1   ichiro void
    275  1.1   ichiro ixp12x0_reset(void)
    276  1.1   ichiro {
    277  1.1   ichiro 	bus_space_write_4(ixp12x0_softc->sc_iot, ixp12x0_softc->sc_pci_ioh,
    278  1.1   ichiro 		IXPPCI_IXP1200_RESET, RESET_FULL);
    279  1.1   ichiro }
    280