Home | History | Annotate | Line # | Download | only in pci
pciconf_indirect.c revision 1.1.6.1
      1  1.1.6.1  joerg /* $NetBSD: pciconf_indirect.c,v 1.1.6.1 2007/11/02 13:34:43 joerg Exp $ */
      2  1.1.6.1  joerg 
      3  1.1.6.1  joerg /*-
      4  1.1.6.1  joerg  * Copyright (c) 2007 The NetBSD Foundation, Inc.
      5  1.1.6.1  joerg  * All rights reserved.
      6  1.1.6.1  joerg  *
      7  1.1.6.1  joerg  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1.6.1  joerg  * by Tim Rightnour
      9  1.1.6.1  joerg  *
     10  1.1.6.1  joerg  * Redistribution and use in source and binary forms, with or without
     11  1.1.6.1  joerg  * modification, are permitted provided that the following conditions
     12  1.1.6.1  joerg  * are met:
     13  1.1.6.1  joerg  * 1. Redistributions of source code must retain the above copyright
     14  1.1.6.1  joerg  *    notice, this list of conditions and the following disclaimer.
     15  1.1.6.1  joerg  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1.6.1  joerg  *    notice, this list of conditions and the following disclaimer in the
     17  1.1.6.1  joerg  *    documentation and/or other materials provided with the distribution.
     18  1.1.6.1  joerg  * 3. All advertising materials mentioning features or use of this software
     19  1.1.6.1  joerg  *    must display the following acknowledgement:
     20  1.1.6.1  joerg  *        This product includes software developed by the NetBSD
     21  1.1.6.1  joerg  *        Foundation, Inc. and its contributors.
     22  1.1.6.1  joerg  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1.6.1  joerg  *    contributors may be used to endorse or promote products derived
     24  1.1.6.1  joerg  *    from this software without specific prior written permission.
     25  1.1.6.1  joerg  *
     26  1.1.6.1  joerg  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1.6.1  joerg  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1.6.1  joerg  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1.6.1  joerg  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1.6.1  joerg  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1.6.1  joerg  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1.6.1  joerg  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1.6.1  joerg  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1.6.1  joerg  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1.6.1  joerg  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1.6.1  joerg  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1.6.1  joerg  */
     38  1.1.6.1  joerg 
     39  1.1.6.1  joerg /*
     40  1.1.6.1  joerg  * Generic PowerPC functions for talking to an indirect configuration style
     41  1.1.6.1  joerg  * PCI Bridge.
     42  1.1.6.1  joerg  */
     43  1.1.6.1  joerg 
     44  1.1.6.1  joerg #include <sys/cdefs.h>
     45  1.1.6.1  joerg __KERNEL_RCSID(0, "$NetBSD: pciconf_indirect.c,v 1.1.6.1 2007/11/02 13:34:43 joerg Exp $");
     46  1.1.6.1  joerg 
     47  1.1.6.1  joerg #include <sys/types.h>
     48  1.1.6.1  joerg #include <sys/param.h>
     49  1.1.6.1  joerg #include <sys/time.h>
     50  1.1.6.1  joerg #include <sys/systm.h>
     51  1.1.6.1  joerg #include <sys/errno.h>
     52  1.1.6.1  joerg #include <sys/device.h>
     53  1.1.6.1  joerg 
     54  1.1.6.1  joerg #include <uvm/uvm_extern.h>
     55  1.1.6.1  joerg 
     56  1.1.6.1  joerg #define _POWERPC_BUS_DMA_PRIVATE
     57  1.1.6.1  joerg #include <machine/bus.h>
     58  1.1.6.1  joerg #include <machine/intr.h>
     59  1.1.6.1  joerg #include <machine/pio.h>
     60  1.1.6.1  joerg 
     61  1.1.6.1  joerg #if NISA > 0
     62  1.1.6.1  joerg #include <dev/isa/isavar.h>
     63  1.1.6.1  joerg #endif
     64  1.1.6.1  joerg 
     65  1.1.6.1  joerg #include <dev/pci/pcivar.h>
     66  1.1.6.1  joerg #include <dev/pci/pcireg.h>
     67  1.1.6.1  joerg #include <dev/pci/pcidevs.h>
     68  1.1.6.1  joerg 
     69  1.1.6.1  joerg #define	PCI_MODE1_ENABLE	0x80000000UL
     70  1.1.6.1  joerg 
     71  1.1.6.1  joerg void
     72  1.1.6.1  joerg genppc_pci_indirect_attach_hook(struct device *parent, struct device *self,
     73  1.1.6.1  joerg     struct pcibus_attach_args *pba)
     74  1.1.6.1  joerg {
     75  1.1.6.1  joerg 
     76  1.1.6.1  joerg 	if (pba->pba_bus != 0)
     77  1.1.6.1  joerg 		return;
     78  1.1.6.1  joerg 
     79  1.1.6.1  joerg 	printf(": indirect configuration space access");
     80  1.1.6.1  joerg }
     81  1.1.6.1  joerg 
     82  1.1.6.1  joerg pcitag_t
     83  1.1.6.1  joerg genppc_pci_indirect_make_tag(void *v, int bus, int device, int function)
     84  1.1.6.1  joerg {
     85  1.1.6.1  joerg 	pcitag_t tag;
     86  1.1.6.1  joerg 
     87  1.1.6.1  joerg 	if (bus >= 256 || device >= 32 || function >= 8)
     88  1.1.6.1  joerg 		panic("pci_make_tag: bad request");
     89  1.1.6.1  joerg 
     90  1.1.6.1  joerg 	tag = PCI_MODE1_ENABLE |
     91  1.1.6.1  joerg 		    (bus << 16) | (device << 11) | (function << 8);
     92  1.1.6.1  joerg 	return tag;
     93  1.1.6.1  joerg }
     94  1.1.6.1  joerg 
     95  1.1.6.1  joerg void
     96  1.1.6.1  joerg genppc_pci_indirect_decompose_tag(void *v, pcitag_t tag, int *bp, int *dp,
     97  1.1.6.1  joerg     int *fp)
     98  1.1.6.1  joerg {
     99  1.1.6.1  joerg 
    100  1.1.6.1  joerg 	if (bp != NULL)
    101  1.1.6.1  joerg 		*bp = (tag >> 16) & 0xff;
    102  1.1.6.1  joerg 	if (dp != NULL)
    103  1.1.6.1  joerg 		*dp = (tag >> 11) & 0x1f;
    104  1.1.6.1  joerg 	if (fp != NULL)
    105  1.1.6.1  joerg 		*fp = (tag >> 8) & 0x7;
    106  1.1.6.1  joerg 	return;
    107  1.1.6.1  joerg }
    108  1.1.6.1  joerg 
    109  1.1.6.1  joerg pcireg_t
    110  1.1.6.1  joerg genppc_pci_indirect_conf_read(void *v, pcitag_t tag, int reg)
    111  1.1.6.1  joerg {
    112  1.1.6.1  joerg 	pci_chipset_tag_t pc = (pci_chipset_tag_t)v;
    113  1.1.6.1  joerg 	pcireg_t data;
    114  1.1.6.1  joerg 	int s;
    115  1.1.6.1  joerg 
    116  1.1.6.1  joerg 	s = splhigh();
    117  1.1.6.1  joerg 	out32rb(pc->pc_addr, tag | reg);
    118  1.1.6.1  joerg 	data = in32rb(pc->pc_data);
    119  1.1.6.1  joerg 	out32rb(pc->pc_addr, 0);
    120  1.1.6.1  joerg 	splx(s);
    121  1.1.6.1  joerg 
    122  1.1.6.1  joerg 	return data;
    123  1.1.6.1  joerg }
    124  1.1.6.1  joerg 
    125  1.1.6.1  joerg void
    126  1.1.6.1  joerg genppc_pci_indirect_conf_write(void *v, pcitag_t tag, int reg, pcireg_t data)
    127  1.1.6.1  joerg {
    128  1.1.6.1  joerg 	pci_chipset_tag_t pc = (pci_chipset_tag_t)v;
    129  1.1.6.1  joerg 	int s;
    130  1.1.6.1  joerg 
    131  1.1.6.1  joerg 	s = splhigh();
    132  1.1.6.1  joerg 	out32rb(pc->pc_addr, tag | reg);
    133  1.1.6.1  joerg 	out32rb(pc->pc_data, data);
    134  1.1.6.1  joerg 	out32rb(pc->pc_addr, 0);
    135  1.1.6.1  joerg 	splx(s);
    136  1.1.6.1  joerg }
    137