Upgraded GRUB2 to 2.00 release.
[AROS.git] / arch / all-pc / boot / grub2-aros / grub-core / lib / ieee1275 / cmos.c
blobfa57db9e7156678b33a2d1564896fdc5f468813b
1 /*
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>
21 #include <grub/dl.h>
22 #include <grub/ieee1275/ieee1275.h>
23 #include <grub/misc.h>
25 volatile grub_uint8_t *grub_cmos_port = 0;
26 grub_err_t
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];
34 grub_ssize_t actual;
35 /* Enough to check if it's "m5819" */
36 char compat[100];
37 if (grub_ieee1275_finddevice (alias->path, &dev))
38 return 0;
39 if (grub_ieee1275_get_property (dev, "compatible", compat, sizeof (compat),
40 0))
41 return 0;
42 if (grub_strcmp (compat, "m5819") != 0)
43 return 0;
44 if (grub_ieee1275_get_integer_property (dev, "address",
45 addr, sizeof (addr), &actual))
46 return 0;
47 if (actual == 4)
49 grub_cmos_port = (volatile grub_uint8_t *) (grub_addr_t) addr[0];
50 return 1;
53 #if GRUB_CPU_SIZEOF_VOID_P == 8
54 if (actual == 8)
56 grub_cmos_port = (volatile grub_uint8_t *)
57 ((((grub_addr_t) addr[0]) << 32) | addr[1]);
58 return 1;
60 #else
61 if (actual == 8 && addr[0] == 0)
63 grub_cmos_port = (volatile grub_uint8_t *) addr[1];
64 return 1;
66 #endif
67 return 0;
70 grub_ieee1275_devices_iterate (hook);
71 if (!grub_cmos_port)
72 return grub_error (GRUB_ERR_IO, "no cmos found");
74 return GRUB_ERR_NONE;