cmdline.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Based on the fbdev code in drivers/video/fbdev/core/fb_cmdline:
  4. *
  5. * Copyright (C) 2014 Intel Corp
  6. * Copyright (C) 1994 Martin Schaller
  7. *
  8. * 2001 - Documented with DocBook
  9. * - Brad Douglas <brad@neruo.com>
  10. *
  11. * This file is subject to the terms and conditions of the GNU General Public
  12. * License. See the file COPYING in the main directory of this archive
  13. * for more details.
  14. *
  15. * Authors:
  16. * Daniel Vetter <daniel.vetter@ffwll.ch>
  17. */
  18. #include <linux/fb.h> /* for FB_MAX */
  19. #include <linux/init.h>
  20. #include <video/cmdline.h>
  21. /*
  22. * FB_MAX is the maximum number of framebuffer devices and also
  23. * the maximum number of video= parameters. Although not directly
  24. * related to each other, it makes sense to keep it that way.
  25. */
  26. static const char *video_options[FB_MAX] __read_mostly;
  27. static const char *video_option __read_mostly;
  28. static int video_of_only __read_mostly;
  29. static const char *__video_get_option_string(const char *name)
  30. {
  31. const char *options = NULL;
  32. size_t name_len = 0;
  33. if (name)
  34. name_len = strlen(name);
  35. if (name_len) {
  36. unsigned int i;
  37. const char *opt;
  38. for (i = 0; i < ARRAY_SIZE(video_options); ++i) {
  39. if (!video_options[i])
  40. continue;
  41. if (video_options[i][0] == '\0')
  42. continue;
  43. opt = video_options[i];
  44. if (!strncmp(opt, name, name_len) && opt[name_len] == ':')
  45. options = opt + name_len + 1;
  46. }
  47. }
  48. /* No match, return global options */
  49. if (!options)
  50. options = video_option;
  51. return options;
  52. }
  53. /**
  54. * video_get_options - get kernel boot parameters
  55. * @name: name of the output as it would appear in the boot parameter
  56. * line (video=<name>:<options>)
  57. *
  58. * Looks up the video= options for the given name. Names are connector
  59. * names with DRM, or driver names with fbdev. If no video option for
  60. * the name has been specified, the function returns the global video=
  61. * setting. A @name of NULL always returns the global video setting.
  62. *
  63. * Returns:
  64. * The string of video options for the given name, or NULL if no video
  65. * option has been specified.
  66. */
  67. const char *video_get_options(const char *name)
  68. {
  69. return __video_get_option_string(name);
  70. }
  71. EXPORT_SYMBOL(video_get_options);
  72. #if IS_ENABLED(CONFIG_FB_CORE)
  73. bool __video_get_options(const char *name, const char **options, bool is_of)
  74. {
  75. bool enabled = true;
  76. const char *opt = NULL;
  77. if (video_of_only && !is_of)
  78. enabled = false;
  79. opt = __video_get_option_string(name);
  80. if (options)
  81. *options = opt;
  82. return enabled;
  83. }
  84. EXPORT_SYMBOL(__video_get_options);
  85. #endif
  86. /*
  87. * Process command line options for video adapters. This function is
  88. * a __setup and __init function. It only stores the options. Drivers
  89. * have to call video_get_options() as necessary.
  90. */
  91. static int __init video_setup(char *options)
  92. {
  93. if (!options || !*options)
  94. goto out;
  95. if (!strncmp(options, "ofonly", 6)) {
  96. video_of_only = true;
  97. goto out;
  98. }
  99. if (strchr(options, ':')) {
  100. /* named */
  101. size_t i;
  102. for (i = 0; i < ARRAY_SIZE(video_options); i++) {
  103. if (!video_options[i]) {
  104. video_options[i] = options;
  105. break;
  106. }
  107. }
  108. } else {
  109. /* global */
  110. video_option = options;
  111. }
  112. out:
  113. return 1;
  114. }
  115. __setup("video=", video_setup);