1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
commit b83f4c83f60e8cf5da52a10e2546fef20053d25c
Author: Sjoerd Simons <sjoerd@luon.net>
Date: Tue Sep 26 22:42:50 2006 +0200
Read out model and compatible property out of openfirmware if possible. And use the openfirmware module property to decide what formfactor the system has.
diff --git a/hald/linux/osspec.c b/hald/linux/osspec.c
index 8aca683..a2a1998 100644
--- a/hald/linux/osspec.c
+++ b/hald/linux/osspec.c
@@ -496,6 +496,70 @@ out:
hal_device_property_set_bool (d, "power_management.can_suspend_to_disk", can_hibernate);
}
+static void
+get_openfirmware_entry(HalDevice *d, char *property, char *entry,
+ gboolean multivalue) {
+ char *contents;
+ gsize length;
+ if (!g_file_get_contents(entry, &contents, &length, NULL)) {
+ return;
+ }
+ if (multivalue) {
+ gsize offset = 0;
+ while (offset < length) {
+ hal_device_property_strlist_append(d, property, contents + offset);
+ for (; offset < length - 1 && contents[offset] != '\0'; offset++)
+ ;
+ offset++;
+ }
+ } else {
+ hal_device_property_set_string(d, property, contents);
+ }
+ free(contents);
+}
+
+static void
+detect_openfirmware_formfactor(HalDevice *root) {
+ int x;
+ struct { gchar *model; gchar *formfactor; } model_formfactor[] =
+ {
+ { "RackMac" , "server" },
+ { "AAPL,3400" , "laptop" },
+ { "AAPL,3500" , "laptop" },
+ { "PowerBook" , "laptop" },
+ { "AAPL" , "desktop" },
+ { "iMac" , "desktop" },
+ { "PowerMac" , "desktop" },
+ {NULL, NULL }
+ };
+ const gchar *model =
+ hal_device_property_get_string(root, "openfirmware.model");
+ if (model == NULL)
+ return;
+
+ for (x = 0 ; model_formfactor[x].model ; x++) {
+ if (strstr(model, model_formfactor[x].model)) {
+ hal_device_property_set_string (root, "system.formfactor",
+ model_formfactor[x].formfactor);
+ break;
+ }
+ }
+}
+
+static void
+probe_openfirmware(HalDevice *root) {
+#define DEVICE_TREE "/proc/device-tree/"
+ if (!g_file_test(DEVICE_TREE, G_FILE_TEST_IS_DIR)) {
+ return;
+ }
+ get_openfirmware_entry(root, "openfirmware.model",
+ DEVICE_TREE "model", FALSE);
+ get_openfirmware_entry(root, "openfirmware.compatible",
+ DEVICE_TREE "compatible", TRUE);
+ detect_openfirmware_formfactor(root);
+}
+
+
void
osspec_probe (void)
{
@@ -547,12 +609,12 @@ osspec_probe (void)
*/
set_suspend_hibernate_keys (root);
- /* TODO: add prober for PowerMac's */
if (should_decode_dmi) {
hald_runner_run (root, "hald-probe-smbios", NULL, HAL_HELPER_TIMEOUT,
computer_probing_pcbios_helper_done, NULL, NULL);
} else {
/* no probing */
+ probe_openfirmware(root);
computer_probing_helper_done (root);
}
}
diff --git a/hald/linux/pmu.c b/hald/linux/pmu.c
index d2ce912..b43d5f0 100644
--- a/hald/linux/pmu.c
+++ b/hald/linux/pmu.c
@@ -381,9 +381,6 @@ pmu_synthesize_hotplug_events (void)
/* Add Laptop Panel */
snprintf (path, sizeof (path), "%s/pmu/info", get_hal_proc_path ());
pmu_synthesize_item (path, PMU_TYPE_LAPTOP_PANEL);
-
- /* If the machine has got battery bays then this is a laptop. */
- hal_device_property_set_string (computer, "system.formfactor", "laptop");
}
/* setup timer for things that we need to poll */
|