All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lv Zheng <lv.zheng@intel.com>
To: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Len Brown <len.brown@intel.com>
Cc: Lv Zheng <lv.zheng@intel.com>, Lv Zheng <zetalog@gmail.com>,
	linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org,
	Bob Moore <robert.moore@intel.com>
Subject: [PATCH 10/15] ACPICA: Hardware: Add optimized access bit width support
Date: Wed,  4 May 2016 13:49:11 +0800	[thread overview]
Message-ID: <cc4ab42cfaa00fbbd2f6c2d5f124a8c90a2ae650.1462331121.git.lv.zheng@intel.com> (raw)
In-Reply-To: <cover.1462331120.git.lv.zheng@intel.com>

ACPICA commit c49a751b4dae7baec1790748a2b4b6e8ab599f51

For Access Size = 0, it actually can use user expected access bit width.
This patch implements this.

Besides of the ACPICA upstream commit, this patch also includes a fix fixing
the issue reported by the FreeBSD community.
The old register descriptors are translated in acpi_tb_init_generic_address()
with access_width being filled with 0. This breaks code in
acpi_hw_get_access_bit_width() when the registers are 16-bit IO ports and their
bit_width fields are filled with 16. The rapid fix is meant to make code
written for acpi_hw_get_access_bit_width() regression safer before the issue is
correctly fixed from acpi_tb_init_generic_address(). Reported by
John Baldwin <jhb@freebsd.org>, fixed by Lv Zheng <lv.zheng@intel.com>, tested
by Jung-uk Kim <jkim@freebsd.org>.

Link: https://github.com/acpica/acpica/commit/c49a751b
Reported-by: John Baldwin <jhb@freebsd.org>
Tested-by Jung-uk Kim <jkim@freebsd.org>.
Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Signed-off-by: Bob Moore <robert.moore@intel.com>
---
 drivers/acpi/acpica/hwregs.c |   49 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 47 insertions(+), 2 deletions(-)

diff --git a/drivers/acpi/acpica/hwregs.c b/drivers/acpi/acpica/hwregs.c
index 035fb52..892e677 100644
--- a/drivers/acpi/acpica/hwregs.c
+++ b/drivers/acpi/acpica/hwregs.c
@@ -51,6 +51,10 @@ ACPI_MODULE_NAME("hwregs")
 
 #if (!ACPI_REDUCED_HARDWARE)
 /* Local Prototypes */
+static u8
+acpi_hw_get_access_bit_width(struct acpi_generic_address *reg,
+			     u8 max_bit_width);
+
 static acpi_status
 acpi_hw_read_multiple(u32 *value,
 		      struct acpi_generic_address *register_a,
@@ -65,6 +69,48 @@ acpi_hw_write_multiple(u32 value,
 
 /******************************************************************************
  *
+ * FUNCTION:    acpi_hw_get_access_bit_width
+ *
+ * PARAMETERS:  reg                 - GAS register structure
+ *              max_bit_width       - Max bit_width supported (32 or 64)
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Obtain optimal access bit width
+ *
+ ******************************************************************************/
+
+static u8
+acpi_hw_get_access_bit_width(struct acpi_generic_address *reg, u8 max_bit_width)
+{
+	u64 address;
+
+	if (!reg->access_width) {
+		/*
+		 * Detect old register descriptors where only the bit_width field
+		 * makes senses. The target address is copied to handle possible
+		 * alignment issues.
+		 */
+		ACPI_MOVE_64_TO_64(&address, &reg->address);
+		if (!reg->bit_offset && reg->bit_width &&
+		    ACPI_IS_POWER_OF_TWO(reg->bit_width) &&
+		    ACPI_IS_ALIGNED(reg->bit_width, 8) &&
+		    ACPI_IS_ALIGNED(address, reg->bit_width)) {
+			return (reg->bit_width);
+		} else {
+			if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
+				return (32);
+			} else {
+				return (max_bit_width);
+			}
+		}
+	} else {
+		return (1 << (reg->access_width + 2));
+	}
+}
+
+/******************************************************************************
+ *
  * FUNCTION:    acpi_hw_validate_register
  *
  * PARAMETERS:  reg                 - GAS register structure
@@ -122,8 +168,7 @@ acpi_hw_validate_register(struct acpi_generic_address *reg,
 
 	/* Validate the bit_width, convert access_width into number of bits */
 
-	access_width = reg->access_width ? reg->access_width : 1;
-	access_width = 1 << (access_width + 2);
+	access_width = acpi_hw_get_access_bit_width(reg, max_bit_width);
 	bit_width =
 	    ACPI_ROUND_UP(reg->bit_offset + reg->bit_width, access_width);
 	if (max_bit_width < bit_width) {
-- 
1.7.10

WARNING: multiple messages have this Message-ID (diff)
From: Lv Zheng <lv.zheng@intel.com>
To: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Len Brown <len.brown@intel.com>
Cc: Lv Zheng <lv.zheng@intel.com>, Lv Zheng <zetalog@gmail.com>,
	<linux-kernel@vger.kernel.org>,
	linux-acpi@vger.kernel.org, Bob Moore <robert.moore@intel.com>
Subject: [PATCH 10/15] ACPICA: Hardware: Add optimized access bit width support
Date: Wed,  4 May 2016 13:49:11 +0800	[thread overview]
Message-ID: <cc4ab42cfaa00fbbd2f6c2d5f124a8c90a2ae650.1462331121.git.lv.zheng@intel.com> (raw)
In-Reply-To: <cover.1462331120.git.lv.zheng@intel.com>

ACPICA commit c49a751b4dae7baec1790748a2b4b6e8ab599f51

For Access Size = 0, it actually can use user expected access bit width.
This patch implements this.

Besides of the ACPICA upstream commit, this patch also includes a fix fixing
the issue reported by the FreeBSD community.
The old register descriptors are translated in acpi_tb_init_generic_address()
with access_width being filled with 0. This breaks code in
acpi_hw_get_access_bit_width() when the registers are 16-bit IO ports and their
bit_width fields are filled with 16. The rapid fix is meant to make code
written for acpi_hw_get_access_bit_width() regression safer before the issue is
correctly fixed from acpi_tb_init_generic_address(). Reported by
John Baldwin <jhb@freebsd.org>, fixed by Lv Zheng <lv.zheng@intel.com>, tested
by Jung-uk Kim <jkim@freebsd.org>.

Link: https://github.com/acpica/acpica/commit/c49a751b
Reported-by: John Baldwin <jhb@freebsd.org>
Tested-by Jung-uk Kim <jkim@freebsd.org>.
Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Signed-off-by: Bob Moore <robert.moore@intel.com>
---
 drivers/acpi/acpica/hwregs.c |   49 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 47 insertions(+), 2 deletions(-)

diff --git a/drivers/acpi/acpica/hwregs.c b/drivers/acpi/acpica/hwregs.c
index 035fb52..892e677 100644
--- a/drivers/acpi/acpica/hwregs.c
+++ b/drivers/acpi/acpica/hwregs.c
@@ -51,6 +51,10 @@ ACPI_MODULE_NAME("hwregs")
 
 #if (!ACPI_REDUCED_HARDWARE)
 /* Local Prototypes */
+static u8
+acpi_hw_get_access_bit_width(struct acpi_generic_address *reg,
+			     u8 max_bit_width);
+
 static acpi_status
 acpi_hw_read_multiple(u32 *value,
 		      struct acpi_generic_address *register_a,
@@ -65,6 +69,48 @@ acpi_hw_write_multiple(u32 value,
 
 /******************************************************************************
  *
+ * FUNCTION:    acpi_hw_get_access_bit_width
+ *
+ * PARAMETERS:  reg                 - GAS register structure
+ *              max_bit_width       - Max bit_width supported (32 or 64)
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Obtain optimal access bit width
+ *
+ ******************************************************************************/
+
+static u8
+acpi_hw_get_access_bit_width(struct acpi_generic_address *reg, u8 max_bit_width)
+{
+	u64 address;
+
+	if (!reg->access_width) {
+		/*
+		 * Detect old register descriptors where only the bit_width field
+		 * makes senses. The target address is copied to handle possible
+		 * alignment issues.
+		 */
+		ACPI_MOVE_64_TO_64(&address, &reg->address);
+		if (!reg->bit_offset && reg->bit_width &&
+		    ACPI_IS_POWER_OF_TWO(reg->bit_width) &&
+		    ACPI_IS_ALIGNED(reg->bit_width, 8) &&
+		    ACPI_IS_ALIGNED(address, reg->bit_width)) {
+			return (reg->bit_width);
+		} else {
+			if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
+				return (32);
+			} else {
+				return (max_bit_width);
+			}
+		}
+	} else {
+		return (1 << (reg->access_width + 2));
+	}
+}
+
+/******************************************************************************
+ *
  * FUNCTION:    acpi_hw_validate_register
  *
  * PARAMETERS:  reg                 - GAS register structure
@@ -122,8 +168,7 @@ acpi_hw_validate_register(struct acpi_generic_address *reg,
 
 	/* Validate the bit_width, convert access_width into number of bits */
 
-	access_width = reg->access_width ? reg->access_width : 1;
-	access_width = 1 << (access_width + 2);
+	access_width = acpi_hw_get_access_bit_width(reg, max_bit_width);
 	bit_width =
 	    ACPI_ROUND_UP(reg->bit_offset + reg->bit_width, access_width);
 	if (max_bit_width < bit_width) {
-- 
1.7.10

  parent reply	other threads:[~2016-05-04  5:49 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-04  5:47 [PATCH 00/15] ACPICA: 20160422 Release Lv Zheng
2016-05-04  5:47 ` Lv Zheng
2016-05-04  5:48 ` [PATCH 01/15] ACPICA: Linuxize: reduce divergences for 20160422 release Lv Zheng
2016-05-04  5:48   ` Lv Zheng
2016-05-04 21:37   ` Rafael J. Wysocki
2016-05-04 21:38     ` Rafael J. Wysocki
2016-05-05  2:16       ` Zheng, Lv
2016-05-05  2:15     ` Zheng, Lv
2016-05-04  5:48 ` [PATCH 02/15] ACPICA: Divergence: remove unwanted spaces for typedef Lv Zheng
2016-05-04  5:48   ` Lv Zheng
2016-05-04  5:48 ` [PATCH 03/15] ACPICA: Refactor evaluate_object to reduce nesting Lv Zheng
2016-05-04  5:48   ` Lv Zheng
2016-05-04  5:48 ` [PATCH 04/15] ACPICA: ACPI 6.1: Support for new PCCT subtable Lv Zheng
2016-05-04  5:48   ` Lv Zheng
2016-05-04  5:48 ` [PATCH 05/15] ACPICA: ACPI 6.0: Update _BIX support for new package element Lv Zheng
2016-05-04  5:48   ` Lv Zheng
2016-05-04  5:48 ` [PATCH 06/15] ACPICA: ACPI 6.0, tools/iasl: Add support for new resource descriptors Lv Zheng
2016-05-04  5:48   ` Lv Zheng
2016-05-04  5:48 ` [PATCH 07/15] ACPICA: Renamed some #defined flag constants for clarity Lv Zheng
2016-05-04  5:48   ` Lv Zheng
2016-05-04  5:48 ` [PATCH 08/15] ACPICA: Dispatcher: Update thread ID for recursive method calls Lv Zheng
2016-05-04  5:48   ` Lv Zheng
2016-05-04 15:10   ` Prarit Bhargava
2016-05-04 19:22     ` Rafael J. Wysocki
2016-05-04 20:30       ` Mario_Limonciello
2016-05-04 20:30         ` Mario_Limonciello
2016-05-04 20:45         ` Rafael J. Wysocki
2016-05-04  5:49 ` [PATCH 09/15] ACPICA: Utilities: Add ACPI_IS_ALIGNED() macro Lv Zheng
2016-05-04  5:49   ` Lv Zheng
2016-05-04  5:49 ` Lv Zheng [this message]
2016-05-04  5:49   ` [PATCH 10/15] ACPICA: Hardware: Add optimized access bit width support Lv Zheng
2016-05-04  5:49 ` [PATCH 11/15] ACPICA: Executer: Introduce a set of macros to handle bit width mask generation Lv Zheng
2016-05-04  5:49   ` Lv Zheng
2016-05-04  5:49 ` [PATCH 12/15] ACPICA: Hardware: Add access_width/bit_offset support in acpi_hw_read() Lv Zheng
2016-05-04  5:49   ` Lv Zheng
2016-05-04  5:49 ` [PATCH 13/15] ACPICA: Hardware: Add access_width/bit_offset support for acpi_hw_write() Lv Zheng
2016-05-04  5:49   ` Lv Zheng
2016-05-04  5:49 ` [PATCH 14/15] ACPICA: Move all ASCII utilities to a common file Lv Zheng
2016-05-04  5:49   ` Lv Zheng
2016-05-04  5:49 ` [PATCH 15/15] ACPICA: Update version to 20160422 Lv Zheng
2016-05-04  5:49   ` Lv Zheng
2016-05-05  4:57 ` [PATCH v2 00/13] ACPICA: 20160422 Release Lv Zheng
2016-05-05  4:57   ` Lv Zheng
2016-05-05  4:57   ` [PATCH v2 01/13] ACPICA: Divergence: remove unwanted spaces for typedef Lv Zheng
2016-05-05  4:57     ` Lv Zheng
2016-05-05  4:58   ` [PATCH v2 02/13] ACPICA: Refactor evaluate_object to reduce nesting Lv Zheng
2016-05-05  4:58     ` Lv Zheng
2016-05-05  4:58   ` [PATCH v2 03/13] ACPICA: ACPI 6.1: Support for new PCCT subtable Lv Zheng
2016-05-05  4:58     ` Lv Zheng
2016-05-05  4:58   ` [PATCH v2 04/13] ACPICA: ACPI 6.0: Update _BIX support for new package element Lv Zheng
2016-05-05  4:58     ` Lv Zheng
2016-05-05  4:58   ` [PATCH v2 05/13] ACPICA: ACPI 6.0, tools/iasl: Add support for new resource descriptors Lv Zheng
2016-05-05  4:58     ` Lv Zheng
2016-05-05  4:58   ` [PATCH v2 06/13] ACPICA: Renamed some #defined flag constants for clarity Lv Zheng
2016-05-05  4:58     ` Lv Zheng
2016-05-05  4:58   ` [PATCH v2 07/13] ACPICA: Utilities: Add ACPI_IS_ALIGNED() macro Lv Zheng
2016-05-05  4:58     ` Lv Zheng
2016-05-05  4:58   ` [PATCH v2 08/13] ACPICA: Hardware: Add optimized access bit width support Lv Zheng
2016-05-05  4:58     ` Lv Zheng
2016-05-25 19:17     ` Boris Ostrovsky
2016-05-26 16:26       ` Jan Beulich
2016-05-26 16:26       ` Jan Beulich
2016-05-26 16:26         ` Jan Beulich
2016-05-26 16:55         ` Boris Ostrovsky
2016-05-26 21:59           ` Boris Ostrovsky
2016-05-26 21:59           ` Boris Ostrovsky
2016-05-27  3:24           ` Zheng, Lv
2016-05-27  3:24           ` Zheng, Lv
2016-05-27  7:34           ` Zheng, Lv
2016-05-27  7:34           ` Zheng, Lv
2016-05-27 17:31             ` Boris Ostrovsky
2016-05-27 17:31             ` Boris Ostrovsky
2016-05-26 16:55         ` Boris Ostrovsky
2016-05-27  3:14       ` Zheng, Lv
2016-05-27  3:14       ` Zheng, Lv
2016-05-25 19:17     ` Boris Ostrovsky
2016-05-05  4:58   ` [PATCH v2 09/13] ACPICA: Executer: Introduce a set of macros to handle bit width mask generation Lv Zheng
2016-05-05  4:58     ` Lv Zheng
2016-05-05  4:58   ` [PATCH v2 10/13] ACPICA: ACPI 2.0, Hardware: Add access_width/bit_offset support in acpi_hw_read() Lv Zheng
2016-05-05  4:58     ` Lv Zheng
2016-05-05  5:00   ` [PATCH v2 11/13] ACPICA: ACPI 2.0, Hardware: Add access_width/bit_offset support for acpi_hw_write() Lv Zheng
2016-05-05  5:00     ` Lv Zheng
2016-05-05  5:00   ` [PATCH v2 12/13] ACPICA: Move all ASCII utilities to a common file Lv Zheng
2016-05-05  5:00     ` Lv Zheng
2016-05-05  5:00   ` [PATCH v2 13/13] ACPICA: Update version to 20160422 Lv Zheng
2016-05-05  5:00     ` Lv Zheng
2016-05-05 23:49   ` [PATCH v2 00/13] ACPICA: 20160422 Release Rafael J. Wysocki

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=cc4ab42cfaa00fbbd2f6c2d5f124a8c90a2ae650.1462331121.git.lv.zheng@intel.com \
    --to=lv.zheng@intel.com \
    --cc=len.brown@intel.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=rjw@rjwysocki.net \
    --cc=robert.moore@intel.com \
    --cc=zetalog@gmail.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 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.