fdcadffc532320611434f0796f88269e3fadde2f
[mesa.git] / src / gallium / winsys / r600 / drm / r600.c
1 /*
2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Authors:
24 * Jerome Glisse
25 */
26 #include "xf86drm.h"
27 #include "radeon_drm.h"
28 #include "r600_priv.h"
29
30 enum radeon_family r600_get_family(struct radeon *r600)
31 {
32 return r600->family;
33 }
34
35 enum chip_class r600_get_family_class(struct radeon *radeon)
36 {
37 return radeon->chip_class;
38 }
39
40 static int r600_get_device(struct radeon *r600)
41 {
42 struct drm_radeon_info info;
43
44 r600->device = 0;
45 info.request = RADEON_INFO_DEVICE_ID;
46 info.value = (uintptr_t)&r600->device;
47 return drmCommandWriteRead(r600->fd, DRM_RADEON_INFO, &info, sizeof(struct drm_radeon_info));
48 }
49
50 struct radeon *r600_new(int fd, unsigned device)
51 {
52 struct radeon *r600;
53 int r;
54
55 r600 = calloc(1, sizeof(*r600));
56 if (r600 == NULL) {
57 return NULL;
58 }
59 r600->fd = fd;
60 r600->device = device;
61 if (fd >= 0) {
62 r = r600_get_device(r600);
63 if (r) {
64 R600_ERR("Failed to get device id\n");
65 r600_delete(r600);
66 return NULL;
67 }
68 }
69 r600->family = radeon_family_from_device(r600->device);
70 if (r600->family == CHIP_UNKNOWN) {
71 R600_ERR("Unknown chipset 0x%04X\n", r600->device);
72 r600_delete(r600);
73 return NULL;
74 }
75 switch (r600->family) {
76 case CHIP_R600:
77 case CHIP_RV610:
78 case CHIP_RV630:
79 case CHIP_RV670:
80 case CHIP_RV620:
81 case CHIP_RV635:
82 case CHIP_RS780:
83 case CHIP_RS880:
84 case CHIP_RV770:
85 case CHIP_RV730:
86 case CHIP_RV710:
87 case CHIP_RV740:
88 break;
89 case CHIP_R100:
90 case CHIP_RV100:
91 case CHIP_RS100:
92 case CHIP_RV200:
93 case CHIP_RS200:
94 case CHIP_R200:
95 case CHIP_RV250:
96 case CHIP_RS300:
97 case CHIP_RV280:
98 case CHIP_R300:
99 case CHIP_R350:
100 case CHIP_RV350:
101 case CHIP_RV380:
102 case CHIP_R420:
103 case CHIP_R423:
104 case CHIP_RV410:
105 case CHIP_RS400:
106 case CHIP_RS480:
107 case CHIP_RS600:
108 case CHIP_RS690:
109 case CHIP_RS740:
110 case CHIP_RV515:
111 case CHIP_R520:
112 case CHIP_RV530:
113 case CHIP_RV560:
114 case CHIP_RV570:
115 case CHIP_R580:
116 case CHIP_CEDAR:
117 case CHIP_REDWOOD:
118 case CHIP_JUNIPER:
119 case CHIP_CYPRESS:
120 case CHIP_HEMLOCK:
121 default:
122 R600_ERR("unknown or unsupported chipset 0x%04X\n", r600->device);
123 break;
124 }
125
126 /* setup class */
127 switch (r600->family) {
128 case CHIP_R600:
129 case CHIP_RV610:
130 case CHIP_RV630:
131 case CHIP_RV670:
132 case CHIP_RV620:
133 case CHIP_RV635:
134 case CHIP_RS780:
135 case CHIP_RS880:
136 r600->chip_class = R600;
137 break;
138 case CHIP_RV770:
139 case CHIP_RV730:
140 case CHIP_RV710:
141 case CHIP_RV740:
142 r600->chip_class = R700;
143 break;
144 case CHIP_CEDAR:
145 case CHIP_REDWOOD:
146 case CHIP_JUNIPER:
147 case CHIP_CYPRESS:
148 case CHIP_HEMLOCK:
149 r600->chip_class = EVERGREEN;
150 break;
151 default:
152 R600_ERR("unknown or unsupported chipset 0x%04X\n", r600->device);
153 break;
154 }
155
156 return r600;
157 }
158
159 void r600_delete(struct radeon *r600)
160 {
161 if (r600 == NULL)
162 return;
163 drmClose(r600->fd);
164 free(r600);
165 }