~hamo/ubuntu/precise/grub2/grub2.hi_res

« back to all changes in this revision

Viewing changes to video/sm712.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson, Colin Watson, Robert Millan, Updated translations
  • Date: 2010-11-22 12:24:56 UTC
  • mfrom: (1.26.4 upstream) (17.3.36 sid)
  • mto: (17.3.43 sid)
  • mto: This revision was merged to the branch mainline in revision 89.
  • Revision ID: james.westby@ubuntu.com-20101122122456-y82z3sfb7k4zfdcc
Tags: 1.99~20101122-1
[ Colin Watson ]
* New Bazaar snapshot.  Too many changes to list in full, but some of the
  more user-visible ones are as follows:
  - GRUB script:
    + Function parameters, "break", "continue", "shift", "setparams",
      "return", and "!".
    + "export" command supports multiple variable names.
    + Multi-line quoted strings support.
    + Wildcard expansion.
  - sendkey support.
  - USB hotunplugging and USB serial support.
  - Rename CD-ROM to cd on BIOS.
  - Add new --boot-directory option to grub-install, grub-reboot, and
    grub-set-default; the old --root-directory option is still accepted
    but was often confusing.
  - Basic btrfs detection/UUID support (but no file reading yet).
  - bash-completion for utilities.
  - If a device is listed in device.map, always assume that it is
    BIOS-visible rather than using extra layers such as LVM or RAID.
  - Add grub-mknetdir script (closes: #550658).
  - Remove deprecated "root" command.
  - Handle RAID devices containing virtio components.
  - GRUB Legacy configuration file support (via grub-menulst2cfg).
  - Keyboard layout support (via grub-mklayout and grub-kbdcomp).
  - Check generated grub.cfg for syntax errors before saving.
  - Pause execution for at most ten seconds if any errors are displayed,
    so that the user has a chance to see them.
  - Support submenus.
  - Write embedding zone using Reed-Solomon, so that it's robust against
    being partially overwritten (closes: #550702, #591416, #593347).
  - GRUB_DISABLE_LINUX_RECOVERY and GRUB_DISABLE_NETBSD_RECOVERY merged
    into a single GRUB_DISABLE_RECOVERY variable.
  - Fix loader memory allocation failure (closes: #551627).
  - Don't call savedefault on recovery entries (closes: #589325).
  - Support triple-indirect blocks on ext2 (closes: #543924).
  - Recognise DDF1 fake RAID (closes: #603354).

[ Robert Millan ]
* Use dpkg architecture wildcards.

[ Updated translations ]
* Slovenian (Vanja Cvelbar).  Closes: #604003
* Dzongkha (dawa pemo via Tenzin Dendup).  Closes: #604102

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  GRUB  --  GRand Unified Bootloader
3
 
 *  Copyright (C) 2005,2006,2007,2008,2009,2010  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
 
 
19
 
#define grub_video_render_target grub_video_fbrender_target
20
 
 
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
 
 
30
 
static struct
31
 
{
32
 
  struct grub_video_mode_info mode_info;
33
 
  struct grub_video_render_target *render_target;
34
 
 
35
 
  unsigned int bytes_per_scan_line;
36
 
  unsigned int bytes_per_pixel;
37
 
  grub_uint8_t *ptr;
38
 
  int index_color_mode;
39
 
  int mapped;
40
 
  grub_uint32_t base;
41
 
  grub_pci_device_t dev;
42
 
} framebuffer;
43
 
 
44
 
static grub_err_t
45
 
grub_video_sm712_video_init (void)
46
 
{
47
 
  /* Reset frame buffer.  */
48
 
  grub_memset (&framebuffer, 0, sizeof(framebuffer));
49
 
 
50
 
  return grub_video_fb_init ();
51
 
}
52
 
 
53
 
static grub_err_t
54
 
grub_video_sm712_video_fini (void)
55
 
{
56
 
  if (framebuffer.mapped)
57
 
    grub_pci_device_unmap_range (framebuffer.dev, framebuffer.ptr,
58
 
                                 1024 * 600 * 2);
59
 
 
60
 
  return grub_video_fb_fini ();
61
 
}
62
 
 
63
 
static grub_err_t
64
 
grub_video_sm712_setup (unsigned int width, unsigned int height,
65
 
                        unsigned int mode_type, unsigned int mode_mask __attribute__ ((unused)))
66
 
{
67
 
  int depth;
68
 
  grub_err_t err;
69
 
  int found = 0;
70
 
 
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)))
73
 
    {
74
 
      grub_pci_address_t addr;
75
 
      grub_uint32_t class;
76
 
 
77
 
      addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
78
 
      class = grub_pci_read (addr);
79
 
 
80
 
      if (((class >> 16) & 0xffff) != 0x0300 || pciid != 0x0712126f)
81
 
        return 0;
82
 
      
83
 
      found = 1;
84
 
 
85
 
      addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG0);
86
 
      framebuffer.base = grub_pci_read (addr);
87
 
      framebuffer.dev = dev;
88
 
 
89
 
      return 1;
90
 
    }
91
 
 
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;
95
 
 
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");
100
 
 
101
 
  grub_pci_iterate (find_card);
102
 
  if (!found)
103
 
    return grub_error (GRUB_ERR_IO, "Couldn't find graphics card");
104
 
 
105
 
  if (found && framebuffer.base == 0)
106
 
    {
107
 
      /* FIXME: change framebuffer base */
108
 
    }
109
 
 
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,
129
 
                                                        framebuffer.base,
130
 
                                                        1024 * 600 * 2);
131
 
  framebuffer.mapped = 1;
132
 
 
133
 
  err = grub_video_fb_create_render_target_from_pointer (&framebuffer.render_target, &framebuffer.mode_info, framebuffer.ptr);
134
 
 
135
 
  if (err)
136
 
    return err;
137
 
 
138
 
  err = grub_video_fb_set_active_render_target (framebuffer.render_target);
139
 
  
140
 
  if (err)
141
 
    return err;
142
 
 
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);
146
 
  return err;
147
 
}
148
 
 
149
 
static grub_err_t
150
 
grub_video_sm712_set_palette (unsigned int start, unsigned int count,
151
 
                            struct grub_video_palette_data *palette_data)
152
 
{
153
 
  if (framebuffer.index_color_mode)
154
 
    {
155
 
      /* TODO: Implement setting indexed color mode palette to hardware.  */
156
 
    }
157
 
 
158
 
  /* Then set color to emulated palette.  */
159
 
  return grub_video_fb_set_palette (start, count, palette_data);
160
 
}
161
 
 
162
 
static grub_err_t
163
 
grub_video_sm712_swap_buffers (void)
164
 
{
165
 
  /* TODO: Implement buffer swapping.  */
166
 
  return GRUB_ERR_NONE;
167
 
}
168
 
 
169
 
static grub_err_t
170
 
grub_video_sm712_set_active_render_target (struct grub_video_render_target *target)
171
 
{
172
 
  if (target == GRUB_VIDEO_RENDER_TARGET_DISPLAY)
173
 
      target = framebuffer.render_target;
174
 
 
175
 
  return grub_video_fb_set_active_render_target (target);
176
 
}
177
 
 
178
 
static grub_err_t
179
 
grub_video_sm712_get_info_and_fini (struct grub_video_mode_info *mode_info,
180
 
                                    void **framebuf)
181
 
{
182
 
  grub_memcpy (mode_info, &(framebuffer.mode_info), sizeof (*mode_info));
183
 
  *framebuf = (char *) framebuffer.ptr;
184
 
 
185
 
  grub_video_fb_fini ();
186
 
 
187
 
  return GRUB_ERR_NONE;
188
 
}
189
 
 
190
 
 
191
 
static struct grub_video_adapter grub_video_sm712_adapter =
192
 
  {
193
 
    .name = "SM712 Video Driver",
194
 
 
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,
217
 
 
218
 
    .next = 0
219
 
  };
220
 
 
221
 
GRUB_MOD_INIT(video_sm712)
222
 
{
223
 
  grub_video_register (&grub_video_sm712_adapter);
224
 
}
225
 
 
226
 
GRUB_MOD_FINI(video_sm712)
227
 
{
228
 
  grub_video_unregister (&grub_video_sm712_adapter);
229
 
}