Home | History | Annotate | Line # | Download | only in obio
obio.c revision 1.15
      1 /*	$NetBSD: obio.c,v 1.15 2009/03/14 15:36:10 dsl Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Wayne Knowles
      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: obio.c,v 1.15 2009/03/14 15:36:10 dsl Exp $");
     34 
     35 #include "locators.h"
     36 
     37 #include <sys/param.h>
     38 #include <sys/systm.h>
     39 #include <sys/device.h>
     40 
     41 #include <machine/autoconf.h>
     42 #include <machine/mainboard.h>
     43 #include <machine/bus.h>
     44 #include <machine/sysconf.h>
     45 
     46 static int	obio_match(struct device *, struct cfdata *, void *);
     47 static void	obio_attach(struct device *, struct device *, void *);
     48 static int	obio_search(struct device *, struct cfdata *,
     49 				 const int *, void *);
     50 static int	obio_print(void *, const char *);
     51 static void	obio_intr_establish(bus_space_tag_t, int, int, int,
     52 					  int (*)(void *), void *);
     53 
     54 CFATTACH_DECL(obio, sizeof(struct device),
     55     obio_match, obio_attach, NULL, NULL);
     56 
     57 extern struct cfdriver obio_cd;
     58 
     59 struct mipsco_bus_space obio_bustag;
     60 struct mipsco_bus_dma_tag obio_dmatag;
     61 
     62 static int
     63 obio_match(struct device *parent, struct cfdata *cf, void *aux)
     64 {
     65 	struct confargs *ca = aux;
     66 
     67 	if (strcmp(ca->ca_name, obio_cd.cd_name) != 0)
     68 		return 0;
     69 
     70 	return 1;
     71 }
     72 
     73 static void
     74 obio_attach(struct device *parent, struct device *self, void *aux)
     75 {
     76 	struct confargs *ca = aux;
     77 
     78 	/* PIZAZZ (Mips 3000 Magnum)  Address Map */
     79 	mipsco_bus_space_init(&obio_bustag, "obio",
     80 			      0x18000000, 0xb8000000,
     81 			      0xb8000000, 0x08000000);
     82 
     83 	_bus_dma_tag_init(&obio_dmatag);
     84 	obio_bustag.bs_intr_establish = obio_intr_establish; /* XXX */
     85 
     86 	ca->ca_bustag = &obio_bustag;
     87 	ca->ca_dmatag = &obio_dmatag;
     88 
     89 	printf("\n");
     90 	config_search_ia(obio_search, self, "obio", ca);
     91 }
     92 
     93 static int
     94 obio_search(struct device *parent, struct cfdata *cf, const int *ldesc, void *aux)
     95 {
     96 	struct confargs *ca = aux;
     97 
     98 	ca->ca_addr = cf->cf_addr;
     99 	ca->ca_name = cf->cf_name;
    100 
    101 	if (config_match(parent, cf, ca) != 0)
    102 		config_attach(parent, cf, ca, obio_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 obio_print(void *args, const char *name)
    113 {
    114 	struct confargs *ca = args;
    115 
    116 	if (name)
    117 		return(QUIET);
    118 
    119 	if (ca->ca_addr != -1)
    120 		aprint_normal(" addr 0x%x", ca->ca_addr);
    121 
    122 	return(UNCONF);
    123 }
    124 
    125 void
    126 obio_intr_establish(bst, level, pri, flags, func, arg)
    127 	bus_space_tag_t bst;
    128 	int level;
    129 	int pri;
    130 	int flags;
    131 	int (*func)(void *);
    132 	void *arg;
    133 {
    134 	(*platform.intr_establish)(level, func, arg);
    135 }
    136