linux/drivers/gpu/drm/nouveau/core/core/option.c
<<
>>
Prefs
   1/*
   2 * Copyright 2012 Red Hat Inc.
   3 *
   4 * Permission is hereby granted, free of charge, to any person obtaining a
   5 * copy of this software and associated documentation files (the "Software"),
   6 * to deal in the Software without restriction, including without limitation
   7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
   8 * and/or sell copies of the Software, and to permit persons to whom the
   9 * Software is furnished to do so, subject to the following conditions:
  10 *
  11 * The above copyright notice and this permission notice shall be included in
  12 * all copies or substantial portions of the Software.
  13 *
  14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20 * OTHER DEALINGS IN THE SOFTWARE.
  21 *
  22 * Authors: Ben Skeggs
  23 */
  24
  25#include <core/option.h>
  26#include <core/debug.h>
  27
  28const char *
  29nouveau_stropt(const char *optstr, const char *opt, int *arglen)
  30{
  31        while (optstr && *optstr != '\0') {
  32                int len = strcspn(optstr, ",=");
  33                switch (optstr[len]) {
  34                case '=':
  35                        if (!strncasecmpz(optstr, opt, len)) {
  36                                optstr += len + 1;
  37                                *arglen = strcspn(optstr, ",=");
  38                                return *arglen ? optstr : NULL;
  39                        }
  40                        optstr++;
  41                        break;
  42                case ',':
  43                        optstr++;
  44                        break;
  45                default:
  46                        break;
  47                }
  48                optstr += len;
  49        }
  50
  51        return NULL;
  52}
  53
  54bool
  55nouveau_boolopt(const char *optstr, const char *opt, bool value)
  56{
  57        int arglen;
  58
  59        optstr = nouveau_stropt(optstr, opt, &arglen);
  60        if (optstr) {
  61                if (!strncasecmpz(optstr, "0", arglen) ||
  62                    !strncasecmpz(optstr, "no", arglen) ||
  63                    !strncasecmpz(optstr, "off", arglen) ||
  64                    !strncasecmpz(optstr, "false", arglen))
  65                        value = false;
  66                else
  67                if (!strncasecmpz(optstr, "1", arglen) ||
  68                    !strncasecmpz(optstr, "yes", arglen) ||
  69                    !strncasecmpz(optstr, "on", arglen) ||
  70                    !strncasecmpz(optstr, "true", arglen))
  71                        value = true;
  72        }
  73
  74        return value;
  75}
  76
  77int
  78nouveau_dbgopt(const char *optstr, const char *sub)
  79{
  80        int mode = 1, level = CONFIG_NOUVEAU_DEBUG_DEFAULT;
  81
  82        while (optstr) {
  83                int len = strcspn(optstr, ",=");
  84                switch (optstr[len]) {
  85                case '=':
  86                        if (strncasecmpz(optstr, sub, len))
  87                                mode = 0;
  88                        optstr++;
  89                        break;
  90                default:
  91                        if (mode) {
  92                                if (!strncasecmpz(optstr, "fatal", len))
  93                                        level = NV_DBG_FATAL;
  94                                else if (!strncasecmpz(optstr, "error", len))
  95                                        level = NV_DBG_ERROR;
  96                                else if (!strncasecmpz(optstr, "warn", len))
  97                                        level = NV_DBG_WARN;
  98                                else if (!strncasecmpz(optstr, "info", len))
  99                                        level = NV_DBG_INFO_NORMAL;
 100                                else if (!strncasecmpz(optstr, "debug", len))
 101                                        level = NV_DBG_DEBUG;
 102                                else if (!strncasecmpz(optstr, "trace", len))
 103                                        level = NV_DBG_TRACE;
 104                                else if (!strncasecmpz(optstr, "paranoia", len))
 105                                        level = NV_DBG_PARANOIA;
 106                                else if (!strncasecmpz(optstr, "spam", len))
 107                                        level = NV_DBG_SPAM;
 108                        }
 109
 110                        if (optstr[len] != '\0') {
 111                                optstr++;
 112                                mode = 1;
 113                                break;
 114                        }
 115
 116                        return level;
 117                }
 118                optstr += len;
 119        }
 120
 121        return level;
 122}
 123