1 /* $NetBSD: ebus.c,v 1.4 2021/08/07 16:18:48 thorpej 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.4 2021/08/07 16:18:48 thorpej 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
ebusattach(device_t parent,device_t self,void * aux)47 ebusattach(device_t parent, device_t self, void *aux)
48 {
49 struct ebus_dev_attach_args *ida = aux;
50 struct ebus_attach_args *ia;
51 void *addr;
52 int i;
53 int locs[EBUSCF_NLOCS];
54
55 printf("\n");
56
57 /*
58 * Loop through the devices and attach them. If a probe-size
59 * is specified, it's an optional item on the platform and
60 * do a badaddr() test to make sure it's there.
61 */
62 for (i = 0; i < ida->ida_ndevs; i++) {
63 ia = &ida->ida_devs[i];
64
65 #if 0 // DEBUG
66 printf("PROBING %s %d@%x i=%d\n",
67 ia->ia_name, ia->ia_basz, ia->ia_paddr, ia->ia_cookie);
68 #endif
69 if (ia->ia_basz != 0) {
70 addr = (void *)mips_map_physmem(ia->ia_paddr,
71 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 locs[EBUSCF_ADDR] = ia->ia_paddr;
84
85 if (config_found(self, ia, ebusprint,
86 CFARGS(.submatch = config_stdsubmatch,
87 .locators = locs)) == NULL) {
88 /* do we need to say anything? */
89 if (ia->ia_basz != 0) {
90 mips_unmap_physmem((vaddr_t)ia->ia_vaddr,
91 ia->ia_basz);
92 }
93 }
94 }
95 }
96
97 int
ebusprint(void * aux,const char * pnp)98 ebusprint(void *aux, const char *pnp)
99 {
100 struct ebus_attach_args *ia = aux;
101
102 if (pnp)
103 aprint_normal("%s at %s", ia->ia_name, pnp);
104
105 aprint_normal(" addr 0x%x", ia->ia_paddr);
106
107 return UNCONF;
108 }
109
110 void
ebus_intr_establish(device_t dev,void * cookie,int level,int (* handler)(void *,void *),void * arg)111 ebus_intr_establish(device_t dev, void *cookie, int level,
112 int (*handler)(void *, void *), void *arg)
113 {
114
115 (*platform.intr_establish)(dev, cookie, level, handler, arg);
116 }
117