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