Home | History | Annotate | Line # | Download | only in ebus
ebus.c revision 1.2.68.1
      1  1.2.68.1  thorpej /*	$NetBSD: ebus.c,v 1.2.68.1 2021/03/22 02:00:55 thorpej 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.2.68.1  thorpej __KERNEL_RCSID(0, "$NetBSD: ebus.c,v 1.2.68.1 2021/03/22 02:00:55 thorpej 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.2  tsutsui 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.2  tsutsui 	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.2  tsutsui 		printf("PROBING %s %d@%x i=%d\n",
     67       1.2  tsutsui 		    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.2  tsutsui 			addr = (void *)mips_map_physmem(ia->ia_paddr,
     71       1.2  tsutsui 			    ia->ia_basz);
     72       1.2  tsutsui 			if (addr == NULL) {
     73       1.2  tsutsui 				printf("Failed to map %s: phys %x size %d\n",
     74       1.2  tsutsui 				    ia->ia_name, ia->ia_paddr, ia->ia_basz);
     75       1.2  tsutsui 				continue;
     76       1.2  tsutsui 			}
     77       1.2  tsutsui 			ia->ia_vaddr = addr;
     78       1.1    pooka #if 0 // DEBUG
     79       1.2  tsutsui 			printf("MAPPED at %p\n", ia->ia_vaddr);
     80       1.1    pooka #endif
     81       1.2  tsutsui 		}
     82       1.1    pooka 
     83       1.1    pooka 		locs[EBUSCF_ADDR] = ia->ia_paddr;
     84       1.1    pooka 
     85  1.2.68.1  thorpej 		if (config_found(self, ia, ebusprint,
     86  1.2.68.1  thorpej 				 CFARG_SUBMATCH, config_stdsubmatch,
     87  1.2.68.1  thorpej 				 CFARG_IATTR, "ebus",
     88  1.2.68.1  thorpej 				 CFARG_LOCATORS, locs,
     89  1.2.68.1  thorpej 				 CFARG_EOL) == NULL) {
     90       1.2  tsutsui 			/* do we need to say anything? */
     91       1.2  tsutsui 			if (ia->ia_basz != 0) {
     92       1.2  tsutsui 				mips_unmap_physmem((vaddr_t)ia->ia_vaddr,
     93       1.2  tsutsui 				    ia->ia_basz);
     94       1.2  tsutsui 			}
     95       1.2  tsutsui 		}
     96       1.1    pooka 	}
     97       1.1    pooka }
     98       1.1    pooka 
     99       1.1    pooka int
    100       1.2  tsutsui ebusprint(void *aux, const char *pnp)
    101       1.1    pooka {
    102       1.1    pooka 	struct ebus_attach_args *ia = aux;
    103       1.1    pooka 
    104       1.1    pooka 	if (pnp)
    105       1.1    pooka 		aprint_normal("%s at %s", ia->ia_name, pnp);
    106       1.1    pooka 
    107       1.1    pooka 	aprint_normal(" addr 0x%x", ia->ia_paddr);
    108       1.1    pooka 
    109       1.2  tsutsui 	return UNCONF;
    110       1.1    pooka }
    111       1.1    pooka 
    112       1.1    pooka void
    113       1.2  tsutsui ebus_intr_establish(device_t dev, void *cookie, int level,
    114       1.2  tsutsui     int (*handler)(void *, void *), void *arg)
    115       1.1    pooka {
    116       1.2  tsutsui 
    117       1.1    pooka 	(*platform.intr_establish)(dev, cookie, level, handler, arg);
    118       1.1    pooka }
    119