Esempio n. 1
0
grub_err_t
grub_set_datetime (struct grub_datetime *datetime)
{
  grub_efi_status_t status;
  struct grub_efi_time efi_time;

  status = efi_call_2 (grub_efi_system_table->runtime_services->get_time,
                       &efi_time, 0);

  if (status)
    return grub_error (GRUB_ERR_INVALID_COMMAND,
                       "can\'t get datetime using efi");

  efi_time.year = datetime->year;
  efi_time.month = datetime->month;
  efi_time.day = datetime->day;
  efi_time.hour = datetime->hour;
  efi_time.minute = datetime->minute;
  efi_time.second = datetime->second;

  status = efi_call_1 (grub_efi_system_table->runtime_services->set_time,
                       &efi_time);

  if (status)
    return grub_error (GRUB_ERR_INVALID_COMMAND,
                       "can\'t set datetime using efi");

  return 0;
}
Esempio n. 2
0
/* Free pages starting from ADDRESS.  */
void
grub_efi_free_pages (grub_efi_physical_address_t address,
		     grub_efi_uintn_t pages)
{
  grub_efi_boot_services_t *b;

  b = grub_efi_system_table->boot_services;
  efi_call_2 (b->free_pages, address, pages);
}
Esempio n. 3
0
static grub_err_t
grub_video_gop_fini (void)
{
  if (restore_needed)
    {
      efi_call_2 (gop->set_mode, gop, old_mode);
      restore_needed = 0;
    }
  return grub_video_fb_fini ();
}
Esempio n. 4
0
int
grub_efi_exit_boot_services (grub_efi_uintn_t map_key)
{
  grub_efi_boot_services_t *b;
  grub_efi_status_t status;

  b = grub_efi_system_table->boot_services;
  status = efi_call_2 (b->exit_boot_services, grub_efi_image_handle, map_key);
  return status == GRUB_EFI_SUCCESS;
}
Esempio n. 5
0
static grub_efi_boolean_t grub_tpm2_present(grub_efi_tpm2_protocol_t *tpm)
{
  grub_efi_status_t status;
  EFI_TCG2_BOOT_SERVICE_CAPABILITY caps;

  caps.Size = (grub_uint8_t)sizeof(caps);

  status = efi_call_2(tpm->get_capability, tpm, &caps);

  if (status != GRUB_EFI_SUCCESS || !caps.TPMPresentFlag)
    return 0;

  return 1;
}
Esempio n. 6
0
grub_uint32_t
grub_get_rtc (void)
{
  grub_efi_time_t time;
  grub_efi_runtime_services_t *r;

  r = grub_efi_system_table->runtime_services;
  if (efi_call_2 (r->get_time, &time, 0) != GRUB_EFI_SUCCESS)
    /* What is possible in this case?  */
    return 0;

  return (((time.minute * 60 + time.second) * 1000
	   + time.nanosecond / 1000000)
	  * GRUB_TICKS_PER_SECOND / 1000);
}
Esempio n. 7
0
File: efi.c Progetto: Arvian/GRUB2
int
grub_efi_set_text_mode (int on)
{
  grub_efi_console_control_protocol_t *c;
  grub_efi_screen_mode_t mode, new_mode;

  c = grub_efi_locate_protocol (&console_control_guid, 0);
  if (! c)
    /* No console control protocol instance available, assume it is
       already in text mode. */
    return 1;

  if (efi_call_4 (c->get_mode, c, &mode, 0, 0) != GRUB_EFI_SUCCESS)
    return 0;

  new_mode = on ? GRUB_EFI_SCREEN_TEXT : GRUB_EFI_SCREEN_GRAPHICS;
  if (mode != new_mode)
    if (efi_call_2 (c->set_mode, c, new_mode) != GRUB_EFI_SUCCESS)
      return 0;

  return 1;
}
Esempio n. 8
0
static grub_err_t
grub_video_gop_setup (unsigned int width, unsigned int height,
		      unsigned int mode_type,
		      unsigned int mode_mask __attribute__ ((unused)))
{
  unsigned int depth;
  struct grub_efi_gop_mode_info *info = NULL;
  unsigned best_mode = 0;
  grub_err_t err;
  unsigned bpp;
  int found = 0;
  unsigned long long best_volume = 0;

  depth = (mode_type & GRUB_VIDEO_MODE_TYPE_DEPTH_MASK)
    >> GRUB_VIDEO_MODE_TYPE_DEPTH_POS;

  /* Keep current mode if possible.  */
  if (gop->mode->info)
    {
      bpp = grub_video_gop_get_bpp (gop->mode->info);
      if (bpp && ((width == gop->mode->info->width
		   && height == gop->mode->info->height)
		  || (width == 0 && height == 0))
	  && (depth == bpp || depth == 0))
	{
	  grub_dprintf ("video", "GOP: keeping mode %d\n", gop->mode->mode);
	  best_mode = gop->mode->mode;
	  found = 1;
	}
    }
 
  if (!found)
    {
      unsigned mode;
      grub_dprintf ("video", "GOP: %d modes detected\n", gop->mode->max_mode);
      for (mode = 0; mode < gop->mode->max_mode; mode++)
	{
	  grub_efi_uintn_t size;
	  grub_efi_status_t status;
	 
	  status = efi_call_4 (gop->query_mode, gop, mode, &size, &info);
	  if (status)
	    {
	      info = 0;
	      continue;
	    }

	  grub_dprintf ("video", "GOP: mode %d: %dx%d\n", mode, info->width,
			info->height);

	  bpp = grub_video_gop_get_bpp (info);
	  if (!bpp)
	    {
	      grub_dprintf ("video", "GOP: mode %d: incompatible pixel mode\n",
			    mode);
	      continue;
	    }

	  grub_dprintf ("video", "GOP: mode %d: depth %d\n", mode, bpp);

	  if (!(((info->width == width && info->height == height)
		|| (width == 0 && height == 0))
		&& (bpp == depth || depth == 0)))
	    {
	      grub_dprintf ("video", "GOP: mode %d: rejected\n", mode);
	      continue;
	    }

	  if (best_volume < ((unsigned long long) info->width)
	      * ((unsigned long long) info->height)
	      * ((unsigned long long) bpp))
	    {
	      best_volume = ((unsigned long long) info->width)
		* ((unsigned long long) info->height)
		* ((unsigned long long) bpp);
	      best_mode = mode;
	    }
	  found = 1;
	}
    }

  if (!found)
    {
      grub_dprintf ("video", "GOP: no mode found\n");
      return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no matching mode found");
    }

  if (best_mode != gop->mode->mode)
    {
      if (!restore_needed)
	{
	  old_mode = gop->mode->mode;
	  restore_needed = 1;
	}
      efi_call_2 (gop->set_mode, gop, best_mode);
    }

  info = gop->mode->info;

  err = grub_video_gop_fill_mode_info (gop->mode->mode, info,
				       &framebuffer.mode_info);
  if (err)
    {
      grub_dprintf ("video", "GOP: couldn't fill mode info\n");
      return err;
    }

  framebuffer.ptr = (void *) (grub_addr_t) gop->mode->fb_base;

  grub_dprintf ("video", "GOP: initialising FB @ %p %dx%dx%d\n",
		framebuffer.ptr, framebuffer.mode_info.width,
		framebuffer.mode_info.height, framebuffer.mode_info.bpp);
 
  err = grub_video_fb_create_render_target_from_pointer
    (&framebuffer.render_target, &framebuffer.mode_info, framebuffer.ptr);

  if (err)
    {
      grub_dprintf ("video", "GOP: Couldn't create FB target\n");
      return err;
    }
 
  err = grub_video_fb_set_active_render_target (framebuffer.render_target);
 
  if (err)
    {
      grub_dprintf ("video", "GOP: Couldn't set FB target\n");
      return err;
    }
 
  err = grub_video_fb_set_palette (0, GRUB_VIDEO_FBSTD_NUMCOLORS,
				   grub_video_fbstd_colors);

  if (err)
    grub_dprintf ("video", "GOP: Couldn't set palette\n");
  else
    grub_dprintf ("video", "GOP: Success\n");
 
  return err;
}