Home | History | Annotate | Line # | Download | only in pci
pciconf_ofmethod.c revision 1.4
      1 /* $NetBSD: pciconf_ofmethod.c,v 1.4 2011/06/18 06:41:43 matt Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2007 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jochen Kunz and Tim Rightnour
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 /*
     33  * Generic PowerPC functions for talking to a PCI Bridge via the RTAS or
     34  * OF methods of the device.
     35  */
     36 
     37 #include <sys/cdefs.h>
     38 __KERNEL_RCSID(0, "$NetBSD: pciconf_ofmethod.c,v 1.4 2011/06/18 06:41:43 matt Exp $");
     39 
     40 #define _POWERPC_BUS_DMA_PRIVATE
     41 
     42 #include <sys/types.h>
     43 #include <sys/param.h>
     44 #include <sys/time.h>
     45 #include <sys/systm.h>
     46 #include <sys/errno.h>
     47 #include <sys/device.h>
     48 #include <sys/bus.h>
     49 #include <sys/intr.h>
     50 
     51 #include <uvm/uvm_extern.h>
     52 
     53 #include <machine/pio.h>
     54 
     55 #include <dev/ofw/openfirm.h>
     56 #include <dev/ofw/ofw_pci.h>
     57 
     58 #if NISA > 0
     59 #include <dev/isa/isavar.h>
     60 #endif
     61 
     62 #include <dev/pci/pcivar.h>
     63 #include <dev/pci/pcireg.h>
     64 #include <dev/pci/pcidevs.h>
     65 
     66 void
     67 genppc_pci_ofmethod_attach_hook(device_t parent, device_t self,
     68     struct pcibus_attach_args *pba)
     69 {
     70 
     71 	if (pba->pba_bus != 0)
     72 		return;
     73 
     74 	aprint_normal(": OFW method configuration space access");
     75 }
     76 
     77 pcitag_t
     78 genppc_pci_ofmethod_make_tag(void *v, int bus, int dev, int func)
     79 {
     80 	return ((bus << OFW_PCI_PHYS_HI_BUSSHIFT) & OFW_PCI_PHYS_HI_BUSMASK) |
     81 	    ((dev << OFW_PCI_PHYS_HI_DEVICESHIFT) & OFW_PCI_PHYS_HI_DEVICEMASK)|
     82 	    ((func << OFW_PCI_PHYS_HI_FUNCTIONSHIFT) &
     83 	    OFW_PCI_PHYS_HI_FUNCTIONMASK);
     84 }
     85 
     86 void
     87 genppc_pci_ofmethod_decompose_tag(void *v, pcitag_t tag, int *bp, int *dp,
     88     int *fp)
     89 {
     90 
     91 	if (bp != NULL)
     92 		*bp = OFW_PCI_PHYS_HI_BUS(tag);
     93 	if (dp != NULL)
     94 		*dp = OFW_PCI_PHYS_HI_DEVICE(tag);
     95 	if (fp != NULL)
     96 		*fp = OFW_PCI_PHYS_HI_FUNCTION(tag);
     97 	return;
     98 }
     99 
    100 pcireg_t
    101 genppc_pci_ofmethod_conf_read(void *v, pcitag_t tag, int reg)
    102 {
    103 	pci_chipset_tag_t pc = (pci_chipset_tag_t)v;
    104 	pcireg_t data;
    105 
    106 	tag &= OFW_PCI_PHYS_HI_BUSMASK | OFW_PCI_PHYS_HI_DEVICEMASK |
    107 	    OFW_PCI_PHYS_HI_FUNCTIONMASK;
    108 	tag |= reg & OFW_PCI_PHYS_HI_REGISTERMASK;
    109 	if (OF_call_method("config-l@", pc->pc_ihandle, 1, 1, tag, &data) < 0)
    110 		return (pcireg_t) -1;
    111 	/*printf("data=0x%x\n", data); */
    112 	return data;
    113 }
    114 
    115 void
    116 genppc_pci_ofmethod_conf_write(void *v, pcitag_t tag, int reg, pcireg_t data)
    117 {
    118 	pci_chipset_tag_t pc = (pci_chipset_tag_t)v;
    119 
    120 	tag &= OFW_PCI_PHYS_HI_BUSMASK | OFW_PCI_PHYS_HI_DEVICEMASK |
    121 	    OFW_PCI_PHYS_HI_FUNCTIONMASK;
    122 	tag |= reg & OFW_PCI_PHYS_HI_REGISTERMASK;
    123 	OF_call_method("config-l!", pc->pc_ihandle, 2, 0, data, tag);
    124 }
    125