f0c1771c77823b481a26f6d279b33af68e0f08df
[mesa.git] / src / mesa / drivers / ggi / display / fbdev_visual.c
1 /******************************************************************************
2
3 display-fbdev-mesa: visual handling
4
5 Copyright (C) 1999 Jon Taylor [taylorj@ggi-project.org]
6
7 Permission is hereby granted, free of charge, to any person obtaining a
8 copy of this software and associated documentation files (the "Software"),
9 to deal in the Software without restriction, including without limitation
10 the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 and/or sell copies of the Software, and to permit persons to whom the
12 Software is furnished to do so, subject to the following conditions:
13
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
24 ******************************************************************************
25 */
26
27 #include <ggi/internal/ggi-dl.h>
28 #include <ggi/mesa/ggimesa_int.h>
29 #include <ggi/mesa/display_fbdev.h>
30 #include <ggi/mesa/debug.h>
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <ctype.h>
36 #include <errno.h>
37 #include <unistd.h>
38 #include <fcntl.h>
39 #include <sys/stat.h>
40
41
42 #ifdef HAVE_SYS_VT_H
43 #include <sys/vt.h>
44 #else
45 #include <linux/vt.h>
46 #endif
47 #ifdef HAVE_LINUX_KDEV_T_H
48 #include <linux/kdev_t.h>
49 #endif
50 #include <linux/tty.h>
51
52 #define MAX_DEV_LEN 63
53 #define DEFAULT_FBNUM 0
54
55 static char accel_prefix[] = "tgt-fbdev-";
56 #define PREFIX_LEN (sizeof(accel_prefix))
57
58 typedef struct {
59 int async;
60 char *str;
61 } accel_info;
62
63 static accel_info accel_strings[] = {
64 { 0, "kgicon-generic",}, /* no accel - check for KGIcon */
65 { 0, NULL }, /* Atari Blitter */
66 };
67
68 #define NUM_ACCELS (sizeof(accel_strings)/sizeof(accel_info))
69
70
71
72 static int GGIopen(ggi_visual *vis, struct ggi_dlhandle *dlh,
73 const char *args, void *argptr, uint32 *dlret)
74 {
75 int err;
76 struct fbdev_priv_mesa *priv;
77 ggifunc_getapi *oldgetapi;
78
79
80 priv->oldpriv = LIBGGI_PRIVATE(vis); /* Hook back */
81
82 GGIMESA_PRIV(vis) = priv = malloc(sizeof(struct fbdev_priv_mesa));
83 if (priv == NULL) {
84 fprintf(stderr, "GGIMesa: Failed to allocate fbdev private data\n");
85 return GGI_ENOMEM;
86 }
87
88 oldgetapi = vis->opdisplay->getapi;
89 vis->opdisplay->getapi = GGIMesa_fbdev_getapi;
90 changed(vis, GGI_CHG_APILIST);
91
92 /* If the accel sublibs didn't sucessfuly hook a driver,
93 * back up and keep looking */
94 if ((LIBGGI_MESAEXT(vis)->update_state == NULL) ||
95 (LIBGGI_MESAEXT(vis)->setup_driver == NULL))
96 {
97 vis->opdisplay->getapi = oldgetapi;
98 }
99
100 *dlret = GGI_DL_EXTENSION;
101 return 0;
102 }
103
104
105 static int GGIclose(ggi_visual *vis, struct ggi_dlhandle *dlh)
106 {
107 struct fbdev_priv_mesa *priv = GGIMESA_PRIV(vis);
108
109 if (priv) {
110 LIBGGI_PRIVATE(vis) = priv->oldpriv;
111 free(priv);
112 }
113
114 return 0;
115 }
116
117
118 int MesaGGIdl_fbdev_mesa(int func, void **funcptr)
119 {
120 switch (func) {
121 case GGIFUNC_open:
122 *funcptr = GGIopen;
123 return 0;
124 case GGIFUNC_exit:
125 *funcptr = NULL;
126 return 0;
127 case GGIFUNC_close:
128 *funcptr = GGIclose;
129 return 0;
130 default:
131 *funcptr = NULL;
132 }
133
134 return GGI_ENOTFOUND;
135 }
136
137
138 #include <ggi/internal/ggidlinit.h>