Indentation fix, cleanup.
[AROS.git] / arch / all-pc / boot / grub2-aros / grub-core / video / radeon_yeeloong3a.c
blob52614feb69ad520bbf3c6cdf5640abb4973ac463
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2005,2006,2007,2008,2009,2010,2011,2013 Free Software Foundation, Inc.
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.
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.
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/>.
19 #define grub_video_render_target grub_video_fbrender_target
21 #include <grub/err.h>
22 #include <grub/types.h>
23 #include <grub/dl.h>
24 #include <grub/misc.h>
25 #include <grub/mm.h>
26 #include <grub/video.h>
27 #include <grub/video_fb.h>
28 #include <grub/pci.h>
29 #include <grub/vga.h>
31 #define GRUB_RADEON_YEELOONG3A_TOTAL_MEMORY_SPACE 1048576
33 static struct
35 struct grub_video_mode_info mode_info;
36 struct grub_video_render_target *render_target;
38 grub_uint8_t *ptr;
39 int mapped;
40 grub_uint32_t base;
41 grub_pci_device_t dev;
42 } framebuffer;
44 static grub_err_t
45 grub_video_radeon_yeeloong3a_video_init (void)
47 /* Reset frame buffer. */
48 grub_memset (&framebuffer, 0, sizeof(framebuffer));
50 return grub_video_fb_init ();
53 static grub_err_t
54 grub_video_radeon_yeeloong3a_video_fini (void)
56 if (framebuffer.mapped)
57 grub_pci_device_unmap_range (framebuffer.dev, framebuffer.ptr,
58 GRUB_RADEON_YEELOONG3A_TOTAL_MEMORY_SPACE);
59 return grub_video_fb_fini ();
62 #ifndef TEST
63 /* Helper for grub_video_radeon_yeeloong3a_setup. */
64 static int
65 find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data)
67 int *found = data;
68 grub_pci_address_t addr;
69 grub_uint32_t class;
71 addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
72 class = grub_pci_read (addr);
74 if (((class >> 16) & 0xffff) != GRUB_PCI_CLASS_SUBCLASS_VGA
75 || pciid != 0x96151002)
76 return 0;
78 *found = 1;
80 addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG0);
81 framebuffer.base = grub_pci_read (addr);
82 framebuffer.dev = dev;
84 return 1;
86 #endif
88 static grub_err_t
89 grub_video_radeon_yeeloong3a_setup (unsigned int width, unsigned int height,
90 unsigned int mode_type, unsigned int mode_mask __attribute__ ((unused)))
92 int depth;
93 grub_err_t err;
94 int found = 0;
96 #ifndef TEST
97 /* Decode depth from mode_type. If it is zero, then autodetect. */
98 depth = (mode_type & GRUB_VIDEO_MODE_TYPE_DEPTH_MASK)
99 >> GRUB_VIDEO_MODE_TYPE_DEPTH_POS;
101 if ((width != 800 && width != 0) || (height != 600 && height != 0)
102 || (depth != 16 && depth != 0))
103 return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
104 "Only 640x480x16 is supported");
106 grub_pci_iterate (find_card, &found);
107 if (!found)
108 return grub_error (GRUB_ERR_IO, "Couldn't find graphics card");
109 #endif
110 /* Fill mode info details. */
111 framebuffer.mode_info.width = 800;
112 framebuffer.mode_info.height = 600;
113 framebuffer.mode_info.mode_type = GRUB_VIDEO_MODE_TYPE_RGB;
114 framebuffer.mode_info.bpp = 16;
115 framebuffer.mode_info.bytes_per_pixel = 2;
116 framebuffer.mode_info.pitch = 800 * 2;
117 framebuffer.mode_info.number_of_colors = 256;
118 framebuffer.mode_info.red_mask_size = 5;
119 framebuffer.mode_info.red_field_pos = 11;
120 framebuffer.mode_info.green_mask_size = 6;
121 framebuffer.mode_info.green_field_pos = 5;
122 framebuffer.mode_info.blue_mask_size = 5;
123 framebuffer.mode_info.blue_field_pos = 0;
124 framebuffer.mode_info.reserved_mask_size = 0;
125 framebuffer.mode_info.reserved_field_pos = 0;
126 #ifndef TEST
127 framebuffer.mode_info.blit_format
128 = grub_video_get_blit_format (&framebuffer.mode_info);
129 #endif
131 /* We can safely discard volatile attribute. */
132 #ifndef TEST
133 framebuffer.ptr = (void *) grub_pci_device_map_range (framebuffer.dev,
134 framebuffer.base,
135 GRUB_RADEON_YEELOONG3A_TOTAL_MEMORY_SPACE);
136 framebuffer.mapped = 1;
137 #endif
139 /* Prevent garbage from appearing on the screen. */
140 grub_memset (framebuffer.ptr, 0,
141 framebuffer.mode_info.height * framebuffer.mode_info.pitch);
143 #ifndef TEST
144 err = grub_video_fb_create_render_target_from_pointer (&framebuffer
145 .render_target,
146 &framebuffer.mode_info,
147 framebuffer.ptr);
149 if (err)
150 return err;
152 err = grub_video_fb_set_active_render_target (framebuffer.render_target);
154 if (err)
155 return err;
157 /* Copy default palette to initialize emulated palette. */
158 err = grub_video_fb_set_palette (0, GRUB_VIDEO_FBSTD_NUMCOLORS,
159 grub_video_fbstd_colors);
160 #endif
161 return err;
164 static grub_err_t
165 grub_video_radeon_yeeloong3a_swap_buffers (void)
167 /* TODO: Implement buffer swapping. */
168 return GRUB_ERR_NONE;
171 static grub_err_t
172 grub_video_radeon_yeeloong3a_set_active_render_target (struct grub_video_render_target *target)
174 if (target == GRUB_VIDEO_RENDER_TARGET_DISPLAY)
175 target = framebuffer.render_target;
177 return grub_video_fb_set_active_render_target (target);
180 static grub_err_t
181 grub_video_radeon_yeeloong3a_get_info_and_fini (struct grub_video_mode_info *mode_info,
182 void **framebuf)
184 grub_memcpy (mode_info, &(framebuffer.mode_info), sizeof (*mode_info));
185 *framebuf = (char *) framebuffer.ptr;
187 grub_video_fb_fini ();
189 return GRUB_ERR_NONE;
192 static struct grub_video_adapter grub_video_radeon_yeeloong3a_adapter =
194 .name = "RADEON (Yeeloong3a) Video Driver",
195 .id = GRUB_VIDEO_DRIVER_RADEON_YEELOONG3A,
197 .prio = GRUB_VIDEO_ADAPTER_PRIO_NATIVE,
199 .init = grub_video_radeon_yeeloong3a_video_init,
200 .fini = grub_video_radeon_yeeloong3a_video_fini,
201 .setup = grub_video_radeon_yeeloong3a_setup,
202 .get_info = grub_video_fb_get_info,
203 .get_info_and_fini = grub_video_radeon_yeeloong3a_get_info_and_fini,
204 .set_palette = grub_video_fb_set_palette,
205 .get_palette = grub_video_fb_get_palette,
206 .set_viewport = grub_video_fb_set_viewport,
207 .get_viewport = grub_video_fb_get_viewport,
208 .set_region = grub_video_fb_set_region,
209 .get_region = grub_video_fb_get_region,
210 .set_area_status = grub_video_fb_set_area_status,
211 .get_area_status = grub_video_fb_get_area_status,
212 .map_color = grub_video_fb_map_color,
213 .map_rgb = grub_video_fb_map_rgb,
214 .map_rgba = grub_video_fb_map_rgba,
215 .unmap_color = grub_video_fb_unmap_color,
216 .fill_rect = grub_video_fb_fill_rect,
217 .blit_bitmap = grub_video_fb_blit_bitmap,
218 .blit_render_target = grub_video_fb_blit_render_target,
219 .scroll = grub_video_fb_scroll,
220 .swap_buffers = grub_video_radeon_yeeloong3a_swap_buffers,
221 .create_render_target = grub_video_fb_create_render_target,
222 .delete_render_target = grub_video_fb_delete_render_target,
223 .set_active_render_target = grub_video_radeon_yeeloong3a_set_active_render_target,
224 .get_active_render_target = grub_video_fb_get_active_render_target,
226 .next = 0
229 GRUB_MOD_INIT(video_radeon_yeeloong3a)
231 grub_video_register (&grub_video_radeon_yeeloong3a_adapter);
234 GRUB_MOD_FINI(video_radeon_yeeloong3a)
236 grub_video_unregister (&grub_video_radeon_yeeloong3a_adapter);