xref: /netbsd-src/sys/arch/vax/uba/uba_mainbus.c (revision 4d5abbe83f525258eb479e5fca29f25cb943f379)
1 /*	$NetBSD: uba_mainbus.c,v 1.12 2015/07/05 04:53:26 matt Exp $	   */
2 /*
3  * Copyright (c) 1982, 1986 The Regents of the University of California.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the University nor the names of its contributors
15  *    may be used to endorse or promote products derived from this software
16  *    without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  *	@(#)uba.c	7.10 (Berkeley) 12/16/90
31  *	@(#)autoconf.c	7.20 (Berkeley) 5/9/91
32  */
33 
34 /*
35  * Copyright (c) 1996 Jonathan Stone.
36  * Copyright (c) 1994, 1996 Ludd, University of Lule}, Sweden.
37  *
38  * Redistribution and use in source and binary forms, with or without
39  * modification, are permitted provided that the following conditions
40  * are met:
41  * 1. Redistributions of source code must retain the above copyright
42  *    notice, this list of conditions and the following disclaimer.
43  * 2. Redistributions in binary form must reproduce the above copyright
44  *    notice, this list of conditions and the following disclaimer in the
45  *    documentation and/or other materials provided with the distribution.
46  * 3. All advertising materials mentioning features or use of this software
47  *    must display the following acknowledgement:
48  *	This product includes software developed by the University of
49  *	California, Berkeley and its contributors.
50  * 4. Neither the name of the University nor the names of its contributors
51  *    may be used to endorse or promote products derived from this software
52  *    without specific prior written permission.
53  *
54  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64  * SUCH DAMAGE.
65  *
66  *	@(#)uba.c	7.10 (Berkeley) 12/16/90
67  *	@(#)autoconf.c	7.20 (Berkeley) 5/9/91
68  */
69 
70 #include <sys/cdefs.h>
71 __KERNEL_RCSID(0, "$NetBSD: uba_mainbus.c,v 1.12 2015/07/05 04:53:26 matt Exp $");
72 
73 #define _VAX_BUS_DMA_PRIVATE
74 
75 #include <sys/param.h>
76 #include <sys/systm.h>
77 #include <sys/bus.h>
78 #include <sys/cpu.h>
79 #include <sys/device.h>
80 
81 #include <machine/nexus.h>
82 #include <machine/sgmap.h>
83 #include <machine/mainbus.h>
84 
85 #include <dev/qbus/ubavar.h>
86 
87 #include <vax/uba/uba_common.h>
88 
89 #include "ioconf.h"
90 
91 /* Some Qbus-specific defines */
92 #define	QBASIZE	(8192 * VAX_NBPG)
93 #define	QBAMAP	0x20088000
94 #define	QBAMEM	0x30000000
95 #define	QIOPAGE	0x20000000
96 
97 /*
98  * The Q22 bus is the main IO bus on MicroVAX II/MicroVAX III systems.
99  * It has an address space of 4MB (22 address bits), therefore the name,
100  * and is hardware compatible with all 16 and 18 bits Q-bus devices.
101  */
102 static	int	qba_match(device_t, cfdata_t, void *);
103 static	void	qba_attach(device_t, device_t, void *);
104 static	void	qba_beforescan(struct uba_softc*);
105 static	void	qba_init(struct uba_softc*);
106 
107 CFATTACH_DECL_NEW(uba_mainbus, sizeof(struct uba_vsoftc),
108     qba_match, qba_attach, NULL, NULL);
109 
110 extern	struct vax_bus_space vax_mem_bus_space;
111 
112 int
113 qba_match(device_t parent, cfdata_t cf, void *aux)
114 {
115 	struct mainbus_attach_args * const ma = aux;
116 
117 	return !strcmp(uba_cd.cd_name, ma->ma_type);
118 }
119 
120 void
121 qba_attach(device_t parent, device_t self, void *aux)
122 {
123 	struct mainbus_attach_args * const ma = aux;
124 	struct uba_vsoftc * const sc = device_private(self);
125 	paddr_t paddr;
126 	vaddr_t vaddr;
127 	int *mapp;
128 	int pgnum;
129 	//int val;
130 	int start;
131 
132 	aprint_normal(": Q22\n");
133 
134 	sc->uv_sc.uh_dev = self;
135 	/*
136 	 * Fill in bus specific data.
137 	 */
138 	sc->uv_sc.uh_beforescan = qba_beforescan;
139 	sc->uv_sc.uh_ubainit = qba_init;
140 	sc->uv_sc.uh_iot = ma->ma_iot;
141 	sc->uv_sc.uh_dmat = &sc->uv_dmat;
142 
143 	/*
144 	 * Fill in variables used by the sgmap system.
145 	 */
146 	sc->uv_size = QBASIZE;	/* Size in bytes of Qbus space */
147 	sc->uv_addr = QBAMAP;	/* Physical address of map registers */
148 
149 	uba_dma_init(sc);
150 
151 	mapp = (int *)vax_map_physmem(QBAMAP, QBASIZE/VAX_NBPG);
152 	//val = 0;
153 
154 	for (paddr = QBAMEM, pgnum = 0, start = -1;
155 	     paddr < QBAMEM + QBASIZE - 8192;
156 	     paddr += VAX_NBPG, pgnum += 1) {
157 		//val = mapp[pgnum];
158 		mapp[pgnum] = 0;
159 		vaddr = vax_map_physmem(paddr, 1);
160 		if (badaddr((void *)vaddr, 2) == 0) {
161 			if (start < 0)
162 				start = pgnum;
163 		} else if (start >= 0) {
164 			aprint_normal("sgmap exclusion at %#x - %#x\n",
165 			    start*VAX_NBPG, pgnum*VAX_NBPG - 1);
166 			vax_sgmap_reserve(start*VAX_NBPG,
167 			    (pgnum - start)*VAX_NBPG, &sc->uv_sgmap);
168 			start = -1;
169 		}
170 		vax_unmap_physmem(vaddr, 1);
171 		//mapp[pgnum] = val;
172 	}
173 	vax_unmap_physmem((vaddr_t)mapp, QBASIZE/VAX_NBPG);
174 	if (start >= 0) {
175 		aprint_normal("sgmap exclusion at %#x - %#x\n",
176 		    start*VAX_NBPG, pgnum*VAX_NBPG - 1);
177 		vax_sgmap_reserve(start*VAX_NBPG, (pgnum - start)*VAX_NBPG,
178 		    &sc->uv_sgmap);
179 	}
180 
181 	/* reserve I/O space within Qbus */
182 	vax_sgmap_reserve(0x3fe000, 0x400000 - 0x3fe000, &sc->uv_sgmap);
183 
184 	uba_attach(&sc->uv_sc, QIOPAGE);
185 }
186 
187 /*
188  * Called when the QBA is set up; to enable DMA access from
189  * QBA devices to main memory.
190  */
191 void
192 qba_beforescan(struct uba_softc *sc)
193 {
194 #define	QIPCR	0x1f40
195 #define	Q_LMEAE	0x20
196 	bus_space_write_2(sc->uh_tag, sc->uh_ioh, QIPCR, Q_LMEAE);
197 }
198 
199 void
200 qba_init(struct uba_softc *sc)
201 {
202 	mtpr(0, PR_IUR);
203 	DELAY(500000);
204 	qba_beforescan(sc);
205 }
206