patches, patches, patches :)

Sjoerd Simons sjoerd at luon.net
Tue Sep 26 14:58:28 PDT 2006


On Tue, Sep 26, 2006 at 11:50:56PM +0200, Sjoerd Simons wrote:
> Hi,
> 
>   Some patches attached, including a changelog per patch. 
>   Please review and let me know if their okay to commit.

And ofcourse i forgot to actually attach anything.

  Sjoerd
-- 
Death is nature's way of saying `Howdy'.
-------------- next part --------------
commit 80b89a74fe53fb036b5826fbea4ebec18d3378c8
Author: Sjoerd Simons <sjoerd at luon.net>
Date:   Sun Sep 17 22:26:24 2006 +0200

    Set system.formfactor fallback in exactly one place instead of three and be
    carefull not to override if already set. Fixes bug on macintosh powerpc
    machines where the detected value was overriden by the fallback.

diff --git a/hald/linux/osspec.c b/hald/linux/osspec.c
index b9fb922..8aca683 100644
--- a/hald/linux/osspec.c
+++ b/hald/linux/osspec.c
@@ -346,6 +346,10 @@ hotplug_queue_now_empty (void)
 static void
 computer_probing_helper_done (HalDevice *d)
 {
+	/* if not set, set a default value */
+	if (!hal_device_has_property (d, "system.formfactor")) {
+		hal_device_property_set_string (d, "system.formfactor", "unknown");
+	}
 	di_search_and_merge (d, DEVICE_INFO_TYPE_INFORMATION);
 	di_search_and_merge (d, DEVICE_INFO_TYPE_POLICY);
 
@@ -363,9 +367,6 @@ computer_probing_pcbios_helper_done (Hal
 	const char *system_version;
 
 	if (exit_type == HALD_RUN_FAILED) {
-		/* set a default value */
-		if (!hal_device_has_property (d, "system.formfactor"))
-			hal_device_property_set_string (d, "system.formfactor", "unknown");
 		goto out;
 	}
 
@@ -433,10 +434,7 @@ computer_probing_pcbios_helper_done (Hal
 				}
 			}
 		       
-		} else {
-			/* set a default value */
-			hal_device_property_set_string (d, "system.formfactor", "unknown");
-		}
+		} 
 	}
 out:
 	computer_probing_helper_done (d);
@@ -554,11 +552,9 @@ osspec_probe (void)
 		hald_runner_run (root, "hald-probe-smbios", NULL, HAL_HELPER_TIMEOUT,
         	                 computer_probing_pcbios_helper_done, NULL, NULL);
 	} else {
-		/* set a default value, can be overridden by others */
-		hal_device_property_set_string (root, "system.formfactor", "unknown");
 		/* no probing */
 		computer_probing_helper_done (root);
-  	}
+	}
 }
 
 DBusHandlerResult
-------------- next part --------------
commit b83f4c83f60e8cf5da52a10e2546fef20053d25c
Author: Sjoerd Simons <sjoerd at 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,68 @@ 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");
+
+	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 */
-------------- next part --------------
commit 0a14231944a194b6bc31b737ff9b0dbec91edebc
Author: Sjoerd Simons <sjoerd at luon.net>
Date:   Sun Sep 17 20:25:25 2006 +0200

    Always set power_management.can_suspend to true if the power_management.type is
    pmu. Recent kernels don't report mem in /sys/power/state for ppc, but we have
    our own utility that issues ioctl's to suspend.

diff --git a/hald/linux/osspec.c b/hald/linux/osspec.c
index ed762a8..b9fb922 100644
--- a/hald/linux/osspec.c
+++ b/hald/linux/osspec.c
@@ -475,6 +475,11 @@ set_suspend_hibernate_keys (HalDevice *d
 		can_hibernate = TRUE;
 	free (poweroptions);
 
+	if (!strcmp(hal_device_property_get_string(d, "power_management.type"), "pmu")) {
+		/* We got our own helper for suspend PMU machines */
+		can_suspend = TRUE;
+	}
+
 	/* check for the presence of suspend2 */
 	if (access ("/proc/software_suspend", F_OK) == 0)
 		can_hibernate = TRUE;
-------------- next part --------------
commit 7b4b27aa607baf38d1e8d8b38d748cff2e5210e3
Author: Sjoerd Simons <sjoerd at luon.net>
Date:   Sun Sep 17 21:57:11 2006 +0200

    Let probe-smbios only return successfully if it actually got something
    usefull to parse

diff --git a/hald/linux/probing/probe-smbios.c b/hald/linux/probing/probe-smbios.c
index 2beb809..bb9ace3 100644
--- a/hald/linux/probing/probe-smbios.c
+++ b/hald/linux/probing/probe-smbios.c
@@ -140,7 +140,7 @@ main (int argc, char *argv[])
 		break;
 	case -1:
 		HAL_ERROR (("Cannot fork!"));
-		break;
+		goto out;
 	}
 	
 	/* parent continues from here */
@@ -199,6 +199,10 @@ main (int argc, char *argv[])
 		if (dmiparser_state == DMIPARSER_STATE_IGNORE)
 			continue;
 
+		/* return success only if there was something usefull to parse */
+		ret = 0;
+
+
 		/* removes the leading tab */
 		nbuf = &buf[1];
 
@@ -228,9 +232,6 @@ main (int argc, char *argv[])
 	/* as read to EOF, close */
 	fclose (f);
 
-	/* return success */
-	ret = 0;
-
 out:
 	/* free ctx */
 	if (ctx != NULL) {


More information about the hal mailing list