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