xref: /netbsd/sys/arch/atari/vme/vme.c (revision bf9ec67e)
1 /*	$NetBSD: vme.c,v 1.3 1998/01/12 18:04:22 thorpej Exp $	*/
2 
3 /*-
4  * Copyright (c) 1997 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *        This product includes software developed by the NetBSD
18  *        Foundation, Inc. and its contributors.
19  * 4. Neither the name of The NetBSD Foundation nor the names of its
20  *    contributors may be used to endorse or promote products derived
21  *    from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/conf.h>
40 #include <sys/malloc.h>
41 #include <sys/device.h>
42 
43 #include <machine/intr.h>
44 
45 #include <atari/vme/vmevar.h>
46 
47 int vmematch __P((struct device *, struct cfdata *, void *));
48 void vmeattach __P((struct device *, struct device *, void *));
49 int vmeprint __P((void *, const char *));
50 
51 struct cfattach vme_ca = {
52 	sizeof(struct vme_softc), vmematch, vmeattach
53 };
54 
55 int	vmesearch __P((struct device *, struct cfdata *, void *));
56 
57 int
58 vmematch(parent, cf, aux)
59 	struct device *parent;
60 	struct cfdata *cf;
61 	void *aux;
62 {
63 	struct vmebus_attach_args *vba = aux;
64 
65 	if (strcmp(vba->vba_busname, cf->cf_driver->cd_name))
66 		return (0);
67 
68         return (1);
69 }
70 
71 void
72 vmeattach(parent, self, aux)
73 	struct device *parent, *self;
74 	void *aux;
75 {
76 	struct vme_softc *sc = (struct vme_softc *)self;
77 	struct vmebus_attach_args *vba = aux;
78 
79 	printf("\n");
80 
81 	sc->sc_iot  = vba->vba_iot;
82 	sc->sc_memt = vba->vba_memt;
83 	sc->sc_vc   = vba->vba_vc;
84 
85 	config_search(vmesearch, self, NULL);
86 }
87 
88 int
89 vmeprint(aux, vme)
90 	void *aux;
91 	const char *vme;
92 {
93 	struct vme_attach_args *va = aux;
94 
95 	if (va->va_iosize)
96 		printf(" port 0x%x", va->va_iobase);
97 	if (va->va_iosize > 1)
98 		printf("-0x%x", va->va_iobase + va->va_iosize - 1);
99 	if (va->va_msize)
100 		printf(" iomem 0x%x", va->va_maddr);
101 	if (va->va_msize > 1)
102 		printf("-0x%x", va->va_maddr + va->va_msize - 1);
103 	if (va->va_irq != IRQUNK)
104 		printf(" irq %d", va->va_irq);
105 	return (UNCONF);
106 }
107 
108 int
109 vmesearch(parent, cf, aux)
110 	struct device *parent;
111 	struct cfdata *cf;
112 	void *aux;
113 {
114 	struct vme_softc *sc = (struct vme_softc *)parent;
115 	struct vme_attach_args va;
116 
117 	va.va_iot    = sc->sc_iot;
118 	va.va_memt   = sc->sc_memt;
119 	va.va_vc     = sc->sc_vc;
120 	va.va_iobase = cf->cf_iobase;
121 	va.va_iosize = cf->cf_iosize;
122 	va.va_maddr  = cf->cf_maddr;
123 	va.va_msize  = cf->cf_msize;
124 	va.va_irq    = cf->cf_irq;
125 
126 	if ((*cf->cf_attach->ca_match)(parent, cf, &va) > 0)
127 		config_attach(parent, cf, &va, vmeprint);
128 	return (0);
129 }
130