ixp12x0_pci.c revision 1.3 1 1.3 ichiro /* $NetBSD: ixp12x0_pci.c,v 1.3 2002/12/08 13:21:44 ichiro Exp $ */
2 1.1 ichiro /*
3 1.1 ichiro * Copyright (c) 2002 The NetBSD Foundation, Inc.
4 1.1 ichiro * All rights reserved.
5 1.1 ichiro *
6 1.1 ichiro * This code is derived from software contributed to The NetBSD Foundation
7 1.1 ichiro * by Ichiro FUKUHARA and Naoto Shimazaki.
8 1.1 ichiro *
9 1.1 ichiro * Redistribution and use in source and binary forms, with or without
10 1.1 ichiro * modification, are permitted provided that the following conditions
11 1.1 ichiro * are met:
12 1.1 ichiro * 1. Redistributions of source code must retain the above copyright
13 1.1 ichiro * notice, this list of conditions and the following disclaimer.
14 1.1 ichiro * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 ichiro * notice, this list of conditions and the following disclaimer in the
16 1.1 ichiro * documentation and/or other materials provided with the distribution.
17 1.1 ichiro * 3. All advertising materials mentioning features or use of this software
18 1.1 ichiro * must display the following acknowledgement:
19 1.1 ichiro * This product includes software developed by the NetBSD
20 1.1 ichiro * Foundation, Inc. and its contributors.
21 1.1 ichiro * 4. Neither the name of The NetBSD Foundation nor the names of its
22 1.1 ichiro * contributors may be used to endorse or promote products derived
23 1.1 ichiro * from this software without specific prior written permission.
24 1.1 ichiro *
25 1.1 ichiro * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26 1.1 ichiro * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.1 ichiro * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.1 ichiro * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29 1.1 ichiro * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1 ichiro * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1 ichiro * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1 ichiro * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1 ichiro * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1 ichiro * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.1 ichiro * POSSIBILITY OF SUCH DAMAGE.
36 1.1 ichiro */
37 1.1 ichiro
38 1.1 ichiro /*
39 1.1 ichiro * PCI configuration support for IXP12x0 Network Processor chip.
40 1.1 ichiro */
41 1.1 ichiro
42 1.1 ichiro #include <sys/param.h>
43 1.1 ichiro #include <sys/systm.h>
44 1.1 ichiro #include <sys/device.h>
45 1.1 ichiro #include <sys/extent.h>
46 1.1 ichiro #include <sys/malloc.h>
47 1.1 ichiro
48 1.1 ichiro #include <uvm/uvm_extern.h>
49 1.1 ichiro
50 1.1 ichiro #include <arm/ixp12x0/ixp12x0reg.h>
51 1.1 ichiro #include <arm/ixp12x0/ixp12x0var.h>
52 1.1 ichiro
53 1.1 ichiro #include <dev/pci/pcireg.h>
54 1.1 ichiro #include <dev/pci/pcivar.h>
55 1.2 thorpej #include <dev/pci/pciconf.h>
56 1.1 ichiro
57 1.1 ichiro #include "opt_pci.h"
58 1.1 ichiro #include "pci.h"
59 1.1 ichiro
60 1.1 ichiro void ixp12x0_pci_attach_hook(struct device *, struct device *,
61 1.1 ichiro struct pcibus_attach_args *);
62 1.1 ichiro int ixp12x0_pci_bus_maxdevs(void *, int);
63 1.1 ichiro pcitag_t ixp12x0_pci_make_tag(void *, int, int, int);
64 1.1 ichiro void ixp12x0_pci_decompose_tag(void *, pcitag_t, int *, int *, int *);
65 1.1 ichiro pcireg_t ixp12x0_pci_conf_read(void *, pcitag_t, int);
66 1.1 ichiro void ixp12x0_pci_conf_write(void *, pcitag_t, int, pcireg_t);
67 1.1 ichiro
68 1.3 ichiro #define MAX_PCI_DEVICES 4
69 1.3 ichiro
70 1.3 ichiro /*
71 1.3 ichiro * IXM1200 PCI configuration Cycles
72 1.3 ichiro * Device Address
73 1.3 ichiro * -------------------------------------
74 1.3 ichiro * 0 IXP1200 0x0800 - 0x08FF
75 1.3 ichiro * 1 i21555 0x1000 - 0x10FF
76 1.3 ichiro * 2 i82559 0x2000 - 0x20FF
77 1.3 ichiro * 3 PMC expansion 0x4000 - 0x40FF
78 1.3 ichiro */
79 1.1 ichiro
80 1.1 ichiro void
81 1.1 ichiro ixp12x0_pci_init(pc, cookie)
82 1.1 ichiro pci_chipset_tag_t pc;
83 1.1 ichiro void *cookie;
84 1.1 ichiro {
85 1.1 ichiro pc->pc_conf_v = cookie;
86 1.1 ichiro pc->pc_attach_hook = ixp12x0_pci_attach_hook;
87 1.1 ichiro pc->pc_bus_maxdevs = ixp12x0_pci_bus_maxdevs;
88 1.1 ichiro pc->pc_make_tag = ixp12x0_pci_make_tag;
89 1.1 ichiro pc->pc_decompose_tag = ixp12x0_pci_decompose_tag;
90 1.1 ichiro pc->pc_conf_read = ixp12x0_pci_conf_read;
91 1.1 ichiro pc->pc_conf_write = ixp12x0_pci_conf_write;
92 1.1 ichiro }
93 1.1 ichiro
94 1.1 ichiro void
95 1.1 ichiro pci_conf_interrupt(pc, a, b, c, d, p)
96 1.1 ichiro pci_chipset_tag_t pc;
97 1.1 ichiro int a, b, c, d, *p;
98 1.1 ichiro {
99 1.1 ichiro /* Nothing */
100 1.1 ichiro }
101 1.1 ichiro
102 1.1 ichiro void
103 1.1 ichiro ixp12x0_pci_attach_hook(parent, self, pba)
104 1.1 ichiro struct device *parent;
105 1.1 ichiro struct device *self;
106 1.1 ichiro struct pcibus_attach_args *pba;
107 1.1 ichiro {
108 1.1 ichiro /* Nothing to do. */
109 1.1 ichiro }
110 1.1 ichiro
111 1.1 ichiro int
112 1.1 ichiro ixp12x0_pci_bus_maxdevs(v, busno)
113 1.1 ichiro void *v;
114 1.1 ichiro int busno;
115 1.1 ichiro {
116 1.1 ichiro return(MAX_PCI_DEVICES);
117 1.1 ichiro }
118 1.1 ichiro
119 1.1 ichiro pcitag_t
120 1.1 ichiro ixp12x0_pci_make_tag(v, bus, device, function)
121 1.1 ichiro void *v;
122 1.1 ichiro int bus, device, function;
123 1.1 ichiro {
124 1.1 ichiro #ifdef PCI_DEBUG
125 1.1 ichiro printf("ixp12x0_pci_make_tag(v=%p, bus=%d, device=%d, function=%d)\n",
126 1.1 ichiro v, bus, device, function);
127 1.1 ichiro #endif
128 1.3 ichiro #ifdef PCI_DEBUG2
129 1.3 ichiro printf("ixp12x0_pci_make_tag return = 0x%x\n",
130 1.3 ichiro ((bus << 16) | (device << 11) | (function << 8)));
131 1.3 ichiro #endif
132 1.1 ichiro return ((bus << 16) | (device << 11) | (function << 8));
133 1.1 ichiro }
134 1.1 ichiro
135 1.1 ichiro void
136 1.1 ichiro ixp12x0_pci_decompose_tag(v, tag, busp, devicep, functionp)
137 1.1 ichiro void *v;
138 1.1 ichiro pcitag_t tag;
139 1.1 ichiro int *busp, *devicep, *functionp;
140 1.1 ichiro {
141 1.1 ichiro #ifdef PCI_DEBUG
142 1.1 ichiro printf("ixp12x0_pci_decompose_tag(v=%p, tag=0x%08lx, bp=%x, dp=%x, fp=%x)\n",
143 1.1 ichiro v, tag, (int)busp, (int)devicep, (int)functionp);
144 1.1 ichiro #endif
145 1.1 ichiro
146 1.1 ichiro if (busp != NULL)
147 1.1 ichiro *busp = (tag >> 16) & 0xff;
148 1.1 ichiro if (devicep != NULL)
149 1.1 ichiro *devicep = (tag >> 11) & 0x1f;
150 1.1 ichiro if (functionp != NULL)
151 1.1 ichiro *functionp = (tag >> 8) & 0x7;
152 1.1 ichiro }
153 1.1 ichiro
154 1.1 ichiro pcireg_t
155 1.1 ichiro ixp12x0_pci_conf_read(v, tag, offset)
156 1.1 ichiro void *v;
157 1.1 ichiro pcitag_t tag;
158 1.1 ichiro int offset;
159 1.1 ichiro {
160 1.1 ichiro int bus, device, function;
161 1.1 ichiro u_int address;
162 1.1 ichiro pcireg_t val;
163 1.1 ichiro
164 1.1 ichiro ixp12x0_pci_decompose_tag(v, tag, &bus, &device, &function);
165 1.1 ichiro
166 1.3 ichiro /* bus == 0 */
167 1.3 ichiro address = IXP12X0_PCI_TYPE0_VBASE |
168 1.3 ichiro ((0x1) << (device)) << 11 | (offset & 0xff); /* XXX */
169 1.1 ichiro
170 1.1 ichiro val = *((unsigned int *)address);
171 1.1 ichiro
172 1.1 ichiro #ifdef PCI_DEBUG
173 1.1 ichiro printf("ixp12x0_pci_conf_read(addr=%08x)(v=%p tag=0x%08lx offset=0x%02x)=0x%08x\n",
174 1.1 ichiro address, v, tag, offset, val);
175 1.1 ichiro #endif
176 1.3 ichiro #ifdef PCI_DEBUG2
177 1.3 ichiro printf("ixp12x0_pci_conf_read(addr=%08x)(bus=0x%08x device=0x%08x function=0x%08x offset=0x%02x)\n", address, bus, device, function, offset);
178 1.3 ichiro #endif
179 1.1 ichiro return(val);
180 1.1 ichiro }
181 1.1 ichiro
182 1.1 ichiro void
183 1.1 ichiro ixp12x0_pci_conf_write(v, tag, offset, val)
184 1.1 ichiro void *v;
185 1.1 ichiro pcitag_t tag;
186 1.1 ichiro int offset;
187 1.1 ichiro pcireg_t val;
188 1.1 ichiro {
189 1.1 ichiro int bus, device, function;
190 1.1 ichiro u_int address;
191 1.1 ichiro
192 1.1 ichiro ixp12x0_pci_decompose_tag(v, tag, &bus, &device, &function);
193 1.1 ichiro
194 1.3 ichiro /* bus == 0 */
195 1.3 ichiro address = IXP12X0_PCI_TYPE0_VBASE |
196 1.3 ichiro ((0x1) << (device)) << 11 | (offset & 0xff); /* XXX */
197 1.3 ichiro
198 1.1 ichiro
199 1.1 ichiro #ifdef PCI_DEBUG
200 1.1 ichiro printf("ixp12x0_pci_conf_write(addr=%08x)(v=%p tag=0x%08lx offset=0x%02x)=0x%08x\n",
201 1.1 ichiro address, v, tag, offset, val);
202 1.1 ichiro #endif
203 1.1 ichiro *((unsigned int *)address) = val;
204 1.1 ichiro }
205