vaseboot/VasEBoot-core/lib/ieee1275/cmos.c

78 lines
2.3 KiB
C

/*
* VAS_EBOOT -- GRand Unified Bootloader
* Copyright (C) 2011 Free Software Foundation, Inc.
*
* VAS_EBOOT 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.
*
* VAS_EBOOT 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 VAS_EBOOT. If not, see <http://www.gnu.org/licenses/>.
*/
#include <VasEBoot/datetime.h>
#include <VasEBoot/cmos.h>
#include <VasEBoot/dl.h>
#include <VasEBoot/ieee1275/ieee1275.h>
#include <VasEBoot/misc.h>
volatile VasEBoot_uint8_t *VasEBoot_cmos_port = 0;
/* Helper for VasEBoot_cmos_find_port. */
static int
VasEBoot_cmos_find_port_iter (struct VasEBoot_ieee1275_devalias *alias)
{
VasEBoot_ieee1275_phandle_t dev;
VasEBoot_uint32_t addr[2];
VasEBoot_ssize_t actual;
/* Enough to check if it's "m5819" */
char compat[100];
if (VasEBoot_ieee1275_finddevice (alias->path, &dev))
return 0;
if (VasEBoot_ieee1275_get_property (dev, "compatible", compat, sizeof (compat),
0))
return 0;
if (VasEBoot_strcmp (compat, "m5819") != 0)
return 0;
if (VasEBoot_ieee1275_get_integer_property (dev, "address",
addr, sizeof (addr), &actual))
return 0;
if (actual == 4)
{
VasEBoot_cmos_port = (volatile VasEBoot_uint8_t *) (VasEBoot_addr_t) addr[0];
return 1;
}
#if VAS_EBOOT_CPU_SIZEOF_VOID_P == 8
if (actual == 8)
{
VasEBoot_cmos_port = (volatile VasEBoot_uint8_t *)
((((VasEBoot_addr_t) addr[0]) << 32) | addr[1]);
return 1;
}
#else
if (actual == 8 && addr[0] == 0)
{
VasEBoot_cmos_port = (volatile VasEBoot_uint8_t *) addr[1];
return 1;
}
#endif
return 0;
}
VasEBoot_err_t
VasEBoot_cmos_find_port (void)
{
VasEBoot_ieee1275_devices_iterate (VasEBoot_cmos_find_port_iter);
if (!VasEBoot_cmos_port)
return VasEBoot_error (VAS_EBOOT_ERR_IO, "no cmos found");
return VAS_EBOOT_ERR_NONE;
}