~ubuntu-branches/ubuntu/trusty/grub2/trusty-updates

« back to all changes in this revision

Viewing changes to grub-core/video/video.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-09-13 18:02:04 UTC
  • mfrom: (1.17.15 upstream)
  • mto: (17.6.27 experimental)
  • mto: This revision was merged to the branch mainline in revision 145.
  • Revision ID: package-import@ubuntu.com-20120913180204-mojnmocbimlom4im
Tags: upstream-2.00
ImportĀ upstreamĀ versionĀ 2.00

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include <grub/dl.h>
22
22
#include <grub/misc.h>
23
23
#include <grub/mm.h>
 
24
#include <grub/i18n.h>
24
25
 
25
26
GRUB_MOD_LICENSE ("GPLv3+");
26
27
 
376
377
  return grub_video_adapter_active->get_active_render_target (target);
377
378
}
378
379
 
 
380
grub_err_t
 
381
grub_video_edid_checksum (struct grub_video_edid_info *edid_info)
 
382
{
 
383
  const char *edid_bytes = (const char *) edid_info;
 
384
  int i;
 
385
  char checksum = 0;
 
386
 
 
387
  /* Check EDID checksum.  */
 
388
  for (i = 0; i < 128; ++i)
 
389
    checksum += edid_bytes[i];
 
390
 
 
391
  if (checksum != 0)
 
392
    return grub_error (GRUB_ERR_BAD_DEVICE,
 
393
                       "invalid EDID checksum %d", checksum);
 
394
 
 
395
  grub_errno = GRUB_ERR_NONE;
 
396
  return grub_errno;
 
397
}
 
398
 
 
399
grub_err_t
 
400
grub_video_edid_preferred_mode (struct grub_video_edid_info *edid_info,
 
401
                                unsigned int *width, unsigned int *height)
 
402
{
 
403
  /* Bit 1 in the Feature Support field indicates that the first
 
404
     Detailed Timing Description is the preferred timing mode.  */
 
405
  if (edid_info->version == 1 /* we don't understand later versions */
 
406
      && (edid_info->feature_support
 
407
          & GRUB_VIDEO_EDID_FEATURE_PREFERRED_TIMING_MODE)
 
408
      && edid_info->detailed_timings[0].pixel_clock)
 
409
    {
 
410
      *width = edid_info->detailed_timings[0].horizontal_active_lo
 
411
               | (((unsigned int)
 
412
                   (edid_info->detailed_timings[0].horizontal_hi & 0xf0))
 
413
                  << 4);
 
414
      *height = edid_info->detailed_timings[0].vertical_active_lo
 
415
                | (((unsigned int)
 
416
                    (edid_info->detailed_timings[0].vertical_hi & 0xf0))
 
417
                   << 4);
 
418
      if (*width && *height)
 
419
        return GRUB_ERR_NONE;
 
420
    }
 
421
 
 
422
  return grub_error (GRUB_ERR_BAD_DEVICE, "no preferred mode available");
 
423
}
 
424
 
379
425
/* Parse <width>x<height>[x<depth>]*/
380
426
static grub_err_t
381
427
parse_modespec (const char *current_mode, int *width, int *height, int *depth)
396
442
  param = grub_strchr(param, 'x');
397
443
  if (param == NULL)
398
444
    return grub_error (GRUB_ERR_BAD_ARGUMENT,
399
 
                       "Invalid mode: %s\n",
 
445
                       N_("invalid video mode specification `%s'"),
400
446
                       current_mode);
401
447
 
402
448
  param++;
404
450
  *width = grub_strtoul (value, 0, 0);
405
451
  if (grub_errno != GRUB_ERR_NONE)
406
452
      return grub_error (GRUB_ERR_BAD_ARGUMENT,
407
 
                         "Invalid mode: %s\n",
 
453
                         N_("invalid video mode specification `%s'"),
408
454
                         current_mode);
409
455
  
410
456
  /* Find height value.  */
415
461
      *height = grub_strtoul (value, 0, 0);
416
462
      if (grub_errno != GRUB_ERR_NONE)
417
463
        return grub_error (GRUB_ERR_BAD_ARGUMENT,
418
 
                           "Invalid mode: %s\n",
 
464
                           N_("invalid video mode specification `%s'"),
419
465
                           current_mode);
420
466
    }
421
467
  else
426
472
      *height = grub_strtoul (value, 0, 0);
427
473
      if (grub_errno != GRUB_ERR_NONE)
428
474
        return grub_error (GRUB_ERR_BAD_ARGUMENT,
429
 
                           "Invalid mode: %s\n",
 
475
                           N_("invalid video mode specification `%s'"),
430
476
                           current_mode);
431
477
      
432
478
      /* Convert color depth value.  */
434
480
      *depth = grub_strtoul (value, 0, 0);
435
481
      if (grub_errno != GRUB_ERR_NONE)
436
482
        return grub_error (GRUB_ERR_BAD_ARGUMENT,
437
 
                           "Invalid mode: %s\n",
 
483
                           N_("invalid video mode specification `%s'"),
438
484
                           current_mode);
439
485
    }
440
486
  return GRUB_ERR_NONE;
459
505
  next_mode = modevar;
460
506
 
461
507
  if (! modevar)
462
 
    return grub_error (GRUB_ERR_OUT_OF_MEMORY,
463
 
                       "couldn't allocate space for local modevar copy");
 
508
    return grub_errno;
464
509
 
465
510
  if (grub_memcmp (next_mode, "keep", sizeof ("keep")) == 0
466
511
      || grub_memcmp (next_mode, "keep,", sizeof ("keep,") - 1) == 0
496
541
        {
497
542
          grub_free (modevar);
498
543
 
 
544
          /* TRANSLATORS: This doesn't imply that there is no available video
 
545
             mode at all. All modes may have been filtered out by some criteria.
 
546
           */
499
547
          return grub_error (GRUB_ERR_BAD_ARGUMENT,
500
 
                             "no suitable mode found");
 
548
                             N_("no suitable video mode found"));
501
549
        }
502
550
 
503
551
      /* Skip separator. */
661
709
  grub_free (modevar);
662
710
 
663
711
  return grub_error (GRUB_ERR_BAD_ARGUMENT,
664
 
                     "no suitable mode found");
665
 
}
666
 
 
667
 
/* Initialize Video API module.  */
668
 
GRUB_MOD_INIT(video)
669
 
{
670
 
}
671
 
 
672
 
/* Finalize Video API module.  */
673
 
GRUB_MOD_FINI(video)
674
 
{
 
712
                     N_("no suitable video mode found"));
675
713
}