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 void radeon_set_mem_constant(struct radeon
*radeon
, boolean state
)
35 radeon
->use_mem_constant
= state
;
38 static int radeon_get_device(struct radeon
*radeon
)
40 struct drm_radeon_info info
;
44 info
.request
= RADEON_INFO_DEVICE_ID
;
45 info
.value
= (uintptr_t)&radeon
->device
;
46 r
= drmCommandWriteRead(radeon
->fd
, DRM_RADEON_INFO
, &info
,
47 sizeof(struct drm_radeon_info
));
51 struct radeon
*radeon_new(int fd
, unsigned device
)
53 struct radeon
*radeon
;
56 radeon
= calloc(1, sizeof(*radeon
));
61 radeon
->device
= device
;
64 r
= radeon_get_device(radeon
);
66 fprintf(stderr
, "Failed to get device id\n");
67 return radeon_decref(radeon
);
70 radeon
->family
= radeon_family_from_device(radeon
->device
);
71 if (radeon
->family
== CHIP_UNKNOWN
) {
72 fprintf(stderr
, "Unknown chipset 0x%04X\n", radeon
->device
);
73 return radeon_decref(radeon
);
75 switch (radeon
->family
) {
93 if (r600_init(radeon
)) {
94 return radeon_decref(radeon
);
125 fprintf(stderr
, "%s unknown or unsupported chipset 0x%04X\n",
126 __func__
, radeon
->device
);
130 radeon
->mman
= pb_malloc_bufmgr_create();
133 radeon
->kman
= radeon_bo_pbmgr_create(radeon
);
139 struct radeon
*radeon_incref(struct radeon
*radeon
)
147 struct radeon
*radeon_decref(struct radeon
*radeon
)
151 if (--radeon
->refcount
> 0) {
155 radeon
->mman
->destroy(radeon
->mman
);
156 radeon
->kman
->destroy(radeon
->kman
);
157 drmClose(radeon
->fd
);