source: mainline/uspace/drv/char/sun4v-con/main.c@ 09ab0a9a

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

Fix vertical spacing with new Ccheck revision.

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 * Copyright (c) 2017 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @file Sun4v console driver
30 */
31
32#include <ddf/driver.h>
33#include <ddf/log.h>
34#include <device/hw_res_parsed.h>
35#include <errno.h>
36#include <stdio.h>
37
38#include "sun4v-con.h"
39
40#define NAME "sun4v-con"
41
42static errno_t sun4v_con_dev_add(ddf_dev_t *dev);
43static errno_t sun4v_con_dev_remove(ddf_dev_t *dev);
44static errno_t sun4v_con_dev_gone(ddf_dev_t *dev);
45static errno_t sun4v_con_fun_online(ddf_fun_t *fun);
46static errno_t sun4v_con_fun_offline(ddf_fun_t *fun);
47
48static driver_ops_t driver_ops = {
49 .dev_add = sun4v_con_dev_add,
50 .dev_remove = sun4v_con_dev_remove,
51 .dev_gone = sun4v_con_dev_gone,
52 .fun_online = sun4v_con_fun_online,
53 .fun_offline = sun4v_con_fun_offline
54};
55
56static driver_t sun4v_con_driver = {
57 .name = NAME,
58 .driver_ops = &driver_ops
59};
60
61static errno_t sun4v_con_get_res(ddf_dev_t *dev, sun4v_con_res_t *res)
62{
63 async_sess_t *parent_sess;
64 hw_res_list_parsed_t hw_res;
65 errno_t rc;
66
67 parent_sess = ddf_dev_parent_sess_get(dev);
68 if (parent_sess == NULL)
69 return ENOMEM;
70
71 hw_res_list_parsed_init(&hw_res);
72 rc = hw_res_get_list_parsed(parent_sess, &hw_res, 0);
73 if (rc != EOK)
74 return rc;
75
76 if (hw_res.mem_ranges.count != 2) {
77 rc = EINVAL;
78 goto error;
79 }
80
81 res->in_base = RNGABS(hw_res.mem_ranges.ranges[0]);
82 res->out_base = RNGABS(hw_res.mem_ranges.ranges[1]);
83 return EOK;
84error:
85 hw_res_list_parsed_clean(&hw_res);
86 return rc;
87}
88
89static errno_t sun4v_con_dev_add(ddf_dev_t *dev)
90{
91 sun4v_con_t *sun4v_con;
92 sun4v_con_res_t res;
93 errno_t rc;
94
95 ddf_msg(LVL_DEBUG, "sun4v_con_dev_add(%p)", dev);
96 sun4v_con = ddf_dev_data_alloc(dev, sizeof(sun4v_con_t));
97 if (sun4v_con == NULL) {
98 ddf_msg(LVL_ERROR, "Failed allocating soft state.");
99 return ENOMEM;
100 }
101
102 sun4v_con->dev = dev;
103
104 rc = sun4v_con_get_res(dev, &res);
105 if (rc != EOK) {
106 ddf_msg(LVL_ERROR, "Failed getting hardware resource list.\n");
107 return EIO;
108 }
109
110 return sun4v_con_add(sun4v_con, &res);
111}
112
113static errno_t sun4v_con_dev_remove(ddf_dev_t *dev)
114{
115 sun4v_con_t *sun4v_con = (sun4v_con_t *)ddf_dev_data_get(dev);
116
117 ddf_msg(LVL_DEBUG, "sun4v_con_dev_remove(%p)", dev);
118
119 return sun4v_con_remove(sun4v_con);
120}
121
122static errno_t sun4v_con_dev_gone(ddf_dev_t *dev)
123{
124 sun4v_con_t *sun4v_con = (sun4v_con_t *)ddf_dev_data_get(dev);
125
126 ddf_msg(LVL_DEBUG, "sun4v_con_dev_gone(%p)", dev);
127
128 return sun4v_con_gone(sun4v_con);
129}
130
131static errno_t sun4v_con_fun_online(ddf_fun_t *fun)
132{
133 ddf_msg(LVL_DEBUG, "sun4v_con_fun_online()");
134 return ddf_fun_online(fun);
135}
136
137static errno_t sun4v_con_fun_offline(ddf_fun_t *fun)
138{
139 ddf_msg(LVL_DEBUG, "sun4v_con_fun_offline()");
140 return ddf_fun_offline(fun);
141}
142
143int main(int argc, char *argv[])
144{
145 printf(NAME ": Sun4v console driver\n");
146 ddf_log_init(NAME);
147 return ddf_driver_main(&sun4v_con_driver);
148}
149
150/** @}
151 */
Note: See TracBrowser for help on using the repository browser.