public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: Len Brown <lenb@kernel.org>,
	NaamaX Shachar <naamax.shachar@intel.com>,
	linux-acpi@vger.kernel.org
Subject: Re: [PATCH] ACPI: Run USB4 _OSC() first with query bit set
Date: Tue, 21 Nov 2023 07:48:51 +0200	[thread overview]
Message-ID: <20231121054851.GC1074920@black.fi.intel.com> (raw)
In-Reply-To: <CAJZ5v0iEt=GqEkVPp5iuBzKjKGxq9i7=W_L+NiOBk4oGiwyHdg@mail.gmail.com>

On Mon, Nov 20, 2023 at 05:54:28PM +0100, Rafael J. Wysocki wrote:
> On Tue, Nov 14, 2023 at 1:06 PM Mika Westerberg
> <mika.westerberg@linux.intel.com> wrote:
> >
> > The platform can deny certain tunneling from the OS and it does that by
> > clearing the control bits it does not want the OS to get and returning
> > with OSC_CAPABILITIES_MASK_ERROR bit set. Currently we do not handle
> > this properly so if this happens, for example when the platform denies
> > PCIe tunneling, we just fail the whole negotiation and revert back to
> > what the Thunderbolt driver is doing to figure out whether the
> > controller is running firmware connection manager or not. However, we
> > should honor what the platform returns.
> >
> > For this reason run the USB4 _OSC() first with query bit set, and then
> > use the returned control double word (that may contain some of the bits
> > cleared by the platform) and run it second time with query bit clear.
> >
> > While there, remove an extra space from the assignment of the control
> > double word.
> >
> > Reported-by: NaamaX Shachar <naamax.shachar@intel.com>
> > Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> > ---
> >  drivers/acpi/bus.c | 32 +++++++++++++++++++++++++++++---
> >  1 file changed, 29 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
> > index 72e64c0718c9..569bd15f211b 100644
> > --- a/drivers/acpi/bus.c
> > +++ b/drivers/acpi/bus.c
> > @@ -408,7 +408,7 @@ static void acpi_bus_decode_usb_osc(const char *msg, u32 bits)
> >  static u8 sb_usb_uuid_str[] = "23A0D13A-26AB-486C-9C5F-0FFA525A575A";
> >  static void acpi_bus_osc_negotiate_usb_control(void)
> >  {
> > -       u32 capbuf[3];
> > +       u32 capbuf[3], *capbuf_ret;
> >         struct acpi_osc_context context = {
> >                 .uuid_str = sb_usb_uuid_str,
> >                 .rev = 1,
> > @@ -428,7 +428,12 @@ static void acpi_bus_osc_negotiate_usb_control(void)
> >         control = OSC_USB_USB3_TUNNELING | OSC_USB_DP_TUNNELING |
> >                   OSC_USB_PCIE_TUNNELING | OSC_USB_XDOMAIN;
> >
> > -       capbuf[OSC_QUERY_DWORD] = 0;
> > +       /*
> > +        * Run _OSC first with query bit set, trying to get control over
> > +        * all tunneling. The platform can then clear out bits in the
> > +        * control dword that it does not want to grant to the OS.
> > +        */
> > +       capbuf[OSC_QUERY_DWORD] = OSC_QUERY_ENABLE;
> >         capbuf[OSC_SUPPORT_DWORD] = 0;
> >         capbuf[OSC_CONTROL_DWORD] = control;
> >
> > @@ -441,8 +446,29 @@ static void acpi_bus_osc_negotiate_usb_control(void)
> >                 goto out_free;
> >         }
> >
> > +       /*
> > +        * Run _OSC again now with query bit clear and the control dword
> > +        * matching what the platform granted (which may not have all
> > +        * the control bits set).
> > +        */
> > +       capbuf_ret = context.ret.pointer;
> > +
> > +       capbuf[OSC_QUERY_DWORD] = 0;
> > +       capbuf[OSC_CONTROL_DWORD] = capbuf_ret[OSC_CONTROL_DWORD];
> > +
> > +       kfree(context.ret.pointer);
> > +
> > +       status = acpi_run_osc(handle, &context);
> > +       if (ACPI_FAILURE(status))
> > +               return;
> > +
> > +       if (context.ret.length != sizeof(capbuf)) {
> > +               pr_info("USB4 _OSC: returned invalid length buffer\n");
> > +               goto out_free;
> > +       }
> > +
> >         osc_sb_native_usb4_control =
> > -               control &  acpi_osc_ctx_get_pci_control(&context);
> > +               control & acpi_osc_ctx_get_pci_control(&context);
> >
> >         acpi_bus_decode_usb_osc("USB4 _OSC: OS supports", control);
> >         acpi_bus_decode_usb_osc("USB4 _OSC: OS controls",
> > --
> 
> Applied as 6.8 material, but if you want me to push this for 6.7-rc,
> please let me know (in which case it would be nice to have a Fixes:
> tag to put on it).

Thanks! I think v6.8 is fine.

      reply	other threads:[~2023-11-21  5:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-14 12:06 [PATCH] ACPI: Run USB4 _OSC() first with query bit set Mika Westerberg
2023-11-20 16:54 ` Rafael J. Wysocki
2023-11-21  5:48   ` Mika Westerberg [this message]

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=20231121054851.GC1074920@black.fi.intel.com \
    --to=mika.westerberg@linux.intel.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=naamax.shachar@intel.com \
    --cc=rafael@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox