2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2005,2006,2007,2008,2009,2010 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
22 #include <grub/types.h>
24 #include <grub/misc.h>
26 #include <grub/video.h>
27 #include <grub/video_fb.h>
32 struct grub_video_mode_info mode_info
;
33 struct grub_video_render_target
*render_target
;
35 unsigned int bytes_per_scan_line
;
36 unsigned int bytes_per_pixel
;
41 grub_pci_device_t dev
;
45 grub_video_sm712_video_init (void)
47 /* Reset frame buffer. */
48 grub_memset (&framebuffer
, 0, sizeof(framebuffer
));
50 return grub_video_fb_init ();
54 grub_video_sm712_video_fini (void)
56 if (framebuffer
.mapped
)
57 grub_pci_device_unmap_range (framebuffer
.dev
, framebuffer
.ptr
,
60 return grub_video_fb_fini ();
64 grub_video_sm712_setup (unsigned int width
, unsigned int height
,
65 unsigned int mode_type
, unsigned int mode_mask
__attribute__ ((unused
)))
71 auto int NESTED_FUNC_ATTR
find_card (grub_pci_device_t dev
, grub_pci_id_t pciid
__attribute__ ((unused
)));
72 int NESTED_FUNC_ATTR
find_card (grub_pci_device_t dev
, grub_pci_id_t pciid
__attribute__ ((unused
)))
74 grub_pci_address_t addr
;
77 addr
= grub_pci_make_address (dev
, GRUB_PCI_REG_CLASS
);
78 class = grub_pci_read (addr
);
80 if (((class >> 16) & 0xffff) != 0x0300 || pciid
!= 0x0712126f)
85 addr
= grub_pci_make_address (dev
, GRUB_PCI_REG_ADDRESS_REG0
);
86 framebuffer
.base
= grub_pci_read (addr
);
87 framebuffer
.dev
= dev
;
92 /* Decode depth from mode_type. If it is zero, then autodetect. */
93 depth
= (mode_type
& GRUB_VIDEO_MODE_TYPE_DEPTH_MASK
)
94 >> GRUB_VIDEO_MODE_TYPE_DEPTH_POS
;
96 if ((width
!= 1024 && width
!= 0) || (height
!= 600 && height
!= 0)
97 || (depth
!= 16 && depth
!= 0))
98 return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET
,
99 "Only 1024x600x16 is supported");
101 grub_pci_iterate (find_card
);
103 return grub_error (GRUB_ERR_IO
, "Couldn't find graphics card");
105 if (found
&& framebuffer
.base
== 0)
107 /* FIXME: change framebuffer base */
110 /* Fill mode info details. */
111 framebuffer
.mode_info
.width
= 1024;
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
= 1024 * 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 framebuffer
.mode_info
.blit_format
= grub_video_get_blit_format (&framebuffer
.mode_info
);
127 /* We can safely discard volatile attribute. */
128 framebuffer
.ptr
= (void *) grub_pci_device_map_range (framebuffer
.dev
,
131 framebuffer
.mapped
= 1;
133 err
= grub_video_fb_create_render_target_from_pointer (&framebuffer
.render_target
, &framebuffer
.mode_info
, framebuffer
.ptr
);
138 err
= grub_video_fb_set_active_render_target (framebuffer
.render_target
);
143 /* Copy default palette to initialize emulated palette. */
144 err
= grub_video_fb_set_palette (0, GRUB_VIDEO_FBSTD_NUMCOLORS
,
145 grub_video_fbstd_colors
);
150 grub_video_sm712_set_palette (unsigned int start
, unsigned int count
,
151 struct grub_video_palette_data
*palette_data
)
153 if (framebuffer
.index_color_mode
)
155 /* TODO: Implement setting indexed color mode palette to hardware. */
158 /* Then set color to emulated palette. */
159 return grub_video_fb_set_palette (start
, count
, palette_data
);
163 grub_video_sm712_swap_buffers (void)
165 /* TODO: Implement buffer swapping. */
166 return GRUB_ERR_NONE
;
170 grub_video_sm712_set_active_render_target (struct grub_video_render_target
*target
)
172 if (target
== GRUB_VIDEO_RENDER_TARGET_DISPLAY
)
173 target
= framebuffer
.render_target
;
175 return grub_video_fb_set_active_render_target (target
);
179 grub_video_sm712_get_info_and_fini (struct grub_video_mode_info
*mode_info
,
182 grub_memcpy (mode_info
, &(framebuffer
.mode_info
), sizeof (*mode_info
));
183 *framebuf
= (char *) framebuffer
.ptr
;
185 grub_video_fb_fini ();
187 return GRUB_ERR_NONE
;
191 static struct grub_video_adapter grub_video_sm712_adapter
=
193 .name
= "SM712 Video Driver",
195 .init
= grub_video_sm712_video_init
,
196 .fini
= grub_video_sm712_video_fini
,
197 .setup
= grub_video_sm712_setup
,
198 .get_info
= grub_video_fb_get_info
,
199 .get_info_and_fini
= grub_video_sm712_get_info_and_fini
,
200 .set_palette
= grub_video_sm712_set_palette
,
201 .get_palette
= grub_video_fb_get_palette
,
202 .set_viewport
= grub_video_fb_set_viewport
,
203 .get_viewport
= grub_video_fb_get_viewport
,
204 .map_color
= grub_video_fb_map_color
,
205 .map_rgb
= grub_video_fb_map_rgb
,
206 .map_rgba
= grub_video_fb_map_rgba
,
207 .unmap_color
= grub_video_fb_unmap_color
,
208 .fill_rect
= grub_video_fb_fill_rect
,
209 .blit_bitmap
= grub_video_fb_blit_bitmap
,
210 .blit_render_target
= grub_video_fb_blit_render_target
,
211 .scroll
= grub_video_fb_scroll
,
212 .swap_buffers
= grub_video_sm712_swap_buffers
,
213 .create_render_target
= grub_video_fb_create_render_target
,
214 .delete_render_target
= grub_video_fb_delete_render_target
,
215 .set_active_render_target
= grub_video_sm712_set_active_render_target
,
216 .get_active_render_target
= grub_video_fb_get_active_render_target
,
221 GRUB_MOD_INIT(video_sm712
)
223 grub_video_register (&grub_video_sm712_adapter
);
226 GRUB_MOD_FINI(video_sm712
)
228 grub_video_unregister (&grub_video_sm712_adapter
);