Merge branch 'mesa_7_6_branch' into mesa_7_7_branch
[mesa.git] / src / gallium / winsys / drm / vmware / xorg / 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 static void vmw_xorg_identify(int flags);
37 static Bool vmw_xorg_pci_probe(DriverPtr driver,
38 int entity_num,
39 struct pci_device *device,
40 intptr_t match_data);
41
42 static const struct pci_id_match vmw_xorg_device_match[] = {
43 {0x15ad, PCI_MATCH_ANY, PCI_MATCH_ANY, PCI_MATCH_ANY, 0, 0, 0},
44 {0, 0, 0, 0, 0, 0, 0},
45 };
46
47 static SymTabRec vmw_xorg_chipsets[] = {
48 {PCI_MATCH_ANY, "VMware SVGA Device"},
49 {-1, NULL}
50 };
51
52 static PciChipsets vmw_xorg_pci_devices[] = {
53 {PCI_MATCH_ANY, PCI_MATCH_ANY, NULL},
54 {-1, -1, NULL}
55 };
56
57 static XF86ModuleVersionInfo vmw_xorg_version = {
58 "vmwgfx",
59 MODULEVENDORSTRING,
60 MODINFOSTRING1,
61 MODINFOSTRING2,
62 XORG_VERSION_CURRENT,
63 0, 1, 0, /* major, minor, patch */
64 ABI_CLASS_VIDEODRV,
65 ABI_VIDEODRV_VERSION,
66 MOD_CLASS_VIDEODRV,
67 {0, 0, 0, 0}
68 };
69
70 /*
71 * Xorg driver exported structures
72 */
73
74 _X_EXPORT DriverRec vmwgfx = {
75 1,
76 "vmwgfx",
77 vmw_xorg_identify,
78 NULL,
79 xorg_tracker_available_options,
80 NULL,
81 0,
82 NULL,
83 vmw_xorg_device_match,
84 vmw_xorg_pci_probe
85 };
86
87 static MODULESETUPPROTO(vmw_xorg_setup);
88
89 _X_EXPORT XF86ModuleData vmwgfxModuleData = {
90 &vmw_xorg_version,
91 vmw_xorg_setup,
92 NULL
93 };
94
95 /*
96 * Xorg driver functions
97 */
98
99 static pointer
100 vmw_xorg_setup(pointer module, pointer opts, int *errmaj, int *errmin)
101 {
102 static Bool setupDone = 0;
103
104 /* This module should be loaded only once, but check to be sure.
105 */
106 if (!setupDone) {
107 setupDone = 1;
108 xf86AddDriver(&vmwgfx, module, HaveDriverFuncs);
109
110 /*
111 * The return value must be non-NULL on success even though there
112 * is no TearDownProc.
113 */
114 return (pointer) 1;
115 } else {
116 if (errmaj)
117 *errmaj = LDR_ONCEONLY;
118 return NULL;
119 }
120 }
121
122 static void
123 vmw_xorg_identify(int flags)
124 {
125 xf86PrintChipsets("vmwgfx", "Driver for VMware SVGA device",
126 vmw_xorg_chipsets);
127 }
128
129 static Bool
130 vmw_xorg_pci_probe(DriverPtr driver,
131 int entity_num, struct pci_device *device, intptr_t match_data)
132 {
133 ScrnInfoPtr scrn = NULL;
134 EntityInfoPtr entity;
135
136 scrn = xf86ConfigPciEntity(scrn, 0, entity_num, vmw_xorg_pci_devices,
137 NULL, NULL, NULL, NULL, NULL);
138 if (scrn != NULL) {
139 scrn->driverVersion = 1;
140 scrn->driverName = "vmwgfx";
141 scrn->name = "vmwgfx";
142 scrn->Probe = NULL;
143
144 entity = xf86GetEntityInfo(entity_num);
145
146 /* Use all the functions from the xorg tracker */
147 xorg_tracker_set_functions(scrn);
148
149 vmw_screen_set_functions(scrn);
150 }
151 return scrn != NULL;
152 }