|
|
|
@ -204,19 +204,10 @@ pub fn close_gem(fd: RawFd, handle: DrmGemHandle) -> Result<(), i32> {
|
|
|
|
|
pub enum GemIoctlError {
|
|
|
|
|
InvalidHandle,
|
|
|
|
|
PermissionDenied,
|
|
|
|
|
UnsupportedOnDevice,
|
|
|
|
|
UnsupportedOnHandle,
|
|
|
|
|
Unknown(i32),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
|
|
|
pub struct DrmGemTileInfo {
|
|
|
|
|
pub tiling_mode: u32,
|
|
|
|
|
pub swizzle_mode: u32,
|
|
|
|
|
pub phys_swizzle_mode: u32,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn gem_get_tiling(fd: RawFd, handle: &DrmGemHandle) -> Result<DrmGemTileInfo, GemIoctlError> {
|
|
|
|
|
pub fn gem_has_tiling(fd: RawFd, handle: &DrmGemHandle) -> Result<bool, GemIoctlError> {
|
|
|
|
|
unsafe {
|
|
|
|
|
let mut tiling = native::drm_i915_gem_get_tiling {
|
|
|
|
|
handle: handle.handle,
|
|
|
|
@ -225,47 +216,12 @@ pub fn gem_get_tiling(fd: RawFd, handle: &DrmGemHandle) -> Result<DrmGemTileInfo
|
|
|
|
|
phys_swizzle_mode: 0,
|
|
|
|
|
};
|
|
|
|
|
let res = libc::ioctl(fd, native::DRM_IOCTL_I915_GEM_GET_TILING, &mut tiling);
|
|
|
|
|
let tile_info = DrmGemTileInfo {
|
|
|
|
|
tiling_mode: tiling.tiling_mode,
|
|
|
|
|
swizzle_mode: tiling.swizzle_mode,
|
|
|
|
|
phys_swizzle_mode: tiling.phys_swizzle_mode,
|
|
|
|
|
};
|
|
|
|
|
let errno = *libc::__errno_location();
|
|
|
|
|
match errno {
|
|
|
|
|
0 => Ok(tile_info),
|
|
|
|
|
libc::ENOENT => Err(GemIoctlError::InvalidHandle),
|
|
|
|
|
libc::EPERM => Err(GemIoctlError::PermissionDenied),
|
|
|
|
|
libc::EOPNOTSUPP => Err(GemIoctlError::UnsupportedOnDevice),
|
|
|
|
|
_ => Err(GemIoctlError::Unknown(res)),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn gem_has_tiling(fd: RawFd, handle: &DrmGemHandle) -> Result<bool, GemIoctlError> {
|
|
|
|
|
let res = gem_get_tiling(fd, handle);
|
|
|
|
|
if res.is_ok() {
|
|
|
|
|
return Ok(true);
|
|
|
|
|
}
|
|
|
|
|
if res.is_err() && res.unwrap_err() == GemIoctlError::UnsupportedOnDevice {
|
|
|
|
|
return Ok(false);
|
|
|
|
|
}
|
|
|
|
|
return Err(res.unwrap_err());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn gem_get_caching(fd: RawFd, handle: &DrmGemHandle) -> Result<u32, GemIoctlError> {
|
|
|
|
|
unsafe {
|
|
|
|
|
let mut caching = native::drm_i915_gem_caching {
|
|
|
|
|
handle: handle.handle,
|
|
|
|
|
caching: 0,
|
|
|
|
|
};
|
|
|
|
|
let res = libc::ioctl(fd, native::DRM_IOCTL_I915_GEM_GET_CACHING, &mut caching);
|
|
|
|
|
let errno = *libc::__errno_location();
|
|
|
|
|
match errno {
|
|
|
|
|
0 => Ok(caching.caching),
|
|
|
|
|
0 => Ok(true),
|
|
|
|
|
libc::ENOENT => Err(GemIoctlError::InvalidHandle),
|
|
|
|
|
libc::EPERM => Err(GemIoctlError::PermissionDenied),
|
|
|
|
|
libc::ENODEV => Err(GemIoctlError::UnsupportedOnDevice),
|
|
|
|
|
libc::EOPNOTSUPP => Err(GemIoctlError::UnsupportedOnHandle),
|
|
|
|
|
libc::EINVAL => Ok(false),
|
|
|
|
|
_ => Err(GemIoctlError::Unknown(res)),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -281,6 +237,7 @@ pub fn gem_is_valid(fd: RawFd, handle: &DrmGemHandle) -> Result<bool, GemIoctlEr
|
|
|
|
|
return Ok(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
println!("Unexpected error: {:?}", res.unwrap_err());
|
|
|
|
|
return Err(res.unwrap_err());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|