Currently Tyr is not storing any resources in its drm::Driver RegistrationData.
Move Tyr's device-private resources and gpu information from drm::Driver::Data to drm::Driver::RegistrationData. This allows Tyr to access this data safely within the lifetime of its binding to its parent platform device and while registered with userspace. Signed-off-by: Deborah Brouwer <[email protected]> --- drivers/gpu/drm/tyr/driver.rs | 42 +++++++++++++++++++++--------------------- drivers/gpu/drm/tyr/file.rs | 11 ++++++----- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/drivers/gpu/drm/tyr/driver.rs b/drivers/gpu/drm/tyr/driver.rs index 8348c6cd3929..46ce5c41e310 100644 --- a/drivers/gpu/drm/tyr/driver.rs +++ b/drivers/gpu/drm/tyr/driver.rs @@ -6,6 +6,7 @@ OptionalClk, // }, device::{ + Bound, Core, Device, DeviceContext, // @@ -27,10 +28,7 @@ regulator, regulator::Regulator, sizes::SZ_2M, - sync::{ - aref::ARef, - Mutex, // - }, + sync::Mutex, time, // }; @@ -53,13 +51,17 @@ #[pin_data(PinnedDrop)] pub(crate) struct TyrPlatformDriverData<'bound> { - _device: ARef<TyrDrmDevice>, _reg: drm::Registration<'bound, TyrDrmDriver>, } +/// Data owned by the DRM [`Registration`]. +/// +/// This data can have references tied to the parent platform device binding scope +/// and is accessible only while the DRM device is registered with userspace. #[pin_data] -pub(crate) struct TyrDrmDeviceData { - pub(crate) pdev: ARef<platform::Device>, +pub(crate) struct TyrDrmRegistrationData<'bound> { + /// Parent platform device. + pub(crate) pdev: &'bound platform::Device<Bound>, #[pin] clks: Mutex<Clocks>, @@ -67,9 +69,10 @@ pub(crate) struct TyrDrmDeviceData { #[pin] regulators: Mutex<Regulators>, - /// Some information on the GPU. - /// - /// This is mainly queried by userspace, i.e.: Mesa. + /// GPU MMIO register mapping. + pub(crate) iomem: IoMem<'bound>, + + /// GPU information read from hardware during probe. pub(crate) gpu_info: GpuInfo, } @@ -134,10 +137,10 @@ fn probe<'bound>( // other threads of execution. unsafe { pdev.dma_set_mask_and_coherent(DmaMask::try_new(pa_bits)?)? }; - let platform: ARef<platform::Device> = pdev.into(); + let unreg_dev = drm::UnregisteredDevice::<TyrDrmDriver>::new(pdev, Ok(()))?; - let data = try_pin_init!(TyrDrmDeviceData { - pdev: platform.clone(), + let reg_data = try_pin_init!(TyrDrmRegistrationData { + pdev, clks <- new_mutex!(Clocks { core: core_clk, stacks: stacks_clk, @@ -147,18 +150,15 @@ fn probe<'bound>( _mali: mali_regulator, _sram: sram_regulator, }), + iomem, gpu_info, }); - let tdev = drm::UnregisteredDevice::<TyrDrmDriver>::new(pdev, data)?; // SAFETY: `reg` is stored in `TyrPlatformDriverData` and dropped when the driver is // unbound; it is never forgotten. - let reg = unsafe { drm::Registration::new(pdev.as_ref(), tdev, (), 0)? }; + let reg = unsafe { drm::Registration::new(pdev.as_ref(), unreg_dev, reg_data, 0)? }; - let driver = TyrPlatformDriverData { - _device: reg.device().into(), - _reg: reg, - }; + let driver = TyrPlatformDriverData { _reg: reg }; // We need this to be dev_info!() because dev_dbg!() does not work at // all in Rust for now, and we need to see whether probe succeeded. @@ -184,8 +184,8 @@ fn drop(self: Pin<&mut Self>) {} #[vtable] impl drm::Driver for TyrDrmDriver { - type Data = TyrDrmDeviceData; - type RegistrationData<'a> = (); + type Data = (); + type RegistrationData<'bound> = TyrDrmRegistrationData<'bound>; type File = TyrDrmFileData; type Object = drm::gem::shmem::Object<BoData>; type ParentDevice<Ctx: DeviceContext> = platform::Device<Ctx>; diff --git a/drivers/gpu/drm/tyr/file.rs b/drivers/gpu/drm/tyr/file.rs index b686041d5d6b..9f60a90d4948 100644 --- a/drivers/gpu/drm/tyr/file.rs +++ b/drivers/gpu/drm/tyr/file.rs @@ -12,7 +12,8 @@ use crate::driver::{ TyrDrmDevice, - TyrDrmDriver, // + TyrDrmDriver, + TyrDrmRegistrationData, // }; #[pin_data] @@ -31,15 +32,15 @@ fn open(_dev: &drm::Device<Self::Driver>) -> Result<Pin<KBox<Self>>> { impl TyrDrmFileData { pub(crate) fn dev_query( - ddev: &TyrDrmDevice<Registered>, - _reg_data: &(), + _ddev: &TyrDrmDevice<Registered>, + reg_data: &TyrDrmRegistrationData<'_>, devquery: &mut uapi::drm_panthor_dev_query, _file: &TyrDrmFile, ) -> Result<u32> { if devquery.pointer == 0 { match devquery.type_ { uapi::drm_panthor_dev_query_type_DRM_PANTHOR_DEV_QUERY_GPU_INFO => { - devquery.size = core::mem::size_of_val(&ddev.gpu_info) as u32; + devquery.size = core::mem::size_of_val(®_data.gpu_info) as u32; Ok(0) } _ => Err(EINVAL), @@ -53,7 +54,7 @@ pub(crate) fn dev_query( ) .writer(); - writer.write(&ddev.gpu_info)?; + writer.write(®_data.gpu_info)?; Ok(0) } -- 2.54.0
