xref: /netbsd/sys/arch/powerpc/pci/pciconf_ofmethod.c (revision 6550d01e)
1 /* $NetBSD: pciconf_ofmethod.c,v 1.2 2008/04/28 20:23:32 martin 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.2 2008/04/28 20:23:32 martin Exp $");
39 
40 #include <sys/types.h>
41 #include <sys/param.h>
42 #include <sys/time.h>
43 #include <sys/systm.h>
44 #include <sys/errno.h>
45 #include <sys/device.h>
46 
47 #include <uvm/uvm_extern.h>
48 
49 #define _POWERPC_BUS_DMA_PRIVATE
50 #include <machine/bus.h>
51 #include <machine/intr.h>
52 #include <machine/pio.h>
53 #include <dev/ofw/openfirm.h>
54 #include <dev/ofw/ofw_pci.h>
55 
56 #if NISA > 0
57 #include <dev/isa/isavar.h>
58 #endif
59 
60 #include <dev/pci/pcivar.h>
61 #include <dev/pci/pcireg.h>
62 #include <dev/pci/pcidevs.h>
63 
64 void
65 genppc_pci_ofmethod_attach_hook(struct device *parent, struct device *self,
66     struct pcibus_attach_args *pba)
67 {
68 
69 	if (pba->pba_bus != 0)
70 		return;
71 
72 	aprint_normal(": OFW method configuration space access");
73 }
74 
75 pcitag_t
76 genppc_pci_ofmethod_make_tag(void *v, int bus, int dev, int func)
77 {
78 	return ((bus << OFW_PCI_PHYS_HI_BUSSHIFT) & OFW_PCI_PHYS_HI_BUSMASK) |
79 	    ((dev << OFW_PCI_PHYS_HI_DEVICESHIFT) & OFW_PCI_PHYS_HI_DEVICEMASK)|
80 	    ((func << OFW_PCI_PHYS_HI_FUNCTIONSHIFT) &
81 	    OFW_PCI_PHYS_HI_FUNCTIONMASK);
82 }
83 
84 void
85 genppc_pci_ofmethod_decompose_tag(void *v, pcitag_t tag, int *bp, int *dp,
86     int *fp)
87 {
88 
89 	if (bp != NULL)
90 		*bp = OFW_PCI_PHYS_HI_BUS(tag);
91 	if (dp != NULL)
92 		*dp = OFW_PCI_PHYS_HI_DEVICE(tag);
93 	if (fp != NULL)
94 		*fp = OFW_PCI_PHYS_HI_FUNCTION(tag);
95 	return;
96 }
97 
98 pcireg_t
99 genppc_pci_ofmethod_conf_read(void *v, pcitag_t tag, int reg)
100 {
101 	pci_chipset_tag_t pc = (pci_chipset_tag_t)v;
102 	pcireg_t data;
103 
104 	tag &= OFW_PCI_PHYS_HI_BUSMASK | OFW_PCI_PHYS_HI_DEVICEMASK |
105 	    OFW_PCI_PHYS_HI_FUNCTIONMASK;
106 	tag |= reg & OFW_PCI_PHYS_HI_REGISTERMASK;
107 	if (OF_call_method("config-l@", pc->pc_ihandle, 1, 1, tag, &data) < 0)
108 		return (pcireg_t) -1;
109 	/*printf("data=0x%x\n", data); */
110 	return data;
111 }
112 
113 void
114 genppc_pci_ofmethod_conf_write(void *v, pcitag_t tag, int reg, pcireg_t data)
115 {
116 	pci_chipset_tag_t pc = (pci_chipset_tag_t)v;
117 
118 	tag &= OFW_PCI_PHYS_HI_BUSMASK | OFW_PCI_PHYS_HI_DEVICEMASK |
119 	    OFW_PCI_PHYS_HI_FUNCTIONMASK;
120 	tag |= reg & OFW_PCI_PHYS_HI_REGISTERMASK;
121 	OF_call_method("config-l!", pc->pc_ihandle, 2, 0, data, tag);
122 }
123