1/* $NetBSD: vme.c,v 1.21 2023/12/20 00:40:43 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.21 2023/12/20 00:40:43 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/device.h> 37 38#include <machine/intr.h> 39 40#include <atari/vme/vmevar.h> 41 42static int vmematch(device_t, cfdata_t, void *); 43static void vmeattach(device_t, device_t, void *); 44static int vmeprint(void *, const char *); 45 46CFATTACH_DECL_NEW(vme, sizeof(struct vme_softc), 47 vmematch, vmeattach, NULL, NULL); 48 49static int vmesearch(device_t, cfdata_t, const int *, void *); 50 51static int 52vmematch(device_t parent, cfdata_t cf, void *aux) 53{ 54 struct vmebus_attach_args *vba = aux; 55 56 if (strcmp(vba->vba_busname, cf->cf_name)) 57 return 0; 58 59 return 1; 60} 61 62static void 63vmeattach(device_t parent, device_t self, void *aux) 64{ 65 struct vme_softc *sc = device_private(self); 66 struct vmebus_attach_args *vba = aux; 67 68 aprint_normal("\n"); 69 70 sc->sc_dev = self; 71 sc->sc_iot = vba->vba_iot; 72 sc->sc_memt = vba->vba_memt; 73 sc->sc_vc = vba->vba_vc; 74 75 config_search(self, NULL, 76 CFARGS(.search = vmesearch)); 77} 78 79static int 80vmeprint(void *aux, const char *vme) 81{ 82 struct vme_attach_args *va = aux; 83 84 if (va->va_iosize) 85 aprint_normal(" port 0x%x", va->va_iobase); 86 if (va->va_iosize > 1) 87 aprint_normal("-0x%x", va->va_iobase + va->va_iosize - 1); 88 if (va->va_msize) 89 aprint_normal(" iomem 0x%x", va->va_maddr); 90 if (va->va_msize > 1) 91 aprint_normal("-0x%x", va->va_maddr + va->va_msize - 1); 92 if (va->va_irq != IRQUNK) 93 aprint_normal(" irq %d", va->va_irq); 94 return UNCONF; 95} 96 97static int 98vmesearch(device_t parent, cfdata_t cf, const int *ldesc, void *aux) 99{ 100 struct vme_softc *sc = device_private(parent); 101 struct vme_attach_args va; 102 103 va.va_iot = sc->sc_iot; 104 va.va_memt = sc->sc_memt; 105 va.va_vc = sc->sc_vc; 106 va.va_iobase = cf->cf_iobase; 107 va.va_iosize = cf->cf_iosize; 108 va.va_maddr = cf->cf_maddr; 109 va.va_msize = cf->cf_msize; 110 va.va_irq = cf->cf_irq; 111 112 if (config_probe(parent, cf, &va)) 113 config_attach(parent, cf, &va, vmeprint, CFARGS_NONE); 114 return 0; 115} 116