Home | History | Annotate | Line # | Download | only in xscale
i80321_pci.c revision 1.1.8.2
      1  1.1.8.2  jdolecek /*	$NetBSD: i80321_pci.c,v 1.1.8.2 2002/06/23 17:34:58 jdolecek Exp $	*/
      2  1.1.8.2  jdolecek 
      3  1.1.8.2  jdolecek /*
      4  1.1.8.2  jdolecek  * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
      5  1.1.8.2  jdolecek  * All rights reserved.
      6  1.1.8.2  jdolecek  *
      7  1.1.8.2  jdolecek  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
      8  1.1.8.2  jdolecek  *
      9  1.1.8.2  jdolecek  * Redistribution and use in source and binary forms, with or without
     10  1.1.8.2  jdolecek  * modification, are permitted provided that the following conditions
     11  1.1.8.2  jdolecek  * are met:
     12  1.1.8.2  jdolecek  * 1. Redistributions of source code must retain the above copyright
     13  1.1.8.2  jdolecek  *    notice, this list of conditions and the following disclaimer.
     14  1.1.8.2  jdolecek  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1.8.2  jdolecek  *    notice, this list of conditions and the following disclaimer in the
     16  1.1.8.2  jdolecek  *    documentation and/or other materials provided with the distribution.
     17  1.1.8.2  jdolecek  * 3. All advertising materials mentioning features or use of this software
     18  1.1.8.2  jdolecek  *    must display the following acknowledgement:
     19  1.1.8.2  jdolecek  *	This product includes software developed for the NetBSD Project by
     20  1.1.8.2  jdolecek  *	Wasabi Systems, Inc.
     21  1.1.8.2  jdolecek  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  1.1.8.2  jdolecek  *    or promote products derived from this software without specific prior
     23  1.1.8.2  jdolecek  *    written permission.
     24  1.1.8.2  jdolecek  *
     25  1.1.8.2  jdolecek  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  1.1.8.2  jdolecek  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.1.8.2  jdolecek  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.1.8.2  jdolecek  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  1.1.8.2  jdolecek  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.1.8.2  jdolecek  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.1.8.2  jdolecek  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.1.8.2  jdolecek  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.1.8.2  jdolecek  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.1.8.2  jdolecek  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.1.8.2  jdolecek  * POSSIBILITY OF SUCH DAMAGE.
     36  1.1.8.2  jdolecek  */
     37  1.1.8.2  jdolecek 
     38  1.1.8.2  jdolecek /*
     39  1.1.8.2  jdolecek  * PCI configuration support for i80321 I/O Processor chip.
     40  1.1.8.2  jdolecek  */
     41  1.1.8.2  jdolecek 
     42  1.1.8.2  jdolecek #include <sys/param.h>
     43  1.1.8.2  jdolecek #include <sys/systm.h>
     44  1.1.8.2  jdolecek #include <sys/device.h>
     45  1.1.8.2  jdolecek #include <sys/extent.h>
     46  1.1.8.2  jdolecek #include <sys/malloc.h>
     47  1.1.8.2  jdolecek 
     48  1.1.8.2  jdolecek #include <uvm/uvm_extern.h>
     49  1.1.8.2  jdolecek 
     50  1.1.8.2  jdolecek #include <machine/bus.h>
     51  1.1.8.2  jdolecek 
     52  1.1.8.2  jdolecek #include <arm/xscale/i80321reg.h>
     53  1.1.8.2  jdolecek #include <arm/xscale/i80321var.h>
     54  1.1.8.2  jdolecek 
     55  1.1.8.2  jdolecek #include <dev/pci/ppbreg.h>
     56  1.1.8.2  jdolecek #include <dev/pci/pciconf.h>
     57  1.1.8.2  jdolecek 
     58  1.1.8.2  jdolecek #include "opt_pci.h"
     59  1.1.8.2  jdolecek #include "pci.h"
     60  1.1.8.2  jdolecek 
     61  1.1.8.2  jdolecek void		i80321_pci_attach_hook(struct device *, struct device *,
     62  1.1.8.2  jdolecek 		    struct pcibus_attach_args *);
     63  1.1.8.2  jdolecek int		i80321_pci_bus_maxdevs(void *, int);
     64  1.1.8.2  jdolecek pcitag_t	i80321_pci_make_tag(void *, int, int, int);
     65  1.1.8.2  jdolecek void		i80321_pci_decompose_tag(void *, pcitag_t, int *, int *,
     66  1.1.8.2  jdolecek 		    int *);
     67  1.1.8.2  jdolecek pcireg_t	i80321_pci_conf_read(void *, pcitag_t, int);
     68  1.1.8.2  jdolecek void		i80321_pci_conf_write(void *, pcitag_t, int, pcireg_t);
     69  1.1.8.2  jdolecek 
     70  1.1.8.2  jdolecek #define	PCI_CONF_LOCK(s)	(s) = disable_interrupts(I32_bit)
     71  1.1.8.2  jdolecek #define	PCI_CONF_UNLOCK(s)	restore_interrupts((s))
     72  1.1.8.2  jdolecek 
     73  1.1.8.2  jdolecek void
     74  1.1.8.2  jdolecek i80321_pci_init(pci_chipset_tag_t pc, void *cookie)
     75  1.1.8.2  jdolecek {
     76  1.1.8.2  jdolecek #if NPCI > 0 && defined(PCI_NETBSD_CONFIGURE)
     77  1.1.8.2  jdolecek 	struct i80321_softc *sc = cookie;
     78  1.1.8.2  jdolecek 	struct extent *ioext, *memext;
     79  1.1.8.2  jdolecek 	uint32_t busno;
     80  1.1.8.2  jdolecek #endif
     81  1.1.8.2  jdolecek 
     82  1.1.8.2  jdolecek 	pc->pc_conf_v = cookie;
     83  1.1.8.2  jdolecek 	pc->pc_attach_hook = i80321_pci_attach_hook;
     84  1.1.8.2  jdolecek 	pc->pc_bus_maxdevs = i80321_pci_bus_maxdevs;
     85  1.1.8.2  jdolecek 	pc->pc_make_tag = i80321_pci_make_tag;
     86  1.1.8.2  jdolecek 	pc->pc_decompose_tag = i80321_pci_decompose_tag;
     87  1.1.8.2  jdolecek 	pc->pc_conf_read = i80321_pci_conf_read;
     88  1.1.8.2  jdolecek 	pc->pc_conf_write = i80321_pci_conf_write;
     89  1.1.8.2  jdolecek 
     90  1.1.8.2  jdolecek #if NPCI > 0 && defined(PCI_NETBSD_CONFIGURE)
     91  1.1.8.2  jdolecek 	/*
     92  1.1.8.2  jdolecek 	 * Configure the PCI bus.
     93  1.1.8.2  jdolecek 	 *
     94  1.1.8.2  jdolecek 	 * XXX We need to revisit this.  We only configure the Secondary
     95  1.1.8.2  jdolecek 	 * bus (and its children).  The bus configure code needs changes
     96  1.1.8.2  jdolecek 	 * to support how the busses are arranged on this chip.  We also
     97  1.1.8.2  jdolecek 	 * need to only configure devices in the private device space on
     98  1.1.8.2  jdolecek 	 * the Secondary bus.
     99  1.1.8.2  jdolecek 	 */
    100  1.1.8.2  jdolecek 
    101  1.1.8.2  jdolecek 	busno = bus_space_read_4(sc->sc_st, sc->sc_atu_sh, ATU_PCIXSR);
    102  1.1.8.2  jdolecek 	busno = PCIXSR_BUSNO(busno);
    103  1.1.8.2  jdolecek 	if (busno == 0xff)
    104  1.1.8.2  jdolecek 		busno = 0;
    105  1.1.8.2  jdolecek 
    106  1.1.8.2  jdolecek 	ioext  = extent_create("pciio", sc->sc_ioout_xlate,
    107  1.1.8.2  jdolecek 	    sc->sc_ioout_xlate + VERDE_OUT_XLATE_IO_WIN_SIZE - 1,
    108  1.1.8.2  jdolecek 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
    109  1.1.8.2  jdolecek 	memext = extent_create("pcimem", sc->sc_owin[0].owin_xlate_lo,
    110  1.1.8.2  jdolecek 	    sc->sc_owin[0].owin_xlate_lo + VERDE_OUT_XLATE_MEM_WIN_SIZE - 1,
    111  1.1.8.2  jdolecek 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
    112  1.1.8.2  jdolecek 
    113  1.1.8.2  jdolecek 	printf("%s: configuring PCI bus\n", sc->sc_dev.dv_xname);
    114  1.1.8.2  jdolecek 	pci_configure_bus(pc, ioext, memext, NULL, busno, arm_dcache_align);
    115  1.1.8.2  jdolecek 
    116  1.1.8.2  jdolecek 	extent_destroy(ioext);
    117  1.1.8.2  jdolecek 	extent_destroy(memext);
    118  1.1.8.2  jdolecek #endif
    119  1.1.8.2  jdolecek }
    120  1.1.8.2  jdolecek 
    121  1.1.8.2  jdolecek void
    122  1.1.8.2  jdolecek pci_conf_interrupt(pci_chipset_tag_t pc, int a, int b, int c, int d, int *p)
    123  1.1.8.2  jdolecek {
    124  1.1.8.2  jdolecek }
    125  1.1.8.2  jdolecek 
    126  1.1.8.2  jdolecek void
    127  1.1.8.2  jdolecek i80321_pci_attach_hook(struct device *parent, struct device *self,
    128  1.1.8.2  jdolecek     struct pcibus_attach_args *pba)
    129  1.1.8.2  jdolecek {
    130  1.1.8.2  jdolecek 
    131  1.1.8.2  jdolecek 	/* Nothing to do. */
    132  1.1.8.2  jdolecek }
    133  1.1.8.2  jdolecek 
    134  1.1.8.2  jdolecek int
    135  1.1.8.2  jdolecek i80321_pci_bus_maxdevs(void *v, int busno)
    136  1.1.8.2  jdolecek {
    137  1.1.8.2  jdolecek 
    138  1.1.8.2  jdolecek 	return (32);
    139  1.1.8.2  jdolecek }
    140  1.1.8.2  jdolecek 
    141  1.1.8.2  jdolecek pcitag_t
    142  1.1.8.2  jdolecek i80321_pci_make_tag(void *v, int b, int d, int f)
    143  1.1.8.2  jdolecek {
    144  1.1.8.2  jdolecek 
    145  1.1.8.2  jdolecek 	return ((b << 16) | (d << 11) | (f << 8));
    146  1.1.8.2  jdolecek }
    147  1.1.8.2  jdolecek 
    148  1.1.8.2  jdolecek void
    149  1.1.8.2  jdolecek i80321_pci_decompose_tag(void *v, pcitag_t tag, int *bp, int *dp, int *fp)
    150  1.1.8.2  jdolecek {
    151  1.1.8.2  jdolecek 
    152  1.1.8.2  jdolecek 	if (bp != NULL)
    153  1.1.8.2  jdolecek 		*bp = (tag >> 16) & 0xff;
    154  1.1.8.2  jdolecek 	if (dp != NULL)
    155  1.1.8.2  jdolecek 		*dp = (tag >> 11) & 0x1f;
    156  1.1.8.2  jdolecek 	if (fp != NULL)
    157  1.1.8.2  jdolecek 		*fp = (tag >> 8) & 0x7;
    158  1.1.8.2  jdolecek }
    159  1.1.8.2  jdolecek 
    160  1.1.8.2  jdolecek struct pciconf_state {
    161  1.1.8.2  jdolecek 	uint32_t ps_addr_val;
    162  1.1.8.2  jdolecek 
    163  1.1.8.2  jdolecek 	int ps_b, ps_d, ps_f;
    164  1.1.8.2  jdolecek };
    165  1.1.8.2  jdolecek 
    166  1.1.8.2  jdolecek static int
    167  1.1.8.2  jdolecek i80321_pci_conf_setup(struct i80321_softc *sc, pcitag_t tag, int offset,
    168  1.1.8.2  jdolecek     struct pciconf_state *ps)
    169  1.1.8.2  jdolecek {
    170  1.1.8.2  jdolecek 	uint32_t busno;
    171  1.1.8.2  jdolecek 
    172  1.1.8.2  jdolecek 	i80321_pci_decompose_tag(sc, tag, &ps->ps_b, &ps->ps_d, &ps->ps_f);
    173  1.1.8.2  jdolecek 
    174  1.1.8.2  jdolecek 	busno = bus_space_read_4(sc->sc_st, sc->sc_atu_sh, ATU_PCIXSR);
    175  1.1.8.2  jdolecek 	busno = PCIXSR_BUSNO(busno);
    176  1.1.8.2  jdolecek 	if (busno == 0xff)
    177  1.1.8.2  jdolecek 		busno = 0;
    178  1.1.8.2  jdolecek 
    179  1.1.8.2  jdolecek 	/*
    180  1.1.8.2  jdolecek 	 * If the bus # is the same as our own, then use Type 0 cycles,
    181  1.1.8.2  jdolecek 	 * else use Type 1.
    182  1.1.8.2  jdolecek 	 *
    183  1.1.8.2  jdolecek 	 * XXX We should filter out all non-private devices here!
    184  1.1.8.2  jdolecek 	 * XXX How does private space interact with PCI-PCI bridges?
    185  1.1.8.2  jdolecek 	 */
    186  1.1.8.2  jdolecek 	if (ps->ps_b == busno) {
    187  1.1.8.2  jdolecek 		if (ps->ps_d > (31 - 16))
    188  1.1.8.2  jdolecek 			return (1);
    189  1.1.8.2  jdolecek 		ps->ps_addr_val = (1U << (ps->ps_d + 16)) | (ps->ps_f << 8) |
    190  1.1.8.2  jdolecek 		    offset;
    191  1.1.8.2  jdolecek 	} else {
    192  1.1.8.2  jdolecek 		/* The tag is already in the correct format. */
    193  1.1.8.2  jdolecek 		ps->ps_addr_val = tag | offset | 1;
    194  1.1.8.2  jdolecek 	}
    195  1.1.8.2  jdolecek 
    196  1.1.8.2  jdolecek 	return (0);
    197  1.1.8.2  jdolecek }
    198  1.1.8.2  jdolecek 
    199  1.1.8.2  jdolecek pcireg_t
    200  1.1.8.2  jdolecek i80321_pci_conf_read(void *v, pcitag_t tag, int offset)
    201  1.1.8.2  jdolecek {
    202  1.1.8.2  jdolecek 	struct i80321_softc *sc = v;
    203  1.1.8.2  jdolecek 	struct pciconf_state ps;
    204  1.1.8.2  jdolecek 	vaddr_t va;
    205  1.1.8.2  jdolecek 	uint32_t isr;
    206  1.1.8.2  jdolecek 	pcireg_t rv;
    207  1.1.8.2  jdolecek 	u_int s;
    208  1.1.8.2  jdolecek 
    209  1.1.8.2  jdolecek 	if (i80321_pci_conf_setup(sc, tag, offset, &ps))
    210  1.1.8.2  jdolecek 		return ((pcireg_t) -1);
    211  1.1.8.2  jdolecek 
    212  1.1.8.2  jdolecek 	PCI_CONF_LOCK(s);
    213  1.1.8.2  jdolecek 
    214  1.1.8.2  jdolecek 	bus_space_write_4(sc->sc_st, sc->sc_atu_sh, ATU_OCCAR,
    215  1.1.8.2  jdolecek 	    ps.ps_addr_val);
    216  1.1.8.2  jdolecek 
    217  1.1.8.2  jdolecek 	va = (vaddr_t) bus_space_vaddr(sc->sc_st, sc->sc_atu_sh);
    218  1.1.8.2  jdolecek 	if (badaddr_read((void *) (va + ATU_OCCDR), sizeof(rv), &rv)) {
    219  1.1.8.2  jdolecek 		isr = bus_space_read_4(sc->sc_st, sc->sc_atu_sh, ATU_ATUISR);
    220  1.1.8.2  jdolecek 		bus_space_write_4(sc->sc_st, sc->sc_atu_sh, ATU_ATUISR,
    221  1.1.8.2  jdolecek 		    isr & (ATUISR_P_SERR_DET|ATUISR_PMA|ATUISR_PTAM|
    222  1.1.8.2  jdolecek 			   ATUISR_PTAT|ATUISR_PMPE));
    223  1.1.8.2  jdolecek #if 0
    224  1.1.8.2  jdolecek 		printf("conf_read: %d/%d/%d bad address\n",
    225  1.1.8.2  jdolecek 		    ps.ps_b, ps.ps_d, ps.ps_f);
    226  1.1.8.2  jdolecek #endif
    227  1.1.8.2  jdolecek 		rv = (pcireg_t) -1;
    228  1.1.8.2  jdolecek 	}
    229  1.1.8.2  jdolecek 
    230  1.1.8.2  jdolecek 	PCI_CONF_UNLOCK(s);
    231  1.1.8.2  jdolecek 
    232  1.1.8.2  jdolecek 	return (rv);
    233  1.1.8.2  jdolecek }
    234  1.1.8.2  jdolecek 
    235  1.1.8.2  jdolecek void
    236  1.1.8.2  jdolecek i80321_pci_conf_write(void *v, pcitag_t tag, int offset, pcireg_t val)
    237  1.1.8.2  jdolecek {
    238  1.1.8.2  jdolecek 	struct i80321_softc *sc = v;
    239  1.1.8.2  jdolecek 	struct pciconf_state ps;
    240  1.1.8.2  jdolecek 	u_int s;
    241  1.1.8.2  jdolecek 
    242  1.1.8.2  jdolecek 	if (i80321_pci_conf_setup(sc, tag, offset, &ps))
    243  1.1.8.2  jdolecek 		return;
    244  1.1.8.2  jdolecek 
    245  1.1.8.2  jdolecek 	PCI_CONF_LOCK(s);
    246  1.1.8.2  jdolecek 
    247  1.1.8.2  jdolecek 	bus_space_write_4(sc->sc_st, sc->sc_atu_sh, ATU_OCCAR,
    248  1.1.8.2  jdolecek 	    ps.ps_addr_val);
    249  1.1.8.2  jdolecek 	bus_space_write_4(sc->sc_st, sc->sc_atu_sh, ATU_OCCDR, val);
    250  1.1.8.2  jdolecek 
    251  1.1.8.2  jdolecek 	PCI_CONF_UNLOCK(s);
    252  1.1.8.2  jdolecek }
    253