Home | History | Annotate | Line # | Download | only in pci
sbbrz_pci.c revision 1.4.2.1
      1  1.4.2.1    yamt /* $NetBSD: sbbrz_pci.c,v 1.4.2.1 2014/05/22 11:39:58 yamt Exp $ */
      2      1.2    matt 
      3      1.2    matt /*
      4      1.2    matt  * Copyright 2000, 2001
      5      1.2    matt  * Broadcom Corporation. All rights reserved.
      6      1.2    matt  *
      7      1.2    matt  * This software is furnished under license and may be used and copied only
      8      1.2    matt  * in accordance with the following terms and conditions.  Subject to these
      9      1.2    matt  * conditions, you may download, copy, install, use, modify and distribute
     10      1.2    matt  * modified or unmodified copies of this software in source and/or binary
     11      1.2    matt  * form. No title or ownership is transferred hereby.
     12      1.2    matt  *
     13      1.2    matt  * 1) Any source code used, modified or distributed must reproduce and
     14      1.2    matt  *    retain this copyright notice and list of conditions as they appear in
     15      1.2    matt  *    the source file.
     16      1.2    matt  *
     17      1.2    matt  * 2) No right is granted to use any trade name, trademark, or logo of
     18      1.2    matt  *    Broadcom Corporation. Neither the "Broadcom Corporation" name nor any
     19      1.2    matt  *    trademark or logo of Broadcom Corporation may be used to endorse or
     20      1.2    matt  *    promote products derived from this software without the prior written
     21      1.2    matt  *    permission of Broadcom Corporation.
     22      1.2    matt  *
     23      1.2    matt  * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
     24      1.2    matt  *    WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
     25      1.2    matt  *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
     26      1.2    matt  *    NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
     27      1.2    matt  *    FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
     28      1.2    matt  *    LIABLE FOR DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     29      1.2    matt  *    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     30      1.2    matt  *    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
     31      1.2    matt  *    BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     32      1.2    matt  *    WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
     33      1.2    matt  *    OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     34      1.2    matt  */
     35      1.2    matt 
     36      1.2    matt /* from: $NetBSD: apecs_pci.c,v 1.18 2000/06/29 08:58:45 mrg Exp */
     37      1.2    matt 
     38      1.2    matt /*
     39      1.2    matt  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
     40      1.2    matt  * All rights reserved.
     41      1.2    matt  *
     42      1.2    matt  * Author: Chris G. Demetriou
     43      1.2    matt  *
     44      1.2    matt  * Permission to use, copy, modify and distribute this software and
     45      1.2    matt  * its documentation is hereby granted, provided that both the copyright
     46      1.2    matt  * notice and this permission notice appear in all copies of the
     47      1.2    matt  * software, derivative works or modified versions, and any portions
     48      1.2    matt  * thereof, and that both notices appear in supporting documentation.
     49      1.2    matt  *
     50      1.2    matt  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     51      1.2    matt  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     52      1.2    matt  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     53      1.2    matt  *
     54      1.2    matt  * Carnegie Mellon requests users of this software to return to
     55      1.2    matt  *
     56      1.2    matt  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     57      1.2    matt  *  School of Computer Science
     58      1.2    matt  *  Carnegie Mellon University
     59      1.2    matt  *  Pittsburgh PA 15213-3890
     60      1.2    matt  *
     61      1.2    matt  * any improvements or extensions that they make and grant Carnegie the
     62      1.2    matt  * rights to redistribute these changes.
     63      1.2    matt  */
     64      1.2    matt 
     65      1.2    matt #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     66      1.2    matt 
     67  1.4.2.1    yamt __KERNEL_RCSID(0, "$NetBSD: sbbrz_pci.c,v 1.4.2.1 2014/05/22 11:39:58 yamt Exp $");
     68      1.2    matt 
     69      1.2    matt #include <sys/param.h>
     70      1.2    matt #include <sys/systm.h>
     71      1.2    matt #include <sys/kernel.h>
     72      1.2    matt #include <sys/device.h>
     73      1.2    matt #include <uvm/uvm_extern.h>
     74      1.2    matt 
     75      1.2    matt #include <dev/pci/pcireg.h>
     76      1.2    matt #include <dev/pci/pcivar.h>
     77      1.2    matt 
     78      1.4    matt #include <mips/locore.h>
     79      1.2    matt #include <mips/sibyte/include/sb1250_regs.h>
     80      1.2    matt #include <mips/sibyte/include/sb1250_scd.h>
     81      1.2    matt #include <mips/sibyte/include/sb1250_int.h>
     82      1.2    matt #include <mips/sibyte/pci/sbbrzvar.h>
     83      1.2    matt 
     84      1.2    matt void		sbbrz_pci_attach_hook(device_t, device_t,
     85      1.2    matt 		    struct pcibus_attach_args *);
     86      1.2    matt static int	sbbrz_pci_bus_maxdevs(void *, int);
     87      1.2    matt static pcitag_t	sbbrz_pci_make_tag(void *, int, int, int);
     88      1.2    matt static void	sbbrz_pci_decompose_tag(void *, pcitag_t, int *, int *, int *);
     89      1.2    matt 
     90      1.2    matt static pcireg_t	sbbrz_pci_conf_read(void *, pcitag_t, int);
     91      1.2    matt static void	sbbrz_pci_conf_write(void *, pcitag_t, int, pcireg_t);
     92      1.2    matt #ifdef PCI_NETBSD_CONFIGURE
     93      1.2    matt static void	sbbrz_pci_conf_interrupt(void *, int, int, int, int, int *);
     94      1.2    matt #endif
     95      1.2    matt 
     96      1.3  dyoung static int	sbbrz_pci_intr_map(const struct pci_attach_args *,
     97      1.2    matt 		    pci_intr_handle_t *);
     98      1.2    matt static const char *
     99  1.4.2.1    yamt 		sbbrz_pci_intr_string(void *, pci_intr_handle_t, char *, size_t);
    100      1.2    matt static const struct evcnt *
    101      1.2    matt 		sbbrz_pci_intr_evcnt(void *, pci_intr_handle_t);
    102      1.2    matt static void *	sbbrz_pci_intr_establish(void *, pci_intr_handle_t,
    103      1.2    matt 		    int, int (*)(void *), void *);
    104      1.2    matt static void	sbbrz_pci_intr_disestablish(void *, void *);
    105      1.2    matt 
    106      1.2    matt 
    107      1.2    matt void
    108      1.2    matt sbbrz_pci_init(pci_chipset_tag_t pc, void *v)
    109      1.2    matt {
    110      1.2    matt 
    111      1.2    matt 	pc->pc_conf_v = v;
    112      1.2    matt 	pc->pc_attach_hook = sbbrz_pci_attach_hook;
    113      1.2    matt 	pc->pc_bus_maxdevs = sbbrz_pci_bus_maxdevs;
    114      1.2    matt 	pc->pc_make_tag = sbbrz_pci_make_tag;
    115      1.2    matt 	pc->pc_decompose_tag = sbbrz_pci_decompose_tag;
    116      1.2    matt 	pc->pc_conf_read = sbbrz_pci_conf_read;
    117      1.2    matt 	pc->pc_conf_write = sbbrz_pci_conf_write;
    118      1.2    matt 	pc->pc_intr_map = sbbrz_pci_intr_map;
    119      1.2    matt 	pc->pc_intr_string = sbbrz_pci_intr_string;
    120      1.2    matt 	pc->pc_intr_evcnt = sbbrz_pci_intr_evcnt;
    121      1.2    matt 	pc->pc_intr_establish = sbbrz_pci_intr_establish;
    122      1.2    matt 	pc->pc_intr_disestablish = sbbrz_pci_intr_disestablish;
    123      1.2    matt #ifdef PCI_NETBSD_CONFIGURE
    124      1.2    matt 	pc->pc_conf_interrupt = sbbrz_pci_conf_interrupt;
    125      1.2    matt #endif
    126      1.2    matt #ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
    127      1.2    matt 	pc->pc_pciide_compat_intr_establish = sbbrz_pciide_compat_intr_establish;
    128      1.2    matt #endif
    129      1.2    matt }
    130      1.2    matt 
    131      1.2    matt void
    132      1.2    matt sbbrz_pci_attach_hook(device_t parent, device_t self,
    133      1.2    matt     struct pcibus_attach_args *pba)
    134      1.2    matt {
    135      1.2    matt }
    136      1.2    matt 
    137      1.2    matt int
    138      1.2    matt sbbrz_pci_bus_maxdevs(void *cpv, int busno)
    139      1.2    matt {
    140      1.2    matt 	uint64_t regval;
    141      1.2    matt 	int host;
    142      1.2    matt 
    143      1.2    matt 	/* If not the PCI bus directly off the 1250, always up to 32 devs.  */
    144      1.2    matt 	if (busno != 0)
    145      1.2    matt 		return 32;
    146      1.2    matt 
    147      1.2    matt 	/* If the PCI on the 1250, 32 devices if host mode, otherwise only 2. */
    148      1.2    matt 	regval = mips3_ld((void *)MIPS_PHYS_TO_KSEG1(A_SCD_SYSTEM_CFG));
    149      1.2    matt 	host = (regval & M_SYS_PCI_HOST) != 0;
    150      1.2    matt 
    151      1.2    matt 	return (host ? 32 : 2);
    152      1.2    matt }
    153      1.2    matt 
    154      1.2    matt pcitag_t
    155      1.2    matt sbbrz_pci_make_tag(void *cpv, int b, int d, int f)
    156      1.2    matt {
    157      1.2    matt 
    158      1.2    matt 	return (b << 16) | (d << 11) | (f << 8);
    159      1.2    matt }
    160      1.2    matt 
    161      1.2    matt void
    162      1.2    matt sbbrz_pci_decompose_tag(void *cpv, pcitag_t tag,
    163      1.2    matt 	int *bp, int *dp, int *fp)
    164      1.2    matt {
    165      1.2    matt 
    166      1.2    matt 	if (bp != NULL)
    167      1.2    matt 		*bp = (tag >> 16) & 0xff;
    168      1.2    matt 	if (dp != NULL)
    169      1.2    matt 		*dp = (tag >> 11) & 0x1f;
    170      1.2    matt 	if (fp != NULL)
    171      1.2    matt 		*fp = (tag >> 8) & 0x7;
    172      1.2    matt }
    173      1.2    matt 
    174      1.2    matt pcireg_t
    175      1.2    matt sbbrz_pci_conf_read(void *cpv, pcitag_t tag, int offset)
    176      1.2    matt {
    177      1.2    matt 	uint64_t addr;
    178      1.2    matt 
    179      1.2    matt #ifdef DIAGNOSTIC
    180      1.2    matt 	if ((offset & 0x3) != 0)
    181      1.2    matt 		panic ("pci_conf_read: misaligned");
    182      1.2    matt #endif
    183      1.2    matt 
    184      1.2    matt 	addr = A_PHYS_LDTPCI_CFG_MATCH_BITS + tag + offset;
    185      1.2    matt 	addr = MIPS_PHYS_TO_XKPHYS(MIPS3_TLB_ATTR_UNCACHED, addr);
    186      1.2    matt 
    187      1.2    matt 	__asm volatile("sync");
    188      1.2    matt 
    189      1.2    matt 	if (badaddr64(addr, 4) != 0)
    190      1.2    matt 		return 0xffffffff;
    191      1.2    matt 
    192      1.2    matt 	return mips3_lw_a64(addr);
    193      1.2    matt }
    194      1.2    matt 
    195      1.2    matt void
    196      1.2    matt sbbrz_pci_conf_write(void *cpv, pcitag_t tag, int offset, pcireg_t data)
    197      1.2    matt {
    198      1.2    matt 	uint64_t addr;
    199      1.2    matt 
    200      1.2    matt #ifdef DIAGNOSTIC
    201      1.2    matt 	if ((offset & 0x3) != 0)
    202      1.2    matt 		panic ("pci_conf_write: misaligned");
    203      1.2    matt #endif
    204      1.2    matt 
    205      1.2    matt 	addr = A_PHYS_LDTPCI_CFG_MATCH_BITS + tag + offset;
    206      1.2    matt 	addr = MIPS_PHYS_TO_XKPHYS(MIPS3_TLB_ATTR_UNCACHED, addr);
    207      1.2    matt 
    208      1.2    matt 	return mips3_sw_a64(addr, data);
    209      1.2    matt }
    210      1.2    matt 
    211      1.2    matt int
    212      1.3  dyoung sbbrz_pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    213      1.2    matt {
    214      1.2    matt 	int bus, device, func;
    215      1.2    matt 	sbbrz_pci_decompose_tag(NULL, pa->pa_intrtag, &bus, &device, &func);
    216      1.2    matt 	*ihp = 0;
    217      1.2    matt 	if (pa->pa_intrpin == PCI_INTERRUPT_PIN_NONE)
    218      1.2    matt 		return EINVAL;
    219      1.2    matt 	if (bus == 0) {
    220      1.2    matt 		*ihp = K_INT_PCI_INTA
    221      1.2    matt 		    + (((device-5) + pa->pa_intrswiz + pa->pa_intrpin - PCI_INTERRUPT_PIN_A) % 4);
    222      1.2    matt 		return 0;
    223      1.2    matt 	}
    224      1.2    matt 	return EOPNOTSUPP;
    225      1.2    matt }
    226      1.2    matt 
    227      1.2    matt const char *
    228  1.4.2.1    yamt sbbrz_pci_intr_string(void *v, pci_intr_handle_t ih, char *buf, size_t len)
    229      1.2    matt {
    230  1.4.2.1    yamt 	char c;
    231  1.4.2.1    yamt 
    232      1.2    matt 	switch (ih) {
    233  1.4.2.1    yamt 	default:		c = '?'; break;
    234  1.4.2.1    yamt 	case K_INT_PCI_INTA:	c = 'a'; break;
    235  1.4.2.1    yamt 	case K_INT_PCI_INTB:	c = 'b'; break;
    236  1.4.2.1    yamt 	case K_INT_PCI_INTC:	c = 'c'; break;
    237  1.4.2.1    yamt 	case K_INT_PCI_INTD:	c = 'd'; break;
    238      1.2    matt 	}
    239  1.4.2.1    yamt 	snprintf(buf, len, "pci int%c", c);
    240  1.4.2.1    yamt 	return buf;
    241      1.2    matt }
    242      1.2    matt 
    243      1.2    matt const struct evcnt *
    244      1.2    matt sbbrz_pci_intr_evcnt(void *v, pci_intr_handle_t ih)
    245      1.2    matt {
    246      1.2    matt 	return NULL;
    247      1.2    matt }
    248      1.2    matt 
    249      1.2    matt void *
    250      1.2    matt sbbrz_pci_intr_establish(void *v, pci_intr_handle_t ih, int level,
    251      1.2    matt 	int (*handler)(void *), void *arg)
    252      1.2    matt {
    253      1.2    matt 	return cpu_intr_establish(ih, level,
    254      1.2    matt 	    (void (*)(void *, uint32_t, vaddr_t))handler, arg);
    255      1.2    matt }
    256      1.2    matt 
    257      1.2    matt void
    258      1.2    matt sbbrz_pci_intr_disestablish(void *v, void *ih)
    259      1.2    matt {
    260      1.2    matt }
    261