Skip to content

Commit

Permalink
drm/ast: Convert ast to SHMEM
Browse files Browse the repository at this point in the history
Replace GEM VRAM helpers with GEM SHMEM helpers in ast. Avoids OOM
errors when allocating video memory. Also adds support for dma-buf
functionality.

Aspeed display hardware supports display resolutions of FullHD and
higher at 32-bit pixel depth. But the amount of video memory is in
the range of 8 MiB to 32 MiB, which adds constraints to the actually
available resolutions. As atomic modesetting with VRAM helpers
requires double buffering in video memory, ast fails to pageflip
in some configurations. For example, FullHD with an active cursor
plane does not work on devices with 16 MiB of video memory.

Resolve this problem by converting the ast driver to GEM SHMEM helpers.
Keep the buffer objects in system memory and copy to video memory
on pageflips via shadow-plane helpers. Userspace used to require shadow
planes for decent performance, but that's now provided by the driver.
To replace the memory management, the patch also implements damage
handling for the primary plane.

With GEM SHMEM helpers, dma-buf import and export is now supported
by ast. This allows easier screen mirroring across devices or with
an Aspeed-based BMC. A corresponding feature request is available
at [1].

v2:
	* fix typos in commit message (Jocelyn)

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Jocelyn Falempe <jfalempe@redhat.com>
Tested-by: Jocelyn Falempe <jfalempe@redhat.com>
Link: https://lore.kernel.org/dri-devel/20220901124451.2523077-1-oushixiong@kylinos.cn/ # [1]
Link: https://patchwork.freedesktop.org/patch/msgid/20221013112923.769-8-tzimmermann@suse.de
  • Loading branch information
Thomas Zimmermann committed Oct 16, 2022
1 parent d95dcfc commit f2fa5a9
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 115 deletions.
4 changes: 1 addition & 3 deletions drivers/gpu/drm/ast/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
config DRM_AST
tristate "AST server chips"
depends on DRM && PCI && MMU
select DRM_GEM_SHMEM_HELPER
select DRM_KMS_HELPER
select DRM_VRAM_HELPER
select DRM_TTM
select DRM_TTM_HELPER
help
Say yes for experimental AST GPU driver. Do not enable
this driver without having a working -modesetting,
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpu/drm/ast/ast_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <drm/drm_atomic_helper.h>
#include <drm/drm_crtc_helper.h>
#include <drm/drm_drv.h>
#include <drm/drm_gem_vram_helper.h>
#include <drm/drm_gem_shmem_helper.h>
#include <drm/drm_module.h>
#include <drm/drm_probe_helper.h>

Expand Down Expand Up @@ -63,7 +63,7 @@ static const struct drm_driver ast_driver = {
.minor = DRIVER_MINOR,
.patchlevel = DRIVER_PATCHLEVEL,

DRM_GEM_VRAM_DRIVER
DRM_GEM_SHMEM_DRIVER_OPS
};

/*
Expand Down
13 changes: 9 additions & 4 deletions drivers/gpu/drm/ast/ast_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ enum ast_tx_chip {
struct ast_plane {
struct drm_plane base;

struct drm_gem_vram_object *gbo;
struct iosys_map map;
u64 off;
void __iomem *vaddr;
u64 offset;
unsigned long size;
};

static inline struct ast_plane *to_ast_plane(struct drm_plane *plane)
Expand Down Expand Up @@ -172,7 +172,12 @@ struct ast_private {
uint32_t dram_type;
uint32_t mclk;

struct drm_plane primary_plane;
void __iomem *vram;
unsigned long vram_base;
unsigned long vram_size;
unsigned long vram_fb_available;

struct ast_plane primary_plane;
struct ast_plane cursor_plane;
struct drm_crtc crtc;
struct {
Expand Down
5 changes: 2 additions & 3 deletions drivers/gpu/drm/ast/ast_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include <drm/drm_crtc_helper.h>
#include <drm/drm_drv.h>
#include <drm/drm_gem.h>
#include <drm/drm_gem_vram_helper.h>
#include <drm/drm_managed.h>

#include "ast_drv.h"
Expand Down Expand Up @@ -461,8 +460,8 @@ struct ast_private *ast_device_create(const struct drm_driver *drv,

/* map reserved buffer */
ast->dp501_fw_buf = NULL;
if (dev->vram_mm->vram_size < pci_resource_len(pdev, 0)) {
ast->dp501_fw_buf = pci_iomap_range(pdev, 0, dev->vram_mm->vram_size, 0);
if (ast->vram_size < pci_resource_len(pdev, 0)) {
ast->dp501_fw_buf = pci_iomap_range(pdev, 0, ast->vram_size, 0);
if (!ast->dp501_fw_buf)
drm_info(dev, "failed to map reserved buffer!\n");
}
Expand Down
14 changes: 7 additions & 7 deletions drivers/gpu/drm/ast/ast_mm.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

#include <linux/pci.h>

#include <drm/drm_gem_vram_helper.h>
#include <drm/drm_managed.h>
#include <drm/drm_print.h>

Expand Down Expand Up @@ -80,7 +79,6 @@ int ast_mm_init(struct ast_private *ast)
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);
Expand All @@ -91,11 +89,13 @@ int ast_mm_init(struct ast_private *ast)

vram_size = ast_get_vram_size(ast);

ret = drmm_vram_helper_init(dev, base, vram_size);
if (ret) {
drm_err(dev, "Error initializing VRAM MM; %d\n", ret);
return ret;
}
ast->vram = devm_ioremap_wc(dev->dev, base, vram_size);
if (!ast->vram)
return -ENOMEM;

ast->vram_base = base;
ast->vram_size = vram_size;
ast->vram_fb_available = vram_size;

return 0;
}
Loading

0 comments on commit f2fa5a9

Please sign in to comment.