Commit ebb04eb3 authored by Thomas Zimmermann's avatar Thomas Zimmermann Committed by Gerd Hoffmann

drm/mgag200: Convert mgag200 driver to |struct drm_gem_vram_object|

The data structure |struct drm_gem_vram_object| and its helpers replace
|struct mgag200_bo|. It's the same implementation; except for the type
names.

v4:
	* cleanups from checkpatch.pl
	* select config option DRM_VRAM_HELPER
Signed-off-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
Link: http://patchwork.freedesktop.org/patch/msgid/20190508082630.15116-15-tzimmermann@suse.deSigned-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
parent b3a25b9a
...@@ -3,6 +3,7 @@ config DRM_MGAG200 ...@@ -3,6 +3,7 @@ config DRM_MGAG200
depends on DRM && PCI && MMU depends on DRM && PCI && MMU
select DRM_KMS_HELPER select DRM_KMS_HELPER
select DRM_TTM select DRM_TTM
select DRM_VRAM_HELPER
help help
This is a KMS driver for the MGA G200 server chips, it This is a KMS driver for the MGA G200 server chips, it
does not support the original MGA G200 or any of the desktop does not support the original MGA G200 or any of the desktop
......
...@@ -23,9 +23,9 @@ static void mga_hide_cursor(struct mga_device *mdev) ...@@ -23,9 +23,9 @@ static void mga_hide_cursor(struct mga_device *mdev)
WREG8(MGA_CURPOSXL, 0); WREG8(MGA_CURPOSXL, 0);
WREG8(MGA_CURPOSXH, 0); WREG8(MGA_CURPOSXH, 0);
if (mdev->cursor.pixels_1->pin_count) if (mdev->cursor.pixels_1->pin_count)
mgag200_bo_unpin(mdev->cursor.pixels_1); drm_gem_vram_unpin(mdev->cursor.pixels_1);
if (mdev->cursor.pixels_2->pin_count) if (mdev->cursor.pixels_2->pin_count)
mgag200_bo_unpin(mdev->cursor.pixels_2); drm_gem_vram_unpin(mdev->cursor.pixels_2);
} }
int mga_crtc_cursor_set(struct drm_crtc *crtc, int mga_crtc_cursor_set(struct drm_crtc *crtc,
...@@ -36,12 +36,12 @@ int mga_crtc_cursor_set(struct drm_crtc *crtc, ...@@ -36,12 +36,12 @@ int mga_crtc_cursor_set(struct drm_crtc *crtc,
{ {
struct drm_device *dev = crtc->dev; struct drm_device *dev = crtc->dev;
struct mga_device *mdev = (struct mga_device *)dev->dev_private; struct mga_device *mdev = (struct mga_device *)dev->dev_private;
struct mgag200_bo *pixels_1 = mdev->cursor.pixels_1; struct drm_gem_vram_object *pixels_1 = mdev->cursor.pixels_1;
struct mgag200_bo *pixels_2 = mdev->cursor.pixels_2; struct drm_gem_vram_object *pixels_2 = mdev->cursor.pixels_2;
struct mgag200_bo *pixels_current = mdev->cursor.pixels_current; struct drm_gem_vram_object *pixels_current = mdev->cursor.pixels_current;
struct mgag200_bo *pixels_prev = mdev->cursor.pixels_prev; struct drm_gem_vram_object *pixels_prev = mdev->cursor.pixels_prev;
struct drm_gem_object *obj; struct drm_gem_object *obj;
struct mgag200_bo *bo = NULL; struct drm_gem_vram_object *gbo = NULL;
int ret = 0; int ret = 0;
unsigned int i, row, col; unsigned int i, row, col;
uint32_t colour_set[16]; uint32_t colour_set[16];
...@@ -50,7 +50,7 @@ int mga_crtc_cursor_set(struct drm_crtc *crtc, ...@@ -50,7 +50,7 @@ int mga_crtc_cursor_set(struct drm_crtc *crtc,
uint32_t this_colour; uint32_t this_colour;
bool found = false; bool found = false;
int colour_count = 0; int colour_count = 0;
u64 gpu_addr; s64 gpu_addr;
u8 reg_index; u8 reg_index;
u8 this_row[48]; u8 this_row[48];
...@@ -79,44 +79,55 @@ int mga_crtc_cursor_set(struct drm_crtc *crtc, ...@@ -79,44 +79,55 @@ int mga_crtc_cursor_set(struct drm_crtc *crtc,
if (!obj) if (!obj)
return -ENOENT; return -ENOENT;
ret = mgag200_bo_reserve(pixels_1, true); ret = drm_gem_vram_reserve(pixels_1, true);
if (ret) { if (ret) {
WREG8(MGA_CURPOSXL, 0); WREG8(MGA_CURPOSXL, 0);
WREG8(MGA_CURPOSXH, 0); WREG8(MGA_CURPOSXH, 0);
goto out_unref; goto out_unref;
} }
ret = mgag200_bo_reserve(pixels_2, true); ret = drm_gem_vram_reserve(pixels_2, true);
if (ret) { if (ret) {
WREG8(MGA_CURPOSXL, 0); WREG8(MGA_CURPOSXL, 0);
WREG8(MGA_CURPOSXH, 0); WREG8(MGA_CURPOSXH, 0);
mgag200_bo_unreserve(pixels_1); drm_gem_vram_unreserve(pixels_1);
goto out_unreserve1; goto out_unreserve1;
} }
/* Move cursor buffers into VRAM if they aren't already */ /* Move cursor buffers into VRAM if they aren't already */
if (!pixels_1->pin_count) { if (!pixels_1->pin_count) {
ret = mgag200_bo_pin(pixels_1, TTM_PL_FLAG_VRAM, ret = drm_gem_vram_pin(pixels_1, DRM_GEM_VRAM_PL_FLAG_VRAM);
&mdev->cursor.pixels_1_gpu_addr);
if (ret) if (ret)
goto out1; goto out1;
gpu_addr = drm_gem_vram_offset(pixels_1);
if (gpu_addr < 0) {
drm_gem_vram_unpin(pixels_1);
goto out1;
}
mdev->cursor.pixels_1_gpu_addr = gpu_addr;
} }
if (!pixels_2->pin_count) { if (!pixels_2->pin_count) {
ret = mgag200_bo_pin(pixels_2, TTM_PL_FLAG_VRAM, ret = drm_gem_vram_pin(pixels_2, DRM_GEM_VRAM_PL_FLAG_VRAM);
&mdev->cursor.pixels_2_gpu_addr);
if (ret) { if (ret) {
mgag200_bo_unpin(pixels_1); drm_gem_vram_unpin(pixels_1);
goto out1;
}
gpu_addr = drm_gem_vram_offset(pixels_2);
if (gpu_addr < 0) {
drm_gem_vram_unpin(pixels_1);
drm_gem_vram_unpin(pixels_2);
goto out1; goto out1;
} }
mdev->cursor.pixels_2_gpu_addr = gpu_addr;
} }
bo = gem_to_mga_bo(obj); gbo = drm_gem_vram_of_gem(obj);
ret = mgag200_bo_reserve(bo, true); ret = drm_gem_vram_reserve(gbo, true);
if (ret) { if (ret) {
dev_err(&dev->pdev->dev, "failed to reserve user bo\n"); dev_err(&dev->pdev->dev, "failed to reserve user bo\n");
goto out1; goto out1;
} }
if (!bo->kmap.virtual) { if (!gbo->kmap.virtual) {
ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &bo->kmap); ret = ttm_bo_kmap(&gbo->bo, 0, gbo->bo.num_pages, &gbo->kmap);
if (ret) { if (ret) {
dev_err(&dev->pdev->dev, "failed to kmap user buffer updates\n"); dev_err(&dev->pdev->dev, "failed to kmap user buffer updates\n");
goto out2; goto out2;
...@@ -126,7 +137,7 @@ int mga_crtc_cursor_set(struct drm_crtc *crtc, ...@@ -126,7 +137,7 @@ int mga_crtc_cursor_set(struct drm_crtc *crtc,
memset(&colour_set[0], 0, sizeof(uint32_t)*16); memset(&colour_set[0], 0, sizeof(uint32_t)*16);
/* width*height*4 = 16384 */ /* width*height*4 = 16384 */
for (i = 0; i < 16384; i += 4) { for (i = 0; i < 16384; i += 4) {
this_colour = ioread32(bo->kmap.virtual + i); this_colour = ioread32(gbo->kmap.virtual + i);
/* No transparency */ /* No transparency */
if (this_colour>>24 != 0xff && if (this_colour>>24 != 0xff &&
this_colour>>24 != 0x0) { this_colour>>24 != 0x0) {
...@@ -192,7 +203,7 @@ int mga_crtc_cursor_set(struct drm_crtc *crtc, ...@@ -192,7 +203,7 @@ int mga_crtc_cursor_set(struct drm_crtc *crtc,
for (row = 0; row < 64; row++) { for (row = 0; row < 64; row++) {
memset(&this_row[0], 0, 48); memset(&this_row[0], 0, 48);
for (col = 0; col < 64; col++) { for (col = 0; col < 64; col++) {
this_colour = ioread32(bo->kmap.virtual + 4*(col + 64*row)); this_colour = ioread32(gbo->kmap.virtual + 4*(col + 64*row));
/* write transparent pixels */ /* write transparent pixels */
if (this_colour>>24 == 0x0) { if (this_colour>>24 == 0x0) {
this_row[47 - col/8] |= 0x80>>(col%8); this_row[47 - col/8] |= 0x80>>(col%8);
...@@ -238,15 +249,15 @@ int mga_crtc_cursor_set(struct drm_crtc *crtc, ...@@ -238,15 +249,15 @@ int mga_crtc_cursor_set(struct drm_crtc *crtc,
ttm_bo_kunmap(&pixels_prev->kmap); ttm_bo_kunmap(&pixels_prev->kmap);
out3: out3:
ttm_bo_kunmap(&bo->kmap); ttm_bo_kunmap(&gbo->kmap);
out2: out2:
mgag200_bo_unreserve(bo); drm_gem_vram_unreserve(gbo);
out1: out1:
if (ret) if (ret)
mga_hide_cursor(mdev); mga_hide_cursor(mdev);
mgag200_bo_unreserve(pixels_1); drm_gem_vram_unreserve(pixels_1);
out_unreserve1: out_unreserve1:
mgag200_bo_unreserve(pixels_2); drm_gem_vram_unreserve(pixels_2);
out_unref: out_unref:
drm_gem_object_put_unlocked(obj); drm_gem_object_put_unlocked(obj);
......
...@@ -80,9 +80,10 @@ static struct drm_driver driver = { ...@@ -80,9 +80,10 @@ static struct drm_driver driver = {
.minor = DRIVER_MINOR, .minor = DRIVER_MINOR,
.patchlevel = DRIVER_PATCHLEVEL, .patchlevel = DRIVER_PATCHLEVEL,
.gem_free_object_unlocked = mgag200_gem_free_object, .gem_free_object_unlocked =
drm_gem_vram_driver_gem_free_object_unlocked,
.dumb_create = mgag200_dumb_create, .dumb_create = mgag200_dumb_create,
.dumb_map_offset = mgag200_dumb_mmap_offset, .dumb_map_offset = drm_gem_vram_driver_dumb_mmap_offset,
}; };
static struct pci_driver mgag200_pci_driver = { static struct pci_driver mgag200_pci_driver = {
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <drm/ttm/ttm_module.h> #include <drm/ttm/ttm_module.h>
#include <drm/drm_gem.h> #include <drm/drm_gem.h>
#include <drm/drm_gem_vram_helper.h>
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/i2c-algo-bit.h> #include <linux/i2c-algo-bit.h>
...@@ -159,13 +160,13 @@ struct mga_cursor { ...@@ -159,13 +160,13 @@ struct mga_cursor {
If either of these is NULL, then don't do hardware cursors, and If either of these is NULL, then don't do hardware cursors, and
fall back to software. fall back to software.
*/ */
struct mgag200_bo *pixels_1; struct drm_gem_vram_object *pixels_1;
struct mgag200_bo *pixels_2; struct drm_gem_vram_object *pixels_2;
u64 pixels_1_gpu_addr, pixels_2_gpu_addr; u64 pixels_1_gpu_addr, pixels_2_gpu_addr;
/* The currently displayed icon, this points to one of pixels_1, or pixels_2 */ /* The currently displayed icon, this points to one of pixels_1, or pixels_2 */
struct mgag200_bo *pixels_current; struct drm_gem_vram_object *pixels_current;
/* The previously displayed icon */ /* The previously displayed icon */
struct mgag200_bo *pixels_prev; struct drm_gem_vram_object *pixels_prev;
}; };
struct mga_mc { struct mga_mc {
...@@ -219,23 +220,6 @@ struct mga_device { ...@@ -219,23 +220,6 @@ struct mga_device {
u32 unique_rev_id; u32 unique_rev_id;
}; };
struct mgag200_bo {
struct ttm_buffer_object bo;
struct ttm_placement placement;
struct ttm_bo_kmap_obj kmap;
struct drm_gem_object gem;
struct ttm_place placements[3];
int pin_count;
};
#define gem_to_mga_bo(gobj) container_of((gobj), struct mgag200_bo, gem)
static inline struct mgag200_bo *
mgag200_bo(struct ttm_buffer_object *bo)
{
return container_of(bo, struct mgag200_bo, bo);
}
/* mgag200_mode.c */ /* mgag200_mode.c */
int mgag200_modeset_init(struct mga_device *mdev); int mgag200_modeset_init(struct mga_device *mdev);
void mgag200_modeset_fini(struct mga_device *mdev); void mgag200_modeset_fini(struct mga_device *mdev);
...@@ -259,45 +243,15 @@ int mgag200_gem_create(struct drm_device *dev, ...@@ -259,45 +243,15 @@ int mgag200_gem_create(struct drm_device *dev,
int mgag200_dumb_create(struct drm_file *file, int mgag200_dumb_create(struct drm_file *file,
struct drm_device *dev, struct drm_device *dev,
struct drm_mode_create_dumb *args); struct drm_mode_create_dumb *args);
void mgag200_gem_free_object(struct drm_gem_object *obj);
int
mgag200_dumb_mmap_offset(struct drm_file *file,
struct drm_device *dev,
uint32_t handle,
uint64_t *offset);
/* mgag200_i2c.c */ /* mgag200_i2c.c */
struct mga_i2c_chan *mgag200_i2c_create(struct drm_device *dev); struct mga_i2c_chan *mgag200_i2c_create(struct drm_device *dev);
void mgag200_i2c_destroy(struct mga_i2c_chan *i2c); void mgag200_i2c_destroy(struct mga_i2c_chan *i2c);
void mgag200_ttm_placement(struct mgag200_bo *bo, int domain);
static inline int mgag200_bo_reserve(struct mgag200_bo *bo, bool no_wait)
{
int ret;
ret = ttm_bo_reserve(&bo->bo, true, no_wait, NULL);
if (ret) {
if (ret != -ERESTARTSYS && ret != -EBUSY)
DRM_ERROR("reserve failed %p\n", bo);
return ret;
}
return 0;
}
static inline void mgag200_bo_unreserve(struct mgag200_bo *bo)
{
ttm_bo_unreserve(&bo->bo);
}
int mgag200_bo_create(struct drm_device *dev, int size, int align,
uint32_t flags, struct mgag200_bo **pastbo);
int mgag200_mm_init(struct mga_device *mdev); int mgag200_mm_init(struct mga_device *mdev);
void mgag200_mm_fini(struct mga_device *mdev); void mgag200_mm_fini(struct mga_device *mdev);
int mgag200_mmap(struct file *filp, struct vm_area_struct *vma); int mgag200_mmap(struct file *filp, struct vm_area_struct *vma);
int mgag200_bo_pin(struct mgag200_bo *bo, u32 pl_flag, u64 *gpu_addr);
int mgag200_bo_unpin(struct mgag200_bo *bo);
int mgag200_bo_push_sysram(struct mgag200_bo *bo);
/* mgag200_cursor.c */
int mga_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv, int mga_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
uint32_t handle, uint32_t width, uint32_t height); uint32_t handle, uint32_t width, uint32_t height);
int mga_crtc_cursor_move(struct drm_crtc *crtc, int x, int y); int mga_crtc_cursor_move(struct drm_crtc *crtc, int x, int y);
......
...@@ -23,7 +23,7 @@ static void mga_dirty_update(struct mga_fbdev *mfbdev, ...@@ -23,7 +23,7 @@ static void mga_dirty_update(struct mga_fbdev *mfbdev,
{ {
int i; int i;
struct drm_gem_object *obj; struct drm_gem_object *obj;
struct mgag200_bo *bo; struct drm_gem_vram_object *gbo;
int src_offset, dst_offset; int src_offset, dst_offset;
int bpp = mfbdev->mfb.base.format->cpp[0]; int bpp = mfbdev->mfb.base.format->cpp[0];
int ret = -EBUSY; int ret = -EBUSY;
...@@ -33,7 +33,7 @@ static void mga_dirty_update(struct mga_fbdev *mfbdev, ...@@ -33,7 +33,7 @@ static void mga_dirty_update(struct mga_fbdev *mfbdev,
unsigned long flags; unsigned long flags;
obj = mfbdev->mfb.obj; obj = mfbdev->mfb.obj;
bo = gem_to_mga_bo(obj); gbo = drm_gem_vram_of_gem(obj);
/* /*
* try and reserve the BO, if we fail with busy * try and reserve the BO, if we fail with busy
...@@ -41,7 +41,7 @@ static void mga_dirty_update(struct mga_fbdev *mfbdev, ...@@ -41,7 +41,7 @@ static void mga_dirty_update(struct mga_fbdev *mfbdev,
* store up the damage until later. * store up the damage until later.
*/ */
if (drm_can_sleep()) if (drm_can_sleep())
ret = mgag200_bo_reserve(bo, true); ret = drm_gem_vram_reserve(gbo, true);
if (ret) { if (ret) {
if (ret != -EBUSY) if (ret != -EBUSY)
return; return;
...@@ -75,25 +75,27 @@ static void mga_dirty_update(struct mga_fbdev *mfbdev, ...@@ -75,25 +75,27 @@ static void mga_dirty_update(struct mga_fbdev *mfbdev,
mfbdev->x2 = mfbdev->y2 = 0; mfbdev->x2 = mfbdev->y2 = 0;
spin_unlock_irqrestore(&mfbdev->dirty_lock, flags); spin_unlock_irqrestore(&mfbdev->dirty_lock, flags);
if (!bo->kmap.virtual) { if (!gbo->kmap.virtual) {
ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &bo->kmap); ret = ttm_bo_kmap(&gbo->bo, 0, gbo->bo.num_pages, &gbo->kmap);
if (ret) { if (ret) {
DRM_ERROR("failed to kmap fb updates\n"); DRM_ERROR("failed to kmap fb updates\n");
mgag200_bo_unreserve(bo); drm_gem_vram_unreserve(gbo);
return; return;
} }
unmap = true; unmap = true;
} }
for (i = y; i <= y2; i++) { for (i = y; i <= y2; i++) {
/* assume equal stride for now */ /* assume equal stride for now */
src_offset = dst_offset = i * mfbdev->mfb.base.pitches[0] + (x * bpp); src_offset = dst_offset =
memcpy_toio(bo->kmap.virtual + src_offset, mfbdev->sysram + src_offset, (x2 - x + 1) * bpp); i * mfbdev->mfb.base.pitches[0] + (x * bpp);
memcpy_toio(gbo->kmap.virtual + src_offset,
mfbdev->sysram + dst_offset, (x2 - x + 1) * bpp);
} }
if (unmap) if (unmap)
ttm_bo_kunmap(&bo->kmap); ttm_bo_kunmap(&gbo->kmap);
mgag200_bo_unreserve(bo); drm_gem_vram_unreserve(gbo);
} }
static void mga_fillrect(struct fb_info *info, static void mga_fillrect(struct fb_info *info,
......
...@@ -230,11 +230,13 @@ int mgag200_driver_load(struct drm_device *dev, unsigned long flags) ...@@ -230,11 +230,13 @@ int mgag200_driver_load(struct drm_device *dev, unsigned long flags)
} }
/* Make small buffers to store a hardware cursor (double buffered icon updates) */ /* Make small buffers to store a hardware cursor (double buffered icon updates) */
mgag200_bo_create(dev, roundup(48*64, PAGE_SIZE), 0, 0, mdev->cursor.pixels_1 = drm_gem_vram_create(dev, &mdev->ttm.bdev,
&mdev->cursor.pixels_1); roundup(48*64, PAGE_SIZE),
mgag200_bo_create(dev, roundup(48*64, PAGE_SIZE), 0, 0, 0, 0);
&mdev->cursor.pixels_2); mdev->cursor.pixels_2 = drm_gem_vram_create(dev, &mdev->ttm.bdev,
if (!mdev->cursor.pixels_2 || !mdev->cursor.pixels_1) { roundup(48*64, PAGE_SIZE),
0, 0);
if (IS_ERR(mdev->cursor.pixels_2) || IS_ERR(mdev->cursor.pixels_1)) {
mdev->cursor.pixels_1 = NULL; mdev->cursor.pixels_1 = NULL;
mdev->cursor.pixels_2 = NULL; mdev->cursor.pixels_2 = NULL;
dev_warn(&dev->pdev->dev, dev_warn(&dev->pdev->dev,
...@@ -272,7 +274,8 @@ int mgag200_gem_create(struct drm_device *dev, ...@@ -272,7 +274,8 @@ int mgag200_gem_create(struct drm_device *dev,
u32 size, bool iskernel, u32 size, bool iskernel,
struct drm_gem_object **obj) struct drm_gem_object **obj)
{ {
struct mgag200_bo *astbo; struct mga_device *mdev = dev->dev_private;
struct drm_gem_vram_object *gbo;
int ret; int ret;
*obj = NULL; *obj = NULL;
...@@ -281,13 +284,14 @@ int mgag200_gem_create(struct drm_device *dev, ...@@ -281,13 +284,14 @@ int mgag200_gem_create(struct drm_device *dev,
if (size == 0) if (size == 0)
return -EINVAL; return -EINVAL;
ret = mgag200_bo_create(dev, size, 0, 0, &astbo); gbo = drm_gem_vram_create(dev, &mdev->ttm.bdev, size, 0, false);
if (ret) { if (IS_ERR(gbo)) {
ret = PTR_ERR(gbo);
if (ret != -ERESTARTSYS) if (ret != -ERESTARTSYS)
DRM_ERROR("failed to allocate GEM object\n"); DRM_ERROR("failed to allocate GEM object\n");
return ret; return ret;
} }
*obj = &astbo->gem; *obj = &gbo->gem;
return 0; return 0;
} }
...@@ -295,64 +299,8 @@ int mgag200_dumb_create(struct drm_file *file, ...@@ -295,64 +299,8 @@ int mgag200_dumb_create(struct drm_file *file,
struct drm_device *dev, struct drm_device *dev,
struct drm_mode_create_dumb *args) struct drm_mode_create_dumb *args)
{ {
int ret; struct mga_device *mdev = dev->dev_private;
struct drm_gem_object *gobj;
u32 handle;
args->pitch = args->width * ((args->bpp + 7) / 8);
args->size = args->pitch * args->height;
ret = mgag200_gem_create(dev, args->size, false,
&gobj);
if (ret)
return ret;
ret = drm_gem_handle_create(file, gobj, &handle);
drm_gem_object_put_unlocked(gobj);
if (ret)
return ret;
args->handle = handle;
return 0;
}
static void mgag200_bo_unref(struct mgag200_bo **bo)
{
if ((*bo) == NULL)
return;
ttm_bo_put(&((*bo)->bo));
*bo = NULL;
}
void mgag200_gem_free_object(struct drm_gem_object *obj)
{
struct mgag200_bo *mgag200_bo = gem_to_mga_bo(obj);
mgag200_bo_unref(&mgag200_bo);
}
static inline u64 mgag200_bo_mmap_offset(struct mgag200_bo *bo)
{
return drm_vma_node_offset_addr(&bo->bo.vma_node);
}
int
mgag200_dumb_mmap_offset(struct drm_file *file,
struct drm_device *dev,
uint32_t handle,
uint64_t *offset)
{
struct drm_gem_object *obj;
struct mgag200_bo *bo;
obj = drm_gem_object_lookup(file, handle);
if (obj == NULL)
return -ENOENT;
bo = gem_to_mga_bo(obj);
*offset = mgag200_bo_mmap_offset(bo);
drm_gem_object_put_unlocked(obj); return drm_gem_vram_fill_create_dumb(file, dev, &mdev->ttm.bdev, 0,
return 0; false, args);
} }
...@@ -867,48 +867,57 @@ static int mga_crtc_do_set_base(struct drm_crtc *crtc, ...@@ -867,48 +867,57 @@ static int mga_crtc_do_set_base(struct drm_crtc *crtc,
struct mga_device *mdev = crtc->dev->dev_private; struct mga_device *mdev = crtc->dev->dev_private;
struct drm_gem_object *obj; struct drm_gem_object *obj;
struct mga_framebuffer *mga_fb; struct mga_framebuffer *mga_fb;
struct mgag200_bo *bo; struct drm_gem_vram_object *gbo;
int ret; int ret;
u64 gpu_addr; s64 gpu_addr;
/* push the previous fb to system ram */ /* push the previous fb to system ram */
if (!atomic && fb) { if (!atomic && fb) {
mga_fb = to_mga_framebuffer(fb); mga_fb = to_mga_framebuffer(fb);
obj = mga_fb->obj; obj = mga_fb->obj;
bo = gem_to_mga_bo(obj); gbo = drm_gem_vram_of_gem(obj);
ret = mgag200_bo_reserve(bo, false); ret = drm_gem_vram_reserve(gbo, false);
if (ret) if (ret)
return ret; return ret;
mgag200_bo_push_sysram(bo); drm_gem_vram_push_to_system(gbo);
mgag200_bo_unreserve(bo); drm_gem_vram_unreserve(gbo);
} }
mga_fb = to_mga_framebuffer(crtc->primary->fb); mga_fb = to_mga_framebuffer(crtc->primary->fb);
obj = mga_fb->obj; obj = mga_fb->obj;
bo = gem_to_mga_bo(obj); gbo = drm_gem_vram_of_gem(obj);
ret = mgag200_bo_reserve(bo, false); ret = drm_gem_vram_reserve(gbo, false);
if (ret) if (ret)
return ret; return ret;
ret = mgag200_bo_pin(bo, TTM_PL_FLAG_VRAM, &gpu_addr); ret = drm_gem_vram_pin(gbo, DRM_GEM_VRAM_PL_FLAG_VRAM);
if (ret) { if (ret)
mgag200_bo_unreserve(bo); goto err_drm_gem_vram_unreserve;
return ret; gpu_addr = drm_gem_vram_offset(gbo);
if (gpu_addr < 0) {
ret = (int)gpu_addr;
goto err_drm_gem_vram_unpin;
} }
if (&mdev->mfbdev->mfb == mga_fb) { if (&mdev->mfbdev->mfb == mga_fb) {
/* if pushing console in kmap it */ /* if pushing console in kmap it */
ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &bo->kmap); ret = ttm_bo_kmap(&gbo->bo, 0, gbo->bo.num_pages, &gbo->kmap);
if (ret) if (ret)
DRM_ERROR("failed to kmap fbcon\n"); DRM_ERROR("failed to kmap fbcon\n");
} }
mgag200_bo_unreserve(bo); drm_gem_vram_unreserve(gbo);
mga_set_start_address(crtc, (u32)gpu_addr); mga_set_start_address(crtc, (u32)gpu_addr);
return 0; return 0;
err_drm_gem_vram_unpin:
drm_gem_vram_unpin(gbo);
err_drm_gem_vram_unreserve:
drm_gem_vram_unreserve(gbo);
return ret;
} }
static int mga_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, static int mga_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
...@@ -1428,12 +1437,13 @@ static void mga_crtc_disable(struct drm_crtc *crtc) ...@@ -1428,12 +1437,13 @@ static void mga_crtc_disable(struct drm_crtc *crtc)
if (crtc->primary->fb) { if (crtc->primary->fb) {
struct mga_framebuffer *mga_fb = to_mga_framebuffer(crtc->primary->fb); struct mga_framebuffer *mga_fb = to_mga_framebuffer(crtc->primary->fb);
struct drm_gem_object *obj = mga_fb->obj; struct drm_gem_object *obj = mga_fb->obj;
struct mgag200_bo *bo = gem_to_mga_bo(obj); struct drm_gem_vram_object *gbo = drm_gem_vram_of_gem(obj);
ret = mgag200_bo_reserve(bo, false);
ret = drm_gem_vram_reserve(gbo, false);
if (ret) if (ret)
return; return;
mgag200_bo_push_sysram(bo); drm_gem_vram_push_to_system(gbo);
mgag200_bo_unreserve(bo); drm_gem_vram_unreserve(gbo);
} }
crtc->primary->fb = NULL; crtc->primary->fb = NULL;
} }
......
...@@ -36,23 +36,6 @@ mgag200_bdev(struct ttm_bo_device *bd) ...@@ -36,23 +36,6 @@ mgag200_bdev(struct ttm_bo_device *bd)
return container_of(bd, struct mga_device, ttm.bdev); return container_of(bd, struct mga_device, ttm.bdev);
} }
static void mgag200_bo_ttm_destroy(struct ttm_buffer_object *tbo)
{
struct mgag200_bo *bo;
bo = container_of(tbo, struct mgag200_bo, bo);
drm_gem_object_release(&bo->gem);
kfree(bo);
}
static bool mgag200_ttm_bo_is_mgag200_bo(struct ttm_buffer_object *bo)
{
if (bo->destroy == &mgag200_bo_ttm_destroy)
return true;
return false;
}
static int static int
mgag200_bo_init_mem_type(struct ttm_bo_device *bdev, uint32_t type, mgag200_bo_init_mem_type(struct ttm_bo_device *bdev, uint32_t type,
struct ttm_mem_type_manager *man) struct ttm_mem_type_manager *man)
...@@ -78,26 +61,6 @@ mgag200_bo_init_mem_type(struct ttm_bo_device *bdev, uint32_t type, ...@@ -78,26 +61,6 @@ mgag200_bo_init_mem_type(struct ttm_bo_device *bdev, uint32_t type,
return 0; return 0;
} }
static void
mgag200_bo_evict_flags(struct ttm_buffer_object *bo, struct ttm_placement *pl)
{
struct mgag200_bo *mgabo = mgag200_bo(bo);
if (!mgag200_ttm_bo_is_mgag200_bo(bo))
return;
mgag200_ttm_placement(mgabo, TTM_PL_FLAG_SYSTEM);
*pl = mgabo->placement;
}
static int mgag200_bo_verify_access(struct ttm_buffer_object *bo, struct file *filp)
{
struct mgag200_bo *mgabo = mgag200_bo(bo);
return drm_vma_node_verify_access(&mgabo->gem.vma_node,
filp->private_data);
}
static int mgag200_ttm_io_mem_reserve(struct ttm_bo_device *bdev, static int mgag200_ttm_io_mem_reserve(struct ttm_bo_device *bdev,
struct ttm_mem_reg *mem) struct ttm_mem_reg *mem)
{ {
...@@ -162,9 +125,9 @@ struct ttm_bo_driver mgag200_bo_driver = { ...@@ -162,9 +125,9 @@ struct ttm_bo_driver mgag200_bo_driver = {
.ttm_tt_create = mgag200_ttm_tt_create, .ttm_tt_create = mgag200_ttm_tt_create,
.init_mem_type = mgag200_bo_init_mem_type, .init_mem_type = mgag200_bo_init_mem_type,
.eviction_valuable = ttm_bo_eviction_valuable, .eviction_valuable = ttm_bo_eviction_valuable,
.evict_flags = mgag200_bo_evict_flags, .evict_flags = drm_gem_vram_bo_driver_evict_flags,
.move = NULL, .move = NULL,
.verify_access = mgag200_bo_verify_access, .verify_access = drm_gem_vram_bo_driver_verify_access,
.io_mem_reserve = &mgag200_ttm_io_mem_reserve, .io_mem_reserve = &mgag200_ttm_io_mem_reserve,
.io_mem_free = &mgag200_ttm_io_mem_free, .io_mem_free = &mgag200_ttm_io_mem_free,
}; };
...@@ -211,137 +174,6 @@ void mgag200_mm_fini(struct mga_device *mdev) ...@@ -211,137 +174,6 @@ void mgag200_mm_fini(struct mga_device *mdev)
mdev->fb_mtrr = 0; mdev->fb_mtrr = 0;
} }
void mgag200_ttm_placement(struct mgag200_bo *bo, int domain)
{
u32 c = 0;
unsigned i;
bo->placement.placement = bo->placements;
bo->placement.busy_placement = bo->placements;
if (domain & TTM_PL_FLAG_VRAM)
bo->placements[c++].flags = TTM_PL_FLAG_WC | TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_VRAM;
if (domain & TTM_PL_FLAG_SYSTEM)
bo->placements[c++].flags = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM;
if (!c)
bo->placements[c++].flags = TTM_PL_MASK_CACHING | TTM_PL_FLAG_SYSTEM;
bo->placement.num_placement = c;
bo->placement.num_busy_placement = c;
for (i = 0; i < c; ++i) {
bo->placements[i].fpfn = 0;
bo->placements[i].lpfn = 0;
}
}
int mgag200_bo_create(struct drm_device *dev, int size, int align,
uint32_t flags, struct mgag200_bo **pmgabo)
{
struct mga_device *mdev = dev->dev_private;
struct mgag200_bo *mgabo;
size_t acc_size;
int ret;
mgabo = kzalloc(sizeof(struct mgag200_bo), GFP_KERNEL);
if (!mgabo)
return -ENOMEM;
ret = drm_gem_object_init(dev, &mgabo->gem, size);
if (ret) {
kfree(mgabo);
return ret;
}
mgabo->bo.bdev = &mdev->ttm.bdev;
mgag200_ttm_placement(mgabo, TTM_PL_FLAG_VRAM | TTM_PL_FLAG_SYSTEM);
acc_size = ttm_bo_dma_acc_size(&mdev->ttm.bdev, size,
sizeof(struct mgag200_bo));
ret = ttm_bo_init(&mdev->ttm.bdev, &mgabo->bo, size,
ttm_bo_type_device, &mgabo->placement,
align >> PAGE_SHIFT, false, acc_size,
NULL, NULL, mgag200_bo_ttm_destroy);
if (ret)
return ret;
*pmgabo = mgabo;
return 0;
}
static inline u64 mgag200_bo_gpu_offset(struct mgag200_bo *bo)
{
return bo->bo.offset;
}
int mgag200_bo_pin(struct mgag200_bo *bo, u32 pl_flag, u64 *gpu_addr)
{
struct ttm_operation_ctx ctx = { false, false };
int i, ret;
if (bo->pin_count) {
bo->pin_count++;
if (gpu_addr)
*gpu_addr = mgag200_bo_gpu_offset(bo);
return 0;
}
mgag200_ttm_placement(bo, pl_flag);
for (i = 0; i < bo->placement.num_placement; i++)
bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT;
ret = ttm_bo_validate(&bo->bo, &bo->placement, &ctx);
if (ret)
return ret;
bo->pin_count = 1;
if (gpu_addr)
*gpu_addr = mgag200_bo_gpu_offset(bo);
return 0;
}
int mgag200_bo_unpin(struct mgag200_bo *bo)
{
struct ttm_operation_ctx ctx = { false, false };
int i;
if (!bo->pin_count) {
DRM_ERROR("unpin bad %p\n", bo);
return 0;
}
bo->pin_count--;
if (bo->pin_count)
return 0;
for (i = 0; i < bo->placement.num_placement ; i++)
bo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT;
return ttm_bo_validate(&bo->bo, &bo->placement, &ctx);
}
int mgag200_bo_push_sysram(struct mgag200_bo *bo)
{
struct ttm_operation_ctx ctx = { false, false };
int i, ret;
if (!bo->pin_count) {
DRM_ERROR("unpin bad %p\n", bo);
return 0;
}
bo->pin_count--;
if (bo->pin_count)
return 0;
if (bo->kmap.virtual)
ttm_bo_kunmap(&bo->kmap);
mgag200_ttm_placement(bo, TTM_PL_FLAG_SYSTEM);
for (i = 0; i < bo->placement.num_placement ; i++)
bo->placements[i].flags |= TTM_PL_FLAG_NO_EVICT;
ret = ttm_bo_validate(&bo->bo, &bo->placement, &ctx);
if (ret) {
DRM_ERROR("pushing to VRAM failed\n");
return ret;
}
return 0;
}
int mgag200_mmap(struct file *filp, struct vm_area_struct *vma) int mgag200_mmap(struct file *filp, struct vm_area_struct *vma)
{ {
struct drm_file *file_priv = filp->private_data; struct drm_file *file_priv = filp->private_data;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment