2 * Copyright (c) 2015 Imre Vadász <imre@vdsz.com>
3 * Copyright (c) 2015 Rimvydas Jasinskas
5 * DRM Dragonfly-specific helper functions
7 * Permission to use, copy, modify, distribute, and sell this software and its
8 * documentation for any purpose is hereby granted without fee, provided that
9 * the above copyright notice appear in all copies and that both that copyright
10 * notice and this permission notice appear in supporting documentation, and
11 * that the name of the copyright holders not be used in advertising or
12 * publicity pertaining to distribution of the software without specific,
13 * written prior permission. The copyright holders make no representations
14 * about the suitability of this software for any purpose. It is provided "as
15 * is" without express or implied warranty.
17 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
18 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
19 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
20 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
22 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
26 #include <sys/libkern.h>
27 #include <sys/ctype.h>
31 commit 26a028bf8c7694e64d44f9e2bb8bd0fba47d7519
32 Author: Imre Vadász <imre@vdsz.com>
33 Date: Tue Jun 2 23:14:52 2015 +0200
35 drm: hack together an implementation of fb_get_options
37 This can be used to set the video mode used for the syscons fb console,
38 a la "video=..." in linux.
42 * An implementation of fb_get_options()
43 * This can be used to set the video mode used for the syscons fb console,
44 * a la "video=..." in linux.
47 fb_get_options(const char *connector_name, char **option)
49 char buf[128], str[1024];
53 * This hack allows us to use drm.video.lvds1="<video-mode>"
54 * in loader.conf, where linux would use video=LVDS-1:<video-mode>.
55 * e.g. drm.video.lvds1=1024x768 sets the LVDS-1 connector to
56 * a 1024x768 video mode in the syscons framebuffer console.
57 * See https://wiki.archlinux.org/index.php/Kernel_mode_setting
58 * for an explanation of the video mode command line option.
59 * (This corresponds to the video= Linux kernel command-line
62 memset(str, 0, sizeof(str));
63 ksnprintf(buf, sizeof(buf), "drm.video.%s", connector_name);
65 while (i < strlen(buf)) {
66 buf[i] = tolower(buf[i]);
68 memmove(&buf[i], &buf[i+1], strlen(buf)-i);
73 kprintf("looking up kenv for \"%s\"\n", buf);
74 if (kgetenv_string(buf, str, sizeof(str)-1)) {
75 kprintf("found kenv %s=%s\n", buf, str);
76 *option = kstrdup(str, M_DRM);
79 kprintf("didn't find value for kenv %s\n", buf);
85 * Implement simplified version of kvasnrprintf() for drm needs using
86 * M_DRM and kvsnprintf(). Since it is unclear what string size is
87 * optimal thus use of an actual length.
89 char *drm_vasprintf(int flags, const char *format, __va_list ap)
96 size = kvsnprintf(NULL, 0, format, aq);
99 str = kmalloc(size+1, M_DRM, flags);
103 kvsnprintf(str, size+1, format, ap);
108 /* mimic ksnrprintf(), return pointer to char* and match drm api */
109 char *drm_asprintf(int flags, const char *format, ...)
114 __va_start(ap, format);
115 str = drm_vasprintf(flags, format, ap);