xref: /netbsd-src/sys/arch/vax/uba/uba_mainbus.c (revision 6a6027692662ba623e7bf5274322989a7b5d1440)
1*6a602769Sragge /*	$NetBSD: uba_mainbus.c,v 1.14 2017/05/22 17:15:45 ragge Exp $	   */
2aad01611Sagc /*
3aad01611Sagc  * Copyright (c) 1982, 1986 The Regents of the University of California.
4aad01611Sagc  * All rights reserved.
5aad01611Sagc  *
6aad01611Sagc  * Redistribution and use in source and binary forms, with or without
7aad01611Sagc  * modification, are permitted provided that the following conditions
8aad01611Sagc  * are met:
9aad01611Sagc  * 1. Redistributions of source code must retain the above copyright
10aad01611Sagc  *    notice, this list of conditions and the following disclaimer.
11aad01611Sagc  * 2. Redistributions in binary form must reproduce the above copyright
12aad01611Sagc  *    notice, this list of conditions and the following disclaimer in the
13aad01611Sagc  *    documentation and/or other materials provided with the distribution.
14aad01611Sagc  * 3. Neither the name of the University nor the names of its contributors
15aad01611Sagc  *    may be used to endorse or promote products derived from this software
16aad01611Sagc  *    without specific prior written permission.
17aad01611Sagc  *
18aad01611Sagc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19aad01611Sagc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20aad01611Sagc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21aad01611Sagc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22aad01611Sagc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23aad01611Sagc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24aad01611Sagc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25aad01611Sagc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26aad01611Sagc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27aad01611Sagc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28aad01611Sagc  * SUCH DAMAGE.
29aad01611Sagc  *
30aad01611Sagc  *	@(#)uba.c	7.10 (Berkeley) 12/16/90
31aad01611Sagc  *	@(#)autoconf.c	7.20 (Berkeley) 5/9/91
32aad01611Sagc  */
33aad01611Sagc 
34ad1db202Sragge /*
35ad1db202Sragge  * Copyright (c) 1996 Jonathan Stone.
36ad1db202Sragge  * Copyright (c) 1994, 1996 Ludd, University of Lule}, Sweden.
37ad1db202Sragge  *
38ad1db202Sragge  * Redistribution and use in source and binary forms, with or without
39ad1db202Sragge  * modification, are permitted provided that the following conditions
40ad1db202Sragge  * are met:
41ad1db202Sragge  * 1. Redistributions of source code must retain the above copyright
42ad1db202Sragge  *    notice, this list of conditions and the following disclaimer.
43ad1db202Sragge  * 2. Redistributions in binary form must reproduce the above copyright
44ad1db202Sragge  *    notice, this list of conditions and the following disclaimer in the
45ad1db202Sragge  *    documentation and/or other materials provided with the distribution.
46ad1db202Sragge  *
47ad1db202Sragge  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
48ad1db202Sragge  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49ad1db202Sragge  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50ad1db202Sragge  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51ad1db202Sragge  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52ad1db202Sragge  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53ad1db202Sragge  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54ad1db202Sragge  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55ad1db202Sragge  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56ad1db202Sragge  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57ad1db202Sragge  * SUCH DAMAGE.
58ad1db202Sragge  *
59ad1db202Sragge  *	@(#)uba.c	7.10 (Berkeley) 12/16/90
60ad1db202Sragge  *	@(#)autoconf.c	7.20 (Berkeley) 5/9/91
61ad1db202Sragge  */
62ad1db202Sragge 
633b4fb6d0Slukem #include <sys/cdefs.h>
64*6a602769Sragge __KERNEL_RCSID(0, "$NetBSD: uba_mainbus.c,v 1.14 2017/05/22 17:15:45 ragge Exp $");
65ad1db202Sragge 
66134b65fdSragge #define _VAX_BUS_DMA_PRIVATE
6706386a01Smatt 
6806386a01Smatt #include <sys/param.h>
6906386a01Smatt #include <sys/systm.h>
7006386a01Smatt #include <sys/bus.h>
7106386a01Smatt #include <sys/cpu.h>
7206386a01Smatt #include <sys/device.h>
7306386a01Smatt 
74ad1db202Sragge #include <machine/nexus.h>
75134b65fdSragge #include <machine/sgmap.h>
76dfba8166Smatt #include <machine/mainbus.h>
77ad1db202Sragge 
78134b65fdSragge #include <dev/qbus/ubavar.h>
79134b65fdSragge 
80dfba8166Smatt #include <vax/uba/uba_common.h>
81dfba8166Smatt 
82dfba8166Smatt #include "ioconf.h"
83134b65fdSragge 
84134b65fdSragge /* Some Qbus-specific defines */
85134b65fdSragge #define	QBASIZE	(8192 * VAX_NBPG)
86134b65fdSragge #define	QBAMAP	0x20088000
875227f182Smatt #define	QBAMEM	0x30000000
88134b65fdSragge #define	QIOPAGE	0x20000000
89ad1db202Sragge 
90ad1db202Sragge /*
91ad1db202Sragge  * The Q22 bus is the main IO bus on MicroVAX II/MicroVAX III systems.
92ad1db202Sragge  * It has an address space of 4MB (22 address bits), therefore the name,
93ad1db202Sragge  * and is hardware compatible with all 16 and 18 bits Q-bus devices.
94ad1db202Sragge  */
95dfba8166Smatt static	int	qba_match(device_t, cfdata_t, void *);
96dfba8166Smatt static	void	qba_attach(device_t, device_t, void *);
97dfba8166Smatt static	void	qba_beforescan(struct uba_softc*);
98dfba8166Smatt static	void	qba_init(struct uba_softc*);
99ad1db202Sragge 
100dfba8166Smatt CFATTACH_DECL_NEW(uba_mainbus, sizeof(struct uba_vsoftc),
1014bf871a7Sthorpej     qba_match, qba_attach, NULL, NULL);
102ad1db202Sragge 
103ad1db202Sragge extern	struct vax_bus_space vax_mem_bus_space;
104ad1db202Sragge 
105ad1db202Sragge int
qba_match(device_t parent,cfdata_t cf,void * aux)106dfba8166Smatt qba_match(device_t parent, cfdata_t cf, void *aux)
107ad1db202Sragge {
108dfba8166Smatt 	struct mainbus_attach_args * const ma = aux;
109ad1db202Sragge 
110dfba8166Smatt 	return !strcmp(uba_cd.cd_name, ma->ma_type);
111ad1db202Sragge }
112ad1db202Sragge 
113ad1db202Sragge void
qba_attach(device_t parent,device_t self,void * aux)114dfba8166Smatt qba_attach(device_t parent, device_t self, void *aux)
115ad1db202Sragge {
116dfba8166Smatt 	struct mainbus_attach_args * const ma = aux;
117dfba8166Smatt 	struct uba_vsoftc * const sc = device_private(self);
1185227f182Smatt 	paddr_t paddr;
1195227f182Smatt 	vaddr_t vaddr;
1205227f182Smatt 	int *mapp;
1215227f182Smatt 	int pgnum;
1225227f182Smatt 	//int val;
1235227f182Smatt 	int start;
124ad1db202Sragge 
125dfba8166Smatt 	aprint_normal(": Q22\n");
126dfba8166Smatt 
127dfba8166Smatt 	sc->uv_sc.uh_dev = self;
128ad1db202Sragge 	/*
129ad1db202Sragge 	 * Fill in bus specific data.
130ad1db202Sragge 	 */
131134b65fdSragge 	sc->uv_sc.uh_beforescan = qba_beforescan;
132134b65fdSragge 	sc->uv_sc.uh_ubainit = qba_init;
133dfba8166Smatt 	sc->uv_sc.uh_iot = ma->ma_iot;
134134b65fdSragge 	sc->uv_sc.uh_dmat = &sc->uv_dmat;
135ad1db202Sragge 
136134b65fdSragge 	/*
137134b65fdSragge 	 * Fill in variables used by the sgmap system.
138134b65fdSragge 	 */
139134b65fdSragge 	sc->uv_size = QBASIZE;	/* Size in bytes of Qbus space */
140134b65fdSragge 	sc->uv_addr = QBAMAP;	/* Physical address of map registers */
141134b65fdSragge 
142134b65fdSragge 	uba_dma_init(sc);
1435227f182Smatt 
1445227f182Smatt 	mapp = (int *)vax_map_physmem(QBAMAP, QBASIZE/VAX_NBPG);
1455227f182Smatt 	//val = 0;
1465227f182Smatt 
1475227f182Smatt 	for (paddr = QBAMEM, pgnum = 0, start = -1;
1485227f182Smatt 	     paddr < QBAMEM + QBASIZE - 8192;
1495227f182Smatt 	     paddr += VAX_NBPG, pgnum += 1) {
1505227f182Smatt 		//val = mapp[pgnum];
1515227f182Smatt 		mapp[pgnum] = 0;
1525227f182Smatt 		vaddr = vax_map_physmem(paddr, 1);
1535227f182Smatt 		if (badaddr((void *)vaddr, 2) == 0) {
1545227f182Smatt 			if (start < 0)
1555227f182Smatt 				start = pgnum;
1565227f182Smatt 		} else if (start >= 0) {
1575227f182Smatt 			aprint_normal("sgmap exclusion at %#x - %#x\n",
1585227f182Smatt 			    start*VAX_NBPG, pgnum*VAX_NBPG - 1);
1595141ec2aSmatt 			vax_sgmap_reserve(start*VAX_NBPG,
1605227f182Smatt 			    (pgnum - start)*VAX_NBPG, &sc->uv_sgmap);
1615227f182Smatt 			start = -1;
1625227f182Smatt 		}
1635227f182Smatt 		vax_unmap_physmem(vaddr, 1);
1645227f182Smatt 		//mapp[pgnum] = val;
1655227f182Smatt 	}
1665227f182Smatt 	vax_unmap_physmem((vaddr_t)mapp, QBASIZE/VAX_NBPG);
1675227f182Smatt 	if (start >= 0) {
1685227f182Smatt 		aprint_normal("sgmap exclusion at %#x - %#x\n",
1695227f182Smatt 		    start*VAX_NBPG, pgnum*VAX_NBPG - 1);
1705227f182Smatt 		vax_sgmap_reserve(start*VAX_NBPG, (pgnum - start)*VAX_NBPG,
1715227f182Smatt 		    &sc->uv_sgmap);
1725227f182Smatt 	}
1735227f182Smatt 
1745227f182Smatt 	/* reserve I/O space within Qbus */
1755227f182Smatt 	vax_sgmap_reserve(0x3fe000, 0x400000 - 0x3fe000, &sc->uv_sgmap);
1765227f182Smatt 
177134b65fdSragge 	uba_attach(&sc->uv_sc, QIOPAGE);
178ad1db202Sragge }
179ad1db202Sragge 
180ad1db202Sragge /*
181ad1db202Sragge  * Called when the QBA is set up; to enable DMA access from
182ad1db202Sragge  * QBA devices to main memory.
183ad1db202Sragge  */
184ad1db202Sragge void
qba_beforescan(struct uba_softc * sc)185dfba8166Smatt qba_beforescan(struct uba_softc *sc)
186ad1db202Sragge {
187134b65fdSragge #define	QIPCR	0x1f40
188134b65fdSragge #define	Q_LMEAE	0x20
18919537c0fSchristos 	bus_space_write_2(sc->uh_iot, sc->uh_ioh, QIPCR, Q_LMEAE);
190ad1db202Sragge }
191ad1db202Sragge 
192ad1db202Sragge void
qba_init(struct uba_softc * sc)193dfba8166Smatt qba_init(struct uba_softc *sc)
194ad1db202Sragge {
195ad1db202Sragge 	mtpr(0, PR_IUR);
196ad1db202Sragge 	DELAY(500000);
197ad1db202Sragge 	qba_beforescan(sc);
198ad1db202Sragge }
199