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

Last change on this file was 4122410, checked in by Jakub Jermar <jakub@…>, 7 years ago

Improve Doxygen documentaion

This is stil WiP. A number of libraries, drivers and services were
converted to using a more hierarchical and decentralized scheme when it
comes to specifying to which doxygen group they belong.

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