Home | History | Annotate | Line # | Download | only in gio
gio.c revision 1.2
      1  1.2  simonb /*	$NetBSD: gio.c,v 1.2 2002/03/13 13:12:27 simonb Exp $	*/
      2  1.1   soren 
      3  1.1   soren /*
      4  1.1   soren  * Copyright (c) 2000 Soren S. Jorvang
      5  1.1   soren  * All rights reserved.
      6  1.2  simonb  *
      7  1.1   soren  * Redistribution and use in source and binary forms, with or without
      8  1.1   soren  * modification, are permitted provided that the following conditions
      9  1.1   soren  * are met:
     10  1.1   soren  * 1. Redistributions of source code must retain the above copyright
     11  1.1   soren  *    notice, this list of conditions and the following disclaimer.
     12  1.1   soren  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1   soren  *    notice, this list of conditions and the following disclaimer in the
     14  1.1   soren  *    documentation and/or other materials provided with the distribution.
     15  1.1   soren  * 3. All advertising materials mentioning features or use of this software
     16  1.1   soren  *    must display the following acknowledgement:
     17  1.1   soren  *          This product includes software developed for the
     18  1.1   soren  *          NetBSD Project.  See http://www.netbsd.org/ for
     19  1.1   soren  *          information about NetBSD.
     20  1.1   soren  * 4. The name of the author may not be used to endorse or promote products
     21  1.1   soren  *    derived from this software without specific prior written permission.
     22  1.2  simonb  *
     23  1.1   soren  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     24  1.1   soren  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     25  1.1   soren  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     26  1.1   soren  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     27  1.1   soren  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     28  1.1   soren  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     29  1.1   soren  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     30  1.1   soren  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     31  1.1   soren  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     32  1.1   soren  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     33  1.1   soren  */
     34  1.1   soren 
     35  1.1   soren #include "opt_ddb.h"
     36  1.1   soren 
     37  1.1   soren #include <sys/param.h>
     38  1.1   soren #include <sys/systm.h>
     39  1.1   soren #include <sys/device.h>
     40  1.1   soren 
     41  1.1   soren #include <sgimips/gio/gioreg.h>
     42  1.1   soren #include <sgimips/gio/giovar.h>
     43  1.1   soren 
     44  1.1   soren #include "locators.h"
     45  1.1   soren 
     46  1.1   soren struct gio_softc {
     47  1.1   soren 	struct	device sc_dev;
     48  1.1   soren };
     49  1.1   soren 
     50  1.1   soren static int	gio_match(struct device *, struct cfdata *, void *);
     51  1.1   soren static void	gio_attach(struct device *, struct device *, void *);
     52  1.1   soren static int	gio_print(void *, const char *);
     53  1.1   soren static int	gio_search(struct device *, struct cfdata *, void *);
     54  1.1   soren 
     55  1.1   soren struct cfattach gio_ca = {
     56  1.2  simonb 	sizeof(struct gio_softc), gio_match, gio_attach
     57  1.1   soren };
     58  1.1   soren 
     59  1.1   soren static int
     60  1.1   soren gio_match(parent, match, aux)
     61  1.1   soren 	struct device *parent;
     62  1.1   soren 	struct cfdata *match;
     63  1.2  simonb 	void *aux;
     64  1.1   soren {
     65  1.1   soren 	struct giobus_attach_args *gba = aux;
     66  1.1   soren 
     67  1.1   soren 	if (strcmp(gba->gba_busname, match->cf_driver->cd_name) != 0)
     68  1.1   soren 		return 0;
     69  1.1   soren 
     70  1.2  simonb 	return 1;
     71  1.1   soren }
     72  1.1   soren 
     73  1.1   soren static void
     74  1.1   soren gio_attach(parent, self, aux)
     75  1.1   soren 	struct device *parent;
     76  1.1   soren 	struct device *self;
     77  1.1   soren 	void *aux;
     78  1.1   soren {
     79  1.1   soren 	struct gio_attach_args ga;
     80  1.1   soren 
     81  1.1   soren 	printf("\n");
     82  1.1   soren 
     83  1.1   soren 	config_search(gio_search, self, &ga);
     84  1.1   soren }
     85  1.1   soren 
     86  1.1   soren static int
     87  1.1   soren gio_print(aux, pnp)
     88  1.1   soren 	void *aux;
     89  1.1   soren 	const char *pnp;
     90  1.1   soren {
     91  1.1   soren 	struct gio_attach_args *ga = aux;
     92  1.1   soren 
     93  1.1   soren 	if (pnp != 0)
     94  1.1   soren 		return QUIET;
     95  1.1   soren 
     96  1.1   soren 	if (ga->ga_slot != GIOCF_SLOT_DEFAULT)
     97  1.1   soren 		printf(" slot %d", ga->ga_slot);
     98  1.1   soren 	if (ga->ga_addr != GIOCF_ADDR_DEFAULT)
     99  1.1   soren 		printf(" addr 0x%x", ga->ga_addr);
    100  1.1   soren 
    101  1.1   soren 	return UNCONF;
    102  1.1   soren }
    103  1.1   soren 
    104  1.1   soren static int
    105  1.1   soren gio_search(parent, cf, aux)
    106  1.1   soren 	struct device *parent;
    107  1.2  simonb 	struct cfdata *cf;
    108  1.1   soren 	void *aux;
    109  1.2  simonb {
    110  1.1   soren 	struct gio_attach_args *ga = aux;
    111  1.1   soren 
    112  1.1   soren 	do {
    113  1.1   soren 		ga->ga_slot = cf->cf_loc[GIOCF_SLOT];
    114  1.1   soren 		ga->ga_addr = cf->cf_loc[GIOCF_ADDR];
    115  1.1   soren 		ga->ga_iot = 0;
    116  1.1   soren 		ga->ga_ioh = MIPS_PHYS_TO_KSEG1(ga->ga_addr);
    117  1.1   soren 		if ((*cf->cf_attach->ca_match)(parent, cf, ga) > 0)
    118  1.1   soren 			config_attach(parent, cf, ga, gio_print);
    119  1.1   soren 	} while (cf->cf_fstate == FSTATE_STAR);
    120  1.1   soren 
    121  1.1   soren 	return 0;
    122  1.1   soren }
    123