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 struct radeon
*radeon_new(int fd
, unsigned device
)
47 struct radeon
*radeon
;
50 radeon
= calloc(1, sizeof(*radeon
));
55 radeon
->device
= device
;
58 r
= radeon_get_device(radeon
);
60 fprintf(stderr
, "Failed to get device id\n");
61 return radeon_decref(radeon
);
64 radeon
->family
= radeon_family_from_device(radeon
->device
);
65 if (radeon
->family
== CHIP_UNKNOWN
) {
66 fprintf(stderr
, "Unknown chipset 0x%04X\n", radeon
->device
);
67 return radeon_decref(radeon
);
69 switch (radeon
->family
) {
87 if (r600_init(radeon
)) {
88 return radeon_decref(radeon
);
119 fprintf(stderr
, "%s unknown or unsupported chipset 0x%04X\n",
120 __func__
, radeon
->device
);
126 struct radeon
*radeon_incref(struct radeon
*radeon
)
134 struct radeon
*radeon_decref(struct radeon
*radeon
)
138 if (--radeon
->refcount
> 0) {
141 drmClose(radeon
->fd
);