All of lore.kernel.org
 help / color / mirror / Atom feed
From: Samuel Pitoiset <samuel.pitoiset-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Pierre Moreau <pierre.morrow-GANU6spQydw@public.gmane.org>,
	nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Cc: bskeggs-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Subject: Re: [PATCH 7/8] acpi: Add support for Apple Gmux _DMS
Date: Tue, 26 May 2015 10:13:57 +0200	[thread overview]
Message-ID: <55642B45.3020509@gmail.com> (raw)
In-Reply-To: <1432592573-13743-7-git-send-email-pierre.morrow-GANU6spQydw@public.gmane.org>



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

  parent reply	other threads:[~2015-05-26  8:13 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
     [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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55642B45.3020509@gmail.com \
    --to=samuel.pitoiset-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=bskeggs-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=pierre.morrow-GANU6spQydw@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.