xref: /netbsd-src/sys/arch/alpha/pci/apecs_pci.c (revision c2f76ff004a2cb67efe5b12d97bd3ef7fe89e18d)
1 /* $NetBSD: apecs_pci.c,v 1.23 2010/12/15 01:27:18 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: apecs_pci.c,v 1.23 2010/12/15 01:27:18 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/apecsreg.h>
42 #include <alpha/pci/apecsvar.h>
43 
44 void		apecs_attach_hook(struct device *, struct device *,
45 		    struct pcibus_attach_args *);
46 int		apecs_bus_maxdevs(void *, int);
47 pcitag_t	apecs_make_tag(void *, int, int, int);
48 void		apecs_decompose_tag(void *, pcitag_t, int *, int *,
49 		    int *);
50 pcireg_t	apecs_conf_read(void *, pcitag_t, int);
51 void		apecs_conf_write(void *, pcitag_t, int, pcireg_t);
52 
53 void
54 apecs_pci_init(pci_chipset_tag_t pc, void *v)
55 {
56 
57 	pc->pc_conf_v = v;
58 	pc->pc_attach_hook = apecs_attach_hook;
59 	pc->pc_bus_maxdevs = apecs_bus_maxdevs;
60 	pc->pc_make_tag = apecs_make_tag;
61 	pc->pc_decompose_tag = apecs_decompose_tag;
62 	pc->pc_conf_read = apecs_conf_read;
63 	pc->pc_conf_write = apecs_conf_write;
64 }
65 
66 void
67 apecs_attach_hook(struct device *parent, struct device *self, struct pcibus_attach_args *pba)
68 {
69 }
70 
71 int
72 apecs_bus_maxdevs(void *cpv, int busno)
73 {
74 
75 	return 32;
76 }
77 
78 pcitag_t
79 apecs_make_tag(void *cpv, int b, int d, int f)
80 {
81 
82 	return (b << 16) | (d << 11) | (f << 8);
83 }
84 
85 void
86 apecs_decompose_tag(void *cpv, pcitag_t tag, int *bp, int *dp, int *fp)
87 {
88 
89 	if (bp != NULL)
90 		*bp = (tag >> 16) & 0xff;
91 	if (dp != NULL)
92 		*dp = (tag >> 11) & 0x1f;
93 	if (fp != NULL)
94 		*fp = (tag >> 8) & 0x7;
95 }
96 
97 pcireg_t
98 apecs_conf_read(void *cpv, pcitag_t tag, int offset)
99 {
100 	struct apecs_config *acp = cpv;
101 	pcireg_t *datap, data;
102 	int s, secondary, ba;
103 	int32_t old_haxr2;					/* XXX */
104 
105 	s = 0;					/* XXX gcc -Wuninitialized */
106 	old_haxr2 = 0;				/* XXX gcc -Wuninitialized */
107 
108 	/* secondary if bus # != 0 */
109 	pci_decompose_tag(&acp->ac_pc, tag, &secondary, 0, 0);
110 	if (secondary) {
111 		s = splhigh();
112 		old_haxr2 = REGVAL(EPIC_HAXR2);
113 		alpha_mb();
114 		REGVAL(EPIC_HAXR2) = old_haxr2 | 0x1;
115 		alpha_mb();
116 	}
117 
118 	datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(APECS_PCI_CONF |
119 	    tag << 5UL |					/* XXX */
120 	    (offset & ~0x03) << 5 |				/* XXX */
121 	    0 << 5 |						/* XXX */
122 	    0x3 << 3);						/* XXX */
123 	data = (pcireg_t)-1;
124 	if (!(ba = badaddr(datap, sizeof *datap)))
125 		data = *datap;
126 
127 	if (secondary) {
128 		alpha_mb();
129 		REGVAL(EPIC_HAXR2) = old_haxr2;
130 		alpha_mb();
131 		splx(s);
132 	}
133 
134 #if 0
135 	printf("apecs_conf_read: tag 0x%lx, reg 0x%lx -> %x @ %p%s\n", tag, reg,
136 	    data, datap, ba ? " (badaddr)" : "");
137 #endif
138 
139 	return data;
140 }
141 
142 void
143 apecs_conf_write(void *cpv, pcitag_t tag, int offset, pcireg_t data)
144 {
145 	struct apecs_config *acp = cpv;
146 	pcireg_t *datap;
147 	int s, secondary;
148 	int32_t old_haxr2;					/* XXX */
149 
150 	s = 0;					/* XXX gcc -Wuninitialized */
151 	old_haxr2 = 0;				/* XXX gcc -Wuninitialized */
152 
153 	/* secondary if bus # != 0 */
154 	pci_decompose_tag(&acp->ac_pc, tag, &secondary, 0, 0);
155 	if (secondary) {
156 		s = splhigh();
157 		old_haxr2 = REGVAL(EPIC_HAXR2);
158 		alpha_mb();
159 		REGVAL(EPIC_HAXR2) = old_haxr2 | 0x1;
160 		alpha_mb();
161 	}
162 
163 	datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(APECS_PCI_CONF |
164 	    tag << 5UL |					/* XXX */
165 	    (offset & ~0x03) << 5 |				/* XXX */
166 	    0 << 5 |						/* XXX */
167 	    0x3 << 3);						/* XXX */
168 
169 	alpha_mb();
170 	*datap = data;
171 	alpha_mb();
172 	alpha_mb();
173 
174 	if (secondary) {
175 		alpha_mb();
176 		REGVAL(EPIC_HAXR2) = old_haxr2;
177 		alpha_mb();
178 		splx(s);
179 	}
180 
181 #if 0
182 	printf("apecs_conf_write: tag 0x%lx, reg 0x%lx -> 0x%x @ %p\n", tag,
183 	    reg, data, datap);
184 #endif
185 }
186