Home | History | Annotate | Line # | Download | only in uba
      1 /*	$NetBSD: uba_mainbus.c,v 1.15 2025/07/14 12:38:11 hans 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  *
     47  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     48  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     49  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     50  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     51  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     52  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     53  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     54  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     55  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     56  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     57  * SUCH DAMAGE.
     58  *
     59  *	@(#)uba.c	7.10 (Berkeley) 12/16/90
     60  *	@(#)autoconf.c	7.20 (Berkeley) 5/9/91
     61  */
     62 
     63 #include <sys/cdefs.h>
     64 __KERNEL_RCSID(0, "$NetBSD: uba_mainbus.c,v 1.15 2025/07/14 12:38:11 hans Exp $");
     65 
     66 #define _VAX_BUS_DMA_PRIVATE
     67 
     68 #include <sys/param.h>
     69 #include <sys/systm.h>
     70 #include <sys/bus.h>
     71 #include <sys/cpu.h>
     72 #include <sys/device.h>
     73 
     74 #include <machine/nexus.h>
     75 #include <machine/sgmap.h>
     76 #include <machine/mainbus.h>
     77 
     78 #include <dev/qbus/ubavar.h>
     79 
     80 #include <vax/uba/uba_common.h>
     81 
     82 #include "ioconf.h"
     83 
     84 /* Some Qbus-specific defines */
     85 #define	QBASIZE	(8192 * VAX_NBPG)
     86 #define	QBAMAP	0x20088000
     87 #define	QBAMEM	0x30000000
     88 #define	QIOPAGE	0x20000000
     89 
     90 /*
     91  * The Q22 bus is the main IO bus on MicroVAX II/MicroVAX III systems.
     92  * It has an address space of 4MB (22 address bits), therefore the name,
     93  * and is hardware compatible with all 16 and 18 bits Q-bus devices.
     94  */
     95 static	int	qba_match(device_t, cfdata_t, void *);
     96 static	void	qba_attach(device_t, device_t, void *);
     97 static	void	qba_beforescan(struct uba_softc*);
     98 static	void	qba_init(struct uba_softc*);
     99 
    100 CFATTACH_DECL_NEW(uba_mainbus, sizeof(struct uba_vsoftc),
    101     qba_match, qba_attach, NULL, NULL);
    102 
    103 extern	struct vax_bus_space vax_mem_bus_space;
    104 
    105 int
    106 qba_match(device_t parent, cfdata_t cf, void *aux)
    107 {
    108 	struct mainbus_attach_args * const ma = aux;
    109 
    110 	return !strcmp(uba_cd.cd_name, ma->ma_type);
    111 }
    112 
    113 void
    114 qba_attach(device_t parent, device_t self, void *aux)
    115 {
    116 	struct mainbus_attach_args * const ma = aux;
    117 	struct uba_vsoftc * const sc = device_private(self);
    118 	paddr_t paddr;
    119 	vaddr_t vaddr;
    120 	int *mapp;
    121 	int pgnum;
    122 	int val;
    123 	int start;
    124 
    125 	aprint_normal(": Q22\n");
    126 
    127 	sc->uv_sc.uh_dev = self;
    128 	/*
    129 	 * Fill in bus specific data.
    130 	 */
    131 	sc->uv_sc.uh_beforescan = qba_beforescan;
    132 	sc->uv_sc.uh_ubainit = qba_init;
    133 	sc->uv_sc.uh_iot = ma->ma_iot;
    134 	sc->uv_sc.uh_dmat = &sc->uv_dmat;
    135 
    136 	/*
    137 	 * Fill in variables used by the sgmap system.
    138 	 */
    139 	sc->uv_size = QBASIZE;	/* Size in bytes of Qbus space */
    140 	sc->uv_addr = QBAMAP;	/* Physical address of map registers */
    141 
    142 	uba_dma_init(sc);
    143 
    144 	mapp = (int *)vax_map_physmem(QBAMAP, QBASIZE/VAX_NBPG);
    145 	val = 0;
    146 
    147 	for (paddr = QBAMEM, pgnum = 0, start = -1;
    148 	     paddr < QBAMEM + QBASIZE - 8192;
    149 	     paddr += VAX_NBPG, pgnum += 1) {
    150 		val = mapp[pgnum];
    151 		mapp[pgnum] = 0;
    152 		vaddr = vax_map_physmem(paddr, 1);
    153 		if (badaddr((void *)vaddr, 2) == 0) {
    154 			if (start < 0)
    155 				start = pgnum;
    156 		} else if (start >= 0) {
    157 			aprint_normal("sgmap exclusion at %#x - %#x\n",
    158 			    start*VAX_NBPG, pgnum*VAX_NBPG - 1);
    159 			vax_sgmap_reserve(start*VAX_NBPG,
    160 			    (pgnum - start)*VAX_NBPG, &sc->uv_sgmap);
    161 			start = -1;
    162 		}
    163 		vax_unmap_physmem(vaddr, 1);
    164 		mapp[pgnum] = val;
    165 	}
    166 	vax_unmap_physmem((vaddr_t)mapp, QBASIZE/VAX_NBPG);
    167 	if (start >= 0) {
    168 		aprint_normal("sgmap exclusion at %#x - %#x\n",
    169 		    start*VAX_NBPG, pgnum*VAX_NBPG - 1);
    170 		vax_sgmap_reserve(start*VAX_NBPG, (pgnum - start)*VAX_NBPG,
    171 		    &sc->uv_sgmap);
    172 	}
    173 
    174 	/* reserve I/O space within Qbus */
    175 	vax_sgmap_reserve(0x3fe000, 0x400000 - 0x3fe000, &sc->uv_sgmap);
    176 
    177 	uba_attach(&sc->uv_sc, QIOPAGE);
    178 }
    179 
    180 /*
    181  * Called when the QBA is set up; to enable DMA access from
    182  * QBA devices to main memory.
    183  */
    184 void
    185 qba_beforescan(struct uba_softc *sc)
    186 {
    187 #define	QIPCR	0x1f40
    188 #define	Q_LMEAE	0x20
    189 	bus_space_write_2(sc->uh_iot, sc->uh_ioh, QIPCR, Q_LMEAE);
    190 }
    191 
    192 void
    193 qba_init(struct uba_softc *sc)
    194 {
    195 	mtpr(0, PR_IUR);
    196 	DELAY(500000);
    197 	qba_beforescan(sc);
    198 }
    199