Home | History | Annotate | Line # | Download | only in dev
hb.c revision 1.1
      1  1.1  tsutsui /*	$NetBSD: hb.c,v 1.1 1999/12/09 14:53:04 tsutsui 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.1  tsutsui #include <sys/param.h>
     30  1.1  tsutsui #include <sys/systm.h>
     31  1.1  tsutsui #include <sys/device.h>
     32  1.1  tsutsui 
     33  1.1  tsutsui #include <machine/autoconf.h>
     34  1.1  tsutsui 
     35  1.1  tsutsui #include <news68k/news68k/isr.h>
     36  1.1  tsutsui #include <news68k/dev/hbvar.h>
     37  1.1  tsutsui 
     38  1.1  tsutsui static int	hb_match __P((struct device *, struct cfdata *, void *));
     39  1.1  tsutsui static void	hb_attach __P((struct device *, struct device *, void *));
     40  1.1  tsutsui static int	hb_search __P((struct device *, struct cfdata *, void *));
     41  1.1  tsutsui static int	hb_print __P((void *, const char *));
     42  1.1  tsutsui 
     43  1.1  tsutsui struct cfattach hb_ca = {
     44  1.1  tsutsui 	sizeof(struct device), hb_match, hb_attach
     45  1.1  tsutsui };
     46  1.1  tsutsui 
     47  1.1  tsutsui extern struct cfdriver hb_cd;
     48  1.1  tsutsui 
     49  1.1  tsutsui static int
     50  1.1  tsutsui hb_match(parent, cf, aux)
     51  1.1  tsutsui 	struct device *parent;
     52  1.1  tsutsui 	struct cfdata *cf;
     53  1.1  tsutsui 	void *aux;
     54  1.1  tsutsui {
     55  1.1  tsutsui 	char *ma_name = aux;
     56  1.1  tsutsui 
     57  1.1  tsutsui 	if (strcmp(ma_name, hb_cd.cd_name) != 0)
     58  1.1  tsutsui 		return 0;
     59  1.1  tsutsui 
     60  1.1  tsutsui 	return 1;
     61  1.1  tsutsui }
     62  1.1  tsutsui 
     63  1.1  tsutsui static void
     64  1.1  tsutsui hb_attach(parent, self, aux)
     65  1.1  tsutsui 	struct device *parent;
     66  1.1  tsutsui 	struct device *self;
     67  1.1  tsutsui 	void *aux;
     68  1.1  tsutsui {
     69  1.1  tsutsui 	struct hb_attach_args ha;
     70  1.1  tsutsui 
     71  1.1  tsutsui 	printf("\n");
     72  1.1  tsutsui 	bzero(&ha, sizeof(ha));
     73  1.1  tsutsui 
     74  1.1  tsutsui 	config_search(hb_search, self, &ha);
     75  1.1  tsutsui }
     76  1.1  tsutsui 
     77  1.1  tsutsui static int
     78  1.1  tsutsui hb_search(parent, cf, aux)
     79  1.1  tsutsui 	struct device *parent;
     80  1.1  tsutsui 	struct cfdata *cf;
     81  1.1  tsutsui 	void *aux;
     82  1.1  tsutsui {
     83  1.1  tsutsui 	struct hb_attach_args *ha = aux;
     84  1.1  tsutsui 
     85  1.1  tsutsui 	ha->ha_name = cf->cf_driver->cd_name;
     86  1.1  tsutsui 	ha->ha_address = cf->cf_addr;
     87  1.1  tsutsui 	ha->ha_ipl = cf->cf_ipl;
     88  1.1  tsutsui 	ha->ha_vect = cf->cf_vect;
     89  1.1  tsutsui 
     90  1.1  tsutsui 	if ((*cf->cf_attach->ca_match)(parent, cf, ha) > 0)
     91  1.1  tsutsui 		config_attach(parent, cf, ha, hb_print);
     92  1.1  tsutsui 
     93  1.1  tsutsui 	return 0;
     94  1.1  tsutsui }
     95  1.1  tsutsui 
     96  1.1  tsutsui /*
     97  1.1  tsutsui  * Print out the confargs.  The (parent) name is non-NULL
     98  1.1  tsutsui  * when there was no match found by config_found().
     99  1.1  tsutsui  */
    100  1.1  tsutsui static int
    101  1.1  tsutsui hb_print(args, name)
    102  1.1  tsutsui 	void *args;
    103  1.1  tsutsui 	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.1  tsutsui 		printf (" addr 0x%08lx", ha->ha_address);
    111  1.1  tsutsui 	if (ha->ha_ipl > 0)
    112  1.1  tsutsui 		printf (" ipl %d", ha->ha_ipl);
    113  1.1  tsutsui 	if (ha->ha_vect > 0) {
    114  1.1  tsutsui 		printf (" vect %d", ha->ha_vect);
    115  1.1  tsutsui 	}
    116  1.1  tsutsui 
    117  1.1  tsutsui 	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.1  tsutsui hb_intr_establish(hbvect, hand, ipl, arg)
    125  1.1  tsutsui 	int hbvect;
    126  1.1  tsutsui 	int (*hand) __P((void *)), ipl;
    127  1.1  tsutsui 	void *arg;
    128  1.1  tsutsui {
    129  1.1  tsutsui 
    130  1.1  tsutsui 	if ((ipl < 1) || (ipl > 7)) {
    131  1.1  tsutsui 		printf("hb: illegal interrupt level: %d\n", ipl);
    132  1.1  tsutsui 		panic("hb_intr_establish");
    133  1.1  tsutsui 	}
    134  1.1  tsutsui 
    135  1.1  tsutsui 	if ((hbvect < 0) || (hbvect > 255)) {
    136  1.1  tsutsui 		printf("pcc: illegal vector offset: 0x%x\n", hbvect);
    137  1.1  tsutsui 		panic("pccintr_establish");
    138  1.1  tsutsui 	}
    139  1.1  tsutsui 
    140  1.1  tsutsui 	isrlink_vectored(hand, arg, ipl, hbvect);
    141  1.1  tsutsui }
    142  1.1  tsutsui 
    143  1.1  tsutsui void
    144  1.1  tsutsui hb_intr_disestablish(hbvect)
    145  1.1  tsutsui 	int hbvect;
    146  1.1  tsutsui {
    147  1.1  tsutsui 
    148  1.1  tsutsui 	if ((hbvect < 0) || (hbvect > 255)) {
    149  1.1  tsutsui 		printf("hb: illegal vector offset: 0x%x\n", hbvect);
    150  1.1  tsutsui 		panic("hb_intr_disestablish");
    151  1.1  tsutsui 	}
    152  1.1  tsutsui 
    153  1.1  tsutsui 	isrunlink_vectored(hbvect);
    154  1.1  tsutsui }
    155