source: mainline/uspace/drv/platform/msim/msim.c@ d92060f

Last change on this file since d92060f was a35b458, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 8 years ago

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

  • Property mode set to 100644
File size: 6.0 KB
Line 
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 <ddf/driver.h>
41#include <ddf/log.h>
42#include <errno.h>
43#include <ipc/dev_iface.h>
44#include <ops/hw_res.h>
45#include <ops/pio_window.h>
46#include <stdbool.h>
47#include <stdio.h>
48
49#define NAME "msim"
50
51#define MSIM_DDISK_BASE UINT32_C(0x10000200)
52#define MSIM_DDISK_SIZE UINT32_C(0x00000010)
53#define MSIM_DDISK_IRQ 6
54
55#define MSIM_KBD_ADDRESS UINT32_C(0x10000000)
56#define MSIM_KBD_SIZE 1
57#define MSIM_KBD_IRQ 2
58
59typedef struct msim_fun {
60 hw_resource_list_t hw_resources;
61 pio_window_t pio_window;
62} msim_fun_t;
63
64static errno_t msim_dev_add(ddf_dev_t *dev);
65static void msim_init(void);
66
67/** Standard driver operations. */
68static driver_ops_t msim_ops = {
69 .dev_add = &msim_dev_add
70};
71
72/** Driver structure. */
73static driver_t msim_driver = {
74 .name = NAME,
75 .driver_ops = &msim_ops
76};
77
78static 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 = MSIM_DDISK_IRQ
92 }
93 }
94};
95
96static 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_DDISK_BASE,
104 .size = MSIM_DDISK_SIZE
105 }
106 }
107};
108
109static hw_resource_t console_regs[] = {
110 {
111 .type = MEM_RANGE,
112 .res.mem_range = {
113 .address = 0,
114 .size = 1,
115 .relative = true,
116 .endianness = LITTLE_ENDIAN
117 }
118 },
119 {
120 .type = INTERRUPT,
121 .res.interrupt = {
122 .irq = MSIM_KBD_IRQ
123 }
124 }
125};
126
127static msim_fun_t console_data = {
128 .hw_resources = {
129 sizeof(console_regs) / sizeof(console_regs[0]),
130 console_regs
131 },
132 .pio_window = {
133 .mem = {
134 .base = MSIM_KBD_ADDRESS,
135 .size = MSIM_KBD_SIZE
136 }
137 }
138};
139
140/** Obtain function soft-state from DDF function node */
141static msim_fun_t *msim_fun(ddf_fun_t *fnode)
142{
143 return ddf_fun_data_get(fnode);
144}
145
146static hw_resource_list_t *msim_get_resources(ddf_fun_t *fnode)
147{
148 msim_fun_t *fun = msim_fun(fnode);
149
150 assert(fun != NULL);
151 return &fun->hw_resources;
152}
153
154static errno_t msim_enable_interrupt(ddf_fun_t *fun, int irq)
155{
156 /* Nothing to do. */
157
158 return EOK;
159}
160
161static pio_window_t *msim_get_pio_window(ddf_fun_t *fnode)
162{
163 msim_fun_t *fun = msim_fun(fnode);
164
165 assert(fun != NULL);
166 return &fun->pio_window;
167}
168
169static hw_res_ops_t fun_hw_res_ops = {
170 .get_resource_list = &msim_get_resources,
171 .enable_interrupt = &msim_enable_interrupt,
172};
173
174static pio_window_ops_t fun_pio_window_ops = {
175 .get_pio_window = &msim_get_pio_window
176};
177
178/* Initialized in msim_init() function. */
179static ddf_dev_ops_t msim_fun_ops;
180
181static bool
182msim_add_fun(ddf_dev_t *dev, const char *name, const char *str_match_id,
183 msim_fun_t *fun_proto)
184{
185 ddf_msg(LVL_DEBUG, "Adding new function '%s'.", name);
186
187 ddf_fun_t *fnode = NULL;
188 errno_t rc;
189
190 /* Create new device. */
191 fnode = ddf_fun_create(dev, fun_inner, name);
192 if (fnode == NULL)
193 goto failure;
194
195 msim_fun_t *fun = ddf_fun_data_alloc(fnode, sizeof(msim_fun_t));
196 if (fun == NULL)
197 goto failure;
198
199 *fun = *fun_proto;
200
201 /* Add match ID */
202 rc = ddf_fun_add_match_id(fnode, str_match_id, 100);
203 if (rc != EOK)
204 goto failure;
205
206 /* Set provided operations to the device. */
207 ddf_fun_set_ops(fnode, &msim_fun_ops);
208
209 /* Register function. */
210 if (ddf_fun_bind(fnode) != EOK) {
211 ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
212 goto failure;
213 }
214
215 return true;
216
217failure:
218 if (fnode != NULL)
219 ddf_fun_destroy(fnode);
220
221 ddf_msg(LVL_ERROR, "Failed adding function '%s'.", name);
222
223 return false;
224}
225
226static bool msim_add_functions(ddf_dev_t *dev)
227{
228 if (!msim_add_fun(dev, "disk0", "msim/ddisk", &disk_data))
229 return false;
230 if (!msim_add_fun(dev, "console", "msim/console", &console_data))
231 return false;
232 return true;
233}
234
235/** Add MSIM platform device.
236 *
237 * @param dev DDF device
238 * @return Zero on success or non-zero error code.
239 */
240static errno_t msim_dev_add(ddf_dev_t *dev)
241{
242 ddf_msg(LVL_DEBUG, "msim_dev_add, device handle = %d",
243 (int) ddf_dev_get_handle(dev));
244
245 /* Register functions. */
246 if (!msim_add_functions(dev))
247 ddf_msg(LVL_ERROR, "Failed to add functions for the MSIM platform.");
248
249 return EOK;
250}
251
252static void msim_init(void)
253{
254 ddf_log_init(NAME);
255 msim_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops;
256 msim_fun_ops.interfaces[PIO_WINDOW_DEV_IFACE] = &fun_pio_window_ops;
257}
258
259int main(int argc, char *argv[])
260{
261 printf(NAME ": HelenOS MSIM platform driver\n");
262 msim_init();
263 return ddf_driver_main(&msim_driver);
264}
265
266/**
267 * @}
268 */
Note: See TracBrowser for help on using the repository browser.