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 void radeon_set_mem_constant(struct radeon
*radeon
, boolean state
)
34 radeon
->use_mem_constant
= state
;
37 static int radeon_get_device(struct radeon
*radeon
)
39 struct drm_radeon_info info
;
43 info
.request
= RADEON_INFO_DEVICE_ID
;
44 info
.value
= (uintptr_t)&radeon
->device
;
45 r
= drmCommandWriteRead(radeon
->fd
, DRM_RADEON_INFO
, &info
,
46 sizeof(struct drm_radeon_info
));
50 struct radeon
*radeon_new(int fd
, unsigned device
)
52 struct radeon
*radeon
;
55 radeon
= calloc(1, sizeof(*radeon
));
60 radeon
->device
= device
;
63 r
= radeon_get_device(radeon
);
65 fprintf(stderr
, "Failed to get device id\n");
66 return radeon_decref(radeon
);
69 radeon
->family
= radeon_family_from_device(radeon
->device
);
70 if (radeon
->family
== CHIP_UNKNOWN
) {
71 fprintf(stderr
, "Unknown chipset 0x%04X\n", radeon
->device
);
72 return radeon_decref(radeon
);
74 switch (radeon
->family
) {
92 if (r600_init(radeon
)) {
93 return radeon_decref(radeon
);
124 fprintf(stderr
, "%s unknown or unsupported chipset 0x%04X\n",
125 __func__
, radeon
->device
);
131 struct radeon
*radeon_incref(struct radeon
*radeon
)
139 struct radeon
*radeon_decref(struct radeon
*radeon
)
143 if (--radeon
->refcount
> 0) {
146 drmClose(radeon
->fd
);