Home | History | Annotate | Line # | Download | only in ebus
ebus.c revision 1.1
      1  1.1  pooka /*	$NetBSD: ebus.c,v 1.1 2011/01/26 01:18:50 pooka Exp $	*/
      2  1.1  pooka 
      3  1.1  pooka /*-
      4  1.1  pooka  * Copyright (c) 2010 The NetBSD Foundation, Inc.
      5  1.1  pooka  * All rights reserved.
      6  1.1  pooka  *
      7  1.1  pooka  * This code was written by Alessandro Forin and Neil Pittman
      8  1.1  pooka  * at Microsoft Research and contributed to The NetBSD Foundation
      9  1.1  pooka  * by Microsoft Corporation.
     10  1.1  pooka  *
     11  1.1  pooka  * Redistribution and use in source and binary forms, with or without
     12  1.1  pooka  * modification, are permitted provided that the following conditions
     13  1.1  pooka  * are met:
     14  1.1  pooka  * 1. Redistributions of source code must retain the above copyright
     15  1.1  pooka  *    notice, this list of conditions and the following disclaimer.
     16  1.1  pooka  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1  pooka  *    notice, this list of conditions and the following disclaimer in the
     18  1.1  pooka  *    documentation and/or other materials provided with the distribution.
     19  1.1  pooka  *
     20  1.1  pooka  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21  1.1  pooka  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  1.1  pooka  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  1.1  pooka  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24  1.1  pooka  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  1.1  pooka  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  1.1  pooka  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  1.1  pooka  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  1.1  pooka  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  1.1  pooka  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  1.1  pooka  * POSSIBILITY OF SUCH DAMAGE.
     31  1.1  pooka  */
     32  1.1  pooka 
     33  1.1  pooka #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     34  1.1  pooka __KERNEL_RCSID(0, "$NetBSD: ebus.c,v 1.1 2011/01/26 01:18:50 pooka Exp $");
     35  1.1  pooka 
     36  1.1  pooka #include <sys/param.h>
     37  1.1  pooka #include <sys/systm.h>
     38  1.1  pooka #include <sys/device.h>
     39  1.1  pooka 
     40  1.1  pooka #include <machine/sysconf.h>
     41  1.1  pooka #include <emips/ebus/ebusvar.h>
     42  1.1  pooka #include <emips/emips/machdep.h>
     43  1.1  pooka 
     44  1.1  pooka #include "locators.h"
     45  1.1  pooka 
     46  1.1  pooka void
     47  1.1  pooka ebusattach(parent, self, aux)
     48  1.1  pooka 	struct device *parent, *self;
     49  1.1  pooka 	void *aux;
     50  1.1  pooka {
     51  1.1  pooka 	struct ebus_dev_attach_args *ida = aux;
     52  1.1  pooka 	struct ebus_attach_args *ia;
     53  1.1  pooka     void *addr;
     54  1.1  pooka 	int i;
     55  1.1  pooka 	int locs[EBUSCF_NLOCS];
     56  1.1  pooka 
     57  1.1  pooka 	printf("\n");
     58  1.1  pooka 
     59  1.1  pooka 	/*
     60  1.1  pooka 	 * Loop through the devices and attach them.  If a probe-size
     61  1.1  pooka 	 * is specified, it's an optional item on the platform and
     62  1.1  pooka 	 * do a badaddr() test to make sure it's there.
     63  1.1  pooka 	 */
     64  1.1  pooka 	for (i = 0; i < ida->ida_ndevs; i++) {
     65  1.1  pooka 		ia = &ida->ida_devs[i];
     66  1.1  pooka 
     67  1.1  pooka #if 0 // DEBUG
     68  1.1  pooka         printf("PROBING %s %d@%x i=%d\n", ia->ia_name, ia->ia_basz, ia->ia_paddr, ia->ia_cookie);
     69  1.1  pooka #endif
     70  1.1  pooka 		if (ia->ia_basz != 0) {
     71  1.1  pooka             addr = (void *) mips_map_physmem(ia->ia_paddr, ia->ia_basz);
     72  1.1  pooka             if (addr == NULL){
     73  1.1  pooka                 printf("Failed to map %s: phys %x size %d\n",
     74  1.1  pooka                        ia->ia_name, ia->ia_paddr, ia->ia_basz);
     75  1.1  pooka                 continue;
     76  1.1  pooka             }
     77  1.1  pooka             ia->ia_vaddr = addr;
     78  1.1  pooka #if 0 // DEBUG
     79  1.1  pooka             printf("MAPPED at %p\n", ia->ia_vaddr);
     80  1.1  pooka #endif
     81  1.1  pooka         }
     82  1.1  pooka 
     83  1.1  pooka 
     84  1.1  pooka 		locs[EBUSCF_ADDR] = ia->ia_paddr;
     85  1.1  pooka 
     86  1.1  pooka 		if (NULL == config_found_sm_loc(self, "ebus", locs, ia,
     87  1.1  pooka                                         ebusprint, config_stdsubmatch)) {
     88  1.1  pooka             /* do we need to say anything? */
     89  1.1  pooka             if (ia->ia_basz != 0) {
     90  1.1  pooka                 mips_unmap_physmem((vaddr_t)ia->ia_vaddr, ia->ia_basz);
     91  1.1  pooka             }
     92  1.1  pooka         }
     93  1.1  pooka 	}
     94  1.1  pooka }
     95  1.1  pooka 
     96  1.1  pooka int
     97  1.1  pooka ebusprint(aux, pnp)
     98  1.1  pooka 	void *aux;
     99  1.1  pooka 	const char *pnp;
    100  1.1  pooka {
    101  1.1  pooka 	struct ebus_attach_args *ia = aux;
    102  1.1  pooka 
    103  1.1  pooka 	if (pnp)
    104  1.1  pooka 		aprint_normal("%s at %s", ia->ia_name, pnp);
    105  1.1  pooka 
    106  1.1  pooka 	aprint_normal(" addr 0x%x", ia->ia_paddr);
    107  1.1  pooka 
    108  1.1  pooka 	return (UNCONF);
    109  1.1  pooka }
    110  1.1  pooka 
    111  1.1  pooka void
    112  1.1  pooka ebus_intr_establish(dev, cookie, level, handler, arg)
    113  1.1  pooka 	struct device *dev;
    114  1.1  pooka 	void *cookie;
    115  1.1  pooka 	int level;
    116  1.1  pooka 	int (*handler) (void *, void *);
    117  1.1  pooka 	void *arg;
    118  1.1  pooka {
    119  1.1  pooka 	(*platform.intr_establish)(dev, cookie, level, handler, arg);
    120  1.1  pooka }
    121