Skip to content

Commit 5428da4

Browse files
committed
drm/asahi: file: adapt to new DRM file/ioctl rust abstractions
Signed-off-by: Janne Grunau <j@jannau.net>
1 parent e876ce0 commit 5428da4

1 file changed

Lines changed: 28 additions & 15 deletions

File tree

drivers/gpu/drm/asahi/file.rs

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use kernel::drm::gem::BaseObject;
2020
use kernel::error::code::*;
2121
use kernel::prelude::*;
2222
use kernel::sync::{Arc, Mutex};
23+
use kernel::types::ForeignOwnable;
2324
use kernel::uaccess::{UserPtr, UserSlice};
2425
use kernel::{dma_fence, drm, uapi, xarray};
2526

@@ -183,13 +184,16 @@ const VM_USER_RANGE: Range<u64> = mmu::IOVA_USER_USABLE_RANGE;
183184
const VM_KERNEL_MIN_SIZE: u64 = 0x20000000;
184185

185186
impl drm::file::DriverFile for File {
186-
type Driver = driver::AsahiDriver;
187+
kernel::define_driver_file_types!(driver::AsahiDriver);
187188

188189
/// Create a new `File` instance for a fresh client.
189-
fn open(device: &AsahiDevice) -> Result<Pin<KBox<Self>>> {
190+
fn open(
191+
device: &AsahiDevice,
192+
dev_data: <Self as drm::file::DriverFile>::BorrowedData<'_>,
193+
) -> Result<Pin<KBox<Self>>> {
190194
debug::update_debug_flags();
191195

192-
let gpu = &device.data().gpu;
196+
let gpu = &dev_data.gpu;
193197
let id = gpu.ids().file.next();
194198

195199
mod_dev_dbg!(device, "[File {}]: DRM device opened\n", id);
@@ -228,12 +232,13 @@ impl File {
228232
/// IOCTL: get_param: Get a driver parameter value.
229233
pub(crate) fn get_params(
230234
device: &AsahiDevice,
235+
dev_data: <Self as drm::file::DriverFile>::BorrowedData<'_>,
231236
data: &mut uapi::drm_asahi_get_params,
232237
file: &DrmFile,
233238
) -> Result<u32> {
234239
mod_dev_dbg!(device, "[File {}]: IOCTL: get_params\n", file.inner().id);
235240

236-
let gpu = &device.data().gpu;
241+
let gpu = &dev_data.gpu;
237242

238243
if data.extensions != 0 || data.param_group != 0 || data.pad != 0 {
239244
cls_pr_debug!(Errors, "get_params: Invalid arguments\n");
@@ -321,6 +326,7 @@ impl File {
321326
/// IOCTL: vm_create: Create a new `Vm`.
322327
pub(crate) fn vm_create(
323328
device: &AsahiDevice,
329+
dev_data: <Self as drm::file::DriverFile>::BorrowedData<'_>,
324330
data: &mut uapi::drm_asahi_vm_create,
325331
file: &DrmFile,
326332
) -> Result<u32> {
@@ -349,7 +355,7 @@ impl File {
349355
let kernel_gpu_range = kernel_range.start..(kernel_range.start + kernel_half_size);
350356
let kernel_gpufw_range = kernel_gpu_range.end..kernel_range.end;
351357

352-
let gpu = &device.data().gpu;
358+
let gpu = &dev_data.gpu;
353359
let file_id = file.inner().id;
354360
let vm = gpu.new_vm(kernel_range.clone())?;
355361

@@ -423,6 +429,7 @@ impl File {
423429
/// IOCTL: vm_destroy: Destroy a `Vm`.
424430
pub(crate) fn vm_destroy(
425431
_device: &AsahiDevice,
432+
_dev_data: <Self as drm::file::DriverFile>::BorrowedData<'_>,
426433
data: &mut uapi::drm_asahi_vm_destroy,
427434
file: &DrmFile,
428435
) -> Result<u32> {
@@ -441,6 +448,7 @@ impl File {
441448
/// IOCTL: gem_create: Create a new GEM object.
442449
pub(crate) fn gem_create(
443450
device: &AsahiDevice,
451+
_dev_data: <Self as drm::file::DriverFile>::BorrowedData<'_>,
444452
data: &mut uapi::drm_asahi_gem_create,
445453
file: &DrmFile,
446454
) -> Result<u32> {
@@ -492,6 +500,7 @@ impl File {
492500
/// IOCTL: gem_mmap_offset: Assign an mmap offset to a GEM object.
493501
pub(crate) fn gem_mmap_offset(
494502
device: &AsahiDevice,
503+
_dev_data: <Self as drm::file::DriverFile>::BorrowedData<'_>,
495504
data: &mut uapi::drm_asahi_gem_mmap_offset,
496505
file: &DrmFile,
497506
) -> Result<u32> {
@@ -515,6 +524,7 @@ impl File {
515524
/// IOCTL: gem_bind: Map or unmap a GEM object into a Vm.
516525
pub(crate) fn gem_bind(
517526
device: &AsahiDevice,
527+
_dev_data: <Self as drm::file::DriverFile>::BorrowedData<'_>,
518528
data: &mut uapi::drm_asahi_gem_bind,
519529
file: &DrmFile,
520530
) -> Result<u32> {
@@ -760,6 +770,7 @@ impl File {
760770
/// IOCTL: gem_bind_object: Map or unmap a GEM object as a special object.
761771
pub(crate) fn gem_bind_object(
762772
device: &AsahiDevice,
773+
dev_data: <Self as drm::file::DriverFile>::BorrowedData<'_>,
763774
data: &mut uapi::drm_asahi_gem_bind_object,
764775
file: &DrmFile,
765776
) -> Result<u32> {
@@ -793,10 +804,10 @@ impl File {
793804

794805
match data.op {
795806
uapi::drm_asahi_bind_object_op_ASAHI_BIND_OBJECT_OP_BIND => {
796-
Self::do_gem_bind_object(device, data, file)
807+
Self::do_gem_bind_object(device, dev_data, data, file)
797808
}
798809
uapi::drm_asahi_bind_object_op_ASAHI_BIND_OBJECT_OP_UNBIND => {
799-
Self::do_gem_unbind_object(device, data, file)
810+
Self::do_gem_unbind_object(device, dev_data, data, file)
800811
}
801812
_ => {
802813
cls_pr_debug!(Errors, "gem_bind_object: Invalid op {}\n", data.op);
@@ -806,7 +817,8 @@ impl File {
806817
}
807818

808819
pub(crate) fn do_gem_bind_object(
809-
device: &AsahiDevice,
820+
_device: &AsahiDevice,
821+
dev_data: <Self as drm::file::DriverFile>::BorrowedData<'_>,
810822
data: &mut uapi::drm_asahi_gem_bind_object,
811823
file: &DrmFile,
812824
) -> Result<u32> {
@@ -834,10 +846,7 @@ impl File {
834846
let bo = gem::lookup_handle(file, data.handle)?;
835847

836848
let mapping = Arc::new(
837-
device
838-
.data()
839-
.gpu
840-
.map_timestamp_buffer(bo, offset..end_offset)?,
849+
dev_data.gpu.map_timestamp_buffer(bo, offset..end_offset)?,
841850
GFP_KERNEL,
842851
)?;
843852
let obj = KBox::new(Object::TimestampBuffer(mapping), GFP_KERNEL)?;
@@ -849,6 +858,7 @@ impl File {
849858

850859
pub(crate) fn do_gem_unbind_object(
851860
_device: &AsahiDevice,
861+
_dev_data: <Self as drm::file::DriverFile>::BorrowedData<'_>,
852862
data: &mut uapi::drm_asahi_gem_bind_object,
853863
file: &DrmFile,
854864
) -> Result<u32> {
@@ -895,6 +905,7 @@ impl File {
895905
/// IOCTL: queue_create: Create a new command submission queue of a given type.
896906
pub(crate) fn queue_create(
897907
device: &AsahiDevice,
908+
dev_data: <Self as drm::file::DriverFile>::BorrowedData<'_>,
898909
data: &mut uapi::drm_asahi_queue_create,
899910
file: &DrmFile,
900911
) -> Result<u32> {
@@ -937,8 +948,7 @@ impl File {
937948
core::mem::drop(file_vm);
938949

939950
let queue =
940-
device
941-
.data()
951+
dev_data
942952
.gpu
943953
.new_queue(vm, ualloc, ualloc_priv, data.priority, data.queue_caps)?;
944954

@@ -951,6 +961,7 @@ impl File {
951961
/// IOCTL: queue_destroy: Destroy a command submission queue.
952962
pub(crate) fn queue_destroy(
953963
_device: &AsahiDevice,
964+
_dev_data: <Self as drm::file::DriverFile>::BorrowedData<'_>,
954965
data: &mut uapi::drm_asahi_queue_destroy,
955966
file: &DrmFile,
956967
) -> Result<u32> {
@@ -974,6 +985,7 @@ impl File {
974985
/// IOCTL: submit: Submit GPU work to a command submission queue.
975986
pub(crate) fn submit(
976987
device: &AsahiDevice,
988+
dev_data: <Self as drm::file::DriverFile>::BorrowedData<'_>,
977989
data: &mut uapi::drm_asahi_submit,
978990
file: &DrmFile,
979991
) -> Result<u32> {
@@ -998,7 +1010,7 @@ impl File {
9981010
return Err(EINVAL);
9991011
}
10001012

1001-
let gpu = &device.data().gpu;
1013+
let gpu = &dev_data.gpu;
10021014
gpu.update_globals();
10031015

10041016
// Upgrade to Arc<T> to drop the XArray lock early
@@ -1103,6 +1115,7 @@ impl File {
11031115
/// IOCTL: get_time: Get the current GPU timer value.
11041116
pub(crate) fn get_time(
11051117
_device: &AsahiDevice,
1118+
_dev_data: <Self as drm::file::DriverFile>::BorrowedData<'_>,
11061119
data: &mut uapi::drm_asahi_get_time,
11071120
_file: &DrmFile,
11081121
) -> Result<u32> {

0 commit comments

Comments
 (0)