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"
27 enum radeon_family
radeon_get_family(struct radeon
*radeon
)
29 return radeon
->family
;
32 static int radeon_get_device(struct radeon
*radeon
)
34 struct drm_radeon_info info
;
38 info
.request
= RADEON_INFO_DEVICE_ID
;
39 info
.value
= (uintptr_t)&radeon
->device
;
40 r
= drmCommandWriteRead(radeon
->fd
, DRM_RADEON_INFO
, &info
,
41 sizeof(struct drm_radeon_info
));
45 /* symbol missing drove me crazy hack to get symbol exported */
46 static void fake(void)
48 struct radeon_ctx
*ctx
;
49 struct radeon_draw
*draw
;
51 ctx
= radeon_ctx(NULL
);
52 draw
= radeon_draw(NULL
);
55 struct radeon
*radeon_new(int fd
, unsigned device
)
57 struct radeon
*radeon
;
60 radeon
= calloc(1, sizeof(*radeon
));
66 radeon
->device
= device
;
69 r
= radeon_get_device(radeon
);
71 fprintf(stderr
, "Failed to get device id\n");
72 return radeon_decref(radeon
);
75 radeon
->family
= radeon_family_from_device(radeon
->device
);
76 if (radeon
->family
== CHIP_UNKNOWN
) {
77 fprintf(stderr
, "Unknown chipset 0x%04X\n", radeon
->device
);
78 return radeon_decref(radeon
);
80 switch (radeon
->family
) {
93 if (r600_init(radeon
)) {
94 return radeon_decref(radeon
);
130 fprintf(stderr
, "%s unknown or unsupported chipset 0x%04X\n",
131 __func__
, radeon
->device
);
137 struct radeon
*radeon_incref(struct radeon
*radeon
)
145 struct radeon
*radeon_decref(struct radeon
*radeon
)
149 if (--radeon
->refcount
> 0) {
152 drmClose(radeon
->fd
);
157 int radeon_reg_id(struct radeon
*radeon
, unsigned offset
, unsigned *typeid, unsigned *stateid
, unsigned *id
)
161 for (i
= 0; i
< radeon
->ntype
; i
++) {
162 if (radeon
->type
[i
].range_start
) {
163 if (offset
>= radeon
->type
[i
].range_start
&& offset
< radeon
->type
[i
].range_end
) {
165 j
= offset
- radeon
->type
[i
].range_start
;
166 j
/= radeon
->type
[i
].stride
;
167 *stateid
= radeon
->type
[i
].id
+ j
;
168 *id
= (offset
- radeon
->type
[i
].range_start
- radeon
->type
[i
].stride
* j
) / 4;
172 for (j
= 0; j
< radeon
->type
[i
].nstates
; j
++) {
173 if (radeon
->type
[i
].regs
[j
].offset
== offset
) {
175 *stateid
= radeon
->type
[i
].id
;
182 fprintf(stderr
, "%s unknown register 0x%08X\n", __func__
, offset
);
186 unsigned radeon_type_from_id(struct radeon
*radeon
, unsigned id
)
190 for (i
= 0; i
< radeon
->ntype
- 1; i
++) {
191 if (radeon
->type
[i
].id
== id
)
193 if (id
> radeon
->type
[i
].id
&& id
< radeon
->type
[i
+ 1].id
)
196 if (radeon
->type
[i
].id
== id
)