Indentation fix, cleanup.
[AROS.git] / arch / all-pc / boot / grub2-aros / grub-core / video / radeon_fuloong2e.c
blobb4da34b5eeb680921ed4302af0a1ab70f34e9443
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2005,2006,2007,2008,2009,2010,2011 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_FULOONG2E_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_fuloong2e_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_fuloong2e_video_fini (void)
56 if (framebuffer.mapped)
57 grub_pci_device_unmap_range (framebuffer.dev, framebuffer.ptr,
58 GRUB_RADEON_FULOONG2E_TOTAL_MEMORY_SPACE);
60 return grub_video_fb_fini ();
63 #ifndef TEST
64 /* Helper for grub_video_radeon_fuloong2e_setup. */
65 static int
66 find_card (grub_pci_device_t dev, grub_pci_id_t pciid, void *data)
68 int *found = data;
69 grub_pci_address_t addr;
70 grub_uint32_t class;
72 addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
73 class = grub_pci_read (addr);
75 if (((class >> 16) & 0xffff) != GRUB_PCI_CLASS_SUBCLASS_VGA
76 || pciid != 0x515a1002)
77 return 0;
79 *found = 1;
81 addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG0);
82 framebuffer.base = grub_pci_read (addr);
83 framebuffer.dev = dev;
85 return 1;
87 #endif
89 static grub_err_t
90 grub_video_radeon_fuloong2e_setup (unsigned int width, unsigned int height,
91 unsigned int mode_type, unsigned int mode_mask __attribute__ ((unused)))
93 int depth;
94 grub_err_t err;
95 int found = 0;
97 #ifndef TEST
98 /* Decode depth from mode_type. If it is zero, then autodetect. */
99 depth = (mode_type & GRUB_VIDEO_MODE_TYPE_DEPTH_MASK)
100 >> GRUB_VIDEO_MODE_TYPE_DEPTH_POS;
102 if ((width != 640 && width != 0) || (height != 480 && height != 0)
103 || (depth != 16 && depth != 0))
104 return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
105 "Only 640x480x16 is supported");
107 grub_pci_iterate (find_card, &found);
108 if (!found)
109 return grub_error (GRUB_ERR_IO, "Couldn't find graphics card");
110 #endif
111 /* Fill mode info details. */
112 framebuffer.mode_info.width = 640;
113 framebuffer.mode_info.height = 480;
114 framebuffer.mode_info.mode_type = GRUB_VIDEO_MODE_TYPE_RGB;
115 framebuffer.mode_info.bpp = 16;
116 framebuffer.mode_info.bytes_per_pixel = 2;
117 framebuffer.mode_info.pitch = 640 * 2;
118 framebuffer.mode_info.number_of_colors = 256;
119 framebuffer.mode_info.red_mask_size = 5;
120 framebuffer.mode_info.red_field_pos = 11;
121 framebuffer.mode_info.green_mask_size = 6;
122 framebuffer.mode_info.green_field_pos = 5;
123 framebuffer.mode_info.blue_mask_size = 5;
124 framebuffer.mode_info.blue_field_pos = 0;
125 framebuffer.mode_info.reserved_mask_size = 0;
126 framebuffer.mode_info.reserved_field_pos = 0;
127 #ifndef TEST
128 framebuffer.mode_info.blit_format
129 = grub_video_get_blit_format (&framebuffer.mode_info);
130 #endif
132 /* We can safely discard volatile attribute. */
133 #ifndef TEST
134 framebuffer.ptr
135 = (void *) grub_pci_device_map_range (framebuffer.dev,
136 framebuffer.base,
137 GRUB_RADEON_FULOONG2E_TOTAL_MEMORY_SPACE);
138 #endif
139 framebuffer.mapped = 1;
141 /* Prevent garbage from appearing on the screen. */
142 grub_memset (framebuffer.ptr, 0x55,
143 framebuffer.mode_info.height * framebuffer.mode_info.pitch);
145 #ifndef TEST
146 err = grub_video_fb_create_render_target_from_pointer (&framebuffer
147 .render_target,
148 &framebuffer.mode_info,
149 framebuffer.ptr);
151 if (err)
152 return err;
154 err = grub_video_fb_set_active_render_target (framebuffer.render_target);
156 if (err)
157 return err;
159 /* Copy default palette to initialize emulated palette. */
160 err = grub_video_fb_set_palette (0, GRUB_VIDEO_FBSTD_NUMCOLORS,
161 grub_video_fbstd_colors);
162 #endif
163 return err;
166 static grub_err_t
167 grub_video_radeon_fuloong2e_swap_buffers (void)
169 /* TODO: Implement buffer swapping. */
170 return GRUB_ERR_NONE;
173 static grub_err_t
174 grub_video_radeon_fuloong2e_set_active_render_target (struct grub_video_render_target *target)
176 if (target == GRUB_VIDEO_RENDER_TARGET_DISPLAY)
177 target = framebuffer.render_target;
179 return grub_video_fb_set_active_render_target (target);
182 static grub_err_t
183 grub_video_radeon_fuloong2e_get_info_and_fini (struct grub_video_mode_info *mode_info,
184 void **framebuf)
186 grub_memcpy (mode_info, &(framebuffer.mode_info), sizeof (*mode_info));
187 *framebuf = (char *) framebuffer.ptr;
189 grub_video_fb_fini ();
191 return GRUB_ERR_NONE;
194 static struct grub_video_adapter grub_video_radeon_fuloong2e_adapter =
196 .name = "RADEON RV100 QZ (Fuloong2E) Video Driver",
197 .id = GRUB_VIDEO_DRIVER_RADEON_FULOONG2E,
199 .prio = GRUB_VIDEO_ADAPTER_PRIO_NATIVE,
201 .init = grub_video_radeon_fuloong2e_video_init,
202 .fini = grub_video_radeon_fuloong2e_video_fini,
203 .setup = grub_video_radeon_fuloong2e_setup,
204 .get_info = grub_video_fb_get_info,
205 .get_info_and_fini = grub_video_radeon_fuloong2e_get_info_and_fini,
206 .set_palette = grub_video_fb_set_palette,
207 .get_palette = grub_video_fb_get_palette,
208 .set_viewport = grub_video_fb_set_viewport,
209 .get_viewport = grub_video_fb_get_viewport,
210 .set_region = grub_video_fb_set_region,
211 .get_region = grub_video_fb_get_region,
212 .set_area_status = grub_video_fb_set_area_status,
213 .get_area_status = grub_video_fb_get_area_status,
214 .map_color = grub_video_fb_map_color,
215 .map_rgb = grub_video_fb_map_rgb,
216 .map_rgba = grub_video_fb_map_rgba,
217 .unmap_color = grub_video_fb_unmap_color,
218 .fill_rect = grub_video_fb_fill_rect,
219 .blit_bitmap = grub_video_fb_blit_bitmap,
220 .blit_render_target = grub_video_fb_blit_render_target,
221 .scroll = grub_video_fb_scroll,
222 .swap_buffers = grub_video_radeon_fuloong2e_swap_buffers,
223 .create_render_target = grub_video_fb_create_render_target,
224 .delete_render_target = grub_video_fb_delete_render_target,
225 .set_active_render_target = grub_video_radeon_fuloong2e_set_active_render_target,
226 .get_active_render_target = grub_video_fb_get_active_render_target,
228 .next = 0
231 GRUB_MOD_INIT(video_radeon_fuloong2e)
233 grub_video_register (&grub_video_radeon_fuloong2e_adapter);
236 GRUB_MOD_FINI(video_radeon_fuloong2e)
238 grub_video_unregister (&grub_video_radeon_fuloong2e_adapter);