Home | History | Annotate | Line # | Download | only in hpc
hpcioman.c revision 1.19
      1 /*	$NetBSD: hpcioman.c,v 1.19 2012/10/27 17:18:17 chs Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 1999-2001 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by UCHIYAMA Yasushi.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: hpcioman.c,v 1.19 2012/10/27 17:18:17 chs Exp $");
     34 
     35 #include <sys/param.h>
     36 #include <sys/systm.h>
     37 #include <sys/device.h>
     38 
     39 #include <machine/config_hook.h>
     40 #include <machine/platid.h>
     41 #include <machine/platid_mask.h>
     42 
     43 #include <sys/bus.h>
     44 #include <dev/hpc/hpciovar.h>
     45 #include <dev/hpc/hpciomanvar.h>
     46 
     47 #include "locators.h"
     48 
     49 int	hpcioman_match(device_t, cfdata_t, void *);
     50 void	hpcioman_attach(device_t, device_t, void *);
     51 int	hpcioman_print(void *, const char *);
     52 int	hpcioman_search(device_t, cfdata_t, const int *, void *);
     53 
     54 CFATTACH_DECL_NEW(hpcioman, 0,
     55     hpcioman_match, hpcioman_attach, NULL, NULL);
     56 
     57 int
     58 hpcioman_match(device_t parent, cfdata_t cf, void *aux)
     59 {
     60 	struct hpcio_attach_args *haa = aux;
     61 	platid_mask_t mask;
     62 
     63 	if (strcmp(haa->haa_busname, HPCIO_BUSNAME))
     64 		return (0);
     65 	/* select platform */
     66 	mask = PLATID_DEREF(cf->cf_loc[HPCIOIFCF_PLATFORM]);
     67 
     68 	return (platid_match(&platid, &mask));
     69 }
     70 
     71 void
     72 hpcioman_attach(device_t parent, device_t self, void *aux)
     73 {
     74 	printf("\n");
     75 
     76 	config_search_ia(hpcioman_search, self, "hpcioman", aux);
     77 }
     78 
     79 int
     80 hpcioman_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
     81 {
     82 	struct hpcio_attach_args *haa = aux;
     83 	struct hpcioman_attach_args hma;
     84 
     85 	/* get io chip */
     86 	hma.hma_hc = (*haa->haa_getchip)(haa->haa_sc, cf->cf_iochip);
     87 
     88 	/* interrupt mode */
     89 	if (cf->cf_level != HPCIOMANCF_LEVEL_DEFAULT) {
     90 		switch (cf->cf_hold) {
     91 		case 1:
     92 			hma.hma_intr_mode = HPCIO_INTR_HOLD;
     93 			break;
     94 		case 0:
     95 		case HPCIOMANCF_HOLD_DEFAULT:
     96 		default:
     97 			hma.hma_intr_mode = HPCIO_INTR_THROUGH;
     98 			break;
     99 		}
    100 		hma.hma_intr_mode |= HPCIO_INTR_LEVEL;
    101 		if (cf->cf_level == 0)
    102 			hma.hma_intr_mode |= HPCIO_INTR_LOW;
    103 		else
    104 			hma.hma_intr_mode |= HPCIO_INTR_HIGH;
    105 	} else {
    106 		switch (cf->cf_hold) {
    107 		case 0:
    108 			hma.hma_intr_mode = HPCIO_INTR_THROUGH;
    109 			break;
    110 		case 1:
    111 		case HPCIOMANCF_HOLD_DEFAULT:
    112 		default:
    113 			hma.hma_intr_mode = HPCIO_INTR_HOLD;
    114 			break;
    115 		}
    116 		hma.hma_intr_mode |= HPCIO_INTR_EDGE;
    117 		switch (cf->cf_edge) {
    118 		case 1:
    119 			hma.hma_intr_mode |= HPCIO_INTR_POSEDGE;
    120 			break;
    121 		case 2:
    122 			hma.hma_intr_mode |= HPCIO_INTR_NEGEDGE;
    123 			break;
    124 		case 0:
    125 		case 3:
    126 		case HPCIOMANCF_EDGE_DEFAULT:
    127 			hma.hma_intr_mode |= HPCIO_INTR_POSEDGE;
    128 			hma.hma_intr_mode |= HPCIO_INTR_NEGEDGE;
    129 			break;
    130 		default:
    131 			printf("%s(%d): invalid configuration, edge=%d",
    132 			    __FILE__, __LINE__, cf->cf_edge);
    133 			break;
    134 		}
    135 	}
    136 
    137 	hma.hma_type = cf->cf_type;
    138 	hma.hma_id = cf->cf_id;
    139 	hma.hma_port = cf->cf_port;
    140 	if (cf->cf_active == 0) {
    141 		hma.hma_on = 0;
    142 		hma.hma_off = 1;
    143 	} else {
    144 		hma.hma_on = 1;
    145 		hma.hma_off = 0;
    146 	}
    147 	hma.hma_initvalue = -1; /* none */
    148 	if (cf->cf_initvalue != HPCIOMANCF_INITVALUE_DEFAULT) {
    149 		if (cf->cf_initvalue == 0)
    150 			hma.hma_initvalue = hma.hma_off;
    151 		else
    152 			hma.hma_initvalue = hma.hma_on;
    153 	}
    154 	hma.hma_connect = cf->cf_connect;
    155 
    156 	config_attach(parent, cf, &hma, hpcioman_print);
    157 
    158 	return (0);
    159 }
    160 
    161 int
    162 hpcioman_print(void *aux, const char *pnp)
    163 {
    164 	struct hpcioman_attach_args *hma = aux;
    165 	int type = hma->hma_type;
    166 
    167 	if (!pnp)  {
    168 		aprint_normal(" iochip %s, port %d, type %d, id %d",
    169 		    hma->hma_hc ? hma->hma_hc->hc_name : "not found",
    170 		    hma->hma_port, type, hma->hma_id);
    171 		if (type == CONFIG_HOOK_BUTTONEVENT ||
    172 		    type == CONFIG_HOOK_PMEVENT ||
    173 		    type == CONFIG_HOOK_EVENT ||
    174 		    type == CONFIG_HOOK_PCIINTR) {
    175 			if (hma->hma_intr_mode & HPCIO_INTR_EDGE)
    176 				aprint_normal (", interrupt edge [%s%s]",
    177 				    (hma->hma_intr_mode&HPCIO_INTR_POSEDGE)
    178 				    ? "p" : "",
    179 				    (hma->hma_intr_mode&HPCIO_INTR_NEGEDGE)
    180 				    ? "n" : "");
    181 			else
    182 				aprint_normal (", interrupt level %s",
    183 				    (hma->hma_intr_mode&HPCIO_INTR_HIGH) ?
    184 				    "high" : "low");
    185 		}
    186 		if (hma->hma_initvalue != -1)
    187 			aprint_normal(", initial value %d", hma->hma_initvalue);
    188 		if (hma->hma_on == 0)
    189 			aprint_normal(", active low");
    190 	}
    191 
    192 	return (QUIET);
    193 }
    194