cirrus_drv.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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_fb_helper.h>
  15. #include <drm/ttm/ttm_bo_api.h>
  16. #include <drm/ttm/ttm_bo_driver.h>
  17. #include <drm/ttm/ttm_placement.h>
  18. #include <drm/ttm/ttm_memory.h>
  19. #include <drm/ttm/ttm_module.h>
  20. #define DRIVER_AUTHOR "Matthew Garrett"
  21. #define DRIVER_NAME "cirrus"
  22. #define DRIVER_DESC "qemu Cirrus emulation"
  23. #define DRIVER_DATE "20110418"
  24. #define DRIVER_MAJOR 1
  25. #define DRIVER_MINOR 0
  26. #define DRIVER_PATCHLEVEL 0
  27. #define CIRRUSFB_CONN_LIMIT 1
  28. #define RREG8(reg) ioread8(((void __iomem *)cdev->rmmio) + (reg))
  29. #define WREG8(reg, v) iowrite8(v, ((void __iomem *)cdev->rmmio) + (reg))
  30. #define RREG32(reg) ioread32(((void __iomem *)cdev->rmmio) + (reg))
  31. #define WREG32(reg, v) iowrite32(v, ((void __iomem *)cdev->rmmio) + (reg))
  32. #define SEQ_INDEX 4
  33. #define SEQ_DATA 5
  34. #define WREG_SEQ(reg, v) \
  35. do { \
  36. WREG8(SEQ_INDEX, reg); \
  37. WREG8(SEQ_DATA, v); \
  38. } while (0) \
  39. #define CRT_INDEX 0x14
  40. #define CRT_DATA 0x15
  41. #define WREG_CRT(reg, v) \
  42. do { \
  43. WREG8(CRT_INDEX, reg); \
  44. WREG8(CRT_DATA, v); \
  45. } while (0) \
  46. #define GFX_INDEX 0xe
  47. #define GFX_DATA 0xf
  48. #define WREG_GFX(reg, v) \
  49. do { \
  50. WREG8(GFX_INDEX, reg); \
  51. WREG8(GFX_DATA, v); \
  52. } while (0) \
  53. /*
  54. * Cirrus has a "hidden" DAC register that can be accessed by writing to
  55. * the pixel mask register to reset the state, then reading from the register
  56. * four times. The next write will then pass to the DAC
  57. */
  58. #define VGA_DAC_MASK 0x6
  59. #define WREG_HDR(v) \
  60. do { \
  61. RREG8(VGA_DAC_MASK); \
  62. RREG8(VGA_DAC_MASK); \
  63. RREG8(VGA_DAC_MASK); \
  64. RREG8(VGA_DAC_MASK); \
  65. WREG8(VGA_DAC_MASK, v); \
  66. } while (0) \
  67. #define CIRRUS_MAX_FB_HEIGHT 4096
  68. #define CIRRUS_MAX_FB_WIDTH 4096
  69. #define CIRRUS_DPMS_CLEARED (-1)
  70. #define to_cirrus_crtc(x) container_of(x, struct cirrus_crtc, base)
  71. #define to_cirrus_encoder(x) container_of(x, struct cirrus_encoder, base)
  72. #define to_cirrus_framebuffer(x) container_of(x, struct cirrus_framebuffer, base)
  73. struct cirrus_crtc {
  74. struct drm_crtc base;
  75. u8 lut_r[256], lut_g[256], lut_b[256];
  76. int last_dpms;
  77. bool enabled;
  78. };
  79. struct cirrus_fbdev;
  80. struct cirrus_mode_info {
  81. bool mode_config_initialized;
  82. struct cirrus_crtc *crtc;
  83. /* pointer to fbdev info structure */
  84. struct cirrus_fbdev *gfbdev;
  85. };
  86. struct cirrus_encoder {
  87. struct drm_encoder base;
  88. int last_dpms;
  89. };
  90. struct cirrus_connector {
  91. struct drm_connector base;
  92. };
  93. struct cirrus_framebuffer {
  94. struct drm_framebuffer base;
  95. struct drm_gem_object *obj;
  96. };
  97. struct cirrus_mc {
  98. resource_size_t vram_size;
  99. resource_size_t vram_base;
  100. };
  101. struct cirrus_device {
  102. struct drm_device *dev;
  103. unsigned long flags;
  104. resource_size_t rmmio_base;
  105. resource_size_t rmmio_size;
  106. void __iomem *rmmio;
  107. struct cirrus_mc mc;
  108. struct cirrus_mode_info mode_info;
  109. int num_crtc;
  110. int fb_mtrr;
  111. struct {
  112. struct drm_global_reference mem_global_ref;
  113. struct ttm_bo_global_ref bo_global_ref;
  114. struct ttm_bo_device bdev;
  115. } ttm;
  116. bool mm_inited;
  117. };
  118. struct cirrus_fbdev {
  119. struct drm_fb_helper helper;
  120. struct cirrus_framebuffer gfb;
  121. struct list_head fbdev_list;
  122. void *sysram;
  123. int size;
  124. };
  125. struct cirrus_bo {
  126. struct ttm_buffer_object bo;
  127. struct ttm_placement placement;
  128. struct ttm_bo_kmap_obj kmap;
  129. struct drm_gem_object gem;
  130. u32 placements[3];
  131. int pin_count;
  132. };
  133. #define gem_to_cirrus_bo(gobj) container_of((gobj), struct cirrus_bo, gem)
  134. static inline struct cirrus_bo *
  135. cirrus_bo(struct ttm_buffer_object *bo)
  136. {
  137. return container_of(bo, struct cirrus_bo, bo);
  138. }
  139. #define to_cirrus_obj(x) container_of(x, struct cirrus_gem_object, base)
  140. #define DRM_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT)
  141. /* cirrus_mode.c */
  142. void cirrus_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
  143. u16 blue, int regno);
  144. void cirrus_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
  145. u16 *blue, int regno);
  146. /* cirrus_main.c */
  147. int cirrus_device_init(struct cirrus_device *cdev,
  148. struct drm_device *ddev,
  149. struct pci_dev *pdev,
  150. uint32_t flags);
  151. void cirrus_device_fini(struct cirrus_device *cdev);
  152. int cirrus_gem_init_object(struct drm_gem_object *obj);
  153. void cirrus_gem_free_object(struct drm_gem_object *obj);
  154. int cirrus_dumb_mmap_offset(struct drm_file *file,
  155. struct drm_device *dev,
  156. uint32_t handle,
  157. uint64_t *offset);
  158. int cirrus_gem_create(struct drm_device *dev,
  159. u32 size, bool iskernel,
  160. struct drm_gem_object **obj);
  161. int cirrus_dumb_create(struct drm_file *file,
  162. struct drm_device *dev,
  163. struct drm_mode_create_dumb *args);
  164. int cirrus_dumb_destroy(struct drm_file *file,
  165. struct drm_device *dev,
  166. uint32_t handle);
  167. int cirrus_framebuffer_init(struct drm_device *dev,
  168. struct cirrus_framebuffer *gfb,
  169. struct drm_mode_fb_cmd2 *mode_cmd,
  170. struct drm_gem_object *obj);
  171. /* cirrus_display.c */
  172. int cirrus_modeset_init(struct cirrus_device *cdev);
  173. void cirrus_modeset_fini(struct cirrus_device *cdev);
  174. /* cirrus_fbdev.c */
  175. int cirrus_fbdev_init(struct cirrus_device *cdev);
  176. void cirrus_fbdev_fini(struct cirrus_device *cdev);
  177. /* cirrus_irq.c */
  178. void cirrus_driver_irq_preinstall(struct drm_device *dev);
  179. int cirrus_driver_irq_postinstall(struct drm_device *dev);
  180. void cirrus_driver_irq_uninstall(struct drm_device *dev);
  181. irqreturn_t cirrus_driver_irq_handler(DRM_IRQ_ARGS);
  182. /* cirrus_kms.c */
  183. int cirrus_driver_load(struct drm_device *dev, unsigned long flags);
  184. int cirrus_driver_unload(struct drm_device *dev);
  185. extern struct drm_ioctl_desc cirrus_ioctls[];
  186. extern int cirrus_max_ioctl;
  187. int cirrus_mm_init(struct cirrus_device *cirrus);
  188. void cirrus_mm_fini(struct cirrus_device *cirrus);
  189. void cirrus_ttm_placement(struct cirrus_bo *bo, int domain);
  190. int cirrus_bo_create(struct drm_device *dev, int size, int align,
  191. uint32_t flags, struct cirrus_bo **pcirrusbo);
  192. int cirrus_mmap(struct file *filp, struct vm_area_struct *vma);
  193. int cirrus_bo_reserve(struct cirrus_bo *bo, bool no_wait);
  194. void cirrus_bo_unreserve(struct cirrus_bo *bo);
  195. int cirrus_bo_push_sysram(struct cirrus_bo *bo);
  196. int cirrus_bo_pin(struct cirrus_bo *bo, u32 pl_flag, u64 *gpu_addr);
  197. #endif /* __CIRRUS_DRV_H__ */