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

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.de


Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
parent b3a25b9a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ config DRM_MGAG200
	depends on DRM && PCI && MMU
	select DRM_KMS_HELPER
	select DRM_TTM
	select DRM_VRAM_HELPER
	help
	 This is a KMS driver for the MGA G200 server chips, it
         does not support the original MGA G200 or any of the desktop
+37 −26
Original line number Diff line number Diff line
@@ -23,9 +23,9 @@ static void mga_hide_cursor(struct mga_device *mdev)
	WREG8(MGA_CURPOSXL, 0);
	WREG8(MGA_CURPOSXH, 0);
	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)
		mgag200_bo_unpin(mdev->cursor.pixels_2);
		drm_gem_vram_unpin(mdev->cursor.pixels_2);
}

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 mga_device *mdev = (struct mga_device *)dev->dev_private;
	struct mgag200_bo *pixels_1 = mdev->cursor.pixels_1;
	struct mgag200_bo *pixels_2 = mdev->cursor.pixels_2;
	struct mgag200_bo *pixels_current = mdev->cursor.pixels_current;
	struct mgag200_bo *pixels_prev = mdev->cursor.pixels_prev;
	struct drm_gem_vram_object *pixels_1 = mdev->cursor.pixels_1;
	struct drm_gem_vram_object *pixels_2 = mdev->cursor.pixels_2;
	struct drm_gem_vram_object *pixels_current = mdev->cursor.pixels_current;
	struct drm_gem_vram_object *pixels_prev = mdev->cursor.pixels_prev;
	struct drm_gem_object *obj;
	struct mgag200_bo *bo = NULL;
	struct drm_gem_vram_object *gbo = NULL;
	int ret = 0;
	unsigned int i, row, col;
	uint32_t colour_set[16];
@@ -50,7 +50,7 @@ int mga_crtc_cursor_set(struct drm_crtc *crtc,
	uint32_t this_colour;
	bool found = false;
	int colour_count = 0;
	u64 gpu_addr;
	s64 gpu_addr;
	u8 reg_index;
	u8 this_row[48];

@@ -79,44 +79,55 @@ int mga_crtc_cursor_set(struct drm_crtc *crtc,
	if (!obj)
		return -ENOENT;

	ret = mgag200_bo_reserve(pixels_1, true);
	ret = drm_gem_vram_reserve(pixels_1, true);
	if (ret) {
		WREG8(MGA_CURPOSXL, 0);
		WREG8(MGA_CURPOSXH, 0);
		goto out_unref;
	}
	ret = mgag200_bo_reserve(pixels_2, true);
	ret = drm_gem_vram_reserve(pixels_2, true);
	if (ret) {
		WREG8(MGA_CURPOSXL, 0);
		WREG8(MGA_CURPOSXH, 0);
		mgag200_bo_unreserve(pixels_1);
		drm_gem_vram_unreserve(pixels_1);
		goto out_unreserve1;
	}

	/* Move cursor buffers into VRAM if they aren't already */
	if (!pixels_1->pin_count) {
		ret = mgag200_bo_pin(pixels_1, TTM_PL_FLAG_VRAM,
				     &mdev->cursor.pixels_1_gpu_addr);
		ret = drm_gem_vram_pin(pixels_1, DRM_GEM_VRAM_PL_FLAG_VRAM);
		if (ret)
			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) {
		ret = mgag200_bo_pin(pixels_2, TTM_PL_FLAG_VRAM,
				     &mdev->cursor.pixels_2_gpu_addr);
		ret = drm_gem_vram_pin(pixels_2, DRM_GEM_VRAM_PL_FLAG_VRAM);
		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;
		}
		mdev->cursor.pixels_2_gpu_addr = gpu_addr;
	}

	bo = gem_to_mga_bo(obj);
	ret = mgag200_bo_reserve(bo, true);
	gbo = drm_gem_vram_of_gem(obj);
	ret = drm_gem_vram_reserve(gbo, true);
	if (ret) {
		dev_err(&dev->pdev->dev, "failed to reserve user bo\n");
		goto out1;
	}
	if (!bo->kmap.virtual) {
		ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &bo->kmap);
	if (!gbo->kmap.virtual) {
		ret = ttm_bo_kmap(&gbo->bo, 0, gbo->bo.num_pages, &gbo->kmap);
		if (ret) {
			dev_err(&dev->pdev->dev, "failed to kmap user buffer updates\n");
			goto out2;
@@ -126,7 +137,7 @@ int mga_crtc_cursor_set(struct drm_crtc *crtc,
	memset(&colour_set[0], 0, sizeof(uint32_t)*16);
	/* width*height*4 = 16384 */
	for (i = 0; i < 16384; i += 4) {
		this_colour = ioread32(bo->kmap.virtual + i);
		this_colour = ioread32(gbo->kmap.virtual + i);
		/* No transparency */
		if (this_colour>>24 != 0xff &&
			this_colour>>24 != 0x0) {
@@ -192,7 +203,7 @@ int mga_crtc_cursor_set(struct drm_crtc *crtc,
	for (row = 0; row < 64; row++) {
		memset(&this_row[0], 0, 48);
		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 */
			if (this_colour>>24 == 0x0) {
				this_row[47 - col/8] |= 0x80>>(col%8);
@@ -238,15 +249,15 @@ int mga_crtc_cursor_set(struct drm_crtc *crtc,

	ttm_bo_kunmap(&pixels_prev->kmap);
 out3:
	ttm_bo_kunmap(&bo->kmap);
	ttm_bo_kunmap(&gbo->kmap);
 out2:
	mgag200_bo_unreserve(bo);
	drm_gem_vram_unreserve(gbo);
 out1:
	if (ret)
		mga_hide_cursor(mdev);
	mgag200_bo_unreserve(pixels_1);
	drm_gem_vram_unreserve(pixels_1);
out_unreserve1:
	mgag200_bo_unreserve(pixels_2);
	drm_gem_vram_unreserve(pixels_2);
out_unref:
	drm_gem_object_put_unlocked(obj);

+3 −2
Original line number Diff line number Diff line
@@ -80,9 +80,10 @@ static struct drm_driver driver = {
	.minor = DRIVER_MINOR,
	.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_map_offset = mgag200_dumb_mmap_offset,
	.dumb_map_offset = drm_gem_vram_driver_dumb_mmap_offset,
};

static struct pci_driver mgag200_pci_driver = {
+8 −54
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include <drm/ttm/ttm_module.h>

#include <drm/drm_gem.h>
#include <drm/drm_gem_vram_helper.h>

#include <linux/i2c.h>
#include <linux/i2c-algo-bit.h>
@@ -159,13 +160,13 @@ struct mga_cursor {
	   If either of these is NULL, then don't do hardware cursors, and
	   fall back to software.
	*/
	struct mgag200_bo *pixels_1;
	struct mgag200_bo *pixels_2;
	struct drm_gem_vram_object *pixels_1;
	struct drm_gem_vram_object *pixels_2;
	u64 pixels_1_gpu_addr, pixels_2_gpu_addr;
	/* 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 */
	struct mgag200_bo *pixels_prev;
	struct drm_gem_vram_object *pixels_prev;
};

struct mga_mc {
@@ -219,23 +220,6 @@ struct mga_device {
	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 */
int mgag200_modeset_init(struct mga_device *mdev);
void mgag200_modeset_fini(struct mga_device *mdev);
@@ -259,45 +243,15 @@ int mgag200_gem_create(struct drm_device *dev,
int mgag200_dumb_create(struct drm_file *file,
			struct drm_device *dev,
			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 */
struct mga_i2c_chan *mgag200_i2c_create(struct drm_device *dev);
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);
void mgag200_mm_fini(struct mga_device *mdev);
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,
						uint32_t handle, uint32_t width, uint32_t height);
int mga_crtc_cursor_move(struct drm_crtc *crtc, int x, int y);
+12 −10
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ static void mga_dirty_update(struct mga_fbdev *mfbdev,
{
	int i;
	struct drm_gem_object *obj;
	struct mgag200_bo *bo;
	struct drm_gem_vram_object *gbo;
	int src_offset, dst_offset;
	int bpp = mfbdev->mfb.base.format->cpp[0];
	int ret = -EBUSY;
@@ -33,7 +33,7 @@ static void mga_dirty_update(struct mga_fbdev *mfbdev,
	unsigned long flags;

	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
@@ -41,7 +41,7 @@ static void mga_dirty_update(struct mga_fbdev *mfbdev,
	 * store up the damage until later.
	 */
	if (drm_can_sleep())
		ret = mgag200_bo_reserve(bo, true);
		ret = drm_gem_vram_reserve(gbo, true);
	if (ret) {
		if (ret != -EBUSY)
			return;
@@ -75,25 +75,27 @@ static void mga_dirty_update(struct mga_fbdev *mfbdev,
	mfbdev->x2 = mfbdev->y2 = 0;
	spin_unlock_irqrestore(&mfbdev->dirty_lock, flags);

	if (!bo->kmap.virtual) {
		ret = ttm_bo_kmap(&bo->bo, 0, bo->bo.num_pages, &bo->kmap);
	if (!gbo->kmap.virtual) {
		ret = ttm_bo_kmap(&gbo->bo, 0, gbo->bo.num_pages, &gbo->kmap);
		if (ret) {
			DRM_ERROR("failed to kmap fb updates\n");
			mgag200_bo_unreserve(bo);
			drm_gem_vram_unreserve(gbo);
			return;
		}
		unmap = true;
	}
	for (i = y; i <= y2; i++) {
		/* assume equal stride for now */
		src_offset = dst_offset = i * mfbdev->mfb.base.pitches[0] + (x * bpp);
		memcpy_toio(bo->kmap.virtual + src_offset, mfbdev->sysram + src_offset, (x2 - x + 1) * bpp);
		src_offset = dst_offset =
			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)
		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,
Loading