Skip to content

drm/verisilicon: properly implement vmap #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

Icenowy
Copy link

@Icenowy Icenowy commented Jul 15, 2025

On 6.6 kernel, the address returned by dma_alloc_attrs() is directly from the linear mapping and not mapped with the expected page attribute.

Properly implement a vmap (and corresponding vunmap) to ensure the virtual address set by it is mapped with the expect write-combining page attributes.

===============

This PR fixes fbcon refreshing issue on (at least) Lichee Console 4A.

Summary by Sourcery

Apply proper vmap/vunmap mapping with write-combining attributes for Verisilicon GEM objects to ensure correct kernel mappings and resolve framebuffer refresh issues.

Bug Fixes:

  • Fix fbcon refreshing issue on Lichee Console 4A by ensuring memory is mapped with write-combining attributes

Enhancements:

  • Implement vmap() in vs_gem_prime_vmap with pgprot_writecombine and corresponding vunmap() in vs_gem_prime_vunmap
  • Add a new vaddr field to vs_gem_object to track the virtual mapping
  • Replace legacy direct kernel mapping of dma_alloc_attrs() return values to guarantee correct page attributes

On 6.6 kernel, the address returned by dma_alloc_attrs() is directly
from the linear mapping and not mapped with the expected page attribute.

Properly implement a vmap (and corresponding vunmap) to ensure the
virtual address set by it is mapped with the expect write-combining page
attributes.

Signed-off-by: Icenowy Zheng <[email protected]>
Copy link

sourcery-ai bot commented Jul 15, 2025

Reviewer's Guide

This PR replaces direct linear DMA mappings with explicit vmap/vunmap calls to ensure write-combining page attributes by adding a vaddr field for tracking and updating both prime_vmap and prime_vunmap implementations.

Class diagram for updated vs_gem_object and vmap/vunmap logic

classDiagram
    class vs_gem_object {
        drm_gem_object base
        size_t size
        void *cookie
        void *vaddr
        dma_addr_t dma_addr
        u32 iova
        unsigned long dma_attrs
    }

    class vs_gem_prime_vmap {
        +int vs_gem_prime_vmap(drm_gem_object *obj, iosys_map *map)
    }
    class vs_gem_prime_vunmap {
        +void vs_gem_prime_vunmap(drm_gem_object *obj, iosys_map *map)
    }

    vs_gem_object <.. vs_gem_prime_vmap : uses
    vs_gem_object <.. vs_gem_prime_vunmap : uses
Loading

Flow diagram for vmap/vunmap implementation in vs_gem_prime_vmap/vunmap

flowchart TD
    A[vs_gem_prime_vmap called] --> B{vs_obj->vaddr exists?}
    B -- Yes --> C[Set iosys_map to vs_obj->vaddr]
    B -- No --> D[Calculate nr_pages]
    D --> E[Call vmap with write-combining attributes]
    E --> F{vmap success?}
    F -- Yes --> G[Set vs_obj->vaddr]
    F -- No --> H[Return -ENOMEM]
    G --> C
    C --> I[Return 0]

    subgraph Unmapping
      J[vs_gem_prime_vunmap called] --> K{vs_obj->vaddr exists?}
      K -- No --> L[Return]
      K -- Yes --> M[Call vunmap on vs_obj->vaddr]
      M --> N[Set vs_obj->vaddr to NULL]
    end
Loading

File-Level Changes

Change Details Files
Track and store virtual mapping address
  • Add vaddr field to struct vs_gem_object to hold vmap result
drivers/gpu/drm/verisilicon/vs_gem.h
Implement vmap in prime_vmap
  • Calculate number of pages from object size
  • Call vmap with pgprot_writecombine and store in vaddr
  • Add reuse path for existing vaddr
  • Handle allocation failure and return -ENOMEM
  • Replace conditional cookie-based mapping logic
drivers/gpu/drm/verisilicon/vs_gem.c
Implement vunmap in prime_vunmap
  • Check if vaddr is set before unmapping
  • Call vunmap on vaddr and clear vaddr field
drivers/gpu/drm/verisilicon/vs_gem.c

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Icenowy - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Icenowy
Copy link
Author

Icenowy commented Jul 17, 2025

Superseded by #31 .

@Icenowy Icenowy closed this Jul 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant