Home | History | Annotate | Line # | Download | only in dev
hb.c revision 1.5.2.1
      1 /*	$NetBSD: hb.c,v 1.5.2.1 2002/10/10 18:34:28 jdolecek 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 CFATTACH_DECL(hb, sizeof(struct device),
     46     hb_match, hb_attach, NULL, NULL);
     47 
     48 extern struct cfdriver hb_cd;
     49 
     50 static int
     51 hb_match(parent, cf, aux)
     52 	struct device *parent;
     53 	struct cfdata *cf;
     54 	void *aux;
     55 {
     56 	struct mainbus_attach_args *ma = aux;
     57 
     58 	if (strcmp(ma->ma_name, hb_cd.cd_name) != 0)
     59 		return 0;
     60 
     61 	if (ma->ma_systype != -1 && ma->ma_systype != systype)
     62 		return 0;
     63 
     64 	return 1;
     65 }
     66 
     67 static void
     68 hb_attach(parent, self, aux)
     69 	struct device *parent;
     70 	struct device *self;
     71 	void *aux;
     72 {
     73 	struct hb_attach_args ha;
     74 
     75 	printf("\n");
     76 	memset(&ha, 0, sizeof(ha));
     77 
     78 	config_search(hb_search, self, &ha);
     79 }
     80 
     81 static int
     82 hb_search(parent, cf, aux)
     83 	struct device *parent;
     84 	struct cfdata *cf;
     85 	void *aux;
     86 {
     87 	struct hb_attach_args *ha = aux;
     88 
     89 	ha->ha_name = cf->cf_name;
     90 	ha->ha_address = cf->cf_addr;
     91 	ha->ha_ipl = cf->cf_ipl;
     92 	ha->ha_vect = cf->cf_vect;
     93 
     94 	/* XXX news68k Hyper-bus is not a real bus... */
     95 	ha->ha_bust = ISIIOPA(ha->ha_address) ?
     96 	    NEWS68K_BUS_SPACE_INTIO : NEWS68K_BUS_SPACE_EIO;
     97 
     98 	if (config_match(parent, cf, ha) > 0)
     99 		config_attach(parent, cf, ha, hb_print);
    100 
    101 	return 0;
    102 }
    103 
    104 /*
    105  * Print out the confargs.  The (parent) name is non-NULL
    106  * when there was no match found by config_found().
    107  */
    108 static int
    109 hb_print(args, name)
    110 	void *args;
    111 	const char *name;
    112 {
    113 	struct hb_attach_args *ha = args;
    114 
    115 #if 0
    116 	if (ha->ha_addr > 0)
    117 #endif
    118 		printf (" addr 0x%08lx", ha->ha_address);
    119 	if (ha->ha_ipl > 0)
    120 		printf (" ipl %d", ha->ha_ipl);
    121 	if (ha->ha_vect > 0) {
    122 		printf (" vect %d", ha->ha_vect);
    123 	}
    124 
    125 	return (QUIET);
    126 }
    127 
    128 /*
    129  * hb_intr_establish: establish hb interrupt
    130  */
    131 void
    132 hb_intr_establish(hbvect, hand, ipl, arg)
    133 	int hbvect;
    134 	int (*hand) __P((void *)), ipl;
    135 	void *arg;
    136 {
    137 
    138 	if ((ipl < 1) || (ipl > 7)) {
    139 		printf("hb: illegal interrupt level: %d\n", ipl);
    140 		panic("hb_intr_establish");
    141 	}
    142 
    143 	if ((hbvect < 0) || (hbvect > 255)) {
    144 		printf("hb: illegal vector offset: 0x%x\n", hbvect);
    145 		panic("hb_intr_establish");
    146 	}
    147 
    148 	isrlink_vectored(hand, arg, ipl, hbvect);
    149 }
    150 
    151 void
    152 hb_intr_disestablish(hbvect)
    153 	int hbvect;
    154 {
    155 
    156 	if ((hbvect < 0) || (hbvect > 255)) {
    157 		printf("hb: illegal vector offset: 0x%x\n", hbvect);
    158 		panic("hb_intr_disestablish");
    159 	}
    160 
    161 	isrunlink_vectored(hbvect);
    162 }
    163