Merge remote branch 'main/master' into radeon-rewrite
[mesa.git] / src / gallium / winsys / drm / radeon / xorg / radeon_xorg.c
1 /*
2 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 *
26 * Author: Alan Hourihane <alanh@tungstengraphics.com>
27 * Author: Jakob Bornecrantz <wallbraker@gmail.com>
28 * Author: Corbin Simpson <MostAwesomedude@gmail.com>
29 *
30 */
31
32 #include "../../../../state_trackers/xorg/xorg_winsys.h"
33
34 static void radeon_xorg_identify(int flags);
35 static Bool radeon_xorg_pci_probe(DriverPtr driver,
36 int entity_num,
37 struct pci_device *device,
38 intptr_t match_data);
39
40 static const struct pci_id_match radeon_xorg_device_match[] = {
41 {0x1002, 0x5E4D, 0xffff, 0xffff, 0, 0, 0},
42 {0x1002, 0x7249, 0xffff, 0xffff, 0, 0, 0},
43 {0, 0, 0},
44 };
45
46 static SymTabRec radeon_xorg_chipsets[] = {
47 {0x5E4D, "Radeon RV410 PCIE (X700)"},
48 {0x7249, "Radeon R580 PCIE (X1900 XT)"},
49 {-1, NULL}
50 };
51
52 static PciChipsets radeon_xorg_pci_devices[] = {
53 {0x5E4D, 0x5E4D, RES_SHARED_VGA},
54 {0x7249, 0x7249, RES_SHARED_VGA},
55 {-1, -1, RES_UNDEFINED}
56 };
57
58 static XF86ModuleVersionInfo radeon_xorg_version = {
59 "modesetting",
60 MODULEVENDORSTRING,
61 MODINFOSTRING1,
62 MODINFOSTRING2,
63 XORG_VERSION_CURRENT,
64 0, 1, 0, /* major, minor, patch */
65 ABI_CLASS_VIDEODRV,
66 ABI_VIDEODRV_VERSION,
67 MOD_CLASS_VIDEODRV,
68 {0, 0, 0, 0}
69 };
70
71 /*
72 * Xorg driver exported structures
73 */
74
75 _X_EXPORT DriverRec modesetting = {
76 1,
77 "modesetting",
78 radeon_xorg_identify,
79 NULL,
80 xorg_tracker_available_options,
81 NULL,
82 0,
83 NULL,
84 radeon_xorg_device_match,
85 radeon_xorg_pci_probe
86 };
87
88 static MODULESETUPPROTO(radeon_xorg_setup);
89
90 _X_EXPORT XF86ModuleData modesettingModuleData = {
91 &radeon_xorg_version,
92 radeon_xorg_setup,
93 NULL
94 };
95
96 /*
97 * Xorg driver functions
98 */
99
100 static pointer
101 radeon_xorg_setup(pointer module, pointer opts, int *errmaj, int *errmin)
102 {
103 static Bool setupDone = 0;
104
105 /* This module should be loaded only once, but check to be sure.
106 */
107 if (!setupDone) {
108 setupDone = 1;
109 xf86AddDriver(&modesetting, module, HaveDriverFuncs);
110
111 /*
112 * Tell the loader about symbols from other modules that this module
113 * might refer to.
114 */
115 xorg_tracker_loader_ref_sym_lists();
116
117 /*
118 * The return value must be non-NULL on success even though there
119 * is no TearDownProc.
120 */
121 return (pointer) 1;
122 } else {
123 if (errmaj)
124 *errmaj = LDR_ONCEONLY;
125 return NULL;
126 }
127 }
128
129 static void
130 radeon_xorg_identify(int flags)
131 {
132 xf86PrintChipsets("modesetting", "Driver for Modesetting Kernel Drivers",
133 radeon_xorg_chipsets);
134 }
135
136 static Bool
137 radeon_xorg_pci_probe(DriverPtr driver,
138 int entity_num, struct pci_device *device, intptr_t match_data)
139 {
140 ScrnInfoPtr scrn = NULL;
141 EntityInfoPtr entity;
142
143 scrn = xf86ConfigPciEntity(scrn, 0, entity_num, radeon_xorg_pci_devices,
144 NULL, NULL, NULL, NULL, NULL);
145 if (scrn != NULL) {
146 scrn->driverVersion = 1;
147 scrn->driverName = "modesetting";
148 scrn->name = "modesetting";
149 scrn->Probe = NULL;
150
151 entity = xf86GetEntityInfo(entity_num);
152
153 /* Use all the functions from the xorg tracker */
154 xorg_tracker_set_functions(scrn);
155 }
156 return scrn != NULL;
157 }