source: mainline/uspace/drv/platform/msim/msim.c@ 36fb6d7

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 36fb6d7 was 676e833, checked in by Jiri Svoboda <jiri@…>, 8 years ago

Move receiving side of Msim console to a separate driver. Work around possibility that console character device is not available at the moment input server starts.

  • Property mode set to 100644
File size: 5.5 KB
RevLine 
[eec5795]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
59typedef struct msim_fun {
60 hw_resource_list_t hw_resources;
61 pio_window_t pio_window;
62} msim_fun_t;
63
64static int msim_dev_add(ddf_dev_t *dev);
65static void msim_init(void);
66
67/** The root device driver's standard operations. */
68static driver_ops_t msim_ops = {
69 .dev_add = &msim_dev_add
70};
71
72/** The root device 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 = 6
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_DISK_BASE,
104 .size = MSIM_DISK_SIZE
105 }
106 }
107};
108
109/** Obtain function soft-state from DDF function node */
110static msim_fun_t *msim_fun(ddf_fun_t *fnode)
111{
112 return ddf_fun_data_get(fnode);
113}
114
115static 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
[cccd60c3]123static int msim_enable_interrupt(ddf_fun_t *fun, int irq)
[eec5795]124{
125 /* Nothing to do. */
126
127 return true;
128}
129
130static 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
138static hw_res_ops_t fun_hw_res_ops = {
139 .get_resource_list = &msim_get_resources,
140 .enable_interrupt = &msim_enable_interrupt,
141};
142
143static pio_window_ops_t fun_pio_window_ops = {
144 .get_pio_window = &msim_get_pio_window
145};
146
147/* Initialized in msim_init() function. */
148static ddf_dev_ops_t msim_fun_ops;
149
150static bool
151msim_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
183failure:
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
192static bool msim_add_functions(ddf_dev_t *dev)
193{
[676e833]194 if (!msim_add_fun(dev, "disk0", "msim/ddisk", &disk_data))
195 return false;
196 if (!msim_add_fun(dev, "console", "msim/console", &disk_data))
197 return false;
198 return true;
[eec5795]199}
200
201/** Get the root device.
202 *
203 * @param dev The device which is root of the whole device tree (both
204 * of HW and pseudo devices).
205 * @return Zero on success, negative error number otherwise.
206 */
207static int msim_dev_add(ddf_dev_t *dev)
208{
209 ddf_msg(LVL_DEBUG, "msim_dev_add, device handle = %d",
210 (int) ddf_dev_get_handle(dev));
211
212 /* Register functions. */
213 if (!msim_add_functions(dev))
214 ddf_msg(LVL_ERROR, "Failed to add functions for the MSIM platform.");
215
216 return EOK;
217}
218
219static void msim_init(void)
220{
221 ddf_log_init(NAME);
222 msim_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops;
223 msim_fun_ops.interfaces[PIO_WINDOW_DEV_IFACE] = &fun_pio_window_ops;
224}
225
226int main(int argc, char *argv[])
227{
228 printf(NAME ": HelenOS MSIM platform driver\n");
229 msim_init();
230 return ddf_driver_main(&msim_driver);
231}
232
233/**
234 * @}
235 */
Note: See TracBrowser for help on using the repository browser.