Working on fixing the GEM offset code

master
itycodes 1 day ago
parent 9beed69f85
commit 8484870660

@ -58,6 +58,8 @@ impl From<DrmGemTileInfo> for GemTileInfo {
} }
/// An owned GEM handle that will be closed when dropped /// An owned GEM handle that will be closed when dropped
/// Scoped to a file descriptor -
/// this means that it is inherited by `fork` children and can be shared with sendfd
impl GemHandle<'_> { impl GemHandle<'_> {
pub fn new(node: &DrmDeviceNode, size: u64) -> Option<GemHandle> { pub fn new(node: &DrmDeviceNode, size: u64) -> Option<GemHandle> {
uapi::i915::make_gem(node.fd.as_raw_fd(), size).map(|handle| GemHandle { uapi::i915::make_gem(node.fd.as_raw_fd(), size).map(|handle| GemHandle {

@ -284,7 +284,7 @@ pub unsafe fn gem_offset(fd: RawFd, handle: &DrmGemHandle) -> Result<u64, GemIoc
handle: handle.handle, handle: handle.handle,
pad: 0, pad: 0,
offset: 0, offset: 0,
flags: native::I915_MMAP_OFFSET_WB as u64, flags: native::I915_MMAP_OFFSET_GTT as u64,
extensions: 0, extensions: 0,
}; };
let res = libc::ioctl(fd, native::DRM_IOCTL_I915_GEM_MMAP_OFFSET, &mut offset); let res = libc::ioctl(fd, native::DRM_IOCTL_I915_GEM_MMAP_OFFSET, &mut offset);

@ -161,6 +161,21 @@ fn test_i915_uapi_gem_fork_parent() {
} }
} }
#[test]
fn test_i915_uapi_gem_offset() {
let nodes = i915::find_all_nodes();
unsafe {
assert!(nodes.len() > 0);
for node in nodes {
let gem = i915::make_gem(node.fd.as_raw_fd(), 4096).expect("Failed to make gem");
let offset = i915::gem_offset(node.fd.as_raw_fd(), &gem);
println!("gem: {:?}, node: {:?}, offset: {:?}", gem, node, offset);
assert!(offset.unwrap() > 0);
i915::close_gem(node.fd.as_raw_fd(), gem).expect("Failed to close gem");
}
}
}
// TODO: Fix this test // TODO: Fix this test
// Shared mem needs to be used to communicate the gem handle between parent and child // Shared mem needs to be used to communicate the gem handle between parent and child
// Test both a shared fd and separate fd // Test both a shared fd and separate fd

Loading…
Cancel
Save