Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / gallium / targets / xorg-vmwgfx / vmw_xorg.c
1 /**********************************************************
2  * Copyright 2008-2009 VMware, Inc.  All rights reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person
5  * obtaining a copy of this software and associated documentation
6  * files (the "Software"), to deal in the Software without
7  * restriction, including without limitation the rights to use, copy,
8  * modify, merge, publish, distribute, sublicense, and/or sell copies
9  * of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  *
24  **********************************************************/
25
26 /**
27  * @file
28  * Glue file for Xorg State Tracker.
29  *
30  * @author Alan Hourihane <alanh@tungstengraphics.com>
31  * @author Jakob Bornecrantz <wallbraker@gmail.com>
32  */
33
34 #include "vmw_hook.h"
35
36
37 /*
38  * Defines and modinfo
39  */
40
41 #define VMWGFX_DRIVER_NAME "vmwgfx"
42
43 #define VMW_STRING_INNER(s) #s
44 #define VMW_STRING(str) VMW_STRING_INNER(str)
45
46 #define VMWGFX_VERSION_MAJOR 11
47 #define VMWGFX_VERSION_MINOR 0
48 #define VMWGFX_VERSION_PATCH 0
49 #define VMWGFX_VERSION_STRING_MAJOR VMW_STRING(VMWGFX_VERSION_MAJOR)
50 #define VMWGFX_VERSION_STRING_MINOR VMW_STRING(VMWGFX_VERSION_MINOR)
51 #define VMWGFX_VERSION_STRING_PATCH VMW_STRING(VMWGFX_VERSION_PATCH)
52
53 #define VMWGFX_DRIVER_VERSION \
54    (VMWGFX_VERSION_MAJOR * 65536 + VMWGFX_VERSION_MINOR * 256 + VMWGFX_VERSION_PATCH)
55 #define VMWGFX_DRIVER_VERSION_STRING \
56     VMWGFX_VERSION_STRING_MAJOR "." VMWGFX_VERSION_STRING_MINOR \
57     "." VMWGFX_VERSION_STRING_PATCH
58
59 /*
60  * Standard four digit version string expected by VMware Tools installer.
61  * As the driver's version is only  {major, minor, patchlevel}, simply append an
62  * extra zero for the fourth digit.
63  */
64 #ifdef __GNUC__
65 _X_EXPORT const char vmwgfx_drv_modinfo[] __attribute__((section(".modinfo"),unused)) =
66     "version=" VMWGFX_DRIVER_VERSION_STRING ".0";
67 #endif
68
69 static void vmw_xorg_identify(int flags);
70 _X_EXPORT Bool vmw_xorg_pci_probe(DriverPtr driver,
71                                   int entity_num,
72                                   struct pci_device *device,
73                                   intptr_t match_data);
74
75
76 /*
77  * Tables
78  */
79
80 static const struct pci_id_match vmw_xorg_device_match[] = {
81     {0x15ad, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, 0, 0, 0},
82     {0, 0, 0, 0, 0, 0, 0},
83 };
84
85 static SymTabRec vmw_xorg_chipsets[] = {
86     {PCI_MATCH_ANY, "VMware SVGA Device"},
87     {-1, NULL}
88 };
89
90 static PciChipsets vmw_xorg_pci_devices[] = {
91     {PCI_MATCH_ANY, PCI_MATCH_ANY, NULL},
92     {-1, -1, NULL}
93 };
94
95 static XF86ModuleVersionInfo vmw_xorg_version = {
96     VMWGFX_DRIVER_NAME,
97     MODULEVENDORSTRING,
98     MODINFOSTRING1,
99     MODINFOSTRING2,
100     XORG_VERSION_CURRENT,
101     VMWGFX_VERSION_MAJOR, VMWGFX_VERSION_MINOR, VMWGFX_VERSION_PATCH,
102     ABI_CLASS_VIDEODRV,
103     ABI_VIDEODRV_VERSION,
104     MOD_CLASS_VIDEODRV,
105     {0, 0, 0, 0}
106 };
107
108 /*
109  * Xorg driver exported structures
110  */
111
112 _X_EXPORT DriverRec vmwgfx = {
113     1,
114     VMWGFX_DRIVER_NAME,
115     vmw_xorg_identify,
116     NULL,
117     xorg_tracker_available_options,
118     NULL,
119     0,
120     NULL,
121     vmw_xorg_device_match,
122     vmw_xorg_pci_probe
123 };
124
125 static MODULESETUPPROTO(vmw_xorg_setup);
126
127 _X_EXPORT XF86ModuleData vmwgfxModuleData = {
128     &vmw_xorg_version,
129     vmw_xorg_setup,
130     NULL
131 };
132
133
134 /*
135  * Xorg driver functions
136  */
137
138 static pointer
139 vmw_xorg_setup(pointer module, pointer opts, int *errmaj, int *errmin)
140 {
141     static Bool setupDone = 0;
142
143     /* This module should be loaded only once, but check to be sure.
144      */
145     if (!setupDone) {
146         setupDone = 1;
147         xf86AddDriver(&vmwgfx, module, HaveDriverFuncs);
148
149         /*
150          * The return value must be non-NULL on success even though there
151          * is no TearDownProc.
152          */
153         return (pointer) 1;
154     } else {
155         if (errmaj)
156             *errmaj = LDR_ONCEONLY;
157         return NULL;
158     }
159 }
160
161 static void
162 vmw_xorg_identify(int flags)
163 {
164     xf86PrintChipsets("vmwgfx", "Driver for VMware SVGA device",
165                       vmw_xorg_chipsets);
166 }
167
168 _X_EXPORT Bool
169 vmw_xorg_pci_probe(DriverPtr driver,
170           int entity_num, struct pci_device *device, intptr_t match_data)
171 {
172     ScrnInfoPtr scrn = NULL;
173     EntityInfoPtr entity;
174
175     scrn = xf86ConfigPciEntity(scrn, 0, entity_num, vmw_xorg_pci_devices,
176                                NULL, NULL, NULL, NULL, NULL);
177     if (scrn != NULL) {
178         scrn->driverVersion = 1;
179         scrn->driverName = "vmwgfx";
180         scrn->name = "vmwgfx";
181         scrn->Probe = NULL;
182
183         entity = xf86GetEntityInfo(entity_num);
184
185         /* Use all the functions from the xorg tracker */
186         xorg_tracker_set_functions(scrn);
187
188         vmw_screen_set_functions(scrn);
189     }
190     return scrn != NULL;
191 }