* [PATCH v2 0/6] gpiolib: acpi: Refactor to shrink the code by ~8%
@ 2025-04-03 15:59 Andy Shevchenko
2025-04-03 15:59 ` [PATCH v2 1/6] gpiolib: acpi: Improve struct acpi_gpio_info memory footprint Andy Shevchenko
` (7 more replies)
0 siblings, 8 replies; 13+ messages in thread
From: Andy Shevchenko @ 2025-04-03 15:59 UTC (permalink / raw)
To: Andy Shevchenko, Bartosz Golaszewski, linux-gpio, linux-acpi,
linux-kernel
Cc: Mika Westerberg, Linus Walleij, Bartosz Golaszewski
A simple refactoring of the GPIO ACPI library parts to get an impressive
~8% code shrink on x86_64 and ~2% on x86_32. Also reduces a C code a bit.
add/remove: 0/2 grow/shrink: 0/5 up/down: 0/-1221 (-1221)
Function old new delta
acpi_gpio_property_lookup 425 414 -11
acpi_find_gpio.__UNIQUE_ID_ddebug478 56 - -56
acpi_dev_gpio_irq_wake_get_by.__UNIQUE_ID_ddebug480 56 - -56
acpi_find_gpio 354 216 -138
acpi_get_gpiod_by_index 462 307 -155
__acpi_find_gpio 877 638 -239
acpi_dev_gpio_irq_wake_get_by 695 129 -566
Total: Before=15375, After=14154, chg -7.94%
In v2:
- renamed par to params (Mika, Bart)
Andy Shevchenko (6):
gpiolib: acpi: Improve struct acpi_gpio_info memory footprint
gpiolib: acpi: Remove index parameter from acpi_gpio_property_lookup()
gpiolib: acpi: Reduce memory footprint for struct acpi_gpio_params
gpiolib: acpi: Rename par to params for better readability
gpiolib: acpi: Reuse struct acpi_gpio_params in struct
acpi_gpio_lookup
gpiolib: acpi: Deduplicate some code in __acpi_find_gpio()
drivers/gpio/gpiolib-acpi.c | 146 +++++++++++++++++-----------------
include/linux/gpio/consumer.h | 2 +-
2 files changed, 72 insertions(+), 76 deletions(-)
--
2.47.2
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v2 1/6] gpiolib: acpi: Improve struct acpi_gpio_info memory footprint
2025-04-03 15:59 [PATCH v2 0/6] gpiolib: acpi: Refactor to shrink the code by ~8% Andy Shevchenko
@ 2025-04-03 15:59 ` Andy Shevchenko
2025-04-03 15:59 ` [PATCH v2 2/6] gpiolib: acpi: Remove index parameter from acpi_gpio_property_lookup() Andy Shevchenko
` (6 subsequent siblings)
7 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2025-04-03 15:59 UTC (permalink / raw)
To: Andy Shevchenko, Bartosz Golaszewski, linux-gpio, linux-acpi,
linux-kernel
Cc: Mika Westerberg, Linus Walleij, Bartosz Golaszewski
The struct acpi_gpio_info has two boolean members that are located
not close to each other making two gaps due to alignment requirements.
Group them to improve memory footprint.
`pahole` difference before and after (on 32-bit):
- /* size: 36, cachelines: 1, members: 9 */
- /* sum members: 30, holes: 2, sum holes: 6 */
+ /* size: 32, cachelines: 1, members: 9 */
+ /* sum members: 30, holes: 1, sum holes: 2 */
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/gpio/gpiolib-acpi.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index 69caa35c58df..878b11c81c7b 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -96,10 +96,10 @@ struct acpi_gpio_chip {
* @adev: reference to ACPI device which consumes GPIO resource
* @flags: GPIO initialization flags
* @gpioint: if %true this GPIO is of type GpioInt otherwise type is GpioIo
+ * @wake_capable: wake capability as provided by ACPI
* @pin_config: pin bias as provided by ACPI
* @polarity: interrupt polarity as provided by ACPI
* @triggering: triggering type as provided by ACPI
- * @wake_capable: wake capability as provided by ACPI
* @debounce: debounce timeout as provided by ACPI
* @quirks: Linux specific quirks as provided by struct acpi_gpio_mapping
*/
@@ -107,10 +107,10 @@ struct acpi_gpio_info {
struct acpi_device *adev;
enum gpiod_flags flags;
bool gpioint;
+ bool wake_capable;
int pin_config;
int polarity;
int triggering;
- bool wake_capable;
unsigned int debounce;
unsigned int quirks;
};
--
2.47.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v2 2/6] gpiolib: acpi: Remove index parameter from acpi_gpio_property_lookup()
2025-04-03 15:59 [PATCH v2 0/6] gpiolib: acpi: Refactor to shrink the code by ~8% Andy Shevchenko
2025-04-03 15:59 ` [PATCH v2 1/6] gpiolib: acpi: Improve struct acpi_gpio_info memory footprint Andy Shevchenko
@ 2025-04-03 15:59 ` Andy Shevchenko
2025-04-03 15:59 ` [PATCH v2 3/6] gpiolib: acpi: Reduce memory footprint for struct acpi_gpio_params Andy Shevchenko
` (5 subsequent siblings)
7 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2025-04-03 15:59 UTC (permalink / raw)
To: Andy Shevchenko, Bartosz Golaszewski, linux-gpio, linux-acpi,
linux-kernel
Cc: Mika Westerberg, Linus Walleij, Bartosz Golaszewski
In all cases the supplied index is the same as the passed one in
the struct acpi_gpio_lookup. Remove index parameter and reuse one
from the struct acpi_gpio_lookup instead.
add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-14 (-14)
Function old new delta
acpi_get_gpiod_by_index 462 456 -6
acpi_gpio_property_lookup 425 417 -8
Total: Before=15375, After=15361, chg -0.09%
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/gpio/gpiolib-acpi.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index 878b11c81c7b..afeb8d1c7102 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -830,17 +830,17 @@ static int acpi_gpio_resource_lookup(struct acpi_gpio_lookup *lookup,
return 0;
}
-static int acpi_gpio_property_lookup(struct fwnode_handle *fwnode,
- const char *propname, int index,
+static int acpi_gpio_property_lookup(struct fwnode_handle *fwnode, const char *propname,
struct acpi_gpio_lookup *lookup)
{
struct fwnode_reference_args args;
+ unsigned int index = lookup->index;
unsigned int quirks = 0;
int ret;
memset(&args, 0, sizeof(args));
- ret = __acpi_node_get_property_reference(fwnode, propname, index, 3,
- &args);
+
+ ret = __acpi_node_get_property_reference(fwnode, propname, index, 3, &args);
if (ret) {
struct acpi_device *adev;
@@ -905,8 +905,7 @@ static struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev,
if (propname) {
dev_dbg(&adev->dev, "GPIO: looking up %s\n", propname);
- ret = acpi_gpio_property_lookup(acpi_fwnode_handle(adev),
- propname, index, &lookup);
+ ret = acpi_gpio_property_lookup(acpi_fwnode_handle(adev), propname, &lookup);
if (ret)
return ERR_PTR(ret);
@@ -955,7 +954,7 @@ static struct gpio_desc *acpi_get_gpiod_from_data(struct fwnode_handle *fwnode,
memset(&lookup, 0, sizeof(lookup));
lookup.index = index;
- ret = acpi_gpio_property_lookup(fwnode, propname, index, &lookup);
+ ret = acpi_gpio_property_lookup(fwnode, propname, &lookup);
if (ret)
return ERR_PTR(ret);
--
2.47.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v2 3/6] gpiolib: acpi: Reduce memory footprint for struct acpi_gpio_params
2025-04-03 15:59 [PATCH v2 0/6] gpiolib: acpi: Refactor to shrink the code by ~8% Andy Shevchenko
2025-04-03 15:59 ` [PATCH v2 1/6] gpiolib: acpi: Improve struct acpi_gpio_info memory footprint Andy Shevchenko
2025-04-03 15:59 ` [PATCH v2 2/6] gpiolib: acpi: Remove index parameter from acpi_gpio_property_lookup() Andy Shevchenko
@ 2025-04-03 15:59 ` Andy Shevchenko
2025-04-03 15:59 ` [PATCH v2 4/6] gpiolib: acpi: Rename par to params for better readability Andy Shevchenko
` (4 subsequent siblings)
7 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2025-04-03 15:59 UTC (permalink / raw)
To: Andy Shevchenko, Bartosz Golaszewski, linux-gpio, linux-acpi,
linux-kernel
Cc: Mika Westerberg, Linus Walleij, Bartosz Golaszewski
The line_index member in the struct acpi_gpio_params replicates
what is covered in the ACPI GpioIo() or GpioInt() resource.
The value there is limited to 16-bit one, so we don't really need
to have a full 32-bit storage for it. Together with followed
boolean the structure will be smaller.
add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-3 (-3)
Function old new delta
acpi_gpio_property_lookup 417 414 -3
Total: Before=15361, After=15358, chg -0.02%
`pahole` difference before and after:
- /* size: 12, cachelines: 1, members: 3 */
- /* padding: 3 */
+ /* size: 8, cachelines: 1, members: 3 */
+ /* padding: 1 */
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
include/linux/gpio/consumer.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index 45b651c05b9c..899179972bec 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -587,7 +587,7 @@ struct gpio_desc *devm_fwnode_gpiod_get(struct device *dev,
struct acpi_gpio_params {
unsigned int crs_entry_index;
- unsigned int line_index;
+ unsigned short line_index;
bool active_low;
};
--
2.47.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v2 4/6] gpiolib: acpi: Rename par to params for better readability
2025-04-03 15:59 [PATCH v2 0/6] gpiolib: acpi: Refactor to shrink the code by ~8% Andy Shevchenko
` (2 preceding siblings ...)
2025-04-03 15:59 ` [PATCH v2 3/6] gpiolib: acpi: Reduce memory footprint for struct acpi_gpio_params Andy Shevchenko
@ 2025-04-03 15:59 ` Andy Shevchenko
2025-04-03 15:59 ` [PATCH v2 5/6] gpiolib: acpi: Reuse struct acpi_gpio_params in struct acpi_gpio_lookup Andy Shevchenko
` (3 subsequent siblings)
7 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2025-04-03 15:59 UTC (permalink / raw)
To: Andy Shevchenko, Bartosz Golaszewski, linux-gpio, linux-acpi,
linux-kernel
Cc: Mika Westerberg, Linus Walleij, Bartosz Golaszewski
Rename par to params for better readability in acpi_get_driver_gpio_data().
No functional changes intended.
Requested-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/gpio/gpiolib-acpi.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index afeb8d1c7102..d6e9563d9364 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -653,12 +653,12 @@ static bool acpi_get_driver_gpio_data(struct acpi_device *adev,
for (gm = adev->driver_gpios; gm->name; gm++)
if (!strcmp(name, gm->name) && gm->data && index < gm->size) {
- const struct acpi_gpio_params *par = gm->data + index;
+ const struct acpi_gpio_params *params = gm->data + index;
args->fwnode = acpi_fwnode_handle(adev);
- args->args[0] = par->crs_entry_index;
- args->args[1] = par->line_index;
- args->args[2] = par->active_low;
+ args->args[0] = params->crs_entry_index;
+ args->args[1] = params->line_index;
+ args->args[2] = params->active_low;
args->nargs = 3;
*quirks = gm->quirks;
--
2.47.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v2 5/6] gpiolib: acpi: Reuse struct acpi_gpio_params in struct acpi_gpio_lookup
2025-04-03 15:59 [PATCH v2 0/6] gpiolib: acpi: Refactor to shrink the code by ~8% Andy Shevchenko
` (3 preceding siblings ...)
2025-04-03 15:59 ` [PATCH v2 4/6] gpiolib: acpi: Rename par to params for better readability Andy Shevchenko
@ 2025-04-03 15:59 ` Andy Shevchenko
2025-04-03 15:59 ` [PATCH v2 6/6] gpiolib: acpi: Deduplicate some code in __acpi_find_gpio() Andy Shevchenko
` (2 subsequent siblings)
7 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2025-04-03 15:59 UTC (permalink / raw)
To: Andy Shevchenko, Bartosz Golaszewski, linux-gpio, linux-acpi,
linux-kernel
Cc: Mika Westerberg, Linus Walleij, Bartosz Golaszewski
Some of the contents of struct acpi_gpio_lookup repeats what we have
in the struct acpi_gpio_params. Reuse the latter in the former.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/gpio/gpiolib-acpi.c | 36 +++++++++++++++++++-----------------
1 file changed, 19 insertions(+), 17 deletions(-)
diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index d6e9563d9364..f44d25df15cb 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -744,9 +744,7 @@ static int acpi_gpio_update_gpiod_lookup_flags(unsigned long *lookupflags,
struct acpi_gpio_lookup {
struct acpi_gpio_info info;
- int index;
- u16 pin_index;
- bool active_low;
+ struct acpi_gpio_params params;
struct gpio_desc *desc;
int n;
};
@@ -754,6 +752,7 @@ struct acpi_gpio_lookup {
static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)
{
struct acpi_gpio_lookup *lookup = data;
+ struct acpi_gpio_params *params = &lookup->params;
if (ares->type != ACPI_RESOURCE_TYPE_GPIO)
return 1;
@@ -765,12 +764,12 @@ static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)
u16 pin_index;
if (lookup->info.quirks & ACPI_GPIO_QUIRK_ONLY_GPIOIO && gpioint)
- lookup->index++;
+ params->crs_entry_index++;
- if (lookup->n++ != lookup->index)
+ if (lookup->n++ != params->crs_entry_index)
return 1;
- pin_index = lookup->pin_index;
+ pin_index = params->line_index;
if (pin_index >= agpio->pin_table_length)
return 1;
@@ -796,7 +795,7 @@ static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)
lookup->info.polarity = agpio->polarity;
lookup->info.triggering = agpio->triggering;
} else {
- lookup->info.polarity = lookup->active_low;
+ lookup->info.polarity = params->active_low;
}
lookup->info.flags = acpi_gpio_to_gpiod_flags(agpio, lookup->info.polarity);
@@ -834,7 +833,8 @@ static int acpi_gpio_property_lookup(struct fwnode_handle *fwnode, const char *p
struct acpi_gpio_lookup *lookup)
{
struct fwnode_reference_args args;
- unsigned int index = lookup->index;
+ struct acpi_gpio_params *params = &lookup->params;
+ unsigned int index = params->crs_entry_index;
unsigned int quirks = 0;
int ret;
@@ -857,9 +857,9 @@ static int acpi_gpio_property_lookup(struct fwnode_handle *fwnode, const char *p
if (args.nargs != 3)
return -EPROTO;
- lookup->index = args.args[0];
- lookup->pin_index = args.args[1];
- lookup->active_low = !!args.args[2];
+ params->crs_entry_index = args.args[0];
+ params->line_index = args.args[1];
+ params->active_low = !!args.args[2];
lookup->info.adev = to_acpi_device_node(args.fwnode);
lookup->info.quirks = quirks;
@@ -897,10 +897,11 @@ static struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev,
struct acpi_gpio_info *info)
{
struct acpi_gpio_lookup lookup;
+ struct acpi_gpio_params *params = &lookup.params;
int ret;
memset(&lookup, 0, sizeof(lookup));
- lookup.index = index;
+ params->crs_entry_index = index;
if (propname) {
dev_dbg(&adev->dev, "GPIO: looking up %s\n", propname);
@@ -909,11 +910,11 @@ static struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev,
if (ret)
return ERR_PTR(ret);
- dev_dbg(&adev->dev, "GPIO: _DSD returned %s %d %u %u\n",
- dev_name(&lookup.info.adev->dev), lookup.index,
- lookup.pin_index, lookup.active_low);
+ dev_dbg(&adev->dev, "GPIO: _DSD returned %s %u %u %u\n",
+ dev_name(&lookup.info.adev->dev),
+ params->crs_entry_index, params->line_index, params->active_low);
} else {
- dev_dbg(&adev->dev, "GPIO: looking up %d in _CRS\n", index);
+ dev_dbg(&adev->dev, "GPIO: looking up %u in _CRS\n", params->crs_entry_index);
lookup.info.adev = adev;
}
@@ -943,6 +944,7 @@ static struct gpio_desc *acpi_get_gpiod_from_data(struct fwnode_handle *fwnode,
struct acpi_gpio_info *info)
{
struct acpi_gpio_lookup lookup;
+ struct acpi_gpio_params *params = &lookup.params;
int ret;
if (!is_acpi_data_node(fwnode))
@@ -952,7 +954,7 @@ static struct gpio_desc *acpi_get_gpiod_from_data(struct fwnode_handle *fwnode,
return ERR_PTR(-EINVAL);
memset(&lookup, 0, sizeof(lookup));
- lookup.index = index;
+ params->crs_entry_index = index;
ret = acpi_gpio_property_lookup(fwnode, propname, &lookup);
if (ret)
--
2.47.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* [PATCH v2 6/6] gpiolib: acpi: Deduplicate some code in __acpi_find_gpio()
2025-04-03 15:59 [PATCH v2 0/6] gpiolib: acpi: Refactor to shrink the code by ~8% Andy Shevchenko
` (4 preceding siblings ...)
2025-04-03 15:59 ` [PATCH v2 5/6] gpiolib: acpi: Reuse struct acpi_gpio_params in struct acpi_gpio_lookup Andy Shevchenko
@ 2025-04-03 15:59 ` Andy Shevchenko
2025-04-08 20:09 ` Kees Bakker
2025-04-04 4:43 ` [PATCH v2 0/6] gpiolib: acpi: Refactor to shrink the code by ~8% Mika Westerberg
2025-04-04 8:38 ` Bartosz Golaszewski
7 siblings, 1 reply; 13+ messages in thread
From: Andy Shevchenko @ 2025-04-03 15:59 UTC (permalink / raw)
To: Andy Shevchenko, Bartosz Golaszewski, linux-gpio, linux-acpi,
linux-kernel
Cc: Mika Westerberg, Linus Walleij, Bartosz Golaszewski
__acpi_find_gpio() calls two functions depending on the supplied con_id
and possibility to fallback to _CRS lookup. Those functions have the same
pieces of code that can be done only in one place. Do it so.
This gives an impressive shrink of the generated code for x86_64:
add/remove: 0/2 grow/shrink: 0/4 up/down: 0/-1204 (-1204)
Function old new delta
acpi_find_gpio.__UNIQUE_ID_ddebug478 56 - -56
acpi_dev_gpio_irq_wake_get_by.__UNIQUE_ID_ddebug480 56 - -56
acpi_find_gpio 354 216 -138
acpi_get_gpiod_by_index 456 307 -149
__acpi_find_gpio 877 638 -239
acpi_dev_gpio_irq_wake_get_by 695 129 -566
Total: Before=15358, After=14154, chg -7.84%
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/gpio/gpiolib-acpi.c | 101 +++++++++++++++++-------------------
1 file changed, 48 insertions(+), 53 deletions(-)
diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index f44d25df15cb..b3fcb9d5a39f 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -804,8 +804,7 @@ static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)
return 1;
}
-static int acpi_gpio_resource_lookup(struct acpi_gpio_lookup *lookup,
- struct acpi_gpio_info *info)
+static int acpi_gpio_resource_lookup(struct acpi_gpio_lookup *lookup)
{
struct acpi_device *adev = lookup->info.adev;
struct list_head res_list;
@@ -824,8 +823,6 @@ static int acpi_gpio_resource_lookup(struct acpi_gpio_lookup *lookup,
if (!lookup->desc)
return -ENOENT;
- if (info)
- *info = lookup->info;
return 0;
}
@@ -871,97 +868,83 @@ static int acpi_gpio_property_lookup(struct fwnode_handle *fwnode, const char *p
* acpi_get_gpiod_by_index() - get a GPIO descriptor from device resources
* @adev: pointer to a ACPI device to get GPIO from
* @propname: Property name of the GPIO (optional)
- * @index: index of GpioIo/GpioInt resource (starting from %0)
- * @info: info pointer to fill in (optional)
+ * @lookup: pointer to struct acpi_gpio_lookup to fill in
*
- * Function goes through ACPI resources for @adev and based on @index looks
+ * Function goes through ACPI resources for @adev and based on @lookup.index looks
* up a GpioIo/GpioInt resource, translates it to the Linux GPIO descriptor,
- * and returns it. @index matches GpioIo/GpioInt resources only so if there
- * are total %3 GPIO resources, the index goes from %0 to %2.
+ * and returns it. @lookup.index matches GpioIo/GpioInt resources only so if there
+ * are total 3 GPIO resources, the index goes from 0 to 2.
*
* If @propname is specified the GPIO is looked using device property. In
* that case @index is used to select the GPIO entry in the property value
* (in case of multiple).
*
* Returns:
- * GPIO descriptor to use with Linux generic GPIO API.
- * If the GPIO cannot be translated or there is an error an ERR_PTR is
- * returned.
+ * 0 on success, negative errno on failure.
+ *
+ * The @lookup is filled with GPIO descriptor to use with Linux generic GPIO API.
+ * If the GPIO cannot be translated an error will be returned.
*
* Note: if the GPIO resource has multiple entries in the pin list, this
* function only returns the first.
*/
-static struct gpio_desc *acpi_get_gpiod_by_index(struct acpi_device *adev,
- const char *propname,
- int index,
- struct acpi_gpio_info *info)
+static int acpi_get_gpiod_by_index(struct acpi_device *adev, const char *propname,
+ struct acpi_gpio_lookup *lookup)
{
- struct acpi_gpio_lookup lookup;
- struct acpi_gpio_params *params = &lookup.params;
+ struct acpi_gpio_info *info = &lookup->info;
+ struct acpi_gpio_params *params = &lookup->params;
int ret;
- memset(&lookup, 0, sizeof(lookup));
- params->crs_entry_index = index;
-
if (propname) {
dev_dbg(&adev->dev, "GPIO: looking up %s\n", propname);
- ret = acpi_gpio_property_lookup(acpi_fwnode_handle(adev), propname, &lookup);
+ ret = acpi_gpio_property_lookup(acpi_fwnode_handle(adev), propname, lookup);
if (ret)
- return ERR_PTR(ret);
+ return ret;
dev_dbg(&adev->dev, "GPIO: _DSD returned %s %u %u %u\n",
- dev_name(&lookup.info.adev->dev),
+ dev_name(&info->adev->dev),
params->crs_entry_index, params->line_index, params->active_low);
} else {
dev_dbg(&adev->dev, "GPIO: looking up %u in _CRS\n", params->crs_entry_index);
- lookup.info.adev = adev;
+ info->adev = adev;
}
- ret = acpi_gpio_resource_lookup(&lookup, info);
- return ret ? ERR_PTR(ret) : lookup.desc;
+ return acpi_gpio_resource_lookup(lookup);
}
/**
* acpi_get_gpiod_from_data() - get a GPIO descriptor from ACPI data node
* @fwnode: pointer to an ACPI firmware node to get the GPIO information from
* @propname: Property name of the GPIO
- * @index: index of GpioIo/GpioInt resource (starting from %0)
- * @info: info pointer to fill in (optional)
+ * @lookup: pointer to struct acpi_gpio_lookup to fill in
*
* This function uses the property-based GPIO lookup to get to the GPIO
* resource with the relevant information from a data-only ACPI firmware node
* and uses that to obtain the GPIO descriptor to return.
*
* Returns:
- * GPIO descriptor to use with Linux generic GPIO API.
- * If the GPIO cannot be translated or there is an error an ERR_PTR is
- * returned.
+ * 0 on success, negative errno on failure.
+ *
+ * The @lookup is filled with GPIO descriptor to use with Linux generic GPIO API.
+ * If the GPIO cannot be translated an error will be returned.
*/
-static struct gpio_desc *acpi_get_gpiod_from_data(struct fwnode_handle *fwnode,
- const char *propname,
- int index,
- struct acpi_gpio_info *info)
+static int acpi_get_gpiod_from_data(struct fwnode_handle *fwnode, const char *propname,
+ struct acpi_gpio_lookup *lookup)
{
- struct acpi_gpio_lookup lookup;
- struct acpi_gpio_params *params = &lookup.params;
int ret;
if (!is_acpi_data_node(fwnode))
- return ERR_PTR(-ENODEV);
+ return -ENODEV;
if (!propname)
- return ERR_PTR(-EINVAL);
+ return -EINVAL;
- memset(&lookup, 0, sizeof(lookup));
- params->crs_entry_index = index;
-
- ret = acpi_gpio_property_lookup(fwnode, propname, &lookup);
+ ret = acpi_gpio_property_lookup(fwnode, propname, lookup);
if (ret)
- return ERR_PTR(ret);
+ return ret;
- ret = acpi_gpio_resource_lookup(&lookup, info);
- return ret ? ERR_PTR(ret) : lookup.desc;
+ return acpi_gpio_resource_lookup(lookup);
}
static bool acpi_can_fallback_to_crs(struct acpi_device *adev,
@@ -983,17 +966,24 @@ __acpi_find_gpio(struct fwnode_handle *fwnode, const char *con_id, unsigned int
bool can_fallback, struct acpi_gpio_info *info)
{
struct acpi_device *adev = to_acpi_device_node(fwnode);
+ struct acpi_gpio_lookup lookup;
struct gpio_desc *desc;
char propname[32];
+ int ret;
+
+ memset(&lookup, 0, sizeof(lookup));
+ lookup.params.crs_entry_index = idx;
/* Try first from _DSD */
for_each_gpio_property_name(propname, con_id) {
if (adev)
- desc = acpi_get_gpiod_by_index(adev,
- propname, idx, info);
+ ret = acpi_get_gpiod_by_index(adev, propname, &lookup);
else
- desc = acpi_get_gpiod_from_data(fwnode,
- propname, idx, info);
+ ret = acpi_get_gpiod_from_data(fwnode, propname, &lookup);
+ if (ret)
+ continue;
+
+ desc = lookup.desc;
if (PTR_ERR(desc) == -EPROBE_DEFER)
return desc;
@@ -1002,8 +992,13 @@ __acpi_find_gpio(struct fwnode_handle *fwnode, const char *con_id, unsigned int
}
/* Then from plain _CRS GPIOs */
- if (can_fallback)
- return acpi_get_gpiod_by_index(adev, NULL, idx, info);
+ if (can_fallback) {
+ ret = acpi_get_gpiod_by_index(adev, NULL, &lookup);
+ if (ret)
+ return ERR_PTR(ret);
+
+ return lookup.desc;
+ }
return ERR_PTR(-ENOENT);
}
--
2.47.2
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH v2 0/6] gpiolib: acpi: Refactor to shrink the code by ~8%
2025-04-03 15:59 [PATCH v2 0/6] gpiolib: acpi: Refactor to shrink the code by ~8% Andy Shevchenko
` (5 preceding siblings ...)
2025-04-03 15:59 ` [PATCH v2 6/6] gpiolib: acpi: Deduplicate some code in __acpi_find_gpio() Andy Shevchenko
@ 2025-04-04 4:43 ` Mika Westerberg
2025-04-07 6:41 ` Andy Shevchenko
2025-04-04 8:38 ` Bartosz Golaszewski
7 siblings, 1 reply; 13+ messages in thread
From: Mika Westerberg @ 2025-04-04 4:43 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Bartosz Golaszewski, linux-gpio, linux-acpi, linux-kernel,
Mika Westerberg, Linus Walleij, Bartosz Golaszewski
On Thu, Apr 03, 2025 at 06:59:11PM +0300, Andy Shevchenko wrote:
> A simple refactoring of the GPIO ACPI library parts to get an impressive
> ~8% code shrink on x86_64 and ~2% on x86_32. Also reduces a C code a bit.
>
> add/remove: 0/2 grow/shrink: 0/5 up/down: 0/-1221 (-1221)
> Function old new delta
> acpi_gpio_property_lookup 425 414 -11
> acpi_find_gpio.__UNIQUE_ID_ddebug478 56 - -56
> acpi_dev_gpio_irq_wake_get_by.__UNIQUE_ID_ddebug480 56 - -56
> acpi_find_gpio 354 216 -138
> acpi_get_gpiod_by_index 462 307 -155
> __acpi_find_gpio 877 638 -239
> acpi_dev_gpio_irq_wake_get_by 695 129 -566
> Total: Before=15375, After=14154, chg -7.94%
>
> In v2:
> - renamed par to params (Mika, Bart)
>
> Andy Shevchenko (6):
> gpiolib: acpi: Improve struct acpi_gpio_info memory footprint
> gpiolib: acpi: Remove index parameter from acpi_gpio_property_lookup()
> gpiolib: acpi: Reduce memory footprint for struct acpi_gpio_params
> gpiolib: acpi: Rename par to params for better readability
> gpiolib: acpi: Reuse struct acpi_gpio_params in struct
> acpi_gpio_lookup
> gpiolib: acpi: Deduplicate some code in __acpi_find_gpio()
Looks good now,
Acked-by: Mika Westerberg <westeri@kernel.org>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 0/6] gpiolib: acpi: Refactor to shrink the code by ~8%
2025-04-03 15:59 [PATCH v2 0/6] gpiolib: acpi: Refactor to shrink the code by ~8% Andy Shevchenko
` (6 preceding siblings ...)
2025-04-04 4:43 ` [PATCH v2 0/6] gpiolib: acpi: Refactor to shrink the code by ~8% Mika Westerberg
@ 2025-04-04 8:38 ` Bartosz Golaszewski
2025-04-04 10:23 ` Andy Shevchenko
7 siblings, 1 reply; 13+ messages in thread
From: Bartosz Golaszewski @ 2025-04-04 8:38 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Bartosz Golaszewski, linux-gpio, linux-acpi, linux-kernel,
Mika Westerberg, Linus Walleij
On Thu, Apr 3, 2025 at 6:00 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> A simple refactoring of the GPIO ACPI library parts to get an impressive
> ~8% code shrink on x86_64 and ~2% on x86_32. Also reduces a C code a bit.
>
> add/remove: 0/2 grow/shrink: 0/5 up/down: 0/-1221 (-1221)
> Function old new delta
> acpi_gpio_property_lookup 425 414 -11
> acpi_find_gpio.__UNIQUE_ID_ddebug478 56 - -56
> acpi_dev_gpio_irq_wake_get_by.__UNIQUE_ID_ddebug480 56 - -56
> acpi_find_gpio 354 216 -138
> acpi_get_gpiod_by_index 462 307 -155
> __acpi_find_gpio 877 638 -239
> acpi_dev_gpio_irq_wake_get_by 695 129 -566
> Total: Before=15375, After=14154, chg -7.94%
>
> In v2:
> - renamed par to params (Mika, Bart)
>
> Andy Shevchenko (6):
> gpiolib: acpi: Improve struct acpi_gpio_info memory footprint
> gpiolib: acpi: Remove index parameter from acpi_gpio_property_lookup()
> gpiolib: acpi: Reduce memory footprint for struct acpi_gpio_params
> gpiolib: acpi: Rename par to params for better readability
> gpiolib: acpi: Reuse struct acpi_gpio_params in struct
> acpi_gpio_lookup
> gpiolib: acpi: Deduplicate some code in __acpi_find_gpio()
>
> drivers/gpio/gpiolib-acpi.c | 146 +++++++++++++++++-----------------
> include/linux/gpio/consumer.h | 2 +-
> 2 files changed, 72 insertions(+), 76 deletions(-)
>
> --
> 2.47.2
>
Will you take it through your tree or do you want me to pick it up next week?
Bart
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 0/6] gpiolib: acpi: Refactor to shrink the code by ~8%
2025-04-04 8:38 ` Bartosz Golaszewski
@ 2025-04-04 10:23 ` Andy Shevchenko
0 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2025-04-04 10:23 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Bartosz Golaszewski, linux-gpio, linux-acpi, linux-kernel,
Mika Westerberg, Linus Walleij
On Fri, Apr 04, 2025 at 10:38:04AM +0200, Bartosz Golaszewski wrote:
...
> Will you take it through your tree or do you want me to pick it up next week?
Via my tree as usual.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 0/6] gpiolib: acpi: Refactor to shrink the code by ~8%
2025-04-04 4:43 ` [PATCH v2 0/6] gpiolib: acpi: Refactor to shrink the code by ~8% Mika Westerberg
@ 2025-04-07 6:41 ` Andy Shevchenko
0 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2025-04-07 6:41 UTC (permalink / raw)
To: Mika Westerberg
Cc: Bartosz Golaszewski, linux-gpio, linux-acpi, linux-kernel,
Mika Westerberg, Linus Walleij, Bartosz Golaszewski
On Fri, Apr 04, 2025 at 07:43:18AM +0300, Mika Westerberg wrote:
> On Thu, Apr 03, 2025 at 06:59:11PM +0300, Andy Shevchenko wrote:
> > A simple refactoring of the GPIO ACPI library parts to get an impressive
> > ~8% code shrink on x86_64 and ~2% on x86_32. Also reduces a C code a bit.
> >
> > add/remove: 0/2 grow/shrink: 0/5 up/down: 0/-1221 (-1221)
> > Function old new delta
> > acpi_gpio_property_lookup 425 414 -11
> > acpi_find_gpio.__UNIQUE_ID_ddebug478 56 - -56
> > acpi_dev_gpio_irq_wake_get_by.__UNIQUE_ID_ddebug480 56 - -56
> > acpi_find_gpio 354 216 -138
> > acpi_get_gpiod_by_index 462 307 -155
> > __acpi_find_gpio 877 638 -239
> > acpi_dev_gpio_irq_wake_get_by 695 129 -566
> > Total: Before=15375, After=14154, chg -7.94%
> Looks good now,
>
> Acked-by: Mika Westerberg <westeri@kernel.org>
Pushed to my review and testing queue, thanks!
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 6/6] gpiolib: acpi: Deduplicate some code in __acpi_find_gpio()
2025-04-03 15:59 ` [PATCH v2 6/6] gpiolib: acpi: Deduplicate some code in __acpi_find_gpio() Andy Shevchenko
@ 2025-04-08 20:09 ` Kees Bakker
2025-04-09 7:31 ` Andy Shevchenko
0 siblings, 1 reply; 13+ messages in thread
From: Kees Bakker @ 2025-04-08 20:09 UTC (permalink / raw)
To: Andy Shevchenko, Bartosz Golaszewski, linux-gpio, linux-acpi,
linux-kernel
Cc: Mika Westerberg, Linus Walleij, Bartosz Golaszewski
Op 03-04-2025 om 17:59 schreef Andy Shevchenko:
> __acpi_find_gpio() calls two functions depending on the supplied con_id
> and possibility to fallback to _CRS lookup. Those functions have the same
> pieces of code that can be done only in one place. Do it so.
>
> This gives an impressive shrink of the generated code for x86_64:
>
> add/remove: 0/2 grow/shrink: 0/4 up/down: 0/-1204 (-1204)
> Function old new delta
> acpi_find_gpio.__UNIQUE_ID_ddebug478 56 - -56
> acpi_dev_gpio_irq_wake_get_by.__UNIQUE_ID_ddebug480 56 - -56
> acpi_find_gpio 354 216 -138
> acpi_get_gpiod_by_index 456 307 -149
> __acpi_find_gpio 877 638 -239
> acpi_dev_gpio_irq_wake_get_by 695 129 -566
> Total: Before=15358, After=14154, chg -7.84%
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> drivers/gpio/gpiolib-acpi.c | 101 +++++++++++++++++-------------------
> 1 file changed, 48 insertions(+), 53 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
> index f44d25df15cb..b3fcb9d5a39f 100644
> --- a/drivers/gpio/gpiolib-acpi.c
> +++ b/drivers/gpio/gpiolib-acpi.c
> [...]
> @@ -983,17 +966,24 @@ __acpi_find_gpio(struct fwnode_handle *fwnode, const char *con_id, unsigned int
> bool can_fallback, struct acpi_gpio_info *info)
> {
> struct acpi_device *adev = to_acpi_device_node(fwnode);
> + struct acpi_gpio_lookup lookup;
> struct gpio_desc *desc;
> char propname[32];
> + int ret;
> +
> + memset(&lookup, 0, sizeof(lookup));
> + lookup.params.crs_entry_index = idx;
>
> /* Try first from _DSD */
> for_each_gpio_property_name(propname, con_id) {
> if (adev)
> - desc = acpi_get_gpiod_by_index(adev,
> - propname, idx, info);
> + ret = acpi_get_gpiod_by_index(adev, propname, &lookup);
> else
> - desc = acpi_get_gpiod_from_data(fwnode,
> - propname, idx, info);
> + ret = acpi_get_gpiod_from_data(fwnode, propname, &lookup);
> + if (ret)
> + continue;
> +
> + desc = lookup.desc;
> if (PTR_ERR(desc) == -EPROBE_DEFER)
> return desc;
>
> @@ -1002,8 +992,13 @@ __acpi_find_gpio(struct fwnode_handle *fwnode, const char *con_id, unsigned int
> }
>
> /* Then from plain _CRS GPIOs */
> - if (can_fallback)
> - return acpi_get_gpiod_by_index(adev, NULL, idx, info);
> + if (can_fallback) {
> + ret = acpi_get_gpiod_by_index(adev, NULL, &lookup);
> + if (ret)
> + return ERR_PTR(ret);
> +
> + return lookup.desc;
> + }
>
> return ERR_PTR(-ENOENT);
> }
Please, check the changes in this function again.
`__acpi_find_gpio` doesn't fill `info` anymore. The callers of this
function will continue with
an uninitialized struct.
--
Kees
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH v2 6/6] gpiolib: acpi: Deduplicate some code in __acpi_find_gpio()
2025-04-08 20:09 ` Kees Bakker
@ 2025-04-09 7:31 ` Andy Shevchenko
0 siblings, 0 replies; 13+ messages in thread
From: Andy Shevchenko @ 2025-04-09 7:31 UTC (permalink / raw)
To: Kees Bakker
Cc: Bartosz Golaszewski, linux-gpio, linux-acpi, linux-kernel,
Mika Westerberg, Linus Walleij, Bartosz Golaszewski
On Tue, Apr 08, 2025 at 10:09:25PM +0200, Kees Bakker wrote:
> Op 03-04-2025 om 17:59 schreef Andy Shevchenko:
...
> Please, check the changes in this function again.
> `__acpi_find_gpio` doesn't fill `info` anymore. The callers of this function
> will continue with
> an uninitialized struct.
My gosh, you are so right! Now I'm puzzled of what I was tested...
Nevertheless, I will fix this ASAP today, test (and double test to
be sure it works), and push it.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2025-04-09 7:31 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-03 15:59 [PATCH v2 0/6] gpiolib: acpi: Refactor to shrink the code by ~8% Andy Shevchenko
2025-04-03 15:59 ` [PATCH v2 1/6] gpiolib: acpi: Improve struct acpi_gpio_info memory footprint Andy Shevchenko
2025-04-03 15:59 ` [PATCH v2 2/6] gpiolib: acpi: Remove index parameter from acpi_gpio_property_lookup() Andy Shevchenko
2025-04-03 15:59 ` [PATCH v2 3/6] gpiolib: acpi: Reduce memory footprint for struct acpi_gpio_params Andy Shevchenko
2025-04-03 15:59 ` [PATCH v2 4/6] gpiolib: acpi: Rename par to params for better readability Andy Shevchenko
2025-04-03 15:59 ` [PATCH v2 5/6] gpiolib: acpi: Reuse struct acpi_gpio_params in struct acpi_gpio_lookup Andy Shevchenko
2025-04-03 15:59 ` [PATCH v2 6/6] gpiolib: acpi: Deduplicate some code in __acpi_find_gpio() Andy Shevchenko
2025-04-08 20:09 ` Kees Bakker
2025-04-09 7:31 ` Andy Shevchenko
2025-04-04 4:43 ` [PATCH v2 0/6] gpiolib: acpi: Refactor to shrink the code by ~8% Mika Westerberg
2025-04-07 6:41 ` Andy Shevchenko
2025-04-04 8:38 ` Bartosz Golaszewski
2025-04-04 10:23 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).