libdrm-radeon: be verbose on bo failure and cleanup cs a bit

main
Jerome Glisse 2008-11-10 22:18:22 +01:00
parent 7abb8416a7
commit 72997fb372
2 changed files with 44 additions and 42 deletions

View File

@ -99,11 +99,15 @@ static struct radeon_bo *bo_open(struct radeon_bo_manager *bom,
&args, sizeof(args)); &args, sizeof(args));
bo->base.handle = args.handle; bo->base.handle = args.handle;
if (r) { if (r) {
fprintf(stderr, "Failed to allocate :\n");
fprintf(stderr, " size : %d bytes\n", size);
fprintf(stderr, " alignment : %d bytes\n", alignment);
fprintf(stderr, " domains : %d\n", bo->base.domains);
free(bo); free(bo);
return NULL; return NULL;
} }
} }
radeon_bo_ref(bo); radeon_bo_ref((struct radeon_bo*)bo);
return (struct radeon_bo*)bo; return (struct radeon_bo*)bo;
} }
@ -137,7 +141,6 @@ static int bo_map(struct radeon_bo *bo, int write)
struct radeon_bo_gem *bo_gem = (struct radeon_bo_gem*)bo; struct radeon_bo_gem *bo_gem = (struct radeon_bo_gem*)bo;
struct drm_radeon_gem_mmap args; struct drm_radeon_gem_mmap args;
int r; int r;
uint8_t *tt;
if (bo_gem->map_count++ != 0) { if (bo_gem->map_count++ != 0) {
return 0; return 0;
@ -152,8 +155,10 @@ static int bo_map(struct radeon_bo *bo, int write)
sizeof(args)); sizeof(args));
if (!r) { if (!r) {
bo->ptr = (void *)(unsigned long)args.addr_ptr; bo->ptr = (void *)(unsigned long)args.addr_ptr;
} else {
fprintf(stderr, "error mapping %p 0x%08X (error = %d)\n",
bo, bo->handle, r);
} }
tt = bo->ptr;
return r; return r;
} }

View File

@ -58,7 +58,7 @@ struct cs_gem {
struct radeon_bo **relocs_bo; struct radeon_bo **relocs_bo;
}; };
static struct radeon_cs *cs_create(struct radeon_cs_manager *csm, static struct radeon_cs *cs_gem_create(struct radeon_cs_manager *csm,
uint32_t ndw) uint32_t ndw)
{ {
struct cs_gem *csg; struct cs_gem *csg;
@ -104,7 +104,7 @@ static struct radeon_cs *cs_create(struct radeon_cs_manager *csm,
return (struct radeon_cs*)csg; return (struct radeon_cs*)csg;
} }
static int cs_write_dword(struct radeon_cs *cs, uint32_t dword) static int cs_gem_write_dword(struct radeon_cs *cs, uint32_t dword)
{ {
struct cs_gem *csg = (struct cs_gem*)cs; struct cs_gem *csg = (struct cs_gem*)cs;
if (cs->cdw >= cs->ndw) { if (cs->cdw >= cs->ndw) {
@ -123,7 +123,7 @@ static int cs_write_dword(struct radeon_cs *cs, uint32_t dword)
return 0; return 0;
} }
static int cs_write_reloc(struct radeon_cs *cs, static int cs_gem_write_reloc(struct radeon_cs *cs,
struct radeon_bo *bo, struct radeon_bo *bo,
uint32_t soffset, uint32_t soffset,
uint32_t eoffset, uint32_t eoffset,
@ -162,8 +162,8 @@ static int cs_write_reloc(struct radeon_cs *cs,
break; break;
} }
reloc->cnt++; reloc->cnt++;
cs_write_dword(cs, 0xc0001000); cs_gem_write_dword(cs, 0xc0001000);
cs_write_dword(cs, idx); cs_gem_write_dword(cs, idx);
return 0; return 0;
} }
} }
@ -208,12 +208,12 @@ static int cs_write_reloc(struct radeon_cs *cs,
csg->chunks[1].length_dw += 4; csg->chunks[1].length_dw += 4;
radeon_bo_ref(bo); radeon_bo_ref(bo);
cs->relocs_total_size += bo->size; cs->relocs_total_size += bo->size;
cs_write_dword(cs, 0xc0001000); cs_gem_write_dword(cs, 0xc0001000);
cs_write_dword(cs, idx); cs_gem_write_dword(cs, idx);
return 0; return 0;
} }
static int cs_begin(struct radeon_cs *cs, static int cs_gem_begin(struct radeon_cs *cs,
uint32_t ndw, uint32_t ndw,
const char *file, const char *file,
const char *func, const char *func,
@ -222,7 +222,7 @@ static int cs_begin(struct radeon_cs *cs,
return 0; return 0;
} }
static int cs_end(struct radeon_cs *cs, static int cs_gem_end(struct radeon_cs *cs,
const char *file, const char *file,
const char *func, const char *func,
int line) int line)
@ -232,7 +232,7 @@ static int cs_end(struct radeon_cs *cs,
return 0; return 0;
} }
static int cs_emit(struct radeon_cs *cs) static int cs_gem_emit(struct radeon_cs *cs)
{ {
struct cs_gem *csg = (struct cs_gem*)cs; struct cs_gem *csg = (struct cs_gem*)cs;
uint64_t chunk_array[2]; uint64_t chunk_array[2];
@ -249,13 +249,10 @@ static int cs_emit(struct radeon_cs *cs)
if (r) { if (r) {
return r; return r;
} }
for(i = 0; i < cs->crelocs; i++) {
radeon_bo_unref(csg->relocs_bo[i]);
}
return 0; return 0;
} }
static int cs_destroy(struct radeon_cs *cs) static int cs_gem_destroy(struct radeon_cs *cs)
{ {
struct cs_gem *csg = (struct cs_gem*)cs; struct cs_gem *csg = (struct cs_gem*)cs;
@ -266,7 +263,7 @@ static int cs_destroy(struct radeon_cs *cs)
return 0; return 0;
} }
static int cs_erase(struct radeon_cs *cs) static int cs_gem_erase(struct radeon_cs *cs)
{ {
struct cs_gem *csg = (struct cs_gem*)cs; struct cs_gem *csg = (struct cs_gem*)cs;
@ -279,21 +276,21 @@ static int cs_erase(struct radeon_cs *cs)
return 0; return 0;
} }
static int cs_need_flush(struct radeon_cs *cs) static int cs_gem_need_flush(struct radeon_cs *cs)
{ {
return (cs->relocs_total_size > (16*1024*1024)); return (cs->relocs_total_size > (16*1024*1024));
} }
struct radeon_cs_funcs radeon_cs_funcs = { static struct radeon_cs_funcs radeon_cs_gem_funcs = {
cs_create, cs_gem_create,
cs_write_dword, cs_gem_write_dword,
cs_write_reloc, cs_gem_write_reloc,
cs_begin, cs_gem_begin,
cs_end, cs_gem_end,
cs_emit, cs_gem_emit,
cs_destroy, cs_gem_destroy,
cs_erase, cs_gem_erase,
cs_need_flush cs_gem_need_flush
}; };
struct radeon_cs_manager *radeon_cs_manager_gem(int fd) struct radeon_cs_manager *radeon_cs_manager_gem(int fd)
@ -305,7 +302,7 @@ struct radeon_cs_manager *radeon_cs_manager_gem(int fd)
if (csm == NULL) { if (csm == NULL) {
return NULL; return NULL;
} }
csm->funcs = &radeon_cs_funcs; csm->funcs = &radeon_cs_gem_funcs;
csm->fd = fd; csm->fd = fd;
return csm; return csm;
} }