cirrus_drv.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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 "ttm/ttm_bo_api.h"
  16. #include "ttm/ttm_bo_driver.h"
  17. #include "ttm/ttm_placement.h"
  18. #include "ttm/ttm_memory.h"
  19. #include "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. atomic_t validate_sequence;
  116. } ttm;
  117. bool mm_inited;
  118. };
  119. struct cirrus_fbdev {
  120. struct drm_fb_helper helper;
  121. struct cirrus_framebuffer gfb;
  122. struct list_head fbdev_list;
  123. void *sysram;
  124. int size;
  125. };
  126. struct cirrus_bo {
  127. struct ttm_buffer_object bo;
  128. struct ttm_placement placement;
  129. struct ttm_bo_kmap_obj kmap;
  130. struct drm_gem_object gem;
  131. u32 placements[3];
  132. int pin_count;
  133. };
  134. #define gem_to_cirrus_bo(gobj) container_of((gobj), struct cirrus_bo, gem)
  135. static inline struct cirrus_bo *
  136. cirrus_bo(struct ttm_buffer_object *bo)
  137. {
  138. return container_of(bo, struct cirrus_bo, bo);
  139. }
  140. #define to_cirrus_obj(x) container_of(x, struct cirrus_gem_object, base)
  141. #define DRM_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT)
  142. /* cirrus_mode.c */
  143. void cirrus_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
  144. u16 blue, int regno);
  145. void cirrus_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
  146. u16 *blue, int regno);
  147. /* cirrus_main.c */
  148. int cirrus_device_init(struct cirrus_device *cdev,
  149. struct drm_device *ddev,
  150. struct pci_dev *pdev,
  151. uint32_t flags);
  152. void cirrus_device_fini(struct cirrus_device *cdev);
  153. int cirrus_gem_init_object(struct drm_gem_object *obj);
  154. void cirrus_gem_free_object(struct drm_gem_object *obj);
  155. int cirrus_dumb_mmap_offset(struct drm_file *file,
  156. struct drm_device *dev,
  157. uint32_t handle,
  158. uint64_t *offset);
  159. int cirrus_gem_create(struct drm_device *dev,
  160. u32 size, bool iskernel,
  161. struct drm_gem_object **obj);
  162. int cirrus_dumb_create(struct drm_file *file,
  163. struct drm_device *dev,
  164. struct drm_mode_create_dumb *args);
  165. int cirrus_dumb_destroy(struct drm_file *file,
  166. struct drm_device *dev,
  167. uint32_t handle);
  168. int cirrus_framebuffer_init(struct drm_device *dev,
  169. struct cirrus_framebuffer *gfb,
  170. struct drm_mode_fb_cmd2 *mode_cmd,
  171. struct drm_gem_object *obj);
  172. /* cirrus_display.c */
  173. int cirrus_modeset_init(struct cirrus_device *cdev);
  174. void cirrus_modeset_fini(struct cirrus_device *cdev);
  175. /* cirrus_fbdev.c */
  176. int cirrus_fbdev_init(struct cirrus_device *cdev);
  177. void cirrus_fbdev_fini(struct cirrus_device *cdev);
  178. /* cirrus_irq.c */
  179. void cirrus_driver_irq_preinstall(struct drm_device *dev);
  180. int cirrus_driver_irq_postinstall(struct drm_device *dev);
  181. void cirrus_driver_irq_uninstall(struct drm_device *dev);
  182. irqreturn_t cirrus_driver_irq_handler(DRM_IRQ_ARGS);
  183. /* cirrus_kms.c */
  184. int cirrus_driver_load(struct drm_device *dev, unsigned long flags);
  185. int cirrus_driver_unload(struct drm_device *dev);
  186. extern struct drm_ioctl_desc cirrus_ioctls[];
  187. extern int cirrus_max_ioctl;
  188. int cirrus_mm_init(struct cirrus_device *cirrus);
  189. void cirrus_mm_fini(struct cirrus_device *cirrus);
  190. void cirrus_ttm_placement(struct cirrus_bo *bo, int domain);
  191. int cirrus_bo_create(struct drm_device *dev, int size, int align,
  192. uint32_t flags, struct cirrus_bo **pcirrusbo);
  193. int cirrus_mmap(struct file *filp, struct vm_area_struct *vma);
  194. int cirrus_bo_reserve(struct cirrus_bo *bo, bool no_wait);
  195. void cirrus_bo_unreserve(struct cirrus_bo *bo);
  196. int cirrus_bo_push_sysram(struct cirrus_bo *bo);
  197. int cirrus_bo_pin(struct cirrus_bo *bo, u32 pl_flag, u64 *gpu_addr);
  198. #endif /* __CIRRUS_DRV_H__ */