source: mainline/uspace/lib/graph/graph.h@ b7fd2a0

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b7fd2a0 was b7fd2a0, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

Use errno_t in all uspace and kernel code.

Change type of every variable, parameter and return value that holds an
<errno.h> constant to either errno_t (the usual case), or sys_errno_t
(some places in kernel). This is for the purpose of self-documentation,
as well as for type-checking with a bit of type definition hackery.

Although this is a massive commit, it is a simple text replacement, and thus
is very easy to verify. Simply do the following:

`
git checkout <this commit's hash>
git reset HEAD
git add .
tools/srepl '\berrno_t\b' int
git add .
tools/srepl '\bsys_errno_t\b' sysarg_t
git reset
git diff
`

While this doesn't ensure that the replacements are correct, it does ensure
that the commit doesn't do anything except those replacements. Since errno_t
is typedef'd to int in the usual case (and sys_errno_t to sysarg_t), even if
incorrect, this commit cannot change behavior.

  • Property mode set to 100644
File size: 14.0 KB
Line 
1/*
2 * Copyright (c) 2011 Petr Koupy
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/** @addtogroup graph
30 * @{
31 */
32/**
33 * @file
34 */
35
36#ifndef GRAPH_GRAPH_H_
37#define GRAPH_GRAPH_H_
38
39#include <stdbool.h>
40#include <loc.h>
41#include <async.h>
42#include <atomic.h>
43#include <fibril_synch.h>
44#include <adt/list.h>
45#include <io/mode.h>
46#include <io/pixelmap.h>
47#include <ipc/graph.h>
48
49struct visualizer;
50struct renderer;
51
52typedef struct {
53 /**
54 * Device driver shall allocate any necessary internal structures
55 * specific for a claimed visualizer. */
56 errno_t (* claim)(struct visualizer *vs);
57
58 /**
59 * Device driver shall deallocate any necessary internal structures
60 * specific for a claimed visualizer. Driver shall also check whether
61 * the mode is set and if so it shall change its internal state
62 * accordingly (e.g. deallocate frame buffers). */
63 errno_t (* yield)(struct visualizer *vs);
64
65 /**
66 * Device driver shall first try to claim all resources required for
67 * a new mode (e.g. allocate new framebuffers) and only if successful
68 * it shall free resources for the old mode. Although such behaviour
69 * might not be always possible, it is preferable since libgraph tries to
70 * keep current mode functional if the new mode cannot be set (for any
71 * reason). If it is convenient for the device driver (e.g. for better
72 * optimization), the pointer to the handle_damage operation can be
73 * changed at this point. */
74 errno_t (* change_mode)(struct visualizer *vs, vslmode_t new_mode);
75
76 /**
77 * Device driver shall render the cells from damaged region into its
78 * internal framebuffer. In case the driver use multi-buffering, it
79 * shall also switch internal buffers (e.g. by pageflip). Offsets
80 * are intended to support basic vertical and horizontal scrolling on
81 * the shared backbuffer (i.e. when reading from backbuffer, the offsets
82 * shall be added to the coordinates and if necessary the result shall be
83 * wrapped around the edge of the backbuffer). */
84 errno_t (* handle_damage)(struct visualizer *vs,
85 sysarg_t x, sysarg_t y, sysarg_t width, sysarg_t height,
86 sysarg_t x_offset, sysarg_t y_offset);
87
88 /**
89 * Upper layers of the graphic stack might report inactivity. In such
90 * case, device driver might enable power saving mode on the device
91 * corresponding to the visualizer. */
92 errno_t (* suspend)(struct visualizer *vs);
93
94 /**
95 * When upper layers detect activity on suspended visualizer, device
96 * driver shall disable power saving mode on the corresponding device. */
97 errno_t (* wakeup)(struct visualizer *vs);
98} visualizer_ops_t;
99
100/**
101 * Represents final output device (e.g. monitor connected to the port
102 * on the graphic adapter, serial console, local/remote virtual monitor).
103 */
104typedef struct visualizer {
105 /**
106 * Link to the list of all visualizers belonging to the graphic device.
107 * Field is fully managed by libgraph. */
108 link_t link;
109
110 /**
111 * When reference count equals 1, visualizer is claimed by a client,
112 * when equals 0, visualizer is not claimed. At the time, visualizer
113 * can be claimed only by a single client.
114 * Field is fully managed by libgraph. */
115 atomic_t ref_cnt;
116
117 /**
118 * Visualizer ID assigned by some particular registration service
119 * in the system (either location service or device manager). Intended
120 * for cleanup duties (e.g. unregistering visualizer).
121 * If the visualizer is registered through libgraph functions, then the
122 * field is fully managed by libgraph. Otherwise, it is a driver
123 * responsibility to set and update this field. */
124 sysarg_t reg_svc_handle;
125
126 /**
127 * Visualizer ID in the client context. When client gets notified by
128 * libgraph about some event, it can use this identification to lookup
129 * data structures corresponding to a particular visualizer (e.g. viewports
130 * in the compositor).
131 * Field is fully managed by libgraph. It is assigned when the visualizer
132 * gets claimed and is valid until it is yielded. */
133 sysarg_t client_side_handle;
134
135 /**
136 * Callback session to the client. Established by libgraph during initial
137 * phase of client connection. Can be used to notify client about
138 * external asynchronous changes to the output device state
139 * (e.g. monitor gets disconnected from the graphic adapter, virtual
140 * monitor is terminated by the user, pivot monitor is rotated by 90
141 * degrees, virtual monitor is resized by the user).
142 * Field is fully managed by libgraph. Device driver can use it indirectly
143 * through notification functions. */
144 async_sess_t *notif_sess;
145
146 /**
147 * Mutex protecting the mode list and default mode index. This is required
148 * for the case when device driver might asynchronously update these
149 * upon the request from the final output device (e.g. to change mode
150 * dimensions when virtual monitor is resized).
151 * Both device driver and libgraph must lock on this mutex when accessing
152 * modes list or default mode index. */
153 fibril_mutex_t mode_mtx;
154
155 /**
156 * List of all modes that can be set by this visualizer. List is populated
157 * by device driver when creating a new visualizer or when handling the
158 * request from the final output device to change the available modes.
159 * When this happens, the device driver is expected to increment version
160 * numbers in the modified modes. Modes in the list typically represent
161 * the intersection of modes supported by device driver (graphic adapter)
162 * and final output device (e.g. monitor).
163 * Field is fully managed by device driver, libgraph reads it with locked
164 * mutex. */
165 list_t modes;
166
167 /**
168 * Index of the default mode. Might come in handy to the clients that are
169 * not able to enumerate modes and present the choice to the user
170 * (either the client does not have such functionality or the client is
171 * bootstraping without any preliminary knowledge). Device driver shall
172 * maintain this field at the same time when it is doing any changes to the
173 * mode list.
174 * Field is fully managed by device driver, libgraph reads it with locked
175 * mutex. */
176 sysarg_t def_mode_idx;
177
178 /**
179 * Copy of the currently established mode. It is read by both libgraph and
180 * device driver when deallocating resources for the current mode. Device
181 * driver can also read it to properly interpret the cell type and its
182 * internal structures when handling the damage.
183 * Field is fully managed by libgraph, can be read by device driver. */
184 vslmode_t cur_mode;
185
186 /**
187 * Determines whether the visualizer is currently set to some mode or not,
188 * that is whether cur_mode field contains up-to-date data.
189 * Field is fully managed by libgraph, can be read by device driver. */
190 bool mode_set;
191
192 /**
193 * Device driver function pointers.
194 * Field is fully managed by device driver, libgraph invokes driver's
195 * functions through it. */
196 visualizer_ops_t ops;
197
198 /**
199 * Backbuffer shared with the client. Sharing is established by libgraph.
200 * Device driver reads the cells when handling damage. Cells shall be
201 * interpreted according to the currently set mode.
202 * Field is fully managed by libgraph, can be read by device driver. */
203 pixelmap_t cells;
204
205 /**
206 * Device driver context, completely opaque to the libgraph. Intended to
207 * contain pointers to frontbuffers or information representing the
208 * final output device (e.g. hardware port for physical monitor).
209 * Field is fully managed by device driver. */
210 void *dev_ctx;
211} visualizer_t;
212
213typedef struct {
214 // TODO
215 int dummy;
216} renderer_ops_t;
217
218/**
219 * NOTE: Following description is just a result of brainstorming on how the
220 * driver of real physical graphic accelerator could be supported by
221 * libgraph.
222 *
223 * Renderer represents the hardware graphic accelerator. If the device driver
224 * handles more than one physical accelerator (e.g. graphic cards connected in
225 * SLI mode or single graphic card with two GPUs), it is up to the driver
226 * whether the load balancing will be exposed to the clients (that is the
227 * driver will provide multiple renderers) or not (just a single renderer
228 * handling the load balancing internally).
229 *
230 * At runtime, renderer is represented by scheduling thread and multiple
231 * connection fibrils handling client requests. For each client, there is
232 * command queue, condition variable and device context. Connection fibril puts
233 * the command into the command queue and blocks on the condition variable.
234 * Scheduling thread decides what client to serve, switches corresponding device
235 * context into the accelerator, consumes the command from the command queue and
236 * executes it on the accelerator. When the command execution is finished, the
237 * condition variable si signalled and the connection fibril answers the client.
238 *
239 * Operations that are not implemented in the hardware of the accelerator might
240 * be carried out by worker threads managed by scheduling thread. If the
241 * accelerator physical memory is mapped to the address space of the driver, it
242 * could be extended by allowing scheduling thread to page out the memory and
243 * to handle the page faults.
244 *
245 * NOTE: It is not entirely clear which parts should be implemented in libgraph
246 * and which in the device driver. As a rough sketch, the connection
247 * fibril routine, command queue and memory paging should be handled
248 * by libgraph. The scheduling thread and device context should be
249 * provided by device driver.
250 */
251typedef struct renderer {
252 // TODO
253 link_t link;
254
255 atomic_t ref_cnt;
256
257 sysarg_t reg_svc_handle;
258
259 renderer_ops_t ops;
260} renderer_t;
261
262/*----------------------------------------------------------------------------*/
263
264/**
265 * Fill in the basic visualizer structure. The device driver shall take the
266 * created torso and to complete it by adding its specific structures
267 * (device context, modes). */
268extern void graph_init_visualizer(visualizer_t *);
269
270extern void graph_init_renderer(renderer_t *);
271
272/*----------------------------------------------------------------------------*/
273
274/*
275 * NOTE: All functions in this section are intended to be used only by various
276 * driver emulators (e.g. compositor client containing emulated driver
277 * to render the framebuffer of other compositor or console server).
278 * Driver of the physical hardware shall instead use similar functions
279 * from libdrv.
280 */
281
282/**
283 * Allocate the visualizer so it can be initialized. */
284extern visualizer_t *graph_alloc_visualizer(void);
285
286/**
287 * Register the completely prepared visualizer to the location service and
288 * add it to the driver visualizer list. After the registration, the visualizer
289 * is considered ready to handle client connection. Since visualizer
290 * list is guarded by the mutex, visualizers might be added even after the
291 * initialialization of the device driver. */
292extern errno_t graph_register_visualizer(visualizer_t *);
293
294/**
295 * Retrieve the visualizer from the visualizer list according to its
296 * service ID. */
297extern visualizer_t *graph_get_visualizer(sysarg_t);
298
299/**
300 * Unregister the visualizer from the location service and remove it
301 * from the driver visualizer list. Function shall be called by device driver
302 * before deallocating the resources for the visualizer. */
303extern errno_t graph_unregister_visualizer(visualizer_t *);
304
305/**
306 * Destroy the rest of the visualizer. Device driver shall call this function
307 * only after it has unregistered the visualizer and deallocated all the
308 * resources for which the driver is responsible. */
309extern void graph_destroy_visualizer(visualizer_t *);
310
311extern renderer_t *graph_alloc_renderer(void);
312extern errno_t graph_register_renderer(renderer_t *);
313extern renderer_t *graph_get_renderer(sysarg_t);
314extern errno_t graph_unregister_renderer(renderer_t *);
315extern void graph_destroy_renderer(renderer_t *);
316
317/*----------------------------------------------------------------------------*/
318
319/**
320 * Device driver can call this function to notify the client through the
321 * callback connection that the visualizer with a specified service ID should
322 * be switched to the mode with the given index. */
323extern errno_t graph_notify_mode_change(async_sess_t *, sysarg_t, sysarg_t);
324
325/**
326 * Device driver can call this function to notify the client through the
327 * callback connection that the visualizer with a specified service ID has
328 * lost its output device (e.g. virtual monitor was closed by a user). */
329extern errno_t graph_notify_disconnect(async_sess_t *, sysarg_t);
330
331/*----------------------------------------------------------------------------*/
332
333/** Shall be registered to libdrv by physical device driver. */
334extern void graph_visualizer_connection(visualizer_t *, ipc_callid_t, ipc_call_t *, void *);
335
336/** Shall be registered to libdrv by physical device driver. */
337extern void graph_renderer_connection(renderer_t *, ipc_callid_t, ipc_call_t *, void *);
338
339/** Shall be registered to location service by emulated device driver. */
340extern void graph_client_connection(ipc_callid_t, ipc_call_t *, void *);
341
342#endif
343
344/** @}
345 */
Note: See TracBrowser for help on using the repository browser.