Skip to content
Snippets Groups Projects
  1. Aug 02, 2024
    • Lyude Paul's avatar
      WIP: Get vblank support working · d4b8ed04
      Lyude Paul authored
      I've tested vblank events to at least make sure we're firing them off from
      the driver, and am currently in the process of fixing one remaining vblank
      ref leak. It -should- be fixed now, but I have yet to actually run this
      code in my VM and am currently pushing this so there's something to look at
      for my team status report :).
      
      Things to split out of this commit:
      * Random misc. cleanups
      * One safety addition to the C side of DRM (specifically, if one CRTC
        supports vblanks it does not make sense for others to not have things
        like enable_vblank/disable_vblank not implemented - so check for that)
      * More hrtimer WIP
      * Some additions to Ktime
      d4b8ed04
    • Lyude Paul's avatar
      rust: sync: Add Lock::from_raw() for ZST data types · cd1dc98c
      Lyude Paul authored
      
      A few of the APIs I've been writing bindings for (KMS in particular) rely
      on the user manually acquiring specific locks before calling certain
      functions. At the moment though, the only way of acquiring these locks in
      bindings is to simply call the C locking functions directly - since said
      locks are not acquired on the rust side of things.
      
      However - if we add `#[repr(C)]` to `Lock<T, B>`, then given `T` is a ZST -
      `Lock<T, B>` becomes equivalent in data layout to its inner `B::State`
      type. Since locks in C don't have data explicitly associated with them
      anyway, we can take advantage of this to add a `Lock::from_raw()` function
      that can translate a raw pointer to `B::State` into its proper `Lock<T, B>`
      equivalent. This lets us simply acquire a reference to the lock in question
      and work with it like it was initialized on the rust side of things,
      allowing us to use less unsafe code to implement bindings with lock
      requirements.
      
      Signed-off-by: Lyude Paul's avatarLyude Paul <lyude@redhat.com>
      cd1dc98c
    • Lyude Paul's avatar
      rust: sync: Add SpinLockIrq · 4b8b0ef9
      Lyude Paul authored
      
      A variant of SpinLock that is expected to be used in noirq contexts, and
      thus requires that the user provide an kernel::irq::IrqDisabled to prove
      they are in such a context upon lock acquisition. This is the rust
      equivalent of spin_lock_irqsave()/spin_lock_irqrestore().
      
      Signed-off-by: Lyude Paul's avatarLyude Paul <lyude@redhat.com>
      
      ---
      
      V2:
      * s/IrqSpinLock/SpinLockIrq/
      * Implement `lock::Backend` now that we have `Context`
      * Add missing periods
      * Make sure rustdoc examples compile correctly
      * Add documentation suggestions
      4b8b0ef9
    • Lyude Paul's avatar
      rust: sync: Introduce lock::Backend::Context · 7e2852b0
      Lyude Paul authored
      
      Now that we've introduced an `IrqDisabled` token for marking contexts in
      which IRQs are disabled, we need a way to be able to pass it to locks that
      require that IRQs are disabled. In order to continue using the
      `lock::Backend` type instead of inventing our own thing, we accomplish this
      by adding the associated Context type, along with a `lock_with()` function
      that can accept a Context when acquiring a lock. To allow current users of
      context-less locks to keep using the normal `lock()` method, we take an
      example from Wedson Almeida Filho's work and add a `where T<'a>: Default`
      bound to `lock()` so that it can only be called on lock types where the
      context is simply a placeholder value, then re-implement it through the new
      `lock_with()` function.
      
      Signed-off-by: Lyude Paul's avatarLyude Paul <lyude@redhat.com>
      
      ---
      
      V3:
      * Use explicit lifetimes in lock_with() to ensure self and _context have
        the same lifetime (Benno)
      * Use () for locks that don't need a Context instead of PhantomData (Benno)
      7e2852b0
    • Lyude Paul's avatar
      rust: Introduce irq module · 283b7568
      Lyude Paul authored
      
      This introduces a module for dealing with interrupt-disabled contexts,
      including the ability to enable and disable interrupts
      (with_irqs_disabled()) - along with the ability to annotate functions as
      expecting that IRQs are already disabled on the local CPU.
      
      Signed-off-by: Lyude Paul's avatarLyude Paul <lyude@redhat.com>
      
      ---
      
      V2:
      * Actually make it so that we check whether or not we have interrupts
        disabled with debug assertions
      * Fix issues in the documentation (added suggestions, missing periods, made
        sure that all rustdoc examples compile properly)
      * Pass IrqDisabled by value, not reference
      * Ensure that IrqDisabled is !Send and !Sync using
        PhantomData<(&'a (), *mut ())>
      * Add all of the suggested derives from Benno Lossin
      
      V3:
      * Use `impl` for FnOnce bounds in with_irqs_disabled()
      * Use higher-ranked trait bounds for the lifetime of with_irqs_disabled()
      * Wording changes in the documentation for the module itself
      283b7568
  2. Jul 31, 2024
  3. Jul 22, 2024
  4. Jul 16, 2024
  5. Jul 14, 2024
  6. Jul 03, 2024
  7. Jul 02, 2024
    • Lyude Paul's avatar
      drm/panic: Fix uninitialized spinlock acquisition with CONFIG_DRM_PANIC=n · 0e8d8c38
      Lyude Paul authored
      
      It turns out that if you happen to have a kernel config where
      CONFIG_DRM_PANIC is disabled and spinlock debugging is enabled, along with
      KMS being enabled - we'll end up trying to acquire an uninitialized
      spin_lock with drm_panic_lock() when we try to do a commit:
      
        rvkms rvkms.0: [drm:drm_atomic_commit] committing 0000000068d2ade1
        INFO: trying to register non-static key.
        The code is fine but needs lockdep annotation, or maybe
        you didn't initialize this object before use?
        turning off the locking correctness validator.
        CPU: 4 PID: 1347 Comm: modprobe Not tainted 6.10.0-rc1Lyude-Test+ #272
        Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS edk2-20240524-3.fc40 05/24/2024
        Call Trace:
         <TASK>
         dump_stack_lvl+0x77/0xa0
         assign_lock_key+0x114/0x120
         register_lock_class+0xa8/0x2c0
         __lock_acquire+0x7d/0x2bd0
         ? __vmap_pages_range_noflush+0x3a8/0x550
         ? drm_atomic_helper_swap_state+0x2ad/0x3a0
         lock_acquire+0xec/0x290
         ? drm_atomic_helper_swap_state+0x2ad/0x3a0
         ? lock_release+0xee/0x310
         _raw_spin_lock_irqsave+0x4e/0x70
         ? drm_atomic_helper_swap_state+0x2ad/0x3a0
         drm_atomic_helper_swap_state+0x2ad/0x3a0
         drm_atomic_helper_commit+0xb1/0x270
         drm_atomic_commit+0xaf/0xe0
         ? __pfx___drm_printfn_info+0x10/0x10
         drm_client_modeset_commit_atomic+0x1a1/0x250
         drm_client_modeset_commit_locked+0x4b/0x180
         drm_client_modeset_commit+0x27/0x50
         __drm_fb_helper_restore_fbdev_mode_unlocked+0x76/0x90
         drm_fb_helper_set_par+0x38/0x40
         fbcon_init+0x3c4/0x690
         visual_init+0xc0/0x120
         do_bind_con_driver+0x409/0x4c0
         do_take_over_console+0x233/0x280
         do_fb_registered+0x11f/0x210
         fbcon_fb_registered+0x2c/0x60
         register_framebuffer+0x248/0x2a0
         __drm_fb_helper_initial_config_and_unlock+0x58a/0x720
         drm_fbdev_generic_client_hotplug+0x6e/0xb0
         drm_client_register+0x76/0xc0
         _RNvXs_CsHeezP08sTT_5rvkmsNtB4_5RvkmsNtNtCs1cdwasc6FUb_6kernel8platform6Driver5probe+0xed2/0x1060 [rvkms]
         ? _RNvMs_NtCs1cdwasc6FUb_6kernel8platformINtB4_7AdapterNtCsHeezP08sTT_5rvkms5RvkmsE14probe_callbackBQ_+0x2b/0x70 [rvkms]
         ? acpi_dev_pm_attach+0x25/0x110
         ? platform_probe+0x6a/0xa0
         ? really_probe+0x10b/0x400
         ? __driver_probe_device+0x7c/0x140
         ? driver_probe_device+0x22/0x1b0
         ? __device_attach_driver+0x13a/0x1c0
         ? __pfx___device_attach_driver+0x10/0x10
         ? bus_for_each_drv+0x114/0x170
         ? __device_attach+0xd6/0x1b0
         ? bus_probe_device+0x9e/0x120
         ? device_add+0x288/0x4b0
         ? platform_device_add+0x75/0x230
         ? platform_device_register_full+0x141/0x180
         ? rust_helper_platform_device_register_simple+0x85/0xb0
         ? _RNvMs2_NtCs1cdwasc6FUb_6kernel8platformNtB5_6Device13create_simple+0x1d/0x60
         ? _RNvXs0_CsHeezP08sTT_5rvkmsNtB5_5RvkmsNtCs1cdwasc6FUb_6kernel6Module4init+0x11e/0x160 [rvkms]
         ? 0xffffffffc083f000
         ? init_module+0x20/0x1000 [rvkms]
         ? kernfs_xattr_get+0x3e/0x80
         ? do_one_initcall+0x148/0x3f0
         ? __lock_acquire+0x5ef/0x2bd0
         ? __lock_acquire+0x5ef/0x2bd0
         ? __lock_acquire+0x5ef/0x2bd0
         ? put_cpu_partial+0x51/0x1d0
         ? lock_acquire+0xec/0x290
         ? put_cpu_partial+0x51/0x1d0
         ? lock_release+0xee/0x310
         ? put_cpu_partial+0x51/0x1d0
         ? fs_reclaim_acquire+0x69/0xf0
         ? lock_acquire+0xec/0x290
         ? fs_reclaim_acquire+0x69/0xf0
         ? kfree+0x22f/0x340
         ? lock_release+0xee/0x310
         ? kmalloc_trace_noprof+0x48/0x340
         ? do_init_module+0x22/0x240
         ? kmalloc_trace_noprof+0x155/0x340
         ? do_init_module+0x60/0x240
         ? __se_sys_finit_module+0x2e0/0x3f0
         ? do_syscall_64+0xa4/0x180
         ? syscall_exit_to_user_mode+0x108/0x140
         ? do_syscall_64+0xb0/0x180
         ? vma_end_read+0xd0/0xe0
         ? do_user_addr_fault+0x309/0x640
         ? clear_bhb_loop+0x45/0xa0
         ? clear_bhb_loop+0x45/0xa0
         ? clear_bhb_loop+0x45/0xa0
         ? entry_SYSCALL_64_after_hwframe+0x76/0x7e
         </TASK>
      
      Fix this by stubbing these macros out when this config option isn't
      enabled, along with fixing the unused variable warning that introduces.
      
      Signed-off-by: Lyude Paul's avatarLyude Paul <lyude@redhat.com>
      0e8d8c38
    • Lyude Paul's avatar
      WIP SPLIT ME: Update our CRTC bindings for DRM's true drm_crtc_state data model · 73dbe7e6
      Lyude Paul authored
      Sima pointed out that drm_crtc_state violates some of the guarantees that
      other atomic states have, in that the structure can be mutated even after
      being swapped in. As a result, we need to update our bindings to not assume
      that this structure follows rust's data aliasing rules like the rest of the
      KMS atomic states.
      73dbe7e6
    • Lyude Paul's avatar
    • Lyude Paul's avatar
      drm: Introduce RVKMS! · 9b11cf71
      Lyude Paul authored
      
      Now that we've added all of the bits that we need for the KMS API, it's
      time to Bring The Beef and introduce RVKMS!
      
      TODO: write something more here I guess?
      
      Signed-off-by: Lyude Paul's avatarLyude Paul <lyude@redhat.com>
      9b11cf71
    • Lyude Paul's avatar
      rust: Add device::Device::name() · 25102dc7
      Lyude Paul authored
      
      Just a simple binding for retrieving the name of the device through
      dev_name().
      
      Signed-off-by: Lyude Paul's avatarLyude Paul <lyude@redhat.com>
      25102dc7
    • Lyude Paul's avatar
      WIP: Add simple registration of platform devices · 63078f17
      Lyude Paul authored
      TODO:
      * The idea for this came from Maíra originally, and they should probably be
        the commit author (we'll fix that before final submission because credit
        is important :3, right now it's just a bit easier to rewrite the commit)
      63078f17
    • Lyude Paul's avatar
      rust/drm/kms: Add RawPlaneState::rotation() · c8783cc0
      Lyude Paul authored
      
      A binding for retrieving the current rotation of a DRM plane state.
      
      Signed-off-by: Lyude Paul's avatarLyude Paul <lyude@redhat.com>
      c8783cc0
    • Lyude Paul's avatar
      rust/drm/kms: Add simplify_rotation() binding · ee655259
      Lyude Paul authored
      
      Just a binding for drm_simplify_rotation(). We add this in a new module
      blend.rs in order to match the layout of the C side of things.
      
      Signed-off-by: Lyude Paul's avatarLyude Paul <lyude@redhat.com>
      ee655259
    • Lyude Paul's avatar
      rust/drm/kms: Add aliases for ROTATE_* and REFLECT_* · ca3783a9
      Lyude Paul authored
      
      Just add some short-hand aliases to the raw bindings, since that's
      basically all we need. We put this in a new mode.rs module to match the
      layout of the C side of KMS.
      
      Signed-off-by: Lyude Paul's avatarLyude Paul <lyude@redhat.com>
      ca3783a9
    • Lyude Paul's avatar
      rust/drm/kms: Add RawPlaneState::src() and dst() · 655c48b3
      Lyude Paul authored
      
      Bindings for returning the src and dst rectangles for an atomic plane
      state.
      
      Signed-off-by: Lyude Paul's avatarLyude Paul <lyude@redhat.com>
      655c48b3
    • Lyude Paul's avatar
      rust/drm/kms: Add KmsDriver::mode_config_reset() · 5940dc6b
      Lyude Paul authored
      
      This is just a binding around drm_mode_config_reset(), which should be
      called during initialization of a modesetting driver if it doesn't
      read-back hardware state.
      
      Signed-off-by: Lyude Paul's avatarLyude Paul <lyude@redhat.com>
      5940dc6b
    • Lyude Paul's avatar
      WIP: rust/drm/kms: Add ShadowPlaneState<T> · d5b7d4fb
      Lyude Paul authored
      
      Since RVKMS uses drm_shadow_plane_state instead of the normal
      drm_plane_state, let's add bindings to allow drivers to use this using the
      PlaneStateHelper trait that we introduced before.
      
      Of course, all of the normal methods available to DRM planes are also
      available on shadow planes through the use of AsRawPlaneState and friends.
      
      Signed-off-by: Lyude Paul's avatarLyude Paul <lyude@redhat.com>
      
      TODO:
      * Make sure that documentation is consistent and finished
      d5b7d4fb
    • Lyude Paul's avatar
      WIP: rust/drm/kms: Add DriverPlane::prepare_fb() and cleanup_fb() · 791203c0
      Lyude Paul authored
      
      Add optional trait methods for DRM's prepare_fb() and cleanup_fb()
      callbacks now that we have proper Framebuffer bindings. As well, introduce
      a new PlaneState mutator: PlaneStateMutator. The purpose of this mutator
      type is for callbacks where we want the implementor to be able to modify
      the atomic plane state, without providing access to the rest of the atomic
      state.
      
      TODO:
      * Write documentation
      
      Signed-off-by: Lyude Paul's avatarLyude Paul <lyude@redhat.com>
      791203c0
    • Lyude Paul's avatar
      rust/drm/kms: Add RawPlane::framebuffer() · 6ecb031f
      Lyude Paul authored
      
      Returns the Framebuffer currently assigned in an atomic plane state.
      
      Signed-off-by: Lyude Paul's avatarLyude Paul <lyude@redhat.com>
      6ecb031f
    • Lyude Paul's avatar
      WIP: rust/drm/kms: Add basic framebuffer bindings · 10cc2476
      Lyude Paul authored
      
      We're about to add some FB related callbacks to planes now, so let's
      introduce our bindings for Framebuffer objects. Just like Connectors, these
      use RcModeObject.
      
      Signed-off-by: Lyude Paul's avatarLyude Paul <lyude@redhat.com>
      10cc2476
    • Lyude Paul's avatar
      WIP: rust/drm/kms: Add DriverPlane::atomic_update() · eb1585a9
      Lyude Paul authored
      A mandatory trait method used for implementing DRM's atomic plane update
      callback. This is currently only mandatory because with our current
      bindings, DRM will crash without this.
      
      TODO: See if we can fix that and make it only mandatory in certain
      situations.
      eb1585a9
    • Lyude Paul's avatar
      WIP: rust/kms/drm: Add RawPlaneState::atomic_helper_check() · d12220fb
      Lyude Paul authored
      
      Add a binding for DRM's plane state atomic check helper.
      
      TODO:
      * Finish up documentation (we need to document parameters too! I think?)
      
      Signed-off-by: Lyude Paul's avatarLyude Paul <lyude@redhat.com>
      d12220fb
    • Lyude Paul's avatar
      rust/drm/kms: Add RawPlaneState::crtc() · 22c1e4e1
      Lyude Paul authored
      
      Add a binding for retrieving an opaque reference to the CRTC currently set
      for an atomic plane state.
      
      Signed-off-by: Lyude Paul's avatarLyude Paul <lyude@redhat.com>
      22c1e4e1
    • Lyude Paul's avatar
      WIP: rust/drm/kms: Add DriverPlane::atomic_check() · 13371e23
      Lyude Paul authored
      
      Optional trait method for implementing a plane's atomic_check().
      
      TODO:
      * Documentation
      * Figure out if we can make this non-mandatory?
      
      Signed-off-by: Lyude Paul's avatarLyude Paul <lyude@redhat.com>
      13371e23
    • Lyude Paul's avatar
      WIP: rust/drm/kms: Introduce DriverCrtc::atomic_check() · 305bec18
      Lyude Paul authored
      
      An optional trait method for implementing a CRTC's atomic state check.
      
      TODO: Write documentation
      
      Signed-off-by: Lyude Paul's avatarLyude Paul <lyude@redhat.com>
      305bec18
Loading