bochs.h 4.6 KB

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