source: mainline/uspace/drv/fb/amdm37x_dispc/main.c

Last change on this file was de19d4a, checked in by Jiri Svoboda <jiri@…>, 5 years ago

Clean up vestiges of visualizer interface

  • Property mode set to 100644
File size: 3.9 KB
Line 
1/*
2 * Copyright (c) 2020 Jiri Svoboda
3 * Copyright (c) 2013 Jan Vesely
4 * Copyright (c) 2011 Petr Koupy
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * - The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/** @addtogroup amdm37x_dispc
32 * @{
33 */
34/**
35 * @file
36 */
37
38#include <ddev_srv.h>
39#include <ddf/driver.h>
40#include <ddf/log.h>
41#include <errno.h>
42#include <ipcgfx/server.h>
43#include <str_error.h>
44#include <stdio.h>
45
46#include "amdm37x_dispc.h"
47
48#define NAME "amdm37x_dispc"
49
50static void amdm37x_client_conn(ipc_call_t *icall, void *arg)
51{
52 amdm37x_dispc_t *dispc;
53 ddev_srv_t srv;
54 sysarg_t gc_id;
55 gfx_context_t *gc;
56 errno_t rc;
57
58 dispc = (amdm37x_dispc_t *) ddf_dev_data_get(
59 ddf_fun_get_dev((ddf_fun_t *) arg));
60
61 gc_id = ipc_get_arg3(icall);
62
63 if (gc_id == 0) {
64 /* Set up protocol structure */
65 ddev_srv_initialize(&srv);
66 srv.ops = &amdm37x_ddev_ops;
67 srv.arg = dispc;
68
69 /* Handle connection */
70 ddev_conn(icall, &srv);
71 } else {
72 assert(gc_id == 42);
73
74 rc = gfx_context_new(&amdm37x_gc_ops, dispc, &gc);
75 if (rc != EOK)
76 goto error;
77
78 /* GC connection */
79 gc_conn(icall, gc);
80 }
81
82 return;
83error:
84 async_answer_0(icall, rc);
85}
86
87static errno_t amdm37x_dispc_dev_add(ddf_dev_t *dev)
88{
89 assert(dev);
90
91 ddf_fun_t *fun = ddf_fun_create(dev, fun_exposed, "a");
92 if (!fun) {
93 ddf_log_error("Failed to create display device function.");
94 return ENOMEM;
95 }
96
97 ddf_fun_set_conn_handler(fun, &amdm37x_client_conn);
98
99 /* Hw part */
100 amdm37x_dispc_t *dispc =
101 ddf_dev_data_alloc(dev, sizeof(amdm37x_dispc_t));
102 if (!dispc) {
103 ddf_log_error("Failed to allocate dispc structure.");
104 ddf_fun_destroy(fun);
105 return ENOMEM;
106 }
107
108 errno_t rc = amdm37x_dispc_init(dispc, fun);
109 if (rc != EOK) {
110 ddf_log_error("Failed to init dispc: %s.", str_error(rc));
111 ddf_fun_destroy(fun);
112 return rc;
113 }
114
115 /* Bind function */
116 rc = ddf_fun_bind(fun);
117 if (rc != EOK) {
118 ddf_log_error("Failed to bind function: %s.", str_error(rc));
119 amdm37x_dispc_fini(dispc);
120 ddf_fun_destroy(fun);
121 return rc;
122 }
123
124 rc = ddf_fun_add_to_category(fun, "display-device");
125 if (rc != EOK) {
126 ddf_log_error("Failed to add function: %s to display device "
127 "category.", str_error(rc));
128 amdm37x_dispc_fini(dispc);
129 ddf_fun_unbind(fun);
130 ddf_fun_destroy(fun);
131 return rc;
132 }
133
134 ddf_log_note("Added device `%s'", ddf_dev_get_name(dev));
135 return EOK;
136}
137
138static driver_ops_t amdm37x_dispc_driver_ops = {
139 .dev_add = amdm37x_dispc_dev_add,
140};
141
142static driver_t amdm37x_dispc_driver = {
143 .name = NAME,
144 .driver_ops = &amdm37x_dispc_driver_ops
145};
146
147int main(int argc, char *argv[])
148{
149 printf("%s: HelenOS AM/DM37x framebuffer driver\n", NAME);
150 ddf_log_init(NAME);
151 return ddf_driver_main(&amdm37x_dispc_driver);
152}
153
154/** @}
155 */
Note: See TracBrowser for help on using the repository browser.