7e6566980640c28db5afdcec37a3de142db1fd08
2 * Copyright © 2009 Jerome Glisse <glisse@freedesktop.org>
4 * This file is free software; you can redistribute it and/or modify
5 * it under the terms of version 2 of the GNU General Public License
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
24 #include "radeon_priv.h"
25 #include "radeon_drm.h"
28 enum radeon_family
radeon_get_family(struct radeon
*radeon
)
30 return radeon
->family
;
33 static int radeon_get_device(struct radeon
*radeon
)
35 struct drm_radeon_info info
;
39 info
.request
= RADEON_INFO_DEVICE_ID
;
40 info
.value
= (uintptr_t)&radeon
->device
;
41 r
= drmCommandWriteRead(radeon
->fd
, DRM_RADEON_INFO
, &info
,
42 sizeof(struct drm_radeon_info
));
46 /* symbol missing drove me crazy hack to get symbol exported */
47 static void fake(void)
49 struct radeon_ctx
*ctx
;
50 struct radeon_draw
*draw
;
52 ctx
= radeon_ctx(NULL
);
53 draw
= radeon_draw(NULL
);
56 struct radeon
*radeon_new(int fd
, unsigned device
)
58 struct radeon
*radeon
;
61 radeon
= calloc(1, sizeof(*radeon
));
67 radeon
->device
= device
;
70 r
= radeon_get_device(radeon
);
72 fprintf(stderr
, "Failed to get device id\n");
73 return radeon_decref(radeon
);
76 radeon
->family
= radeon_family_from_device(radeon
->device
);
77 if (radeon
->family
== CHIP_UNKNOWN
) {
78 fprintf(stderr
, "Unknown chipset 0x%04X\n", radeon
->device
);
79 return radeon_decref(radeon
);
81 switch (radeon
->family
) {
94 if (r600_init(radeon
)) {
95 return radeon_decref(radeon
);
131 fprintf(stderr
, "%s unknown or unsupported chipset 0x%04X\n",
132 __func__
, radeon
->device
);
138 struct radeon
*radeon_incref(struct radeon
*radeon
)
146 struct radeon
*radeon_decref(struct radeon
*radeon
)
150 if (--radeon
->refcount
> 0) {
153 drmClose(radeon
->fd
);
158 int radeon_reg_id(struct radeon
*radeon
, unsigned offset
, unsigned *typeid, unsigned *stateid
, unsigned *id
)
162 for (i
= 0; i
< radeon
->ntype
; i
++) {
163 if (radeon
->type
[i
].range_start
) {
164 if (offset
>= radeon
->type
[i
].range_start
&& offset
< radeon
->type
[i
].range_end
) {
166 j
= offset
- radeon
->type
[i
].range_start
;
167 j
/= radeon
->type
[i
].stride
;
168 *stateid
= radeon
->type
[i
].id
+ j
;
169 *id
= (offset
- radeon
->type
[i
].range_start
- radeon
->type
[i
].stride
* j
) / 4;
173 for (j
= 0; j
< radeon
->type
[i
].nstates
; j
++) {
174 if (radeon
->type
[i
].regs
[j
].offset
== offset
) {
176 *stateid
= radeon
->type
[i
].id
;
183 fprintf(stderr
, "%s unknown register 0x%08X\n", __func__
, offset
);
187 unsigned radeon_type_from_id(struct radeon
*radeon
, unsigned id
)
191 for (i
= 0; i
< radeon
->ntype
- 1; i
++) {
192 if (radeon
->type
[i
].id
== id
)
194 if (id
> radeon
->type
[i
].id
&& id
< radeon
->type
[i
+ 1].id
)
197 if (radeon
->type
[i
].id
== id
)