1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* Hisilicon Hibmc SoC drm driver 3 * 4 * Based on the bochs drm driver. 5 * 6 * Copyright (c) 2016 Huawei Limited. 7 * 8 * Author: 9 * Rongrong Zou <zourongrong@huawei.com> 10 * Rongrong Zou <zourongrong@gmail.com> 11 * Jianhua Li <lijianhua@huawei.com> 12 */ 13 14 #ifndef HIBMC_DRM_DRV_H 15 #define HIBMC_DRM_DRV_H 16 17 #include <drm/drmP.h> 18 #include <drm/drm_atomic.h> 19 #include <drm/drm_fb_helper.h> 20 #include <drm/drm_gem.h> 21 #include <drm/ttm/ttm_bo_driver.h> 22 23 struct hibmc_framebuffer { 24 struct drm_framebuffer fb; 25 struct drm_gem_object *obj; 26 }; 27 28 struct hibmc_fbdev { 29 struct drm_fb_helper helper; /* must be first */ 30 struct hibmc_framebuffer *fb; 31 int size; 32 }; 33 34 struct hibmc_drm_private { 35 /* hw */ 36 void __iomem *mmio; 37 void __iomem *fb_map; 38 unsigned long fb_base; 39 unsigned long fb_size; 40 bool msi_enabled; 41 42 /* drm */ 43 struct drm_device *dev; 44 bool mode_config_initialized; 45 46 /* ttm */ 47 struct ttm_bo_device bdev; 48 bool initialized; 49 50 /* fbdev */ 51 struct hibmc_fbdev *fbdev; 52 bool mm_inited; 53 }; 54 55 #define to_hibmc_framebuffer(x) container_of(x, struct hibmc_framebuffer, fb) 56 57 struct hibmc_bo { 58 struct ttm_buffer_object bo; 59 struct ttm_placement placement; 60 struct ttm_bo_kmap_obj kmap; 61 struct drm_gem_object gem; 62 struct ttm_place placements[3]; 63 int pin_count; 64 }; 65 66 static inline struct hibmc_bo *hibmc_bo(struct ttm_buffer_object *bo) 67 { 68 return container_of(bo, struct hibmc_bo, bo); 69 } 70 71 static inline struct hibmc_bo *gem_to_hibmc_bo(struct drm_gem_object *gem) 72 { 73 return container_of(gem, struct hibmc_bo, gem); 74 } 75 76 void hibmc_set_power_mode(struct hibmc_drm_private *priv, 77 unsigned int power_mode); 78 void hibmc_set_current_gate(struct hibmc_drm_private *priv, 79 unsigned int gate); 80 81 int hibmc_de_init(struct hibmc_drm_private *priv); 82 int hibmc_vdac_init(struct hibmc_drm_private *priv); 83 int hibmc_fbdev_init(struct hibmc_drm_private *priv); 84 void hibmc_fbdev_fini(struct hibmc_drm_private *priv); 85 86 int hibmc_gem_create(struct drm_device *dev, u32 size, bool iskernel, 87 struct drm_gem_object **obj); 88 struct hibmc_framebuffer * 89 hibmc_framebuffer_init(struct drm_device *dev, 90 const struct drm_mode_fb_cmd2 *mode_cmd, 91 struct drm_gem_object *obj); 92 93 int hibmc_mm_init(struct hibmc_drm_private *hibmc); 94 void hibmc_mm_fini(struct hibmc_drm_private *hibmc); 95 int hibmc_bo_pin(struct hibmc_bo *bo, u32 pl_flag, u64 *gpu_addr); 96 int hibmc_bo_unpin(struct hibmc_bo *bo); 97 void hibmc_gem_free_object(struct drm_gem_object *obj); 98 int hibmc_dumb_create(struct drm_file *file, struct drm_device *dev, 99 struct drm_mode_create_dumb *args); 100 int hibmc_dumb_mmap_offset(struct drm_file *file, struct drm_device *dev, 101 u32 handle, u64 *offset); 102 int hibmc_mmap(struct file *filp, struct vm_area_struct *vma); 103 104 extern const struct drm_mode_config_funcs hibmc_mode_funcs; 105 106 #endif 107