]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/arm/arm/platform.c
MFV ntp 4.2.8p1 (r258945, r275970, r276091, r276092, r276093, r278284)
[FreeBSD/FreeBSD.git] / sys / arm / arm / platform.c
1 /*-
2  * Copyright (c) 2005 Peter Grehan
3  * Copyright (c) 2009 Nathan Whitehorn
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  */
28
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
31
32 /*
33  * Dispatch platform calls to the appropriate platform implementation
34  * through a previously registered kernel object.
35  */
36
37 #define _ARM32_BUS_DMA_PRIVATE
38 #include <sys/param.h>
39 #include <sys/bus.h>
40 #include <sys/kernel.h>
41 #include <sys/lock.h>
42 #include <sys/ktr.h>
43 #include <sys/mutex.h>
44 #include <sys/rman.h>
45 #include <sys/systm.h>
46 #include <sys/smp.h>
47 #include <sys/sysctl.h>
48 #include <sys/types.h>
49
50 #include <vm/vm.h>
51 #include <vm/vm_page.h>
52
53 #include <machine/bus_dma.h>
54 #include <machine/cpu.h>
55 #include <machine/intr.h>
56 #include <machine/md_var.h>
57 #include <machine/platform.h>
58 #include <machine/platformvar.h>
59 #include <machine/smp.h>
60
61 #include "platform_if.h"
62
63 static platform_def_t   *plat_def_impl;
64 static platform_t       plat_obj;
65 static struct kobj_ops  plat_kernel_kops;
66 static struct platform_kobj     plat_kernel_obj;
67
68 static char plat_name[64];
69 SYSCTL_STRING(_hw, OID_AUTO, platform, CTLFLAG_RDTUN | CTLFLAG_NOFETCH, plat_name, 0,
70     "Platform currently in use");
71
72 /*
73  * Platform install routines. Highest priority wins, using the same
74  * algorithm as bus attachment.
75  */
76 SET_DECLARE(platform_set, platform_def_t);
77
78 void
79 platform_probe_and_attach(void)
80 {
81         platform_def_t  **platpp, *platp;
82         int             prio, best_prio;
83
84         plat_obj = &plat_kernel_obj;
85         best_prio = 0;
86
87         /*
88          * We are unable to use TUNABLE_STR as the read will happen
89          * well after this function has returned.
90          */
91         TUNABLE_STR_FETCH("hw.platform", plat_name, sizeof(plat_name));
92
93         /*
94          * Try to locate the best platform kobj
95          */
96         SET_FOREACH(platpp, platform_set) {
97                 platp = *platpp;
98
99                 /*
100                  * Take care of compiling the selected class, and
101                  * then statically initialise the MMU object
102                  */
103                 kobj_class_compile_static(platp, &plat_kernel_kops);
104                 kobj_init_static((kobj_t)plat_obj, platp);
105
106                 plat_obj->cls = platp;
107
108                 prio = PLATFORM_PROBE(plat_obj);
109
110                 /* Check for errors */
111                 if (prio > 0)
112                         continue;
113
114                 /*
115                  * Check if this module was specifically requested through
116                  * the loader tunable we provide.
117                  */
118                 if (strcmp(platp->name,plat_name) == 0) {
119                         plat_def_impl = platp;
120                         break;
121                 }
122
123                 /* Otherwise, see if it is better than our current best */
124                 if (plat_def_impl == NULL || prio > best_prio) {
125                         best_prio = prio;
126                         plat_def_impl = platp;
127                 }
128
129                 /*
130                  * We can't free the KOBJ, since it is static. Reset the ops
131                  * member of this class so that we can come back later.
132                  */
133                 platp->ops = NULL;
134         }
135
136         if (plat_def_impl == NULL)
137                 panic("No platform module found!");
138
139         /*
140          * Recompile to make sure we ended with the
141          * correct one, and then attach.
142          */
143
144         kobj_class_compile_static(plat_def_impl, &plat_kernel_kops);
145         kobj_init_static((kobj_t)plat_obj, plat_def_impl);
146
147         strlcpy(plat_name,plat_def_impl->name,sizeof(plat_name));
148
149         PLATFORM_ATTACH(plat_obj);
150 }
151
152 int
153 platform_devmap_init(void)
154 {
155
156         return PLATFORM_DEVMAP_INIT(plat_obj);
157 }
158
159 vm_offset_t
160 platform_lastaddr(void)
161 {
162
163         return PLATFORM_LASTADDR(plat_obj);
164 }
165
166 void
167 platform_gpio_init(void)
168 {
169
170         PLATFORM_GPIO_INIT(plat_obj);
171 }
172
173 void
174 platform_late_init(void)
175 {
176
177         PLATFORM_LATE_INIT(plat_obj);
178 }
179