Home | History | Annotate | Line # | Download | only in ebus
ebus.c revision 1.1.6.1
      1  1.1.6.1  cherry /*	$NetBSD: ebus.c,v 1.1.6.1 2011/06/23 14:19:05 cherry 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.6.1  cherry __KERNEL_RCSID(0, "$NetBSD: ebus.c,v 1.1.6.1 2011/06/23 14:19:05 cherry 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.6.1  cherry ebusattach(device_t parent, device_t self, void *aux)
     48      1.1   pooka {
     49      1.1   pooka 	struct ebus_dev_attach_args *ida = aux;
     50      1.1   pooka 	struct ebus_attach_args *ia;
     51  1.1.6.1  cherry 	void *addr;
     52      1.1   pooka 	int i;
     53      1.1   pooka 	int locs[EBUSCF_NLOCS];
     54      1.1   pooka 
     55      1.1   pooka 	printf("\n");
     56      1.1   pooka 
     57      1.1   pooka 	/*
     58      1.1   pooka 	 * Loop through the devices and attach them.  If a probe-size
     59      1.1   pooka 	 * is specified, it's an optional item on the platform and
     60      1.1   pooka 	 * do a badaddr() test to make sure it's there.
     61      1.1   pooka 	 */
     62      1.1   pooka 	for (i = 0; i < ida->ida_ndevs; i++) {
     63      1.1   pooka 		ia = &ida->ida_devs[i];
     64      1.1   pooka 
     65      1.1   pooka #if 0 // DEBUG
     66  1.1.6.1  cherry 		printf("PROBING %s %d@%x i=%d\n",
     67  1.1.6.1  cherry 		    ia->ia_name, ia->ia_basz, ia->ia_paddr, ia->ia_cookie);
     68      1.1   pooka #endif
     69      1.1   pooka 		if (ia->ia_basz != 0) {
     70  1.1.6.1  cherry 			addr = (void *)mips_map_physmem(ia->ia_paddr,
     71  1.1.6.1  cherry 			    ia->ia_basz);
     72  1.1.6.1  cherry 			if (addr == NULL) {
     73  1.1.6.1  cherry 				printf("Failed to map %s: phys %x size %d\n",
     74  1.1.6.1  cherry 				    ia->ia_name, ia->ia_paddr, ia->ia_basz);
     75  1.1.6.1  cherry 				continue;
     76  1.1.6.1  cherry 			}
     77  1.1.6.1  cherry 			ia->ia_vaddr = addr;
     78      1.1   pooka #if 0 // DEBUG
     79  1.1.6.1  cherry 			printf("MAPPED at %p\n", ia->ia_vaddr);
     80      1.1   pooka #endif
     81  1.1.6.1  cherry 		}
     82      1.1   pooka 
     83      1.1   pooka 		locs[EBUSCF_ADDR] = ia->ia_paddr;
     84      1.1   pooka 
     85      1.1   pooka 		if (NULL == config_found_sm_loc(self, "ebus", locs, ia,
     86  1.1.6.1  cherry 		    ebusprint, config_stdsubmatch)) {
     87  1.1.6.1  cherry 			/* do we need to say anything? */
     88  1.1.6.1  cherry 			if (ia->ia_basz != 0) {
     89  1.1.6.1  cherry 				mips_unmap_physmem((vaddr_t)ia->ia_vaddr,
     90  1.1.6.1  cherry 				    ia->ia_basz);
     91  1.1.6.1  cherry 			}
     92  1.1.6.1  cherry 		}
     93      1.1   pooka 	}
     94      1.1   pooka }
     95      1.1   pooka 
     96      1.1   pooka int
     97  1.1.6.1  cherry ebusprint(void *aux, const char *pnp)
     98      1.1   pooka {
     99      1.1   pooka 	struct ebus_attach_args *ia = aux;
    100      1.1   pooka 
    101      1.1   pooka 	if (pnp)
    102      1.1   pooka 		aprint_normal("%s at %s", ia->ia_name, pnp);
    103      1.1   pooka 
    104      1.1   pooka 	aprint_normal(" addr 0x%x", ia->ia_paddr);
    105      1.1   pooka 
    106  1.1.6.1  cherry 	return UNCONF;
    107      1.1   pooka }
    108      1.1   pooka 
    109      1.1   pooka void
    110  1.1.6.1  cherry ebus_intr_establish(device_t dev, void *cookie, int level,
    111  1.1.6.1  cherry     int (*handler)(void *, void *), void *arg)
    112      1.1   pooka {
    113  1.1.6.1  cherry 
    114      1.1   pooka 	(*platform.intr_establish)(dev, cookie, level, handler, arg);
    115      1.1   pooka }
    116