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