24d821d5cf00d67350a97dddc6b84e5070ab3f35
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 struct radeon
*radeon_new(int fd
, unsigned device
)
48 struct radeon
*radeon
;
51 radeon
= calloc(1, sizeof(*radeon
));
56 radeon
->device
= device
;
59 r
= radeon_get_device(radeon
);
61 fprintf(stderr
, "Failed to get device id\n");
62 return radeon_decref(radeon
);
65 radeon
->family
= radeon_family_from_device(radeon
->device
);
66 if (radeon
->family
== CHIP_UNKNOWN
) {
67 fprintf(stderr
, "Unknown chipset 0x%04X\n", radeon
->device
);
68 return radeon_decref(radeon
);
70 switch (radeon
->family
) {
83 if (r600_init(radeon
)) {
84 return radeon_decref(radeon
);
120 fprintf(stderr
, "%s unknown or unsupported chipset 0x%04X\n",
121 __func__
, radeon
->device
);
127 struct radeon
*radeon_incref(struct radeon
*radeon
)
135 struct radeon
*radeon_decref(struct radeon
*radeon
)
139 if (--radeon
->refcount
> 0) {
142 drmClose(radeon
->fd
);
147 int radeon_reg_id(struct radeon
*radeon
, unsigned offset
, unsigned *typeid, unsigned *stateid
, unsigned *id
)
151 for (i
= 0; i
< radeon
->ntype
; i
++) {
152 if (radeon
->type
[i
].range_start
) {
153 if (offset
>= radeon
->type
[i
].range_start
&& offset
< radeon
->type
[i
].range_end
) {
155 j
= offset
- radeon
->type
[i
].range_start
;
156 j
/= radeon
->type
[i
].stride
;
157 *stateid
= radeon
->type
[i
].id
+ j
;
158 *id
= (offset
- radeon
->type
[i
].range_start
- radeon
->type
[i
].stride
* j
) / 4;
162 for (j
= 0; j
< radeon
->type
[i
].nstates
; j
++) {
163 if (radeon
->type
[i
].regs
[j
].offset
== offset
) {
165 *stateid
= radeon
->type
[i
].id
;
172 fprintf(stderr
, "%s unknown register 0x%08X\n", __func__
, offset
);
176 unsigned radeon_type_from_id(struct radeon
*radeon
, unsigned id
)
180 for (i
= 0; i
< radeon
->ntype
- 1; i
++) {
181 if (radeon
->type
[i
].id
== id
)
183 if (id
> radeon
->type
[i
].id
&& id
< radeon
->type
[i
+ 1].id
)
186 if (radeon
->type
[i
].id
== id
)