radeon_fuloong2e.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2005,2006,2007,2008,2009,2010,2011 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #define grub_video_render_target grub_video_fbrender_target
  19. #include <grub/err.h>
  20. #include <grub/types.h>
  21. #include <grub/dl.h>
  22. #include <grub/misc.h>
  23. #include <grub/mm.h>
  24. #include <grub/video.h>
  25. #include <grub/video_fb.h>
  26. #include <grub/pci.h>
  27. #include <grub/vga.h>
  28. #define GRUB_RADEON_FULOONG2E_TOTAL_MEMORY_SPACE 1048576
  29. static struct
  30. {
  31. struct grub_video_mode_info mode_info;
  32. struct grub_video_render_target *render_target;
  33. grub_uint8_t *ptr;
  34. int mapped;
  35. grub_uint32_t base;
  36. grub_pci_device_t dev;
  37. } framebuffer;
  38. static grub_err_t
  39. grub_video_radeon_fuloong2e_video_init (void)
  40. {
  41. /* Reset frame buffer. */
  42. grub_memset (&framebuffer, 0, sizeof(framebuffer));
  43. return grub_video_fb_init ();
  44. }
  45. static grub_err_t
  46. grub_video_radeon_fuloong2e_video_fini (void)
  47. {
  48. if (framebuffer.mapped)
  49. grub_pci_device_unmap_range (framebuffer.dev, framebuffer.ptr,
  50. GRUB_RADEON_FULOONG2E_TOTAL_MEMORY_SPACE);
  51. return grub_video_fb_fini ();
  52. }
  53. #ifndef TEST
  54. /* Helper for grub_video_radeon_fuloong2e_setup. */
  55. static int
  56. find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data)
  57. {
  58. int *found = data;
  59. grub_pci_address_t addr;
  60. grub_uint32_t class;
  61. addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
  62. class = grub_pci_read (addr);
  63. if (((class >> 16) & 0xffff) != GRUB_PCI_CLASS_DISPLAY_VGA
  64. || pciid != 0x515a1002)
  65. return 0;
  66. *found = 1;
  67. addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG0);
  68. framebuffer.base = grub_pci_read (addr);
  69. framebuffer.dev = dev;
  70. return 1;
  71. }
  72. #endif
  73. static grub_err_t
  74. grub_video_radeon_fuloong2e_setup (unsigned int width, unsigned int height,
  75. unsigned int mode_type, unsigned int mode_mask __attribute__ ((unused)))
  76. {
  77. int depth;
  78. grub_err_t err;
  79. int found = 0;
  80. #ifndef TEST
  81. /* Decode depth from mode_type. If it is zero, then autodetect. */
  82. depth = (mode_type & GRUB_VIDEO_MODE_TYPE_DEPTH_MASK)
  83. >> GRUB_VIDEO_MODE_TYPE_DEPTH_POS;
  84. if ((width != 640 && width != 0) || (height != 480 && height != 0)
  85. || (depth != 16 && depth != 0))
  86. return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
  87. "Only 640x480x16 is supported");
  88. grub_pci_iterate (find_card, &found);
  89. if (!found)
  90. return grub_error (GRUB_ERR_IO, "Couldn't find graphics card");
  91. #endif
  92. /* Fill mode info details. */
  93. framebuffer.mode_info.width = 640;
  94. framebuffer.mode_info.height = 480;
  95. framebuffer.mode_info.mode_type = GRUB_VIDEO_MODE_TYPE_RGB;
  96. framebuffer.mode_info.bpp = 16;
  97. framebuffer.mode_info.bytes_per_pixel = 2;
  98. framebuffer.mode_info.pitch = 640 * 2;
  99. framebuffer.mode_info.number_of_colors = 256;
  100. framebuffer.mode_info.red_mask_size = 5;
  101. framebuffer.mode_info.red_field_pos = 11;
  102. framebuffer.mode_info.green_mask_size = 6;
  103. framebuffer.mode_info.green_field_pos = 5;
  104. framebuffer.mode_info.blue_mask_size = 5;
  105. framebuffer.mode_info.blue_field_pos = 0;
  106. framebuffer.mode_info.reserved_mask_size = 0;
  107. framebuffer.mode_info.reserved_field_pos = 0;
  108. #ifndef TEST
  109. framebuffer.mode_info.blit_format
  110. = grub_video_get_blit_format (&framebuffer.mode_info);
  111. #endif
  112. /* We can safely discard volatile attribute. */
  113. #ifndef TEST
  114. framebuffer.ptr
  115. = (void *) grub_pci_device_map_range (framebuffer.dev,
  116. framebuffer.base,
  117. GRUB_RADEON_FULOONG2E_TOTAL_MEMORY_SPACE);
  118. #endif
  119. framebuffer.mapped = 1;
  120. /* Prevent garbage from appearing on the screen. */
  121. grub_memset (framebuffer.ptr, 0x55,
  122. framebuffer.mode_info.height * framebuffer.mode_info.pitch);
  123. #ifndef TEST
  124. err = grub_video_fb_create_render_target_from_pointer (&framebuffer
  125. .render_target,
  126. &framebuffer.mode_info,
  127. framebuffer.ptr);
  128. if (err)
  129. return err;
  130. err = grub_video_fb_set_active_render_target (framebuffer.render_target);
  131. if (err)
  132. return err;
  133. /* Copy default palette to initialize emulated palette. */
  134. err = grub_video_fb_set_palette (0, GRUB_VIDEO_FBSTD_NUMCOLORS,
  135. grub_video_fbstd_colors);
  136. #endif
  137. return err;
  138. }
  139. static grub_err_t
  140. grub_video_radeon_fuloong2e_swap_buffers (void)
  141. {
  142. /* TODO: Implement buffer swapping. */
  143. return GRUB_ERR_NONE;
  144. }
  145. static grub_err_t
  146. grub_video_radeon_fuloong2e_set_active_render_target (struct grub_video_render_target *target)
  147. {
  148. if (target == GRUB_VIDEO_RENDER_TARGET_DISPLAY)
  149. target = framebuffer.render_target;
  150. return grub_video_fb_set_active_render_target (target);
  151. }
  152. static grub_err_t
  153. grub_video_radeon_fuloong2e_get_info_and_fini (struct grub_video_mode_info *mode_info,
  154. void **framebuf)
  155. {
  156. grub_memcpy (mode_info, &(framebuffer.mode_info), sizeof (*mode_info));
  157. *framebuf = (char *) framebuffer.ptr;
  158. grub_video_fb_fini ();
  159. return GRUB_ERR_NONE;
  160. }
  161. static struct grub_video_adapter grub_video_radeon_fuloong2e_adapter =
  162. {
  163. .name = "RADEON RV100 QZ (Fuloong2E) Video Driver",
  164. .id = GRUB_VIDEO_DRIVER_RADEON_FULOONG2E,
  165. .prio = GRUB_VIDEO_ADAPTER_PRIO_NATIVE,
  166. .init = grub_video_radeon_fuloong2e_video_init,
  167. .fini = grub_video_radeon_fuloong2e_video_fini,
  168. .setup = grub_video_radeon_fuloong2e_setup,
  169. .get_info = grub_video_fb_get_info,
  170. .get_info_and_fini = grub_video_radeon_fuloong2e_get_info_and_fini,
  171. .set_palette = grub_video_fb_set_palette,
  172. .get_palette = grub_video_fb_get_palette,
  173. .set_viewport = grub_video_fb_set_viewport,
  174. .get_viewport = grub_video_fb_get_viewport,
  175. .set_region = grub_video_fb_set_region,
  176. .get_region = grub_video_fb_get_region,
  177. .set_area_status = grub_video_fb_set_area_status,
  178. .get_area_status = grub_video_fb_get_area_status,
  179. .map_color = grub_video_fb_map_color,
  180. .map_rgb = grub_video_fb_map_rgb,
  181. .map_rgba = grub_video_fb_map_rgba,
  182. .unmap_color = grub_video_fb_unmap_color,
  183. .fill_rect = grub_video_fb_fill_rect,
  184. .blit_bitmap = grub_video_fb_blit_bitmap,
  185. .blit_render_target = grub_video_fb_blit_render_target,
  186. .scroll = grub_video_fb_scroll,
  187. .swap_buffers = grub_video_radeon_fuloong2e_swap_buffers,
  188. .create_render_target = grub_video_fb_create_render_target,
  189. .delete_render_target = grub_video_fb_delete_render_target,
  190. .set_active_render_target = grub_video_radeon_fuloong2e_set_active_render_target,
  191. .get_active_render_target = grub_video_fb_get_active_render_target,
  192. .next = 0
  193. };
  194. GRUB_MOD_INIT(video_radeon_fuloong2e)
  195. {
  196. grub_video_register (&grub_video_radeon_fuloong2e_adapter);
  197. }
  198. GRUB_MOD_FINI(video_radeon_fuloong2e)
  199. {
  200. grub_video_unregister (&grub_video_radeon_fuloong2e_adapter);
  201. }