mirror of
				https://git.proxmox.com/git/grub2
				synced 2025-11-04 14:51:07 +00:00 
			
		
		
		
	* gentpl.py (cmos): Add powerpc and sparc. * grub-core/Makefile.core.def (datetime): Add lib/ieee1275/cmos.c on powerpc and sparc. * grub-core/lib/cmos_datetime.c (grub_get_datetime) [__powerpc__ || __sparc__]: Rename to grub_get_datetime_cmos. (grub_set_datetime) [__powerpc__ || __sparc__]: Likewise to grub_set_datetime_cmos. * grub-core/lib/ieee1275/cmos.c: New file. * grub-core/lib/ieee1275/datetime.c (no_ieee1275_rtc): New vaiable. (find_rtc): Set no_ieee1275_rtc on error. (grub_get_datetime): Call grub_get_datetime_cmos on error. (grub_set_datetime): Call grub_set_datetime_cmos on error. * include/grub/cmos.h (grub_cmos_read): Return grub_err_t since it may fail. Move value to argument. All users updated (grub_cmos_write): Likewise. (grub_cmos_read) [__powerpc__ || __sparc__]: Rewritten. (grub_cmos_write) [__powerpc__ || __sparc__]: Likewise. * include/grub/datetime.h [__powerpc__ || __sparc__]: Declare grub_get_datetime_cmos and grub_set_datetime_cmos.
		
			
				
	
	
		
			113 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			113 lines
		
	
	
		
			2.8 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/*
 | 
						|
 *  GRUB  --  GRand Unified Bootloader
 | 
						|
 *  Copyright (C) 2008, 2009  Free Software Foundation, Inc.
 | 
						|
 *
 | 
						|
 *  GRUB is free software: you can redistribute it and/or modify
 | 
						|
 *  it under the terms of the GNU General Public License as published by
 | 
						|
 *  the Free Software Foundation, either version 3 of the License, or
 | 
						|
 *  (at your option) any later version.
 | 
						|
 *
 | 
						|
 *  GRUB is distributed in the hope that it will be useful,
 | 
						|
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
						|
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
						|
 *  GNU General Public License for more details.
 | 
						|
 *
 | 
						|
 *  You should have received a copy of the GNU General Public License
 | 
						|
 *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
 | 
						|
 */
 | 
						|
 | 
						|
#ifndef	GRUB_CMOS_H
 | 
						|
#define	GRUB_CMOS_H	1
 | 
						|
 | 
						|
#include <grub/types.h>
 | 
						|
#if !defined (__powerpc__) && !defined (__sparc__)
 | 
						|
#include <grub/cpu/io.h>
 | 
						|
#include <grub/cpu/cmos.h>
 | 
						|
#endif
 | 
						|
 | 
						|
#define GRUB_CMOS_INDEX_SECOND		0
 | 
						|
#define GRUB_CMOS_INDEX_SECOND_ALARM	1
 | 
						|
#define GRUB_CMOS_INDEX_MINUTE		2
 | 
						|
#define GRUB_CMOS_INDEX_MINUTE_ALARM	3
 | 
						|
#define GRUB_CMOS_INDEX_HOUR		4
 | 
						|
#define GRUB_CMOS_INDEX_HOUR_ALARM	5
 | 
						|
#define GRUB_CMOS_INDEX_DAY_OF_WEEK	6
 | 
						|
#define GRUB_CMOS_INDEX_DAY_OF_MONTH	7
 | 
						|
#define GRUB_CMOS_INDEX_MONTH		8
 | 
						|
#define GRUB_CMOS_INDEX_YEAR		9
 | 
						|
 | 
						|
#define GRUB_CMOS_INDEX_STATUS_A	0xA
 | 
						|
#define GRUB_CMOS_INDEX_STATUS_B	0xB
 | 
						|
#define GRUB_CMOS_INDEX_STATUS_C	0xC
 | 
						|
#define GRUB_CMOS_INDEX_STATUS_D	0xD
 | 
						|
 | 
						|
#define GRUB_CMOS_STATUS_B_DAYLIGHT	1
 | 
						|
#define GRUB_CMOS_STATUS_B_24HOUR	2
 | 
						|
#define GRUB_CMOS_STATUS_B_BINARY	4
 | 
						|
 | 
						|
static inline grub_uint8_t
 | 
						|
grub_bcd_to_num (grub_uint8_t a)
 | 
						|
{
 | 
						|
  return ((a >> 4) * 10 + (a & 0xF));
 | 
						|
}
 | 
						|
 | 
						|
static inline grub_uint8_t
 | 
						|
grub_num_to_bcd (grub_uint8_t a)
 | 
						|
{
 | 
						|
  return (((a / 10) << 4) + (a % 10));
 | 
						|
}
 | 
						|
 | 
						|
#if !defined (__powerpc__) && !defined (__sparc__)
 | 
						|
static inline grub_err_t
 | 
						|
grub_cmos_read (grub_uint8_t index, grub_uint8_t *val)
 | 
						|
{
 | 
						|
  grub_outb (index, GRUB_CMOS_ADDR_REG);
 | 
						|
  *val = grub_inb (GRUB_CMOS_DATA_REG);
 | 
						|
  return GRUB_ERR_NONE;
 | 
						|
}
 | 
						|
 | 
						|
static inline grub_err_t
 | 
						|
grub_cmos_write (grub_uint8_t index, grub_uint8_t value)
 | 
						|
{
 | 
						|
  grub_outb (index, GRUB_CMOS_ADDR_REG);
 | 
						|
  grub_outb (value, GRUB_CMOS_DATA_REG);
 | 
						|
  return GRUB_ERR_NONE;
 | 
						|
}
 | 
						|
#else
 | 
						|
grub_err_t grub_cmos_find_port (void);
 | 
						|
extern volatile grub_uint8_t *grub_cmos_port;
 | 
						|
 | 
						|
static inline grub_err_t
 | 
						|
grub_cmos_read (grub_uint8_t index, grub_uint8_t *val)
 | 
						|
{
 | 
						|
  if (!grub_cmos_port)
 | 
						|
    {
 | 
						|
      grub_err_t err;
 | 
						|
      err = grub_cmos_find_port ();
 | 
						|
      if (err)
 | 
						|
	return err;
 | 
						|
    }
 | 
						|
  grub_cmos_port[0] = index;
 | 
						|
  *val = grub_cmos_port[1];
 | 
						|
  return GRUB_ERR_NONE;
 | 
						|
}
 | 
						|
 | 
						|
static inline grub_err_t
 | 
						|
grub_cmos_write (grub_uint8_t index, grub_uint8_t val)
 | 
						|
{
 | 
						|
  if (!grub_cmos_port)
 | 
						|
    {
 | 
						|
      grub_err_t err;
 | 
						|
      err = grub_cmos_find_port ();
 | 
						|
      if (err)
 | 
						|
	return err;
 | 
						|
    }
 | 
						|
  grub_cmos_port[0] = index;
 | 
						|
  grub_cmos_port[1] = val;
 | 
						|
  return GRUB_ERR_NONE;
 | 
						|
}
 | 
						|
 | 
						|
#endif
 | 
						|
 | 
						|
#endif /* GRUB_CMOS_H */
 |