Home | History | Annotate | Line # | Download | only in dev
hb.c revision 1.11.2.3
      1  1.11.2.3    skrll /*	$NetBSD: hb.c,v 1.11.2.3 2004/09/21 13:19:25 skrll Exp $	*/
      2       1.1  tsutsui 
      3       1.1  tsutsui /*-
      4       1.1  tsutsui  * Copyright (C) 1999 Izumi Tsutsui.  All rights reserved.
      5       1.1  tsutsui  *
      6       1.1  tsutsui  * Redistribution and use in source and binary forms, with or without
      7       1.1  tsutsui  * modification, are permitted provided that the following conditions
      8       1.1  tsutsui  * are met:
      9       1.1  tsutsui  * 1. Redistributions of source code must retain the above copyright
     10       1.1  tsutsui  *    notice, this list of conditions and the following disclaimer.
     11       1.1  tsutsui  * 2. Redistributions in binary form must reproduce the above copyright
     12       1.1  tsutsui  *    notice, this list of conditions and the following disclaimer in the
     13       1.1  tsutsui  *    documentation and/or other materials provided with the distribution.
     14       1.1  tsutsui  * 3. The name of the author may not be used to endorse or promote products
     15       1.1  tsutsui  *    derived from this software without specific prior written permission.
     16       1.1  tsutsui  *
     17       1.1  tsutsui  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18       1.1  tsutsui  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19       1.1  tsutsui  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20       1.1  tsutsui  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21       1.1  tsutsui  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22       1.1  tsutsui  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23       1.1  tsutsui  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24       1.1  tsutsui  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25       1.1  tsutsui  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     26       1.1  tsutsui  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27       1.1  tsutsui  */
     28       1.1  tsutsui 
     29  1.11.2.1    skrll #include <sys/cdefs.h>
     30  1.11.2.3    skrll __KERNEL_RCSID(0, "$NetBSD: hb.c,v 1.11.2.3 2004/09/21 13:19:25 skrll Exp $");
     31  1.11.2.1    skrll 
     32       1.1  tsutsui #include <sys/param.h>
     33       1.1  tsutsui #include <sys/systm.h>
     34       1.1  tsutsui #include <sys/device.h>
     35       1.1  tsutsui 
     36       1.1  tsutsui #include <machine/autoconf.h>
     37       1.4  tsutsui #include <machine/bus.h>
     38       1.3  tsutsui #include <machine/cpu.h>
     39       1.1  tsutsui 
     40       1.1  tsutsui #include <news68k/news68k/isr.h>
     41       1.1  tsutsui #include <news68k/dev/hbvar.h>
     42       1.1  tsutsui 
     43  1.11.2.2    skrll #include "ioconf.h"
     44  1.11.2.2    skrll 
     45      1.10  tsutsui static int  hb_match(struct device *, struct cfdata *, void *);
     46      1.10  tsutsui static void hb_attach(struct device *, struct device *, void *);
     47      1.10  tsutsui static int  hb_search(struct device *, struct cfdata *, void *);
     48      1.10  tsutsui static int  hb_print(void *, const char *);
     49       1.1  tsutsui 
     50       1.9  thorpej CFATTACH_DECL(hb, sizeof(struct device),
     51       1.9  thorpej     hb_match, hb_attach, NULL, NULL);
     52       1.1  tsutsui 
     53       1.1  tsutsui static int
     54  1.11.2.2    skrll hb_match(struct device *parent, struct cfdata *cf, void *aux)
     55       1.1  tsutsui {
     56       1.3  tsutsui 	struct mainbus_attach_args *ma = aux;
     57       1.1  tsutsui 
     58       1.3  tsutsui 	if (strcmp(ma->ma_name, hb_cd.cd_name) != 0)
     59       1.3  tsutsui 		return 0;
     60       1.3  tsutsui 
     61       1.3  tsutsui 	if (ma->ma_systype != -1 && ma->ma_systype != systype)
     62       1.1  tsutsui 		return 0;
     63       1.1  tsutsui 
     64       1.1  tsutsui 	return 1;
     65       1.1  tsutsui }
     66       1.1  tsutsui 
     67       1.1  tsutsui static void
     68  1.11.2.2    skrll hb_attach(struct device *parent, struct device *self, void *aux)
     69       1.1  tsutsui {
     70       1.1  tsutsui 	struct hb_attach_args ha;
     71       1.1  tsutsui 
     72       1.1  tsutsui 	printf("\n");
     73       1.5  tsutsui 	memset(&ha, 0, sizeof(ha));
     74       1.1  tsutsui 
     75       1.1  tsutsui 	config_search(hb_search, self, &ha);
     76       1.1  tsutsui }
     77       1.1  tsutsui 
     78       1.1  tsutsui static int
     79  1.11.2.2    skrll hb_search(struct device *parent, struct cfdata *cf, void *aux)
     80       1.1  tsutsui {
     81       1.1  tsutsui 	struct hb_attach_args *ha = aux;
     82       1.1  tsutsui 
     83       1.6  thorpej 	ha->ha_name = cf->cf_name;
     84       1.1  tsutsui 	ha->ha_address = cf->cf_addr;
     85       1.1  tsutsui 	ha->ha_ipl = cf->cf_ipl;
     86       1.1  tsutsui 	ha->ha_vect = cf->cf_vect;
     87       1.4  tsutsui 
     88       1.4  tsutsui 	/* XXX news68k Hyper-bus is not a real bus... */
     89       1.4  tsutsui 	ha->ha_bust = ISIIOPA(ha->ha_address) ?
     90       1.4  tsutsui 	    NEWS68K_BUS_SPACE_INTIO : NEWS68K_BUS_SPACE_EIO;
     91       1.1  tsutsui 
     92       1.7  thorpej 	if (config_match(parent, cf, ha) > 0)
     93       1.1  tsutsui 		config_attach(parent, cf, ha, hb_print);
     94       1.1  tsutsui 
     95       1.1  tsutsui 	return 0;
     96       1.1  tsutsui }
     97       1.1  tsutsui 
     98       1.1  tsutsui /*
     99       1.1  tsutsui  * Print out the confargs.  The (parent) name is non-NULL
    100       1.1  tsutsui  * when there was no match found by config_found().
    101       1.1  tsutsui  */
    102       1.1  tsutsui static int
    103  1.11.2.2    skrll hb_print(void *args, const char *name)
    104       1.1  tsutsui {
    105       1.1  tsutsui 	struct hb_attach_args *ha = args;
    106       1.1  tsutsui 
    107       1.1  tsutsui #if 0
    108       1.1  tsutsui 	if (ha->ha_addr > 0)
    109       1.1  tsutsui #endif
    110      1.11  thorpej 		aprint_normal (" addr 0x%08lx", ha->ha_address);
    111       1.1  tsutsui 	if (ha->ha_ipl > 0)
    112      1.11  thorpej 		aprint_normal (" ipl %d", ha->ha_ipl);
    113       1.1  tsutsui 	if (ha->ha_vect > 0) {
    114      1.11  thorpej 		aprint_normal (" vect %d", ha->ha_vect);
    115       1.1  tsutsui 	}
    116       1.1  tsutsui 
    117  1.11.2.2    skrll 	return QUIET;
    118       1.1  tsutsui }
    119       1.1  tsutsui 
    120       1.1  tsutsui /*
    121       1.1  tsutsui  * hb_intr_establish: establish hb interrupt
    122       1.1  tsutsui  */
    123       1.1  tsutsui void
    124  1.11.2.2    skrll hb_intr_establish(int hbvect, int (*hand)(void *), int ipl, void *arg)
    125       1.1  tsutsui {
    126       1.1  tsutsui 
    127       1.1  tsutsui 	if ((ipl < 1) || (ipl > 7)) {
    128       1.1  tsutsui 		printf("hb: illegal interrupt level: %d\n", ipl);
    129       1.1  tsutsui 		panic("hb_intr_establish");
    130       1.1  tsutsui 	}
    131       1.1  tsutsui 
    132       1.1  tsutsui 	if ((hbvect < 0) || (hbvect > 255)) {
    133       1.2  tsutsui 		printf("hb: illegal vector offset: 0x%x\n", hbvect);
    134       1.2  tsutsui 		panic("hb_intr_establish");
    135       1.1  tsutsui 	}
    136       1.1  tsutsui 
    137       1.1  tsutsui 	isrlink_vectored(hand, arg, ipl, hbvect);
    138       1.1  tsutsui }
    139       1.1  tsutsui 
    140       1.1  tsutsui void
    141  1.11.2.2    skrll hb_intr_disestablish(int hbvect)
    142       1.1  tsutsui {
    143       1.1  tsutsui 
    144       1.1  tsutsui 	if ((hbvect < 0) || (hbvect > 255)) {
    145       1.1  tsutsui 		printf("hb: illegal vector offset: 0x%x\n", hbvect);
    146       1.1  tsutsui 		panic("hb_intr_disestablish");
    147       1.1  tsutsui 	}
    148       1.1  tsutsui 
    149       1.1  tsutsui 	isrunlink_vectored(hbvect);
    150       1.1  tsutsui }
    151