lib: devres: Add managed helpers for write-combine setup
Subsystems (6)
Thomas Zimmermann
maintainercover lib: devres: Add managed helpers for write-combine setup
Add devm_arch_phys_wc_add() and devm_arch_io_reserve_memtype_wc() for automatic cleanup of writecombine setup.
Several DRM drivers use the non-managed functions for setting their framebuffer memory to write-combine access. Convert ast, mgag200 and vboxvideo. Remove rsp clean-up code form drivers.
Tested on mgag200 hardware.
Thomas Zimmermann (5):
lib: devres: Add managed arch_phys_wc_add()
lib: devres: Add managed arch_io_reserve_memtype_wc() drm/ast: Use managed interfaces for framebuffer write combining drm/mgag200: Use managed interfaces for framebuffer write combining drm/vboxvideo: Use managed interfaces for framebuffer write combining
drivers/gpu/drm/ast/ast_drv.h | 2 - drivers/gpu/drm/ast/ast_mm.c | 27 ++++----- drivers/gpu/drm/mgag200/mgag200_drv.h | 2 - drivers/gpu/drm/mgag200/mgag200_mm.c | 35 +++--------- drivers/gpu/drm/vboxvideo/vbox_drv.c | 5 +- drivers/gpu/drm/vboxvideo/vbox_drv.h | 1 - drivers/gpu/drm/vboxvideo/vbox_ttm.c | 17 +++--- include/linux/io.h | 5 ++ lib/devres.c | 82 +++++++++++++++++++++++++++ 9 files changed, 113 insertions(+), 63 deletions(-)
--
2.33.0
Thomas Zimmermann
maintainerPATCH 1/5 lib: devres: Add managed arch_phys_wc_add()
Add devm_arch_phys_wc_add() as managed wrapper around arch_phys_wc_add(). Useful for several grahpics drivers that set framebuffer memory to write combining.
--- include/linux/io.h | 2 ++ lib/devres.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+)
include/linux/io.h +2 -0
@@ -132,6 +132,8 @@ static inline int arch_phys_wc_index(int handle)#endif #endif +int devm_arch_phys_wc_add (struct device *dev,unsigned long base,unsigned long size); +enum {/* See memremap() kernel-doc for usage description... */ MEMREMAP_WB =1 <<0 ,
lib/devres.c +36 -0
@@ -528,3 +528,39 @@ void pcim_iounmap_regions(struct pci_dev *pdev, int mask) }EXPORT_SYMBOL (pcim_iounmap_regions);#endif /* CONFIG_PCI */ + +static void devm_arch_phys_ac_add_release (struct device *dev,void *res) +{ +arch_phys_wc_del (*((int *)res)); +} + +/** +* devm_arch_phys_wc_add - Managed arch_phys_wc_add() +* @dev: Managed device +* @base: Memory base address +* @size: Size of memory range +* +* Adds a WC MTRR using arch_phys_wc_add() and sets up a release callback. +* See arch_phys_wc_add() for more information. +*/ +int devm_arch_phys_wc_add (struct device *dev,unsigned long base,unsigned long size) +{ +int *mtrr; +int ret; + + mtrr =devres_alloc (devm_arch_phys_ac_add_release,sizeof (*mtrr),GFP_KERNEL ); +if (!mtrr) +return -ENOMEM ; + + ret =arch_phys_wc_add (base, size); +if (ret <0 ) { +devres_free (mtrr); +return ret; + } + + *mtrr = ret; +devres_add (dev, mtrr); + +return ret; +} +EXPORT_SYMBOL (devm_arch_phys_wc_add);
Signature · 1 line
2.33.0
Thomas Zimmermann
maintainerPATCH 2/5 lib: devres: Add managed arch_io_reserve_memtype_wc()
In reply to Thomas ZimmermannAdd devm_arch_io_reserve_memtype_wc() as managed wrapper around arch_io_reserve_memtype_wc(). Useful for several grahpics drivers that set framebuffer memory to write combining.
--- include/linux/io.h | 3 +++ lib/devres.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+)
include/linux/io.h +3 -0
@@ -168,4 +168,7 @@ static inline void arch_io_free_memtype_wc(resource_size_t base, }#endif +int devm_arch_io_reserve_memtype_wc (struct device *dev,resource_size_t start, +resource_size_t size); +#endif /* _LINUX_IO_H */
lib/devres.c +46 -0
49 lines not on this page · raw message
Signature · 1 line
2.33.0
Thomas Zimmermann
maintainerPATCH 3/5 drm/ast: Use managed interfaces for framebuffer write combining
In reply to Thomas ZimmermannReplace arch_phys_wc_add() and arch_io_reserve_memtype_wc() with the rsp managed functions. Allows for removing the cleanup code for memory management
--- drivers/gpu/drm/ast/ast_drv.h | 2 -- drivers/gpu/drm/ast/ast_mm.c | 27 ++++++++++----------------- 2 files changed, 10 insertions(+), 19 deletions(-)
drivers/gpu/drm/ast/ast_drv.h +0 -2
@@ -158,8 +158,6 @@ struct ast_private {uint32_t dram_type;uint32_t mclk; -int fb_mtrr; -struct drm_plane primary_plane;struct ast_cursor_plane cursor_plane;struct drm_crtc crtc;
drivers/gpu/drm/ast/ast_mm.c +10 -17
@@ -74,35 +74,28 @@ static u32 ast_get_vram_size(struct ast_private *ast)return vram_size; } -static void ast_mm_release (struct drm_device *dev,void *ptr) -{ -struct ast_private *ast =to_ast_private (dev); -struct pci_dev *pdev =to_pci_dev (dev->dev); - -arch_phys_wc_del (ast->fb_mtrr); -arch_io_free_memtype_wc (pci_resource_start (pdev,0 ), -pci_resource_len (pdev,0 )); -} -int ast_mm_init (struct ast_private *ast) {struct drm_device *dev = &ast->base;struct pci_dev *pdev =to_pci_dev (dev->dev); +resource_size_t base, size;u32 vram_size;int ret; + base =pci_resource_start (pdev,0 ); + size =pci_resource_len (pdev,0 ); + +/* Don't fail on errors, but performance might be reduced. */ +devm_arch_io_reserve_memtype_wc (dev->dev, base, size); +devm_arch_phys_wc_add (dev->dev, base, size); + vram_size =ast_get_vram_size (ast); - ret =drmm_vram_helper_init (dev,pci_resource_start (pdev,0 ), vram_size); + ret =drmm_vram_helper_init (dev, base, vram_size);if (ret) {drm_err (dev,"Error initializing VRAM MM; %d\n" , ret);return ret; } -arch_io_reserve_memtype_wc (pci_resource_start (pdev,0 ), -pci_resource_len (pdev,0 )); - ast->fb_mtrr =arch_phys_wc_add (pci_resource_start (pdev,0 ), -pci_resource_len (pdev,0 )); - -return drmm_add_action_or_reset (dev, ast_mm_release,NULL ); +return 0 ; }
Signature · 1 line
2.33.0
Thomas Zimmermann
maintainerPATCH 4/5 drm/mgag200: Use managed interfaces for framebuffer write combining
In reply to Thomas ZimmermannReplace arch_phys_wc_add() and arch_io_reserve_memtype_wc() with the rsp managed functions. Allows for removing the cleanup code for memory management
--- drivers/gpu/drm/mgag200/mgag200_drv.h | 2 -- drivers/gpu/drm/mgag200/mgag200_mm.c | 35 ++++++--------------------- 2 files changed, 7 insertions(+), 30 deletions(-)
drivers/gpu/drm/mgag200/mgag200_drv.h +0 -2
@@ -224,8 +224,6 @@ struct mga_device {enum mga_type type; -int fb_mtrr; - union { struct { long ref_clk;
drivers/gpu/drm/mgag200/mgag200_mm.c +7 -28
@@ -75,26 +75,12 @@ static size_t mgag200_probe_vram(struct mga_device *mdev, void __iomem *mem,return offset -65536 ; } -static void mgag200_mm_release (struct drm_device *dev,void *ptr) -{ -struct mga_device *mdev =to_mga_device (dev); -struct pci_dev *pdev =to_pci_dev (dev->dev); - - mdev->vram_fb_available =0 ; -iounmap (mdev->vram); -arch_io_free_memtype_wc (pci_resource_start (pdev,0 ), -pci_resource_len (pdev,0 )); -arch_phys_wc_del (mdev->fb_mtrr); - mdev->fb_mtrr =0 ; -} -int mgag200_mm_init (struct mga_device *mdev) {struct drm_device *dev = &mdev->base;struct pci_dev *pdev =to_pci_dev (dev->dev);u8 misc;resource_size_t start, len; -int ret;WREG_ECRT (0x04 ,0x00 );
@@ -112,15 +98,13 @@ int mgag200_mm_init(struct mga_device *mdev)return -ENXIO ; } -arch_io_reserve_memtype_wc (start, len); - - mdev->fb_mtrr =arch_phys_wc_add (start, len); +/* Don't fail on errors, but performance might be reduced. */ +devm_arch_io_reserve_memtype_wc (dev->dev, start, len); +devm_arch_phys_wc_add (dev->dev, start, len); - mdev->vram =ioremap (start, len); -if (!mdev->vram) { - ret = -ENOMEM ; - goto err_arch_phys_wc_del; - } + mdev->vram =devm_ioremap (dev->dev, start, len); +if (!mdev->vram) +return -ENOMEM ; mdev->mc.vram_size =mgag200_probe_vram (mdev, mdev->vram, len); mdev->mc.vram_base = start;
@@ -128,10 +112,5 @@ int mgag200_mm_init(struct mga_device *mdev) mdev->vram_fb_available = mdev->mc.vram_size; -return drmm_add_action_or_reset (dev, mgag200_mm_release,NULL ); - -err_arch_phys_wc_del: -arch_phys_wc_del (mdev->fb_mtrr); -arch_io_free_memtype_wc (start, len); -return ret; +return 0 ; }
Signature · 1 line
2.33.0
Thomas Zimmermann
maintainerPATCH 5/5 drm/vboxvideo: Use managed interfaces for framebuffer write combining
In reply to Thomas ZimmermannReplace arch_phys_wc_add() with the rsp managed function. Allows for removing the cleanup code for memory management
--- drivers/gpu/drm/vboxvideo/vbox_drv.c | 5 +---- drivers/gpu/drm/vboxvideo/vbox_drv.h | 1 - drivers/gpu/drm/vboxvideo/vbox_ttm.c | 17 ++++++++--------- 3 files changed, 9 insertions(+), 14 deletions(-)
drivers/gpu/drm/vboxvideo/vbox_drv.c +1 -4
@@ -69,7 +69,7 @@ static int vbox_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) ret =vbox_mode_init (vbox);if (ret) - goto err_mm_fini; + goto err_hw_fini; ret =vbox_irq_init (vbox);if (ret)
@@ -87,8 +87,6 @@ static int vbox_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)vbox_irq_fini (vbox); err_mode_fini:vbox_mode_fini (vbox); -err_mm_fini: -vbox_mm_fini (vbox); err_hw_fini:vbox_hw_fini (vbox);return ret;
@@ -101,7 +99,6 @@ static void vbox_pci_remove(struct pci_dev *pdev)drm_dev_unregister (&vbox->ddev);vbox_irq_fini (vbox);vbox_mode_fini (vbox); -vbox_mm_fini (vbox);vbox_hw_fini (vbox); }
drivers/gpu/drm/vboxvideo/vbox_drv.h +0 -1
@@ -139,7 +139,6 @@ void vbox_mode_fini(struct vbox_private *vbox);void vbox_report_caps (struct vbox_private *vbox);int vbox_mm_init (struct vbox_private *vbox); -void vbox_mm_fini (struct vbox_private *vbox);/* vbox_irq.c */ int vbox_irq_init (struct vbox_private *vbox);
drivers/gpu/drm/vboxvideo/vbox_ttm.c +8 -9
@@ -13,22 +13,21 @@int vbox_mm_init (struct vbox_private *vbox) {int ret; +resource_size_t base, size;struct drm_device *dev = &vbox->ddev;struct pci_dev *pdev =to_pci_dev (dev->dev); - ret =drmm_vram_helper_init (dev,pci_resource_start (pdev,0 ), - vbox->available_vram_size); + base =pci_resource_start (pdev,0 ); + size =pci_resource_len (pdev,0 ); + +/* Don't fail on errors, but performance might be reduced. */ +devm_arch_phys_wc_add (&pdev->dev, base, size); + + ret =drmm_vram_helper_init (dev, base, vbox->available_vram_size);if (ret) {DRM_ERROR ("Error initializing VRAM MM; %d\n" , ret);return ret; } - vbox->fb_mtrr =arch_phys_wc_add (pci_resource_start (pdev,0 ), -pci_resource_len (pdev,0 ));return 0 ; } - -void vbox_mm_fini (struct vbox_private *vbox) -{ -arch_phys_wc_del (vbox->fb_mtrr); -}
Signature · 1 line
2.33.0
Re: [PATCH 5/5] drm/vboxvideo: Use managed interfaces for framebuffer write combining
Hi,
Quoted 4 lines · Thomas Zimmermann
Replace
arch_phys_wc_add()with the rsp managed function. Allows for removing the cleanup code for memory managementSigned-off-by Thomas Zimmermann <[email protected]>
Thanks, patch looks good to me:
Regards,
Hans
Quoted 84 lines
--- drivers/gpu/drm/vboxvideo/vbox_drv.c | 5 +---- drivers/gpu/drm/vboxvideo/vbox_drv.h | 1 - drivers/gpu/drm/vboxvideo/vbox_ttm.c | 17 ++++++++--------- 3 files changed, 9 insertions(+), 14 deletions(-)drivers/gpu/drm/vboxvideo/vbox_drv.c +1
-4@@ -69,7 +69,7 @@ static int vbox_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) ret =vbox_mode_init (vbox);if (ret) - goto err_mm_fini; + goto err_hw_fini; ret =vbox_irq_init (vbox);if (ret)@@ -87,8 +87,6 @@ static int vbox_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)vbox_irq_fini (vbox); err_mode_fini:vbox_mode_fini (vbox); -err_mm_fini: -vbox_mm_fini (vbox); err_hw_fini:vbox_hw_fini (vbox);return ret;@@ -101,7 +99,6 @@ static void vbox_pci_remove(struct pci_dev *pdev)drm_dev_unregister (&vbox->ddev);vbox_irq_fini (vbox);vbox_mode_fini (vbox); -vbox_mm_fini (vbox);vbox_hw_fini (vbox); }drivers/gpu/drm/vboxvideo/vbox_drv.h +0
-1@@ -139,7 +139,6 @@ void vbox_mode_fini(struct vbox_private *vbox);void vbox_report_caps (struct vbox_private *vbox);int vbox_mm_init (struct vbox_private *vbox); -void vbox_mm_fini (struct vbox_private *vbox);/* vbox_irq.c */ int vbox_irq_init (struct vbox_private *vbox);drivers/gpu/drm/vboxvideo/vbox_ttm.c +8
-9@@ -13,22 +13,21 @@int vbox_mm_init (struct vbox_private *vbox) {int ret; +resource_size_t base, size;struct drm_device *dev = &vbox->ddev;struct pci_dev *pdev =to_pci_dev (dev->dev); - ret =drmm_vram_helper_init (dev,pci_resource_start (pdev,0 ), - vbox->available_vram_size); + base =pci_resource_start (pdev,0 ); + size =pci_resource_len (pdev,0 ); + +/* Don't fail on errors, but performance might be reduced. */ +devm_arch_phys_wc_add (&pdev->dev, base, size); + + ret =drmm_vram_helper_init (dev, base, vbox->available_vram_size);if (ret) {DRM_ERROR ("Error initializing VRAM MM; %d\n" , ret);return ret; } - vbox->fb_mtrr =arch_phys_wc_add (pci_resource_start (pdev,0 ), -pci_resource_len (pdev,0 ));return 0 ; } - -void vbox_mm_fini (struct vbox_private *vbox) -{ -arch_phys_wc_del (vbox->fb_mtrr); -}
Re: [PATCH 5/5] drm/vboxvideo: Use managed interfaces for framebuffer write combining
Quoted 11 lines · Hans de Goede
Hi,
Quoted 4 lines · Thomas Zimmermann
Replace
arch_phys_wc_add()with the rsp managed function. Allows for removing the cleanup code for memory managementSigned-off-by Thomas Zimmermann <[email protected]>Thanks, patch looks good to me:
Reviewed-by Hans de Goede <[email protected]>
Maybe review entire series and then ask Thomas to unblock some of your stuff?
-Daniel
Quoted 91 lines
Regards,
Hans
Quoted 84 lines
--- drivers/gpu/drm/vboxvideo/vbox_drv.c | 5 +---- drivers/gpu/drm/vboxvideo/vbox_drv.h | 1 - drivers/gpu/drm/vboxvideo/vbox_ttm.c | 17 ++++++++--------- 3 files changed, 9 insertions(+), 14 deletions(-)drivers/gpu/drm/vboxvideo/vbox_drv.c +1
-4@@ -69,7 +69,7 @@ static int vbox_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) ret =vbox_mode_init (vbox);if (ret) - goto err_mm_fini; + goto err_hw_fini; ret =vbox_irq_init (vbox);if (ret)@@ -87,8 +87,6 @@ static int vbox_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)vbox_irq_fini (vbox); err_mode_fini:vbox_mode_fini (vbox); -err_mm_fini: -vbox_mm_fini (vbox); err_hw_fini:vbox_hw_fini (vbox);return ret;@@ -101,7 +99,6 @@ static void vbox_pci_remove(struct pci_dev *pdev)drm_dev_unregister (&vbox->ddev);vbox_irq_fini (vbox);vbox_mode_fini (vbox); -vbox_mm_fini (vbox);vbox_hw_fini (vbox); }drivers/gpu/drm/vboxvideo/vbox_drv.h +0
-1@@ -139,7 +139,6 @@ void vbox_mode_fini(struct vbox_private *vbox);void vbox_report_caps (struct vbox_private *vbox);int vbox_mm_init (struct vbox_private *vbox); -void vbox_mm_fini (struct vbox_private *vbox);/* vbox_irq.c */ int vbox_irq_init (struct vbox_private *vbox);drivers/gpu/drm/vboxvideo/vbox_ttm.c +8
-9@@ -13,22 +13,21 @@int vbox_mm_init (struct vbox_private *vbox) {int ret; +resource_size_t base, size;struct drm_device *dev = &vbox->ddev;struct pci_dev *pdev =to_pci_dev (dev->dev); - ret =drmm_vram_helper_init (dev,pci_resource_start (pdev,0 ), - vbox->available_vram_size); + base =pci_resource_start (pdev,0 ); + size =pci_resource_len (pdev,0 ); + +/* Don't fail on errors, but performance might be reduced. */ +devm_arch_phys_wc_add (&pdev->dev, base, size); + + ret =drmm_vram_helper_init (dev, base, vbox->available_vram_size);if (ret) {DRM_ERROR ("Error initializing VRAM MM; %d\n" , ret);return ret; } - vbox->fb_mtrr =arch_phys_wc_add (pci_resource_start (pdev,0 ), -pci_resource_len (pdev,0 ));return 0 ; } - -void vbox_mm_fini (struct vbox_private *vbox) -{ -arch_phys_wc_del (vbox->fb_mtrr); -}
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Hi,
Quoted 7 lines · Thomas Zimmermann
Add
devm_arch_phys_wc_add()anddevm_arch_io_reserve_memtype_wc()for automatic cleanup of writecombine setup.Several DRM drivers use the non-managed functions for setting their framebuffer memory to write-combine access. Convert ast, mgag200 and vboxvideo. Remove rsp clean-up code form drivers.
Quoted 8 lines
Tested on mgag200 hardware.
Thomas Zimmermann (5):
lib: devres: Add managedarch_phys_wc_add()
lib: devres: Add managedarch_io_reserve_memtype_wc()drm/ast: Use managed interfaces for framebuffer write combining drm/mgag200: Use managed interfaces for framebuffer write combining drm/vboxvideo: Use managed interfaces for framebuffer write combining
Thanks, the entire series looks good to me:
For the series.
Regards,
Hans
Thomas Zimmermann
maintainerHi
Am 17.09.21 um 16:47 schrieb Hans de Goede:
Quoted 19 lines
Hi,
Quoted 7 lines · Thomas Zimmermann
Add
devm_arch_phys_wc_add()anddevm_arch_io_reserve_memtype_wc()for automatic cleanup of writecombine setup.Several DRM drivers use the non-managed functions for setting their framebuffer memory to write-combine access. Convert ast, mgag200 and vboxvideo. Remove rsp clean-up code form drivers.
Quoted 8 lines
Tested on mgag200 hardware.
Thomas Zimmermann (5):
lib: devres: Add managedarch_phys_wc_add()
lib: devres: Add managedarch_io_reserve_memtype_wc()drm/ast: Use managed interfaces for framebuffer write combining drm/mgag200: Use managed interfaces for framebuffer write combining drm/vboxvideo: Use managed interfaces for framebuffer write combining
Quoted 5 lines
Thanks, the entire series looks good to me:
Reviewed-by Hans de Goede <[email protected]>For the series.
Thanks. Let me know if I can review some DRM code for you, as Daniel suggested.
I'll wait a bit before merging the patches. Maybe devres devs want to comment.
Best regards
Thomas
Quoted 5 lines
Regards,
Hans
Signature · 6 lines
Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 Nürnberg, Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer
Hi,
Quoted 22 lines · Thomas Zimmermann
Hi
Am 17.09.21 um 16:47 schrieb Hans de Goede:
Quoted 19 lines
Hi,
Quoted 15 lines · Thomas Zimmermann
Add
devm_arch_phys_wc_add()anddevm_arch_io_reserve_memtype_wc()for automatic cleanup of writecombine setup.Several DRM drivers use the non-managed functions for setting their framebuffer memory to write-combine access. Convert ast, mgag200 and vboxvideo. Remove rsp clean-up code form drivers.
Tested on mgag200 hardware.
Thomas Zimmermann (5):
lib: devres: Add managedarch_phys_wc_add()
lib: devres: Add managedarch_io_reserve_memtype_wc()drm/ast: Use managed interfaces for framebuffer write combining drm/mgag200: Use managed interfaces for framebuffer write combining drm/vboxvideo: Use managed interfaces for framebuffer write combining
Quoted 7 lines
Quoted 5 lines
Thanks, the entire series looks good to me:
Reviewed-by Hans de Goede <[email protected]>For the series.
Thanks. Let me know if I can review some DRM code for you, as Daniel suggested.
Thank you for the offer, ATM I don't have anything queued up in need of review, but I will probably make use of your offer in the future :) Regards,
Hans