xref: /netbsd-src/sys/arch/alpha/pci/lca_pci.c (revision 76dfffe33547c37f8bdd446e3e4ab0f3c16cea4b)
1 /*	$NetBSD: lca_pci.c,v 1.7 1996/11/13 21:13:28 cgd Exp $	*/
2 
3 /*
4  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
5  * All rights reserved.
6  *
7  * Author: Chris G. Demetriou
8  *
9  * Permission to use, copy, modify and distribute this software and
10  * its documentation is hereby granted, provided that both the copyright
11  * notice and this permission notice appear in all copies of the
12  * software, derivative works or modified versions, and any portions
13  * thereof, and that both notices appear in supporting documentation.
14  *
15  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18  *
19  * Carnegie Mellon requests users of this software to return to
20  *
21  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
22  *  School of Computer Science
23  *  Carnegie Mellon University
24  *  Pittsburgh PA 15213-3890
25  *
26  * any improvements or extensions that they make and grant Carnegie the
27  * rights to redistribute these changes.
28  */
29 
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
33 #include <sys/device.h>
34 #include <vm/vm.h>
35 
36 #include <dev/pci/pcireg.h>
37 #include <dev/pci/pcivar.h>
38 #include <alpha/pci/lcareg.h>
39 #include <alpha/pci/lcavar.h>
40 
41 void		lca_attach_hook __P((struct device *, struct device *,
42 		    struct pcibus_attach_args *));
43 int		lca_bus_maxdevs __P((void *, int));
44 pcitag_t	lca_make_tag __P((void *, int, int, int));
45 void		lca_decompose_tag __P((void *, pcitag_t, int *, int *,
46 		    int *));
47 pcireg_t	lca_conf_read __P((void *, pcitag_t, int));
48 void		lca_conf_write __P((void *, pcitag_t, int, pcireg_t));
49 
50 void
51 lca_pci_init(pc, v)
52 	pci_chipset_tag_t pc;
53 	void *v;
54 {
55 
56 	pc->pc_conf_v = v;
57 	pc->pc_attach_hook = lca_attach_hook;
58 	pc->pc_bus_maxdevs = lca_bus_maxdevs;
59 	pc->pc_make_tag = lca_make_tag;
60 	pc->pc_decompose_tag = lca_decompose_tag;
61 	pc->pc_conf_read = lca_conf_read;
62 	pc->pc_conf_write = lca_conf_write;
63 }
64 
65 void
66 lca_attach_hook(parent, self, pba)
67 	struct device *parent, *self;
68 	struct pcibus_attach_args *pba;
69 {
70 }
71 
72 int
73 lca_bus_maxdevs(cpv, busno)
74 	void *cpv;
75 	int busno;
76 {
77 
78 	if (busno == 0)
79 		return 16;
80 	else
81 		return 32;
82 }
83 
84 pcitag_t
85 lca_make_tag(cpv, b, d, f)
86 	void *cpv;
87 	int b, d, f;
88 {
89 
90 	return (b << 16) | (d << 11) | (f << 8);
91 }
92 
93 void
94 lca_decompose_tag(cpv, tag, bp, dp, fp)
95 	void *cpv;
96 	pcitag_t tag;
97 	int *bp, *dp, *fp;
98 {
99 
100 	if (bp != NULL)
101 		*bp = (tag >> 16) & 0xff;
102 	if (dp != NULL)
103 		*dp = (tag >> 11) & 0x1f;
104 	if (fp != NULL)
105 		*fp = (tag >> 8) & 0x7;
106 }
107 
108 pcireg_t
109 lca_conf_read(cpv, tag, offset)
110 	void *cpv;
111 	pcitag_t tag;
112 	int offset;
113 {
114 	struct lca_config *lcp = cpv;
115 	pcireg_t *datap, data;
116 	int s, secondary, device, ba;
117 
118 #ifdef DIAGNOSTIC
119 	s = 0;					/* XXX gcc -Wuninitialized */
120 #endif
121 
122 	/* secondary if bus # != 0 */
123 	pci_decompose_tag(&lcp->lc_pc, tag, &secondary, &device, 0);
124 	if (secondary) {
125 		s = splhigh();
126 		alpha_mb();
127 		REGVAL(LCA_IOC_CONF) = 0x01;
128 		alpha_mb();
129 	} else {
130 		/*
131 		 * on the LCA, must frob the tag used for
132 		 * devices on the primary bus, in the same ways
133 		 * as is used by type 1 configuration cycles
134 		 * on PCs.
135 		 */
136 		tag = (1 << (device + 11)) | (tag & 0x7ff);
137 	}
138 
139 	datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(LCA_PCI_CONF |
140 	    tag << 5UL |					/* XXX */
141 	    (offset & ~0x03) << 5 |				/* XXX */
142 	    0 << 5 |						/* XXX */
143 	    0x3 << 3);						/* XXX */
144 	data = (pcireg_t)-1;
145 	if (!(ba = badaddr(datap, sizeof *datap)))
146 		data = *datap;
147 
148 	if (secondary) {
149 		alpha_mb();
150 		REGVAL(LCA_IOC_CONF) = 0x00;
151 		alpha_mb();
152 		splx(s);
153 	}
154 
155 #if 0
156 	printf("lca_conf_read: tag 0x%lx, reg 0x%lx -> %x @ %p%s\n", tag, reg,
157 	    data, datap, ba ? " (badaddr)" : "");
158 #endif
159 
160 	return data;
161 }
162 
163 void
164 lca_conf_write(cpv, tag, offset, data)
165 	void *cpv;
166 	pcitag_t tag;
167 	int offset;
168 	pcireg_t data;
169 {
170 	struct lca_config *lcp = cpv;
171 	pcireg_t *datap;
172 	int s, secondary, device;
173 
174 #ifdef DIAGNOSTIC
175 	s = 0;					/* XXX gcc -Wuninitialized */
176 #endif
177 
178 	/* secondary if bus # != 0 */
179 	pci_decompose_tag(&lcp->lc_pc, tag, &secondary, &device, 0);
180 	if (secondary) {
181 		s = splhigh();
182 		alpha_mb();
183 		REGVAL(LCA_IOC_CONF) = 0x01;
184 		alpha_mb();
185 	} else {
186 		/*
187 		 * on the LCA, must frob the tag used for
188 		 * devices on the primary bus, in the same ways
189 		 * as is used by type 1 configuration cycles
190 		 * on PCs.
191 		 */
192 		tag = (1 << (device + 11)) | (tag & 0x7ff);
193 	}
194 
195 	datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(LCA_PCI_CONF |
196 	    tag << 5UL |					/* XXX */
197 	    (offset & ~0x03) << 5 |				/* XXX */
198 	    0 << 5 |						/* XXX */
199 	    0x3 << 3);						/* XXX */
200 	*datap = data;
201 
202 	if (secondary) {
203 		alpha_mb();
204 		REGVAL(LCA_IOC_CONF) = 0x00;
205 		alpha_mb();
206 		splx(s);
207 	}
208 
209 #if 0
210 	printf("lca_conf_write: tag 0x%lx, reg 0x%lx -> 0x%x @ %p\n", tag,
211 	    reg, data, datap);
212 #endif
213 }
214