Skip to content

Commit 969562b

Browse files
tdzkraxel
authored andcommitted
drm/ast: Convert AST driver to VRAM MM
The data structure |struct drm_vram_mm| and its helpers replace ast's TTM-based memory manager. It's the same implementation; except for the type names. v4: * don't select DRM_TTM or DRM_VRAM_MM_HELPER v3: * use drm_gem_vram_mm_funcs * convert driver to drm_device-based instance v2: * implement ast_mmap() with drm_vram_mm_mmap() Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> Link: http://patchwork.freedesktop.org/patch/msgid/20190508082630.15116-11-tzimmermann@suse.de Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
1 parent 5b37097 commit 969562b

5 files changed

Lines changed: 13 additions & 167 deletions

File tree

‎drivers/gpu/drm/ast/Kconfig‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
config DRM_AST
22
tristate "AST server chips"
33
depends on DRM && PCI && MMU
4-
select DRM_TTM
54
select DRM_KMS_HELPER
65
select DRM_VRAM_HELPER
76
help

‎drivers/gpu/drm/ast/ast_drv.c‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,7 @@ static struct pci_driver ast_pci_driver = {
205205

206206
static const struct file_operations ast_fops = {
207207
.owner = THIS_MODULE,
208-
.open = drm_open,
209-
.release = drm_release,
210-
.unlocked_ioctl = drm_ioctl,
211-
.mmap = ast_mmap,
212-
.poll = drm_poll,
213-
.compat_ioctl = drm_compat_ioctl,
214-
.read = drm_read,
208+
DRM_VRAM_MM_FILE_OPERATIONS
215209
};
216210

217211
static struct drm_driver driver = {
@@ -228,11 +222,7 @@ static struct drm_driver driver = {
228222
.minor = DRIVER_MINOR,
229223
.patchlevel = DRIVER_PATCHLEVEL,
230224

231-
.gem_free_object_unlocked =
232-
drm_gem_vram_driver_gem_free_object_unlocked,
233-
.dumb_create = ast_dumb_create,
234-
.dumb_map_offset = drm_gem_vram_driver_dumb_mmap_offset,
235-
225+
DRM_GEM_VRAM_DRIVER
236226
};
237227

238228
static int __init ast_init(void)

‎drivers/gpu/drm/ast/ast_drv.h‎

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,11 @@
3131
#include <drm/drm_encoder.h>
3232
#include <drm/drm_fb_helper.h>
3333

34-
#include <drm/ttm/ttm_bo_api.h>
35-
#include <drm/ttm/ttm_bo_driver.h>
36-
#include <drm/ttm/ttm_placement.h>
37-
#include <drm/ttm/ttm_memory.h>
38-
#include <drm/ttm/ttm_module.h>
39-
4034
#include <drm/drm_gem.h>
4135
#include <drm/drm_gem_vram_helper.h>
4236

37+
#include <drm/drm_vram_mm_helper.h>
38+
4339
#include <linux/i2c.h>
4440
#include <linux/i2c-algo-bit.h>
4541

@@ -104,10 +100,6 @@ struct ast_private {
104100

105101
int fb_mtrr;
106102

107-
struct {
108-
struct ttm_bo_device bdev;
109-
} ttm;
110-
111103
struct drm_gem_object *cursor_cache;
112104
uint64_t cursor_cache_gpu_addr;
113105
/* Acces to this cache is protected by the crtc->mutex of the only crtc
@@ -325,19 +317,13 @@ void ast_fbdev_set_base(struct ast_private *ast, unsigned long gpu_addr);
325317
#define AST_MM_ALIGN_SHIFT 4
326318
#define AST_MM_ALIGN_MASK ((1 << AST_MM_ALIGN_SHIFT) - 1)
327319

328-
extern int ast_dumb_create(struct drm_file *file,
329-
struct drm_device *dev,
330-
struct drm_mode_create_dumb *args);
331-
332320
int ast_mm_init(struct ast_private *ast);
333321
void ast_mm_fini(struct ast_private *ast);
334322

335323
int ast_gem_create(struct drm_device *dev,
336324
u32 size, bool iskernel,
337325
struct drm_gem_object **obj);
338326

339-
int ast_mmap(struct file *filp, struct vm_area_struct *vma);
340-
341327
/* ast post */
342328
void ast_enable_vga(struct drm_device *dev);
343329
void ast_enable_mmio(struct drm_device *dev);

‎drivers/gpu/drm/ast/ast_main.c‎

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,6 @@ int ast_gem_create(struct drm_device *dev,
593593
u32 size, bool iskernel,
594594
struct drm_gem_object **obj)
595595
{
596-
struct ast_private *ast = dev->dev_private;
597596
struct drm_gem_vram_object *gbo;
598597
int ret;
599598

@@ -603,7 +602,7 @@ int ast_gem_create(struct drm_device *dev,
603602
if (size == 0)
604603
return -EINVAL;
605604

606-
gbo = drm_gem_vram_create(dev, &ast->ttm.bdev, size, 0, false);
605+
gbo = drm_gem_vram_create(dev, &dev->vram_mm->bdev, size, 0, false);
607606
if (IS_ERR(gbo)) {
608607
ret = PTR_ERR(gbo);
609608
if (ret != -ERESTARTSYS)
@@ -613,13 +612,3 @@ int ast_gem_create(struct drm_device *dev,
613612
*obj = &gbo->gem;
614613
return 0;
615614
}
616-
617-
int ast_dumb_create(struct drm_file *file,
618-
struct drm_device *dev,
619-
struct drm_mode_create_dumb *args)
620-
{
621-
struct ast_private *ast = dev->dev_private;
622-
623-
return drm_gem_vram_fill_create_dumb(file, dev, &ast->ttm.bdev, 0,
624-
false, args);
625-
}

‎drivers/gpu/drm/ast/ast_ttm.c‎

Lines changed: 8 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -26,131 +26,21 @@
2626
* Authors: Dave Airlie <airlied@redhat.com>
2727
*/
2828
#include <drm/drmP.h>
29-
#include <drm/ttm/ttm_page_alloc.h>
3029

3130
#include "ast_drv.h"
3231

33-
static inline struct ast_private *
34-
ast_bdev(struct ttm_bo_device *bd)
35-
{
36-
return container_of(bd, struct ast_private, ttm.bdev);
37-
}
38-
39-
static int
40-
ast_bo_init_mem_type(struct ttm_bo_device *bdev, uint32_t type,
41-
struct ttm_mem_type_manager *man)
42-
{
43-
switch (type) {
44-
case TTM_PL_SYSTEM:
45-
man->flags = TTM_MEMTYPE_FLAG_MAPPABLE;
46-
man->available_caching = TTM_PL_MASK_CACHING;
47-
man->default_caching = TTM_PL_FLAG_CACHED;
48-
break;
49-
case TTM_PL_VRAM:
50-
man->func = &ttm_bo_manager_func;
51-
man->flags = TTM_MEMTYPE_FLAG_FIXED |
52-
TTM_MEMTYPE_FLAG_MAPPABLE;
53-
man->available_caching = TTM_PL_FLAG_UNCACHED |
54-
TTM_PL_FLAG_WC;
55-
man->default_caching = TTM_PL_FLAG_WC;
56-
break;
57-
default:
58-
DRM_ERROR("Unsupported memory type %u\n", (unsigned)type);
59-
return -EINVAL;
60-
}
61-
return 0;
62-
}
63-
64-
static int ast_ttm_io_mem_reserve(struct ttm_bo_device *bdev,
65-
struct ttm_mem_reg *mem)
66-
{
67-
struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type];
68-
struct ast_private *ast = ast_bdev(bdev);
69-
70-
mem->bus.addr = NULL;
71-
mem->bus.offset = 0;
72-
mem->bus.size = mem->num_pages << PAGE_SHIFT;
73-
mem->bus.base = 0;
74-
mem->bus.is_iomem = false;
75-
if (!(man->flags & TTM_MEMTYPE_FLAG_MAPPABLE))
76-
return -EINVAL;
77-
switch (mem->mem_type) {
78-
case TTM_PL_SYSTEM:
79-
/* system memory */
80-
return 0;
81-
case TTM_PL_VRAM:
82-
mem->bus.offset = mem->start << PAGE_SHIFT;
83-
mem->bus.base = pci_resource_start(ast->dev->pdev, 0);
84-
mem->bus.is_iomem = true;
85-
break;
86-
default:
87-
return -EINVAL;
88-
break;
89-
}
90-
return 0;
91-
}
92-
93-
static void ast_ttm_io_mem_free(struct ttm_bo_device *bdev, struct ttm_mem_reg *mem)
94-
{
95-
}
96-
97-
static void ast_ttm_backend_destroy(struct ttm_tt *tt)
98-
{
99-
ttm_tt_fini(tt);
100-
kfree(tt);
101-
}
102-
103-
static struct ttm_backend_func ast_tt_backend_func = {
104-
.destroy = &ast_ttm_backend_destroy,
105-
};
106-
107-
108-
static struct ttm_tt *ast_ttm_tt_create(struct ttm_buffer_object *bo,
109-
uint32_t page_flags)
110-
{
111-
struct ttm_tt *tt;
112-
113-
tt = kzalloc(sizeof(struct ttm_tt), GFP_KERNEL);
114-
if (tt == NULL)
115-
return NULL;
116-
tt->func = &ast_tt_backend_func;
117-
if (ttm_tt_init(tt, bo, page_flags)) {
118-
kfree(tt);
119-
return NULL;
120-
}
121-
return tt;
122-
}
123-
124-
struct ttm_bo_driver ast_bo_driver = {
125-
.ttm_tt_create = ast_ttm_tt_create,
126-
.init_mem_type = ast_bo_init_mem_type,
127-
.eviction_valuable = ttm_bo_eviction_valuable,
128-
.evict_flags = drm_gem_vram_bo_driver_evict_flags,
129-
.move = NULL,
130-
.verify_access = drm_gem_vram_bo_driver_verify_access,
131-
.io_mem_reserve = &ast_ttm_io_mem_reserve,
132-
.io_mem_free = &ast_ttm_io_mem_free,
133-
};
134-
13532
int ast_mm_init(struct ast_private *ast)
13633
{
34+
struct drm_vram_mm *vmm;
13735
int ret;
13836
struct drm_device *dev = ast->dev;
139-
struct ttm_bo_device *bdev = &ast->ttm.bdev;
140-
141-
ret = ttm_bo_device_init(&ast->ttm.bdev,
142-
&ast_bo_driver,
143-
dev->anon_inode->i_mapping,
144-
true);
145-
if (ret) {
146-
DRM_ERROR("Error initialising bo driver; %d\n", ret);
147-
return ret;
148-
}
14937

150-
ret = ttm_bo_init_mm(bdev, TTM_PL_VRAM,
151-
ast->vram_size >> PAGE_SHIFT);
152-
if (ret) {
153-
DRM_ERROR("Failed ttm VRAM init: %d\n", ret);
38+
vmm = drm_vram_helper_alloc_mm(
39+
dev, pci_resource_start(dev->pdev, 0),
40+
ast->vram_size, &drm_gem_vram_mm_funcs);
41+
if (IS_ERR(vmm)) {
42+
ret = PTR_ERR(vmm);
43+
DRM_ERROR("Error initializing VRAM MM; %d\n", ret);
15444
return ret;
15545
}
15646

@@ -166,17 +56,9 @@ void ast_mm_fini(struct ast_private *ast)
16656
{
16757
struct drm_device *dev = ast->dev;
16858

169-
ttm_bo_device_release(&ast->ttm.bdev);
59+
drm_vram_helper_release_mm(dev);
17060

17161
arch_phys_wc_del(ast->fb_mtrr);
17262
arch_io_free_memtype_wc(pci_resource_start(dev->pdev, 0),
17363
pci_resource_len(dev->pdev, 0));
17464
}
175-
176-
int ast_mmap(struct file *filp, struct vm_area_struct *vma)
177-
{
178-
struct drm_file *file_priv = filp->private_data;
179-
struct ast_private *ast = file_priv->minor->dev->dev_private;
180-
181-
return ttm_bo_mmap(filp, vma, &ast->ttm.bdev);
182-
}

0 commit comments

Comments
 (0)