xref: /netbsd/sys/arch/atari/vme/vme.c (revision c4a72b64)
1 /*	$NetBSD: vme.c,v 1.7 2002/10/02 05:04:27 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 CFATTACH_DECL(vme, sizeof(struct vme_softc),
52     vmematch, vmeattach, NULL, NULL);
53 
54 int	vmesearch __P((struct device *, struct cfdata *, void *));
55 
56 int
57 vmematch(parent, cf, aux)
58 	struct device *parent;
59 	struct cfdata *cf;
60 	void *aux;
61 {
62 	struct vmebus_attach_args *vba = aux;
63 
64 	if (strcmp(vba->vba_busname, cf->cf_name))
65 		return (0);
66 
67         return (1);
68 }
69 
70 void
71 vmeattach(parent, self, aux)
72 	struct device *parent, *self;
73 	void *aux;
74 {
75 	struct vme_softc *sc = (struct vme_softc *)self;
76 	struct vmebus_attach_args *vba = aux;
77 
78 	printf("\n");
79 
80 	sc->sc_iot  = vba->vba_iot;
81 	sc->sc_memt = vba->vba_memt;
82 	sc->sc_vc   = vba->vba_vc;
83 
84 	config_search(vmesearch, self, NULL);
85 }
86 
87 int
88 vmeprint(aux, vme)
89 	void *aux;
90 	const char *vme;
91 {
92 	struct vme_attach_args *va = aux;
93 
94 	if (va->va_iosize)
95 		printf(" port 0x%x", va->va_iobase);
96 	if (va->va_iosize > 1)
97 		printf("-0x%x", va->va_iobase + va->va_iosize - 1);
98 	if (va->va_msize)
99 		printf(" iomem 0x%x", va->va_maddr);
100 	if (va->va_msize > 1)
101 		printf("-0x%x", va->va_maddr + va->va_msize - 1);
102 	if (va->va_irq != IRQUNK)
103 		printf(" irq %d", va->va_irq);
104 	return (UNCONF);
105 }
106 
107 int
108 vmesearch(parent, cf, aux)
109 	struct device *parent;
110 	struct cfdata *cf;
111 	void *aux;
112 {
113 	struct vme_softc *sc = (struct vme_softc *)parent;
114 	struct vme_attach_args va;
115 
116 	va.va_iot    = sc->sc_iot;
117 	va.va_memt   = sc->sc_memt;
118 	va.va_vc     = sc->sc_vc;
119 	va.va_iobase = cf->cf_iobase;
120 	va.va_iosize = cf->cf_iosize;
121 	va.va_maddr  = cf->cf_maddr;
122 	va.va_msize  = cf->cf_msize;
123 	va.va_irq    = cf->cf_irq;
124 
125 	if (config_match(parent, cf, &va) > 0)
126 		config_attach(parent, cf, &va, vmeprint);
127 	return (0);
128 }
129