Home | History | Annotate | Line # | Download | only in vme
vme.c revision 1.20
      1 /*	$NetBSD: vme.c,v 1.20 2022/06/26 05:11:54 tsutsui 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.20 2022/06/26 05:11:54 tsutsui 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 static int vmematch(device_t, cfdata_t, void *);
     44 static void vmeattach(device_t, device_t, void *);
     45 static int vmeprint(void *, const char *);
     46 
     47 CFATTACH_DECL_NEW(vme, sizeof(struct vme_softc),
     48     vmematch, vmeattach, NULL, NULL);
     49 
     50 static int vmesearch(device_t, cfdata_t, const int *, void *);
     51 
     52 static 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 static 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 	aprint_normal("\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 	    CFARGS(.search = vmesearch));
     78 }
     79 
     80 static int
     81 vmeprint(void *aux, const char *vme)
     82 {
     83 	struct vme_attach_args *va = aux;
     84 
     85 	if (va->va_iosize)
     86 		aprint_normal(" port 0x%x", va->va_iobase);
     87 	if (va->va_iosize > 1)
     88 		aprint_normal("-0x%x", va->va_iobase + va->va_iosize - 1);
     89 	if (va->va_msize)
     90 		aprint_normal(" iomem 0x%x", va->va_maddr);
     91 	if (va->va_msize > 1)
     92 		aprint_normal("-0x%x", va->va_maddr + va->va_msize - 1);
     93 	if (va->va_irq != IRQUNK)
     94 		aprint_normal(" irq %d", va->va_irq);
     95 	return UNCONF;
     96 }
     97 
     98 static int
     99 vmesearch(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
    100 {
    101 	struct vme_softc *sc = device_private(parent);
    102 	struct vme_attach_args va;
    103 
    104 	va.va_iot    = sc->sc_iot;
    105 	va.va_memt   = sc->sc_memt;
    106 	va.va_vc     = sc->sc_vc;
    107 	va.va_iobase = cf->cf_iobase;
    108 	va.va_iosize = cf->cf_iosize;
    109 	va.va_maddr  = cf->cf_maddr;
    110 	va.va_msize  = cf->cf_msize;
    111 	va.va_irq    = cf->cf_irq;
    112 
    113 	if (config_probe(parent, cf, &va))
    114 		config_attach(parent, cf, &va, vmeprint, CFARGS_NONE);
    115 	return 0;
    116 }
    117