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
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/**
[4122410]31 * @addtogroup msim
[eec5795]32 * @{
33 */
34
35/** @file
36 */
37
38#include <assert.h>
39#include <ddf/driver.h>
40#include <ddf/log.h>
[7de5f12]41#include <errno.h>
[eec5795]42#include <ipc/dev_iface.h>
43#include <ops/hw_res.h>
44#include <ops/pio_window.h>
[7de5f12]45#include <stdbool.h>
46#include <stdio.h>
[eec5795]47
48#define NAME "msim"
49
[7de5f12]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
[eec5795]57
58typedef struct msim_fun {
59 hw_resource_list_t hw_resources;
60 pio_window_t pio_window;
61} msim_fun_t;
62
[b7fd2a0]63static errno_t msim_dev_add(ddf_dev_t *dev);
[eec5795]64static void msim_init(void);
65
[19d2ce01]66/** Standard driver operations. */
[eec5795]67static driver_ops_t msim_ops = {
68 .dev_add = &msim_dev_add
69};
70
[19d2ce01]71/** Driver structure. */
[eec5795]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 = {
[7de5f12]90 .irq = MSIM_DDISK_IRQ
[eec5795]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 = {
[7de5f12]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
[eec5795]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);
[a35b458]148
[eec5795]149 assert(fun != NULL);
150 return &fun->hw_resources;
151}
152
[b7fd2a0]153static errno_t msim_enable_interrupt(ddf_fun_t *fun, int irq)
[eec5795]154{
155 /* Nothing to do. */
156
[1569a9b]157 return EOK;
[eec5795]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);
[a35b458]185
[eec5795]186 ddf_fun_t *fnode = NULL;
[b7fd2a0]187 errno_t rc;
[a35b458]188
[eec5795]189 /* Create new device. */
190 fnode = ddf_fun_create(dev, fun_inner, name);
191 if (fnode == NULL)
192 goto failure;
[a35b458]193
[eec5795]194 msim_fun_t *fun = ddf_fun_data_alloc(fnode, sizeof(msim_fun_t));
[19d2ce01]195 if (fun == NULL)
196 goto failure;
[a35b458]197
[eec5795]198 *fun = *fun_proto;
[a35b458]199
[eec5795]200 /* Add match ID */
201 rc = ddf_fun_add_match_id(fnode, str_match_id, 100);
202 if (rc != EOK)
203 goto failure;
[a35b458]204
[eec5795]205 /* Set provided operations to the device. */
206 ddf_fun_set_ops(fnode, &msim_fun_ops);
[a35b458]207
[eec5795]208 /* Register function. */
209 if (ddf_fun_bind(fnode) != EOK) {
210 ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
211 goto failure;
212 }
[a35b458]213
[eec5795]214 return true;
[a35b458]215
[eec5795]216failure:
217 if (fnode != NULL)
218 ddf_fun_destroy(fnode);
[a35b458]219
[eec5795]220 ddf_msg(LVL_ERROR, "Failed adding function '%s'.", name);
[a35b458]221
[eec5795]222 return false;
223}
224
225static bool msim_add_functions(ddf_dev_t *dev)
226{
[676e833]227 if (!msim_add_fun(dev, "disk0", "msim/ddisk", &disk_data))
228 return false;
[7de5f12]229 if (!msim_add_fun(dev, "console", "msim/console", &console_data))
[676e833]230 return false;
231 return true;
[eec5795]232}
233
[19d2ce01]234/** Add MSIM platform device.
[eec5795]235 *
[19d2ce01]236 * @param dev DDF device
237 * @return Zero on success or non-zero error code.
[eec5795]238 */
[b7fd2a0]239static errno_t msim_dev_add(ddf_dev_t *dev)
[eec5795]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.");
[a35b458]247
[eec5795]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.