bochs.h 4.6 KB

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