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