void drmSetServerInfo(drmServerInfoPtr info)
{
- drm_server_info = info;
+ drm_server_info = info;
}
/**
static int drmDebugPrint(const char *format, va_list ap)
{
- return vfprintf(stderr, format, ap);
+ return vfprintf(stderr, format, ap);
}
static int (*drm_debug_print)(const char *format, va_list ap) = drmDebugPrint;
void
drmSetDebugMsgFunction(int (*debug_msg_ptr)(const char *format, va_list ap))
{
- drm_debug_print = debug_msg_ptr;
+ drm_debug_print = debug_msg_ptr;
}
static void *drmHashTable = NULL; /* Context switch callbacks */
void *drmGetHashTable(void)
{
- return drmHashTable;
+ return drmHashTable;
}
void *drmMalloc(int size)
{
void *pt;
- if ((pt = malloc(size))) memset(pt, 0, size);
+ if ((pt = malloc(size)))
+ memset(pt, 0, size);
return pt;
}
void drmFree(void *pt)
{
- if (pt) free(pt);
+ if (pt)
+ free(pt);
}
/* drmStrdup can't use strdup(3), since it doesn't call _DRM_MALLOC... */
void *value;
drmHashEntry *entry;
- if (!drmHashTable) drmHashTable = drmHashCreate();
+ if (!drmHashTable)
+ drmHashTable = drmHashCreate();
if (drmHashLookup(drmHashTable, key, &value)) {
entry = drmMalloc(sizeof(*entry));
drmMsg("drmOpenDevice: node name is %s\n", buf);
if (drm_server_info) {
- drm_server_info->get_perms(&serv_group, &serv_mode);
- devmode = serv_mode ? serv_mode : DRM_DEV_MODE;
- devmode &= ~(S_IXUSR|S_IXGRP|S_IXOTH);
- group = (serv_group >= 0) ? serv_group : DRM_DEV_GID;
+ drm_server_info->get_perms(&serv_group, &serv_mode);
+ devmode = serv_mode ? serv_mode : DRM_DEV_MODE;
+ devmode &= ~(S_IXUSR|S_IXGRP|S_IXOTH);
+ group = (serv_group >= 0) ? serv_group : DRM_DEV_GID;
}
if (stat(DRM_DIR_NAME, &st)) {
- if (!isroot) return DRM_ERR_NOT_ROOT;
+ if (!isroot)
+ return DRM_ERR_NOT_ROOT;
mkdir(DRM_DIR_NAME, DRM_DEV_DIRMODE);
chown(DRM_DIR_NAME, 0, 0); /* root:root */
chmod(DRM_DIR_NAME, DRM_DEV_DIRMODE);
/* Check if the device node exists and create it if necessary. */
if (stat(buf, &st)) {
- if (!isroot) return DRM_ERR_NOT_ROOT;
+ if (!isroot)
+ return DRM_ERR_NOT_ROOT;
remove(buf);
mknod(buf, S_IFCHR | devmode, dev);
}
if (drm_server_info) {
- chown(buf, user, group);
- chmod(buf, devmode);
+ chown(buf, user, group);
+ chmod(buf, devmode);
}
fd = open(buf, O_RDWR, 0);
drmMsg("drmOpenDevice: open result is %d, (%s)\n",
fd, fd < 0 ? strerror(errno) : "OK");
- if (fd >= 0) return fd;
+ if (fd >= 0)
+ return fd;
/* Check if the device node is not what we expect it to be, and recreate it
* and try again if so.
*/
if (st.st_rdev != dev) {
- if (!isroot) return DRM_ERR_NOT_ROOT;
+ if (!isroot)
+ return DRM_ERR_NOT_ROOT;
remove(buf);
mknod(buf, S_IFCHR | devmode, dev);
if (drm_server_info) {
- chown(buf, user, group);
- chmod(buf, devmode);
+ chown(buf, user, group);
+ chmod(buf, devmode);
}
}
fd = open(buf, O_RDWR, 0);
drmMsg("drmOpenDevice: open result is %d, (%s)\n",
fd, fd < 0 ? strerror(errno) : "OK");
- if (fd >= 0) return fd;
+ if (fd >= 0)
+ return fd;
drmMsg("drmOpenDevice: Open failed\n");
remove(buf);
int fd;
char buf[64];
- if (create) return drmOpenDevice(makedev(DRM_MAJOR, minor), minor);
+ if (create)
+ return drmOpenDevice(makedev(DRM_MAJOR, minor), minor);
sprintf(buf, DRM_DEV_NAME, DRM_DIR_NAME, minor);
- if ((fd = open(buf, O_RDWR, 0)) >= 0) return fd;
+ if ((fd = open(buf, O_RDWR, 0)) >= 0)
+ return fd;
return -errno;
}
if ((fd = drmOpenMinor(0, 1)) < 0) {
#ifdef __linux__
/* Try proc for backward Linux compatibility */
- if (!access("/proc/dri/0", R_OK)) return 1;
+ if (!access("/proc/dri/0", R_OK))
+ return 1;
#endif
return 0;
}
drmFreeBusid(buf);
return fd;
}
- if (buf) drmFreeBusid(buf);
+ if (buf)
+ drmFreeBusid(buf);
close(fd);
}
}
char * id;
if (!drmAvailable()) {
- if (!drm_server_info)
- return -1;
- else {
- /* try to load the kernel module now */
- if (!drm_server_info->load_module(name)) {
- drmMsg("[drm] failed to load kernel module \"%s\"\n",
- name);
- return -1;
- }
- }
+ if (!drm_server_info) {
+ return -1;
+ }
+ else {
+ /* try to load the kernel module now */
+ if (!drm_server_info->load_module(name)) {
+ drmMsg("[drm] failed to load kernel module \"%s\"\n", name);
+ return -1;
+ }
+ }
}
/*
if (!drmAvailable() && name != NULL && drm_server_info) {
/* try to load the kernel */
if (!drm_server_info->load_module(name)) {
- drmMsg("[drm] failed to load kernel module \"%s\"\n",
- name);
+ drmMsg("[drm] failed to load kernel module \"%s\"\n", name);
return -1;
}
}
if (busid) {
- int fd;
-
- fd = drmOpenByBusid(busid);
+ int fd = drmOpenByBusid(busid);
if (fd >= 0)
return fd;
}
*/
void drmFreeVersion(drmVersionPtr v)
{
- if (!v) return;
+ if (!v)
+ return;
drmFree(v->name);
drmFree(v->date);
drmFree(v->desc);
*/
static void drmFreeKernelVersion(drm_version_t *v)
{
- if (!v) return;
+ if (!v)
+ return;
drmFree(v->name);
drmFree(v->date);
drmFree(v->desc);
u.unique_len = 0;
u.unique = NULL;
- if (ioctl(fd, DRM_IOCTL_GET_UNIQUE, &u)) return NULL;
+ if (ioctl(fd, DRM_IOCTL_GET_UNIQUE, &u))
+ return NULL;
u.unique = drmMalloc(u.unique_len + 1);
- if (ioctl(fd, DRM_IOCTL_GET_UNIQUE, &u)) return NULL;
+ if (ioctl(fd, DRM_IOCTL_GET_UNIQUE, &u))
+ return NULL;
u.unique[u.unique_len] = '\0';
return u.unique;
drm_auth_t auth;
*magic = 0;
- if (ioctl(fd, DRM_IOCTL_GET_MAGIC, &auth)) return -errno;
+ if (ioctl(fd, DRM_IOCTL_GET_MAGIC, &auth))
+ return -errno;
*magic = auth.magic;
return 0;
}
drm_auth_t auth;
auth.magic = magic;
- if (ioctl(fd, DRM_IOCTL_AUTH_MAGIC, &auth)) return -errno;
+ if (ioctl(fd, DRM_IOCTL_AUTH_MAGIC, &auth))
+ return -errno;
return 0;
}
map.handle = 0;
map.type = type;
map.flags = flags;
- if (ioctl(fd, DRM_IOCTL_ADD_MAP, &map)) return -errno;
- if (handle) *handle = (drm_handle_t)map.handle;
+ if (ioctl(fd, DRM_IOCTL_ADD_MAP, &map))
+ return -errno;
+ if (handle)
+ *handle = (drm_handle_t)map.handle;
return 0;
}
map.handle = (void *)handle;
- if(ioctl(fd, DRM_IOCTL_RM_MAP, &map)) return -errno;
+ if(ioctl(fd, DRM_IOCTL_RM_MAP, &map))
+ return -errno;
return 0;
}
request.flags = flags;
request.agp_start = agp_offset;
- if (ioctl(fd, DRM_IOCTL_ADD_BUFS, &request)) return -errno;
+ if (ioctl(fd, DRM_IOCTL_ADD_BUFS, &request))
+ return -errno;
return request.count;
}
info.count = 0;
info.list = NULL;
- if (ioctl(fd, DRM_IOCTL_INFO_BUFS, &info)) return -EINVAL;
+ if (ioctl(fd, DRM_IOCTL_INFO_BUFS, &info))
+ return -EINVAL;
- if (!info.count) return -EINVAL;
+ if (!info.count)
+ return -EINVAL;
if (!(info.list = drmMalloc(info.count * sizeof(*info.list))))
return -ENOMEM;
request.count = count;
request.list = list;
- if (ioctl(fd, DRM_IOCTL_FREE_BUFS, &request)) return -errno;
+ if (ioctl(fd, DRM_IOCTL_FREE_BUFS, &request))
+ return -errno;
return 0;
}
{
static unsigned long pagesize_mask = 0;
- if (fd < 0) return -EINVAL;
+ if (fd < 0)
+ return -EINVAL;
if (!pagesize_mask)
pagesize_mask = getpagesize() - 1;
size = (size + pagesize_mask) & ~pagesize_mask;
*address = mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, handle);
- if (*address == MAP_FAILED) return -errno;
+ if (*address == MAP_FAILED)
+ return -errno;
return 0;
}
info.count = 0;
info.list = NULL;
- if (ioctl(fd, DRM_IOCTL_INFO_BUFS, &info)) return NULL;
+ if (ioctl(fd, DRM_IOCTL_INFO_BUFS, &info))
+ return NULL;
if (info.count) {
if (!(info.list = drmMalloc(info.count * sizeof(*info.list))))
bufs.count = 0;
bufs.list = NULL;
bufs.virtual = NULL;
- if (ioctl(fd, DRM_IOCTL_MAP_BUFS, &bufs)) return NULL;
+ if (ioctl(fd, DRM_IOCTL_MAP_BUFS, &bufs))
+ return NULL;
- if (!bufs.count) return NULL;
+ if (!bufs.count)
+ return NULL;
if (!(bufs.list = drmMalloc(bufs.count * sizeof(*bufs.list))))
return NULL;
res.count = 0;
res.contexts = NULL;
- if (ioctl(fd, DRM_IOCTL_RES_CTX, &res)) return NULL;
+ if (ioctl(fd, DRM_IOCTL_RES_CTX, &res))
+ return NULL;
- if (!res.count) return NULL;
+ if (!res.count)
+ return NULL;
- if (!(list = drmMalloc(res.count * sizeof(*list)))) return NULL;
+ if (!(list = drmMalloc(res.count * sizeof(*list))))
+ return NULL;
if (!(retval = drmMalloc(res.count * sizeof(*retval)))) {
drmFree(list);
return NULL;
}
res.contexts = list;
- if (ioctl(fd, DRM_IOCTL_RES_CTX, &res)) return NULL;
+ if (ioctl(fd, DRM_IOCTL_RES_CTX, &res))
+ return NULL;
- for (i = 0; i < res.count; i++) retval[i] = list[i].handle;
+ for (i = 0; i < res.count; i++)
+ retval[i] = list[i].handle;
drmFree(list);
*count = res.count;
drm_ctx_t ctx;
ctx.flags = 0; /* Modified with functions below */
- if (ioctl(fd, DRM_IOCTL_ADD_CTX, &ctx)) return -errno;
+ if (ioctl(fd, DRM_IOCTL_ADD_CTX, &ctx))
+ return -errno;
*handle = ctx.handle;
return 0;
}
drm_ctx_t ctx;
ctx.handle = context;
- if (ioctl(fd, DRM_IOCTL_SWITCH_CTX, &ctx)) return -errno;
+ if (ioctl(fd, DRM_IOCTL_SWITCH_CTX, &ctx))
+ return -errno;
return 0;
}
*/
ctx.handle = context;
ctx.flags = 0;
- if (flags & DRM_CONTEXT_PRESERVED) ctx.flags |= _DRM_CONTEXT_PRESERVED;
- if (flags & DRM_CONTEXT_2DONLY) ctx.flags |= _DRM_CONTEXT_2DONLY;
- if (ioctl(fd, DRM_IOCTL_MOD_CTX, &ctx)) return -errno;
+ if (flags & DRM_CONTEXT_PRESERVED)
+ ctx.flags |= _DRM_CONTEXT_PRESERVED;
+ if (flags & DRM_CONTEXT_2DONLY)
+ ctx.flags |= _DRM_CONTEXT_2DONLY;
+ if (ioctl(fd, DRM_IOCTL_MOD_CTX, &ctx))
+ return -errno;
return 0;
}
drm_ctx_t ctx;
ctx.handle = context;
- if (ioctl(fd, DRM_IOCTL_GET_CTX, &ctx)) return -errno;
+ if (ioctl(fd, DRM_IOCTL_GET_CTX, &ctx))
+ return -errno;
*flags = 0;
- if (ctx.flags & _DRM_CONTEXT_PRESERVED) *flags |= DRM_CONTEXT_PRESERVED;
- if (ctx.flags & _DRM_CONTEXT_2DONLY) *flags |= DRM_CONTEXT_2DONLY;
+ if (ctx.flags & _DRM_CONTEXT_PRESERVED)
+ *flags |= DRM_CONTEXT_PRESERVED;
+ if (ctx.flags & _DRM_CONTEXT_2DONLY)
+ *flags |= DRM_CONTEXT_2DONLY;
return 0;
}
{
drm_ctx_t ctx;
ctx.handle = handle;
- if (ioctl(fd, DRM_IOCTL_RM_CTX, &ctx)) return -errno;
+ if (ioctl(fd, DRM_IOCTL_RM_CTX, &ctx))
+ return -errno;
return 0;
}
int drmCreateDrawable(int fd, drm_drawable_t *handle)
{
drm_draw_t draw;
- if (ioctl(fd, DRM_IOCTL_ADD_DRAW, &draw)) return -errno;
+ if (ioctl(fd, DRM_IOCTL_ADD_DRAW, &draw))
+ return -errno;
*handle = draw.handle;
return 0;
}
{
drm_draw_t draw;
draw.handle = handle;
- if (ioctl(fd, DRM_IOCTL_RM_DRAW, &draw)) return -errno;
+ if (ioctl(fd, DRM_IOCTL_RM_DRAW, &draw))
+ return -errno;
return 0;
}
update.num = num;
update.data = (unsigned long long)(unsigned long)data;
- if (ioctl(fd, DRM_IOCTL_UPDATE_DRAW, &update)) return -errno;
+ if (ioctl(fd, DRM_IOCTL_UPDATE_DRAW, &update))
+ return -errno;
return 0;
}
*/
int drmAgpAcquire(int fd)
{
- if (ioctl(fd, DRM_IOCTL_AGP_ACQUIRE, NULL)) return -errno;
+ if (ioctl(fd, DRM_IOCTL_AGP_ACQUIRE, NULL))
+ return -errno;
return 0;
}
*/
int drmAgpRelease(int fd)
{
- if (ioctl(fd, DRM_IOCTL_AGP_RELEASE, NULL)) return -errno;
+ if (ioctl(fd, DRM_IOCTL_AGP_RELEASE, NULL))
+ return -errno;
return 0;
}
drm_agp_mode_t m;
m.mode = mode;
- if (ioctl(fd, DRM_IOCTL_AGP_ENABLE, &m)) return -errno;
+ if (ioctl(fd, DRM_IOCTL_AGP_ENABLE, &m))
+ return -errno;
return 0;
}
b.size = size;
b.handle = 0;
b.type = type;
- if (ioctl(fd, DRM_IOCTL_AGP_ALLOC, &b)) return -errno;
- if (address != 0UL) *address = b.physical;
+ if (ioctl(fd, DRM_IOCTL_AGP_ALLOC, &b))
+ return -errno;
+ if (address != 0UL)
+ *address = b.physical;
*handle = b.handle;
return 0;
}
b.size = 0;
b.handle = handle;
- if (ioctl(fd, DRM_IOCTL_AGP_FREE, &b)) return -errno;
+ if (ioctl(fd, DRM_IOCTL_AGP_FREE, &b))
+ return -errno;
return 0;
}
b.handle = handle;
b.offset = offset;
- if (ioctl(fd, DRM_IOCTL_AGP_BIND, &b)) return -errno;
+ if (ioctl(fd, DRM_IOCTL_AGP_BIND, &b))
+ return -errno;
return 0;
}
b.handle = handle;
b.offset = 0;
- if (ioctl(fd, DRM_IOCTL_AGP_UNBIND, &b)) return -errno;
+ if (ioctl(fd, DRM_IOCTL_AGP_UNBIND, &b))
+ return -errno;
return 0;
}
{
drm_agp_info_t i;
- if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i)) return -errno;
+ if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i))
+ return -errno;
return i.agp_version_major;
}
{
drm_agp_info_t i;
- if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i)) return -errno;
+ if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i))
+ return -errno;
return i.agp_version_minor;
}
{
drm_agp_info_t i;
- if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i)) return 0;
+ if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i))
+ return 0;
return i.mode;
}
{
drm_agp_info_t i;
- if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i)) return 0;
+ if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i))
+ return 0;
return i.aperture_base;
}
{
drm_agp_info_t i;
- if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i)) return 0;
+ if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i))
+ return 0;
return i.aperture_size;
}
{
drm_agp_info_t i;
- if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i)) return 0;
+ if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i))
+ return 0;
return i.memory_used;
}
{
drm_agp_info_t i;
- if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i)) return 0;
+ if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i))
+ return 0;
return i.memory_allowed;
}
{
drm_agp_info_t i;
- if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i)) return 0;
+ if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i))
+ return 0;
return i.id_vendor;
}
{
drm_agp_info_t i;
- if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i)) return 0;
+ if (ioctl(fd, DRM_IOCTL_AGP_INFO, &i))
+ return 0;
return i.id_device;
}
*handle = 0;
sg.size = size;
sg.handle = 0;
- if (ioctl(fd, DRM_IOCTL_SG_ALLOC, &sg)) return -errno;
+ if (ioctl(fd, DRM_IOCTL_SG_ALLOC, &sg))
+ return -errno;
*handle = sg.handle;
return 0;
}
sg.size = 0;
sg.handle = handle;
- if (ioctl(fd, DRM_IOCTL_SG_FREE, &sg)) return -errno;
+ if (ioctl(fd, DRM_IOCTL_SG_FREE, &sg))
+ return -errno;
return 0;
}
int drmError(int err, const char *label)
{
switch (err) {
- case DRM_ERR_NO_DEVICE: fprintf(stderr, "%s: no device\n", label); break;
- case DRM_ERR_NO_ACCESS: fprintf(stderr, "%s: no access\n", label); break;
- case DRM_ERR_NOT_ROOT: fprintf(stderr, "%s: not root\n", label); break;
- case DRM_ERR_INVALID: fprintf(stderr, "%s: invalid args\n", label);break;
+ case DRM_ERR_NO_DEVICE:
+ fprintf(stderr, "%s: no device\n", label);
+ break;
+ case DRM_ERR_NO_ACCESS:
+ fprintf(stderr, "%s: no access\n", label);
+ break;
+ case DRM_ERR_NOT_ROOT:
+ fprintf(stderr, "%s: not root\n", label);
+ break;
+ case DRM_ERR_INVALID:
+ fprintf(stderr, "%s: invalid args\n", label);
+ break;
default:
- if (err < 0) err = -err;
+ if (err < 0)
+ err = -err;
fprintf( stderr, "%s: error %d (%s)\n", label, err, strerror(err) );
break;
}
ctl.func = DRM_INST_HANDLER;
ctl.irq = irq;
- if (ioctl(fd, DRM_IOCTL_CONTROL, &ctl)) return -errno;
+ if (ioctl(fd, DRM_IOCTL_CONTROL, &ctl))
+ return -errno;
return 0;
}
ctl.func = DRM_UNINST_HANDLER;
ctl.irq = 0;
- if (ioctl(fd, DRM_IOCTL_CONTROL, &ctl)) return -errno;
+ if (ioctl(fd, DRM_IOCTL_CONTROL, &ctl))
+ return -errno;
return 0;
}
if (flags & DRM_LOCK_FLUSH_ALL) lock.flags |= _DRM_LOCK_FLUSH_ALL;
if (flags & DRM_HALT_ALL_QUEUES) lock.flags |= _DRM_HALT_ALL_QUEUES;
if (flags & DRM_HALT_CUR_QUEUES) lock.flags |= _DRM_HALT_CUR_QUEUES;
- if (ioctl(fd, DRM_IOCTL_FINISH, &lock)) return -errno;
+ if (ioctl(fd, DRM_IOCTL_FINISH, &lock))
+ return -errno;
return 0;
}
p.busnum = busnum;
p.devnum = devnum;
p.funcnum = funcnum;
- if (ioctl(fd, DRM_IOCTL_IRQ_BUSID, &p)) return -errno;
+ if (ioctl(fd, DRM_IOCTL_IRQ_BUSID, &p))
+ return -errno;
return p.irq;
}
drmHashEntry *entry = drmGetEntry(fd);
void *value;
- if (drmHashLookup(entry->tagTable, context, &value)) return NULL;
+ if (drmHashLookup(entry->tagTable, context, &value))
+ return NULL;
return value;
}
map.ctx_id = ctx_id;
map.handle = (void *)handle;
- if (ioctl(fd, DRM_IOCTL_SET_SAREA_CTX, &map)) return -errno;
+ if (ioctl(fd, DRM_IOCTL_SET_SAREA_CTX, &map))
+ return -errno;
return 0;
}
map.ctx_id = ctx_id;
- if (ioctl(fd, DRM_IOCTL_GET_SAREA_CTX, &map)) return -errno;
- if (handle) *handle = (drm_handle_t)map.handle;
+ if (ioctl(fd, DRM_IOCTL_GET_SAREA_CTX, &map))
+ return -errno;
+ if (handle)
+ *handle = (drm_handle_t)map.handle;
return 0;
}
drm_map_t map;
map.offset = idx;
- if (ioctl(fd, DRM_IOCTL_GET_MAP, &map)) return -errno;
+ if (ioctl(fd, DRM_IOCTL_GET_MAP, &map))
+ return -errno;
*offset = map.offset;
*size = map.size;
*type = map.type;
drm_client_t client;
client.idx = idx;
- if (ioctl(fd, DRM_IOCTL_GET_CLIENT, &client)) return -errno;
+ if (ioctl(fd, DRM_IOCTL_GET_CLIENT, &client))
+ return -errno;
*auth = client.auth;
*pid = client.pid;
*uid = client.uid;
drm_stats_t s;
int i;
- if (ioctl(fd, DRM_IOCTL_GET_STATS, &s)) return -errno;
+ if (ioctl(fd, DRM_IOCTL_GET_STATS, &s))
+ return -errno;
stats->count = 0;
memset(stats, 0, sizeof(*stats));
int drmFenceBuffers(int fd, unsigned flags, drmFence *fence)
{
drm_fence_arg_t arg;
-
+
memset(&arg, 0, sizeof(arg));
arg.flags = flags;
arg.op = drm_fence_buffers;
int drmFenceDestroy(int fd, const drmFence *fence)
{
drm_fence_arg_t arg;
-
+
memset(&arg, 0, sizeof(arg));
arg.handle = fence->handle;
arg.op = drm_fence_destroy;
int drmFenceReference(int fd, unsigned handle, drmFence *fence)
{
drm_fence_arg_t arg;
-
+
memset(&arg, 0, sizeof(arg));
arg.handle = handle;
arg.op = drm_fence_reference;
int drmFenceUnreference(int fd, const drmFence *fence)
{
drm_fence_arg_t arg;
-
+
memset(&arg, 0, sizeof(arg));
arg.handle = fence->handle;
arg.op = drm_fence_unreference;
int drmFenceFlush(int fd, drmFence *fence, unsigned flush_type)
{
drm_fence_arg_t arg;
-
+
memset(&arg, 0, sizeof(arg));
arg.handle = fence->handle;
arg.type = flush_type;
int drmFenceUpdate(int fd, drmFence *fence)
{
- drm_fence_arg_t arg;
-
+ drm_fence_arg_t arg;
+
memset(&arg, 0, sizeof(arg));
arg.handle = fence->handle;
arg.op = drm_fence_signaled;
int drmFenceSignaled(int fd, drmFence *fence, unsigned fenceType,
int *signaled)
{
- int
- ret;
-
if ((fence->flags & DRM_FENCE_FLAG_SHAREABLE) ||
((fenceType & fence->signaled) != fenceType)) {
-
- ret = drmFenceFlush(fd, fence, fenceType);
+ int ret = drmFenceFlush(fd, fence, fenceType);
if (ret)
return ret;
}
}
}
-int drmBOResetList(drmBOList *list) {
-
+int drmBOResetList(drmBOList *list)
+{
drmMMListHead *l;
int ret;
return ret;
l = list->list.next;
- while(l != &list->list) {
+ while (l != &list->list) {
DRMLISTDEL(l);
DRMLISTADD(l, &list->free);
list->numOnList--;
return NULL;
}
list->numCurrent++;
- } else {
+ }
+ else {
DRMLISTDEL(l);
node = DRMLISTENTRY(drmBONode, l, head);
}
drmBONode *node;
drmMMListHead *l = (drmMMListHead *) iterator;
node = DRMLISTENTRY(drmBONode, l, head);
-
return node->buf;
}
return drmAdjustListNodes(list);
}
-static void drmBOCopyReply(const drm_bo_arg_reply_t *rep,
- drmBO *buf)
+static void drmBOCopyReply(const drm_bo_arg_reply_t *rep, drmBO *buf)
{
buf->handle = rep->handle;
buf->flags = rep->flags;
buf->replyFlags = rep->rep_flags;
buf->pageAlignment = rep->page_alignment;
}
-
-
int drmBOCreate(int fd, unsigned long start, unsigned long size,
unsigned pageAlignment, void *user_buffer, drm_bo_type_t type,
int drmBOReference(int fd, unsigned handle, drmBO *buf)
{
-
drm_bo_arg_t arg;
drm_bo_arg_request_t *req = &arg.d.req;
drm_bo_arg_reply_t *rep = &arg.d.rep;
drm_bo_arg_t arg;
drm_bo_arg_request_t *req = &arg.d.req;
drm_bo_arg_reply_t *rep = &arg.d.rep;
-
if (buf->mapVirtual && (buf->type != drm_bo_type_fake)) {
(void) munmap(buf->mapVirtual, buf->start + buf->size);
int drmBOMap(int fd, drmBO *buf, unsigned mapFlags, unsigned mapHint,
void **address)
{
-
drm_bo_arg_t arg;
drm_bo_arg_request_t *req = &arg.d.req;
drm_bo_arg_reply_t *rep = &arg.d.rep;
drm_bo_arg_request_t *req = &arg.d.req;
drm_bo_arg_reply_t *rep = &arg.d.rep;
-
memset(&arg, 0, sizeof(arg));
req->handle = buf->handle;
req->op = drm_bo_unmap;
do{
ret = ioctl(fd, DRM_IOCTL_BUFOBJ, &arg);
} while (ret && errno == EAGAIN);
-
+
if (ret)
return -errno;
if (!arg.handled)
req->op = drm_bo_fence;
ret = ioctl(fd, DRM_IOCTL_BUFOBJ, &arg);
-
+
if (ret)
return -errno;
if (!arg.handled)
req->op = drm_bo_info;
ret = ioctl(fd, DRM_IOCTL_BUFOBJ, &arg);
-
+
if (ret)
return -errno;
if (!arg.handled)
!(buf->replyFlags & DRM_BO_REP_BUSY)) {
*busy = 0;
return 0;
- } else {
+ }
+ else {
int ret = drmBOInfo(fd, buf);
if (ret)
return ret;
*newItem = 1;
cur->arg0 = flags;
cur->arg1 = mask;
- } else {
+ }
+ else {
unsigned memMask = (cur->arg1 | mask) & DRM_BO_MASK_MEM;
unsigned memFlags = cur->arg0 & flags & memMask;
int drmBOValidateList(int fd, drmBOList *list)
{
-
- drmBONode *node;
- drmMMListHead *l;
- drm_bo_arg_t *arg, *first;
- drm_bo_arg_request_t *req;
- drm_bo_arg_reply_t *rep;
- drm_u64_t *prevNext = NULL;
- drmBO *buf;
- int ret;
-
- first = NULL;
-
- for (l = list->list.next; l != &list->list; l = l->next) {
- node = DRMLISTENTRY(drmBONode, l, head);
-
- arg = &node->bo_arg;
- req = &arg->d.req;
-
- if (!first)
- first = arg;
-
- if (prevNext)
- *prevNext = (unsigned long) arg;
-
- memset(arg, 0, sizeof(*arg));
- prevNext = &arg->next;
- req->handle = node->buf->handle;
- req->op = drm_bo_validate;
- req->mask = node->arg0;
- req->hint = 0;
- req->arg_handle = node->arg1;
- }
-
- if (!first)
- return 0;
+ drmBONode *node;
+ drmMMListHead *l;
+ drm_bo_arg_t *arg, *first;
+ drm_bo_arg_request_t *req;
+ drm_bo_arg_reply_t *rep;
+ drm_u64_t *prevNext = NULL;
+ drmBO *buf;
+ int ret;
- do{
- ret = ioctl(fd, DRM_IOCTL_BUFOBJ, first);
- } while (ret && errno == EAGAIN);
+ first = NULL;
+ for (l = list->list.next; l != &list->list; l = l->next) {
+ node = DRMLISTENTRY(drmBONode, l, head);
+
+ arg = &node->bo_arg;
+ req = &arg->d.req;
- if (ret)
- return -errno;
+ if (!first)
+ first = arg;
+
+ if (prevNext)
+ *prevNext = (unsigned long) arg;
+
+ memset(arg, 0, sizeof(*arg));
+ prevNext = &arg->next;
+ req->handle = node->buf->handle;
+ req->op = drm_bo_validate;
+ req->mask = node->arg0;
+ req->hint = 0;
+ req->arg_handle = node->arg1;
+ }
- for (l = list->list.next; l != &list->list; l = l->next) {
- node = DRMLISTENTRY(drmBONode, l, head);
- arg = &node->bo_arg;
- rep = &arg->d.rep;
-
- if (!arg->handled) {
- drmMsg("Unhandled request\n");
- return -EFAULT;
- }
- if (rep->ret)
- return rep->ret;
-
- buf = node->buf;
- drmBOCopyReply(rep, buf);
- }
-
- return 0;
+ if (!first)
+ return 0;
+
+ do {
+ ret = ioctl(fd, DRM_IOCTL_BUFOBJ, first);
+ } while (ret && errno == EAGAIN);
+
+ if (ret)
+ return -errno;
+
+ for (l = list->list.next; l != &list->list; l = l->next) {
+ node = DRMLISTENTRY(drmBONode, l, head);
+ arg = &node->bo_arg;
+ rep = &arg->d.rep;
+
+ if (!arg->handled) {
+ drmMsg("Unhandled request\n");
+ return -EFAULT;
+ }
+ if (rep->ret)
+ return rep->ret;
+
+ buf = node->buf;
+ drmBOCopyReply(rep, buf);
+ }
+
+ return 0;
}
int drmBOFenceList(int fd, drmBOList *list, unsigned fenceHandle)
{
-
- drmBONode *node;
- drmMMListHead *l;
- drm_bo_arg_t *arg, *first;
- drm_bo_arg_request_t *req;
- drm_bo_arg_reply_t *rep;
- drm_u64_t *prevNext = NULL;
- drmBO *buf;
- unsigned fence_flags;
- int ret;
-
- first = NULL;
-
- for (l = list->list.next; l != &list->list; l = l->next) {
- node = DRMLISTENTRY(drmBONode, l, head);
-
- arg = &node->bo_arg;
- req = &arg->d.req;
-
- if (!first)
- first = arg;
-
- if (prevNext)
- *prevNext = (unsigned long) arg;
-
- memset(arg, 0, sizeof(*arg));
- prevNext = &arg->next;
- req->handle = node->buf->handle;
- req->op = drm_bo_fence;
- req->mask = node->arg0;
- req->arg_handle = fenceHandle;
- }
-
- if (!first)
- return 0;
+ drmBONode *node;
+ drmMMListHead *l;
+ drm_bo_arg_t *arg, *first;
+ drm_bo_arg_request_t *req;
+ drm_bo_arg_reply_t *rep;
+ drm_u64_t *prevNext = NULL;
+ drmBO *buf;
+ unsigned fence_flags;
+ int ret;
+
+ first = NULL;
- ret = ioctl(fd, DRM_IOCTL_BUFOBJ, first);
+ for (l = list->list.next; l != &list->list; l = l->next) {
+ node = DRMLISTENTRY(drmBONode, l, head);
+
+ arg = &node->bo_arg;
+ req = &arg->d.req;
- if (ret)
- return -errno;
+ if (!first)
+ first = arg;
+
+ if (prevNext)
+ *prevNext = (unsigned long) arg;
+
+ memset(arg, 0, sizeof(*arg));
+ prevNext = &arg->next;
+ req->handle = node->buf->handle;
+ req->op = drm_bo_fence;
+ req->mask = node->arg0;
+ req->arg_handle = fenceHandle;
+ }
- for (l = list->list.next; l != &list->list; l = l->next) {
- node = DRMLISTENTRY(drmBONode, l, head);
+ if (!first)
+ return 0;
- arg = &node->bo_arg;
- rep = &arg->d.rep;
-
- if (!arg->handled)
- return -EFAULT;
- if (rep->ret)
- return rep->ret;
- drmBOCopyReply(rep, node->buf);
- }
+ ret = ioctl(fd, DRM_IOCTL_BUFOBJ, first);
- return 0;
+ if (ret)
+ return -errno;
+
+ for (l = list->list.next; l != &list->list; l = l->next) {
+ node = DRMLISTENTRY(drmBONode, l, head);
+ arg = &node->bo_arg;
+ rep = &arg->d.rep;
+ if (!arg->handled)
+ return -EFAULT;
+ if (rep->ret)
+ return rep->ret;
+ drmBOCopyReply(rep, node->buf);
+ }
+
+ return 0;
}
int drmMMInit(int fd, unsigned long pOffset, unsigned long pSize,
unsigned memType)
{
drm_mm_init_arg_t arg;
-
+
memset(&arg, 0, sizeof(arg));
arg.req.op = mm_init;
arg.req.p_offset = pOffset;
if (ioctl(fd, DRM_IOCTL_MM_INIT, &arg))
return -errno;
-
return 0;
}
{
drm_mm_init_arg_t arg;
-
memset(&arg, 0, sizeof(arg));
arg.req.op = mm_takedown;
arg.req.mem_type = memType;
if (ioctl(fd, DRM_IOCTL_MM_INIT, &arg))
return -errno;
-
return 0;
}
do{
ret = ioctl(fd, DRM_IOCTL_MM_INIT, &arg);
} while (ret && errno == EAGAIN);
-
return -errno;
}
do{
ret = ioctl(fd, DRM_IOCTL_MM_INIT, &arg);
} while (ret && errno == EAGAIN);
-
return -errno;
}
#define DRM_MAX_FDS 16
static struct {
- char *BusID;
- int fd;
- int refcount;
+ char *BusID;
+ int fd;
+ int refcount;
} connection[DRM_MAX_FDS];
static int nr_fds = 0;
const char *BusID,
int *newlyopened)
{
- int i;
- int fd;
+ int i;
+ int fd;
- for (i = 0; i < nr_fds; i++)
- if (strcmp(BusID, connection[i].BusID) == 0) {
- connection[i].refcount++;
- *newlyopened = 0;
- return connection[i].fd;
- }
-
- fd = drmOpen(unused, BusID);
- if (fd <= 0 || nr_fds == DRM_MAX_FDS)
- return fd;
+ for (i = 0; i < nr_fds; i++)
+ if (strcmp(BusID, connection[i].BusID) == 0) {
+ connection[i].refcount++;
+ *newlyopened = 0;
+ return connection[i].fd;
+ }
+
+ fd = drmOpen(unused, BusID);
+ if (fd <= 0 || nr_fds == DRM_MAX_FDS)
+ return fd;
- connection[nr_fds].BusID = strdup(BusID);
- connection[nr_fds].fd = fd;
- connection[nr_fds].refcount = 1;
- *newlyopened = 1;
+ connection[nr_fds].BusID = strdup(BusID);
+ connection[nr_fds].fd = fd;
+ connection[nr_fds].refcount = 1;
+ *newlyopened = 1;
- if (0)
- fprintf(stderr, "saved connection %d for %s %d\n",
- nr_fds, connection[nr_fds].BusID,
- strcmp(BusID, connection[nr_fds].BusID));
+ if (0)
+ fprintf(stderr, "saved connection %d for %s %d\n",
+ nr_fds, connection[nr_fds].BusID,
+ strcmp(BusID, connection[nr_fds].BusID));
- nr_fds++;
+ nr_fds++;
- return fd;
+ return fd;
}
void drmCloseOnce(int fd)
{
- int i;
+ int i;
- for (i = 0; i < nr_fds; i++) {
- if (fd == connection[i].fd) {
- if (--connection[i].refcount == 0) {
- drmClose(connection[i].fd);
- free(connection[i].BusID);
+ for (i = 0; i < nr_fds; i++) {
+ if (fd == connection[i].fd) {
+ if (--connection[i].refcount == 0) {
+ drmClose(connection[i].fd);
+ free(connection[i].BusID);
- if (i < --nr_fds)
- connection[i] = connection[nr_fds];
+ if (i < --nr_fds)
+ connection[i] = connection[nr_fds];
- return;
- }
- }
- }
+ return;
+ }
+ }
+ }
}