public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: Maximilian Luz <luzmaximilian@gmail.com>
To: "Schmauss, Erik" <erik.schmauss@intel.com>,
	"Moore, Robert" <robert.moore@intel.com>,
	"Wysocki, Rafael J" <rafael.j.wysocki@intel.com>
Cc: "linux-acpi@vger.kernel.org" <linux-acpi@vger.kernel.org>,
	"devel@acpica.org" <devel@acpica.org>
Subject: Re: PROBLEM: Calling ObjectType on buffer field reports type integer
Date: Sat, 23 Nov 2019 01:33:28 +0100	[thread overview]
Message-ID: <20f023a8-67f2-71dd-266d-700012c05b39@gmail.com> (raw)
In-Reply-To: <CF6A88132359CE47947DB4C6E1709ED53C68481C@ORSMSX122.amr.corp.intel.com>


On 11/23/19 12:29 AM, Schmauss, Erik wrote:
> Bob and I started debugging this and we found the issue:
> 
> Let's say that we have this code:
> 
> Name (BUF1, Buffer (0x10) {})
> Method (M001)
> {
>      CreateField (BUF1, 1, 72, FLD0)
>      local0 = FLD0 // BUG: store operator (aka =)  converts FLD0 into an integer
>      return (ObjectType (local0)) // Integer is returned
> }
> 
> Although FLD0's value is small enough to fit in an integer, the bit length of FLD0 exceeds 64 bits so local0 should actually be a Buffer type.
> 
> This is likely an issue in the implicit object conversion rules implemented in the store operator. I'll take a look at this next week or the week after...

This looks like a separate problem to me. On the SB2 there is this piece
of code, simplified:

     Name(RQBF, Buffer (0xFF) {})
     CreateByteField (RQBF, 0x03, ALEN)

     // ...
     // GenericSerialBus/AttribRawProcessBytes access to fill RQBF
     // ...

     If (/* success and everything is valid */)
     {
         Local3 = (ALEN * 0x08)
         CreateField (RQBF, 0x20, Local3, ARB)
         Local4 = ARB /* \_SB_._SAN.RQSX.ARB_ */
     }
     Else
     {
         Local4 = 0x01   // or some other error code as integer
     }

     // ...
     // some more stuff
     // ...

     If ((ObjectType (Local4) == One /* Integer */))
     {
         // notify that an error has occurred
     }
     Else
     {
         // success and actually use data from Local4
     }

The code in question basically unpacks a payload from some other
management stuff sent over the OperationRegion.

Here, ALEN is the length of a dynamically sized payload in bytes, which
is obtained from the data returned by the OperationRegion access. This
can for example be 4, making the field length 32 bit. So this is not an
issue of the field length being larger than intmax bits, it actually is
sometimes only 32 bits, or 8 bits, depending on the response of the
driver connected to the OperationRegion. Also the DSDT depends on that,
see the example below.

Just to reiterate, the code works fine for payloads with ALEN > 8 (so
more than 8 bytes), but fails for anything less.

Also note that this is not something that can be fixed by just telling
the GenericSerialBus/OperationRegion driver to just return 9 bytes
instead: There are length-checks on Local4 further down the line to
validate it actually contains what was requested.

An example of how this piece of code is actually used, if that helps
(again simplified):

     Method (RQST, 1)
     {
         // pretty much the code above
         Return (Local4)     // either payload or integer error code
     }

     Scope (_SB.BAT1)
     {
         Method (_STA, 0)
         {
             Local0 = RQST(0x01)     // request battery status

             If ((ObjectType (Local0) == 0x03))      // is buffer type
             {
                 If ((SizeOf (Local0) == 0x04))      // has length 4
                 {
                     CreateDWordField (Local0, 0, BAST)
                     Return (BAST)
                 }
             }

             Return (0x00)           // return default value
         }
     }


Regards,
Maximilian

  reply	other threads:[~2019-11-23  0:33 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <3ef42aa1-196d-f3db-0e5d-2fd84c198242@gmail.com>
     [not found] ` <CF6A88132359CE47947DB4C6E1709ED53C592D47@ORSMSX122.amr.corp.intel.com>
     [not found]   ` <CF6A88132359CE47947DB4C6E1709ED53C59405C@ORSMSX122.amr.corp.intel.com>
     [not found]     ` <fe4bcc1c-5c15-caa6-ce01-a5df962ff008@gmail.com>
     [not found]       ` <CF6A88132359CE47947DB4C6E1709ED53C5942CA@ORSMSX122.amr.corp.intel.com>
     [not found]         ` <51e156ec-c2ed-84be-13c0-99a213e1d4b7@gmail.com>
     [not found]           ` <CF6A88132359CE47947DB4C6E1709ED53C595C50@ORSMSX122.amr.corp.intel.com>
2019-07-20 20:45             ` PROBLEM: Calling ObjectType on buffer field reports type integer Maximilian Luz
2019-07-22 23:01               ` Schmauss, Erik
2019-07-23 11:38                 ` Maximilian Luz
2019-11-10 21:29                 ` Maximilian Luz
2019-11-22 17:11                   ` Moore, Robert
2019-11-22 22:07                     ` Moore, Robert
2019-11-22 23:00                       ` Maximilian Luz
2019-11-22 23:29                       ` Schmauss, Erik
2019-11-23  0:33                         ` Maximilian Luz [this message]
2019-11-27  0:25                           ` Schmauss, Erik
2019-12-03 22:21                             ` Kaneda, Erik
2019-12-04 19:33                               ` Maximilian Luz
2019-12-05 23:57                                 ` Kaneda, Erik
2019-12-06 13:48                                   ` Maximilian Luz

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=20f023a8-67f2-71dd-266d-700012c05b39@gmail.com \
    --to=luzmaximilian@gmail.com \
    --cc=devel@acpica.org \
    --cc=erik.schmauss@intel.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=robert.moore@intel.com \
    /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