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