2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2011 Free Software Foundation, Inc.
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.
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.
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/>.
19 #include <grub/datetime.h>
20 #include <grub/cmos.h>
22 #include <grub/ieee1275/ieee1275.h>
23 #include <grub/misc.h>
25 volatile grub_uint8_t
*grub_cmos_port
= 0;
27 grub_cmos_find_port (void)
29 auto int hook (struct grub_ieee1275_devalias
*alias
);
30 int hook (struct grub_ieee1275_devalias
*alias
)
32 grub_ieee1275_phandle_t dev
;
33 grub_uint32_t addr
[2];
35 /* Enough to check if it's "m5819" */
37 if (grub_ieee1275_finddevice (alias
->path
, &dev
))
39 if (grub_ieee1275_get_property (dev
, "compatible", compat
, sizeof (compat
),
42 if (grub_strcmp (compat
, "m5819") != 0)
44 if (grub_ieee1275_get_integer_property (dev
, "address",
45 addr
, sizeof (addr
), &actual
))
49 grub_cmos_port
= (volatile grub_uint8_t
*) (grub_addr_t
) addr
[0];
53 #if GRUB_CPU_SIZEOF_VOID_P == 8
56 grub_cmos_port
= (volatile grub_uint8_t
*)
57 ((((grub_addr_t
) addr
[0]) << 32) | addr
[1]);
61 if (actual
== 8 && addr
[0] == 0)
63 grub_cmos_port
= (volatile grub_uint8_t
*) addr
[1];
70 grub_ieee1275_devices_iterate (hook
);
72 return grub_error (GRUB_ERR_IO
, "no cmos found");