1 | /*
|
---|
2 | * Copyright (c) 2010 Lenka Trochtova
|
---|
3 | * Copyright (c) 2015 Jakub Jermar
|
---|
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 | *
|
---|
10 | * - Redistributions of source code must retain the above copyright
|
---|
11 | * notice, this list of conditions and the following disclaimer.
|
---|
12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
13 | * notice, this list of conditions and the following disclaimer in the
|
---|
14 | * documentation and/or other materials provided with the distribution.
|
---|
15 | * - The name of the author may not be used to endorse or promote products
|
---|
16 | * derived from this software without specific prior written permission.
|
---|
17 | *
|
---|
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
28 | */
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * @defgroup msim MSIM platform driver.
|
---|
32 | * @brief HelenOS MSIM platform driver.
|
---|
33 | * @{
|
---|
34 | */
|
---|
35 |
|
---|
36 | /** @file
|
---|
37 | */
|
---|
38 |
|
---|
39 | #include <assert.h>
|
---|
40 | #include <stdio.h>
|
---|
41 | #include <errno.h>
|
---|
42 | #include <stdbool.h>
|
---|
43 | #include <stdlib.h>
|
---|
44 | #include <ctype.h>
|
---|
45 | #include <macros.h>
|
---|
46 |
|
---|
47 | #include <ddi.h>
|
---|
48 | #include <ddf/driver.h>
|
---|
49 | #include <ddf/log.h>
|
---|
50 | #include <ipc/dev_iface.h>
|
---|
51 | #include <ops/hw_res.h>
|
---|
52 | #include <ops/pio_window.h>
|
---|
53 |
|
---|
54 | #define NAME "msim"
|
---|
55 |
|
---|
56 | #define MSIM_DISK_BASE UINT32_C(0x10000200)
|
---|
57 | #define MSIM_DISK_SIZE UINT32_C(0x00000010)
|
---|
58 |
|
---|
59 | typedef struct msim_fun {
|
---|
60 | hw_resource_list_t hw_resources;
|
---|
61 | pio_window_t pio_window;
|
---|
62 | } msim_fun_t;
|
---|
63 |
|
---|
64 | static int msim_dev_add(ddf_dev_t *dev);
|
---|
65 | static void msim_init(void);
|
---|
66 |
|
---|
67 | /** The root device driver's standard operations. */
|
---|
68 | static driver_ops_t msim_ops = {
|
---|
69 | .dev_add = &msim_dev_add
|
---|
70 | };
|
---|
71 |
|
---|
72 | /** The root device driver structure. */
|
---|
73 | static driver_t msim_driver = {
|
---|
74 | .name = NAME,
|
---|
75 | .driver_ops = &msim_ops
|
---|
76 | };
|
---|
77 |
|
---|
78 | static hw_resource_t disk_regs[] = {
|
---|
79 | {
|
---|
80 | .type = MEM_RANGE,
|
---|
81 | .res.mem_range = {
|
---|
82 | .address = 0,
|
---|
83 | .size = 16,
|
---|
84 | .relative = true,
|
---|
85 | .endianness = LITTLE_ENDIAN
|
---|
86 | }
|
---|
87 | },
|
---|
88 | {
|
---|
89 | .type = INTERRUPT,
|
---|
90 | .res.interrupt = {
|
---|
91 | .irq = 6
|
---|
92 | }
|
---|
93 | }
|
---|
94 | };
|
---|
95 |
|
---|
96 | static msim_fun_t disk_data = {
|
---|
97 | .hw_resources = {
|
---|
98 | sizeof(disk_regs) / sizeof(disk_regs[0]),
|
---|
99 | disk_regs
|
---|
100 | },
|
---|
101 | .pio_window = {
|
---|
102 | .mem = {
|
---|
103 | .base = MSIM_DISK_BASE,
|
---|
104 | .size = MSIM_DISK_SIZE
|
---|
105 | }
|
---|
106 | }
|
---|
107 | };
|
---|
108 |
|
---|
109 | /** Obtain function soft-state from DDF function node */
|
---|
110 | static msim_fun_t *msim_fun(ddf_fun_t *fnode)
|
---|
111 | {
|
---|
112 | return ddf_fun_data_get(fnode);
|
---|
113 | }
|
---|
114 |
|
---|
115 | static hw_resource_list_t *msim_get_resources(ddf_fun_t *fnode)
|
---|
116 | {
|
---|
117 | msim_fun_t *fun = msim_fun(fnode);
|
---|
118 |
|
---|
119 | assert(fun != NULL);
|
---|
120 | return &fun->hw_resources;
|
---|
121 | }
|
---|
122 |
|
---|
123 | static bool msim_enable_interrupt(ddf_fun_t *fun)
|
---|
124 | {
|
---|
125 | /* Nothing to do. */
|
---|
126 |
|
---|
127 | return true;
|
---|
128 | }
|
---|
129 |
|
---|
130 | static pio_window_t *msim_get_pio_window(ddf_fun_t *fnode)
|
---|
131 | {
|
---|
132 | msim_fun_t *fun = msim_fun(fnode);
|
---|
133 |
|
---|
134 | assert(fun != NULL);
|
---|
135 | return &fun->pio_window;
|
---|
136 | }
|
---|
137 |
|
---|
138 | static hw_res_ops_t fun_hw_res_ops = {
|
---|
139 | .get_resource_list = &msim_get_resources,
|
---|
140 | .enable_interrupt = &msim_enable_interrupt,
|
---|
141 | };
|
---|
142 |
|
---|
143 | static pio_window_ops_t fun_pio_window_ops = {
|
---|
144 | .get_pio_window = &msim_get_pio_window
|
---|
145 | };
|
---|
146 |
|
---|
147 | /* Initialized in msim_init() function. */
|
---|
148 | static ddf_dev_ops_t msim_fun_ops;
|
---|
149 |
|
---|
150 | static bool
|
---|
151 | msim_add_fun(ddf_dev_t *dev, const char *name, const char *str_match_id,
|
---|
152 | msim_fun_t *fun_proto)
|
---|
153 | {
|
---|
154 | ddf_msg(LVL_DEBUG, "Adding new function '%s'.", name);
|
---|
155 |
|
---|
156 | ddf_fun_t *fnode = NULL;
|
---|
157 | int rc;
|
---|
158 |
|
---|
159 | /* Create new device. */
|
---|
160 | fnode = ddf_fun_create(dev, fun_inner, name);
|
---|
161 | if (fnode == NULL)
|
---|
162 | goto failure;
|
---|
163 |
|
---|
164 | msim_fun_t *fun = ddf_fun_data_alloc(fnode, sizeof(msim_fun_t));
|
---|
165 | *fun = *fun_proto;
|
---|
166 |
|
---|
167 | /* Add match ID */
|
---|
168 | rc = ddf_fun_add_match_id(fnode, str_match_id, 100);
|
---|
169 | if (rc != EOK)
|
---|
170 | goto failure;
|
---|
171 |
|
---|
172 | /* Set provided operations to the device. */
|
---|
173 | ddf_fun_set_ops(fnode, &msim_fun_ops);
|
---|
174 |
|
---|
175 | /* Register function. */
|
---|
176 | if (ddf_fun_bind(fnode) != EOK) {
|
---|
177 | ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
|
---|
178 | goto failure;
|
---|
179 | }
|
---|
180 |
|
---|
181 | return true;
|
---|
182 |
|
---|
183 | failure:
|
---|
184 | if (fnode != NULL)
|
---|
185 | ddf_fun_destroy(fnode);
|
---|
186 |
|
---|
187 | ddf_msg(LVL_ERROR, "Failed adding function '%s'.", name);
|
---|
188 |
|
---|
189 | return false;
|
---|
190 | }
|
---|
191 |
|
---|
192 | static bool msim_add_functions(ddf_dev_t *dev)
|
---|
193 | {
|
---|
194 | return msim_add_fun(dev, "disk0", "msim/ddisk", &disk_data);
|
---|
195 | }
|
---|
196 |
|
---|
197 | /** Get the root device.
|
---|
198 | *
|
---|
199 | * @param dev The device which is root of the whole device tree (both
|
---|
200 | * of HW and pseudo devices).
|
---|
201 | * @return Zero on success, negative error number otherwise.
|
---|
202 | */
|
---|
203 | static int msim_dev_add(ddf_dev_t *dev)
|
---|
204 | {
|
---|
205 | ddf_msg(LVL_DEBUG, "msim_dev_add, device handle = %d",
|
---|
206 | (int) ddf_dev_get_handle(dev));
|
---|
207 |
|
---|
208 | /* Register functions. */
|
---|
209 | if (!msim_add_functions(dev))
|
---|
210 | ddf_msg(LVL_ERROR, "Failed to add functions for the MSIM platform.");
|
---|
211 |
|
---|
212 | return EOK;
|
---|
213 | }
|
---|
214 |
|
---|
215 | static void msim_init(void)
|
---|
216 | {
|
---|
217 | ddf_log_init(NAME);
|
---|
218 | msim_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops;
|
---|
219 | msim_fun_ops.interfaces[PIO_WINDOW_DEV_IFACE] = &fun_pio_window_ops;
|
---|
220 | }
|
---|
221 |
|
---|
222 | int main(int argc, char *argv[])
|
---|
223 | {
|
---|
224 | printf(NAME ": HelenOS MSIM platform driver\n");
|
---|
225 | msim_init();
|
---|
226 | return ddf_driver_main(&msim_driver);
|
---|
227 | }
|
---|
228 |
|
---|
229 | /**
|
---|
230 | * @}
|
---|
231 | */
|
---|