unsigned r600_get_clock_crystal_freq(struct radeon *radeon)
{
- return radeon->clock_crystal_freq;
+ return radeon->info.r600_clock_crystal_freq;
}
unsigned r600_get_num_backends(struct radeon *radeon)
{
- return radeon->num_backends;
+ return radeon->info.r600_num_backends;
}
unsigned r600_get_num_tile_pipes(struct radeon *radeon)
unsigned r600_get_minor_version(struct radeon *radeon)
{
- return radeon->minor_version;
+ return radeon->info.drm_minor;
}
static int r600_interpret_tiling(struct radeon *radeon, uint32_t tiling_config)
static int radeon_drm_get_tiling(struct radeon *radeon)
{
- struct drm_radeon_info info = {};
- int r;
- uint32_t tiling_config = 0;
-
- info.request = RADEON_INFO_TILING_CONFIG;
- info.value = (uintptr_t)&tiling_config;
- r = drmCommandWriteRead(radeon->fd, DRM_RADEON_INFO, &info,
- sizeof(struct drm_radeon_info));
+ uint32_t tiling_config = radeon->info.r600_tiling_config;
- if (r)
+ if (!tiling_config)
return 0;
if (radeon->chip_class == R600 || radeon->chip_class == R700) {
- r = r600_interpret_tiling(radeon, tiling_config);
+ return r600_interpret_tiling(radeon, tiling_config);
} else {
- r = eg_interpret_tiling(radeon, tiling_config);
+ return eg_interpret_tiling(radeon, tiling_config);
}
- return r;
-}
-
-static int radeon_get_clock_crystal_freq(struct radeon *radeon)
-{
- struct drm_radeon_info info = {};
- uint32_t clock_crystal_freq = 0;
- int r;
-
- info.request = RADEON_INFO_CLOCK_CRYSTAL_FREQ;
- info.value = (uintptr_t)&clock_crystal_freq;
- r = drmCommandWriteRead(radeon->fd, DRM_RADEON_INFO, &info,
- sizeof(struct drm_radeon_info));
- if (r)
- return r;
-
- radeon->clock_crystal_freq = clock_crystal_freq;
- return 0;
-}
-
-
-static int radeon_get_num_backends(struct radeon *radeon)
-{
- struct drm_radeon_info info = {};
- uint32_t num_backends = 0;
- int r;
-
- info.request = RADEON_INFO_NUM_BACKENDS;
- info.value = (uintptr_t)&num_backends;
- r = drmCommandWriteRead(radeon->fd, DRM_RADEON_INFO, &info,
- sizeof(struct drm_radeon_info));
- if (r)
- return r;
-
- radeon->num_backends = num_backends;
- return 0;
}
static int radeon_get_num_tile_pipes(struct radeon *radeon)
info.request = RADEON_INFO_NUM_TILE_PIPES;
info.value = (uintptr_t)&num_tile_pipes;
- r = drmCommandWriteRead(radeon->fd, DRM_RADEON_INFO, &info,
+ r = drmCommandWriteRead(radeon->info.fd, DRM_RADEON_INFO, &info,
sizeof(struct drm_radeon_info));
if (r)
return r;
info.request = RADEON_INFO_BACKEND_MAP;
info.value = (uintptr_t)&backend_map;
- r = drmCommandWriteRead(radeon->fd, DRM_RADEON_INFO, &info,
+ r = drmCommandWriteRead(radeon->info.fd, DRM_RADEON_INFO, &info,
sizeof(struct drm_radeon_info));
if (r)
return r;
return 0;
}
-
static int radeon_init_fence(struct radeon *radeon)
{
radeon->fence = 1;
return PTR_TO_UINT(key1) != PTR_TO_UINT(key2);
}
-static struct radeon *radeon_new(struct radeon_winsys *rw)
+struct radeon *r600_drm_winsys_create(struct radeon_winsys *rw)
{
struct radeon *radeon;
int r;
}
rw->query_info(rw, &radeon->info);
- radeon->fd = radeon->info.fd;
- radeon->device = radeon->info.pci_id;
- radeon->num_backends = radeon->info.r600_num_backends;
- radeon->refcount = 1;
- radeon->minor_version = radeon->info.drm_minor;
- radeon->family = radeon_family_from_device(radeon->device);
+ radeon->family = radeon_family_from_device(radeon->info.pci_id);
if (radeon->family == CHIP_UNKNOWN) {
- fprintf(stderr, "Unknown chipset 0x%04X\n", radeon->device);
+ fprintf(stderr, "Unknown chipset 0x%04X\n", radeon->info.pci_id);
return radeon_decref(radeon);
}
/* setup class */
break;
default:
fprintf(stderr, "%s unknown or unsupported chipset 0x%04X\n",
- __func__, radeon->device);
+ __func__, radeon->info.pci_id);
break;
}
if (radeon_drm_get_tiling(radeon))
return NULL;
- /* get the GPU counter frequency, failure is non fatal */
- radeon_get_clock_crystal_freq(radeon);
-
- if (radeon->minor_version >= 9)
- radeon_get_num_backends(radeon);
-
- if (radeon->minor_version >= 11) {
+ if (radeon->info.drm_minor >= 11) {
radeon_get_num_tile_pipes(radeon);
radeon_get_backend_map(radeon);
}
return radeon;
}
-struct radeon *r600_drm_winsys_create(struct radeon_winsys *rw)
-{
- return radeon_new(rw);
-}
-
struct radeon *radeon_decref(struct radeon *radeon)
{
if (radeon == NULL)
return NULL;
- if (--radeon->refcount > 0) {
- return NULL;
- }
util_hash_table_destroy(radeon->bo_handles);
pipe_mutex_destroy(radeon->bo_handles_mutex);
chunks[1].chunk_data = (uint64_t)(uintptr_t)ctx->reloc;
chunk_array[0] = (uint64_t)(uintptr_t)&chunks[0];
chunk_array[1] = (uint64_t)(uintptr_t)&chunks[1];
- r = drmCommandWriteRead(ctx->radeon->fd, DRM_RADEON_CS, &drmib,
+ r = drmCommandWriteRead(ctx->radeon->info.fd, DRM_RADEON_CS, &drmib,
sizeof(struct drm_radeon_cs));
if (r) {
fprintf(stderr, "radeon: The kernel rejected CS, "
struct radeon {
struct radeon_info info;
- int fd;
- int refcount;
- unsigned device;
unsigned family;
enum chip_class chip_class;
struct r600_tiling_info tiling_info;
unsigned fence;
unsigned *cfence;
struct r600_bo *fence_bo;
- unsigned clock_crystal_freq;
- unsigned num_backends;
unsigned num_tile_pipes;
unsigned backend_map;
boolean backend_map_valid;
- unsigned minor_version;
/* List of buffer handles and its mutex. */
struct util_hash_table *bo_handles;
args.handle = bo->handle;
args.offset = 0;
args.size = (uint64_t)bo->size;
- r = drmCommandWriteRead(radeon->fd, DRM_RADEON_GEM_MMAP,
+ r = drmCommandWriteRead(radeon->info.fd, DRM_RADEON_GEM_MMAP,
&args, sizeof(args));
if (r) {
fprintf(stderr, "error mapping %p 0x%08X (error = %d)\n",
bo, bo->handle, r);
return r;
}
- ptr = mmap(0, args.size, PROT_READ|PROT_WRITE, MAP_SHARED, radeon->fd, args.addr_ptr);
+ ptr = mmap(0, args.size, PROT_READ|PROT_WRITE, MAP_SHARED, radeon->info.fd, args.addr_ptr);
if (ptr == MAP_FAILED) {
fprintf(stderr, "%s failed to map bo\n", __func__);
return -errno;
memset(&open_arg, 0, sizeof(open_arg));
open_arg.name = handle;
- r = drmIoctl(radeon->fd, DRM_IOCTL_GEM_OPEN, &open_arg);
+ r = drmIoctl(radeon->info.fd, DRM_IOCTL_GEM_OPEN, &open_arg);
if (r != 0) {
free(bo);
return NULL;
args.initial_domain = initial_domain;
args.flags = 0;
args.handle = 0;
- r = drmCommandWriteRead(radeon->fd, DRM_RADEON_GEM_CREATE,
+ r = drmCommandWriteRead(radeon->info.fd, DRM_RADEON_GEM_CREATE,
&args, sizeof(args));
bo->handle = args.handle;
if (r) {
radeon_bo_fixed_unmap(radeon, bo);
memset(&args, 0, sizeof(args));
args.handle = bo->handle;
- drmIoctl(radeon->fd, DRM_IOCTL_GEM_CLOSE, &args);
+ drmIoctl(radeon->info.fd, DRM_IOCTL_GEM_CLOSE, &args);
memset(bo, 0, sizeof(struct radeon_bo));
free(bo);
}
memset(&args, 0, sizeof(args));
args.handle = bo->handle;
do {
- ret = drmCommandWriteRead(radeon->fd, DRM_RADEON_GEM_WAIT_IDLE,
+ ret = drmCommandWriteRead(radeon->info.fd, DRM_RADEON_GEM_WAIT_IDLE,
&args, sizeof(args));
} while (ret == -EBUSY);
return ret;
args.handle = bo->handle;
args.domain = 0;
- ret = drmCommandWriteRead(radeon->fd, DRM_RADEON_GEM_BUSY,
+ ret = drmCommandWriteRead(radeon->info.fd, DRM_RADEON_GEM_BUSY,
&args, sizeof(args));
*domain = args.domain;
int ret;
args.handle = bo->handle;
- ret = drmCommandWriteRead(radeon->fd, DRM_RADEON_GEM_GET_TILING,
+ ret = drmCommandWriteRead(radeon->info.fd, DRM_RADEON_GEM_GET_TILING,
&args, sizeof(args));
if (ret)
return ret;
int ret;
flink.handle = bo->handle;
- ret = drmIoctl(radeon->fd, DRM_IOCTL_GEM_FLINK, &flink);
+ ret = drmIoctl(radeon->info.fd, DRM_IOCTL_GEM_FLINK, &flink);
if (ret)
return ret;
#include <xf86drm.h>
#include <stdio.h>
+#ifndef RADEON_INFO_TILING_CONFIG
+#define RADEON_INFO_TILING_CONFIG 6
+#endif
+
#ifndef RADEON_INFO_WANT_HYPERZ
#define RADEON_INFO_WANT_HYPERZ 7
#endif
+
#ifndef RADEON_INFO_WANT_CMASK
#define RADEON_INFO_WANT_CMASK 8
#endif
+
+#ifndef RADEON_INFO_CLOCK_CRYSTAL_FREQ
+#define RADEON_INFO_CLOCK_CRYSTAL_FREQ 9
+#endif
+
#ifndef RADEON_INFO_NUM_BACKENDS
#define RADEON_INFO_NUM_BACKENDS 10
#endif
}
static boolean radeon_get_drm_value(int fd, unsigned request,
- const char *name, uint32_t *out)
+ const char *errname, uint32_t *out)
{
struct drm_radeon_info info = {0};
int retval;
info.request = request;
retval = drmCommandWriteRead(fd, DRM_RADEON_INFO, &info, sizeof(info));
- if (retval) {
- fprintf(stderr, "%s: Failed to get %s, error number %d\n",
- __func__, name, retval);
+ if (retval && errname) {
+ fprintf(stderr, "radeon: Failed to get %s, error number %d\n",
+ errname, retval);
return FALSE;
}
return TRUE;
retval = drmCommandWriteRead(ws->fd, DRM_RADEON_GEM_INFO,
&gem_info, sizeof(gem_info));
if (retval) {
- fprintf(stderr, "%s: Failed to get MM info, error number %d\n",
- __FUNCTION__, retval);
+ fprintf(stderr, "radeon: Failed to get MM info, error number %d\n",
+ retval);
return FALSE;
}
ws->info.gart_size = gem_info.gart_size;
return FALSE;
}
else if (ws->gen == R600) {
- if (!radeon_get_drm_value(ws->fd, RADEON_INFO_NUM_BACKENDS,
+ if (ws->info.drm_minor >= 9 &&
+ !radeon_get_drm_value(ws->fd, RADEON_INFO_NUM_BACKENDS,
"num backends",
&ws->info.r600_num_backends))
return FALSE;
+
+ /* get the GPU counter frequency, failure is not fatal */
+ radeon_get_drm_value(ws->fd, RADEON_INFO_CLOCK_CRYSTAL_FREQ, NULL,
+ &ws->info.r600_clock_crystal_freq);
+
+ radeon_get_drm_value(ws->fd, RADEON_INFO_TILING_CONFIG, NULL,
+ &ws->info.r600_tiling_config);
}
return TRUE;
uint32_t r300_num_z_pipes;
uint32_t r600_num_backends;
+ uint32_t r600_clock_crystal_freq;
+ uint32_t r600_tiling_config;
};
enum radeon_feature_id {