xref: /netbsd-src/sys/arch/alpha/pci/lca_pci.c (revision 6a493d6bc668897c91594964a732d38505b70cbb)
1 /* $NetBSD: lca_pci.c,v 1.21 2012/02/06 02:14:14 matt 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/cdefs.h>			/* RCS ID & Copyright macro defns */
31 
32 __KERNEL_RCSID(0, "$NetBSD: lca_pci.c,v 1.21 2012/02/06 02:14:14 matt Exp $");
33 
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/device.h>
38 
39 #include <dev/pci/pcireg.h>
40 #include <dev/pci/pcivar.h>
41 #include <alpha/pci/lcareg.h>
42 #include <alpha/pci/lcavar.h>
43 
44 void		lca_attach_hook(device_t, device_t,
45 		    struct pcibus_attach_args *);
46 int		lca_bus_maxdevs(void *, int);
47 pcitag_t	lca_make_tag(void *, int, int, int);
48 void		lca_decompose_tag(void *, pcitag_t, int *, int *, int *);
49 pcireg_t	lca_conf_read(void *, pcitag_t, int);
50 void		lca_conf_write(void *, pcitag_t, int, pcireg_t);
51 
52 void
53 lca_pci_init(pci_chipset_tag_t pc, 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(device_t parent, device_t self, struct pcibus_attach_args *pba)
67 {
68 }
69 
70 int
71 lca_bus_maxdevs(void *cpv, int busno)
72 {
73 
74 	if (busno == 0)
75 		return 16;
76 	else
77 		return 32;
78 }
79 
80 pcitag_t
81 lca_make_tag(void *cpv, int b, int d, int f)
82 {
83 
84 	return (b << 16) | (d << 11) | (f << 8);
85 }
86 
87 void
88 lca_decompose_tag(void *cpv, pcitag_t tag, int *bp, int *dp, int *fp)
89 {
90 
91 	if (bp != NULL)
92 		*bp = (tag >> 16) & 0xff;
93 	if (dp != NULL)
94 		*dp = (tag >> 11) & 0x1f;
95 	if (fp != NULL)
96 		*fp = (tag >> 8) & 0x7;
97 }
98 
99 pcireg_t
100 lca_conf_read(void *cpv, pcitag_t tag, int offset)
101 {
102 	struct lca_config *lcp = cpv;
103 	pcireg_t *datap, data;
104 	int s, secondary, device, ba;
105 
106 	s = 0;					/* XXX gcc -Wuninitialized */
107 
108 	/* secondary if bus # != 0 */
109 	pci_decompose_tag(&lcp->lc_pc, tag, &secondary, &device, 0);
110 	if (secondary) {
111 		s = splhigh();
112 		alpha_mb();
113 		REGVAL(LCA_IOC_CONF) = 0x01;
114 		alpha_mb();
115 	} else {
116 		/*
117 		 * on the LCA, must frob the tag used for
118 		 * devices on the primary bus, in the same ways
119 		 * as is used by type 1 configuration cycles
120 		 * on PCs.
121 		 */
122 		tag = (1 << (device + 11)) | (tag & 0x7ff);
123 	}
124 
125 	datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(LCA_PCI_CONF |
126 	    tag << 5UL |					/* XXX */
127 	    (offset & ~0x03) << 5 |				/* XXX */
128 	    0 << 5 |						/* XXX */
129 	    0x3 << 3);						/* XXX */
130 	data = (pcireg_t)-1;
131 	if (!(ba = badaddr(datap, sizeof *datap)))
132 		data = *datap;
133 
134 	if (secondary) {
135 		alpha_mb();
136 		REGVAL(LCA_IOC_CONF) = 0x00;
137 		alpha_mb();
138 		splx(s);
139 	}
140 
141 #if 0
142 	printf("lca_conf_read: tag 0x%lx, reg 0x%lx -> %x @ %p%s\n", tag, reg,
143 	    data, datap, ba ? " (badaddr)" : "");
144 #endif
145 
146 	return data;
147 }
148 
149 void
150 lca_conf_write(void *cpv, pcitag_t tag, int offset, pcireg_t data)
151 {
152 	struct lca_config *lcp = cpv;
153 	pcireg_t *datap;
154 	int s, secondary, device;
155 
156 	s = 0;					/* XXX gcc -Wuninitialized */
157 
158 	/* secondary if bus # != 0 */
159 	pci_decompose_tag(&lcp->lc_pc, tag, &secondary, &device, 0);
160 	if (secondary) {
161 		s = splhigh();
162 		alpha_mb();
163 		REGVAL(LCA_IOC_CONF) = 0x01;
164 		alpha_mb();
165 	} else {
166 		/*
167 		 * on the LCA, must frob the tag used for
168 		 * devices on the primary bus, in the same ways
169 		 * as is used by type 1 configuration cycles
170 		 * on PCs.
171 		 */
172 		tag = (1 << (device + 11)) | (tag & 0x7ff);
173 	}
174 
175 	datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(LCA_PCI_CONF |
176 	    tag << 5UL |					/* XXX */
177 	    (offset & ~0x03) << 5 |				/* XXX */
178 	    0 << 5 |						/* XXX */
179 	    0x3 << 3);						/* XXX */
180 	*datap = data;
181 
182 	if (secondary) {
183 		alpha_mb();
184 		REGVAL(LCA_IOC_CONF) = 0x00;
185 		alpha_mb();
186 		splx(s);
187 	}
188 
189 #if 0
190 	printf("lca_conf_write: tag 0x%lx, reg 0x%lx -> 0x%x @ %p\n", tag,
191 	    reg, data, datap);
192 #endif
193 }
194