All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/8] acpi: Rename v1 DSM to mux to avoid ambiguity
@ 2015-05-25 22:22 Pierre Moreau
       [not found] ` <1432592573-13743-1-git-send-email-pierre.morrow-GANU6spQydw@public.gmane.org>
                   ` (5 more replies)
  0 siblings, 6 replies; 24+ messages in thread
From: Pierre Moreau @ 2015-05-25 22:22 UTC (permalink / raw)
  To: nouveau; +Cc: bskeggs, dri-devel

This is especially true when variables or functions are just called dsm without
precising the v1.

Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>
---
 drm/nouveau/nouveau_acpi.c | 64 +++++++++++++++++++++++-----------------------
 drm/nouveau/nouveau_acpi.h |  4 +--
 drm/nouveau/nouveau_drm.c  |  4 +--
 drm/nouveau/nouveau_vga.c  | 10 ++++----
 4 files changed, 41 insertions(+), 41 deletions(-)

diff --git a/drm/nouveau/nouveau_acpi.c b/drm/nouveau/nouveau_acpi.c
index 6224246..4a48e21 100644
--- a/drm/nouveau/nouveau_acpi.c
+++ b/drm/nouveau/nouveau_acpi.c
@@ -9,16 +9,16 @@
 #include "nouveau_drm.h"
 #include "nouveau_acpi.h"
 
-#define NOUVEAU_DSM_LED 0x02
-#define NOUVEAU_DSM_LED_STATE 0x00
-#define NOUVEAU_DSM_LED_OFF 0x10
-#define NOUVEAU_DSM_LED_STAMINA 0x11
-#define NOUVEAU_DSM_LED_SPEED 0x12
+#define NOUVEAU_DSM_MUX_LED 0x02
+#define NOUVEAU_DSM_MUX_LED_STATE 0x00
+#define NOUVEAU_DSM_MUX_LED_OFF 0x10
+#define NOUVEAU_DSM_MUX_LED_STAMINA 0x11
+#define NOUVEAU_DSM_MUX_LED_SPEED 0x12
 
-#define NOUVEAU_DSM_POWER 0x03
-#define NOUVEAU_DSM_POWER_STATE 0x00
-#define NOUVEAU_DSM_POWER_SPEED 0x01
-#define NOUVEAU_DSM_POWER_STAMINA 0x02
+#define NOUVEAU_DSM_MUX_POWER 0x03
+#define NOUVEAU_DSM_MUX_POWER_STATE 0x00
+#define NOUVEAU_DSM_MUX_POWER_SPEED 0x01
+#define NOUVEAU_DSM_MUX_POWER_STAMINA 0x02
 
 #define NOUVEAU_DSM_OPTIMUS_CAPS 0x1A
 #define NOUVEAU_DSM_OPTIMUS_FLAGS 0x1B
@@ -43,7 +43,7 @@
 #define OPTIMUS_HDA_CODEC_MASK (2 << 27) /* hda bios control */
 
 static struct nouveau_dsm_priv {
-	bool dsm_detected;
+	bool mux_detected;
 	bool optimus_detected;
 	acpi_handle dhandle;
 	acpi_handle rom_handle;
@@ -53,15 +53,15 @@ bool nouveau_is_optimus(void) {
 	return nouveau_dsm_priv.optimus_detected;
 }
 
-bool nouveau_is_v1_dsm(void) {
-	return nouveau_dsm_priv.dsm_detected;
+bool nouveau_has_mux(void) {
+	return nouveau_dsm_priv.mux_detected;
 }
 
 #define NOUVEAU_DSM_HAS_MUX 0x1
 #define NOUVEAU_DSM_HAS_OPT 0x2
 
 #ifdef CONFIG_VGA_SWITCHEROO
-static const char nouveau_dsm_muid[] = {
+static const char nouveau_mux_dsm_muid[] = {
 	0xA0, 0xA0, 0x95, 0x9D, 0x60, 0x00, 0x48, 0x4D,
 	0xB3, 0x4D, 0x7E, 0x5F, 0xEA, 0x12, 0x9F, 0xD4,
 };
@@ -128,7 +128,7 @@ static int nouveau_check_optimus_dsm(acpi_handle handle)
 	return result & 1 && result & (1 << NOUVEAU_DSM_OPTIMUS_CAPS);
 }
 
-static int nouveau_dsm(acpi_handle handle, int func, int arg)
+static int nouveau_mux_dsm(acpi_handle handle, int func, int arg)
 {
 	int ret = 0;
 	union acpi_object *obj;
@@ -137,7 +137,7 @@ static int nouveau_dsm(acpi_handle handle, int func, int arg)
 		.integer.value = arg,
 	};
 
-	obj = acpi_evaluate_dsm_typed(handle, nouveau_dsm_muid, 0x00000102,
+	obj = acpi_evaluate_dsm_typed(handle, nouveau_mux_dsm_muid, 0x00000102,
 				      func, &argv4, ACPI_TYPE_INTEGER);
 	if (!obj) {
 		acpi_handle_info(handle, "failed to evaluate _DSM\n");
@@ -153,30 +153,30 @@ static int nouveau_dsm(acpi_handle handle, int func, int arg)
 
 static int nouveau_dsm_switch_mux(acpi_handle handle, int mux_id)
 {
-	mxm_wmi_call_mxmx(mux_id == NOUVEAU_DSM_LED_STAMINA ? MXM_MXDS_ADAPTER_IGD : MXM_MXDS_ADAPTER_0);
-	mxm_wmi_call_mxds(mux_id == NOUVEAU_DSM_LED_STAMINA ? MXM_MXDS_ADAPTER_IGD : MXM_MXDS_ADAPTER_0);
-	return nouveau_dsm(handle, NOUVEAU_DSM_LED, mux_id);
+	mxm_wmi_call_mxmx(mux_id == NOUVEAU_DSM_MUX_LED_STAMINA ? MXM_MXDS_ADAPTER_IGD : MXM_MXDS_ADAPTER_0);
+	mxm_wmi_call_mxds(mux_id == NOUVEAU_DSM_MUX_LED_STAMINA ? MXM_MXDS_ADAPTER_IGD : MXM_MXDS_ADAPTER_0);
+	return nouveau_mux_dsm(handle, NOUVEAU_DSM_MUX_LED, mux_id);
 }
 
 static int nouveau_dsm_set_discrete_state(acpi_handle handle, enum vga_switcheroo_state state)
 {
 	int arg;
 	if (state == VGA_SWITCHEROO_ON)
-		arg = NOUVEAU_DSM_POWER_SPEED;
+		arg = NOUVEAU_DSM_MUX_POWER_SPEED;
 	else
-		arg = NOUVEAU_DSM_POWER_STAMINA;
-	nouveau_dsm(handle, NOUVEAU_DSM_POWER, arg);
+		arg = NOUVEAU_DSM_MUX_POWER_STAMINA;
+	nouveau_mux_dsm(handle, NOUVEAU_DSM_MUX_POWER, arg);
 	return 0;
 }
 
 static int nouveau_dsm_switchto(enum vga_switcheroo_client_id id)
 {
-	if (!nouveau_dsm_priv.dsm_detected)
+	if (!nouveau_dsm_priv.mux_detected)
 		return 0;
 	if (id == VGA_SWITCHEROO_IGD)
-		return nouveau_dsm_switch_mux(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_LED_STAMINA);
+		return nouveau_dsm_switch_mux(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_MUX_LED_STAMINA);
 	else
-		return nouveau_dsm_switch_mux(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_LED_SPEED);
+		return nouveau_dsm_switch_mux(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_MUX_LED_SPEED);
 }
 
 static int nouveau_dsm_power_state(enum vga_switcheroo_client_id id,
@@ -187,7 +187,7 @@ static int nouveau_dsm_power_state(enum vga_switcheroo_client_id id,
 
 	/* Optimus laptops have the card already disabled in
 	 * nouveau_switcheroo_set_state */
-	if (!nouveau_dsm_priv.dsm_detected)
+	if (!nouveau_dsm_priv.mux_detected)
 		return 0;
 
 	return nouveau_dsm_set_discrete_state(nouveau_dsm_priv.dhandle, state);
@@ -224,8 +224,8 @@ static int nouveau_dsm_pci_probe(struct pci_dev *pdev)
 	if (!acpi_has_method(dhandle, "_DSM"))
 		return false;
 
-	if (acpi_check_dsm(dhandle, nouveau_dsm_muid, 0x00000102,
-			   1 << NOUVEAU_DSM_POWER))
+	if (acpi_check_dsm(dhandle, nouveau_mux_dsm_muid, 0x00000102,
+			   1 << NOUVEAU_DSM_MUX_POWER))
 		retval |= NOUVEAU_DSM_HAS_MUX;
 
 	if (nouveau_check_optimus_dsm(dhandle))
@@ -285,7 +285,7 @@ static bool nouveau_dsm_detect(void)
 			has_optimus = 1;
 	}
 
-	/* find the optimus DSM or the old v1 DSM */
+	/* find the optimus DSM or the mux DSM */
 	if (has_optimus == 1) {
 		acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
 			&buffer);
@@ -296,9 +296,9 @@ static bool nouveau_dsm_detect(void)
 	} else if (vga_count == 2 && has_dsm && guid_valid) {
 		acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
 			&buffer);
-		printk(KERN_INFO "VGA switcheroo: detected DSM switching method %s handle\n",
+		printk(KERN_INFO "VGA switcheroo: detected mux DSM switching method %s handle\n",
 			acpi_method_name);
-		nouveau_dsm_priv.dsm_detected = true;
+		nouveau_dsm_priv.mux_detected = true;
 		ret = true;
 	}
 
@@ -328,13 +328,13 @@ void nouveau_switcheroo_optimus_dsm(void)
 			    0x3, &result);
 
 	nouveau_optimus_dsm(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_OPTIMUS_CAPS,
-		NOUVEAU_DSM_OPTIMUS_SET_POWERDOWN, &result);
+			    NOUVEAU_DSM_OPTIMUS_SET_POWERDOWN, &result);
 
 }
 
 void nouveau_unregister_dsm_handler(void)
 {
-	if (nouveau_dsm_priv.optimus_detected || nouveau_dsm_priv.dsm_detected)
+	if (nouveau_dsm_priv.optimus_detected || nouveau_dsm_priv.mux_detected)
 		vga_switcheroo_unregister_handler();
 }
 #else
diff --git a/drm/nouveau/nouveau_acpi.h b/drm/nouveau/nouveau_acpi.h
index 74acf0f..2bd88a8 100644
--- a/drm/nouveau/nouveau_acpi.h
+++ b/drm/nouveau/nouveau_acpi.h
@@ -5,7 +5,7 @@
 
 #if defined(CONFIG_ACPI) && defined(CONFIG_X86)
 bool nouveau_is_optimus(void);
-bool nouveau_is_v1_dsm(void);
+bool nouveau_has_mux(void);
 void nouveau_register_dsm_handler(void);
 void nouveau_unregister_dsm_handler(void);
 void nouveau_switcheroo_optimus_dsm(void);
@@ -14,7 +14,7 @@ bool nouveau_acpi_rom_supported(struct pci_dev *pdev);
 void *nouveau_acpi_edid(struct drm_device *, struct drm_connector *);
 #else
 static inline bool nouveau_is_optimus(void) { return false; };
-static inline bool nouveau_is_v1_dsm(void) { return false; };
+static inline bool nouveau_has_mux(void) { return false; };
 static inline void nouveau_register_dsm_handler(void) {}
 static inline void nouveau_unregister_dsm_handler(void) {}
 static inline void nouveau_switcheroo_optimus_dsm(void) {}
diff --git a/drm/nouveau/nouveau_drm.c b/drm/nouveau/nouveau_drm.c
index 8904933..c06a7a1 100644
--- a/drm/nouveau/nouveau_drm.c
+++ b/drm/nouveau/nouveau_drm.c
@@ -719,7 +719,7 @@ nouveau_pmops_runtime_suspend(struct device *dev)
 	}
 
 	/* are we optimus enabled? */
-	if (nouveau_runtime_pm == -1 && !nouveau_is_optimus() && !nouveau_is_v1_dsm()) {
+	if (nouveau_runtime_pm == -1 && !nouveau_is_optimus() && !nouveau_has_mux()) {
 		DRM_DEBUG_DRIVER("failing to power off - not optimus\n");
 		pm_runtime_forbid(dev);
 		return -EBUSY;
@@ -780,7 +780,7 @@ nouveau_pmops_runtime_idle(struct device *dev)
 	}
 
 	/* are we optimus enabled? */
-	if (nouveau_runtime_pm == -1 && !nouveau_is_optimus() && !nouveau_is_v1_dsm()) {
+	if (nouveau_runtime_pm == -1 && !nouveau_is_optimus() && !nouveau_has_mux()) {
 		DRM_DEBUG_DRIVER("failing to power off - not optimus\n");
 		pm_runtime_forbid(dev);
 		return -EBUSY;
diff --git a/drm/nouveau/nouveau_vga.c b/drm/nouveau/nouveau_vga.c
index c7592ec..6297566 100644
--- a/drm/nouveau/nouveau_vga.c
+++ b/drm/nouveau/nouveau_vga.c
@@ -36,7 +36,7 @@ nouveau_switcheroo_set_state(struct pci_dev *pdev,
 {
 	struct drm_device *dev = pci_get_drvdata(pdev);
 
-	if ((nouveau_is_optimus() || nouveau_is_v1_dsm()) && state == VGA_SWITCHEROO_OFF)
+	if ((nouveau_is_optimus() || nouveau_has_mux()) && state == VGA_SWITCHEROO_OFF)
 		return;
 
 	if (state == VGA_SWITCHEROO_ON) {
@@ -96,11 +96,11 @@ nouveau_vga_init(struct nouveau_drm *drm)
 
 	if (nouveau_runtime_pm == 1)
 		runtime = true;
-	if ((nouveau_runtime_pm == -1) && (nouveau_is_optimus() || nouveau_is_v1_dsm()))
+	if ((nouveau_runtime_pm == -1) && (nouveau_is_optimus() || nouveau_has_mux()))
 		runtime = true;
 	vga_switcheroo_register_client(dev->pdev, &nouveau_switcheroo_ops, runtime);
 
-	if (runtime && nouveau_is_v1_dsm() && !nouveau_is_optimus())
+	if (runtime && nouveau_has_mux() && !nouveau_is_optimus())
 		vga_switcheroo_init_domain_pm_ops(drm->dev->dev, &drm->vga_pm_domain);
 }
 
@@ -112,11 +112,11 @@ nouveau_vga_fini(struct nouveau_drm *drm)
 
 	if (nouveau_runtime_pm == 1)
 		runtime = true;
-	if ((nouveau_runtime_pm == -1) && (nouveau_is_optimus() || nouveau_is_v1_dsm()))
+	if ((nouveau_runtime_pm == -1) && (nouveau_is_optimus() || nouveau_has_mux()))
 		runtime = true;
 
 	vga_switcheroo_unregister_client(dev->pdev);
-	if (runtime && nouveau_is_v1_dsm() && !nouveau_is_optimus())
+	if (runtime && nouveau_has_mux() && !nouveau_is_optimus())
 		vga_switcheroo_fini_domain_pm_ops(drm->dev->dev);
 	vga_client_register(dev->pdev, NULL, NULL, NULL);
 }
-- 
2.4.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 2/8] acpi: Add evaluate to functons evaluating _DSM
       [not found] ` <1432592573-13743-1-git-send-email-pierre.morrow-GANU6spQydw@public.gmane.org>
@ 2015-05-25 22:22   ` Pierre Moreau
       [not found]     ` <1432592573-13743-2-git-send-email-pierre.morrow-GANU6spQydw@public.gmane.org>
  2015-05-25 22:22   ` [PATCH 5/8] acpi: Check returned object type by Optimus _DSM locally Pierre Moreau
  2015-05-25 22:22   ` [PATCH 8/8] acpi: Use booleans when probing different _DSM types Pierre Moreau
  2 siblings, 1 reply; 24+ messages in thread
From: Pierre Moreau @ 2015-05-25 22:22 UTC (permalink / raw)
  To: nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
  Cc: bskeggs-H+wXaHxf7aLQT0dZR+AlfA,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

This makes it clearer when reading the function name, as well as following the
names of the related ACPI function.

Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>
---
 drm/nouveau/nouveau_acpi.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/drm/nouveau/nouveau_acpi.c b/drm/nouveau/nouveau_acpi.c
index 4a48e21..1f18018 100644
--- a/drm/nouveau/nouveau_acpi.c
+++ b/drm/nouveau/nouveau_acpi.c
@@ -71,7 +71,7 @@ static const char nouveau_op_dsm_muid[] = {
 	0xA7, 0x2B, 0x60, 0x42, 0xA6, 0xB5, 0xBE, 0xE0,
 };
 
-static int nouveau_optimus_dsm(acpi_handle handle, int func, int arg, uint32_t *result)
+static int nouveau_evaluate_optimus_dsm(acpi_handle handle, int func, int arg, uint32_t *result)
 {
 	int i;
 	union acpi_object *obj;
@@ -118,7 +118,7 @@ static int nouveau_check_optimus_dsm(acpi_handle handle)
 	 * Function 0 returns a Buffer containing available functions.
 	 * The args parameter is ignored for function 0, so just put 0 in it
 	 */
-	if (nouveau_optimus_dsm(handle, 0, 0, &result))
+	if (nouveau_evaluate_optimus_dsm(handle, 0, 0, &result))
 		return 0;
 
 	/*
@@ -128,7 +128,7 @@ static int nouveau_check_optimus_dsm(acpi_handle handle)
 	return result & 1 && result & (1 << NOUVEAU_DSM_OPTIMUS_CAPS);
 }
 
-static int nouveau_mux_dsm(acpi_handle handle, int func, int arg)
+static int nouveau_evaluate_mux_dsm(acpi_handle handle, int func, int arg)
 {
 	int ret = 0;
 	union acpi_object *obj;
@@ -155,7 +155,7 @@ static int nouveau_dsm_switch_mux(acpi_handle handle, int mux_id)
 {
 	mxm_wmi_call_mxmx(mux_id == NOUVEAU_DSM_MUX_LED_STAMINA ? MXM_MXDS_ADAPTER_IGD : MXM_MXDS_ADAPTER_0);
 	mxm_wmi_call_mxds(mux_id == NOUVEAU_DSM_MUX_LED_STAMINA ? MXM_MXDS_ADAPTER_IGD : MXM_MXDS_ADAPTER_0);
-	return nouveau_mux_dsm(handle, NOUVEAU_DSM_MUX_LED, mux_id);
+	return nouveau_evaluate_mux_dsm(handle, NOUVEAU_DSM_MUX_LED, mux_id);
 }
 
 static int nouveau_dsm_set_discrete_state(acpi_handle handle, enum vga_switcheroo_state state)
@@ -165,7 +165,7 @@ static int nouveau_dsm_set_discrete_state(acpi_handle handle, enum vga_switchero
 		arg = NOUVEAU_DSM_MUX_POWER_SPEED;
 	else
 		arg = NOUVEAU_DSM_MUX_POWER_STAMINA;
-	nouveau_mux_dsm(handle, NOUVEAU_DSM_MUX_POWER, arg);
+	nouveau_evaluate_mux_dsm(handle, NOUVEAU_DSM_MUX_POWER, arg);
 	return 0;
 }
 
@@ -233,8 +233,8 @@ static int nouveau_dsm_pci_probe(struct pci_dev *pdev)
 
 	if (retval & NOUVEAU_DSM_HAS_OPT) {
 		uint32_t result;
-		nouveau_optimus_dsm(dhandle, NOUVEAU_DSM_OPTIMUS_CAPS, 0,
-				    &result);
+		nouveau_evaluate_optimus_dsm(dhandle, NOUVEAU_DSM_OPTIMUS_CAPS,
+				             0, &result);
 		dev_info(&pdev->dev, "optimus capabilities: %s, status %s%s\n",
 			 (result & OPTIMUS_ENABLED) ? "enabled" : "disabled",
 			 (result & OPTIMUS_DYNAMIC_PWR_CAP) ? "dynamic power, " : "",
@@ -324,11 +324,14 @@ void nouveau_switcheroo_optimus_dsm(void)
 	if (!nouveau_dsm_priv.optimus_detected)
 		return;
 
-	nouveau_optimus_dsm(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_OPTIMUS_FLAGS,
-			    0x3, &result);
+	nouveau_evaluate_optimus_dsm(nouveau_dsm_priv.dhandle,
+			             NOUVEAU_DSM_OPTIMUS_FLAGS,
+			             0x3, &result);
 
-	nouveau_optimus_dsm(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_OPTIMUS_CAPS,
-			    NOUVEAU_DSM_OPTIMUS_SET_POWERDOWN, &result);
+	nouveau_evaluate_optimus_dsm(nouveau_dsm_priv.dhandle,
+			             NOUVEAU_DSM_OPTIMUS_CAPS,
+			             NOUVEAU_DSM_OPTIMUS_SET_POWERDOWN,
+			             &result);
 
 }
 
-- 
2.4.1

_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 3/8] acpi: Define static variables for revision ids
  2015-05-25 22:22 [PATCH 1/8] acpi: Rename v1 DSM to mux to avoid ambiguity Pierre Moreau
       [not found] ` <1432592573-13743-1-git-send-email-pierre.morrow-GANU6spQydw@public.gmane.org>
@ 2015-05-25 22:22 ` Pierre Moreau
  2015-05-28  2:59   ` [Nouveau] " Dave Airlie
  2015-05-25 22:22 ` [PATCH 4/8] acpi: Allow evaluate_optimus_dsm to take NULL results Pierre Moreau
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 24+ messages in thread
From: Pierre Moreau @ 2015-05-25 22:22 UTC (permalink / raw)
  To: nouveau; +Cc: bskeggs, dri-devel

Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>
---
 drm/nouveau/nouveau_acpi.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drm/nouveau/nouveau_acpi.c b/drm/nouveau/nouveau_acpi.c
index 1f18018..36f4a40 100644
--- a/drm/nouveau/nouveau_acpi.c
+++ b/drm/nouveau/nouveau_acpi.c
@@ -61,11 +61,13 @@ bool nouveau_has_mux(void) {
 #define NOUVEAU_DSM_HAS_OPT 0x2
 
 #ifdef CONFIG_VGA_SWITCHEROO
+static const uint32_t nouveau_mux_dsm_rid = 0x00000102;
 static const char nouveau_mux_dsm_muid[] = {
 	0xA0, 0xA0, 0x95, 0x9D, 0x60, 0x00, 0x48, 0x4D,
 	0xB3, 0x4D, 0x7E, 0x5F, 0xEA, 0x12, 0x9F, 0xD4,
 };
 
+static const uint32_t nouveau_op_dsm_rid = 0x00000100;
 static const char nouveau_op_dsm_muid[] = {
 	0xF8, 0xD8, 0x86, 0xA4, 0xDA, 0x0B, 0x1B, 0x47,
 	0xA7, 0x2B, 0x60, 0x42, 0xA6, 0xB5, 0xBE, 0xE0,
@@ -87,7 +89,7 @@ static int nouveau_evaluate_optimus_dsm(acpi_handle handle, int func, int arg, u
 		args_buff[i] = (arg >> i * 8) & 0xFF;
 
 	*result = 0;
-	obj = acpi_evaluate_dsm_typed(handle, nouveau_op_dsm_muid, 0x00000100,
+	obj = acpi_evaluate_dsm_typed(handle, nouveau_op_dsm_muid, nouveau_op_dsm_rid,
 				      func, &argv4, ACPI_TYPE_BUFFER);
 	if (!obj) {
 		acpi_handle_info(handle, "failed to evaluate _DSM\n");
@@ -137,7 +139,7 @@ static int nouveau_evaluate_mux_dsm(acpi_handle handle, int func, int arg)
 		.integer.value = arg,
 	};
 
-	obj = acpi_evaluate_dsm_typed(handle, nouveau_mux_dsm_muid, 0x00000102,
+	obj = acpi_evaluate_dsm_typed(handle, nouveau_mux_dsm_muid, nouveau_mux_dsm_rid,
 				      func, &argv4, ACPI_TYPE_INTEGER);
 	if (!obj) {
 		acpi_handle_info(handle, "failed to evaluate _DSM\n");
@@ -224,7 +226,7 @@ static int nouveau_dsm_pci_probe(struct pci_dev *pdev)
 	if (!acpi_has_method(dhandle, "_DSM"))
 		return false;
 
-	if (acpi_check_dsm(dhandle, nouveau_mux_dsm_muid, 0x00000102,
+	if (acpi_check_dsm(dhandle, nouveau_mux_dsm_muid, nouveau_mux_dsm_rid,
 			   1 << NOUVEAU_DSM_MUX_POWER))
 		retval |= NOUVEAU_DSM_HAS_MUX;
 
-- 
2.4.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 4/8] acpi: Allow evaluate_optimus_dsm to take NULL results
  2015-05-25 22:22 [PATCH 1/8] acpi: Rename v1 DSM to mux to avoid ambiguity Pierre Moreau
       [not found] ` <1432592573-13743-1-git-send-email-pierre.morrow-GANU6spQydw@public.gmane.org>
  2015-05-25 22:22 ` [PATCH 3/8] acpi: Define static variables for revision ids Pierre Moreau
@ 2015-05-25 22:22 ` Pierre Moreau
       [not found]   ` <1432592573-13743-4-git-send-email-pierre.morrow-GANU6spQydw@public.gmane.org>
  2015-05-25 22:22 ` [PATCH 6/8] acpi: Improve some messages level and content Pierre Moreau
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 24+ messages in thread
From: Pierre Moreau @ 2015-05-25 22:22 UTC (permalink / raw)
  To: nouveau; +Cc: bskeggs, dri-devel

Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>
---
 drm/nouveau/nouveau_acpi.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drm/nouveau/nouveau_acpi.c b/drm/nouveau/nouveau_acpi.c
index 36f4a40..073f7d7 100644
--- a/drm/nouveau/nouveau_acpi.c
+++ b/drm/nouveau/nouveau_acpi.c
@@ -88,15 +88,14 @@ static int nouveau_evaluate_optimus_dsm(acpi_handle handle, int func, int arg, u
 	for (i = 0; i < 4; i++)
 		args_buff[i] = (arg >> i * 8) & 0xFF;
 
-	*result = 0;
 	obj = acpi_evaluate_dsm_typed(handle, nouveau_op_dsm_muid, nouveau_op_dsm_rid,
 				      func, &argv4, ACPI_TYPE_BUFFER);
 	if (!obj) {
 		acpi_handle_info(handle, "failed to evaluate _DSM\n");
 		return AE_ERROR;
 	} else {
-		if (obj->buffer.length == 4) {
-			*result |= obj->buffer.pointer[0];
+		if (!result && obj->buffer.length == 4) {
+			*result  = obj->buffer.pointer[0];
 			*result |= (obj->buffer.pointer[1] << 8);
 			*result |= (obj->buffer.pointer[2] << 16);
 			*result |= (obj->buffer.pointer[3] << 24);
@@ -322,18 +321,17 @@ void nouveau_register_dsm_handler(void)
 /* Must be called for Optimus models before the card can be turned off */
 void nouveau_switcheroo_optimus_dsm(void)
 {
-	u32 result = 0;
 	if (!nouveau_dsm_priv.optimus_detected)
 		return;
 
 	nouveau_evaluate_optimus_dsm(nouveau_dsm_priv.dhandle,
 			             NOUVEAU_DSM_OPTIMUS_FLAGS,
-			             0x3, &result);
+			             0x3, NULL);
 
 	nouveau_evaluate_optimus_dsm(nouveau_dsm_priv.dhandle,
 			             NOUVEAU_DSM_OPTIMUS_CAPS,
 			             NOUVEAU_DSM_OPTIMUS_SET_POWERDOWN,
-			             &result);
+			             NULL);
 
 }
 
-- 
2.4.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 5/8] acpi: Check returned object type by Optimus _DSM locally
       [not found] ` <1432592573-13743-1-git-send-email-pierre.morrow-GANU6spQydw@public.gmane.org>
  2015-05-25 22:22   ` [PATCH 2/8] acpi: Add evaluate to functons evaluating _DSM Pierre Moreau
@ 2015-05-25 22:22   ` Pierre Moreau
  2015-05-25 22:39     ` [Nouveau] " Ilia Mirkin
       [not found]     ` <1432592573-13743-5-git-send-email-pierre.morrow-GANU6spQydw@public.gmane.org>
  2015-05-25 22:22   ` [PATCH 8/8] acpi: Use booleans when probing different _DSM types Pierre Moreau
  2 siblings, 2 replies; 24+ messages in thread
From: Pierre Moreau @ 2015-05-25 22:22 UTC (permalink / raw)
  To: nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
  Cc: bskeggs-H+wXaHxf7aLQT0dZR+AlfA,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Most _DSM will return an integer value of 0x80000002 when given an unknown
UUID, revision ID or function ID. Checking locally allows us to differentiate
that case from other ACPI errors, and to not report a "failed to evaluate _DSM"
if 0x80000002 is returned which was confusing.

Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>
---
 drm/nouveau/nouveau_acpi.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drm/nouveau/nouveau_acpi.c b/drm/nouveau/nouveau_acpi.c
index 073f7d7..7aeaf7d 100644
--- a/drm/nouveau/nouveau_acpi.c
+++ b/drm/nouveau/nouveau_acpi.c
@@ -88,12 +88,12 @@ static int nouveau_evaluate_optimus_dsm(acpi_handle handle, int func, int arg, u
 	for (i = 0; i < 4; i++)
 		args_buff[i] = (arg >> i * 8) & 0xFF;
 
-	obj = acpi_evaluate_dsm_typed(handle, nouveau_op_dsm_muid, nouveau_op_dsm_rid,
-				      func, &argv4, ACPI_TYPE_BUFFER);
+	obj = acpi_evaluate_dsm(handle, nouveau_op_dsm_muid, nouveau_op_dsm_rid,
+			        func, &argv4);
 	if (!obj) {
 		acpi_handle_info(handle, "failed to evaluate _DSM\n");
 		return AE_ERROR;
-	} else {
+	} else if (obj->type == ACPI_TYPE_BUFFER) {
 		if (!result && obj->buffer.length == 4) {
 			*result  = obj->buffer.pointer[0];
 			*result |= (obj->buffer.pointer[1] << 8);
@@ -101,6 +101,15 @@ static int nouveau_evaluate_optimus_dsm(acpi_handle handle, int func, int arg, u
 			*result |= (obj->buffer.pointer[3] << 24);
 		}
 		ACPI_FREE(obj);
+	} else if (obj->type == ACPI_TYPE_INTEGER &&
+		   obj->integer.value == 0x80000002) {
+		acpi_handle_debug(handle, "failed to query Optimus _DSM\n");
+		ACPI_FREE(obj);
+		return -ENODEV;
+	} else {
+		acpi_handle_err(handle, "unexpected returned value by Optimus _DSM\n");
+		ACPI_FREE(obj);
+		return AE_ERROR;
 	}
 
 	return 0;
-- 
2.4.1

_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 6/8] acpi: Improve some messages level and content
  2015-05-25 22:22 [PATCH 1/8] acpi: Rename v1 DSM to mux to avoid ambiguity Pierre Moreau
                   ` (2 preceding siblings ...)
  2015-05-25 22:22 ` [PATCH 4/8] acpi: Allow evaluate_optimus_dsm to take NULL results Pierre Moreau
@ 2015-05-25 22:22 ` Pierre Moreau
  2015-05-25 22:22 ` [PATCH 7/8] acpi: Add support for Apple Gmux _DMS Pierre Moreau
  2015-05-28  2:58 ` [Nouveau] [PATCH 1/8] acpi: Rename v1 DSM to mux to avoid ambiguity Dave Airlie
  5 siblings, 0 replies; 24+ messages in thread
From: Pierre Moreau @ 2015-05-25 22:22 UTC (permalink / raw)
  To: nouveau; +Cc: bskeggs, dri-devel

Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>
---
 drm/nouveau/nouveau_acpi.c | 8 ++++----
 drm/nouveau/nouveau_vga.c  | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drm/nouveau/nouveau_acpi.c b/drm/nouveau/nouveau_acpi.c
index 7aeaf7d..104d291 100644
--- a/drm/nouveau/nouveau_acpi.c
+++ b/drm/nouveau/nouveau_acpi.c
@@ -91,7 +91,7 @@ static int nouveau_evaluate_optimus_dsm(acpi_handle handle, int func, int arg, u
 	obj = acpi_evaluate_dsm(handle, nouveau_op_dsm_muid, nouveau_op_dsm_rid,
 			        func, &argv4);
 	if (!obj) {
-		acpi_handle_info(handle, "failed to evaluate _DSM\n");
+		acpi_handle_err(handle, "failed to evaluate Optimus _DSM\n");
 		return AE_ERROR;
 	} else if (obj->type == ACPI_TYPE_BUFFER) {
 		if (!result && obj->buffer.length == 4) {
@@ -150,7 +150,7 @@ static int nouveau_evaluate_mux_dsm(acpi_handle handle, int func, int arg)
 	obj = acpi_evaluate_dsm_typed(handle, nouveau_mux_dsm_muid, nouveau_mux_dsm_rid,
 				      func, &argv4, ACPI_TYPE_INTEGER);
 	if (!obj) {
-		acpi_handle_info(handle, "failed to evaluate _DSM\n");
+		acpi_handle_err(handle, "failed to evaluate mux _DSM\n");
 		return AE_ERROR;
 	} else {
 		if (obj->integer.value == 0x80000002)
@@ -272,7 +272,7 @@ static bool nouveau_dsm_detect(void)
 	guid_valid = mxm_wmi_supported();
 
 	if (guid_valid)
-		printk("MXM: GUID detected in BIOS\n");
+		printk(KERN_INFO "MXM: GUID detected in BIOS\n");
 
 	/* now do DSM detection */
 	while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
@@ -375,7 +375,7 @@ static int nouveau_rom_call(acpi_handle rom_handle, uint8_t *bios,
 
 	status = acpi_evaluate_object(rom_handle, NULL, &rom_arg, &buffer);
 	if (ACPI_FAILURE(status)) {
-		printk(KERN_INFO "failed to evaluate ROM got %s\n", acpi_format_exception(status));
+		printk(KERN_ERR "ACPI: failed to evaluate ROM got %s\n", acpi_format_exception(status));
 		return -ENODEV;
 	}
 	obj = (union acpi_object *)buffer.pointer;
diff --git a/drm/nouveau/nouveau_vga.c b/drm/nouveau/nouveau_vga.c
index 6297566..9a6328f 100644
--- a/drm/nouveau/nouveau_vga.c
+++ b/drm/nouveau/nouveau_vga.c
@@ -40,13 +40,13 @@ nouveau_switcheroo_set_state(struct pci_dev *pdev,
 		return;
 
 	if (state == VGA_SWITCHEROO_ON) {
-		printk(KERN_ERR "VGA switcheroo: switched nouveau on\n");
+		printk(KERN_INFO "VGA switcheroo: switched nouveau on\n");
 		dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
 		nouveau_pmops_resume(&pdev->dev);
 		drm_kms_helper_poll_enable(dev);
 		dev->switch_power_state = DRM_SWITCH_POWER_ON;
 	} else {
-		printk(KERN_ERR "VGA switcheroo: switched nouveau off\n");
+		printk(KERN_INFO "VGA switcheroo: switched nouveau off\n");
 		dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
 		drm_kms_helper_poll_disable(dev);
 		nouveau_switcheroo_optimus_dsm();
-- 
2.4.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 7/8] acpi: Add support for Apple Gmux _DMS
  2015-05-25 22:22 [PATCH 1/8] acpi: Rename v1 DSM to mux to avoid ambiguity Pierre Moreau
                   ` (3 preceding siblings ...)
  2015-05-25 22:22 ` [PATCH 6/8] acpi: Improve some messages level and content Pierre Moreau
@ 2015-05-25 22:22 ` Pierre Moreau
       [not found]   ` <1432592573-13743-7-git-send-email-pierre.morrow-GANU6spQydw@public.gmane.org>
  2015-05-28  2:58 ` [Nouveau] [PATCH 1/8] acpi: Rename v1 DSM to mux to avoid ambiguity Dave Airlie
  5 siblings, 1 reply; 24+ messages in thread
From: Pierre Moreau @ 2015-05-25 22:22 UTC (permalink / raw)
  To: nouveau; +Cc: bskeggs, dri-devel

Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>
---
 drm/nouveau/nouveau_acpi.c | 53 ++++++++++++++++++++++++++++++++++++++++++++--
 drm/nouveau/nouveau_acpi.h |  2 ++
 drm/nouveau/nouveau_drm.c  |  6 ++++--
 drm/nouveau/nouveau_vga.c  | 10 +++++----
 4 files changed, 63 insertions(+), 8 deletions(-)

diff --git a/drm/nouveau/nouveau_acpi.c b/drm/nouveau/nouveau_acpi.c
index 104d291..3d6a1ea 100644
--- a/drm/nouveau/nouveau_acpi.c
+++ b/drm/nouveau/nouveau_acpi.c
@@ -29,6 +29,10 @@
 
 #define NOUVEAU_DSM_OPTIMUS_SET_POWERDOWN (NOUVEAU_DSM_OPTIMUS_POWERDOWN_PS3 | NOUVEAU_DSM_OPTIMUS_FLAGS_CHANGED)
 
+#define NOUVEAU_DSM_GMUX_V1_CAPS (3 << 6)
+
+#define NOUVEAU_DSM_GMUX_V2_CAPS (1 << 1)
+
 /* result of the optimus caps function */
 #define OPTIMUS_ENABLED (1 << 0)
 #define OPTIMUS_STATUS_MASK (3 << 3)
@@ -45,6 +49,7 @@
 static struct nouveau_dsm_priv {
 	bool mux_detected;
 	bool optimus_detected;
+	bool gmux_detected;
 	acpi_handle dhandle;
 	acpi_handle rom_handle;
 } nouveau_dsm_priv;
@@ -57,8 +62,13 @@ bool nouveau_has_mux(void) {
 	return nouveau_dsm_priv.mux_detected;
 }
 
+bool nouveau_has_gmux(void) {
+	return nouveau_dsm_priv.gmux_detected;
+}
+
 #define NOUVEAU_DSM_HAS_MUX 0x1
 #define NOUVEAU_DSM_HAS_OPT 0x2
+#define NOUVEAU_DSM_HAS_GMUX 0x4
 
 #ifdef CONFIG_VGA_SWITCHEROO
 static const uint32_t nouveau_mux_dsm_rid = 0x00000102;
@@ -73,6 +83,18 @@ static const char nouveau_op_dsm_muid[] = {
 	0xA7, 0x2B, 0x60, 0x42, 0xA6, 0xB5, 0xBE, 0xE0,
 };
 
+static const uint32_t nouveau_gmux_v1_dsm_rid = 0x0000101;
+static const char nouveau_gmux_v1_dsm_muid[] = {
+	0xA6, 0x69, 0x86, 0x99, 0xE9, 0x8B, 0xFB, 0x49,
+	0xBD, 0xDB, 0x51, 0xA1, 0xEF, 0xE1, 0x9C, 0x3D,
+};
+
+static const uint32_t nouveau_gmux_v2_dsm_rid = 0x0000001;
+static const char nouveau_gmux_v2_dsm_muid[] = {
+	0xC6, 0xB7, 0xB5, 0xA0, 0x18, 0x13, 0x1C, 0x44,
+	0xB0, 0xC9, 0xFE, 0x69, 0x5E, 0xAF, 0x94, 0x9B,
+};
+
 static int nouveau_evaluate_optimus_dsm(acpi_handle handle, int func, int arg, uint32_t *result)
 {
 	int i;
@@ -161,6 +183,17 @@ static int nouveau_evaluate_mux_dsm(acpi_handle handle, int func, int arg)
 	return ret;
 }
 
+static int nouveau_check_gmux_dsm(acpi_handle handle)
+{
+	bool has_v1 = acpi_check_dsm(handle, nouveau_gmux_v1_dsm_muid,
+			             nouveau_gmux_v1_dsm_rid,
+			             NOUVEAU_DSM_GMUX_V1_CAPS);
+	bool has_v2 = acpi_check_dsm(handle, nouveau_gmux_v2_dsm_muid,
+			             nouveau_gmux_v2_dsm_rid,
+			             NOUVEAU_DSM_GMUX_V2_CAPS);
+	return has_v1 || has_v2;
+}
+
 static int nouveau_dsm_switch_mux(acpi_handle handle, int mux_id)
 {
 	mxm_wmi_call_mxmx(mux_id == NOUVEAU_DSM_MUX_LED_STAMINA ? MXM_MXDS_ADAPTER_IGD : MXM_MXDS_ADAPTER_0);
@@ -238,6 +271,9 @@ static int nouveau_dsm_pci_probe(struct pci_dev *pdev)
 			   1 << NOUVEAU_DSM_MUX_POWER))
 		retval |= NOUVEAU_DSM_HAS_MUX;
 
+	if (nouveau_check_gmux_dsm(dhandle))
+		retval |= NOUVEAU_DSM_HAS_GMUX;
+
 	if (nouveau_check_optimus_dsm(dhandle))
 		retval |= NOUVEAU_DSM_HAS_OPT;
 
@@ -263,6 +299,7 @@ static bool nouveau_dsm_detect(void)
 	struct pci_dev *pdev = NULL;
 	int has_dsm = 0;
 	int has_optimus = 0;
+	bool has_gmux = false;
 	int vga_count = 0;
 	bool guid_valid;
 	int retval;
@@ -283,6 +320,8 @@ static bool nouveau_dsm_detect(void)
 			has_dsm |= 1;
 		if (retval & NOUVEAU_DSM_HAS_OPT)
 			has_optimus = 1;
+		if (retval & NOUVEAU_DSM_HAS_GMUX)
+			has_gmux = true;
 	}
 
 	while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_3D << 8, pdev)) != NULL) {
@@ -293,9 +332,11 @@ static bool nouveau_dsm_detect(void)
 			has_dsm |= 1;
 		if (retval & NOUVEAU_DSM_HAS_OPT)
 			has_optimus = 1;
+		if (retval & NOUVEAU_DSM_HAS_GMUX)
+			has_gmux = true;
 	}
 
-	/* find the optimus DSM or the mux DSM */
+	/* find the optimus DSM, the mux DSM or the gmux DSM */
 	if (has_optimus == 1) {
 		acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
 			&buffer);
@@ -310,6 +351,13 @@ static bool nouveau_dsm_detect(void)
 			acpi_method_name);
 		nouveau_dsm_priv.mux_detected = true;
 		ret = true;
+	} else if (has_gmux) {
+		acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
+			&buffer);
+		printk(KERN_INFO "VGA switcheroo: detected gmux DSM switching method %s handle\n",
+			acpi_method_name);
+		nouveau_dsm_priv.gmux_detected = true;
+		ret = true;
 	}
 
 
@@ -321,7 +369,8 @@ void nouveau_register_dsm_handler(void)
 	bool r;
 
 	r = nouveau_dsm_detect();
-	if (!r)
+	/* Apple Gmux will register its own vga switcheroo handler */
+	if (!r || nouveau_has_gmux())
 		return;
 
 	vga_switcheroo_register_handler(&nouveau_dsm_handler);
diff --git a/drm/nouveau/nouveau_acpi.h b/drm/nouveau/nouveau_acpi.h
index 2bd88a8..7fcfe82 100644
--- a/drm/nouveau/nouveau_acpi.h
+++ b/drm/nouveau/nouveau_acpi.h
@@ -6,6 +6,7 @@
 #if defined(CONFIG_ACPI) && defined(CONFIG_X86)
 bool nouveau_is_optimus(void);
 bool nouveau_has_mux(void);
+bool nouveau_has_gmux(void);
 void nouveau_register_dsm_handler(void);
 void nouveau_unregister_dsm_handler(void);
 void nouveau_switcheroo_optimus_dsm(void);
@@ -15,6 +16,7 @@ void *nouveau_acpi_edid(struct drm_device *, struct drm_connector *);
 #else
 static inline bool nouveau_is_optimus(void) { return false; };
 static inline bool nouveau_has_mux(void) { return false; };
+static inline bool nouveau_has_gmux(void) { return false; };
 static inline void nouveau_register_dsm_handler(void) {}
 static inline void nouveau_unregister_dsm_handler(void) {}
 static inline void nouveau_switcheroo_optimus_dsm(void) {}
diff --git a/drm/nouveau/nouveau_drm.c b/drm/nouveau/nouveau_drm.c
index c06a7a1..702aff8 100644
--- a/drm/nouveau/nouveau_drm.c
+++ b/drm/nouveau/nouveau_drm.c
@@ -719,7 +719,8 @@ nouveau_pmops_runtime_suspend(struct device *dev)
 	}
 
 	/* are we optimus enabled? */
-	if (nouveau_runtime_pm == -1 && !nouveau_is_optimus() && !nouveau_has_mux()) {
+	if (nouveau_runtime_pm == -1 &&
+	    !nouveau_is_optimus() && !nouveau_has_mux() && !nouveau_has_gmux()) {
 		DRM_DEBUG_DRIVER("failing to power off - not optimus\n");
 		pm_runtime_forbid(dev);
 		return -EBUSY;
@@ -780,7 +781,8 @@ nouveau_pmops_runtime_idle(struct device *dev)
 	}
 
 	/* are we optimus enabled? */
-	if (nouveau_runtime_pm == -1 && !nouveau_is_optimus() && !nouveau_has_mux()) {
+	if (nouveau_runtime_pm == -1 &&
+	    !nouveau_is_optimus() && !nouveau_has_mux() && !nouveau_has_gmux()) {
 		DRM_DEBUG_DRIVER("failing to power off - not optimus\n");
 		pm_runtime_forbid(dev);
 		return -EBUSY;
diff --git a/drm/nouveau/nouveau_vga.c b/drm/nouveau/nouveau_vga.c
index 9a6328f..3a7a9b9 100644
--- a/drm/nouveau/nouveau_vga.c
+++ b/drm/nouveau/nouveau_vga.c
@@ -96,11 +96,12 @@ nouveau_vga_init(struct nouveau_drm *drm)
 
 	if (nouveau_runtime_pm == 1)
 		runtime = true;
-	if ((nouveau_runtime_pm == -1) && (nouveau_is_optimus() || nouveau_has_mux()))
+	if ((nouveau_runtime_pm == -1) &&
+	    (nouveau_is_optimus() || nouveau_has_mux() || nouveau_has_gmux()))
 		runtime = true;
 	vga_switcheroo_register_client(dev->pdev, &nouveau_switcheroo_ops, runtime);
 
-	if (runtime && nouveau_has_mux() && !nouveau_is_optimus())
+	if (runtime && (nouveau_has_mux() || nouveau_has_gmux()) && !nouveau_is_optimus())
 		vga_switcheroo_init_domain_pm_ops(drm->dev->dev, &drm->vga_pm_domain);
 }
 
@@ -112,11 +113,12 @@ nouveau_vga_fini(struct nouveau_drm *drm)
 
 	if (nouveau_runtime_pm == 1)
 		runtime = true;
-	if ((nouveau_runtime_pm == -1) && (nouveau_is_optimus() || nouveau_has_mux()))
+	if ((nouveau_runtime_pm == -1) &&
+	    (nouveau_is_optimus() || nouveau_has_mux() || nouveau_has_gmux()))
 		runtime = true;
 
 	vga_switcheroo_unregister_client(dev->pdev);
-	if (runtime && nouveau_has_mux() && !nouveau_is_optimus())
+	if (runtime && (nouveau_has_mux() || nouveau_has_gmux()) && !nouveau_is_optimus())
 		vga_switcheroo_fini_domain_pm_ops(drm->dev->dev);
 	vga_client_register(dev->pdev, NULL, NULL, NULL);
 }
-- 
2.4.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH 8/8] acpi: Use booleans when probing different _DSM types
       [not found] ` <1432592573-13743-1-git-send-email-pierre.morrow-GANU6spQydw@public.gmane.org>
  2015-05-25 22:22   ` [PATCH 2/8] acpi: Add evaluate to functons evaluating _DSM Pierre Moreau
  2015-05-25 22:22   ` [PATCH 5/8] acpi: Check returned object type by Optimus _DSM locally Pierre Moreau
@ 2015-05-25 22:22   ` Pierre Moreau
       [not found]     ` <1432592573-13743-8-git-send-email-pierre.morrow-GANU6spQydw@public.gmane.org>
  2 siblings, 1 reply; 24+ messages in thread
From: Pierre Moreau @ 2015-05-25 22:22 UTC (permalink / raw)
  To: nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
  Cc: bskeggs-H+wXaHxf7aLQT0dZR+AlfA,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>
---
 drm/nouveau/nouveau_acpi.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drm/nouveau/nouveau_acpi.c b/drm/nouveau/nouveau_acpi.c
index 3d6a1ea..5d63621 100644
--- a/drm/nouveau/nouveau_acpi.c
+++ b/drm/nouveau/nouveau_acpi.c
@@ -297,8 +297,8 @@ static bool nouveau_dsm_detect(void)
 	char acpi_method_name[255] = { 0 };
 	struct acpi_buffer buffer = {sizeof(acpi_method_name), acpi_method_name};
 	struct pci_dev *pdev = NULL;
-	int has_dsm = 0;
-	int has_optimus = 0;
+	bool has_mux = false;
+	bool has_optimus = false;
 	bool has_gmux = false;
 	int vga_count = 0;
 	bool guid_valid;
@@ -317,9 +317,9 @@ static bool nouveau_dsm_detect(void)
 
 		retval = nouveau_dsm_pci_probe(pdev);
 		if (retval & NOUVEAU_DSM_HAS_MUX)
-			has_dsm |= 1;
+			has_mux = true;
 		if (retval & NOUVEAU_DSM_HAS_OPT)
-			has_optimus = 1;
+			has_optimus = true;
 		if (retval & NOUVEAU_DSM_HAS_GMUX)
 			has_gmux = true;
 	}
@@ -329,9 +329,9 @@ static bool nouveau_dsm_detect(void)
 
 		retval = nouveau_dsm_pci_probe(pdev);
 		if (retval & NOUVEAU_DSM_HAS_MUX)
-			has_dsm |= 1;
+			has_mux = true;
 		if (retval & NOUVEAU_DSM_HAS_OPT)
-			has_optimus = 1;
+			has_optimus = true;
 		if (retval & NOUVEAU_DSM_HAS_GMUX)
 			has_gmux = true;
 	}
@@ -344,7 +344,7 @@ static bool nouveau_dsm_detect(void)
 			acpi_method_name);
 		nouveau_dsm_priv.optimus_detected = true;
 		ret = true;
-	} else if (vga_count == 2 && has_dsm && guid_valid) {
+	} else if (vga_count == 2 && has_mux && guid_valid) {
 		acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
 			&buffer);
 		printk(KERN_INFO "VGA switcheroo: detected mux DSM switching method %s handle\n",
-- 
2.4.1

_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [Nouveau] [PATCH 5/8] acpi: Check returned object type by Optimus _DSM locally
  2015-05-25 22:22   ` [PATCH 5/8] acpi: Check returned object type by Optimus _DSM locally Pierre Moreau
@ 2015-05-25 22:39     ` Ilia Mirkin
  2015-05-26  5:10       ` Pierre Moreau
       [not found]     ` <1432592573-13743-5-git-send-email-pierre.morrow-GANU6spQydw@public.gmane.org>
  1 sibling, 1 reply; 24+ messages in thread
From: Ilia Mirkin @ 2015-05-25 22:39 UTC (permalink / raw)
  To: Pierre Moreau; +Cc: nouveau, Ben Skeggs, dri-devel

On Mon, May 25, 2015 at 6:22 PM, Pierre Moreau <pierre.morrow@free.fr> wrote:
> Most _DSM will return an integer value of 0x80000002 when given an unknown
> UUID, revision ID or function ID. Checking locally allows us to differentiate
> that case from other ACPI errors, and to not report a "failed to evaluate _DSM"
> if 0x80000002 is returned which was confusing.
>
> Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>
> ---
>  drm/nouveau/nouveau_acpi.c | 15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/drm/nouveau/nouveau_acpi.c b/drm/nouveau/nouveau_acpi.c
> index 073f7d7..7aeaf7d 100644
> --- a/drm/nouveau/nouveau_acpi.c
> +++ b/drm/nouveau/nouveau_acpi.c
> @@ -88,12 +88,12 @@ static int nouveau_evaluate_optimus_dsm(acpi_handle handle, int func, int arg, u
>         for (i = 0; i < 4; i++)
>                 args_buff[i] = (arg >> i * 8) & 0xFF;
>
> -       obj = acpi_evaluate_dsm_typed(handle, nouveau_op_dsm_muid, nouveau_op_dsm_rid,
> -                                     func, &argv4, ACPI_TYPE_BUFFER);
> +       obj = acpi_evaluate_dsm(handle, nouveau_op_dsm_muid, nouveau_op_dsm_rid,
> +                               func, &argv4);
>         if (!obj) {
>                 acpi_handle_info(handle, "failed to evaluate _DSM\n");
>                 return AE_ERROR;
> -       } else {
> +       } else if (obj->type == ACPI_TYPE_BUFFER) {
>                 if (!result && obj->buffer.length == 4) {
>                         *result  = obj->buffer.pointer[0];
>                         *result |= (obj->buffer.pointer[1] << 8);
> @@ -101,6 +101,15 @@ static int nouveau_evaluate_optimus_dsm(acpi_handle handle, int func, int arg, u
>                         *result |= (obj->buffer.pointer[3] << 24);
>                 }
>                 ACPI_FREE(obj);
> +       } else if (obj->type == ACPI_TYPE_INTEGER &&
> +                  obj->integer.value == 0x80000002) {
> +               acpi_handle_debug(handle, "failed to query Optimus _DSM\n");
> +               ACPI_FREE(obj);
> +               return -ENODEV;

should this be AE_ERROR?

> +       } else {
> +               acpi_handle_err(handle, "unexpected returned value by Optimus _DSM\n");
> +               ACPI_FREE(obj);
> +               return AE_ERROR;
>         }
>
>         return 0;
> --
> 2.4.1
>
> _______________________________________________
> Nouveau mailing list
> Nouveau@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/nouveau
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [Nouveau] [PATCH 5/8] acpi: Check returned object type by Optimus _DSM locally
  2015-05-25 22:39     ` [Nouveau] " Ilia Mirkin
@ 2015-05-26  5:10       ` Pierre Moreau
       [not found]         ` <84DFBDB0-0382-479C-8019-7CD888B7B466-GANU6spQydw@public.gmane.org>
  0 siblings, 1 reply; 24+ messages in thread
From: Pierre Moreau @ 2015-05-26  5:10 UTC (permalink / raw)
  To: Ilia Mirkin; +Cc: nouveau, Ben Skeggs, dri-devel





> On 26 May 2015, at 00:39, Ilia Mirkin <imirkin@alum.mit.edu> wrote:
> 
>> On Mon, May 25, 2015 at 6:22 PM, Pierre Moreau <pierre.morrow@free.fr> wrote:
>> Most _DSM will return an integer value of 0x80000002 when given an unknown
>> UUID, revision ID or function ID. Checking locally allows us to differentiate
>> that case from other ACPI errors, and to not report a "failed to evaluate _DSM"
>> if 0x80000002 is returned which was confusing.
>> 
>> Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>
>> ---
>> drm/nouveau/nouveau_acpi.c | 15 ++++++++++++---
>> 1 file changed, 12 insertions(+), 3 deletions(-)
>> 
>> diff --git a/drm/nouveau/nouveau_acpi.c b/drm/nouveau/nouveau_acpi.c
>> index 073f7d7..7aeaf7d 100644
>> --- a/drm/nouveau/nouveau_acpi.c
>> +++ b/drm/nouveau/nouveau_acpi.c
>> @@ -88,12 +88,12 @@ static int nouveau_evaluate_optimus_dsm(acpi_handle handle, int func, int arg, u
>>        for (i = 0; i < 4; i++)
>>                args_buff[i] = (arg >> i * 8) & 0xFF;
>> 
>> -       obj = acpi_evaluate_dsm_typed(handle, nouveau_op_dsm_muid, nouveau_op_dsm_rid,
>> -                                     func, &argv4, ACPI_TYPE_BUFFER);
>> +       obj = acpi_evaluate_dsm(handle, nouveau_op_dsm_muid, nouveau_op_dsm_rid,
>> +                               func, &argv4);
>>        if (!obj) {
>>                acpi_handle_info(handle, "failed to evaluate _DSM\n");
>>                return AE_ERROR;
>> -       } else {
>> +       } else if (obj->type == ACPI_TYPE_BUFFER) {
>>                if (!result && obj->buffer.length == 4) {
>>                        *result  = obj->buffer.pointer[0];
>>                        *result |= (obj->buffer.pointer[1] << 8);
>> @@ -101,6 +101,15 @@ static int nouveau_evaluate_optimus_dsm(acpi_handle handle, int func, int arg, u
>>                        *result |= (obj->buffer.pointer[3] << 24);
>>                }
>>                ACPI_FREE(obj);
>> +       } else if (obj->type == ACPI_TYPE_INTEGER &&
>> +                  obj->integer.value == 0x80000002) {
>> +               acpi_handle_debug(handle, "failed to query Optimus _DSM\n");
>> +               ACPI_FREE(obj);
>> +               return -ENODEV;
> 
> should this be AE_ERROR?

I would say no, because ACPI was parsed correctly, just that we didn't it give the correct arguments, or rather, the _DSM we tested isn't an Optimus one, but it could a mux or gmux. And I used ENODEV as it is the value returned by nouveau_evaluate_mux_dsm in the same context. 

> 
>> +       } else {
>> +               acpi_handle_err(handle, "unexpected returned value by Optimus _DSM\n");
>> +               ACPI_FREE(obj);
>> +               return AE_ERROR;
>>        }
>> 
>>        return 0;
>> --
>> 2.4.1
>> 
>> _______________________________________________
>> Nouveau mailing list
>> Nouveau@lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/nouveau
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 5/8] acpi: Check returned object type by Optimus _DSM locally
       [not found]         ` <84DFBDB0-0382-479C-8019-7CD888B7B466-GANU6spQydw@public.gmane.org>
@ 2015-05-26  5:17           ` Ilia Mirkin
  2015-05-26  8:26             ` [Nouveau] " Pierre Moreau
  0 siblings, 1 reply; 24+ messages in thread
From: Ilia Mirkin @ 2015-05-26  5:17 UTC (permalink / raw)
  To: Pierre Moreau
  Cc: nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW, Ben Skeggs,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

On Tue, May 26, 2015 at 1:10 AM, Pierre Moreau <pierre.morrow@free.fr> wrote:
>> On 26 May 2015, at 00:39, Ilia Mirkin <imirkin@alum.mit.edu> wrote:
>>
>>> On Mon, May 25, 2015 at 6:22 PM, Pierre Moreau <pierre.morrow@free.fr> wrote:
>>> Most _DSM will return an integer value of 0x80000002 when given an unknown
>>> UUID, revision ID or function ID. Checking locally allows us to differentiate
>>> that case from other ACPI errors, and to not report a "failed to evaluate _DSM"
>>> if 0x80000002 is returned which was confusing.
>>>
>>> Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>
>>> ---
>>> drm/nouveau/nouveau_acpi.c | 15 ++++++++++++---
>>> 1 file changed, 12 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drm/nouveau/nouveau_acpi.c b/drm/nouveau/nouveau_acpi.c
>>> index 073f7d7..7aeaf7d 100644
>>> --- a/drm/nouveau/nouveau_acpi.c
>>> +++ b/drm/nouveau/nouveau_acpi.c
>>> @@ -88,12 +88,12 @@ static int nouveau_evaluate_optimus_dsm(acpi_handle handle, int func, int arg, u
>>>        for (i = 0; i < 4; i++)
>>>                args_buff[i] = (arg >> i * 8) & 0xFF;
>>>
>>> -       obj = acpi_evaluate_dsm_typed(handle, nouveau_op_dsm_muid, nouveau_op_dsm_rid,
>>> -                                     func, &argv4, ACPI_TYPE_BUFFER);
>>> +       obj = acpi_evaluate_dsm(handle, nouveau_op_dsm_muid, nouveau_op_dsm_rid,
>>> +                               func, &argv4);
>>>        if (!obj) {
>>>                acpi_handle_info(handle, "failed to evaluate _DSM\n");
>>>                return AE_ERROR;
>>> -       } else {
>>> +       } else if (obj->type == ACPI_TYPE_BUFFER) {
>>>                if (!result && obj->buffer.length == 4) {
>>>                        *result  = obj->buffer.pointer[0];
>>>                        *result |= (obj->buffer.pointer[1] << 8);
>>> @@ -101,6 +101,15 @@ static int nouveau_evaluate_optimus_dsm(acpi_handle handle, int func, int arg, u
>>>                        *result |= (obj->buffer.pointer[3] << 24);
>>>                }
>>>                ACPI_FREE(obj);
>>> +       } else if (obj->type == ACPI_TYPE_INTEGER &&
>>> +                  obj->integer.value == 0x80000002) {
>>> +               acpi_handle_debug(handle, "failed to query Optimus _DSM\n");
>>> +               ACPI_FREE(obj);
>>> +               return -ENODEV;
>>
>> should this be AE_ERROR?
>
> I would say no, because ACPI was parsed correctly, just that we didn't it give the correct arguments, or rather, the _DSM we tested isn't an Optimus one, but it could a mux or gmux. And I used ENODEV as it is the value returned by nouveau_evaluate_mux_dsm in the same context.

Hm ok. It just seemed odd to be returning AE_* in one context, and
-ENODEV in another context -- they're different types of errors.
However if the caller handles it, I guess it's OK... I haven't looked
at the API in depth.

>
>>
>>> +       } else {
>>> +               acpi_handle_err(handle, "unexpected returned value by Optimus _DSM\n");
>>> +               ACPI_FREE(obj);
>>> +               return AE_ERROR;
>>>        }
>>>
>>>        return 0;
>>> --
>>> 2.4.1
>>>
>>> _______________________________________________
>>> Nouveau mailing list
>>> Nouveau@lists.freedesktop.org
>>> http://lists.freedesktop.org/mailman/listinfo/nouveau
_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 2/8] acpi: Add evaluate to functons evaluating _DSM
       [not found]     ` <1432592573-13743-2-git-send-email-pierre.morrow-GANU6spQydw@public.gmane.org>
@ 2015-05-26  8:01       ` Samuel Pitoiset
       [not found]         ` <5564284F.3080406-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 24+ messages in thread
From: Samuel Pitoiset @ 2015-05-26  8:01 UTC (permalink / raw)
  To: Pierre Moreau, nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
  Cc: bskeggs-H+wXaHxf7aLQT0dZR+AlfA,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

s/functons/functions in the commit message.

On 05/26/2015 12:22 AM, Pierre Moreau wrote:
> This makes it clearer when reading the function name, as well as following the
> names of the related ACPI function.
>
> Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>
> ---
>   drm/nouveau/nouveau_acpi.c | 25 ++++++++++++++-----------
>   1 file changed, 14 insertions(+), 11 deletions(-)
>
> diff --git a/drm/nouveau/nouveau_acpi.c b/drm/nouveau/nouveau_acpi.c
> index 4a48e21..1f18018 100644
> --- a/drm/nouveau/nouveau_acpi.c
> +++ b/drm/nouveau/nouveau_acpi.c
> @@ -71,7 +71,7 @@ static const char nouveau_op_dsm_muid[] = {
>   	0xA7, 0x2B, 0x60, 0x42, 0xA6, 0xB5, 0xBE, 0xE0,
>   };
>   
> -static int nouveau_optimus_dsm(acpi_handle handle, int func, int arg, uint32_t *result)
> +static int nouveau_evaluate_optimus_dsm(acpi_handle handle, int func, int arg, uint32_t *result)
>   {
>   	int i;
>   	union acpi_object *obj;
> @@ -118,7 +118,7 @@ static int nouveau_check_optimus_dsm(acpi_handle handle)
>   	 * Function 0 returns a Buffer containing available functions.
>   	 * The args parameter is ignored for function 0, so just put 0 in it
>   	 */
> -	if (nouveau_optimus_dsm(handle, 0, 0, &result))
> +	if (nouveau_evaluate_optimus_dsm(handle, 0, 0, &result))
>   		return 0;
>   
>   	/*
> @@ -128,7 +128,7 @@ static int nouveau_check_optimus_dsm(acpi_handle handle)
>   	return result & 1 && result & (1 << NOUVEAU_DSM_OPTIMUS_CAPS);
>   }
>   
> -static int nouveau_mux_dsm(acpi_handle handle, int func, int arg)
> +static int nouveau_evaluate_mux_dsm(acpi_handle handle, int func, int arg)
>   {
>   	int ret = 0;
>   	union acpi_object *obj;
> @@ -155,7 +155,7 @@ static int nouveau_dsm_switch_mux(acpi_handle handle, int mux_id)
>   {
>   	mxm_wmi_call_mxmx(mux_id == NOUVEAU_DSM_MUX_LED_STAMINA ? MXM_MXDS_ADAPTER_IGD : MXM_MXDS_ADAPTER_0);
>   	mxm_wmi_call_mxds(mux_id == NOUVEAU_DSM_MUX_LED_STAMINA ? MXM_MXDS_ADAPTER_IGD : MXM_MXDS_ADAPTER_0);
> -	return nouveau_mux_dsm(handle, NOUVEAU_DSM_MUX_LED, mux_id);
> +	return nouveau_evaluate_mux_dsm(handle, NOUVEAU_DSM_MUX_LED, mux_id);
>   }
>   
>   static int nouveau_dsm_set_discrete_state(acpi_handle handle, enum vga_switcheroo_state state)
> @@ -165,7 +165,7 @@ static int nouveau_dsm_set_discrete_state(acpi_handle handle, enum vga_switchero
>   		arg = NOUVEAU_DSM_MUX_POWER_SPEED;
>   	else
>   		arg = NOUVEAU_DSM_MUX_POWER_STAMINA;
> -	nouveau_mux_dsm(handle, NOUVEAU_DSM_MUX_POWER, arg);
> +	nouveau_evaluate_mux_dsm(handle, NOUVEAU_DSM_MUX_POWER, arg);
>   	return 0;
>   }
>   
> @@ -233,8 +233,8 @@ static int nouveau_dsm_pci_probe(struct pci_dev *pdev)
>   
>   	if (retval & NOUVEAU_DSM_HAS_OPT) {
>   		uint32_t result;
> -		nouveau_optimus_dsm(dhandle, NOUVEAU_DSM_OPTIMUS_CAPS, 0,
> -				    &result);
> +		nouveau_evaluate_optimus_dsm(dhandle, NOUVEAU_DSM_OPTIMUS_CAPS,
> +				             0, &result);
>   		dev_info(&pdev->dev, "optimus capabilities: %s, status %s%s\n",
>   			 (result & OPTIMUS_ENABLED) ? "enabled" : "disabled",
>   			 (result & OPTIMUS_DYNAMIC_PWR_CAP) ? "dynamic power, " : "",
> @@ -324,11 +324,14 @@ void nouveau_switcheroo_optimus_dsm(void)
>   	if (!nouveau_dsm_priv.optimus_detected)
>   		return;
>   
> -	nouveau_optimus_dsm(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_OPTIMUS_FLAGS,
> -			    0x3, &result);
> +	nouveau_evaluate_optimus_dsm(nouveau_dsm_priv.dhandle,
> +			             NOUVEAU_DSM_OPTIMUS_FLAGS,
> +			             0x3, &result);
>   
> -	nouveau_optimus_dsm(nouveau_dsm_priv.dhandle, NOUVEAU_DSM_OPTIMUS_CAPS,
> -			    NOUVEAU_DSM_OPTIMUS_SET_POWERDOWN, &result);
> +	nouveau_evaluate_optimus_dsm(nouveau_dsm_priv.dhandle,
> +			             NOUVEAU_DSM_OPTIMUS_CAPS,
> +			             NOUVEAU_DSM_OPTIMUS_SET_POWERDOWN,
> +			             &result);
>   
>   }
>   

_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 4/8] acpi: Allow evaluate_optimus_dsm to take NULL results
       [not found]   ` <1432592573-13743-4-git-send-email-pierre.morrow-GANU6spQydw@public.gmane.org>
@ 2015-05-26  8:02     ` Samuel Pitoiset
  2015-05-26  8:27       ` [Nouveau] " Pierre Moreau
  0 siblings, 1 reply; 24+ messages in thread
From: Samuel Pitoiset @ 2015-05-26  8:02 UTC (permalink / raw)
  To: Pierre Moreau, nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
  Cc: bskeggs-H+wXaHxf7aLQT0dZR+AlfA,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW



On 05/26/2015 12:22 AM, Pierre Moreau wrote:
> Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>
> ---
>   drm/nouveau/nouveau_acpi.c | 10 ++++------
>   1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/drm/nouveau/nouveau_acpi.c b/drm/nouveau/nouveau_acpi.c
> index 36f4a40..073f7d7 100644
> --- a/drm/nouveau/nouveau_acpi.c
> +++ b/drm/nouveau/nouveau_acpi.c
> @@ -88,15 +88,14 @@ static int nouveau_evaluate_optimus_dsm(acpi_handle handle, int func, int arg, u
>   	for (i = 0; i < 4; i++)
>   		args_buff[i] = (arg >> i * 8) & 0xFF;
>   
> -	*result = 0;
>   	obj = acpi_evaluate_dsm_typed(handle, nouveau_op_dsm_muid, nouveau_op_dsm_rid,
>   				      func, &argv4, ACPI_TYPE_BUFFER);
>   	if (!obj) {
>   		acpi_handle_info(handle, "failed to evaluate _DSM\n");
>   		return AE_ERROR;
>   	} else {
> -		if (obj->buffer.length == 4) {
> -			*result |= obj->buffer.pointer[0];
> +		if (!result && obj->buffer.length == 4) {
> +			*result  = obj->buffer.pointer[0];

segfault here if result is NULL! ;)

>   			*result |= (obj->buffer.pointer[1] << 8);
>   			*result |= (obj->buffer.pointer[2] << 16);
>   			*result |= (obj->buffer.pointer[3] << 24);
> @@ -322,18 +321,17 @@ void nouveau_register_dsm_handler(void)
>   /* Must be called for Optimus models before the card can be turned off */
>   void nouveau_switcheroo_optimus_dsm(void)
>   {
> -	u32 result = 0;
>   	if (!nouveau_dsm_priv.optimus_detected)
>   		return;
>   
>   	nouveau_evaluate_optimus_dsm(nouveau_dsm_priv.dhandle,
>   			             NOUVEAU_DSM_OPTIMUS_FLAGS,
> -			             0x3, &result);
> +			             0x3, NULL);
>   
>   	nouveau_evaluate_optimus_dsm(nouveau_dsm_priv.dhandle,
>   			             NOUVEAU_DSM_OPTIMUS_CAPS,
>   			             NOUVEAU_DSM_OPTIMUS_SET_POWERDOWN,
> -			             &result);
> +			             NULL);
>   
>   }
>   

_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 5/8] acpi: Check returned object type by Optimus _DSM locally
       [not found]     ` <1432592573-13743-5-git-send-email-pierre.morrow-GANU6spQydw@public.gmane.org>
@ 2015-05-26  8:08       ` Samuel Pitoiset
  0 siblings, 0 replies; 24+ messages in thread
From: Samuel Pitoiset @ 2015-05-26  8:08 UTC (permalink / raw)
  To: Pierre Moreau, nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
  Cc: bskeggs-H+wXaHxf7aLQT0dZR+AlfA,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW



On 05/26/2015 12:22 AM, Pierre Moreau wrote:
> Most _DSM will return an integer value of 0x80000002 when given an unknown
> UUID, revision ID or function ID. Checking locally allows us to differentiate
> that case from other ACPI errors, and to not report a "failed to evaluate _DSM"
> if 0x80000002 is returned which was confusing.
>
> Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>
> ---
>   drm/nouveau/nouveau_acpi.c | 15 ++++++++++++---
>   1 file changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/drm/nouveau/nouveau_acpi.c b/drm/nouveau/nouveau_acpi.c
> index 073f7d7..7aeaf7d 100644
> --- a/drm/nouveau/nouveau_acpi.c
> +++ b/drm/nouveau/nouveau_acpi.c
> @@ -88,12 +88,12 @@ static int nouveau_evaluate_optimus_dsm(acpi_handle handle, int func, int arg, u
>   	for (i = 0; i < 4; i++)
>   		args_buff[i] = (arg >> i * 8) & 0xFF;
>   
> -	obj = acpi_evaluate_dsm_typed(handle, nouveau_op_dsm_muid, nouveau_op_dsm_rid,
> -				      func, &argv4, ACPI_TYPE_BUFFER);
> +	obj = acpi_evaluate_dsm(handle, nouveau_op_dsm_muid, nouveau_op_dsm_rid,
> +			        func, &argv4);
>   	if (!obj) {
>   		acpi_handle_info(handle, "failed to evaluate _DSM\n");
>   		return AE_ERROR;
> -	} else {
> +	} else if (obj->type == ACPI_TYPE_BUFFER) {
>   		if (!result && obj->buffer.length == 4) {
>   			*result  = obj->buffer.pointer[0];
>   			*result |= (obj->buffer.pointer[1] << 8);
> @@ -101,6 +101,15 @@ static int nouveau_evaluate_optimus_dsm(acpi_handle handle, int func, int arg, u
>   			*result |= (obj->buffer.pointer[3] << 24);
>   		}
>   		ACPI_FREE(obj);
> +	} else if (obj->type == ACPI_TYPE_INTEGER &&
> +		   obj->integer.value == 0x80000002) {
> +		acpi_handle_debug(handle, "failed to query Optimus _DSM\n");
> +		ACPI_FREE(obj);
> +		return -ENODEV;
> +	} else {
> +		acpi_handle_err(handle, "unexpected returned value by Optimus _DSM\n");
> +		ACPI_FREE(obj);
> +		return AE_ERROR;
>   	}
>   
>   	return 0;

How do you handle the case where result is NULL and the type is 
ACPI_TYPE_BUFFER ?
Because you don't return any error. Is that expected?
_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 7/8] acpi: Add support for Apple Gmux _DMS
       [not found]   ` <1432592573-13743-7-git-send-email-pierre.morrow-GANU6spQydw@public.gmane.org>
@ 2015-05-26  8:13     ` Samuel Pitoiset
       [not found]       ` <55642B45.3020509-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 24+ messages in thread
From: Samuel Pitoiset @ 2015-05-26  8:13 UTC (permalink / raw)
  To: Pierre Moreau, nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
  Cc: bskeggs-H+wXaHxf7aLQT0dZR+AlfA,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW



On 05/26/2015 12:22 AM, Pierre Moreau wrote:
> Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>
> ---
>   drm/nouveau/nouveau_acpi.c | 53 ++++++++++++++++++++++++++++++++++++++++++++--
>   drm/nouveau/nouveau_acpi.h |  2 ++
>   drm/nouveau/nouveau_drm.c  |  6 ++++--
>   drm/nouveau/nouveau_vga.c  | 10 +++++----
>   4 files changed, 63 insertions(+), 8 deletions(-)
>
> diff --git a/drm/nouveau/nouveau_acpi.c b/drm/nouveau/nouveau_acpi.c
> index 104d291..3d6a1ea 100644
> --- a/drm/nouveau/nouveau_acpi.c
> +++ b/drm/nouveau/nouveau_acpi.c
> @@ -29,6 +29,10 @@
>   
>   #define NOUVEAU_DSM_OPTIMUS_SET_POWERDOWN (NOUVEAU_DSM_OPTIMUS_POWERDOWN_PS3 | NOUVEAU_DSM_OPTIMUS_FLAGS_CHANGED)
>   
> +#define NOUVEAU_DSM_GMUX_V1_CAPS (3 << 6)
> +
> +#define NOUVEAU_DSM_GMUX_V2_CAPS (1 << 1)
> +
>   /* result of the optimus caps function */
>   #define OPTIMUS_ENABLED (1 << 0)
>   #define OPTIMUS_STATUS_MASK (3 << 3)
> @@ -45,6 +49,7 @@
>   static struct nouveau_dsm_priv {
>   	bool mux_detected;
>   	bool optimus_detected;
> +	bool gmux_detected;
>   	acpi_handle dhandle;
>   	acpi_handle rom_handle;
>   } nouveau_dsm_priv;
> @@ -57,8 +62,13 @@ bool nouveau_has_mux(void) {
>   	return nouveau_dsm_priv.mux_detected;
>   }
>   
> +bool nouveau_has_gmux(void) {
> +	return nouveau_dsm_priv.gmux_detected;
> +}
> +
>   #define NOUVEAU_DSM_HAS_MUX 0x1
>   #define NOUVEAU_DSM_HAS_OPT 0x2
> +#define NOUVEAU_DSM_HAS_GMUX 0x4
>   
>   #ifdef CONFIG_VGA_SWITCHEROO
>   static const uint32_t nouveau_mux_dsm_rid = 0x00000102;
> @@ -73,6 +83,18 @@ static const char nouveau_op_dsm_muid[] = {
>   	0xA7, 0x2B, 0x60, 0x42, 0xA6, 0xB5, 0xBE, 0xE0,
>   };
>   
> +static const uint32_t nouveau_gmux_v1_dsm_rid = 0x0000101;
> +static const char nouveau_gmux_v1_dsm_muid[] = {
> +	0xA6, 0x69, 0x86, 0x99, 0xE9, 0x8B, 0xFB, 0x49,
> +	0xBD, 0xDB, 0x51, 0xA1, 0xEF, 0xE1, 0x9C, 0x3D,
> +};
> +
> +static const uint32_t nouveau_gmux_v2_dsm_rid = 0x0000001;
> +static const char nouveau_gmux_v2_dsm_muid[] = {
> +	0xC6, 0xB7, 0xB5, 0xA0, 0x18, 0x13, 0x1C, 0x44,
> +	0xB0, 0xC9, 0xFE, 0x69, 0x5E, 0xAF, 0x94, 0x9B,
> +};
> +
>   static int nouveau_evaluate_optimus_dsm(acpi_handle handle, int func, int arg, uint32_t *result)
>   {
>   	int i;
> @@ -161,6 +183,17 @@ static int nouveau_evaluate_mux_dsm(acpi_handle handle, int func, int arg)
>   	return ret;
>   }
>   
> +static int nouveau_check_gmux_dsm(acpi_handle handle)
> +{
> +	bool has_v1 = acpi_check_dsm(handle, nouveau_gmux_v1_dsm_muid,
> +			             nouveau_gmux_v1_dsm_rid,
> +			             NOUVEAU_DSM_GMUX_V1_CAPS);
> +	bool has_v2 = acpi_check_dsm(handle, nouveau_gmux_v2_dsm_muid,
> +			             nouveau_gmux_v2_dsm_rid,
> +			             NOUVEAU_DSM_GMUX_V2_CAPS);
> +	return has_v1 || has_v2;
> +}
> +
>   static int nouveau_dsm_switch_mux(acpi_handle handle, int mux_id)
>   {
>   	mxm_wmi_call_mxmx(mux_id == NOUVEAU_DSM_MUX_LED_STAMINA ? MXM_MXDS_ADAPTER_IGD : MXM_MXDS_ADAPTER_0);
> @@ -238,6 +271,9 @@ static int nouveau_dsm_pci_probe(struct pci_dev *pdev)
>   			   1 << NOUVEAU_DSM_MUX_POWER))
>   		retval |= NOUVEAU_DSM_HAS_MUX;
>   
> +	if (nouveau_check_gmux_dsm(dhandle))
> +		retval |= NOUVEAU_DSM_HAS_GMUX;
> +
>   	if (nouveau_check_optimus_dsm(dhandle))
>   		retval |= NOUVEAU_DSM_HAS_OPT;
>   
> @@ -263,6 +299,7 @@ static bool nouveau_dsm_detect(void)
>   	struct pci_dev *pdev = NULL;
>   	int has_dsm = 0;
>   	int has_optimus = 0;
> +	bool has_gmux = false;
>   	int vga_count = 0;
>   	bool guid_valid;
>   	int retval;
> @@ -283,6 +320,8 @@ static bool nouveau_dsm_detect(void)
>   			has_dsm |= 1;
>   		if (retval & NOUVEAU_DSM_HAS_OPT)
>   			has_optimus = 1;
> +		if (retval & NOUVEAU_DSM_HAS_GMUX)
> +			has_gmux = true;
>   	}
>   
>   	while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_3D << 8, pdev)) != NULL) {
> @@ -293,9 +332,11 @@ static bool nouveau_dsm_detect(void)
>   			has_dsm |= 1;
>   		if (retval & NOUVEAU_DSM_HAS_OPT)
>   			has_optimus = 1;
> +		if (retval & NOUVEAU_DSM_HAS_GMUX)
> +			has_gmux = true;
>   	}
>   
> -	/* find the optimus DSM or the mux DSM */
> +	/* find the optimus DSM, the mux DSM or the gmux DSM */
>   	if (has_optimus == 1) {
>   		acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
>   			&buffer);
> @@ -310,6 +351,13 @@ static bool nouveau_dsm_detect(void)
>   			acpi_method_name);
>   		nouveau_dsm_priv.mux_detected = true;
>   		ret = true;
> +	} else if (has_gmux) {
> +		acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
> +			&buffer);
> +		printk(KERN_INFO "VGA switcheroo: detected gmux DSM switching method %s handle\n",
> +			acpi_method_name);
> +		nouveau_dsm_priv.gmux_detected = true;
> +		ret = true;
>   	}
>   
>   
> @@ -321,7 +369,8 @@ void nouveau_register_dsm_handler(void)
>   	bool r;
>   
>   	r = nouveau_dsm_detect();
> -	if (!r)
> +	/* Apple Gmux will register its own vga switcheroo handler */
> +	if (!r || nouveau_has_gmux())
>   		return;
>   
>   	vga_switcheroo_register_handler(&nouveau_dsm_handler);
> diff --git a/drm/nouveau/nouveau_acpi.h b/drm/nouveau/nouveau_acpi.h
> index 2bd88a8..7fcfe82 100644
> --- a/drm/nouveau/nouveau_acpi.h
> +++ b/drm/nouveau/nouveau_acpi.h
> @@ -6,6 +6,7 @@
>   #if defined(CONFIG_ACPI) && defined(CONFIG_X86)
>   bool nouveau_is_optimus(void);
>   bool nouveau_has_mux(void);
> +bool nouveau_has_gmux(void);
>   void nouveau_register_dsm_handler(void);
>   void nouveau_unregister_dsm_handler(void);
>   void nouveau_switcheroo_optimus_dsm(void);
> @@ -15,6 +16,7 @@ void *nouveau_acpi_edid(struct drm_device *, struct drm_connector *);
>   #else
>   static inline bool nouveau_is_optimus(void) { return false; };
>   static inline bool nouveau_has_mux(void) { return false; };
> +static inline bool nouveau_has_gmux(void) { return false; };
>   static inline void nouveau_register_dsm_handler(void) {}
>   static inline void nouveau_unregister_dsm_handler(void) {}
>   static inline void nouveau_switcheroo_optimus_dsm(void) {}
> diff --git a/drm/nouveau/nouveau_drm.c b/drm/nouveau/nouveau_drm.c
> index c06a7a1..702aff8 100644
> --- a/drm/nouveau/nouveau_drm.c
> +++ b/drm/nouveau/nouveau_drm.c
> @@ -719,7 +719,8 @@ nouveau_pmops_runtime_suspend(struct device *dev)
>   	}
>   
>   	/* are we optimus enabled? */
> -	if (nouveau_runtime_pm == -1 && !nouveau_is_optimus() && !nouveau_has_mux()) {
> +	if (nouveau_runtime_pm == -1 &&
> +	    !nouveau_is_optimus() && !nouveau_has_mux() && !nouveau_has_gmux()) {
>   		DRM_DEBUG_DRIVER("failing to power off - not optimus\n");
>   		pm_runtime_forbid(dev);
>   		return -EBUSY;
> @@ -780,7 +781,8 @@ nouveau_pmops_runtime_idle(struct device *dev)
>   	}
>   
>   	/* are we optimus enabled? */
> -	if (nouveau_runtime_pm == -1 && !nouveau_is_optimus() && !nouveau_has_mux()) {
> +	if (nouveau_runtime_pm == -1 &&
> +	    !nouveau_is_optimus() && !nouveau_has_mux() && !nouveau_has_gmux()) {
>   		DRM_DEBUG_DRIVER("failing to power off - not optimus\n");
>   		pm_runtime_forbid(dev);
>   		return -EBUSY;
> diff --git a/drm/nouveau/nouveau_vga.c b/drm/nouveau/nouveau_vga.c
> index 9a6328f..3a7a9b9 100644
> --- a/drm/nouveau/nouveau_vga.c
> +++ b/drm/nouveau/nouveau_vga.c
> @@ -96,11 +96,12 @@ nouveau_vga_init(struct nouveau_drm *drm)
>   
>   	if (nouveau_runtime_pm == 1)
>   		runtime = true;
> -	if ((nouveau_runtime_pm == -1) && (nouveau_is_optimus() || nouveau_has_mux()))
> +	if ((nouveau_runtime_pm == -1) &&
> +	    (nouveau_is_optimus() || nouveau_has_mux() || nouveau_has_gmux()))
>   		runtime = true;
>   	vga_switcheroo_register_client(dev->pdev, &nouveau_switcheroo_ops, runtime);
>   
> -	if (runtime && nouveau_has_mux() && !nouveau_is_optimus())
> +	if (runtime && (nouveau_has_mux() || nouveau_has_gmux()) && !nouveau_is_optimus())
>   		vga_switcheroo_init_domain_pm_ops(drm->dev->dev, &drm->vga_pm_domain);
>   }
>   
> @@ -112,11 +113,12 @@ nouveau_vga_fini(struct nouveau_drm *drm)
>   
>   	if (nouveau_runtime_pm == 1)
>   		runtime = true;
> -	if ((nouveau_runtime_pm == -1) && (nouveau_is_optimus() || nouveau_has_mux()))
> +	if ((nouveau_runtime_pm == -1) &&
> +	    (nouveau_is_optimus() || nouveau_has_mux() || nouveau_has_gmux()))
>   		runtime = true;
>   

You could maybe factorize a bit here by adding nouveau_has_optimus(). 
What do you think?

>   	vga_switcheroo_unregister_client(dev->pdev);
> -	if (runtime && nouveau_has_mux() && !nouveau_is_optimus())
> +	if (runtime && (nouveau_has_mux() || nouveau_has_gmux()) && !nouveau_is_optimus())
>   		vga_switcheroo_fini_domain_pm_ops(drm->dev->dev);
>   	vga_client_register(dev->pdev, NULL, NULL, NULL);
>   }

_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [Nouveau] [PATCH 5/8] acpi: Check returned object type by Optimus _DSM locally
  2015-05-26  5:17           ` Ilia Mirkin
@ 2015-05-26  8:26             ` Pierre Moreau
       [not found]               ` <754009E0-60CD-4E58-BA04-5FF8F3315E23-GANU6spQydw@public.gmane.org>
  0 siblings, 1 reply; 24+ messages in thread
From: Pierre Moreau @ 2015-05-26  8:26 UTC (permalink / raw)
  To: Ilia Mirkin; +Cc: nouveau, Ben Skeggs, dri-devel


> On 26 May 2015, at 07:17, Ilia Mirkin <imirkin@alum.mit.edu> wrote:
> 
> On Tue, May 26, 2015 at 1:10 AM, Pierre Moreau <pierre.morrow@free.fr> wrote:
>>> On 26 May 2015, at 00:39, Ilia Mirkin <imirkin@alum.mit.edu> wrote:
>>> 
>>>> On Mon, May 25, 2015 at 6:22 PM, Pierre Moreau <pierre.morrow@free.fr> wrote:
>>>> Most _DSM will return an integer value of 0x80000002 when given an unknown
>>>> UUID, revision ID or function ID. Checking locally allows us to differentiate
>>>> that case from other ACPI errors, and to not report a "failed to evaluate _DSM"
>>>> if 0x80000002 is returned which was confusing.
>>>> 
>>>> Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>
>>>> ---
>>>> drm/nouveau/nouveau_acpi.c | 15 ++++++++++++---
>>>> 1 file changed, 12 insertions(+), 3 deletions(-)
>>>> 
>>>> diff --git a/drm/nouveau/nouveau_acpi.c b/drm/nouveau/nouveau_acpi.c
>>>> index 073f7d7..7aeaf7d 100644
>>>> --- a/drm/nouveau/nouveau_acpi.c
>>>> +++ b/drm/nouveau/nouveau_acpi.c
>>>> @@ -88,12 +88,12 @@ static int nouveau_evaluate_optimus_dsm(acpi_handle handle, int func, int arg, u
>>>>       for (i = 0; i < 4; i++)
>>>>               args_buff[i] = (arg >> i * 8) & 0xFF;
>>>> 
>>>> -       obj = acpi_evaluate_dsm_typed(handle, nouveau_op_dsm_muid, nouveau_op_dsm_rid,
>>>> -                                     func, &argv4, ACPI_TYPE_BUFFER);
>>>> +       obj = acpi_evaluate_dsm(handle, nouveau_op_dsm_muid, nouveau_op_dsm_rid,
>>>> +                               func, &argv4);
>>>>       if (!obj) {
>>>>               acpi_handle_info(handle, "failed to evaluate _DSM\n");
>>>>               return AE_ERROR;
>>>> -       } else {
>>>> +       } else if (obj->type == ACPI_TYPE_BUFFER) {
>>>>               if (!result && obj->buffer.length == 4) {
>>>>                       *result  = obj->buffer.pointer[0];
>>>>                       *result |= (obj->buffer.pointer[1] << 8);
>>>> @@ -101,6 +101,15 @@ static int nouveau_evaluate_optimus_dsm(acpi_handle handle, int func, int arg, u
>>>>                       *result |= (obj->buffer.pointer[3] << 24);
>>>>               }
>>>>               ACPI_FREE(obj);
>>>> +       } else if (obj->type == ACPI_TYPE_INTEGER &&
>>>> +                  obj->integer.value == 0x80000002) {
>>>> +               acpi_handle_debug(handle, "failed to query Optimus _DSM\n");
>>>> +               ACPI_FREE(obj);
>>>> +               return -ENODEV;
>>> 
>>> should this be AE_ERROR?
>> 
>> I would say no, because ACPI was parsed correctly, just that we didn't it give the correct arguments, or rather, the _DSM we tested isn't an Optimus one, but it could a mux or gmux. And I used ENODEV as it is the value returned by nouveau_evaluate_mux_dsm in the same context.
> 
> Hm ok. It just seemed odd to be returning AE_* in one context, and
> -ENODEV in another context -- they're different types of errors.
> However if the caller handles it, I guess it's OK... I haven't looked
> at the API in depth.

The caller doesn’t care about the returned error and just check wether
it’s non-zero (and sometimes it doesn’t even check).

> 
>> 
>>> 
>>>> +       } else {
>>>> +               acpi_handle_err(handle, "unexpected returned value by Optimus _DSM\n");
>>>> +               ACPI_FREE(obj);
>>>> +               return AE_ERROR;
>>>>       }
>>>> 
>>>>       return 0;
>>>> --
>>>> 2.4.1
>>>> 
>>>> _______________________________________________
>>>> Nouveau mailing list
>>>> Nouveau@lists.freedesktop.org
>>>> http://lists.freedesktop.org/mailman/listinfo/nouveau

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [Nouveau] [PATCH 4/8] acpi: Allow evaluate_optimus_dsm to take NULL results
  2015-05-26  8:02     ` Samuel Pitoiset
@ 2015-05-26  8:27       ` Pierre Moreau
  0 siblings, 0 replies; 24+ messages in thread
From: Pierre Moreau @ 2015-05-26  8:27 UTC (permalink / raw)
  To: Samuel Pitoiset; +Cc: nouveau, bskeggs, dri-devel


[-- Attachment #1.1: Type: text/plain, Size: 2033 bytes --]


> On 26 May 2015, at 10:02, Samuel Pitoiset <samuel.pitoiset@gmail.com> wrote:
> 
> 
> 
> On 05/26/2015 12:22 AM, Pierre Moreau wrote:
>> Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>
>> ---
>>  drm/nouveau/nouveau_acpi.c | 10 ++++------
>>  1 file changed, 4 insertions(+), 6 deletions(-)
>> 
>> diff --git a/drm/nouveau/nouveau_acpi.c b/drm/nouveau/nouveau_acpi.c
>> index 36f4a40..073f7d7 100644
>> --- a/drm/nouveau/nouveau_acpi.c
>> +++ b/drm/nouveau/nouveau_acpi.c
>> @@ -88,15 +88,14 @@ static int nouveau_evaluate_optimus_dsm(acpi_handle handle, int func, int arg, u
>>  	for (i = 0; i < 4; i++)
>>  		args_buff[i] = (arg >> i * 8) & 0xFF;
>>  -	*result = 0;
>>  	obj = acpi_evaluate_dsm_typed(handle, nouveau_op_dsm_muid, nouveau_op_dsm_rid,
>>  				      func, &argv4, ACPI_TYPE_BUFFER);
>>  	if (!obj) {
>>  		acpi_handle_info(handle, "failed to evaluate _DSM\n");
>>  		return AE_ERROR;
>>  	} else {
>> -		if (obj->buffer.length == 4) {
>> -			*result |= obj->buffer.pointer[0];
>> +		if (!result && obj->buffer.length == 4) {
>> +			*result  = obj->buffer.pointer[0];
> 
> segfault here if result is NULL! ;)

Good catch!

> 
>>  			*result |= (obj->buffer.pointer[1] << 8);
>>  			*result |= (obj->buffer.pointer[2] << 16);
>>  			*result |= (obj->buffer.pointer[3] << 24);
>> @@ -322,18 +321,17 @@ void nouveau_register_dsm_handler(void)
>>  /* Must be called for Optimus models before the card can be turned off */
>>  void nouveau_switcheroo_optimus_dsm(void)
>>  {
>> -	u32 result = 0;
>>  	if (!nouveau_dsm_priv.optimus_detected)
>>  		return;
>>    	nouveau_evaluate_optimus_dsm(nouveau_dsm_priv.dhandle,
>>  			             NOUVEAU_DSM_OPTIMUS_FLAGS,
>> -			             0x3, &result);
>> +			             0x3, NULL);
>>    	nouveau_evaluate_optimus_dsm(nouveau_dsm_priv.dhandle,
>>  			             NOUVEAU_DSM_OPTIMUS_CAPS,
>>  			             NOUVEAU_DSM_OPTIMUS_SET_POWERDOWN,
>> -			             &result);
>> +			             NULL);
>>    }


[-- Attachment #1.2: Type: text/html, Size: 11239 bytes --]

[-- Attachment #2: Type: text/plain, Size: 159 bytes --]

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 7/8] acpi: Add support for Apple Gmux _DMS
       [not found]       ` <55642B45.3020509-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2015-05-26  8:30         ` Pierre Moreau
  0 siblings, 0 replies; 24+ messages in thread
From: Pierre Moreau @ 2015-05-26  8:30 UTC (permalink / raw)
  To: Samuel Pitoiset
  Cc: nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	bskeggs-H+wXaHxf7aLQT0dZR+AlfA,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW


[-- Attachment #1.1: Type: text/plain, Size: 9176 bytes --]


> On 26 May 2015, at 10:13, Samuel Pitoiset <samuel.pitoiset-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> 
> 
> 
> On 05/26/2015 12:22 AM, Pierre Moreau wrote:
>> Signed-off-by: Pierre Moreau <pierre.morrow-GANU6spQydw@public.gmane.org>
>> ---
>>  drm/nouveau/nouveau_acpi.c | 53 ++++++++++++++++++++++++++++++++++++++++++++--
>>  drm/nouveau/nouveau_acpi.h |  2 ++
>>  drm/nouveau/nouveau_drm.c  |  6 ++++--
>>  drm/nouveau/nouveau_vga.c  | 10 +++++----
>>  4 files changed, 63 insertions(+), 8 deletions(-)
>> 
>> diff --git a/drm/nouveau/nouveau_acpi.c b/drm/nouveau/nouveau_acpi.c
>> index 104d291..3d6a1ea 100644
>> --- a/drm/nouveau/nouveau_acpi.c
>> +++ b/drm/nouveau/nouveau_acpi.c
>> @@ -29,6 +29,10 @@
>>    #define NOUVEAU_DSM_OPTIMUS_SET_POWERDOWN (NOUVEAU_DSM_OPTIMUS_POWERDOWN_PS3 | NOUVEAU_DSM_OPTIMUS_FLAGS_CHANGED)
>>  +#define NOUVEAU_DSM_GMUX_V1_CAPS (3 << 6)
>> +
>> +#define NOUVEAU_DSM_GMUX_V2_CAPS (1 << 1)
>> +
>>  /* result of the optimus caps function */
>>  #define OPTIMUS_ENABLED (1 << 0)
>>  #define OPTIMUS_STATUS_MASK (3 << 3)
>> @@ -45,6 +49,7 @@
>>  static struct nouveau_dsm_priv {
>>  	bool mux_detected;
>>  	bool optimus_detected;
>> +	bool gmux_detected;
>>  	acpi_handle dhandle;
>>  	acpi_handle rom_handle;
>>  } nouveau_dsm_priv;
>> @@ -57,8 +62,13 @@ bool nouveau_has_mux(void) {
>>  	return nouveau_dsm_priv.mux_detected;
>>  }
>>  +bool nouveau_has_gmux(void) {
>> +	return nouveau_dsm_priv.gmux_detected;
>> +}
>> +
>>  #define NOUVEAU_DSM_HAS_MUX 0x1
>>  #define NOUVEAU_DSM_HAS_OPT 0x2
>> +#define NOUVEAU_DSM_HAS_GMUX 0x4
>>    #ifdef CONFIG_VGA_SWITCHEROO
>>  static const uint32_t nouveau_mux_dsm_rid = 0x00000102;
>> @@ -73,6 +83,18 @@ static const char nouveau_op_dsm_muid[] = {
>>  	0xA7, 0x2B, 0x60, 0x42, 0xA6, 0xB5, 0xBE, 0xE0,
>>  };
>>  +static const uint32_t nouveau_gmux_v1_dsm_rid = 0x0000101;
>> +static const char nouveau_gmux_v1_dsm_muid[] = {
>> +	0xA6, 0x69, 0x86, 0x99, 0xE9, 0x8B, 0xFB, 0x49,
>> +	0xBD, 0xDB, 0x51, 0xA1, 0xEF, 0xE1, 0x9C, 0x3D,
>> +};
>> +
>> +static const uint32_t nouveau_gmux_v2_dsm_rid = 0x0000001;
>> +static const char nouveau_gmux_v2_dsm_muid[] = {
>> +	0xC6, 0xB7, 0xB5, 0xA0, 0x18, 0x13, 0x1C, 0x44,
>> +	0xB0, 0xC9, 0xFE, 0x69, 0x5E, 0xAF, 0x94, 0x9B,
>> +};
>> +
>>  static int nouveau_evaluate_optimus_dsm(acpi_handle handle, int func, int arg, uint32_t *result)
>>  {
>>  	int i;
>> @@ -161,6 +183,17 @@ static int nouveau_evaluate_mux_dsm(acpi_handle handle, int func, int arg)
>>  	return ret;
>>  }
>>  +static int nouveau_check_gmux_dsm(acpi_handle handle)
>> +{
>> +	bool has_v1 = acpi_check_dsm(handle, nouveau_gmux_v1_dsm_muid,
>> +			             nouveau_gmux_v1_dsm_rid,
>> +			             NOUVEAU_DSM_GMUX_V1_CAPS);
>> +	bool has_v2 = acpi_check_dsm(handle, nouveau_gmux_v2_dsm_muid,
>> +			             nouveau_gmux_v2_dsm_rid,
>> +			             NOUVEAU_DSM_GMUX_V2_CAPS);
>> +	return has_v1 || has_v2;
>> +}
>> +
>>  static int nouveau_dsm_switch_mux(acpi_handle handle, int mux_id)
>>  {
>>  	mxm_wmi_call_mxmx(mux_id == NOUVEAU_DSM_MUX_LED_STAMINA ? MXM_MXDS_ADAPTER_IGD : MXM_MXDS_ADAPTER_0);
>> @@ -238,6 +271,9 @@ static int nouveau_dsm_pci_probe(struct pci_dev *pdev)
>>  			   1 << NOUVEAU_DSM_MUX_POWER))
>>  		retval |= NOUVEAU_DSM_HAS_MUX;
>>  +	if (nouveau_check_gmux_dsm(dhandle))
>> +		retval |= NOUVEAU_DSM_HAS_GMUX;
>> +
>>  	if (nouveau_check_optimus_dsm(dhandle))
>>  		retval |= NOUVEAU_DSM_HAS_OPT;
>>  @@ -263,6 +299,7 @@ static bool nouveau_dsm_detect(void)
>>  	struct pci_dev *pdev = NULL;
>>  	int has_dsm = 0;
>>  	int has_optimus = 0;
>> +	bool has_gmux = false;
>>  	int vga_count = 0;
>>  	bool guid_valid;
>>  	int retval;
>> @@ -283,6 +320,8 @@ static bool nouveau_dsm_detect(void)
>>  			has_dsm |= 1;
>>  		if (retval & NOUVEAU_DSM_HAS_OPT)
>>  			has_optimus = 1;
>> +		if (retval & NOUVEAU_DSM_HAS_GMUX)
>> +			has_gmux = true;
>>  	}
>>    	while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_3D << 8, pdev)) != NULL) {
>> @@ -293,9 +332,11 @@ static bool nouveau_dsm_detect(void)
>>  			has_dsm |= 1;
>>  		if (retval & NOUVEAU_DSM_HAS_OPT)
>>  			has_optimus = 1;
>> +		if (retval & NOUVEAU_DSM_HAS_GMUX)
>> +			has_gmux = true;
>>  	}
>>  -	/* find the optimus DSM or the mux DSM */
>> +	/* find the optimus DSM, the mux DSM or the gmux DSM */
>>  	if (has_optimus == 1) {
>>  		acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
>>  			&buffer);
>> @@ -310,6 +351,13 @@ static bool nouveau_dsm_detect(void)
>>  			acpi_method_name);
>>  		nouveau_dsm_priv.mux_detected = true;
>>  		ret = true;
>> +	} else if (has_gmux) {
>> +		acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
>> +			&buffer);
>> +		printk(KERN_INFO "VGA switcheroo: detected gmux DSM switching method %s handle\n",
>> +			acpi_method_name);
>> +		nouveau_dsm_priv.gmux_detected = true;
>> +		ret = true;
>>  	}
>>    @@ -321,7 +369,8 @@ void nouveau_register_dsm_handler(void)
>>  	bool r;
>>    	r = nouveau_dsm_detect();
>> -	if (!r)
>> +	/* Apple Gmux will register its own vga switcheroo handler */
>> +	if (!r || nouveau_has_gmux())
>>  		return;
>>    	vga_switcheroo_register_handler(&nouveau_dsm_handler);
>> diff --git a/drm/nouveau/nouveau_acpi.h b/drm/nouveau/nouveau_acpi.h
>> index 2bd88a8..7fcfe82 100644
>> --- a/drm/nouveau/nouveau_acpi.h
>> +++ b/drm/nouveau/nouveau_acpi.h
>> @@ -6,6 +6,7 @@
>>  #if defined(CONFIG_ACPI) && defined(CONFIG_X86)
>>  bool nouveau_is_optimus(void);
>>  bool nouveau_has_mux(void);
>> +bool nouveau_has_gmux(void);
>>  void nouveau_register_dsm_handler(void);
>>  void nouveau_unregister_dsm_handler(void);
>>  void nouveau_switcheroo_optimus_dsm(void);
>> @@ -15,6 +16,7 @@ void *nouveau_acpi_edid(struct drm_device *, struct drm_connector *);
>>  #else
>>  static inline bool nouveau_is_optimus(void) { return false; };
>>  static inline bool nouveau_has_mux(void) { return false; };
>> +static inline bool nouveau_has_gmux(void) { return false; };
>>  static inline void nouveau_register_dsm_handler(void) {}
>>  static inline void nouveau_unregister_dsm_handler(void) {}
>>  static inline void nouveau_switcheroo_optimus_dsm(void) {}
>> diff --git a/drm/nouveau/nouveau_drm.c b/drm/nouveau/nouveau_drm.c
>> index c06a7a1..702aff8 100644
>> --- a/drm/nouveau/nouveau_drm.c
>> +++ b/drm/nouveau/nouveau_drm.c
>> @@ -719,7 +719,8 @@ nouveau_pmops_runtime_suspend(struct device *dev)
>>  	}
>>    	/* are we optimus enabled? */
>> -	if (nouveau_runtime_pm == -1 && !nouveau_is_optimus() && !nouveau_has_mux()) {
>> +	if (nouveau_runtime_pm == -1 &&
>> +	    !nouveau_is_optimus() && !nouveau_has_mux() && !nouveau_has_gmux()) {
>>  		DRM_DEBUG_DRIVER("failing to power off - not optimus\n");
>>  		pm_runtime_forbid(dev);
>>  		return -EBUSY;
>> @@ -780,7 +781,8 @@ nouveau_pmops_runtime_idle(struct device *dev)
>>  	}
>>    	/* are we optimus enabled? */
>> -	if (nouveau_runtime_pm == -1 && !nouveau_is_optimus() && !nouveau_has_mux()) {
>> +	if (nouveau_runtime_pm == -1 &&
>> +	    !nouveau_is_optimus() && !nouveau_has_mux() && !nouveau_has_gmux()) {
>>  		DRM_DEBUG_DRIVER("failing to power off - not optimus\n");
>>  		pm_runtime_forbid(dev);
>>  		return -EBUSY;
>> diff --git a/drm/nouveau/nouveau_vga.c b/drm/nouveau/nouveau_vga.c
>> index 9a6328f..3a7a9b9 100644
>> --- a/drm/nouveau/nouveau_vga.c
>> +++ b/drm/nouveau/nouveau_vga.c
>> @@ -96,11 +96,12 @@ nouveau_vga_init(struct nouveau_drm *drm)
>>    	if (nouveau_runtime_pm == 1)
>>  		runtime = true;
>> -	if ((nouveau_runtime_pm == -1) && (nouveau_is_optimus() || nouveau_has_mux()))
>> +	if ((nouveau_runtime_pm == -1) &&
>> +	    (nouveau_is_optimus() || nouveau_has_mux() || nouveau_has_gmux()))
>>  		runtime = true;
>>  	vga_switcheroo_register_client(dev->pdev, &nouveau_switcheroo_ops, runtime);
>>  -	if (runtime && nouveau_has_mux() && !nouveau_is_optimus())
>> +	if (runtime && (nouveau_has_mux() || nouveau_has_gmux()) && !nouveau_is_optimus())
>>  		vga_switcheroo_init_domain_pm_ops(drm->dev->dev, &drm->vga_pm_domain);
>>  }
>>  @@ -112,11 +113,12 @@ nouveau_vga_fini(struct nouveau_drm *drm)
>>    	if (nouveau_runtime_pm == 1)
>>  		runtime = true;
>> -	if ((nouveau_runtime_pm == -1) && (nouveau_is_optimus() || nouveau_has_mux()))
>> +	if ((nouveau_runtime_pm == -1) &&
>> +	    (nouveau_is_optimus() || nouveau_has_mux() || nouveau_has_gmux()))
>>  		runtime = true;
>>  
> 
> You could maybe factorize a bit here by adding nouveau_has_optimus(). What do you think?

I was thinking of something like that, but I wasn’t sure about the name. Using optimus seems tricky, because you could have nouveau_is_optimus(): false but nouveau_has_optimus(): true…

> 
>>  	vga_switcheroo_unregister_client(dev->pdev);
>> -	if (runtime && nouveau_has_mux() && !nouveau_is_optimus())
>> +	if (runtime && (nouveau_has_mux() || nouveau_has_gmux()) && !nouveau_is_optimus())
>>  		vga_switcheroo_fini_domain_pm_ops(drm->dev->dev);
>>  	vga_client_register(dev->pdev, NULL, NULL, NULL);
>>  }


[-- Attachment #1.2: Type: text/html, Size: 26782 bytes --]

[-- Attachment #2: Type: text/plain, Size: 153 bytes --]

_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 8/8] acpi: Use booleans when probing different _DSM types
       [not found]     ` <1432592573-13743-8-git-send-email-pierre.morrow-GANU6spQydw@public.gmane.org>
@ 2015-05-26 12:46       ` Pierre Moreau
       [not found]         ` <1279603096.13154002.1432644369153.JavaMail.root-x5ewXQG5twBsFmKuirFwRhh1pbbyJDp15NbjCUgZEJk@public.gmane.org>
  0 siblings, 1 reply; 24+ messages in thread
From: Pierre Moreau @ 2015-05-26 12:46 UTC (permalink / raw)
  To: nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
  Cc: bskeggs-H+wXaHxf7aLQT0dZR+AlfA,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

I'm thinking of re-writing this patch to just OR the different returned retval and test for individual bits directly in the final conditionals.
So this would give something like:


int retval = 0;

while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
	vga_count++;
	retval |= nouveau_dsm_pci_probe(pdev);
}
while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_3D << 8, pdev)) != NULL) {
	vga_count++;
	retval |= nouveau_dsm_pci_probe(pdev);
}

if (retval & NOUVEAU_DSM_HAS_OPT) {
	acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
		&buffer);
	printk(KERN_INFO "VGA switcheroo: detected Optimus DSM method %s handle\n",
		acpi_method_name);
	nouveau_dsm_priv.optimus_detected = true;
	ret = true;
} else if (vga_count == 2 && (retval & NOUVEAU_DSM_HAS_MUX) && guid_valid) {
	acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
		&buffer);
	printk(KERN_INFO "VGA switcheroo: detected mux DSM switching method %s handle\n",
		acpi_method_name);
	nouveau_dsm_priv.mux_detected = true;
	ret = true;
} else if (retval & NOUVEAU_DSM_HAS_GMUX) {
	acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
		&buffer);
	printk(KERN_INFO "VGA switcheroo: detected gmux DSM switching method %s handle\n",
		acpi_method_name);
	nouveau_dsm_priv.gmux_detected = true;
	ret = true;
}


Any opinions on this?

Pierre

----- Mail original -----
> Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>
> ---
>  drm/nouveau/nouveau_acpi.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/drm/nouveau/nouveau_acpi.c b/drm/nouveau/nouveau_acpi.c
> index 3d6a1ea..5d63621 100644
> --- a/drm/nouveau/nouveau_acpi.c
> +++ b/drm/nouveau/nouveau_acpi.c
> @@ -297,8 +297,8 @@ static bool nouveau_dsm_detect(void)
>  	char acpi_method_name[255] = { 0 };
>  	struct acpi_buffer buffer = {sizeof(acpi_method_name),
>  	acpi_method_name};
>  	struct pci_dev *pdev = NULL;
> -	int has_dsm = 0;
> -	int has_optimus = 0;
> +	bool has_mux = false;
> +	bool has_optimus = false;
>  	bool has_gmux = false;
>  	int vga_count = 0;
>  	bool guid_valid;
> @@ -317,9 +317,9 @@ static bool nouveau_dsm_detect(void)
>  
>  		retval = nouveau_dsm_pci_probe(pdev);
>  		if (retval & NOUVEAU_DSM_HAS_MUX)
> -			has_dsm |= 1;
> +			has_mux = true;
>  		if (retval & NOUVEAU_DSM_HAS_OPT)
> -			has_optimus = 1;
> +			has_optimus = true;
>  		if (retval & NOUVEAU_DSM_HAS_GMUX)
>  			has_gmux = true;
>  	}
> @@ -329,9 +329,9 @@ static bool nouveau_dsm_detect(void)
>  
>  		retval = nouveau_dsm_pci_probe(pdev);
>  		if (retval & NOUVEAU_DSM_HAS_MUX)
> -			has_dsm |= 1;
> +			has_mux = true;
>  		if (retval & NOUVEAU_DSM_HAS_OPT)
> -			has_optimus = 1;
> +			has_optimus = true;
>  		if (retval & NOUVEAU_DSM_HAS_GMUX)
>  			has_gmux = true;
>  	}
> @@ -344,7 +344,7 @@ static bool nouveau_dsm_detect(void)
>  			acpi_method_name);
>  		nouveau_dsm_priv.optimus_detected = true;
>  		ret = true;
> -	} else if (vga_count == 2 && has_dsm && guid_valid) {
> +	} else if (vga_count == 2 && has_mux && guid_valid) {
>  		acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
>  			&buffer);
>  		printk(KERN_INFO "VGA switcheroo: detected mux DSM switching
>  		method %s handle\n",
> --
> 2.4.1
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel
> 
_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 8/8] acpi: Use booleans when probing different _DSM types
       [not found]         ` <1279603096.13154002.1432644369153.JavaMail.root-x5ewXQG5twBsFmKuirFwRhh1pbbyJDp15NbjCUgZEJk@public.gmane.org>
@ 2015-05-26 20:42           ` Samuel Pitoiset
  0 siblings, 0 replies; 24+ messages in thread
From: Samuel Pitoiset @ 2015-05-26 20:42 UTC (permalink / raw)
  To: Pierre Moreau, nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW
  Cc: bskeggs-H+wXaHxf7aLQT0dZR+AlfA,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW



On 05/26/2015 02:46 PM, Pierre Moreau wrote:
> I'm thinking of re-writing this patch to just OR the different returned retval and test for individual bits directly in the final conditionals.
> So this would give something like:
>
>
> int retval = 0;
>
> while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
> 	vga_count++;
> 	retval |= nouveau_dsm_pci_probe(pdev);
> }
> while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_3D << 8, pdev)) != NULL) {
> 	vga_count++;
> 	retval |= nouveau_dsm_pci_probe(pdev);
> }
>
> if (retval & NOUVEAU_DSM_HAS_OPT) {
> 	acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
> 		&buffer);
> 	printk(KERN_INFO "VGA switcheroo: detected Optimus DSM method %s handle\n",
> 		acpi_method_name);
> 	nouveau_dsm_priv.optimus_detected = true;
> 	ret = true;
> } else if (vga_count == 2 && (retval & NOUVEAU_DSM_HAS_MUX) && guid_valid) {
> 	acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
> 		&buffer);
> 	printk(KERN_INFO "VGA switcheroo: detected mux DSM switching method %s handle\n",
> 		acpi_method_name);
> 	nouveau_dsm_priv.mux_detected = true;
> 	ret = true;
> } else if (retval & NOUVEAU_DSM_HAS_GMUX) {
> 	acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
> 		&buffer);
> 	printk(KERN_INFO "VGA switcheroo: detected gmux DSM switching method %s handle\n",
> 		acpi_method_name);
> 	nouveau_dsm_priv.gmux_detected = true;
> 	ret = true;
> }
>
>
> Any opinions on this?

If this improves readability of the code, go ahead.

>
> Pierre
>
> ----- Mail original -----
>> Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>
>> ---
>>   drm/nouveau/nouveau_acpi.c | 14 +++++++-------
>>   1 file changed, 7 insertions(+), 7 deletions(-)
>>
>> diff --git a/drm/nouveau/nouveau_acpi.c b/drm/nouveau/nouveau_acpi.c
>> index 3d6a1ea..5d63621 100644
>> --- a/drm/nouveau/nouveau_acpi.c
>> +++ b/drm/nouveau/nouveau_acpi.c
>> @@ -297,8 +297,8 @@ static bool nouveau_dsm_detect(void)
>>   	char acpi_method_name[255] = { 0 };
>>   	struct acpi_buffer buffer = {sizeof(acpi_method_name),
>>   	acpi_method_name};
>>   	struct pci_dev *pdev = NULL;
>> -	int has_dsm = 0;
>> -	int has_optimus = 0;
>> +	bool has_mux = false;
>> +	bool has_optimus = false;
>>   	bool has_gmux = false;
>>   	int vga_count = 0;
>>   	bool guid_valid;
>> @@ -317,9 +317,9 @@ static bool nouveau_dsm_detect(void)
>>   
>>   		retval = nouveau_dsm_pci_probe(pdev);
>>   		if (retval & NOUVEAU_DSM_HAS_MUX)
>> -			has_dsm |= 1;
>> +			has_mux = true;
>>   		if (retval & NOUVEAU_DSM_HAS_OPT)
>> -			has_optimus = 1;
>> +			has_optimus = true;
>>   		if (retval & NOUVEAU_DSM_HAS_GMUX)
>>   			has_gmux = true;
>>   	}
>> @@ -329,9 +329,9 @@ static bool nouveau_dsm_detect(void)
>>   
>>   		retval = nouveau_dsm_pci_probe(pdev);
>>   		if (retval & NOUVEAU_DSM_HAS_MUX)
>> -			has_dsm |= 1;
>> +			has_mux = true;
>>   		if (retval & NOUVEAU_DSM_HAS_OPT)
>> -			has_optimus = 1;
>> +			has_optimus = true;
>>   		if (retval & NOUVEAU_DSM_HAS_GMUX)
>>   			has_gmux = true;
>>   	}
>> @@ -344,7 +344,7 @@ static bool nouveau_dsm_detect(void)
>>   			acpi_method_name);
>>   		nouveau_dsm_priv.optimus_detected = true;
>>   		ret = true;
>> -	} else if (vga_count == 2 && has_dsm && guid_valid) {
>> +	} else if (vga_count == 2 && has_mux && guid_valid) {
>>   		acpi_get_name(nouveau_dsm_priv.dhandle, ACPI_FULL_PATHNAME,
>>   			&buffer);
>>   		printk(KERN_INFO "VGA switcheroo: detected mux DSM switching
>>   		method %s handle\n",
>> --
>> 2.4.1
>>
>> _______________________________________________
>> dri-devel mailing list
>> dri-devel@lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/dri-devel
>>
> _______________________________________________
> Nouveau mailing list
> Nouveau@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/nouveau

_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [Nouveau] [PATCH 1/8] acpi: Rename v1 DSM to mux to avoid ambiguity
  2015-05-25 22:22 [PATCH 1/8] acpi: Rename v1 DSM to mux to avoid ambiguity Pierre Moreau
                   ` (4 preceding siblings ...)
  2015-05-25 22:22 ` [PATCH 7/8] acpi: Add support for Apple Gmux _DMS Pierre Moreau
@ 2015-05-28  2:58 ` Dave Airlie
  5 siblings, 0 replies; 24+ messages in thread
From: Dave Airlie @ 2015-05-28  2:58 UTC (permalink / raw)
  To: Pierre Moreau; +Cc: nouveau, Ben Skeggs, dri-devel

On 26 May 2015 at 08:22, Pierre Moreau <pierre.morrow@free.fr> wrote:
> This is especially true when variables or functions are just called dsm without
> precising the v1.
>
> Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>

Seeems reasonable,

Reviewed-by: Dave Airlie <airlied@redhat.com>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 2/8] acpi: Add evaluate to functons evaluating _DSM
       [not found]         ` <5564284F.3080406-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2015-05-28  2:59           ` Dave Airlie
  0 siblings, 0 replies; 24+ messages in thread
From: Dave Airlie @ 2015-05-28  2:59 UTC (permalink / raw)
  To: Samuel Pitoiset; +Cc: nouveau, Ben Skeggs, dri-devel

On 26 May 2015 at 18:01, Samuel Pitoiset <samuel.pitoiset@gmail.com> wrote:
> s/functons/functions in the commit message.
>
>
> On 05/26/2015 12:22 AM, Pierre Moreau wrote:
>>
>> This makes it clearer when reading the function name, as well as following
>> the
>> names of the related ACPI function.
>>

Apart from Samuel's suggested fix,

Reviewed-by: Dave Airlie <airlied@redhat.com>
_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [Nouveau] [PATCH 3/8] acpi: Define static variables for revision ids
  2015-05-25 22:22 ` [PATCH 3/8] acpi: Define static variables for revision ids Pierre Moreau
@ 2015-05-28  2:59   ` Dave Airlie
  0 siblings, 0 replies; 24+ messages in thread
From: Dave Airlie @ 2015-05-28  2:59 UTC (permalink / raw)
  To: Pierre Moreau; +Cc: nouveau, Ben Skeggs, dri-devel

On 26 May 2015 at 08:22, Pierre Moreau <pierre.morrow@free.fr> wrote:
> Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>

Reviewed-by: Dave Airlie <airlied@redhat.com>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 5/8] acpi: Check returned object type by Optimus _DSM locally
       [not found]               ` <754009E0-60CD-4E58-BA04-5FF8F3315E23-GANU6spQydw@public.gmane.org>
@ 2015-05-28  3:03                 ` Dave Airlie
  0 siblings, 0 replies; 24+ messages in thread
From: Dave Airlie @ 2015-05-28  3:03 UTC (permalink / raw)
  To: Pierre Moreau
  Cc: nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW, Ben Skeggs

On 26 May 2015 at 18:26, Pierre Moreau <pierre.morrow@free.fr> wrote:
>
>> On 26 May 2015, at 07:17, Ilia Mirkin <imirkin@alum.mit.edu> wrote:
>>
>> On Tue, May 26, 2015 at 1:10 AM, Pierre Moreau <pierre.morrow@free.fr> wrote:
>>>> On 26 May 2015, at 00:39, Ilia Mirkin <imirkin@alum.mit.edu> wrote:
>>>>
>>>>> On Mon, May 25, 2015 at 6:22 PM, Pierre Moreau <pierre.morrow@free.fr> wrote:
>>>>> Most _DSM will return an integer val
ue of 0x80000002 when given an unknown
>>>>> UUID, revision ID or function ID. Checking locally allows us to differentiate
>>>>> that case from other ACPI errors, and to not report a "failed to evaluate _DSM"
>>>>> if 0x80000002 is returned which was confusing.
>>>>>
>>>>> Signed-off-by: Pierre Moreau <pierre.morrow@free.fr>
>>>>> ---
>>>>> drm/nouveau/nouveau_acpi.c | 15 ++++++++++++---
>>>>> 1 file changed, 12 insertions(+), 3 deletions(-)
>>>>>
>>>>> diff --git a/drm/nouveau/nouveau_acpi.c b/drm/nouveau/nouveau_acpi.c
>>>>> index 073f7d7..7aeaf7d 100644
>>>>> --- a/drm/nouveau/nouveau_acpi.c
>>>>> +++ b/drm/nouveau/nouveau_acpi.c
>>>>> @@ -88,12 +88,12 @@ static int nouveau_evaluate_optimus_dsm(acpi_handle handle, int func, int arg, u
>>>>>       for (i = 0; i < 4; i++)
>>>>>               args_buff[i] = (arg >> i * 8) & 0xFF;
>>>>>
>>>>> -       obj = acpi_evaluate_dsm_typed(handle, nouveau_op_dsm_muid, nouveau_op_dsm_rid,
>>>>> -                                     func, &argv4, ACPI_TYPE_BUFFER);
>>>>> +       obj = acpi_evaluate_dsm(handle, nouveau_op_dsm_muid, nouveau_op_dsm_rid,
>>>>> +                               func, &argv4);
>>>>>       if (!obj) {
>>>>>               acpi_handle_info(handle, "failed to evaluate _DSM\n");
>>>>>               return AE_ERROR;
>>>>> -       } else {
>>>>> +       } else if (obj->type == ACPI_TYPE_BUFFER) {
>>>>>               if (!result && obj->buffer.length == 4) {
>>>>>                       *result  = obj->buffer.pointer[0];
>>>>>                       *result |= (obj->buffer.pointer[1] << 8);
>>>>> @@ -101,6 +101,15 @@ static int nouveau_evaluate_optimus_dsm(acpi_handle handle, int func, int arg, u
>>>>>                       *result |= (obj->buffer.pointer[3] << 24);
>>>>>               }
>>>>>               ACPI_FREE(obj);
>>>>> +       } else if (obj->type == ACPI_TYPE_INTEGER &&
>>>>> +                  obj->integer.value == 0x80000002) {
>>>>> +               acpi_handle_debug(handle, "failed to query Optimus _DSM\n");
>>>>> +               ACPI_FREE(obj);
>>>>> +               return -ENODEV;
>>>>
>>>> should this be AE_ERROR?
>>>
>>> I would say no, because ACPI was parsed correctly, just that we didn't it give the correct arguments, or rather, the _DSM we tested isn't an Optimus one, but it could a mux or gmux. And I used ENODEV as it is the value returned by nouveau_evaluate_mux_dsm in the same context.
>>
>> Hm ok. It just seemed odd to be returning AE_* in one context, and
>> -ENODEV in another context -- they're different types of errors.
>> However if the caller handles it, I guess it's OK... I haven't looked
>> at the API in depth.
>
> The caller doesn’t care about the returned error and just check wether
> it’s non-zero (and sometimes it doesn’t even check).

That's no reason to make it inconsistent, you should probably return
-EINVAL for the AE_ERROR case.

Dave.
_______________________________________________
Nouveau mailing list
Nouveau@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/nouveau

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2015-05-28  3:03 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-25 22:22 [PATCH 1/8] acpi: Rename v1 DSM to mux to avoid ambiguity Pierre Moreau
     [not found] ` <1432592573-13743-1-git-send-email-pierre.morrow-GANU6spQydw@public.gmane.org>
2015-05-25 22:22   ` [PATCH 2/8] acpi: Add evaluate to functons evaluating _DSM Pierre Moreau
     [not found]     ` <1432592573-13743-2-git-send-email-pierre.morrow-GANU6spQydw@public.gmane.org>
2015-05-26  8:01       ` Samuel Pitoiset
     [not found]         ` <5564284F.3080406-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-05-28  2:59           ` Dave Airlie
2015-05-25 22:22   ` [PATCH 5/8] acpi: Check returned object type by Optimus _DSM locally Pierre Moreau
2015-05-25 22:39     ` [Nouveau] " Ilia Mirkin
2015-05-26  5:10       ` Pierre Moreau
     [not found]         ` <84DFBDB0-0382-479C-8019-7CD888B7B466-GANU6spQydw@public.gmane.org>
2015-05-26  5:17           ` Ilia Mirkin
2015-05-26  8:26             ` [Nouveau] " Pierre Moreau
     [not found]               ` <754009E0-60CD-4E58-BA04-5FF8F3315E23-GANU6spQydw@public.gmane.org>
2015-05-28  3:03                 ` Dave Airlie
     [not found]     ` <1432592573-13743-5-git-send-email-pierre.morrow-GANU6spQydw@public.gmane.org>
2015-05-26  8:08       ` Samuel Pitoiset
2015-05-25 22:22   ` [PATCH 8/8] acpi: Use booleans when probing different _DSM types Pierre Moreau
     [not found]     ` <1432592573-13743-8-git-send-email-pierre.morrow-GANU6spQydw@public.gmane.org>
2015-05-26 12:46       ` Pierre Moreau
     [not found]         ` <1279603096.13154002.1432644369153.JavaMail.root-x5ewXQG5twBsFmKuirFwRhh1pbbyJDp15NbjCUgZEJk@public.gmane.org>
2015-05-26 20:42           ` Samuel Pitoiset
2015-05-25 22:22 ` [PATCH 3/8] acpi: Define static variables for revision ids Pierre Moreau
2015-05-28  2:59   ` [Nouveau] " Dave Airlie
2015-05-25 22:22 ` [PATCH 4/8] acpi: Allow evaluate_optimus_dsm to take NULL results Pierre Moreau
     [not found]   ` <1432592573-13743-4-git-send-email-pierre.morrow-GANU6spQydw@public.gmane.org>
2015-05-26  8:02     ` Samuel Pitoiset
2015-05-26  8:27       ` [Nouveau] " Pierre Moreau
2015-05-25 22:22 ` [PATCH 6/8] acpi: Improve some messages level and content Pierre Moreau
2015-05-25 22:22 ` [PATCH 7/8] acpi: Add support for Apple Gmux _DMS Pierre Moreau
     [not found]   ` <1432592573-13743-7-git-send-email-pierre.morrow-GANU6spQydw@public.gmane.org>
2015-05-26  8:13     ` Samuel Pitoiset
     [not found]       ` <55642B45.3020509-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-05-26  8:30         ` Pierre Moreau
2015-05-28  2:58 ` [Nouveau] [PATCH 1/8] acpi: Rename v1 DSM to mux to avoid ambiguity Dave Airlie

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.