All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: linux-acpi@vger.kernel.org
Cc: rafael@kernel.org, andriy.shevchenko@intel.com
Subject: [PATCH 11/11] ACPI: property: Read buffer properties as integers
Date: Fri,  6 May 2022 16:00:25 +0300	[thread overview]
Message-ID: <20220506130025.984026-12-sakari.ailus@linux.intel.com> (raw)
In-Reply-To: <20220506130025.984026-1-sakari.ailus@linux.intel.com>

Instead of adding a new property type, read buffer properties as integers.
Even though the internal representation in ACPI is different, the data
type is the same (byte) than on 8-bit integers.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/acpi/property.c | 34 ++++++++++++++++++++++++++++++----
 1 file changed, 30 insertions(+), 4 deletions(-)

diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
index d3f6d95e0fb19..f23d15abadd65 100644
--- a/drivers/acpi/property.c
+++ b/drivers/acpi/property.c
@@ -1108,6 +1108,10 @@ static int acpi_data_prop_read_single(const struct acpi_device_data *data,
 		size_t i;						\
 									\
 		for (i = 0; i < nval; i++) {				\
+			if (items->type == ACPI_TYPE_BUFFER) {		\
+				val[i] = items->buffer.pointer[i];	\
+				continue;				\
+			}						\
 			if (items[i].type != ACPI_TYPE_INTEGER)		\
 				return -EPROTO;				\
 			if (items[i].integer.value > U##bits##_MAX)	\
@@ -1163,18 +1167,40 @@ static int acpi_data_prop_read(const struct acpi_device_data *data,
 	}
 
 	ret = acpi_data_get_property_array(data, propname, ACPI_TYPE_ANY, &obj);
+	if (ret && proptype >= DEV_PROP_U8 && proptype <= DEV_PROP_U64)
+		ret = acpi_data_get_property(data, propname, ACPI_TYPE_BUFFER,
+					     &obj);
 	if (ret)
 		return ret;
 
-	if (!val)
+	if (!val) {
+		if (obj->type == ACPI_TYPE_BUFFER)
+			return obj->buffer.length;
+
 		return obj->package.count;
+	}
 
-	if (proptype != DEV_PROP_STRING && nval > obj->package.count)
-		return -EOVERFLOW;
+	switch (proptype) {
+	case DEV_PROP_STRING:
+		break;
+	case DEV_PROP_U8 ... DEV_PROP_U64:
+		if (obj->type == ACPI_TYPE_BUFFER) {
+			if (nval <= obj->buffer.length)
+				break;
+			return -EOVERFLOW;
+		}
+		fallthrough;
+	default:
+		if (nval > obj->package.count)
+			return -EOVERFLOW;
+	}
 	if (nval == 0)
 		return -EINVAL;
 
-	items = obj->package.elements;
+	if (obj->type != ACPI_TYPE_BUFFER)
+		items = obj->package.elements;
+	else
+		items = obj;
 
 	switch (proptype) {
 	case DEV_PROP_U8:
-- 
2.30.2


      parent reply	other threads:[~2022-05-06 12:58 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-06 13:00 [PATCH 00/11] ACPI: Buffer property and reference as string support Sakari Ailus
2022-05-06 13:00 ` [PATCH 01/11] ACPI: property: Return type of acpi_add_nondev_subnodes() should be bool Sakari Ailus
2022-05-06 13:00 ` [PATCH 02/11] ACPI: acpica: Constify pathname argument for acpi_get_handle() Sakari Ailus
2022-05-17 16:21   ` Rafael J. Wysocki
2022-05-18 16:14     ` Sakari Ailus
2022-05-18 19:07       ` Rafael J. Wysocki
2022-05-18 19:41         ` Sakari Ailus
2022-05-19 18:05           ` Rafael J. Wysocki
2022-05-20  6:13             ` Sakari Ailus
2022-05-20 14:21               ` Shevchenko, Andriy
2022-05-06 13:00 ` [PATCH 03/11] ACPI: property: Tie data nodes to acpi handles Sakari Ailus
2022-05-06 13:00 ` [PATCH 04/11] ACPI: property: Use acpi_object_type consistently in property ref parsing Sakari Ailus
2022-05-06 13:00 ` [PATCH 05/11] ACPI: property: Move property ref argument parsing into a new function Sakari Ailus
2022-05-06 13:00 ` [PATCH 06/11] ACPI: property: Switch node property referencing from ifs to a switch Sakari Ailus
2022-05-06 13:00 ` [PATCH 07/11] ACPI: Initialise device child list early to access data nodes early Sakari Ailus
2022-05-06 13:28   ` Rafael J. Wysocki
2022-05-06 14:08     ` Sakari Ailus
2022-05-06 13:00 ` [PATCH 08/11] ACPI: property: Parse data node string references in properties Sakari Ailus
2022-05-06 13:00 ` [PATCH 09/11] ACPI: property: Unify integer value reading functions Sakari Ailus
2022-05-06 13:00 ` [PATCH 10/11] ACPI: property: Add support for parsing buffer property UUID Sakari Ailus
2022-05-06 13:00 ` Sakari Ailus [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=20220506130025.984026-12-sakari.ailus@linux.intel.com \
    --to=sakari.ailus@linux.intel.com \
    --cc=andriy.shevchenko@intel.com \
    --cc=linux-acpi@vger.kernel.org \
    --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 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.