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.
23 #include <pipebuffer/pb_bufmgr.h>
25 #include "radeon_priv.h"
26 #include "radeon_drm.h"
28 enum radeon_family
radeon_get_family(struct radeon
*radeon
)
30 return radeon
->family
;
33 enum chip_class
radeon_get_family_class(struct radeon
*radeon
)
35 return radeon
->chip_class
;
38 void radeon_set_mem_constant(struct radeon
*radeon
, boolean state
)
40 radeon
->use_mem_constant
= state
;
43 static int radeon_get_device(struct radeon
*radeon
)
45 struct drm_radeon_info info
;
49 info
.request
= RADEON_INFO_DEVICE_ID
;
50 info
.value
= (uintptr_t)&radeon
->device
;
51 r
= drmCommandWriteRead(radeon
->fd
, DRM_RADEON_INFO
, &info
,
52 sizeof(struct drm_radeon_info
));
56 struct radeon
*radeon_new(int fd
, unsigned device
)
58 struct radeon
*radeon
;
61 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
) {
98 if (r600_init(radeon
)) {
99 return radeon_decref(radeon
);
130 fprintf(stderr
, "%s unknown or unsupported chipset 0x%04X\n",
131 __func__
, radeon
->device
);
136 switch (radeon
->family
) {
145 radeon
->chip_class
= R600
;
151 radeon
->chip_class
= R700
;
158 radeon
->chip_class
= EVERGREEN
;
161 fprintf(stderr
, "%s unknown or unsupported chipset 0x%04X\n",
162 __func__
, radeon
->device
);
166 radeon
->mman
= pb_malloc_bufmgr_create();
169 radeon
->kman
= radeon_bo_pbmgr_create(radeon
);
172 radeon
->cman
= pb_cache_manager_create(radeon
->kman
, 100000);
178 struct radeon
*radeon_incref(struct radeon
*radeon
)
186 struct radeon
*radeon_decref(struct radeon
*radeon
)
190 if (--radeon
->refcount
> 0) {
194 radeon
->mman
->destroy(radeon
->mman
);
195 radeon
->cman
->destroy(radeon
->cman
);
196 radeon
->kman
->destroy(radeon
->kman
);
197 drmClose(radeon
->fd
);