cirrus_drv.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*
  2. * Copyright 2012 Red Hat
  3. *
  4. * This file is subject to the terms and conditions of the GNU General
  5. * Public License version 2. See the file COPYING in the main
  6. * directory of this archive for more details.
  7. *
  8. * Authors: Matthew Garrett
  9. * Dave Airlie
  10. */
  11. #ifndef __CIRRUS_DRV_H__
  12. #define __CIRRUS_DRV_H__
  13. #include <video/vga.h>
  14. #include <drm/drm_encoder.h>
  15. #include <drm/drm_fb_helper.h>
  16. #include <drm/ttm/ttm_bo_api.h>
  17. #include <drm/ttm/ttm_bo_driver.h>
  18. #include <drm/ttm/ttm_placement.h>
  19. #include <drm/ttm/ttm_memory.h>
  20. #include <drm/ttm/ttm_module.h>
  21. #include <drm/drm_gem.h>
  22. #define DRIVER_AUTHOR "Matthew Garrett"
  23. #define DRIVER_NAME "cirrus"
  24. #define DRIVER_DESC "qemu Cirrus emulation"
  25. #define DRIVER_DATE "20110418"
  26. #define DRIVER_MAJOR 1
  27. #define DRIVER_MINOR 0
  28. #define DRIVER_PATCHLEVEL 0
  29. #define CIRRUSFB_CONN_LIMIT 1
  30. #define RREG8(reg) ioread8(((void __iomem *)cdev->rmmio) + (reg))
  31. #define WREG8(reg, v) iowrite8(v, ((void __iomem *)cdev->rmmio) + (reg))
  32. #define RREG32(reg) ioread32(((void __iomem *)cdev->rmmio) + (reg))
  33. #define WREG32(reg, v) iowrite32(v, ((void __iomem *)cdev->rmmio) + (reg))
  34. #define SEQ_INDEX 4
  35. #define SEQ_DATA 5
  36. #define WREG_SEQ(reg, v) \
  37. do { \
  38. WREG8(SEQ_INDEX, reg); \
  39. WREG8(SEQ_DATA, v); \
  40. } while (0) \
  41. #define CRT_INDEX 0x14
  42. #define CRT_DATA 0x15
  43. #define WREG_CRT(reg, v) \
  44. do { \
  45. WREG8(CRT_INDEX, reg); \
  46. WREG8(CRT_DATA, v); \
  47. } while (0) \
  48. #define GFX_INDEX 0xe
  49. #define GFX_DATA 0xf
  50. #define WREG_GFX(reg, v) \
  51. do { \
  52. WREG8(GFX_INDEX, reg); \
  53. WREG8(GFX_DATA, v); \
  54. } while (0) \
  55. /*
  56. * Cirrus has a "hidden" DAC register that can be accessed by writing to
  57. * the pixel mask register to reset the state, then reading from the register
  58. * four times. The next write will then pass to the DAC
  59. */
  60. #define VGA_DAC_MASK 0x6
  61. #define WREG_HDR(v) \
  62. do { \
  63. RREG8(VGA_DAC_MASK); \
  64. RREG8(VGA_DAC_MASK); \
  65. RREG8(VGA_DAC_MASK); \
  66. RREG8(VGA_DAC_MASK); \
  67. WREG8(VGA_DAC_MASK, v); \
  68. } while (0) \
  69. #define CIRRUS_MAX_FB_HEIGHT 4096
  70. #define CIRRUS_MAX_FB_WIDTH 4096
  71. #define CIRRUS_DPMS_CLEARED (-1)
  72. #define to_cirrus_crtc(x) container_of(x, struct cirrus_crtc, base)
  73. #define to_cirrus_encoder(x) container_of(x, struct cirrus_encoder, base)
  74. #define to_cirrus_framebuffer(x) container_of(x, struct cirrus_framebuffer, base)
  75. struct cirrus_crtc {
  76. struct drm_crtc base;
  77. int last_dpms;
  78. bool enabled;
  79. };
  80. struct cirrus_fbdev;
  81. struct cirrus_mode_info {
  82. bool mode_config_initialized;
  83. struct cirrus_crtc *crtc;
  84. /* pointer to fbdev info structure */
  85. struct cirrus_fbdev *gfbdev;
  86. };
  87. struct cirrus_encoder {
  88. struct drm_encoder base;
  89. int last_dpms;
  90. };
  91. struct cirrus_connector {
  92. struct drm_connector base;
  93. };
  94. struct cirrus_framebuffer {
  95. struct drm_framebuffer base;
  96. struct drm_gem_object *obj;
  97. };
  98. struct cirrus_mc {
  99. resource_size_t vram_size;
  100. resource_size_t vram_base;
  101. };
  102. struct cirrus_device {
  103. struct drm_device *dev;
  104. unsigned long flags;
  105. resource_size_t rmmio_base;
  106. resource_size_t rmmio_size;
  107. void __iomem *rmmio;
  108. struct cirrus_mc mc;
  109. struct cirrus_mode_info mode_info;
  110. int num_crtc;
  111. int fb_mtrr;
  112. struct {
  113. struct drm_global_reference mem_global_ref;
  114. struct ttm_bo_global_ref bo_global_ref;
  115. struct ttm_bo_device bdev;
  116. } ttm;
  117. bool mm_inited;
  118. };
  119. struct cirrus_fbdev {
  120. struct drm_fb_helper helper;
  121. struct cirrus_framebuffer gfb;
  122. void *sysram;
  123. int size;
  124. int x1, y1, x2, y2; /* dirty rect */
  125. spinlock_t dirty_lock;
  126. };
  127. struct cirrus_bo {
  128. struct ttm_buffer_object bo;
  129. struct ttm_placement placement;
  130. struct ttm_bo_kmap_obj kmap;
  131. struct drm_gem_object gem;
  132. struct ttm_place placements[3];
  133. int pin_count;
  134. };
  135. #define gem_to_cirrus_bo(gobj) container_of((gobj), struct cirrus_bo, gem)
  136. static inline struct cirrus_bo *
  137. cirrus_bo(struct ttm_buffer_object *bo)
  138. {
  139. return container_of(bo, struct cirrus_bo, bo);
  140. }
  141. #define to_cirrus_obj(x) container_of(x, struct cirrus_gem_object, base)
  142. #define DRM_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT)
  143. /* cirrus_main.c */
  144. int cirrus_device_init(struct cirrus_device *cdev,
  145. struct drm_device *ddev,
  146. struct pci_dev *pdev,
  147. uint32_t flags);
  148. void cirrus_device_fini(struct cirrus_device *cdev);
  149. void cirrus_gem_free_object(struct drm_gem_object *obj);
  150. int cirrus_dumb_mmap_offset(struct drm_file *file,
  151. struct drm_device *dev,
  152. uint32_t handle,
  153. uint64_t *offset);
  154. int cirrus_gem_create(struct drm_device *dev,
  155. u32 size, bool iskernel,
  156. struct drm_gem_object **obj);
  157. int cirrus_dumb_create(struct drm_file *file,
  158. struct drm_device *dev,
  159. struct drm_mode_create_dumb *args);
  160. int cirrus_framebuffer_init(struct drm_device *dev,
  161. struct cirrus_framebuffer *gfb,
  162. const struct drm_mode_fb_cmd2 *mode_cmd,
  163. struct drm_gem_object *obj);
  164. bool cirrus_check_framebuffer(struct cirrus_device *cdev, int width, int height,
  165. int bpp, int pitch);
  166. /* cirrus_display.c */
  167. int cirrus_modeset_init(struct cirrus_device *cdev);
  168. void cirrus_modeset_fini(struct cirrus_device *cdev);
  169. /* cirrus_fbdev.c */
  170. int cirrus_fbdev_init(struct cirrus_device *cdev);
  171. void cirrus_fbdev_fini(struct cirrus_device *cdev);
  172. /* cirrus_irq.c */
  173. void cirrus_driver_irq_preinstall(struct drm_device *dev);
  174. int cirrus_driver_irq_postinstall(struct drm_device *dev);
  175. void cirrus_driver_irq_uninstall(struct drm_device *dev);
  176. irqreturn_t cirrus_driver_irq_handler(int irq, void *arg);
  177. /* cirrus_kms.c */
  178. int cirrus_driver_load(struct drm_device *dev, unsigned long flags);
  179. void cirrus_driver_unload(struct drm_device *dev);
  180. extern struct drm_ioctl_desc cirrus_ioctls[];
  181. extern int cirrus_max_ioctl;
  182. int cirrus_mm_init(struct cirrus_device *cirrus);
  183. void cirrus_mm_fini(struct cirrus_device *cirrus);
  184. void cirrus_ttm_placement(struct cirrus_bo *bo, int domain);
  185. int cirrus_bo_create(struct drm_device *dev, int size, int align,
  186. uint32_t flags, struct cirrus_bo **pcirrusbo);
  187. int cirrus_mmap(struct file *filp, struct vm_area_struct *vma);
  188. static inline int cirrus_bo_reserve(struct cirrus_bo *bo, bool no_wait)
  189. {
  190. int ret;
  191. ret = ttm_bo_reserve(&bo->bo, true, no_wait, NULL);
  192. if (ret) {
  193. if (ret != -ERESTARTSYS && ret != -EBUSY)
  194. DRM_ERROR("reserve failed %p\n", bo);
  195. return ret;
  196. }
  197. return 0;
  198. }
  199. static inline void cirrus_bo_unreserve(struct cirrus_bo *bo)
  200. {
  201. ttm_bo_unreserve(&bo->bo);
  202. }
  203. int cirrus_bo_push_sysram(struct cirrus_bo *bo);
  204. int cirrus_bo_pin(struct cirrus_bo *bo, u32 pl_flag, u64 *gpu_addr);
  205. extern int cirrus_bpp;
  206. #endif /* __CIRRUS_DRV_H__ */