drm/gma500: Rename struct gtt_range to struct psb_gem_object

struct gtt_range represents a GEM object. Rename the structure to struct
psb_gem_object and update all users. No functional changes.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Acked-by: Patrik Jakobsson <patrik.r.jakobsson@gmail.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20211015084053.13708-11-tzimmermann@suse.de
This commit is contained in:
Thomas Zimmermann 2021-10-15 10:40:53 +02:00
parent e1f80341e3
commit f2d061ed01
9 changed files with 123 additions and 117 deletions

View File

@ -81,14 +81,13 @@ static vm_fault_t psbfb_vm_fault(struct vm_fault *vmf)
struct drm_framebuffer *fb = vma->vm_private_data;
struct drm_device *dev = fb->dev;
struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
struct gtt_range *gtt = to_gtt_range(fb->obj[0]);
struct psb_gem_object *pobj = to_psb_gem_object(fb->obj[0]);
int page_num;
int i;
unsigned long address;
vm_fault_t ret = VM_FAULT_SIGBUS;
unsigned long pfn;
unsigned long phys_addr = (unsigned long)dev_priv->stolen_base +
gtt->offset;
unsigned long phys_addr = (unsigned long)dev_priv->stolen_base + pobj->offset;
page_num = vma_pages(vma);
address = vmf->address - (vmf->pgoff << PAGE_SHIFT);
@ -242,7 +241,7 @@ static int psbfb_create(struct drm_fb_helper *fb_helper,
struct drm_mode_fb_cmd2 mode_cmd;
int size;
int ret;
struct gtt_range *backing;
struct psb_gem_object *backing;
struct drm_gem_object *obj;
u32 bpp, depth;
@ -264,7 +263,7 @@ static int psbfb_create(struct drm_fb_helper *fb_helper,
backing = psb_gem_create(dev, size, "fb", true, PAGE_SIZE);
if (IS_ERR(backing))
return PTR_ERR(backing);
obj = &backing->gem;
obj = &backing->base;
memset(dev_priv->vram_addr + backing->offset, 0, size);

View File

@ -21,9 +21,10 @@
#include "gem.h"
#include "psb_drv.h"
int psb_gem_pin(struct gtt_range *gt)
int psb_gem_pin(struct psb_gem_object *pobj)
{
struct drm_device *dev = gt->gem.dev;
struct drm_gem_object *obj = &pobj->base;
struct drm_device *dev = obj->dev;
struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
u32 gpu_base = dev_priv->gtt.gatt_start;
struct page **pages;
@ -32,29 +33,29 @@ int psb_gem_pin(struct gtt_range *gt)
mutex_lock(&dev_priv->gtt_mutex);
if (gt->in_gart || gt->stolen)
if (pobj->in_gart || pobj->stolen)
goto out; /* already mapped */
pages = drm_gem_get_pages(&gt->gem);
pages = drm_gem_get_pages(obj);
if (IS_ERR(pages)) {
ret = PTR_ERR(pages);
goto err_mutex_unlock;
}
npages = gt->gem.size / PAGE_SIZE;
npages = obj->size / PAGE_SIZE;
set_pages_array_wc(pages, npages);
psb_gtt_insert_pages(dev_priv, &gt->resource, pages);
psb_gtt_insert_pages(dev_priv, &pobj->resource, pages);
psb_mmu_insert_pages(psb_mmu_get_default_pd(dev_priv->mmu), pages,
(gpu_base + gt->offset), npages, 0, 0,
(gpu_base + pobj->offset), npages, 0, 0,
PSB_MMU_CACHED_MEMORY);
gt->npage = npages;
gt->pages = pages;
pobj->npage = npages;
pobj->pages = pages;
out:
++gt->in_gart;
++pobj->in_gart;
mutex_unlock(&dev_priv->gtt_mutex);
return 0;
@ -64,31 +65,32 @@ err_mutex_unlock:
return ret;
}
void psb_gem_unpin(struct gtt_range *gt)
void psb_gem_unpin(struct psb_gem_object *pobj)
{
struct drm_device *dev = gt->gem.dev;
struct drm_gem_object *obj = &pobj->base;
struct drm_device *dev = obj->dev;
struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
u32 gpu_base = dev_priv->gtt.gatt_start;
mutex_lock(&dev_priv->gtt_mutex);
WARN_ON(!gt->in_gart);
WARN_ON(!pobj->in_gart);
--gt->in_gart;
--pobj->in_gart;
if (gt->in_gart || gt->stolen)
if (pobj->in_gart || pobj->stolen)
goto out;
psb_mmu_remove_pages(psb_mmu_get_default_pd(dev_priv->mmu),
(gpu_base + gt->offset), gt->npage, 0, 0);
psb_gtt_remove_pages(dev_priv, &gt->resource);
(gpu_base + pobj->offset), pobj->npage, 0, 0);
psb_gtt_remove_pages(dev_priv, &pobj->resource);
/* Reset caching flags */
set_pages_array_wb(gt->pages, gt->npage);
set_pages_array_wb(pobj->pages, pobj->npage);
drm_gem_put_pages(&gt->gem, gt->pages, true, false);
gt->pages = NULL;
gt->npage = 0;
drm_gem_put_pages(obj, pobj->pages, true, false);
pobj->pages = NULL;
pobj->npage = 0;
out:
mutex_unlock(&dev_priv->gtt_mutex);
@ -98,18 +100,18 @@ static vm_fault_t psb_gem_fault(struct vm_fault *vmf);
static void psb_gem_free_object(struct drm_gem_object *obj)
{
struct gtt_range *gt = to_gtt_range(obj);
struct psb_gem_object *pobj = to_psb_gem_object(obj);
drm_gem_object_release(obj);
/* Undo the mmap pin if we are destroying the object */
if (gt->mmapping)
psb_gem_unpin(gt);
if (pobj->mmapping)
psb_gem_unpin(pobj);
WARN_ON(gt->in_gart && !gt->stolen);
WARN_ON(pobj->in_gart && !pobj->stolen);
release_resource(&gt->resource);
kfree(gt);
release_resource(&pobj->resource);
kfree(pobj);
}
static const struct vm_operations_struct psb_gem_vm_ops = {
@ -123,31 +125,31 @@ static const struct drm_gem_object_funcs psb_gem_object_funcs = {
.vm_ops = &psb_gem_vm_ops,
};
struct gtt_range *
struct psb_gem_object *
psb_gem_create(struct drm_device *dev, u64 size, const char *name, bool stolen, u32 align)
{
struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
struct gtt_range *gt;
struct psb_gem_object *pobj;
struct drm_gem_object *obj;
int ret;
size = roundup(size, PAGE_SIZE);
gt = kzalloc(sizeof(*gt), GFP_KERNEL);
if (!gt)
pobj = kzalloc(sizeof(*pobj), GFP_KERNEL);
if (!pobj)
return ERR_PTR(-ENOMEM);
obj = &gt->gem;
obj = &pobj->base;
/* GTT resource */
ret = psb_gtt_allocate_resource(dev_priv, &gt->resource, name, size, align, stolen,
&gt->offset);
ret = psb_gtt_allocate_resource(dev_priv, &pobj->resource, name, size, align, stolen,
&pobj->offset);
if (ret)
goto err_kfree;
if (stolen) {
gt->stolen = true;
gt->in_gart = 1;
pobj->stolen = true;
pobj->in_gart = 1;
}
/* GEM object */
@ -165,12 +167,12 @@ psb_gem_create(struct drm_device *dev, u64 size, const char *name, bool stolen,
mapping_set_gfp_mask(obj->filp->f_mapping, GFP_KERNEL | __GFP_DMA32);
}
return gt;
return pobj;
err_release_resource:
release_resource(&gt->resource);
release_resource(&pobj->resource);
err_kfree:
kfree(gt);
kfree(pobj);
return ERR_PTR(ret);
}
@ -188,7 +190,7 @@ int psb_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
struct drm_mode_create_dumb *args)
{
size_t pitch, size;
struct gtt_range *gt;
struct psb_gem_object *pobj;
struct drm_gem_object *obj;
u32 handle;
int ret;
@ -201,10 +203,10 @@ int psb_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
if (!size)
return -EINVAL;
gt = psb_gem_create(dev, size, "gem", false, PAGE_SIZE);
if (IS_ERR(gt))
return PTR_ERR(gt);
obj = &gt->gem;
pobj = psb_gem_create(dev, size, "gem", false, PAGE_SIZE);
if (IS_ERR(pobj))
return PTR_ERR(pobj);
obj = &pobj->base;
ret = drm_gem_handle_create(file, obj, &handle);
if (ret)
@ -243,7 +245,7 @@ static vm_fault_t psb_gem_fault(struct vm_fault *vmf)
{
struct vm_area_struct *vma = vmf->vma;
struct drm_gem_object *obj;
struct gtt_range *r;
struct psb_gem_object *pobj;
int err;
vm_fault_t ret;
unsigned long pfn;
@ -255,7 +257,7 @@ static vm_fault_t psb_gem_fault(struct vm_fault *vmf)
dev = obj->dev;
dev_priv = to_drm_psb_private(dev);
r = to_gtt_range(obj);
pobj = to_psb_gem_object(obj);
/* Make sure we don't parallel update on a fault, nor move or remove
something from beneath our feet */
@ -263,14 +265,14 @@ static vm_fault_t psb_gem_fault(struct vm_fault *vmf)
/* For now the mmap pins the object and it stays pinned. As things
stand that will do us no harm */
if (r->mmapping == 0) {
err = psb_gem_pin(r);
if (pobj->mmapping == 0) {
err = psb_gem_pin(pobj);
if (err < 0) {
dev_err(dev->dev, "gma500: pin failed: %d\n", err);
ret = vmf_error(err);
goto fail;
}
r->mmapping = 1;
pobj->mmapping = 1;
}
/* Page relative to the VMA start - we must calculate this ourselves
@ -278,10 +280,10 @@ static vm_fault_t psb_gem_fault(struct vm_fault *vmf)
page_offset = (vmf->address - vma->vm_start) >> PAGE_SHIFT;
/* CPU view of the page, don't go via the GART for CPU writes */
if (r->stolen)
pfn = (dev_priv->stolen_base + r->offset) >> PAGE_SHIFT;
if (pobj->stolen)
pfn = (dev_priv->stolen_base + pobj->offset) >> PAGE_SHIFT;
else
pfn = page_to_pfn(r->pages[page_offset]);
pfn = page_to_pfn(pobj->pages[page_offset]);
ret = vmf_insert_pfn(vma, vmf->address, pfn);
fail:
mutex_unlock(&dev_priv->mmap_mutex);

View File

@ -8,14 +8,33 @@
#ifndef _GEM_H
#define _GEM_H
#include <linux/kernel.h>
#include <drm/drm_gem.h>
struct drm_device;
struct gtt_range *
struct psb_gem_object {
struct drm_gem_object base;
struct resource resource; /* GTT resource for our allocation */
u32 offset; /* GTT offset of our object */
int in_gart; /* Currently in the GART (ref ct) */
bool stolen; /* Backed from stolen RAM */
bool mmapping; /* Is mmappable */
struct page **pages; /* Backing pages if present */
int npage; /* Number of backing pages */
};
static inline struct psb_gem_object *to_psb_gem_object(struct drm_gem_object *obj)
{
return container_of(obj, struct psb_gem_object, base);
}
struct psb_gem_object *
psb_gem_create(struct drm_device *dev, u64 size, const char *name, bool stolen, u32 align);
int psb_gem_pin(struct gtt_range *gt);
void psb_gem_unpin(struct gtt_range *gt);
int psb_gem_pin(struct psb_gem_object *pobj);
void psb_gem_unpin(struct psb_gem_object *pobj);
#endif

View File

@ -55,7 +55,7 @@ int gma_pipe_set_base(struct drm_crtc *crtc, int x, int y,
struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
struct drm_framebuffer *fb = crtc->primary->fb;
struct gtt_range *gtt;
struct psb_gem_object *pobj;
int pipe = gma_crtc->pipe;
const struct psb_offset *map = &dev_priv->regmap[pipe];
unsigned long start, offset;
@ -71,14 +71,14 @@ int gma_pipe_set_base(struct drm_crtc *crtc, int x, int y,
goto gma_pipe_cleaner;
}
gtt = to_gtt_range(fb->obj[0]);
pobj = to_psb_gem_object(fb->obj[0]);
/* We are displaying this buffer, make sure it is actually loaded
into the GTT */
ret = psb_gem_pin(gtt);
ret = psb_gem_pin(pobj);
if (ret < 0)
goto gma_pipe_set_base_exit;
start = gtt->offset;
start = pobj->offset;
offset = y * fb->pitches[0] + x * fb->format->cpp[0];
REG_WRITE(map->stride, fb->pitches[0]);
@ -126,7 +126,7 @@ int gma_pipe_set_base(struct drm_crtc *crtc, int x, int y,
gma_pipe_cleaner:
/* If there was a previous display we can now unpin it */
if (old_fb)
psb_gem_unpin(to_gtt_range(old_fb->obj[0]));
psb_gem_unpin(to_psb_gem_object(old_fb->obj[0]));
gma_pipe_set_base_exit:
gma_power_end(dev);
@ -332,8 +332,8 @@ int gma_crtc_cursor_set(struct drm_crtc *crtc,
uint32_t base = (pipe == 0) ? CURABASE : CURBBASE;
uint32_t temp;
size_t addr = 0;
struct gtt_range *gt;
struct gtt_range *cursor_gt = gma_crtc->cursor_gt;
struct psb_gem_object *pobj;
struct psb_gem_object *cursor_pobj = gma_crtc->cursor_pobj;
struct drm_gem_object *obj;
void *tmp_dst, *tmp_src;
int ret = 0, i, cursor_pages;
@ -349,8 +349,8 @@ int gma_crtc_cursor_set(struct drm_crtc *crtc,
/* Unpin the old GEM object */
if (gma_crtc->cursor_obj) {
gt = to_gtt_range(gma_crtc->cursor_obj);
psb_gem_unpin(gt);
pobj = to_psb_gem_object(gma_crtc->cursor_obj);
psb_gem_unpin(pobj);
drm_gem_object_put(gma_crtc->cursor_obj);
gma_crtc->cursor_obj = NULL;
}
@ -375,40 +375,40 @@ int gma_crtc_cursor_set(struct drm_crtc *crtc,
goto unref_cursor;
}
gt = to_gtt_range(obj);
pobj = to_psb_gem_object(obj);
/* Pin the memory into the GTT */
ret = psb_gem_pin(gt);
ret = psb_gem_pin(pobj);
if (ret) {
dev_err(dev->dev, "Can not pin down handle 0x%x\n", handle);
goto unref_cursor;
}
if (dev_priv->ops->cursor_needs_phys) {
if (cursor_gt == NULL) {
if (!cursor_pobj) {
dev_err(dev->dev, "No hardware cursor mem available");
ret = -ENOMEM;
goto unref_cursor;
}
/* Prevent overflow */
if (gt->npage > 4)
if (pobj->npage > 4)
cursor_pages = 4;
else
cursor_pages = gt->npage;
cursor_pages = pobj->npage;
/* Copy the cursor to cursor mem */
tmp_dst = dev_priv->vram_addr + cursor_gt->offset;
tmp_dst = dev_priv->vram_addr + cursor_pobj->offset;
for (i = 0; i < cursor_pages; i++) {
tmp_src = kmap(gt->pages[i]);
tmp_src = kmap(pobj->pages[i]);
memcpy(tmp_dst, tmp_src, PAGE_SIZE);
kunmap(gt->pages[i]);
kunmap(pobj->pages[i]);
tmp_dst += PAGE_SIZE;
}
addr = gma_crtc->cursor_addr;
} else {
addr = gt->offset;
addr = pobj->offset;
gma_crtc->cursor_addr = addr;
}
@ -425,8 +425,8 @@ int gma_crtc_cursor_set(struct drm_crtc *crtc,
/* unpin the old bo */
if (gma_crtc->cursor_obj) {
gt = to_gtt_range(gma_crtc->cursor_obj);
psb_gem_unpin(gt);
pobj = to_psb_gem_object(gma_crtc->cursor_obj);
psb_gem_unpin(pobj);
drm_gem_object_put(gma_crtc->cursor_obj);
}
@ -483,14 +483,14 @@ void gma_crtc_commit(struct drm_crtc *crtc)
void gma_crtc_disable(struct drm_crtc *crtc)
{
struct gtt_range *gt;
struct psb_gem_object *pobj;
const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
if (crtc->primary->fb) {
gt = to_gtt_range(crtc->primary->fb->obj[0]);
psb_gem_unpin(gt);
pobj = to_psb_gem_object(crtc->primary->fb->obj[0]);
psb_gem_unpin(pobj);
}
}
@ -498,8 +498,8 @@ void gma_crtc_destroy(struct drm_crtc *crtc)
{
struct gma_crtc *gma_crtc = to_gma_crtc(crtc);
if (gma_crtc->cursor_gt)
drm_gem_object_put(&gma_crtc->cursor_gt->gem);
if (gma_crtc->cursor_pobj)
drm_gem_object_put(&gma_crtc->cursor_pobj->base);
kfree(gma_crtc->crtc_state);
drm_crtc_cleanup(crtc);

View File

@ -7,6 +7,7 @@
* Alan Cox <alan@linux.intel.com>
*/
#include "gem.h" /* TODO: for struct psb_gem_object, see psb_gtt_restore() */
#include "psb_drv.h"
@ -302,7 +303,7 @@ int psb_gtt_restore(struct drm_device *dev)
{
struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
struct resource *r = dev_priv->gtt_mem->child;
struct gtt_range *range;
struct psb_gem_object *pobj;
unsigned int restored = 0, total = 0, size = 0;
/* On resume, the gtt_mutex is already initialized */
@ -312,13 +313,13 @@ int psb_gtt_restore(struct drm_device *dev)
while (r != NULL) {
/*
* TODO: GTT restoration needs a refactoring, so that we don't have to touch
* struct gtt_range here. The type represents a GEM object and is not
* related to the GTT itself.
* struct psb_gem_object here. The type represents a GEM object and is
* not related to the GTT itself.
*/
range = container_of(r, struct gtt_range, resource);
if (range->pages) {
psb_gtt_insert_pages(dev_priv, &range->resource, range->pages);
size += range->resource.end - range->resource.start;
pobj = container_of(r, struct psb_gem_object, resource);
if (pobj->pages) {
psb_gtt_insert_pages(dev_priv, &pobj->resource, pobj->pages);
size += pobj->resource.end - pobj->resource.start;
restored++;
}
r = r->sibling;

View File

@ -28,21 +28,6 @@ struct psb_gtt {
/* Exported functions */
extern int psb_gtt_init(struct drm_device *dev, int resume);
extern void psb_gtt_takedown(struct drm_device *dev);
/* Each gtt_range describes an allocation in the GTT area */
struct gtt_range {
struct resource resource; /* Resource for our allocation */
u32 offset; /* GTT offset of our object */
struct drm_gem_object gem; /* GEM high level stuff */
int in_gart; /* Currently in the GART (ref ct) */
bool stolen; /* Backed from stolen RAM */
bool mmapping; /* Is mmappable */
struct page **pages; /* Backing pages if present */
int npage; /* Number of backing pages */
};
#define to_gtt_range(x) container_of(x, struct gtt_range, gem)
extern int psb_gtt_restore(struct drm_device *dev);
int psb_gtt_allocate_resource(struct drm_psb_private *pdev, struct resource *res,

View File

@ -10,6 +10,7 @@
#include <drm/drm_fourcc.h>
#include "framebuffer.h"
#include "gem.h"
#include "gma_display.h"
#include "power.h"
#include "psb_drv.h"
@ -608,7 +609,7 @@ static int oaktrail_pipe_set_base(struct drm_crtc *crtc,
if (!gma_power_begin(dev, true))
return 0;
start = to_gtt_range(fb->obj[0])->offset;
start = to_psb_gem_object(fb->obj[0])->offset;
offset = y * fb->pitches[0] + x * fb->format->cpp[0];
REG_WRITE(map->stride, fb->pitches[0]);

View File

@ -455,22 +455,21 @@ static void psb_intel_cursor_init(struct drm_device *dev,
struct drm_psb_private *dev_priv = to_drm_psb_private(dev);
u32 control[3] = { CURACNTR, CURBCNTR, CURCCNTR };
u32 base[3] = { CURABASE, CURBBASE, CURCBASE };
struct gtt_range *cursor_gt;
struct psb_gem_object *cursor_pobj;
if (dev_priv->ops->cursor_needs_phys) {
/* Allocate 4 pages of stolen mem for a hardware cursor. That
* is enough for the 64 x 64 ARGB cursors we support.
*/
cursor_gt = psb_gem_create(dev, 4 * PAGE_SIZE, "cursor", true, PAGE_SIZE);
if (IS_ERR(cursor_gt)) {
gma_crtc->cursor_gt = NULL;
cursor_pobj = psb_gem_create(dev, 4 * PAGE_SIZE, "cursor", true, PAGE_SIZE);
if (IS_ERR(cursor_pobj)) {
gma_crtc->cursor_pobj = NULL;
goto out;
}
gma_crtc->cursor_gt = cursor_gt;
gma_crtc->cursor_addr = dev_priv->stolen_base +
cursor_gt->offset;
gma_crtc->cursor_pobj = cursor_pobj;
gma_crtc->cursor_addr = dev_priv->stolen_base + cursor_pobj->offset;
} else {
gma_crtc->cursor_gt = NULL;
gma_crtc->cursor_pobj = NULL;
}
out:

View File

@ -140,7 +140,7 @@ struct gma_crtc {
int pipe;
int plane;
uint32_t cursor_addr;
struct gtt_range *cursor_gt;
struct psb_gem_object *cursor_pobj;
u8 lut_adj[256];
struct psb_intel_framebuffer *fbdev_fb;
/* a mode_set for fbdev users on this crtc */