vme.c revision 1.18 1 /* $NetBSD: vme.c,v 1.18 2021/04/24 23:36:30 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 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: vme.c,v 1.18 2021/04/24 23:36:30 thorpej Exp $");
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/kernel.h>
35 #include <sys/conf.h>
36 #include <sys/malloc.h>
37 #include <sys/device.h>
38
39 #include <machine/intr.h>
40
41 #include <atari/vme/vmevar.h>
42
43 int vmematch(device_t, cfdata_t, void *);
44 void vmeattach(device_t, device_t, void *);
45 int vmeprint(void *, const char *);
46
47 CFATTACH_DECL_NEW(vme, sizeof(struct vme_softc),
48 vmematch, vmeattach, NULL, NULL);
49
50 int vmesearch(device_t, cfdata_t, const int *, void *);
51
52 int
53 vmematch(device_t parent, cfdata_t cf, void *aux)
54 {
55 struct vmebus_attach_args *vba = aux;
56
57 if (strcmp(vba->vba_busname, cf->cf_name))
58 return (0);
59
60 return (1);
61 }
62
63 void
64 vmeattach(device_t parent, device_t self, void *aux)
65 {
66 struct vme_softc *sc = device_private(self);
67 struct vmebus_attach_args *vba = aux;
68
69 printf("\n");
70
71 sc->sc_dev = self;
72 sc->sc_iot = vba->vba_iot;
73 sc->sc_memt = vba->vba_memt;
74 sc->sc_vc = vba->vba_vc;
75
76 config_search(self, NULL,
77 CFARG_SEARCH, vmesearch,
78 CFARG_EOL);
79 }
80
81 int
82 vmeprint(void *aux, const char *vme)
83 {
84 struct vme_attach_args *va = aux;
85
86 if (va->va_iosize)
87 aprint_normal(" port 0x%x", va->va_iobase);
88 if (va->va_iosize > 1)
89 aprint_normal("-0x%x", va->va_iobase + va->va_iosize - 1);
90 if (va->va_msize)
91 aprint_normal(" iomem 0x%x", va->va_maddr);
92 if (va->va_msize > 1)
93 aprint_normal("-0x%x", va->va_maddr + va->va_msize - 1);
94 if (va->va_irq != IRQUNK)
95 aprint_normal(" irq %d", va->va_irq);
96 return (UNCONF);
97 }
98
99 int
100 vmesearch(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
101 {
102 struct vme_softc *sc = device_private(parent);
103 struct vme_attach_args va;
104
105 va.va_iot = sc->sc_iot;
106 va.va_memt = sc->sc_memt;
107 va.va_vc = sc->sc_vc;
108 va.va_iobase = cf->cf_iobase;
109 va.va_iosize = cf->cf_iosize;
110 va.va_maddr = cf->cf_maddr;
111 va.va_msize = cf->cf_msize;
112 va.va_irq = cf->cf_irq;
113
114 if (config_probe(parent, cf, &va))
115 config_attach(parent, cf, &va, vmeprint, CFARG_EOL);
116 return (0);
117 }
118