xref: /netbsd-src/sys/arch/powerpc/pci/pciconf_ofmethod.c (revision 8b0f9554ff8762542c4defc4f70e1eb76fb508fa)
1 /* $NetBSD: pciconf_ofmethod.c,v 1.1 2007/10/25 16:55:51 garbled 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  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 /*
40  * Generic PowerPC functions for talking to a PCI Bridge via the RTAS or
41  * OF methods of the device.
42  */
43 
44 #include <sys/cdefs.h>
45 __KERNEL_RCSID(0, "$NetBSD: pciconf_ofmethod.c,v 1.1 2007/10/25 16:55:51 garbled Exp $");
46 
47 #include <sys/types.h>
48 #include <sys/param.h>
49 #include <sys/time.h>
50 #include <sys/systm.h>
51 #include <sys/errno.h>
52 #include <sys/device.h>
53 
54 #include <uvm/uvm_extern.h>
55 
56 #define _POWERPC_BUS_DMA_PRIVATE
57 #include <machine/bus.h>
58 #include <machine/intr.h>
59 #include <machine/pio.h>
60 #include <dev/ofw/openfirm.h>
61 #include <dev/ofw/ofw_pci.h>
62 
63 #if NISA > 0
64 #include <dev/isa/isavar.h>
65 #endif
66 
67 #include <dev/pci/pcivar.h>
68 #include <dev/pci/pcireg.h>
69 #include <dev/pci/pcidevs.h>
70 
71 void
72 genppc_pci_ofmethod_attach_hook(struct device *parent, struct device *self,
73     struct pcibus_attach_args *pba)
74 {
75 
76 	if (pba->pba_bus != 0)
77 		return;
78 
79 	aprint_normal(": OFW method configuration space access");
80 }
81 
82 pcitag_t
83 genppc_pci_ofmethod_make_tag(void *v, int bus, int dev, int func)
84 {
85 	return ((bus << OFW_PCI_PHYS_HI_BUSSHIFT) & OFW_PCI_PHYS_HI_BUSMASK) |
86 	    ((dev << OFW_PCI_PHYS_HI_DEVICESHIFT) & OFW_PCI_PHYS_HI_DEVICEMASK)|
87 	    ((func << OFW_PCI_PHYS_HI_FUNCTIONSHIFT) &
88 	    OFW_PCI_PHYS_HI_FUNCTIONMASK);
89 }
90 
91 void
92 genppc_pci_ofmethod_decompose_tag(void *v, pcitag_t tag, int *bp, int *dp,
93     int *fp)
94 {
95 
96 	if (bp != NULL)
97 		*bp = OFW_PCI_PHYS_HI_BUS(tag);
98 	if (dp != NULL)
99 		*dp = OFW_PCI_PHYS_HI_DEVICE(tag);
100 	if (fp != NULL)
101 		*fp = OFW_PCI_PHYS_HI_FUNCTION(tag);
102 	return;
103 }
104 
105 pcireg_t
106 genppc_pci_ofmethod_conf_read(void *v, pcitag_t tag, int reg)
107 {
108 	pci_chipset_tag_t pc = (pci_chipset_tag_t)v;
109 	pcireg_t data;
110 
111 	tag &= OFW_PCI_PHYS_HI_BUSMASK | OFW_PCI_PHYS_HI_DEVICEMASK |
112 	    OFW_PCI_PHYS_HI_FUNCTIONMASK;
113 	tag |= reg & OFW_PCI_PHYS_HI_REGISTERMASK;
114 	if (OF_call_method("config-l@", pc->pc_ihandle, 1, 1, tag, &data) < 0)
115 		return (pcireg_t) -1;
116 	/*printf("data=0x%x\n", data); */
117 	return data;
118 }
119 
120 void
121 genppc_pci_ofmethod_conf_write(void *v, pcitag_t tag, int reg, pcireg_t data)
122 {
123 	pci_chipset_tag_t pc = (pci_chipset_tag_t)v;
124 
125 	tag &= OFW_PCI_PHYS_HI_BUSMASK | OFW_PCI_PHYS_HI_DEVICEMASK |
126 	    OFW_PCI_PHYS_HI_FUNCTIONMASK;
127 	tag |= reg & OFW_PCI_PHYS_HI_REGISTERMASK;
128 	OF_call_method("config-l!", pc->pc_ihandle, 2, 0, data, tag);
129 }
130