ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / char / drm / drm_init.h
1 /**
2  * \file drm_init.h 
3  * Setup/Cleanup for DRM
4  *
5  * \author Rickard E. (Rik) Faith <faith@valinux.com>
6  * \author Gareth Hughes <gareth@valinux.com>
7  */
8
9 /*
10  * Created: Mon Jan  4 08:58:31 1999 by faith@valinux.com
11  *
12  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
13  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
14  * All Rights Reserved.
15  *
16  * Permission is hereby granted, free of charge, to any person obtaining a
17  * copy of this software and associated documentation files (the "Software"),
18  * to deal in the Software without restriction, including without limitation
19  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
20  * and/or sell copies of the Software, and to permit persons to whom the
21  * Software is furnished to do so, subject to the following conditions:
22  *
23  * The above copyright notice and this permission notice (including the next
24  * paragraph) shall be included in all copies or substantial portions of the
25  * Software.
26  *
27  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
30  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
31  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
32  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
33  * OTHER DEALINGS IN THE SOFTWARE.
34  */
35
36 #include "drmP.h"
37
38 /** Debug flags.  Set by parse_option(). */
39 #if 0
40 int DRM(flags) = DRM_FLAG_DEBUG;
41 #else
42 int DRM(flags) = 0;
43 #endif
44
45 /**
46  * Parse a single option.
47  *
48  * \param s option string.
49  *
50  * \sa See parse_options() for details.
51  */
52 static void DRM(parse_option)(char *s)
53 {
54         char *c, *r;
55
56         DRM_DEBUG("\"%s\"\n", s);
57         if (!s || !*s) return;
58         for (c = s; *c && *c != ':'; c++); /* find : or \0 */
59         if (*c) r = c + 1; else r = NULL;  /* remember remainder */
60         *c = '\0';                         /* terminate */
61         if (!strcmp(s, "debug")) {
62                 DRM(flags) |= DRM_FLAG_DEBUG;
63                 DRM_INFO("Debug messages ON\n");
64                 return;
65         }
66         DRM_ERROR("\"%s\" is not a valid option\n", s);
67         return;
68 }
69
70 /**
71  * Parse the insmod "drm_opts=" options, or the command-line
72  * options passed to the kernel via LILO.  
73  *
74  * \param s contains option_list without the 'drm_opts=' part.
75  *
76  * The grammar of the format is as
77  * follows:
78  *
79  * \code
80  * drm          ::= 'drm_opts=' option_list
81  * option_list  ::= option [ ';' option_list ]
82  * option       ::= 'device:' major
83  *              |   'debug'
84  *              |   'noctx'
85  * major        ::= INTEGER
86  * \endcode
87  *
88  * - device=major,minor specifies the device number used for /dev/drm
89  *   - if major == 0 then the misc device is used
90  *   - if major == 0 and minor == 0 then dynamic misc allocation is used
91  * - debug=on specifies that debugging messages will be printk'd
92  * - debug=trace specifies that each function call will be logged via printk
93  * - debug=off turns off all debugging options
94  *
95  * \todo Actually only the \e presence of the 'debug' option is currently
96  * checked.
97  */
98
99 void DRM(parse_options)(char *s)
100 {
101         char *h, *t, *n;
102
103         DRM_DEBUG("\"%s\"\n", s ?: "");
104         if (!s || !*s) return;
105
106         for (h = t = n = s; h && *h; h = n) {
107                 for (; *t && *t != ';'; t++);          /* find ; or \0 */
108                 if (*t) n = t + 1; else n = NULL;      /* remember next */
109                 *t = '\0';                             /* terminate */
110                 DRM(parse_option)(h);                  /* parse */
111         }
112 }
113
114 /**
115  * Check whether DRI will run on this CPU.
116  *
117  * \return non-zero if the DRI will run on this CPU, or zero otherwise.
118  */
119 int DRM(cpu_valid)(void)
120 {
121 #if defined(__i386__)
122         if (boot_cpu_data.x86 == 3) return 0; /* No cmpxchg on a 386 */
123 #endif
124 #if defined(__sparc__) && !defined(__sparc_v9__)
125         return 0; /* No cmpxchg before v9 sparc. */
126 #endif
127         return 1;
128 }