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