bochs.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #include <linux/io.h>
  2. #include <linux/console.h>
  3. #include <drm/drmP.h>
  4. #include <drm/drm_crtc.h>
  5. #include <drm/drm_crtc_helper.h>
  6. #include <drm/drm_fb_helper.h>
  7. #include <drm/drm_gem.h>
  8. #include <ttm/ttm_bo_driver.h>
  9. #include <ttm/ttm_page_alloc.h>
  10. /* ---------------------------------------------------------------------- */
  11. #define VBE_DISPI_IOPORT_INDEX 0x01CE
  12. #define VBE_DISPI_IOPORT_DATA 0x01CF
  13. #define VBE_DISPI_INDEX_ID 0x0
  14. #define VBE_DISPI_INDEX_XRES 0x1
  15. #define VBE_DISPI_INDEX_YRES 0x2
  16. #define VBE_DISPI_INDEX_BPP 0x3
  17. #define VBE_DISPI_INDEX_ENABLE 0x4
  18. #define VBE_DISPI_INDEX_BANK 0x5
  19. #define VBE_DISPI_INDEX_VIRT_WIDTH 0x6
  20. #define VBE_DISPI_INDEX_VIRT_HEIGHT 0x7
  21. #define VBE_DISPI_INDEX_X_OFFSET 0x8
  22. #define VBE_DISPI_INDEX_Y_OFFSET 0x9
  23. #define VBE_DISPI_INDEX_VIDEO_MEMORY_64K 0xa
  24. #define VBE_DISPI_ID0 0xB0C0
  25. #define VBE_DISPI_ID1 0xB0C1
  26. #define VBE_DISPI_ID2 0xB0C2
  27. #define VBE_DISPI_ID3 0xB0C3
  28. #define VBE_DISPI_ID4 0xB0C4
  29. #define VBE_DISPI_ID5 0xB0C5
  30. #define VBE_DISPI_DISABLED 0x00
  31. #define VBE_DISPI_ENABLED 0x01
  32. #define VBE_DISPI_GETCAPS 0x02
  33. #define VBE_DISPI_8BIT_DAC 0x20
  34. #define VBE_DISPI_LFB_ENABLED 0x40
  35. #define VBE_DISPI_NOCLEARMEM 0x80
  36. /* ---------------------------------------------------------------------- */
  37. enum bochs_types {
  38. BOCHS_QEMU_STDVGA,
  39. BOCHS_UNKNOWN,
  40. };
  41. struct bochs_framebuffer {
  42. struct drm_framebuffer base;
  43. struct drm_gem_object *obj;
  44. };
  45. struct bochs_device {
  46. /* hw */
  47. void __iomem *mmio;
  48. int ioports;
  49. void __iomem *fb_map;
  50. unsigned long fb_base;
  51. unsigned long fb_size;
  52. /* mode */
  53. u16 xres;
  54. u16 yres;
  55. u16 yres_virtual;
  56. u32 stride;
  57. u32 bpp;
  58. /* drm */
  59. struct drm_device *dev;
  60. struct drm_crtc crtc;
  61. struct drm_encoder encoder;
  62. struct drm_connector connector;
  63. bool mode_config_initialized;
  64. /* ttm */
  65. struct {
  66. struct drm_global_reference mem_global_ref;
  67. struct ttm_bo_global_ref bo_global_ref;
  68. struct ttm_bo_device bdev;
  69. bool initialized;
  70. } ttm;
  71. /* fbdev */
  72. struct {
  73. struct bochs_framebuffer gfb;
  74. struct drm_fb_helper helper;
  75. int size;
  76. bool initialized;
  77. } fb;
  78. };
  79. #define to_bochs_framebuffer(x) container_of(x, struct bochs_framebuffer, base)
  80. struct bochs_bo {
  81. struct ttm_buffer_object bo;
  82. struct ttm_placement placement;
  83. struct ttm_bo_kmap_obj kmap;
  84. struct drm_gem_object gem;
  85. struct ttm_place placements[3];
  86. int pin_count;
  87. };
  88. static inline struct bochs_bo *bochs_bo(struct ttm_buffer_object *bo)
  89. {
  90. return container_of(bo, struct bochs_bo, bo);
  91. }
  92. static inline struct bochs_bo *gem_to_bochs_bo(struct drm_gem_object *gem)
  93. {
  94. return container_of(gem, struct bochs_bo, gem);
  95. }
  96. #define DRM_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT)
  97. static inline u64 bochs_bo_mmap_offset(struct bochs_bo *bo)
  98. {
  99. return drm_vma_node_offset_addr(&bo->bo.vma_node);
  100. }
  101. /* ---------------------------------------------------------------------- */
  102. /* bochs_hw.c */
  103. int bochs_hw_init(struct drm_device *dev, uint32_t flags);
  104. void bochs_hw_fini(struct drm_device *dev);
  105. void bochs_hw_setmode(struct bochs_device *bochs,
  106. struct drm_display_mode *mode);
  107. void bochs_hw_setbase(struct bochs_device *bochs,
  108. int x, int y, u64 addr);
  109. /* bochs_mm.c */
  110. int bochs_mm_init(struct bochs_device *bochs);
  111. void bochs_mm_fini(struct bochs_device *bochs);
  112. int bochs_mmap(struct file *filp, struct vm_area_struct *vma);
  113. int bochs_gem_create(struct drm_device *dev, u32 size, bool iskernel,
  114. struct drm_gem_object **obj);
  115. int bochs_gem_init_object(struct drm_gem_object *obj);
  116. void bochs_gem_free_object(struct drm_gem_object *obj);
  117. int bochs_dumb_create(struct drm_file *file, struct drm_device *dev,
  118. struct drm_mode_create_dumb *args);
  119. int bochs_dumb_mmap_offset(struct drm_file *file, struct drm_device *dev,
  120. uint32_t handle, uint64_t *offset);
  121. int bochs_framebuffer_init(struct drm_device *dev,
  122. struct bochs_framebuffer *gfb,
  123. const struct drm_mode_fb_cmd2 *mode_cmd,
  124. struct drm_gem_object *obj);
  125. int bochs_bo_pin(struct bochs_bo *bo, u32 pl_flag, u64 *gpu_addr);
  126. int bochs_bo_unpin(struct bochs_bo *bo);
  127. extern const struct drm_mode_config_funcs bochs_mode_funcs;
  128. /* bochs_kms.c */
  129. int bochs_kms_init(struct bochs_device *bochs);
  130. void bochs_kms_fini(struct bochs_device *bochs);
  131. /* bochs_fbdev.c */
  132. int bochs_fbdev_init(struct bochs_device *bochs);
  133. void bochs_fbdev_fini(struct bochs_device *bochs);