irongate_pci.c revision 1.1.4.2 1 1.1.4.2 minoura /* $NetBSD: irongate_pci.c,v 1.1.4.2 2000/06/22 16:58:39 minoura Exp $ */
2 1.1.4.2 minoura
3 1.1.4.2 minoura /*-
4 1.1.4.2 minoura * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 1.1.4.2 minoura * All rights reserved.
6 1.1.4.2 minoura *
7 1.1.4.2 minoura * This code is derived from software contributed to The NetBSD Foundation
8 1.1.4.2 minoura * by Jason R. Thorpe.
9 1.1.4.2 minoura *
10 1.1.4.2 minoura * Redistribution and use in source and binary forms, with or without
11 1.1.4.2 minoura * modification, are permitted provided that the following conditions
12 1.1.4.2 minoura * are met:
13 1.1.4.2 minoura * 1. Redistributions of source code must retain the above copyright
14 1.1.4.2 minoura * notice, this list of conditions and the following disclaimer.
15 1.1.4.2 minoura * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.4.2 minoura * notice, this list of conditions and the following disclaimer in the
17 1.1.4.2 minoura * documentation and/or other materials provided with the distribution.
18 1.1.4.2 minoura * 3. All advertising materials mentioning features or use of this software
19 1.1.4.2 minoura * must display the following acknowledgement:
20 1.1.4.2 minoura * This product includes software developed by the NetBSD
21 1.1.4.2 minoura * Foundation, Inc. and its contributors.
22 1.1.4.2 minoura * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.4.2 minoura * contributors may be used to endorse or promote products derived
24 1.1.4.2 minoura * from this software without specific prior written permission.
25 1.1.4.2 minoura *
26 1.1.4.2 minoura * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.4.2 minoura * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.4.2 minoura * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.4.2 minoura * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.4.2 minoura * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.4.2 minoura * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.4.2 minoura * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.4.2 minoura * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.4.2 minoura * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.4.2 minoura * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.4.2 minoura * POSSIBILITY OF SUCH DAMAGE.
37 1.1.4.2 minoura */
38 1.1.4.2 minoura
39 1.1.4.2 minoura /*
40 1.1.4.2 minoura * PCI Configuration Space support for the AMD 751 (``Irongate'') core logic
41 1.1.4.2 minoura * chipset.
42 1.1.4.2 minoura */
43 1.1.4.2 minoura
44 1.1.4.2 minoura #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
45 1.1.4.2 minoura
46 1.1.4.2 minoura __KERNEL_RCSID(0, "$NetBSD: irongate_pci.c,v 1.1.4.2 2000/06/22 16:58:39 minoura Exp $");
47 1.1.4.2 minoura
48 1.1.4.2 minoura #include <sys/param.h>
49 1.1.4.2 minoura #include <sys/systm.h>
50 1.1.4.2 minoura #include <sys/kernel.h>
51 1.1.4.2 minoura #include <sys/device.h>
52 1.1.4.2 minoura #include <vm/vm.h>
53 1.1.4.2 minoura
54 1.1.4.2 minoura #include <dev/pci/pcireg.h>
55 1.1.4.2 minoura #include <dev/pci/pcivar.h>
56 1.1.4.2 minoura #include <alpha/pci/irongatereg.h>
57 1.1.4.2 minoura #include <alpha/pci/irongatevar.h>
58 1.1.4.2 minoura
59 1.1.4.2 minoura void irongate_attach_hook __P((struct device *, struct device *,
60 1.1.4.2 minoura struct pcibus_attach_args *));
61 1.1.4.2 minoura int irongate_bus_maxdevs __P((void *, int));
62 1.1.4.2 minoura pcitag_t irongate_make_tag __P((void *, int, int, int));
63 1.1.4.2 minoura void irongate_decompose_tag __P((void *, pcitag_t, int *, int *,
64 1.1.4.2 minoura int *));
65 1.1.4.2 minoura pcireg_t irongate_conf_read __P((void *, pcitag_t, int));
66 1.1.4.2 minoura void irongate_conf_write __P((void *, pcitag_t, int, pcireg_t));
67 1.1.4.2 minoura
68 1.1.4.2 minoura /* AMD 751 systems are always single-processor, so this is easy. */
69 1.1.4.2 minoura #define PCI_CONF_LOCK(s) (s) = splhigh()
70 1.1.4.2 minoura #define PCI_CONF_UNLOCK(s) splx((s))
71 1.1.4.2 minoura
72 1.1.4.2 minoura #define PCI_CONF_ADDR (IRONGATE_IO_BASE|IRONGATE_CONFADDR)
73 1.1.4.2 minoura #define PCI_CONF_DATA (IRONGATE_IO_BASE|IRONGATE_CONFDATA)
74 1.1.4.2 minoura
75 1.1.4.2 minoura #define REGVAL(r) (*(__volatile u_int32_t *)ALPHA_PHYS_TO_K0SEG(r))
76 1.1.4.2 minoura
77 1.1.4.2 minoura void
78 1.1.4.2 minoura irongate_pci_init(pci_chipset_tag_t pc, void *v)
79 1.1.4.2 minoura {
80 1.1.4.2 minoura
81 1.1.4.2 minoura pc->pc_conf_v = v;
82 1.1.4.2 minoura pc->pc_attach_hook = irongate_attach_hook;
83 1.1.4.2 minoura pc->pc_bus_maxdevs = irongate_bus_maxdevs;
84 1.1.4.2 minoura pc->pc_make_tag = irongate_make_tag;
85 1.1.4.2 minoura pc->pc_decompose_tag = irongate_decompose_tag;
86 1.1.4.2 minoura pc->pc_conf_read = irongate_conf_read;
87 1.1.4.2 minoura pc->pc_conf_write = irongate_conf_write;
88 1.1.4.2 minoura }
89 1.1.4.2 minoura
90 1.1.4.2 minoura void
91 1.1.4.2 minoura irongate_attach_hook(struct device *parent, struct device *self,
92 1.1.4.2 minoura struct pcibus_attach_args *pba)
93 1.1.4.2 minoura {
94 1.1.4.2 minoura }
95 1.1.4.2 minoura
96 1.1.4.2 minoura int
97 1.1.4.2 minoura irongate_bus_maxdevs(void *ipv, int busno)
98 1.1.4.2 minoura {
99 1.1.4.2 minoura
100 1.1.4.2 minoura return 32;
101 1.1.4.2 minoura }
102 1.1.4.2 minoura
103 1.1.4.2 minoura pcitag_t
104 1.1.4.2 minoura irongate_make_tag(void *ipv, int b, int d, int f)
105 1.1.4.2 minoura {
106 1.1.4.2 minoura
107 1.1.4.2 minoura return (b << 16) | (d << 11) | (f << 8);
108 1.1.4.2 minoura }
109 1.1.4.2 minoura
110 1.1.4.2 minoura void
111 1.1.4.2 minoura irongate_decompose_tag(void *ipv, pcitag_t tag, int *bp, int *dp, int *fp)
112 1.1.4.2 minoura {
113 1.1.4.2 minoura
114 1.1.4.2 minoura if (bp != NULL)
115 1.1.4.2 minoura *bp = (tag >> 16) & 0xff;
116 1.1.4.2 minoura if (dp != NULL)
117 1.1.4.2 minoura *dp = (tag >> 11) & 0x1f;
118 1.1.4.2 minoura if (fp != NULL)
119 1.1.4.2 minoura *fp = (tag >> 8) & 0x7;
120 1.1.4.2 minoura }
121 1.1.4.2 minoura
122 1.1.4.2 minoura pcireg_t
123 1.1.4.2 minoura irongate_conf_read(void *ipv, pcitag_t tag, int offset)
124 1.1.4.2 minoura {
125 1.1.4.2 minoura int d;
126 1.1.4.2 minoura
127 1.1.4.2 minoura /*
128 1.1.4.2 minoura * The AMD 751 appears in PCI configuration space, but
129 1.1.4.2 minoura * that is ... counter-intuitive to the way we normally
130 1.1.4.2 minoura * attach PCI-Host bridges on the Alpha. So, filter out
131 1.1.4.2 minoura * the AMD 751 device here. We provide a private entry
132 1.1.4.2 minoura * point for getting at it from machdep code.
133 1.1.4.2 minoura */
134 1.1.4.2 minoura irongate_decompose_tag(ipv, tag, NULL, &d, NULL);
135 1.1.4.2 minoura if (d == IRONGATE_PCIHOST_DEV)
136 1.1.4.2 minoura return ((pcireg_t) -1);
137 1.1.4.2 minoura
138 1.1.4.2 minoura return (irongate_conf_read0(ipv, tag, offset));
139 1.1.4.2 minoura }
140 1.1.4.2 minoura
141 1.1.4.2 minoura pcireg_t
142 1.1.4.2 minoura irongate_conf_read0(void *ipv, pcitag_t tag, int offset)
143 1.1.4.2 minoura {
144 1.1.4.2 minoura pcireg_t data;
145 1.1.4.2 minoura int s;
146 1.1.4.2 minoura
147 1.1.4.2 minoura PCI_CONF_LOCK(s);
148 1.1.4.2 minoura REGVAL(PCI_CONF_ADDR) = (CONFADDR_ENABLE | tag | (offset & 0xff));
149 1.1.4.2 minoura alpha_mb();
150 1.1.4.2 minoura data = REGVAL(PCI_CONF_DATA);
151 1.1.4.2 minoura REGVAL(PCI_CONF_ADDR) = 0;
152 1.1.4.2 minoura alpha_mb();
153 1.1.4.2 minoura PCI_CONF_UNLOCK(s);
154 1.1.4.2 minoura
155 1.1.4.2 minoura return (data);
156 1.1.4.2 minoura }
157 1.1.4.2 minoura
158 1.1.4.2 minoura void
159 1.1.4.2 minoura irongate_conf_write(void *ipv, pcitag_t tag, int offset, pcireg_t data)
160 1.1.4.2 minoura {
161 1.1.4.2 minoura int s;
162 1.1.4.2 minoura
163 1.1.4.2 minoura PCI_CONF_LOCK(s);
164 1.1.4.2 minoura REGVAL(PCI_CONF_ADDR) = (CONFADDR_ENABLE | tag | (offset & 0xff));
165 1.1.4.2 minoura alpha_mb();
166 1.1.4.2 minoura REGVAL(PCI_CONF_DATA) = data;
167 1.1.4.2 minoura alpha_mb();
168 1.1.4.2 minoura REGVAL(PCI_CONF_ADDR) = 0;
169 1.1.4.2 minoura alpha_mb();
170 1.1.4.2 minoura PCI_CONF_UNLOCK(s);
171 1.1.4.2 minoura }
172