brintos

brintos / linux-shallow public Read only

0
0
Text · 3.1 KiB · 49ee3fb Raw
136 lines · c
1// SPDX-License-Identifier: GPL-2.02/*3 * Based on the fbdev code in drivers/video/fbdev/core/fb_cmdline:4 *5 *  Copyright (C) 2014 Intel Corp6 *  Copyright (C) 1994 Martin Schaller7 *8 *	2001 - Documented with DocBook9 *	- Brad Douglas <brad@neruo.com>10 *11 * This file is subject to the terms and conditions of the GNU General Public12 * License.  See the file COPYING in the main directory of this archive13 * for more details.14 *15 * Authors:16 *    Daniel Vetter <daniel.vetter@ffwll.ch>17 */18 19#include <linux/fb.h> /* for FB_MAX */20#include <linux/init.h>21 22#include <video/cmdline.h>23 24/*25 * FB_MAX is the maximum number of framebuffer devices and also26 * the maximum number of video= parameters. Although not directly27 * related to each other, it makes sense to keep it that way.28 */29static const char *video_options[FB_MAX] __read_mostly;30static const char *video_option __read_mostly;31static int video_of_only __read_mostly;32 33static const char *__video_get_option_string(const char *name)34{35	const char *options = NULL;36	size_t name_len = 0;37 38	if (name)39		name_len = strlen(name);40 41	if (name_len) {42		unsigned int i;43		const char *opt;44 45		for (i = 0; i < ARRAY_SIZE(video_options); ++i) {46			if (!video_options[i])47				continue;48			if (video_options[i][0] == '\0')49				continue;50			opt = video_options[i];51			if (!strncmp(opt, name, name_len) && opt[name_len] == ':')52				options = opt + name_len + 1;53		}54	}55 56	/* No match, return global options */57	if (!options)58		options = video_option;59 60	return options;61}62 63/**64 * video_get_options - get kernel boot parameters65 * @name:	name of the output as it would appear in the boot parameter66 *		line (video=<name>:<options>)67 *68 * Looks up the video= options for the given name. Names are connector69 * names with DRM, or driver names with fbdev. If no video option for70 * the name has been specified, the function returns the global video=71 * setting. A @name of NULL always returns the global video setting.72 *73 * Returns:74 * The string of video options for the given name, or NULL if no video75 * option has been specified.76 */77const char *video_get_options(const char *name)78{79	return __video_get_option_string(name);80}81EXPORT_SYMBOL(video_get_options);82 83#if IS_ENABLED(CONFIG_FB_CORE)84bool __video_get_options(const char *name, const char **options, bool is_of)85{86	bool enabled = true;87	const char *opt = NULL;88 89	if (video_of_only && !is_of)90		enabled = false;91 92	opt = __video_get_option_string(name);93 94	if (options)95		*options = opt;96 97	return enabled;98}99EXPORT_SYMBOL(__video_get_options);100#endif101 102/*103 * Process command line options for video adapters. This function is104 * a __setup and __init function. It only stores the options. Drivers105 * have to call video_get_options() as necessary.106 */107static int __init video_setup(char *options)108{109	if (!options || !*options)110		goto out;111 112	if (!strncmp(options, "ofonly", 6)) {113		video_of_only = true;114		goto out;115	}116 117	if (strchr(options, ':')) {118		/* named */119		size_t i;120 121		for (i = 0; i < ARRAY_SIZE(video_options); i++) {122			if (!video_options[i]) {123				video_options[i] = options;124				break;125			}126		}127	} else {128		/* global */129		video_option = options;130	}131 132out:133	return 1;134}135__setup("video=", video_setup);136