pciconf_indirect.c revision 1.1.2.2 1 /* $NetBSD: pciconf_indirect.c,v 1.1.2.2 2007/05/06 05:11:42 macallan 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 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 an indirect configuration style
41 * PCI Bridge.
42 */
43
44 #include <sys/cdefs.h>
45 __KERNEL_RCSID(0, "$NetBSD: pciconf_indirect.c,v 1.1.2.2 2007/05/06 05:11:42 macallan 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 #ifdef prep
61 #include <machine/platform.h>
62 #endif
63
64 #if NISA > 0
65 #include <dev/isa/isavar.h>
66 #endif
67
68 #include <dev/pci/pcivar.h>
69 #include <dev/pci/pcireg.h>
70 #include <dev/pci/pcidevs.h>
71
72 #define PCI_MODE1_ENABLE 0x80000000UL
73
74 void genppc_pci_indirect_attach_hook(struct device *, struct device *,
75 struct pcibus_attach_args *);
76 pcitag_t genppc_pci_indirect_make_tag(void *, int, int, int);
77 pcireg_t genppc_pci_indirect_conf_read(void *, pcitag_t, int);
78 void genppc_pci_indirect_conf_write(void *, pcitag_t, int, pcireg_t);
79 void genppc_pci_indirect_decompose_tag(void *, pcitag_t, int *, int *, int *);
80
81 void
82 genppc_pci_indirect_attach_hook(struct device *parent, struct device *self,
83 struct pcibus_attach_args *pba)
84 {
85
86 if (pba->pba_bus != 0)
87 return;
88
89 printf(": indirect configuration space access");
90 }
91
92 pcitag_t
93 genppc_pci_indirect_make_tag(void *v, int bus, int device, int function)
94 {
95 pcitag_t tag;
96
97 if (bus >= 256 || device >= 32 || function >= 8)
98 panic("pci_make_tag: bad request");
99
100 tag = PCI_MODE1_ENABLE |
101 (bus << 16) | (device << 11) | (function << 8);
102 return tag;
103 }
104
105 void
106 genppc_pci_indirect_decompose_tag(void *v, pcitag_t tag, int *bp, int *dp,
107 int *fp)
108 {
109
110 if (bp != NULL)
111 *bp = (tag >> 16) & 0xff;
112 if (dp != NULL)
113 *dp = (tag >> 11) & 0x1f;
114 if (fp != NULL)
115 *fp = (tag >> 8) & 0x7;
116 return;
117 }
118
119 pcireg_t
120 genppc_pci_indirect_conf_read(void *v, pcitag_t tag, int reg)
121 {
122 pci_chipset_tag_t pc = (pci_chipset_tag_t)v;
123 pcireg_t data;
124 int s;
125
126 s = splhigh();
127 out32rb(pc->pc_addr, tag | reg);
128 data = in32rb(pc->pc_data);
129 out32rb(pc->pc_addr, 0);
130 splx(s);
131
132 return data;
133 }
134
135 void
136 genppc_pci_indirect_conf_write(void *v, pcitag_t tag, int reg, pcireg_t data)
137 {
138 pci_chipset_tag_t pc = (pci_chipset_tag_t)v;
139 int s;
140
141 s = splhigh();
142 out32rb(pc->pc_addr, tag | reg);
143 out32rb(pc->pc_data, data);
144 out32rb(pc->pc_addr, 0);
145 splx(s);
146 }
147