|
|
@ -29,7 +29,7 @@ pub struct EngineInfo {
|
|
|
|
pub capabilities: u64,
|
|
|
|
pub capabilities: u64,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
#[derive(Debug, PartialEq, Eq)]
|
|
|
|
pub struct DrmGemHandle {
|
|
|
|
pub struct DrmGemHandle {
|
|
|
|
pub handle: u32,
|
|
|
|
pub handle: u32,
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -180,7 +180,7 @@ pub fn make_gem(fd: RawFd, size: u64) -> Option<DrmGemHandle> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn close_gem(fd: RawFd, handle: DrmGemHandle) -> Result<(), i32> {
|
|
|
|
pub unsafe fn close_gem_ref(fd: RawFd, handle: &DrmGemHandle) -> Result<(), i32> {
|
|
|
|
unsafe {
|
|
|
|
unsafe {
|
|
|
|
let mut close = native::drm_gem_close {
|
|
|
|
let mut close = native::drm_gem_close {
|
|
|
|
handle: handle.handle,
|
|
|
|
handle: handle.handle,
|
|
|
@ -194,6 +194,12 @@ pub fn close_gem(fd: RawFd, handle: DrmGemHandle) -> Result<(), i32> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn close_gem(fd: RawFd, handle: DrmGemHandle) -> Result<(), i32> {
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
|
|
|
|
close_gem_ref(fd, &handle)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
|
|
pub enum GemIoctlError {
|
|
|
|
pub enum GemIoctlError {
|
|
|
|
InvalidHandle,
|
|
|
|
InvalidHandle,
|
|
|
@ -210,7 +216,8 @@ pub fn gem_has_tiling(fd: RawFd, handle: &DrmGemHandle) -> Result<bool, GemIoctl
|
|
|
|
phys_swizzle_mode: 0,
|
|
|
|
phys_swizzle_mode: 0,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
let res = libc::ioctl(fd, native::DRM_IOCTL_I915_GEM_GET_TILING, &mut tiling);
|
|
|
|
let res = libc::ioctl(fd, native::DRM_IOCTL_I915_GEM_GET_TILING, &mut tiling);
|
|
|
|
match -res {
|
|
|
|
let errno = *libc::__errno_location();
|
|
|
|
|
|
|
|
match errno {
|
|
|
|
0 => Ok(true),
|
|
|
|
0 => Ok(true),
|
|
|
|
libc::ENOENT => Err(GemIoctlError::InvalidHandle),
|
|
|
|
libc::ENOENT => Err(GemIoctlError::InvalidHandle),
|
|
|
|
libc::EPERM => Err(GemIoctlError::PermissionDenied),
|
|
|
|
libc::EPERM => Err(GemIoctlError::PermissionDenied),
|
|
|
@ -226,11 +233,11 @@ pub fn gem_is_valid(fd: RawFd, handle: &DrmGemHandle) -> Result<bool, GemIoctlEr
|
|
|
|
return Ok(true);
|
|
|
|
return Ok(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// For some reason the kernel returns -EPERM instead of -ENOENT when the handle is invalid...
|
|
|
|
if res.is_err() && res.unwrap_err() == GemIoctlError::InvalidHandle {
|
|
|
|
if res.is_err() && res.unwrap_err() == GemIoctlError::PermissionDenied {
|
|
|
|
|
|
|
|
return Ok(false);
|
|
|
|
return Ok(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
println!("Unexpected error: {:?}", res.unwrap_err());
|
|
|
|
return Err(res.unwrap_err());
|
|
|
|
return Err(res.unwrap_err());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|