Home | History | Annotate | Line # | Download | only in vme
      1  1.21  thorpej /*	$NetBSD: vme.c,v 1.21 2023/12/20 00:40:43 thorpej Exp $	*/
      2   1.1      leo 
      3   1.1      leo /*-
      4   1.1      leo  * Copyright (c) 1997 The NetBSD Foundation, Inc.
      5   1.1      leo  * All rights reserved.
      6   1.1      leo  *
      7   1.1      leo  * Redistribution and use in source and binary forms, with or without
      8   1.1      leo  * modification, are permitted provided that the following conditions
      9   1.1      leo  * are met:
     10   1.1      leo  * 1. Redistributions of source code must retain the above copyright
     11   1.1      leo  *    notice, this list of conditions and the following disclaimer.
     12   1.1      leo  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1      leo  *    notice, this list of conditions and the following disclaimer in the
     14   1.1      leo  *    documentation and/or other materials provided with the distribution.
     15   1.1      leo  *
     16   1.1      leo  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17   1.1      leo  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18   1.1      leo  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19   1.2      jtc  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20   1.2      jtc  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21   1.1      leo  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22   1.1      leo  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23   1.1      leo  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24   1.1      leo  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25   1.1      leo  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26   1.1      leo  * POSSIBILITY OF SUCH DAMAGE.
     27   1.1      leo  */
     28   1.9    lukem 
     29   1.9    lukem #include <sys/cdefs.h>
     30  1.21  thorpej __KERNEL_RCSID(0, "$NetBSD: vme.c,v 1.21 2023/12/20 00:40:43 thorpej Exp $");
     31   1.1      leo 
     32   1.1      leo #include <sys/param.h>
     33   1.1      leo #include <sys/systm.h>
     34   1.1      leo #include <sys/kernel.h>
     35   1.1      leo #include <sys/conf.h>
     36   1.1      leo #include <sys/device.h>
     37   1.1      leo 
     38   1.1      leo #include <machine/intr.h>
     39   1.1      leo 
     40   1.1      leo #include <atari/vme/vmevar.h>
     41   1.1      leo 
     42  1.20  tsutsui static int vmematch(device_t, cfdata_t, void *);
     43  1.20  tsutsui static void vmeattach(device_t, device_t, void *);
     44  1.20  tsutsui static int vmeprint(void *, const char *);
     45   1.1      leo 
     46  1.17  tsutsui CFATTACH_DECL_NEW(vme, sizeof(struct vme_softc),
     47   1.7  thorpej     vmematch, vmeattach, NULL, NULL);
     48   1.1      leo 
     49  1.20  tsutsui static int vmesearch(device_t, cfdata_t, const int *, void *);
     50   1.1      leo 
     51  1.20  tsutsui static int
     52  1.17  tsutsui vmematch(device_t parent, cfdata_t cf, void *aux)
     53   1.1      leo {
     54   1.1      leo 	struct vmebus_attach_args *vba = aux;
     55   1.1      leo 
     56   1.4  thorpej 	if (strcmp(vba->vba_busname, cf->cf_name))
     57  1.20  tsutsui 		return 0;
     58   1.1      leo 
     59  1.20  tsutsui         return 1;
     60   1.1      leo }
     61   1.1      leo 
     62  1.20  tsutsui static void
     63  1.17  tsutsui vmeattach(device_t parent, device_t self, void *aux)
     64   1.1      leo {
     65  1.17  tsutsui 	struct vme_softc *sc = device_private(self);
     66   1.1      leo 	struct vmebus_attach_args *vba = aux;
     67   1.1      leo 
     68  1.20  tsutsui 	aprint_normal("\n");
     69   1.1      leo 
     70  1.17  tsutsui 	sc->sc_dev = self;
     71   1.1      leo 	sc->sc_iot  = vba->vba_iot;
     72   1.1      leo 	sc->sc_memt = vba->vba_memt;
     73   1.1      leo 	sc->sc_vc   = vba->vba_vc;
     74   1.1      leo 
     75  1.18  thorpej 	config_search(self, NULL,
     76  1.19  thorpej 	    CFARGS(.search = vmesearch));
     77   1.1      leo }
     78   1.1      leo 
     79  1.20  tsutsui static int
     80  1.15      dsl vmeprint(void *aux, const char *vme)
     81   1.1      leo {
     82   1.1      leo 	struct vme_attach_args *va = aux;
     83   1.1      leo 
     84   1.1      leo 	if (va->va_iosize)
     85   1.8  thorpej 		aprint_normal(" port 0x%x", va->va_iobase);
     86   1.1      leo 	if (va->va_iosize > 1)
     87   1.8  thorpej 		aprint_normal("-0x%x", va->va_iobase + va->va_iosize - 1);
     88   1.1      leo 	if (va->va_msize)
     89   1.8  thorpej 		aprint_normal(" iomem 0x%x", va->va_maddr);
     90   1.1      leo 	if (va->va_msize > 1)
     91   1.8  thorpej 		aprint_normal("-0x%x", va->va_maddr + va->va_msize - 1);
     92   1.1      leo 	if (va->va_irq != IRQUNK)
     93   1.8  thorpej 		aprint_normal(" irq %d", va->va_irq);
     94  1.20  tsutsui 	return UNCONF;
     95   1.1      leo }
     96   1.1      leo 
     97  1.20  tsutsui static int
     98  1.17  tsutsui vmesearch(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
     99   1.1      leo {
    100  1.17  tsutsui 	struct vme_softc *sc = device_private(parent);
    101   1.1      leo 	struct vme_attach_args va;
    102   1.1      leo 
    103   1.1      leo 	va.va_iot    = sc->sc_iot;
    104   1.1      leo 	va.va_memt   = sc->sc_memt;
    105   1.1      leo 	va.va_vc     = sc->sc_vc;
    106   1.1      leo 	va.va_iobase = cf->cf_iobase;
    107   1.1      leo 	va.va_iosize = cf->cf_iosize;
    108   1.1      leo 	va.va_maddr  = cf->cf_maddr;
    109   1.1      leo 	va.va_msize  = cf->cf_msize;
    110   1.1      leo 	va.va_irq    = cf->cf_irq;
    111   1.1      leo 
    112  1.18  thorpej 	if (config_probe(parent, cf, &va))
    113  1.19  thorpej 		config_attach(parent, cf, &va, vmeprint, CFARGS_NONE);
    114  1.20  tsutsui 	return 0;
    115   1.1      leo }
    116