Commit e4daebc7 authored by Rongrong Zou's avatar Rongrong Zou

drm/hisilicon/hibmc: Add video memory management

Hibmc have 32m video memory which can be accessed through PCIe by host,
we use ttm to manage these memory.
Signed-off-by: default avatarRongrong Zou <zourongrong@gmail.com>
Reviewed-by: default avatarSean Paul <seanpaul@chromium.org>
Reviewed-by: default avatarXinliang Liu <xinliang.liu@linaro.org>
Acked-by: default avatarSean Paul <seanpaul@chromium.org>
parent 5e0df3a0
ccflags-y := -Iinclude/drm ccflags-y := -Iinclude/drm
hibmc-drm-y := hibmc_drm_drv.o hibmc-drm-y := hibmc_drm_drv.o hibmc_ttm.o
obj-$(CONFIG_DRM_HISI_HIBMC) += hibmc-drm.o obj-$(CONFIG_DRM_HISI_HIBMC) += hibmc-drm.o
...@@ -28,6 +28,7 @@ static const struct file_operations hibmc_fops = { ...@@ -28,6 +28,7 @@ static const struct file_operations hibmc_fops = {
.release = drm_release, .release = drm_release,
.unlocked_ioctl = drm_ioctl, .unlocked_ioctl = drm_ioctl,
.compat_ioctl = drm_compat_ioctl, .compat_ioctl = drm_compat_ioctl,
.mmap = hibmc_mmap,
.poll = drm_poll, .poll = drm_poll,
.read = drm_read, .read = drm_read,
.llseek = no_llseek, .llseek = no_llseek,
...@@ -43,6 +44,7 @@ static void hibmc_disable_vblank(struct drm_device *dev, unsigned int pipe) ...@@ -43,6 +44,7 @@ static void hibmc_disable_vblank(struct drm_device *dev, unsigned int pipe)
} }
static struct drm_driver hibmc_driver = { static struct drm_driver hibmc_driver = {
.driver_features = DRIVER_GEM,
.fops = &hibmc_fops, .fops = &hibmc_fops,
.name = "hibmc", .name = "hibmc",
.date = "20160828", .date = "20160828",
...@@ -52,6 +54,10 @@ static struct drm_driver hibmc_driver = { ...@@ -52,6 +54,10 @@ static struct drm_driver hibmc_driver = {
.get_vblank_counter = drm_vblank_no_hw_counter, .get_vblank_counter = drm_vblank_no_hw_counter,
.enable_vblank = hibmc_enable_vblank, .enable_vblank = hibmc_enable_vblank,
.disable_vblank = hibmc_disable_vblank, .disable_vblank = hibmc_disable_vblank,
.gem_free_object_unlocked = hibmc_gem_free_object,
.dumb_create = hibmc_dumb_create,
.dumb_map_offset = hibmc_dumb_mmap_offset,
.dumb_destroy = drm_gem_dumb_destroy,
}; };
static int hibmc_pm_suspend(struct device *dev) static int hibmc_pm_suspend(struct device *dev)
...@@ -194,6 +200,10 @@ static int hibmc_hw_init(struct hibmc_drm_private *priv) ...@@ -194,6 +200,10 @@ static int hibmc_hw_init(struct hibmc_drm_private *priv)
static int hibmc_unload(struct drm_device *dev) static int hibmc_unload(struct drm_device *dev)
{ {
struct hibmc_drm_private *priv = dev->dev_private;
hibmc_mm_fini(priv);
dev->dev_private = NULL;
return 0; return 0;
} }
...@@ -214,6 +224,10 @@ static int hibmc_load(struct drm_device *dev) ...@@ -214,6 +224,10 @@ static int hibmc_load(struct drm_device *dev)
if (ret) if (ret)
goto err; goto err;
ret = hibmc_mm_init(priv);
if (ret)
goto err;
return 0; return 0;
err: err:
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#define HIBMC_DRM_DRV_H #define HIBMC_DRM_DRV_H
#include <drm/drmP.h> #include <drm/drmP.h>
#include <drm/drm_gem.h>
#include <drm/ttm/ttm_bo_driver.h>
struct hibmc_drm_private { struct hibmc_drm_private {
/* hw */ /* hw */
...@@ -31,11 +33,50 @@ struct hibmc_drm_private { ...@@ -31,11 +33,50 @@ struct hibmc_drm_private {
/* drm */ /* drm */
struct drm_device *dev; struct drm_device *dev;
/* ttm */
struct drm_global_reference mem_global_ref;
struct ttm_bo_global_ref bo_global_ref;
struct ttm_bo_device bdev;
bool initialized;
bool mm_inited;
};
struct hibmc_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;
}; };
static inline struct hibmc_bo *hibmc_bo(struct ttm_buffer_object *bo)
{
return container_of(bo, struct hibmc_bo, bo);
}
static inline struct hibmc_bo *gem_to_hibmc_bo(struct drm_gem_object *gem)
{
return container_of(gem, struct hibmc_bo, gem);
}
void hibmc_set_power_mode(struct hibmc_drm_private *priv, void hibmc_set_power_mode(struct hibmc_drm_private *priv,
unsigned int power_mode); unsigned int power_mode);
void hibmc_set_current_gate(struct hibmc_drm_private *priv, void hibmc_set_current_gate(struct hibmc_drm_private *priv,
unsigned int gate); unsigned int gate);
int hibmc_gem_create(struct drm_device *dev, u32 size, bool iskernel,
struct drm_gem_object **obj);
int hibmc_mm_init(struct hibmc_drm_private *hibmc);
void hibmc_mm_fini(struct hibmc_drm_private *hibmc);
int hibmc_bo_pin(struct hibmc_bo *bo, u32 pl_flag, u64 *gpu_addr);
int hibmc_bo_unpin(struct hibmc_bo *bo);
void hibmc_gem_free_object(struct drm_gem_object *obj);
int hibmc_dumb_create(struct drm_file *file, struct drm_device *dev,
struct drm_mode_create_dumb *args);
int hibmc_dumb_mmap_offset(struct drm_file *file, struct drm_device *dev,
u32 handle, u64 *offset);
int hibmc_mmap(struct file *filp, struct vm_area_struct *vma);
#endif #endif
This diff is collapsed.
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