source: mainline/uspace/drv/char/sun4v-con/main.c@ 0f79283b

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

Move receiving side of Niagara console to a separate driver.

  • Property mode set to 100644
File size: 3.3 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 <errno.h>
35#include <stdio.h>
36
37#include "sun4v-con.h"
38
39#define NAME "sun4v-con"
40
41static int sun4v_con_dev_add(ddf_dev_t *dev);
42static int sun4v_con_dev_remove(ddf_dev_t *dev);
43static int sun4v_con_dev_gone(ddf_dev_t *dev);
44static int sun4v_con_fun_online(ddf_fun_t *fun);
45static int sun4v_con_fun_offline(ddf_fun_t *fun);
46
47static driver_ops_t driver_ops = {
48 .dev_add = sun4v_con_dev_add,
49 .dev_remove = sun4v_con_dev_remove,
50 .dev_gone = sun4v_con_dev_gone,
51 .fun_online = sun4v_con_fun_online,
52 .fun_offline = sun4v_con_fun_offline
53};
54
55static driver_t sun4v_con_driver = {
56 .name = NAME,
57 .driver_ops = &driver_ops
58};
59
60static int sun4v_con_dev_add(ddf_dev_t *dev)
61{
62 sun4v_con_t *sun4v_con;
63
64 ddf_msg(LVL_DEBUG, "sun4v_con_dev_add(%p)", dev);
65 sun4v_con = ddf_dev_data_alloc(dev, sizeof(sun4v_con_t));
66 if (sun4v_con == NULL) {
67 ddf_msg(LVL_ERROR, "Failed allocating soft state.");
68 return ENOMEM;
69 }
70
71 sun4v_con->dev = dev;
72
73 return sun4v_con_add(sun4v_con);
74}
75
76static int sun4v_con_dev_remove(ddf_dev_t *dev)
77{
78 sun4v_con_t *sun4v_con = (sun4v_con_t *)ddf_dev_data_get(dev);
79
80 ddf_msg(LVL_DEBUG, "sun4v_con_dev_remove(%p)", dev);
81
82 return sun4v_con_remove(sun4v_con);
83}
84
85static int sun4v_con_dev_gone(ddf_dev_t *dev)
86{
87 sun4v_con_t *sun4v_con = (sun4v_con_t *)ddf_dev_data_get(dev);
88
89 ddf_msg(LVL_DEBUG, "sun4v_con_dev_gone(%p)", dev);
90
91 return sun4v_con_gone(sun4v_con);
92}
93
94static int sun4v_con_fun_online(ddf_fun_t *fun)
95{
96 ddf_msg(LVL_DEBUG, "sun4v_con_fun_online()");
97 return ddf_fun_online(fun);
98}
99
100static int sun4v_con_fun_offline(ddf_fun_t *fun)
101{
102 ddf_msg(LVL_DEBUG, "sun4v_con_fun_offline()");
103 return ddf_fun_offline(fun);
104}
105
106int main(int argc, char *argv[])
107{
108 printf(NAME ": Sun4v console driver\n");
109 ddf_log_init(NAME);
110 return ddf_driver_main(&sun4v_con_driver);
111}
112
113/** @}
114 */
Note: See TracBrowser for help on using the repository browser.