2021-01-18 00:42:26

by Daniel Scally

[permalink] [raw]
Subject: [PATCH v2 0/7] Introduce intel_skl_int3472 driver

Hello all

v1 for this series was originally 14-18 of this series:
https://lore.kernel.org/linux-media/[email protected]/T/#m91934e12e3d033da2e768e952ea3b4a125ee3e67

At the moment in the kernel the ACPI _HID INT3472 is taken by the tps68470
MFD driver, but that driver can only handle some of the cases of that _HID
that we see. There are at least these three possibilities:

1. INT3472 devices that provide GPIOs through the usual framework and run
power and clocks through an operation region; this is the situation that
the current module handles and is seen on ChromeOS devices
2. INT3472 devices that provide GPIOs, plus clocks and regulators that are
meant to be driven through the usual frameworks, usually seen on devices
designed to run Windows
3. INT3472 devices that don't actually represent a physical tps68470, but
are being used as a convenient way of grouping a bunch of system GPIO
lines that are intended to enable power and clocks for sensors which
are called out as dependent on them. Also seen on devices designed to
run Windows.

This series introduces a new module which registers:

1. An i2c driver that determines which scenario (#1 or #2) applies to the
machine and registers platform devices to be bound to GPIO, OpRegion,
clock and regulator drivers as appropriate.
2. A platform driver that binds to the dummy INT3472 devices described in
#3

The platform driver for the dummy device registers the GPIO lines that
enable the clocks and regulators to the sensors via those frameworks so
that sensor drivers can consume them in the usual fashion. The existing
GPIO and OpRegion tps68470 drivers will work with the i2c driver that's
registered. Clock and regulator drivers are currently in the works.

The existing mfd/tps68470.c driver being thus superseded, it is removed.

This has been tested on a number of devices; but currently **not** on a
ChromeOS, which we ideally need to do to ensure no regression caused by
replacing the tps68470 MFD driver.

Thanks
Dan

Daniel Scally (7):
acpi: utils: move acpi_lpss_dep() to utils
acpi: utils: Add function to fetch dependent acpi_devices
i2c: i2c-core-base: Use format macro in i2c_dev_set_name()
i2c: i2c-core-acpi: Add i2c_acpi_dev_name()
gpio: gpiolib-acpi: Export acpi_get_gpiod()
platform: x86: Add intel_skl_int3472 driver
mfd: Remove tps68470 MFD driver

MAINTAINERS | 5 +
drivers/acpi/acpi_lpss.c | 24 -
drivers/acpi/internal.h | 1 +
drivers/acpi/pmic/Kconfig | 1 -
drivers/acpi/utils.c | 58 ++
drivers/gpio/Kconfig | 1 -
drivers/gpio/gpiolib-acpi.c | 3 +-
drivers/i2c/i2c-core-acpi.c | 16 +
drivers/i2c/i2c-core-base.c | 4 +-
drivers/mfd/Kconfig | 18 -
drivers/mfd/Makefile | 1 -
drivers/mfd/tps68470.c | 97 ----
drivers/platform/x86/Kconfig | 25 +
drivers/platform/x86/Makefile | 4 +
.../platform/x86/intel_skl_int3472_common.c | 100 ++++
.../platform/x86/intel_skl_int3472_common.h | 100 ++++
.../platform/x86/intel_skl_int3472_discrete.c | 496 ++++++++++++++++++
.../platform/x86/intel_skl_int3472_tps68470.c | 145 +++++
include/acpi/acpi_bus.h | 2 +
include/linux/acpi.h | 5 +
include/linux/i2c.h | 8 +
21 files changed, 969 insertions(+), 145 deletions(-)
delete mode 100644 drivers/mfd/tps68470.c
create mode 100644 drivers/platform/x86/intel_skl_int3472_common.c
create mode 100644 drivers/platform/x86/intel_skl_int3472_common.h
create mode 100644 drivers/platform/x86/intel_skl_int3472_discrete.c
create mode 100644 drivers/platform/x86/intel_skl_int3472_tps68470.c

--
2.25.1


2021-01-18 00:42:36

by Daniel Scally

[permalink] [raw]
Subject: [PATCH v2 3/7] i2c: i2c-core-base: Use format macro in i2c_dev_set_name()

Some places in the kernel allow users to map resources to a device
using device name (for example, gpiod_lookup_table). Currently
this involves waiting for the i2c_client to have been registered so we
can use dev_name(&client->dev). We want to add a function to allow users
to refer to an i2c device by name before it has been instantiated, so
create a macro for the format that's accessible outside the i2c layer
and use it in i2c_dev_set_name()

Suggested-by: Andy Shevchenko <[email protected]>
Signed-off-by: Daniel Scally <[email protected]>
---
- Used format macro in i2c_dev_set_name() instead of sub func

drivers/i2c/i2c-core-base.c | 4 ++--
include/linux/i2c.h | 3 +++
2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
index 63ebf722a424..547b8926cac8 100644
--- a/drivers/i2c/i2c-core-base.c
+++ b/drivers/i2c/i2c-core-base.c
@@ -811,12 +811,12 @@ static void i2c_dev_set_name(struct i2c_adapter *adap,
struct acpi_device *adev = ACPI_COMPANION(&client->dev);

if (info && info->dev_name) {
- dev_set_name(&client->dev, "i2c-%s", info->dev_name);
+ dev_set_name(&client->dev, I2C_DEV_NAME_FORMAT, info->dev_name);
return;
}

if (adev) {
- dev_set_name(&client->dev, "i2c-%s", acpi_dev_name(adev));
+ dev_set_name(&client->dev, I2C_DEV_NAME_FORMAT, acpi_dev_name(adev));
return;
}

diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 56622658b215..4d40a4b46810 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -39,6 +39,9 @@ enum i2c_slave_event;
typedef int (*i2c_slave_cb_t)(struct i2c_client *client,
enum i2c_slave_event event, u8 *val);

+/* I2C Device Name Format - to maintain consistency outside the i2c layer */
+#define I2C_DEV_NAME_FORMAT "i2c-%s"
+
/* I2C Frequency Modes */
#define I2C_MAX_STANDARD_MODE_FREQ 100000
#define I2C_MAX_FAST_MODE_FREQ 400000
--
2.25.1

2021-01-18 00:42:50

by Daniel Scally

[permalink] [raw]
Subject: [PATCH v2 4/7] i2c: i2c-core-acpi: Add i2c_acpi_dev_name()

We want to refer to an i2c device by name before it has been
created by the kernel; add a function that constructs the name
from the acpi device instead.

Signed-off-by: Daniel Scally <[email protected]>
---
Changes in v2:

- Stopped using devm_kasprintf()

drivers/i2c/i2c-core-acpi.c | 16 ++++++++++++++++
include/linux/i2c.h | 5 +++++
2 files changed, 21 insertions(+)

diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c
index 37c510d9347a..98c3ba9a2350 100644
--- a/drivers/i2c/i2c-core-acpi.c
+++ b/drivers/i2c/i2c-core-acpi.c
@@ -497,6 +497,22 @@ struct i2c_client *i2c_acpi_new_device(struct device *dev, int index,
}
EXPORT_SYMBOL_GPL(i2c_acpi_new_device);

+/**
+ * i2c_acpi_dev_name - Construct i2c device name for devs sourced from ACPI
+ * @adev: ACPI device to construct the name for
+ *
+ * Constructs the name of an i2c device matching the format used by
+ * i2c_dev_set_name() to allow users to refer to an i2c device by name even
+ * before they have been instantiated.
+ *
+ * The caller is responsible for freeing the returned pointer.
+ */
+char *i2c_acpi_dev_name(struct acpi_device *adev)
+{
+ return kasprintf(GFP_KERNEL, I2C_DEV_NAME_FORMAT, acpi_dev_name(adev));
+}
+EXPORT_SYMBOL_GPL(i2c_acpi_dev_name);
+
#ifdef CONFIG_ACPI_I2C_OPREGION
static int acpi_gsb_i2c_read_bytes(struct i2c_client *client,
u8 cmd, u8 *data, u8 data_len)
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index 4d40a4b46810..b82aac05b17f 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -998,6 +998,7 @@ bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares,
u32 i2c_acpi_find_bus_speed(struct device *dev);
struct i2c_client *i2c_acpi_new_device(struct device *dev, int index,
struct i2c_board_info *info);
+char *i2c_acpi_dev_name(struct acpi_device *adev);
struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle);
#else
static inline bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares,
@@ -1014,6 +1015,10 @@ static inline struct i2c_client *i2c_acpi_new_device(struct device *dev,
{
return ERR_PTR(-ENODEV);
}
+static inline char *i2c_acpi_dev_name(struct acpi_device *adev)
+{
+ return NULL;
+}
static inline struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle)
{
return NULL;
--
2.25.1

2021-01-18 00:43:45

by Daniel Scally

[permalink] [raw]
Subject: [PATCH v2 5/7] gpio: gpiolib-acpi: Export acpi_get_gpiod()

I need to be able to translate GPIO resources in an acpi_device's _CRS
into gpio_descs. Those are represented in _CRS as a pathname to a GPIO
device plus the pin's index number: this function is perfect for that
purpose.

Signed-off-by: Daniel Scally <[email protected]>
---
Changes in v2:

-None

drivers/gpio/gpiolib-acpi.c | 3 ++-
include/linux/acpi.h | 5 +++++
2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index e37a57d0a2f0..83f9f85cd0ab 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -111,7 +111,7 @@ static int acpi_gpiochip_find(struct gpio_chip *gc, void *data)
* controller does not have GPIO chip registered at the moment. This is to
* support probe deferral.
*/
-static struct gpio_desc *acpi_get_gpiod(char *path, int pin)
+struct gpio_desc *acpi_get_gpiod(char *path, int pin)
{
struct gpio_chip *chip;
acpi_handle handle;
@@ -127,6 +127,7 @@ static struct gpio_desc *acpi_get_gpiod(char *path, int pin)

return gpiochip_get_desc(chip, pin);
}
+EXPORT_SYMBOL_GPL(acpi_get_gpiod);

static irqreturn_t acpi_gpio_irq_handler(int irq, void *data)
{
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 2630c2e953f7..5cd272326eb7 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -1066,6 +1066,7 @@ void __acpi_handle_debug(struct _ddebug *descriptor, acpi_handle handle, const c
bool acpi_gpio_get_irq_resource(struct acpi_resource *ares,
struct acpi_resource_gpio **agpio);
int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index);
+struct gpio_desc *acpi_get_gpiod(char *path, int pin);
#else
static inline bool acpi_gpio_get_irq_resource(struct acpi_resource *ares,
struct acpi_resource_gpio **agpio)
@@ -1076,6 +1077,10 @@ static inline int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index)
{
return -ENXIO;
}
+struct gpio_desc *acpi_get_gpiod(char *path, int pin)
+{
+ return NULL;
+}
#endif

/* Device properties */
--
2.25.1

2021-01-18 00:45:16

by Daniel Scally

[permalink] [raw]
Subject: [PATCH v2 7/7] mfd: Remove tps68470 MFD driver

This driver only covered one scenario in which ACPI devices with _HID
INT3472 are found, and its functionality has been taken over by the
intel-skl-int3472 module, so remove it.

Signed-off-by: Daniel Scally <[email protected]>
---
Changes in v2:

- Introduced

drivers/acpi/pmic/Kconfig | 1 -
drivers/gpio/Kconfig | 1 -
drivers/mfd/Kconfig | 18 --------
drivers/mfd/Makefile | 1 -
drivers/mfd/tps68470.c | 97 ---------------------------------------
5 files changed, 118 deletions(-)
delete mode 100644 drivers/mfd/tps68470.c

diff --git a/drivers/acpi/pmic/Kconfig b/drivers/acpi/pmic/Kconfig
index 56bbcb2ce61b..e27d8ef3a32c 100644
--- a/drivers/acpi/pmic/Kconfig
+++ b/drivers/acpi/pmic/Kconfig
@@ -52,7 +52,6 @@ endif # PMIC_OPREGION

config TPS68470_PMIC_OPREGION
bool "ACPI operation region support for TPS68470 PMIC"
- depends on MFD_TPS68470
help
This config adds ACPI operation region support for TI TPS68470 PMIC.
TPS68470 device is an advanced power management unit that powers
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index c70f46e80a3b..07ff8f24b0d9 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -1343,7 +1343,6 @@ config GPIO_TPS65912

config GPIO_TPS68470
bool "TPS68470 GPIO"
- depends on MFD_TPS68470
help
Select this option to enable GPIO driver for the TPS68470
chip family.
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index bdfce7b15621..9a1f648efde0 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1520,24 +1520,6 @@ config MFD_TPS65217
This driver can also be built as a module. If so, the module
will be called tps65217.

-config MFD_TPS68470
- bool "TI TPS68470 Power Management / LED chips"
- depends on ACPI && PCI && I2C=y
- depends on I2C_DESIGNWARE_PLATFORM=y
- select MFD_CORE
- select REGMAP_I2C
- help
- If you say yes here you get support for the TPS68470 series of
- Power Management / LED chips.
-
- These include voltage regulators, LEDs and other features
- that are often used in portable devices.
-
- This option is a bool as it provides an ACPI operation
- region, which must be available before any of the devices
- using this are probed. This option also configures the
- designware-i2c driver to be built-in, for the same reason.
-
config MFD_TI_LP873X
tristate "TI LP873X Power Management IC"
depends on I2C
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 14fdb188af02..5994e812f479 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -105,7 +105,6 @@ obj-$(CONFIG_MFD_TPS65910) += tps65910.o
obj-$(CONFIG_MFD_TPS65912) += tps65912-core.o
obj-$(CONFIG_MFD_TPS65912_I2C) += tps65912-i2c.o
obj-$(CONFIG_MFD_TPS65912_SPI) += tps65912-spi.o
-obj-$(CONFIG_MFD_TPS68470) += tps68470.o
obj-$(CONFIG_MFD_TPS80031) += tps80031.o
obj-$(CONFIG_MENELAUS) += menelaus.o

diff --git a/drivers/mfd/tps68470.c b/drivers/mfd/tps68470.c
deleted file mode 100644
index 4a4df4ffd18c..000000000000
--- a/drivers/mfd/tps68470.c
+++ /dev/null
@@ -1,97 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * TPS68470 chip Parent driver
- *
- * Copyright (C) 2017 Intel Corporation
- *
- * Authors:
- * Rajmohan Mani <[email protected]>
- * Tianshu Qiu <[email protected]>
- * Jian Xu Zheng <[email protected]>
- * Yuning Pu <[email protected]>
- */
-
-#include <linux/acpi.h>
-#include <linux/delay.h>
-#include <linux/i2c.h>
-#include <linux/init.h>
-#include <linux/mfd/core.h>
-#include <linux/mfd/tps68470.h>
-#include <linux/regmap.h>
-
-static const struct mfd_cell tps68470s[] = {
- { .name = "tps68470-gpio" },
- { .name = "tps68470_pmic_opregion" },
-};
-
-static const struct regmap_config tps68470_regmap_config = {
- .reg_bits = 8,
- .val_bits = 8,
- .max_register = TPS68470_REG_MAX,
-};
-
-static int tps68470_chip_init(struct device *dev, struct regmap *regmap)
-{
- unsigned int version;
- int ret;
-
- /* Force software reset */
- ret = regmap_write(regmap, TPS68470_REG_RESET, TPS68470_REG_RESET_MASK);
- if (ret)
- return ret;
-
- ret = regmap_read(regmap, TPS68470_REG_REVID, &version);
- if (ret) {
- dev_err(dev, "Failed to read revision register: %d\n", ret);
- return ret;
- }
-
- dev_info(dev, "TPS68470 REVID: 0x%x\n", version);
-
- return 0;
-}
-
-static int tps68470_probe(struct i2c_client *client)
-{
- struct device *dev = &client->dev;
- struct regmap *regmap;
- int ret;
-
- regmap = devm_regmap_init_i2c(client, &tps68470_regmap_config);
- if (IS_ERR(regmap)) {
- dev_err(dev, "devm_regmap_init_i2c Error %ld\n",
- PTR_ERR(regmap));
- return PTR_ERR(regmap);
- }
-
- i2c_set_clientdata(client, regmap);
-
- ret = tps68470_chip_init(dev, regmap);
- if (ret < 0) {
- dev_err(dev, "TPS68470 Init Error %d\n", ret);
- return ret;
- }
-
- ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE, tps68470s,
- ARRAY_SIZE(tps68470s), NULL, 0, NULL);
- if (ret < 0) {
- dev_err(dev, "devm_mfd_add_devices failed: %d\n", ret);
- return ret;
- }
-
- return 0;
-}
-
-static const struct acpi_device_id tps68470_acpi_ids[] = {
- {"INT3472"},
- {},
-};
-
-static struct i2c_driver tps68470_driver = {
- .driver = {
- .name = "tps68470",
- .acpi_match_table = tps68470_acpi_ids,
- },
- .probe_new = tps68470_probe,
-};
-builtin_i2c_driver(tps68470_driver);
--
2.25.1

2021-01-18 00:46:03

by Daniel Scally

[permalink] [raw]
Subject: [PATCH v2 2/7] acpi: utils: Add function to fetch dependent acpi_devices

In some ACPI tables we encounter, devices use the _DEP method to assert
a dependence on other ACPI devices as opposed to the OpRegions that the
specification intends. We need to be able to find those devices "from"
the dependee, so add a function to parse all ACPI Devices and check if
the include the handle of the dependee device in their _DEP buffer.

Signed-off-by: Daniel Scally <[email protected]>
---
Changes in v2:
- Used acpi_lpss_dep() as Andy suggested.

drivers/acpi/utils.c | 34 ++++++++++++++++++++++++++++++++++
include/acpi/acpi_bus.h | 2 ++
2 files changed, 36 insertions(+)

diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index 78b38775f18b..ec6a2406a886 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -831,6 +831,18 @@ bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle)
return false;
}

+static int acpi_dev_match_by_dep(struct device *dev, const void *data)
+{
+ struct acpi_device *adev = to_acpi_device(dev);
+ const struct acpi_device *dependee = data;
+ acpi_handle handle = dependee->handle;
+
+ if (acpi_lpss_dep(adev, handle))
+ return 1;
+
+ return 0;
+}
+
/**
* acpi_dev_present - Detect that a given ACPI device is present
* @hid: Hardware ID of the device.
@@ -866,6 +878,28 @@ bool acpi_dev_present(const char *hid, const char *uid, s64 hrv)
}
EXPORT_SYMBOL(acpi_dev_present);

+/**
+ * acpi_dev_get_next_dep_dev - Return next ACPI device dependent on input dev
+ * @adev: Pointer to the dependee device
+ * @prev: Pointer to the previous dependent device (or NULL for first match)
+ *
+ * Return the next ACPI device which declares itself dependent on @adev in
+ * the _DEP buffer.
+ *
+ * The caller is responsible to call put_device() on the returned device.
+ */
+struct acpi_device *acpi_dev_get_next_dep_dev(struct acpi_device *adev,
+ struct acpi_device *prev)
+{
+ struct device *start = prev ? &prev->dev : NULL;
+ struct device *dev;
+
+ dev = bus_find_device(&acpi_bus_type, start, adev, acpi_dev_match_by_dep);
+
+ return dev ? to_acpi_device(dev) : NULL;
+}
+EXPORT_SYMBOL(acpi_dev_get_next_dep_dev);
+
/**
* acpi_dev_get_next_match_dev - Return the next match of ACPI device
* @adev: Pointer to the previous acpi_device matching this @hid, @uid and @hrv
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 02a716a0af5d..33deb22294f2 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -683,6 +683,8 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev)

bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2);

+struct acpi_device *
+acpi_dev_get_next_dep_dev(struct acpi_device *adev, struct acpi_device *prev);
struct acpi_device *
acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv);
struct acpi_device *
--
2.25.1

2021-01-18 00:49:20

by Daniel Scally

[permalink] [raw]
Subject: [PATCH v2 1/7] acpi: utils: move acpi_lpss_dep() to utils

I need to be able to identify devices which declare themselves to be
dependent on other devices through _DEP; add this function to utils.c
and export it to the rest of the ACPI layer.

Suggested-by: Andy Shevchenko <[email protected]>
Signed-off-by: Daniel Scally <[email protected]>
---
Changes in v2:
- Introduced

drivers/acpi/acpi_lpss.c | 24 ------------------------
drivers/acpi/internal.h | 1 +
drivers/acpi/utils.c | 24 ++++++++++++++++++++++++
3 files changed, 25 insertions(+), 24 deletions(-)

diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
index be73974ce449..70c7d9a3f715 100644
--- a/drivers/acpi/acpi_lpss.c
+++ b/drivers/acpi/acpi_lpss.c
@@ -543,30 +543,6 @@ static struct device *acpi_lpss_find_device(const char *hid, const char *uid)
return bus_find_device(&pci_bus_type, NULL, &data, match_hid_uid);
}

-static bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle)
-{
- struct acpi_handle_list dep_devices;
- acpi_status status;
- int i;
-
- if (!acpi_has_method(adev->handle, "_DEP"))
- return false;
-
- status = acpi_evaluate_reference(adev->handle, "_DEP", NULL,
- &dep_devices);
- if (ACPI_FAILURE(status)) {
- dev_dbg(&adev->dev, "Failed to evaluate _DEP.\n");
- return false;
- }
-
- for (i = 0; i < dep_devices.count; i++) {
- if (dep_devices.handles[i] == handle)
- return true;
- }
-
- return false;
-}
-
static void acpi_lpss_link_consumer(struct device *dev1,
const struct lpss_device_links *link)
{
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
index cb229e24c563..ee62c0973576 100644
--- a/drivers/acpi/internal.h
+++ b/drivers/acpi/internal.h
@@ -79,6 +79,7 @@ static inline void acpi_lpss_init(void) {}
#endif

void acpi_apd_init(void);
+bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle);

acpi_status acpi_hotplug_schedule(struct acpi_device *adev, u32 src);
bool acpi_queue_hotplug_work(struct work_struct *work);
diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index ddca1550cce6..78b38775f18b 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -807,6 +807,30 @@ static int acpi_dev_match_cb(struct device *dev, const void *data)
return hrv == match->hrv;
}

+bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle)
+{
+ struct acpi_handle_list dep_devices;
+ acpi_status status;
+ int i;
+
+ if (!acpi_has_method(adev->handle, "_DEP"))
+ return false;
+
+ status = acpi_evaluate_reference(adev->handle, "_DEP", NULL,
+ &dep_devices);
+ if (ACPI_FAILURE(status)) {
+ dev_dbg(&adev->dev, "Failed to evaluate _DEP.\n");
+ return false;
+ }
+
+ for (i = 0; i < dep_devices.count; i++) {
+ if (dep_devices.handles[i] == handle)
+ return true;
+ }
+
+ return false;
+}
+
/**
* acpi_dev_present - Detect that a given ACPI device is present
* @hid: Hardware ID of the device.
--
2.25.1

2021-01-18 07:33:10

by Laurent Pinchart

[permalink] [raw]
Subject: Re: [PATCH v2 3/7] i2c: i2c-core-base: Use format macro in i2c_dev_set_name()

Hi Daniel,

Thank you for the patch.

On Mon, Jan 18, 2021 at 12:34:24AM +0000, Daniel Scally wrote:
> Some places in the kernel allow users to map resources to a device
> using device name (for example, gpiod_lookup_table). Currently
> this involves waiting for the i2c_client to have been registered so we
> can use dev_name(&client->dev). We want to add a function to allow users
> to refer to an i2c device by name before it has been instantiated, so
> create a macro for the format that's accessible outside the i2c layer
> and use it in i2c_dev_set_name()
>
> Suggested-by: Andy Shevchenko <[email protected]>
> Signed-off-by: Daniel Scally <[email protected]>

I'd change the subject line to say "Add a format macro for I2C device
names", as that's the most important part of the patch. Apart from that,

Reviewed-by: Laurent Pinchart <[email protected]>

> ---
> - Used format macro in i2c_dev_set_name() instead of sub func
>
> drivers/i2c/i2c-core-base.c | 4 ++--
> include/linux/i2c.h | 3 +++
> 2 files changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
> index 63ebf722a424..547b8926cac8 100644
> --- a/drivers/i2c/i2c-core-base.c
> +++ b/drivers/i2c/i2c-core-base.c
> @@ -811,12 +811,12 @@ static void i2c_dev_set_name(struct i2c_adapter *adap,
> struct acpi_device *adev = ACPI_COMPANION(&client->dev);
>
> if (info && info->dev_name) {
> - dev_set_name(&client->dev, "i2c-%s", info->dev_name);
> + dev_set_name(&client->dev, I2C_DEV_NAME_FORMAT, info->dev_name);
> return;
> }
>
> if (adev) {
> - dev_set_name(&client->dev, "i2c-%s", acpi_dev_name(adev));
> + dev_set_name(&client->dev, I2C_DEV_NAME_FORMAT, acpi_dev_name(adev));
> return;
> }
>
> diff --git a/include/linux/i2c.h b/include/linux/i2c.h
> index 56622658b215..4d40a4b46810 100644
> --- a/include/linux/i2c.h
> +++ b/include/linux/i2c.h
> @@ -39,6 +39,9 @@ enum i2c_slave_event;
> typedef int (*i2c_slave_cb_t)(struct i2c_client *client,
> enum i2c_slave_event event, u8 *val);
>
> +/* I2C Device Name Format - to maintain consistency outside the i2c layer */
> +#define I2C_DEV_NAME_FORMAT "i2c-%s"
> +
> /* I2C Frequency Modes */
> #define I2C_MAX_STANDARD_MODE_FREQ 100000
> #define I2C_MAX_FAST_MODE_FREQ 400000

--
Regards,

Laurent Pinchart

2021-01-18 07:38:16

by Laurent Pinchart

[permalink] [raw]
Subject: Re: [PATCH v2 2/7] acpi: utils: Add function to fetch dependent acpi_devices

Hi Daniel,

Thank you for the patch.

On Mon, Jan 18, 2021 at 12:34:23AM +0000, Daniel Scally wrote:
> In some ACPI tables we encounter, devices use the _DEP method to assert
> a dependence on other ACPI devices as opposed to the OpRegions that the
> specification intends. We need to be able to find those devices "from"
> the dependee, so add a function to parse all ACPI Devices and check if
> the include the handle of the dependee device in their _DEP buffer.
>
> Signed-off-by: Daniel Scally <[email protected]>
> ---
> Changes in v2:
> - Used acpi_lpss_dep() as Andy suggested.
>
> drivers/acpi/utils.c | 34 ++++++++++++++++++++++++++++++++++
> include/acpi/acpi_bus.h | 2 ++
> 2 files changed, 36 insertions(+)
>
> diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
> index 78b38775f18b..ec6a2406a886 100644
> --- a/drivers/acpi/utils.c
> +++ b/drivers/acpi/utils.c
> @@ -831,6 +831,18 @@ bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle)
> return false;
> }
>
> +static int acpi_dev_match_by_dep(struct device *dev, const void *data)
> +{
> + struct acpi_device *adev = to_acpi_device(dev);
> + const struct acpi_device *dependee = data;
> + acpi_handle handle = dependee->handle;
> +
> + if (acpi_lpss_dep(adev, handle))
> + return 1;
> +
> + return 0;
> +}
> +

I think I'd move this just before acpi_dev_get_next_dep_dev() to keep
the two together.

> /**
> * acpi_dev_present - Detect that a given ACPI device is present
> * @hid: Hardware ID of the device.
> @@ -866,6 +878,28 @@ bool acpi_dev_present(const char *hid, const char *uid, s64 hrv)
> }
> EXPORT_SYMBOL(acpi_dev_present);
>
> +/**
> + * acpi_dev_get_next_dep_dev - Return next ACPI device dependent on input dev

Maybe acpi_dev_get_next_dependent_dev() ? "dep" could mean either
dependent or dependency.

> + * @adev: Pointer to the dependee device
> + * @prev: Pointer to the previous dependent device (or NULL for first match)
> + *
> + * Return the next ACPI device which declares itself dependent on @adev in
> + * the _DEP buffer.
> + *
> + * The caller is responsible to call put_device() on the returned device.
> + */
> +struct acpi_device *acpi_dev_get_next_dep_dev(struct acpi_device *adev,
> + struct acpi_device *prev)
> +{
> + struct device *start = prev ? &prev->dev : NULL;
> + struct device *dev;
> +
> + dev = bus_find_device(&acpi_bus_type, start, adev, acpi_dev_match_by_dep);

Having to loop over all ACPI devices is quite inefficient, but if we
need a reverse lookup, we don't really have a choice. We could create a
reverse map, but I don't think it's worth it.

> +
> + return dev ? to_acpi_device(dev) : NULL;
> +}
> +EXPORT_SYMBOL(acpi_dev_get_next_dep_dev);

I would have used EXPORT_SYMBOL_GPL. I'm not sure what the policy is in
the ACPI subsystem, and it's also a personal choice.

Reviewed-by: Laurent Pinchart <[email protected]>

> +
> /**
> * acpi_dev_get_next_match_dev - Return the next match of ACPI device
> * @adev: Pointer to the previous acpi_device matching this @hid, @uid and @hrv
> diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
> index 02a716a0af5d..33deb22294f2 100644
> --- a/include/acpi/acpi_bus.h
> +++ b/include/acpi/acpi_bus.h
> @@ -683,6 +683,8 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
>
> bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2);
>
> +struct acpi_device *
> +acpi_dev_get_next_dep_dev(struct acpi_device *adev, struct acpi_device *prev);
> struct acpi_device *
> acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv);
> struct acpi_device *

--
Regards,

Laurent Pinchart

2021-01-18 07:47:19

by Laurent Pinchart

[permalink] [raw]
Subject: Re: [PATCH v2 7/7] mfd: Remove tps68470 MFD driver

Hi Daniel,

Thank you for the patch.

On Mon, Jan 18, 2021 at 12:34:28AM +0000, Daniel Scally wrote:
> This driver only covered one scenario in which ACPI devices with _HID
> INT3472 are found, and its functionality has been taken over by the
> intel-skl-int3472 module, so remove it.
>
> Signed-off-by: Daniel Scally <[email protected]>
> ---
> Changes in v2:
>
> - Introduced
>
> drivers/acpi/pmic/Kconfig | 1 -
> drivers/gpio/Kconfig | 1 -
> drivers/mfd/Kconfig | 18 --------
> drivers/mfd/Makefile | 1 -
> drivers/mfd/tps68470.c | 97 ---------------------------------------
> 5 files changed, 118 deletions(-)
> delete mode 100644 drivers/mfd/tps68470.c
>
> diff --git a/drivers/acpi/pmic/Kconfig b/drivers/acpi/pmic/Kconfig
> index 56bbcb2ce61b..e27d8ef3a32c 100644
> --- a/drivers/acpi/pmic/Kconfig
> +++ b/drivers/acpi/pmic/Kconfig
> @@ -52,7 +52,6 @@ endif # PMIC_OPREGION
>
> config TPS68470_PMIC_OPREGION
> bool "ACPI operation region support for TPS68470 PMIC"
> - depends on MFD_TPS68470

Should this now depend on INTEL_SKL_INT3472 ?

> help
> This config adds ACPI operation region support for TI TPS68470 PMIC.
> TPS68470 device is an advanced power management unit that powers
> diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
> index c70f46e80a3b..07ff8f24b0d9 100644
> --- a/drivers/gpio/Kconfig
> +++ b/drivers/gpio/Kconfig
> @@ -1343,7 +1343,6 @@ config GPIO_TPS65912
>
> config GPIO_TPS68470
> bool "TPS68470 GPIO"
> - depends on MFD_TPS68470

Same here.

This won't deal with the case where th TPS68470 is instantiated through
DT, but that's not supported yet, so it can be dealt with it later when
the need arises.

Reviewed-by: Laurent Pinchart <[email protected]>

> help
> Select this option to enable GPIO driver for the TPS68470
> chip family.
> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> index bdfce7b15621..9a1f648efde0 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -1520,24 +1520,6 @@ config MFD_TPS65217
> This driver can also be built as a module. If so, the module
> will be called tps65217.
>
> -config MFD_TPS68470
> - bool "TI TPS68470 Power Management / LED chips"
> - depends on ACPI && PCI && I2C=y
> - depends on I2C_DESIGNWARE_PLATFORM=y
> - select MFD_CORE
> - select REGMAP_I2C
> - help
> - If you say yes here you get support for the TPS68470 series of
> - Power Management / LED chips.
> -
> - These include voltage regulators, LEDs and other features
> - that are often used in portable devices.
> -
> - This option is a bool as it provides an ACPI operation
> - region, which must be available before any of the devices
> - using this are probed. This option also configures the
> - designware-i2c driver to be built-in, for the same reason.
> -
> config MFD_TI_LP873X
> tristate "TI LP873X Power Management IC"
> depends on I2C
> diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
> index 14fdb188af02..5994e812f479 100644
> --- a/drivers/mfd/Makefile
> +++ b/drivers/mfd/Makefile
> @@ -105,7 +105,6 @@ obj-$(CONFIG_MFD_TPS65910) += tps65910.o
> obj-$(CONFIG_MFD_TPS65912) += tps65912-core.o
> obj-$(CONFIG_MFD_TPS65912_I2C) += tps65912-i2c.o
> obj-$(CONFIG_MFD_TPS65912_SPI) += tps65912-spi.o
> -obj-$(CONFIG_MFD_TPS68470) += tps68470.o
> obj-$(CONFIG_MFD_TPS80031) += tps80031.o
> obj-$(CONFIG_MENELAUS) += menelaus.o
>
> diff --git a/drivers/mfd/tps68470.c b/drivers/mfd/tps68470.c
> deleted file mode 100644
> index 4a4df4ffd18c..000000000000
> --- a/drivers/mfd/tps68470.c
> +++ /dev/null
> @@ -1,97 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -/*
> - * TPS68470 chip Parent driver
> - *
> - * Copyright (C) 2017 Intel Corporation
> - *
> - * Authors:
> - * Rajmohan Mani <[email protected]>
> - * Tianshu Qiu <[email protected]>
> - * Jian Xu Zheng <[email protected]>
> - * Yuning Pu <[email protected]>
> - */
> -
> -#include <linux/acpi.h>
> -#include <linux/delay.h>
> -#include <linux/i2c.h>
> -#include <linux/init.h>
> -#include <linux/mfd/core.h>
> -#include <linux/mfd/tps68470.h>
> -#include <linux/regmap.h>
> -
> -static const struct mfd_cell tps68470s[] = {
> - { .name = "tps68470-gpio" },
> - { .name = "tps68470_pmic_opregion" },
> -};
> -
> -static const struct regmap_config tps68470_regmap_config = {
> - .reg_bits = 8,
> - .val_bits = 8,
> - .max_register = TPS68470_REG_MAX,
> -};
> -
> -static int tps68470_chip_init(struct device *dev, struct regmap *regmap)
> -{
> - unsigned int version;
> - int ret;
> -
> - /* Force software reset */
> - ret = regmap_write(regmap, TPS68470_REG_RESET, TPS68470_REG_RESET_MASK);
> - if (ret)
> - return ret;
> -
> - ret = regmap_read(regmap, TPS68470_REG_REVID, &version);
> - if (ret) {
> - dev_err(dev, "Failed to read revision register: %d\n", ret);
> - return ret;
> - }
> -
> - dev_info(dev, "TPS68470 REVID: 0x%x\n", version);
> -
> - return 0;
> -}
> -
> -static int tps68470_probe(struct i2c_client *client)
> -{
> - struct device *dev = &client->dev;
> - struct regmap *regmap;
> - int ret;
> -
> - regmap = devm_regmap_init_i2c(client, &tps68470_regmap_config);
> - if (IS_ERR(regmap)) {
> - dev_err(dev, "devm_regmap_init_i2c Error %ld\n",
> - PTR_ERR(regmap));
> - return PTR_ERR(regmap);
> - }
> -
> - i2c_set_clientdata(client, regmap);
> -
> - ret = tps68470_chip_init(dev, regmap);
> - if (ret < 0) {
> - dev_err(dev, "TPS68470 Init Error %d\n", ret);
> - return ret;
> - }
> -
> - ret = devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE, tps68470s,
> - ARRAY_SIZE(tps68470s), NULL, 0, NULL);
> - if (ret < 0) {
> - dev_err(dev, "devm_mfd_add_devices failed: %d\n", ret);
> - return ret;
> - }
> -
> - return 0;
> -}
> -
> -static const struct acpi_device_id tps68470_acpi_ids[] = {
> - {"INT3472"},
> - {},
> -};
> -
> -static struct i2c_driver tps68470_driver = {
> - .driver = {
> - .name = "tps68470",
> - .acpi_match_table = tps68470_acpi_ids,
> - },
> - .probe_new = tps68470_probe,
> -};
> -builtin_i2c_driver(tps68470_driver);

--
Regards,

Laurent Pinchart

2021-01-18 08:36:11

by Daniel Scally

[permalink] [raw]
Subject: Re: [PATCH v2 1/7] acpi: utils: move acpi_lpss_dep() to utils

Hi Laurent

On 18/01/2021 07:24, Laurent Pinchart wrote:
> Hi Daniel,
>
> Thank you for the patch.
>
> On Mon, Jan 18, 2021 at 12:34:22AM +0000, Daniel Scally wrote:
>> I need to be able to identify devices which declare themselves to be
>> dependent on other devices through _DEP; add this function to utils.c
>> and export it to the rest of the ACPI layer.
>>
>> Suggested-by: Andy Shevchenko <[email protected]>
>> Signed-off-by: Daniel Scally <[email protected]>
>> ---
>> Changes in v2:
>> - Introduced
>>
>> drivers/acpi/acpi_lpss.c | 24 ------------------------
>> drivers/acpi/internal.h | 1 +
>> drivers/acpi/utils.c | 24 ++++++++++++++++++++++++
>> 3 files changed, 25 insertions(+), 24 deletions(-)
>>
>> diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
>> index be73974ce449..70c7d9a3f715 100644
>> --- a/drivers/acpi/acpi_lpss.c
>> +++ b/drivers/acpi/acpi_lpss.c
>> @@ -543,30 +543,6 @@ static struct device *acpi_lpss_find_device(const char *hid, const char *uid)
>> return bus_find_device(&pci_bus_type, NULL, &data, match_hid_uid);
>> }
>>
>> -static bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle)
>> -{
>> - struct acpi_handle_list dep_devices;
>> - acpi_status status;
>> - int i;
>> -
>> - if (!acpi_has_method(adev->handle, "_DEP"))
>> - return false;
>> -
>> - status = acpi_evaluate_reference(adev->handle, "_DEP", NULL,
>> - &dep_devices);
>> - if (ACPI_FAILURE(status)) {
>> - dev_dbg(&adev->dev, "Failed to evaluate _DEP.\n");
>> - return false;
>> - }
>> -
>> - for (i = 0; i < dep_devices.count; i++) {
>> - if (dep_devices.handles[i] == handle)
>> - return true;
>> - }
>> -
>> - return false;
>> -}
>> -
>> static void acpi_lpss_link_consumer(struct device *dev1,
>> const struct lpss_device_links *link)
>> {
>> diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
>> index cb229e24c563..ee62c0973576 100644
>> --- a/drivers/acpi/internal.h
>> +++ b/drivers/acpi/internal.h
>> @@ -79,6 +79,7 @@ static inline void acpi_lpss_init(void) {}
>> #endif
>>
>> void acpi_apd_init(void);
>> +bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle);
> "lpss" stands for low power subsystem, an Intel device within the PCH
> that handles I2C, SPI, UART, ... I think the function should be renamed,
> as it's now generic. acpi_dev_has_dep() is a potential candidate, I'm
> sure better ones exist. A bit of kerneldoc would also not hurt.
Okedokey; I shall add kerneldoc and think of an appropriate name, plus
rename all the uses of it. How about acpi_dev_is_dep()? "has_dep" to me
implies anything at all in _DEP should return true.
>>
>> acpi_status acpi_hotplug_schedule(struct acpi_device *adev, u32 src);
>> bool acpi_queue_hotplug_work(struct work_struct *work);
>> diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
>> index ddca1550cce6..78b38775f18b 100644
>> --- a/drivers/acpi/utils.c
>> +++ b/drivers/acpi/utils.c
>> @@ -807,6 +807,30 @@ static int acpi_dev_match_cb(struct device *dev, const void *data)
>> return hrv == match->hrv;
>> }
>>
>> +bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle)
>> +{
>> + struct acpi_handle_list dep_devices;
>> + acpi_status status;
>> + int i;
>> +
>> + if (!acpi_has_method(adev->handle, "_DEP"))
>> + return false;
>> +
>> + status = acpi_evaluate_reference(adev->handle, "_DEP", NULL,
>> + &dep_devices);
>> + if (ACPI_FAILURE(status)) {
>> + dev_dbg(&adev->dev, "Failed to evaluate _DEP.\n");
>> + return false;
>> + }
>> +
>> + for (i = 0; i < dep_devices.count; i++) {
>> + if (dep_devices.handles[i] == handle)
>> + return true;
>> + }
>> +
>> + return false;
>> +}
>> +
>> /**
>> * acpi_dev_present - Detect that a given ACPI device is present
>> * @hid: Hardware ID of the device.

2021-01-18 08:39:40

by Daniel Scally

[permalink] [raw]
Subject: Re: [PATCH v2 2/7] acpi: utils: Add function to fetch dependent acpi_devices

Morning Laurent

On 18/01/2021 07:34, Laurent Pinchart wrote:
> Hi Daniel,
>
> Thank you for the patch.
>
> On Mon, Jan 18, 2021 at 12:34:23AM +0000, Daniel Scally wrote:
>> In some ACPI tables we encounter, devices use the _DEP method to assert
>> a dependence on other ACPI devices as opposed to the OpRegions that the
>> specification intends. We need to be able to find those devices "from"
>> the dependee, so add a function to parse all ACPI Devices and check if
>> the include the handle of the dependee device in their _DEP buffer.
>>
>> Signed-off-by: Daniel Scally <[email protected]>
>> ---
>> Changes in v2:
>> - Used acpi_lpss_dep() as Andy suggested.
>>
>> drivers/acpi/utils.c | 34 ++++++++++++++++++++++++++++++++++
>> include/acpi/acpi_bus.h | 2 ++
>> 2 files changed, 36 insertions(+)
>>
>> diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
>> index 78b38775f18b..ec6a2406a886 100644
>> --- a/drivers/acpi/utils.c
>> +++ b/drivers/acpi/utils.c
>> @@ -831,6 +831,18 @@ bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle)
>> return false;
>> }
>>
>> +static int acpi_dev_match_by_dep(struct device *dev, const void *data)
>> +{
>> + struct acpi_device *adev = to_acpi_device(dev);
>> + const struct acpi_device *dependee = data;
>> + acpi_handle handle = dependee->handle;
>> +
>> + if (acpi_lpss_dep(adev, handle))
>> + return 1;
>> +
>> + return 0;
>> +}
>> +
> I think I'd move this just before acpi_dev_get_next_dep_dev() to keep
> the two together.


Will do

>
>> /**
>> * acpi_dev_present - Detect that a given ACPI device is present
>> * @hid: Hardware ID of the device.
>> @@ -866,6 +878,28 @@ bool acpi_dev_present(const char *hid, const char *uid, s64 hrv)
>> }
>> EXPORT_SYMBOL(acpi_dev_present);
>>
>> +/**
>> + * acpi_dev_get_next_dep_dev - Return next ACPI device dependent on input dev
> Maybe acpi_dev_get_next_dependent_dev() ? "dep" could mean either
> dependent or dependency.


Yes, good point, I agree.

>
>> + * @adev: Pointer to the dependee device
>> + * @prev: Pointer to the previous dependent device (or NULL for first match)
>> + *
>> + * Return the next ACPI device which declares itself dependent on @adev in
>> + * the _DEP buffer.
>> + *
>> + * The caller is responsible to call put_device() on the returned device.
>> + */
>> +struct acpi_device *acpi_dev_get_next_dep_dev(struct acpi_device *adev,
>> + struct acpi_device *prev)
>> +{
>> + struct device *start = prev ? &prev->dev : NULL;
>> + struct device *dev;
>> +
>> + dev = bus_find_device(&acpi_bus_type, start, adev, acpi_dev_match_by_dep);
> Having to loop over all ACPI devices is quite inefficient, but if we
> need a reverse lookup, we don't really have a choice. We could create a
> reverse map, but I don't think it's worth it.
>
>> +
>> + return dev ? to_acpi_device(dev) : NULL;
>> +}
>> +EXPORT_SYMBOL(acpi_dev_get_next_dep_dev);
> I would have used EXPORT_SYMBOL_GPL. I'm not sure what the policy is in
> the ACPI subsystem, and it's also a personal choice.
EXPORT_SYMBOL_GPL would be my usual choice, but the other functions in
the file all use EXPORT_SYMBOL, so I assumed there was some policy that
that be used (since basically everywhere else I've touched in the kernel
so far defaults to the GPL version)
>
> Reviewed-by: Laurent Pinchart <[email protected]>

Thanks!

>
>> +
>> /**
>> * acpi_dev_get_next_match_dev - Return the next match of ACPI device
>> * @adev: Pointer to the previous acpi_device matching this @hid, @uid and @hrv
>> diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
>> index 02a716a0af5d..33deb22294f2 100644
>> --- a/include/acpi/acpi_bus.h
>> +++ b/include/acpi/acpi_bus.h
>> @@ -683,6 +683,8 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
>>
>> bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2);
>>
>> +struct acpi_device *
>> +acpi_dev_get_next_dep_dev(struct acpi_device *adev, struct acpi_device *prev);
>> struct acpi_device *
>> acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv);
>> struct acpi_device *

2021-01-18 09:49:18

by Laurent Pinchart

[permalink] [raw]
Subject: Re: [PATCH v2 4/7] i2c: i2c-core-acpi: Add i2c_acpi_dev_name()

Hi Daniel,

Thank you for the patch.

On Mon, Jan 18, 2021 at 12:34:25AM +0000, Daniel Scally wrote:
> We want to refer to an i2c device by name before it has been

s/i2c device/acpi i2c device/ ?

> created by the kernel; add a function that constructs the name
> from the acpi device instead.
>
> Signed-off-by: Daniel Scally <[email protected]>
> ---
> Changes in v2:
>
> - Stopped using devm_kasprintf()
>
> drivers/i2c/i2c-core-acpi.c | 16 ++++++++++++++++
> include/linux/i2c.h | 5 +++++
> 2 files changed, 21 insertions(+)
>
> diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c
> index 37c510d9347a..98c3ba9a2350 100644
> --- a/drivers/i2c/i2c-core-acpi.c
> +++ b/drivers/i2c/i2c-core-acpi.c
> @@ -497,6 +497,22 @@ struct i2c_client *i2c_acpi_new_device(struct device *dev, int index,
> }
> EXPORT_SYMBOL_GPL(i2c_acpi_new_device);
>
> +/**
> + * i2c_acpi_dev_name - Construct i2c device name for devs sourced from ACPI
> + * @adev: ACPI device to construct the name for
> + *
> + * Constructs the name of an i2c device matching the format used by
> + * i2c_dev_set_name() to allow users to refer to an i2c device by name even
> + * before they have been instantiated.
> + *
> + * The caller is responsible for freeing the returned pointer.
> + */
> +char *i2c_acpi_dev_name(struct acpi_device *adev)
> +{
> + return kasprintf(GFP_KERNEL, I2C_DEV_NAME_FORMAT, acpi_dev_name(adev));

There's a real danger of a memory leak, as the function name sounds very
similar to dev_name() or acpi_dev_name() and those don't allocate
memory. I'm not sure what a better name would be, but given that this
function is only used in patch 6/7 and not in the I2C subsystem itself,
I wonder if we should inline this kasprintf() call in the caller and
drop this patch.

> +}
> +EXPORT_SYMBOL_GPL(i2c_acpi_dev_name);
> +
> #ifdef CONFIG_ACPI_I2C_OPREGION
> static int acpi_gsb_i2c_read_bytes(struct i2c_client *client,
> u8 cmd, u8 *data, u8 data_len)
> diff --git a/include/linux/i2c.h b/include/linux/i2c.h
> index 4d40a4b46810..b82aac05b17f 100644
> --- a/include/linux/i2c.h
> +++ b/include/linux/i2c.h
> @@ -998,6 +998,7 @@ bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares,
> u32 i2c_acpi_find_bus_speed(struct device *dev);
> struct i2c_client *i2c_acpi_new_device(struct device *dev, int index,
> struct i2c_board_info *info);
> +char *i2c_acpi_dev_name(struct acpi_device *adev);
> struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle);
> #else
> static inline bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares,
> @@ -1014,6 +1015,10 @@ static inline struct i2c_client *i2c_acpi_new_device(struct device *dev,
> {
> return ERR_PTR(-ENODEV);
> }
> +static inline char *i2c_acpi_dev_name(struct acpi_device *adev)
> +{
> + return NULL;
> +}
> static inline struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle)
> {
> return NULL;

--
Regards,

Laurent Pinchart

2021-01-18 10:10:52

by Sakari Ailus

[permalink] [raw]
Subject: Re: [PATCH v2 3/7] i2c: i2c-core-base: Use format macro in i2c_dev_set_name()

Hi Daniel,

On Mon, Jan 18, 2021 at 12:34:24AM +0000, Daniel Scally wrote:
> Some places in the kernel allow users to map resources to a device
> using device name (for example, gpiod_lookup_table). Currently
> this involves waiting for the i2c_client to have been registered so we
> can use dev_name(&client->dev). We want to add a function to allow users
> to refer to an i2c device by name before it has been instantiated, so
> create a macro for the format that's accessible outside the i2c layer
> and use it in i2c_dev_set_name()
>
> Suggested-by: Andy Shevchenko <[email protected]>
> Signed-off-by: Daniel Scally <[email protected]>
> ---
> - Used format macro in i2c_dev_set_name() instead of sub func
>
> drivers/i2c/i2c-core-base.c | 4 ++--
> include/linux/i2c.h | 3 +++
> 2 files changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
> index 63ebf722a424..547b8926cac8 100644
> --- a/drivers/i2c/i2c-core-base.c
> +++ b/drivers/i2c/i2c-core-base.c
> @@ -811,12 +811,12 @@ static void i2c_dev_set_name(struct i2c_adapter *adap,
> struct acpi_device *adev = ACPI_COMPANION(&client->dev);
>
> if (info && info->dev_name) {
> - dev_set_name(&client->dev, "i2c-%s", info->dev_name);
> + dev_set_name(&client->dev, I2C_DEV_NAME_FORMAT, info->dev_name);
> return;
> }
>
> if (adev) {
> - dev_set_name(&client->dev, "i2c-%s", acpi_dev_name(adev));
> + dev_set_name(&client->dev, I2C_DEV_NAME_FORMAT, acpi_dev_name(adev));

Over 80, please wrap.

With that,

Acked-by: Sakari Ailus <[email protected]>

> return;
> }
>
> diff --git a/include/linux/i2c.h b/include/linux/i2c.h
> index 56622658b215..4d40a4b46810 100644
> --- a/include/linux/i2c.h
> +++ b/include/linux/i2c.h
> @@ -39,6 +39,9 @@ enum i2c_slave_event;
> typedef int (*i2c_slave_cb_t)(struct i2c_client *client,
> enum i2c_slave_event event, u8 *val);
>
> +/* I2C Device Name Format - to maintain consistency outside the i2c layer */
> +#define I2C_DEV_NAME_FORMAT "i2c-%s"
> +
> /* I2C Frequency Modes */
> #define I2C_MAX_STANDARD_MODE_FREQ 100000
> #define I2C_MAX_FAST_MODE_FREQ 400000
> --
> 2.25.1
>

--
Sakari Ailus

2021-01-18 10:14:59

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH v2 3/7] i2c: i2c-core-base: Use format macro in i2c_dev_set_name()


> > if (adev) {
> > - dev_set_name(&client->dev, "i2c-%s", acpi_dev_name(adev));
> > + dev_set_name(&client->dev, I2C_DEV_NAME_FORMAT, acpi_dev_name(adev));
>
> Over 80, please wrap.

I am not that strict with the 80, and I don't think it will improve
readability here. It can stay this time IMO.


Attachments:
(No filename) (314.00 B)
signature.asc (849.00 B)
Download all attachments

2021-01-18 12:48:53

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v2 3/7] i2c: i2c-core-base: Use format macro in i2c_dev_set_name()

On Mon, Jan 18, 2021 at 12:34:24AM +0000, Daniel Scally wrote:
> Some places in the kernel allow users to map resources to a device
> using device name (for example, gpiod_lookup_table). Currently

"...in the struct gpiod_lookup_table)." ?

> this involves waiting for the i2c_client to have been registered so we

I?C client ?

> can use dev_name(&client->dev). We want to add a function to allow users
> to refer to an i2c device by name before it has been instantiated, so

I?C device ?

> create a macro for the format that's accessible outside the i2c layer

I?C layer ?

> and use it in i2c_dev_set_name()

Period at the end.

For the record, I do not like wrapping below to 80 limit and agree with
Wolfram.

Reviewed-by: Andy Shevchenko <[email protected]>

> Suggested-by: Andy Shevchenko <[email protected]>
> Signed-off-by: Daniel Scally <[email protected]>
> ---
> - Used format macro in i2c_dev_set_name() instead of sub func
>
> drivers/i2c/i2c-core-base.c | 4 ++--
> include/linux/i2c.h | 3 +++
> 2 files changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
> index 63ebf722a424..547b8926cac8 100644
> --- a/drivers/i2c/i2c-core-base.c
> +++ b/drivers/i2c/i2c-core-base.c
> @@ -811,12 +811,12 @@ static void i2c_dev_set_name(struct i2c_adapter *adap,
> struct acpi_device *adev = ACPI_COMPANION(&client->dev);
>
> if (info && info->dev_name) {
> - dev_set_name(&client->dev, "i2c-%s", info->dev_name);
> + dev_set_name(&client->dev, I2C_DEV_NAME_FORMAT, info->dev_name);
> return;
> }
>
> if (adev) {
> - dev_set_name(&client->dev, "i2c-%s", acpi_dev_name(adev));
> + dev_set_name(&client->dev, I2C_DEV_NAME_FORMAT, acpi_dev_name(adev));
> return;
> }
>
> diff --git a/include/linux/i2c.h b/include/linux/i2c.h
> index 56622658b215..4d40a4b46810 100644
> --- a/include/linux/i2c.h
> +++ b/include/linux/i2c.h
> @@ -39,6 +39,9 @@ enum i2c_slave_event;
> typedef int (*i2c_slave_cb_t)(struct i2c_client *client,
> enum i2c_slave_event event, u8 *val);
>
> +/* I2C Device Name Format - to maintain consistency outside the i2c layer */
> +#define I2C_DEV_NAME_FORMAT "i2c-%s"
> +
> /* I2C Frequency Modes */
> #define I2C_MAX_STANDARD_MODE_FREQ 100000
> #define I2C_MAX_FAST_MODE_FREQ 400000
> --
> 2.25.1
>

--
With Best Regards,
Andy Shevchenko


2021-01-18 13:01:19

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v2 1/7] acpi: utils: move acpi_lpss_dep() to utils

On Mon, Jan 18, 2021 at 09:24:10AM +0200, Laurent Pinchart wrote:
> On Mon, Jan 18, 2021 at 12:34:22AM +0000, Daniel Scally wrote:

...

> > +bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle);
>
> "lpss" stands for low power subsystem, an Intel device within the PCH
> that handles I2C, SPI, UART, ... I think the function should be renamed,
> as it's now generic. acpi_dev_has_dep() is a potential candidate, I'm
> sure better ones exist. A bit of kerneldoc would also not hurt.

Actually a good suggestions. Please apply my tag after addressing above.

--
With Best Regards,
Andy Shevchenko


2021-01-18 13:03:47

by Daniel Scally

[permalink] [raw]
Subject: Re: [PATCH v2 1/7] acpi: utils: move acpi_lpss_dep() to utils


On 18/01/2021 12:29, Andy Shevchenko wrote:
> On Mon, Jan 18, 2021 at 09:24:10AM +0200, Laurent Pinchart wrote:
>> On Mon, Jan 18, 2021 at 12:34:22AM +0000, Daniel Scally wrote:
> ...
>
>>> +bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle);
>> "lpss" stands for low power subsystem, an Intel device within the PCH
>> that handles I2C, SPI, UART, ... I think the function should be renamed,
>> as it's now generic. acpi_dev_has_dep() is a potential candidate, I'm
>> sure better ones exist. A bit of kerneldoc would also not hurt.
> Actually a good suggestions. Please apply my tag after addressing above.


Will do, thanks

2021-01-18 13:42:09

by Daniel Scally

[permalink] [raw]
Subject: Re: [PATCH v2 2/7] acpi: utils: Add function to fetch dependent acpi_devices


On 18/01/2021 12:33, Andy Shevchenko wrote:
> On Mon, Jan 18, 2021 at 12:34:23AM +0000, Daniel Scally wrote:
>> In some ACPI tables we encounter, devices use the _DEP method to assert
>> a dependence on other ACPI devices as opposed to the OpRegions that the
>> specification intends. We need to be able to find those devices "from"
>> the dependee, so add a function to parse all ACPI Devices and check if
>> the include the handle of the dependee device in their _DEP buffer.
> Fix prefix to be "ACPI / utils: " and rebase on top of function name changes as
> suggested by Laurent.


OK.

>> +/**
>> + * acpi_dev_get_next_dep_dev - Return next ACPI device dependent on input dev
> Are you expecting some kind of for_each_*() macro to be added and used?
> Otherwise there is probably no need to have it "_next_" in the name as it will
> be a bit confusing.


I thought that somebody might want to do that in the future yes,
although I've no need for it at the minute because each of the dummy
INT3472 devices only has one dependent sensor that we've seen so far.
But for the INT3472 devices representing a physical TPS68470, there are
platforms where 2 sensors are called out as dependent on the same PMIC
ACPI device (Surface Go2 for example).

It can be renamed and just cross that bridge when we come to it though,
I have no problem with that.

>
>> + * @adev: Pointer to the dependee device
>> + * @prev: Pointer to the previous dependent device (or NULL for first match)
>> + *
>> + * Return the next ACPI device which declares itself dependent on @adev in
>> + * the _DEP buffer.
>> + *
>> + * The caller is responsible to call put_device() on the returned device.
>> + */

2021-01-18 13:51:41

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v2 4/7] i2c: i2c-core-acpi: Add i2c_acpi_dev_name()

On Mon, Jan 18, 2021 at 12:34:25AM +0000, Daniel Scally wrote:
> We want to refer to an i2c device by name before it has been

I?C

> created by the kernel; add a function that constructs the name
> from the acpi device instead.

acpi -> ACPI

Prefix: "i2c: core: "

With above
Reviewed-by: Andy Shevchenko <[email protected]>

> Signed-off-by: Daniel Scally <[email protected]>
> ---
> Changes in v2:
>
> - Stopped using devm_kasprintf()
>
> drivers/i2c/i2c-core-acpi.c | 16 ++++++++++++++++
> include/linux/i2c.h | 5 +++++
> 2 files changed, 21 insertions(+)
>
> diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c
> index 37c510d9347a..98c3ba9a2350 100644
> --- a/drivers/i2c/i2c-core-acpi.c
> +++ b/drivers/i2c/i2c-core-acpi.c
> @@ -497,6 +497,22 @@ struct i2c_client *i2c_acpi_new_device(struct device *dev, int index,
> }
> EXPORT_SYMBOL_GPL(i2c_acpi_new_device);
>
> +/**
> + * i2c_acpi_dev_name - Construct i2c device name for devs sourced from ACPI
> + * @adev: ACPI device to construct the name for
> + *
> + * Constructs the name of an i2c device matching the format used by
> + * i2c_dev_set_name() to allow users to refer to an i2c device by name even
> + * before they have been instantiated.
> + *
> + * The caller is responsible for freeing the returned pointer.
> + */
> +char *i2c_acpi_dev_name(struct acpi_device *adev)
> +{
> + return kasprintf(GFP_KERNEL, I2C_DEV_NAME_FORMAT, acpi_dev_name(adev));
> +}
> +EXPORT_SYMBOL_GPL(i2c_acpi_dev_name);
> +
> #ifdef CONFIG_ACPI_I2C_OPREGION
> static int acpi_gsb_i2c_read_bytes(struct i2c_client *client,
> u8 cmd, u8 *data, u8 data_len)
> diff --git a/include/linux/i2c.h b/include/linux/i2c.h
> index 4d40a4b46810..b82aac05b17f 100644
> --- a/include/linux/i2c.h
> +++ b/include/linux/i2c.h
> @@ -998,6 +998,7 @@ bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares,
> u32 i2c_acpi_find_bus_speed(struct device *dev);
> struct i2c_client *i2c_acpi_new_device(struct device *dev, int index,
> struct i2c_board_info *info);
> +char *i2c_acpi_dev_name(struct acpi_device *adev);
> struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle);
> #else
> static inline bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares,
> @@ -1014,6 +1015,10 @@ static inline struct i2c_client *i2c_acpi_new_device(struct device *dev,
> {
> return ERR_PTR(-ENODEV);
> }
> +static inline char *i2c_acpi_dev_name(struct acpi_device *adev)
> +{
> + return NULL;
> +}
> static inline struct i2c_adapter *i2c_acpi_find_adapter_by_handle(acpi_handle handle)
> {
> return NULL;
> --
> 2.25.1
>

--
With Best Regards,
Andy Shevchenko


2021-01-18 13:52:57

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v2 5/7] gpio: gpiolib-acpi: Export acpi_get_gpiod()

On Mon, Jan 18, 2021 at 12:34:26AM +0000, Daniel Scally wrote:
> I need to be able to translate GPIO resources in an acpi_device's _CRS

ACPI device's

> into gpio_descs. Those are represented in _CRS as a pathname to a GPIO

into GPIO descriptor array

> device plus the pin's index number: this function is perfect for that
> purpose.

...

> diff --git a/include/linux/acpi.h b/include/linux/acpi.h

Wrong header. Please use gpio/consumer.h.

--
With Best Regards,
Andy Shevchenko


2021-01-18 16:14:09

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v2 1/7] acpi: utils: move acpi_lpss_dep() to utils

On Mon, Jan 18, 2021 at 1:30 PM Andy Shevchenko
<[email protected]> wrote:
>
> On Mon, Jan 18, 2021 at 12:34:22AM +0000, Daniel Scally wrote:
> > I need to be able to identify devices which declare themselves to be
> > dependent on other devices through _DEP; add this function to utils.c
> > and export it to the rest of the ACPI layer.
>
> Prefix -> "ACPI / utils: "

Preferably "ACPI: utils: " for that matter and yes, please rename the
function while moving it.

> Otherwise good to me
> Reviewed-by: Andy Shevchenko <[email protected]>
>
> > Suggested-by: Andy Shevchenko <[email protected]>
> > Signed-off-by: Daniel Scally <[email protected]>
> > ---
> > Changes in v2:
> > - Introduced
> >
> > drivers/acpi/acpi_lpss.c | 24 ------------------------
> > drivers/acpi/internal.h | 1 +
> > drivers/acpi/utils.c | 24 ++++++++++++++++++++++++
> > 3 files changed, 25 insertions(+), 24 deletions(-)
> >
> > diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
> > index be73974ce449..70c7d9a3f715 100644
> > --- a/drivers/acpi/acpi_lpss.c
> > +++ b/drivers/acpi/acpi_lpss.c
> > @@ -543,30 +543,6 @@ static struct device *acpi_lpss_find_device(const char *hid, const char *uid)
> > return bus_find_device(&pci_bus_type, NULL, &data, match_hid_uid);
> > }
> >
> > -static bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle)
> > -{
> > - struct acpi_handle_list dep_devices;
> > - acpi_status status;
> > - int i;
> > -
> > - if (!acpi_has_method(adev->handle, "_DEP"))
> > - return false;
> > -
> > - status = acpi_evaluate_reference(adev->handle, "_DEP", NULL,
> > - &dep_devices);
> > - if (ACPI_FAILURE(status)) {
> > - dev_dbg(&adev->dev, "Failed to evaluate _DEP.\n");
> > - return false;
> > - }
> > -
> > - for (i = 0; i < dep_devices.count; i++) {
> > - if (dep_devices.handles[i] == handle)
> > - return true;
> > - }
> > -
> > - return false;
> > -}
> > -
> > static void acpi_lpss_link_consumer(struct device *dev1,
> > const struct lpss_device_links *link)
> > {
> > diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
> > index cb229e24c563..ee62c0973576 100644
> > --- a/drivers/acpi/internal.h
> > +++ b/drivers/acpi/internal.h
> > @@ -79,6 +79,7 @@ static inline void acpi_lpss_init(void) {}
> > #endif
> >
> > void acpi_apd_init(void);
> > +bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle);
> >
> > acpi_status acpi_hotplug_schedule(struct acpi_device *adev, u32 src);
> > bool acpi_queue_hotplug_work(struct work_struct *work);
> > diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
> > index ddca1550cce6..78b38775f18b 100644
> > --- a/drivers/acpi/utils.c
> > +++ b/drivers/acpi/utils.c
> > @@ -807,6 +807,30 @@ static int acpi_dev_match_cb(struct device *dev, const void *data)
> > return hrv == match->hrv;
> > }
> >
> > +bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle)
> > +{
> > + struct acpi_handle_list dep_devices;
> > + acpi_status status;
> > + int i;
> > +
> > + if (!acpi_has_method(adev->handle, "_DEP"))
> > + return false;
> > +
> > + status = acpi_evaluate_reference(adev->handle, "_DEP", NULL,
> > + &dep_devices);
> > + if (ACPI_FAILURE(status)) {
> > + dev_dbg(&adev->dev, "Failed to evaluate _DEP.\n");
> > + return false;
> > + }
> > +
> > + for (i = 0; i < dep_devices.count; i++) {
> > + if (dep_devices.handles[i] == handle)
> > + return true;
> > + }
> > +
> > + return false;
> > +}
> > +
> > /**
> > * acpi_dev_present - Detect that a given ACPI device is present
> > * @hid: Hardware ID of the device.
> > --
> > 2.25.1
> >
>
> --
> With Best Regards,
> Andy Shevchenko
>
>

2021-01-18 16:48:26

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v2 1/7] acpi: utils: move acpi_lpss_dep() to utils

On Mon, Jan 18, 2021 at 05:06:30PM +0100, Rafael J. Wysocki wrote:
> On Mon, Jan 18, 2021 at 1:30 PM Andy Shevchenko
> <[email protected]> wrote:
> >
> > On Mon, Jan 18, 2021 at 12:34:22AM +0000, Daniel Scally wrote:
> > > I need to be able to identify devices which declare themselves to be
> > > dependent on other devices through _DEP; add this function to utils.c
> > > and export it to the rest of the ACPI layer.
> >
> > Prefix -> "ACPI / utils: "
>
> Preferably "ACPI: utils: " for that matter

Ah, good to know! I was always bending between / and : there.

--
With Best Regards,
Andy Shevchenko


2021-01-18 20:11:11

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH v2 7/7] mfd: Remove tps68470 MFD driver

On Mon, 2021-01-18 at 15:53 +0200, Andy Shevchenko wrote:
> On Mon, Jan 18, 2021 at 12:34:28AM +0000, Daniel Scally wrote:
> > This driver only covered one scenario in which ACPI devices with _HID
> > INT3472 are found, and its functionality has been taken over by the
> > intel-skl-int3472 module, so remove it.
>
> Prefix: "mfd: tps68470: ". Rationale: easier to look for specific commits, by,
> for example, running `git log --grep tps68470`.

It's also reasonable to grep by path instead

$ git log --pretty=oneline --grep 'tps68470'
cf2e8c544cd3b33e9e403b7b72404c221bf888d1 Merge tag 'mfd-next-5.1' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd
66265e719b4603ef9a1b8a6c876bcb542c021496 mfd: tps68470: Drop unused MODULE_DEVICE_TABLE
883cad5ba8cc2d9b740b4ad0a8a91063c99c75a3 Merge tag 'mfd-next-4.18' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd
ca34b4f0bed802e1c8612ef08456b20992aeb02a gpio: tps68470: Update to SPDX license identifier

vs

$ git log --pretty=oneline -- '*tps68470*'
e42615ec233b30dfaf117b108d4cb49455b4df1d gpio: Use new GPIO_LINE_DIRECTION
66265e719b4603ef9a1b8a6c876bcb542c021496 mfd: tps68470: Drop unused MODULE_DEVICE_TABLE
36b835176fe014197639f335d9d35424b7805027 ACPI / PMIC: Sort headers alphabetically
37c089d1facaf03969f66a5469c169a2c73429f6 mfd: Update to SPDX license identifier
1b2951dd99af3970c1c1a8385a12b90236b837de Merge tag 'gpio-v4.17-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio
ca34b4f0bed802e1c8612ef08456b20992aeb02a gpio: tps68470: Update to SPDX license identifier
66444f460e68d641a63f0787627bac6c1ee340b5 ACPI / PMIC: Replace license boilerplate with SPDX license identifier
e13452ac379070f038c264618e35559434252175 ACPI / PMIC: Add TI PMIC TPS68470 operation region driver
968c61f7da3cf6d58a49587cfe00d899ca72c1ad Merge tag 'mfd-next-4.14' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd
9bbf6a15ce19dd947b7fa6ad4095931ab3682da8 mfd: Add support for TPS68470 device
275b13a65547e2dc39c75d660d2e0f0fddde90f6 gpio: Add support for TPS68470 GPIOs




2021-01-18 22:57:53

by Laurent Pinchart

[permalink] [raw]
Subject: Re: [PATCH v2 1/7] acpi: utils: move acpi_lpss_dep() to utils

Hi Daniel,

Thank you for the patch.

On Mon, Jan 18, 2021 at 12:34:22AM +0000, Daniel Scally wrote:
> I need to be able to identify devices which declare themselves to be
> dependent on other devices through _DEP; add this function to utils.c
> and export it to the rest of the ACPI layer.
>
> Suggested-by: Andy Shevchenko <[email protected]>
> Signed-off-by: Daniel Scally <[email protected]>
> ---
> Changes in v2:
> - Introduced
>
> drivers/acpi/acpi_lpss.c | 24 ------------------------
> drivers/acpi/internal.h | 1 +
> drivers/acpi/utils.c | 24 ++++++++++++++++++++++++
> 3 files changed, 25 insertions(+), 24 deletions(-)
>
> diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
> index be73974ce449..70c7d9a3f715 100644
> --- a/drivers/acpi/acpi_lpss.c
> +++ b/drivers/acpi/acpi_lpss.c
> @@ -543,30 +543,6 @@ static struct device *acpi_lpss_find_device(const char *hid, const char *uid)
> return bus_find_device(&pci_bus_type, NULL, &data, match_hid_uid);
> }
>
> -static bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle)
> -{
> - struct acpi_handle_list dep_devices;
> - acpi_status status;
> - int i;
> -
> - if (!acpi_has_method(adev->handle, "_DEP"))
> - return false;
> -
> - status = acpi_evaluate_reference(adev->handle, "_DEP", NULL,
> - &dep_devices);
> - if (ACPI_FAILURE(status)) {
> - dev_dbg(&adev->dev, "Failed to evaluate _DEP.\n");
> - return false;
> - }
> -
> - for (i = 0; i < dep_devices.count; i++) {
> - if (dep_devices.handles[i] == handle)
> - return true;
> - }
> -
> - return false;
> -}
> -
> static void acpi_lpss_link_consumer(struct device *dev1,
> const struct lpss_device_links *link)
> {
> diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
> index cb229e24c563..ee62c0973576 100644
> --- a/drivers/acpi/internal.h
> +++ b/drivers/acpi/internal.h
> @@ -79,6 +79,7 @@ static inline void acpi_lpss_init(void) {}
> #endif
>
> void acpi_apd_init(void);
> +bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle);

"lpss" stands for low power subsystem, an Intel device within the PCH
that handles I2C, SPI, UART, ... I think the function should be renamed,
as it's now generic. acpi_dev_has_dep() is a potential candidate, I'm
sure better ones exist. A bit of kerneldoc would also not hurt.

>
> acpi_status acpi_hotplug_schedule(struct acpi_device *adev, u32 src);
> bool acpi_queue_hotplug_work(struct work_struct *work);
> diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
> index ddca1550cce6..78b38775f18b 100644
> --- a/drivers/acpi/utils.c
> +++ b/drivers/acpi/utils.c
> @@ -807,6 +807,30 @@ static int acpi_dev_match_cb(struct device *dev, const void *data)
> return hrv == match->hrv;
> }
>
> +bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle)
> +{
> + struct acpi_handle_list dep_devices;
> + acpi_status status;
> + int i;
> +
> + if (!acpi_has_method(adev->handle, "_DEP"))
> + return false;
> +
> + status = acpi_evaluate_reference(adev->handle, "_DEP", NULL,
> + &dep_devices);
> + if (ACPI_FAILURE(status)) {
> + dev_dbg(&adev->dev, "Failed to evaluate _DEP.\n");
> + return false;
> + }
> +
> + for (i = 0; i < dep_devices.count; i++) {
> + if (dep_devices.handles[i] == handle)
> + return true;
> + }
> +
> + return false;
> +}
> +
> /**
> * acpi_dev_present - Detect that a given ACPI device is present
> * @hid: Hardware ID of the device.

--
Regards,

Laurent Pinchart

2021-01-18 23:08:35

by Laurent Pinchart

[permalink] [raw]
Subject: Re: [PATCH v2 5/7] gpio: gpiolib-acpi: Export acpi_get_gpiod()

Hi Daniel,

Thank you for the patch.

On Mon, Jan 18, 2021 at 12:34:26AM +0000, Daniel Scally wrote:
> I need to be able to translate GPIO resources in an acpi_device's _CRS
> into gpio_descs. Those are represented in _CRS as a pathname to a GPIO
> device plus the pin's index number: this function is perfect for that
> purpose.
>
> Signed-off-by: Daniel Scally <[email protected]>

Reviewed-by: Laurent Pinchart <[email protected]>

> ---
> Changes in v2:
>
> -None
>
> drivers/gpio/gpiolib-acpi.c | 3 ++-
> include/linux/acpi.h | 5 +++++
> 2 files changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
> index e37a57d0a2f0..83f9f85cd0ab 100644
> --- a/drivers/gpio/gpiolib-acpi.c
> +++ b/drivers/gpio/gpiolib-acpi.c
> @@ -111,7 +111,7 @@ static int acpi_gpiochip_find(struct gpio_chip *gc, void *data)
> * controller does not have GPIO chip registered at the moment. This is to
> * support probe deferral.
> */
> -static struct gpio_desc *acpi_get_gpiod(char *path, int pin)
> +struct gpio_desc *acpi_get_gpiod(char *path, int pin)
> {
> struct gpio_chip *chip;
> acpi_handle handle;
> @@ -127,6 +127,7 @@ static struct gpio_desc *acpi_get_gpiod(char *path, int pin)
>
> return gpiochip_get_desc(chip, pin);
> }
> +EXPORT_SYMBOL_GPL(acpi_get_gpiod);
>
> static irqreturn_t acpi_gpio_irq_handler(int irq, void *data)
> {
> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
> index 2630c2e953f7..5cd272326eb7 100644
> --- a/include/linux/acpi.h
> +++ b/include/linux/acpi.h
> @@ -1066,6 +1066,7 @@ void __acpi_handle_debug(struct _ddebug *descriptor, acpi_handle handle, const c
> bool acpi_gpio_get_irq_resource(struct acpi_resource *ares,
> struct acpi_resource_gpio **agpio);
> int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index);
> +struct gpio_desc *acpi_get_gpiod(char *path, int pin);
> #else
> static inline bool acpi_gpio_get_irq_resource(struct acpi_resource *ares,
> struct acpi_resource_gpio **agpio)
> @@ -1076,6 +1077,10 @@ static inline int acpi_dev_gpio_irq_get(struct acpi_device *adev, int index)
> {
> return -ENXIO;
> }
> +struct gpio_desc *acpi_get_gpiod(char *path, int pin)
> +{
> + return NULL;
> +}
> #endif
>
> /* Device properties */

--
Regards,

Laurent Pinchart

2021-01-19 02:59:56

by Sakari Ailus

[permalink] [raw]
Subject: Re: [PATCH v2 3/7] i2c: i2c-core-base: Use format macro in i2c_dev_set_name()

On Mon, Jan 18, 2021 at 11:41:58AM +0200, Sakari Ailus wrote:
> Hi Daniel,
>
> On Mon, Jan 18, 2021 at 12:34:24AM +0000, Daniel Scally wrote:
> > Some places in the kernel allow users to map resources to a device
> > using device name (for example, gpiod_lookup_table). Currently
> > this involves waiting for the i2c_client to have been registered so we
> > can use dev_name(&client->dev). We want to add a function to allow users
> > to refer to an i2c device by name before it has been instantiated, so
> > create a macro for the format that's accessible outside the i2c layer
> > and use it in i2c_dev_set_name()
> >
> > Suggested-by: Andy Shevchenko <[email protected]>
> > Signed-off-by: Daniel Scally <[email protected]>
> > ---
> > - Used format macro in i2c_dev_set_name() instead of sub func
> >
> > drivers/i2c/i2c-core-base.c | 4 ++--
> > include/linux/i2c.h | 3 +++
> > 2 files changed, 5 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c
> > index 63ebf722a424..547b8926cac8 100644
> > --- a/drivers/i2c/i2c-core-base.c
> > +++ b/drivers/i2c/i2c-core-base.c
> > @@ -811,12 +811,12 @@ static void i2c_dev_set_name(struct i2c_adapter *adap,
> > struct acpi_device *adev = ACPI_COMPANION(&client->dev);
> >
> > if (info && info->dev_name) {
> > - dev_set_name(&client->dev, "i2c-%s", info->dev_name);
> > + dev_set_name(&client->dev, I2C_DEV_NAME_FORMAT, info->dev_name);
> > return;
> > }
> >
> > if (adev) {
> > - dev_set_name(&client->dev, "i2c-%s", acpi_dev_name(adev));
> > + dev_set_name(&client->dev, I2C_DEV_NAME_FORMAT, acpi_dev_name(adev));
>
> Over 80, please wrap.
>
> With that,
>
> Acked-by: Sakari Ailus <[email protected]>

Or rather:

Reviewed-by: Sakari Ailus <[email protected]>

>
> > return;
> > }
> >
> > diff --git a/include/linux/i2c.h b/include/linux/i2c.h
> > index 56622658b215..4d40a4b46810 100644
> > --- a/include/linux/i2c.h
> > +++ b/include/linux/i2c.h
> > @@ -39,6 +39,9 @@ enum i2c_slave_event;
> > typedef int (*i2c_slave_cb_t)(struct i2c_client *client,
> > enum i2c_slave_event event, u8 *val);
> >
> > +/* I2C Device Name Format - to maintain consistency outside the i2c layer */
> > +#define I2C_DEV_NAME_FORMAT "i2c-%s"
> > +
> > /* I2C Frequency Modes */
> > #define I2C_MAX_STANDARD_MODE_FREQ 100000
> > #define I2C_MAX_FAST_MODE_FREQ 400000
> > --
> > 2.25.1
> >
>
> --
> Sakari Ailus

--
Sakari Ailus

2021-01-19 04:11:40

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v2 1/7] acpi: utils: move acpi_lpss_dep() to utils

On Mon, Jan 18, 2021 at 12:34:22AM +0000, Daniel Scally wrote:
> I need to be able to identify devices which declare themselves to be
> dependent on other devices through _DEP; add this function to utils.c
> and export it to the rest of the ACPI layer.

Prefix -> "ACPI / utils: "

Otherwise good to me
Reviewed-by: Andy Shevchenko <[email protected]>

> Suggested-by: Andy Shevchenko <[email protected]>
> Signed-off-by: Daniel Scally <[email protected]>
> ---
> Changes in v2:
> - Introduced
>
> drivers/acpi/acpi_lpss.c | 24 ------------------------
> drivers/acpi/internal.h | 1 +
> drivers/acpi/utils.c | 24 ++++++++++++++++++++++++
> 3 files changed, 25 insertions(+), 24 deletions(-)
>
> diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
> index be73974ce449..70c7d9a3f715 100644
> --- a/drivers/acpi/acpi_lpss.c
> +++ b/drivers/acpi/acpi_lpss.c
> @@ -543,30 +543,6 @@ static struct device *acpi_lpss_find_device(const char *hid, const char *uid)
> return bus_find_device(&pci_bus_type, NULL, &data, match_hid_uid);
> }
>
> -static bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle)
> -{
> - struct acpi_handle_list dep_devices;
> - acpi_status status;
> - int i;
> -
> - if (!acpi_has_method(adev->handle, "_DEP"))
> - return false;
> -
> - status = acpi_evaluate_reference(adev->handle, "_DEP", NULL,
> - &dep_devices);
> - if (ACPI_FAILURE(status)) {
> - dev_dbg(&adev->dev, "Failed to evaluate _DEP.\n");
> - return false;
> - }
> -
> - for (i = 0; i < dep_devices.count; i++) {
> - if (dep_devices.handles[i] == handle)
> - return true;
> - }
> -
> - return false;
> -}
> -
> static void acpi_lpss_link_consumer(struct device *dev1,
> const struct lpss_device_links *link)
> {
> diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h
> index cb229e24c563..ee62c0973576 100644
> --- a/drivers/acpi/internal.h
> +++ b/drivers/acpi/internal.h
> @@ -79,6 +79,7 @@ static inline void acpi_lpss_init(void) {}
> #endif
>
> void acpi_apd_init(void);
> +bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle);
>
> acpi_status acpi_hotplug_schedule(struct acpi_device *adev, u32 src);
> bool acpi_queue_hotplug_work(struct work_struct *work);
> diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
> index ddca1550cce6..78b38775f18b 100644
> --- a/drivers/acpi/utils.c
> +++ b/drivers/acpi/utils.c
> @@ -807,6 +807,30 @@ static int acpi_dev_match_cb(struct device *dev, const void *data)
> return hrv == match->hrv;
> }
>
> +bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle)
> +{
> + struct acpi_handle_list dep_devices;
> + acpi_status status;
> + int i;
> +
> + if (!acpi_has_method(adev->handle, "_DEP"))
> + return false;
> +
> + status = acpi_evaluate_reference(adev->handle, "_DEP", NULL,
> + &dep_devices);
> + if (ACPI_FAILURE(status)) {
> + dev_dbg(&adev->dev, "Failed to evaluate _DEP.\n");
> + return false;
> + }
> +
> + for (i = 0; i < dep_devices.count; i++) {
> + if (dep_devices.handles[i] == handle)
> + return true;
> + }
> +
> + return false;
> +}
> +
> /**
> * acpi_dev_present - Detect that a given ACPI device is present
> * @hid: Hardware ID of the device.
> --
> 2.25.1
>

--
With Best Regards,
Andy Shevchenko


2021-01-19 04:12:14

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v2 2/7] acpi: utils: Add function to fetch dependent acpi_devices

On Mon, Jan 18, 2021 at 12:34:23AM +0000, Daniel Scally wrote:
> In some ACPI tables we encounter, devices use the _DEP method to assert
> a dependence on other ACPI devices as opposed to the OpRegions that the
> specification intends. We need to be able to find those devices "from"
> the dependee, so add a function to parse all ACPI Devices and check if
> the include the handle of the dependee device in their _DEP buffer.

Fix prefix to be "ACPI / utils: " and rebase on top of function name changes as
suggested by Laurent.

...

> +/**
> + * acpi_dev_get_next_dep_dev - Return next ACPI device dependent on input dev

Are you expecting some kind of for_each_*() macro to be added and used?
Otherwise there is probably no need to have it "_next_" in the name as it will
be a bit confusing.

> + * @adev: Pointer to the dependee device
> + * @prev: Pointer to the previous dependent device (or NULL for first match)
> + *
> + * Return the next ACPI device which declares itself dependent on @adev in
> + * the _DEP buffer.
> + *
> + * The caller is responsible to call put_device() on the returned device.
> + */

--
With Best Regards,
Andy Shevchenko


2021-01-19 04:14:56

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v2 3/7] i2c: i2c-core-base: Use format macro in i2c_dev_set_name()

On Mon, Jan 18, 2021 at 09:28:34AM +0200, Laurent Pinchart wrote:
> On Mon, Jan 18, 2021 at 12:34:24AM +0000, Daniel Scally wrote:

> I'd change the subject line to say "Add a format macro for I2C device
> names", as that's the most important part of the patch. Apart from that,


Actually prefix can be "i2c: core: ".

Hint: look at the git history to find what was lately used mostly.

% git log --oneline -- drivers/i2c/i2c-*

--
With Best Regards,
Andy Shevchenko


2021-01-19 04:24:22

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v2 4/7] i2c: i2c-core-acpi: Add i2c_acpi_dev_name()

On Mon, Jan 18, 2021 at 11:18:55AM +0200, Laurent Pinchart wrote:
> On Mon, Jan 18, 2021 at 12:34:25AM +0000, Daniel Scally wrote:

...

> > +/**
> > + * i2c_acpi_dev_name - Construct i2c device name for devs sourced from ACPI
> > + * @adev: ACPI device to construct the name for
> > + *
> > + * Constructs the name of an i2c device matching the format used by
> > + * i2c_dev_set_name() to allow users to refer to an i2c device by name even
> > + * before they have been instantiated.
> > + *
> > + * The caller is responsible for freeing the returned pointer.
> > + */
> > +char *i2c_acpi_dev_name(struct acpi_device *adev)
> > +{
> > + return kasprintf(GFP_KERNEL, I2C_DEV_NAME_FORMAT, acpi_dev_name(adev));
>
> There's a real danger of a memory leak, as the function name sounds very
> similar to dev_name() or acpi_dev_name() and those don't allocate
> memory. I'm not sure what a better name would be, but given that this
> function is only used in patch 6/7 and not in the I2C subsystem itself,
> I wonder if we should inline this kasprintf() call in the caller and
> drop this patch.

Dan, I'm fine with either choice.

> > +}

--
With Best Regards,
Andy Shevchenko


2021-01-19 04:26:34

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v2 5/7] gpio: gpiolib-acpi: Export acpi_get_gpiod()

On Mon, Jan 18, 2021 at 03:45:02PM +0200, Andy Shevchenko wrote:
> On Mon, Jan 18, 2021 at 12:34:26AM +0000, Daniel Scally wrote:

And prefix: "gpiolib: acpi: ".

--
With Best Regards,
Andy Shevchenko


2021-01-19 04:26:47

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v2 7/7] mfd: Remove tps68470 MFD driver

On Mon, Jan 18, 2021 at 12:34:28AM +0000, Daniel Scally wrote:
> This driver only covered one scenario in which ACPI devices with _HID
> INT3472 are found, and its functionality has been taken over by the
> intel-skl-int3472 module, so remove it.

Prefix: "mfd: tps68470: ". Rationale: easier to look for specific commits, by,
for example, running `git log --grep tps68470`.

--
With Best Regards,
Andy Shevchenko


2021-01-19 04:44:47

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v2 2/7] acpi: utils: Add function to fetch dependent acpi_devices

On Mon, Jan 18, 2021 at 1:37 AM Daniel Scally <[email protected]> wrote:
>
> In some ACPI tables we encounter, devices use the _DEP method to assert
> a dependence on other ACPI devices as opposed to the OpRegions that the
> specification intends. We need to be able to find those devices "from"
> the dependee, so add a function to parse all ACPI Devices and check if
> the include the handle of the dependee device in their _DEP buffer.

What exactly do you need this for?

Would it be practical to look up the suppliers in acpi_dep_list instead?

Note that supplier drivers may remove entries from there, but does
that matter for your use case?

> Signed-off-by: Daniel Scally <[email protected]>
> ---
> Changes in v2:
> - Used acpi_lpss_dep() as Andy suggested.
>
> drivers/acpi/utils.c | 34 ++++++++++++++++++++++++++++++++++
> include/acpi/acpi_bus.h | 2 ++
> 2 files changed, 36 insertions(+)
>
> diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
> index 78b38775f18b..ec6a2406a886 100644
> --- a/drivers/acpi/utils.c
> +++ b/drivers/acpi/utils.c
> @@ -831,6 +831,18 @@ bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle)
> return false;
> }
>
> +static int acpi_dev_match_by_dep(struct device *dev, const void *data)
> +{
> + struct acpi_device *adev = to_acpi_device(dev);
> + const struct acpi_device *dependee = data;
> + acpi_handle handle = dependee->handle;
> +
> + if (acpi_lpss_dep(adev, handle))
> + return 1;
> +
> + return 0;
> +}
> +
> /**
> * acpi_dev_present - Detect that a given ACPI device is present
> * @hid: Hardware ID of the device.
> @@ -866,6 +878,28 @@ bool acpi_dev_present(const char *hid, const char *uid, s64 hrv)
> }
> EXPORT_SYMBOL(acpi_dev_present);
>
> +/**
> + * acpi_dev_get_next_dep_dev - Return next ACPI device dependent on input dev
> + * @adev: Pointer to the dependee device
> + * @prev: Pointer to the previous dependent device (or NULL for first match)
> + *
> + * Return the next ACPI device which declares itself dependent on @adev in
> + * the _DEP buffer.
> + *
> + * The caller is responsible to call put_device() on the returned device.
> + */
> +struct acpi_device *acpi_dev_get_next_dep_dev(struct acpi_device *adev,
> + struct acpi_device *prev)
> +{
> + struct device *start = prev ? &prev->dev : NULL;
> + struct device *dev;
> +
> + dev = bus_find_device(&acpi_bus_type, start, adev, acpi_dev_match_by_dep);
> +
> + return dev ? to_acpi_device(dev) : NULL;
> +}
> +EXPORT_SYMBOL(acpi_dev_get_next_dep_dev);
> +
> /**
> * acpi_dev_get_next_match_dev - Return the next match of ACPI device
> * @adev: Pointer to the previous acpi_device matching this @hid, @uid and @hrv
> diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
> index 02a716a0af5d..33deb22294f2 100644
> --- a/include/acpi/acpi_bus.h
> +++ b/include/acpi/acpi_bus.h
> @@ -683,6 +683,8 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
>
> bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2);
>
> +struct acpi_device *
> +acpi_dev_get_next_dep_dev(struct acpi_device *adev, struct acpi_device *prev);
> struct acpi_device *
> acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv);
> struct acpi_device *
> --
> 2.25.1
>

2021-01-19 05:04:03

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v2 4/7] i2c: i2c-core-acpi: Add i2c_acpi_dev_name()

On Mon, Jan 18, 2021 at 08:56:44PM +0200, Andy Shevchenko wrote:
> On Mon, Jan 18, 2021 at 10:43:14AM -0800, Joe Perches wrote:
> > On Mon, 2021-01-18 at 15:39 +0200, Andy Shevchenko wrote:
> > > On Mon, Jan 18, 2021 at 12:34:25AM +0000, Daniel Scally wrote:

...

> > > Prefix: "i2c: core: "
> >
> > Please stop being a pedant on these trivial things.
> > It's unimportant and has almost no value.
>
> This series is going to have a new version, that's why I did those comments.
> If it had been the only comments, I would have not posted them.

And actually to the rationale: it makes slightly easier to grep for patches
against same driver / group of drivers / subsystem.

I bet the `... --grep 'i2c: core:' will give different results to the
`... -- drivers/i2c/i2c-* include/i2c*` besides being shorter.

--
With Best Regards,
Andy Shevchenko


2021-01-19 05:04:08

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH v2 4/7] i2c: i2c-core-acpi: Add i2c_acpi_dev_name()

On Mon, 2021-01-18 at 20:56 +0200, Andy Shevchenko wrote:
> On Mon, Jan 18, 2021 at 10:43:14AM -0800, Joe Perches wrote:
> > On Mon, 2021-01-18 at 15:39 +0200, Andy Shevchenko wrote:
> > > On Mon, Jan 18, 2021 at 12:34:25AM +0000, Daniel Scally wrote:
> > > > We want to refer to an i2c device by name before it has been
> > >
> > > I?C
> >
> > Andy, are you next going to suggest renaming all the files with i2c?
>
> Where did you get this from?

By extension from the request to use I?C.
And it's a leading question not a statement of fact.


2021-01-19 05:05:36

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH v2 4/7] i2c: i2c-core-acpi: Add i2c_acpi_dev_name()

On Mon, 2021-01-18 at 15:39 +0200, Andy Shevchenko wrote:
> On Mon, Jan 18, 2021 at 12:34:25AM +0000, Daniel Scally wrote:
> > We want to refer to an i2c device by name before it has been
>
> I?C

Andy, are you next going to suggest renaming all the files with i2c?

$ git ls-files | grep i2c | wc -l
953

Please do not use the pedantic I?C, 7 bit ascii is just fine here.

My keyboard does not have a superscripted 2 key, and yes, I know
how to use it with multiple keypresses but it's irrelevant.

> > created by the kernel; add a function that constructs the name
> > from the acpi device instead.
>
> acpi -> ACPI

Same deal with acpi filenames. Everyone already recognizes acpi is
actually ACPI and there isn't any confusion in anyone's mind.

$ git ls-files | grep acpi | wc -l
533

> Prefix: "i2c: core: "

Please stop being a pedant on these trivial things.
It's unimportant and has almost no value.


2021-01-19 05:07:05

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v2 4/7] i2c: i2c-core-acpi: Add i2c_acpi_dev_name()

On Mon, Jan 18, 2021 at 10:43:14AM -0800, Joe Perches wrote:
> On Mon, 2021-01-18 at 15:39 +0200, Andy Shevchenko wrote:
> > On Mon, Jan 18, 2021 at 12:34:25AM +0000, Daniel Scally wrote:
> > > We want to refer to an i2c device by name before it has been
> >
> > I?C
>
> Andy, are you next going to suggest renaming all the files with i2c?

Where did you get this from?

> Please do not use the pedantic I?C, 7 bit ascii is just fine here.
>
> My keyboard does not have a superscripted 2 key, and yes, I know
> how to use it with multiple keypresses but it's irrelevant.

I2C is fine for me as well.

...

> > > created by the kernel; add a function that constructs the name
> > > from the acpi device instead.
> >
> > acpi -> ACPI
>
> Same deal with acpi filenames.

Where did you get about *file* names, really? Maybe you read again above?

...

> > Prefix: "i2c: core: "
>
> Please stop being a pedant on these trivial things.
> It's unimportant and has almost no value.

This series is going to have a new version, that's why I did those comments.
If it had been the only comments, I would have not posted them.

--
With Best Regards,
Andy Shevchenko


2021-01-19 05:18:54

by Daniel Scally

[permalink] [raw]
Subject: Re: [PATCH v2 2/7] acpi: utils: Add function to fetch dependent acpi_devices

On 18/01/2021 16:14, Rafael J. Wysocki wrote:
> On Mon, Jan 18, 2021 at 1:37 AM Daniel Scally <[email protected]> wrote:
>> In some ACPI tables we encounter, devices use the _DEP method to assert
>> a dependence on other ACPI devices as opposed to the OpRegions that the
>> specification intends. We need to be able to find those devices "from"
>> the dependee, so add a function to parse all ACPI Devices and check if
>> the include the handle of the dependee device in their _DEP buffer.
> What exactly do you need this for?


So, in our DSDT we have devices with _HID INT3472, plus sensors which
refer to those INT3472's in their _DEP method. The driver binds to the
INT3472 device, we need to find the sensors dependent on them.


> Would it be practical to look up the suppliers in acpi_dep_list instead?
>
> Note that supplier drivers may remove entries from there, but does
> that matter for your use case?


Ah - that may work, yes. Thank you, let me test that.


>
>> Signed-off-by: Daniel Scally <[email protected]>
>> ---
>> Changes in v2:
>> - Used acpi_lpss_dep() as Andy suggested.
>>
>> drivers/acpi/utils.c | 34 ++++++++++++++++++++++++++++++++++
>> include/acpi/acpi_bus.h | 2 ++
>> 2 files changed, 36 insertions(+)
>>
>> diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
>> index 78b38775f18b..ec6a2406a886 100644
>> --- a/drivers/acpi/utils.c
>> +++ b/drivers/acpi/utils.c
>> @@ -831,6 +831,18 @@ bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle)
>> return false;
>> }
>>
>> +static int acpi_dev_match_by_dep(struct device *dev, const void *data)
>> +{
>> + struct acpi_device *adev = to_acpi_device(dev);
>> + const struct acpi_device *dependee = data;
>> + acpi_handle handle = dependee->handle;
>> +
>> + if (acpi_lpss_dep(adev, handle))
>> + return 1;
>> +
>> + return 0;
>> +}
>> +
>> /**
>> * acpi_dev_present - Detect that a given ACPI device is present
>> * @hid: Hardware ID of the device.
>> @@ -866,6 +878,28 @@ bool acpi_dev_present(const char *hid, const char *uid, s64 hrv)
>> }
>> EXPORT_SYMBOL(acpi_dev_present);
>>
>> +/**
>> + * acpi_dev_get_next_dep_dev - Return next ACPI device dependent on input dev
>> + * @adev: Pointer to the dependee device
>> + * @prev: Pointer to the previous dependent device (or NULL for first match)
>> + *
>> + * Return the next ACPI device which declares itself dependent on @adev in
>> + * the _DEP buffer.
>> + *
>> + * The caller is responsible to call put_device() on the returned device.
>> + */
>> +struct acpi_device *acpi_dev_get_next_dep_dev(struct acpi_device *adev,
>> + struct acpi_device *prev)
>> +{
>> + struct device *start = prev ? &prev->dev : NULL;
>> + struct device *dev;
>> +
>> + dev = bus_find_device(&acpi_bus_type, start, adev, acpi_dev_match_by_dep);
>> +
>> + return dev ? to_acpi_device(dev) : NULL;
>> +}
>> +EXPORT_SYMBOL(acpi_dev_get_next_dep_dev);
>> +
>> /**
>> * acpi_dev_get_next_match_dev - Return the next match of ACPI device
>> * @adev: Pointer to the previous acpi_device matching this @hid, @uid and @hrv
>> diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
>> index 02a716a0af5d..33deb22294f2 100644
>> --- a/include/acpi/acpi_bus.h
>> +++ b/include/acpi/acpi_bus.h
>> @@ -683,6 +683,8 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
>>
>> bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2);
>>
>> +struct acpi_device *
>> +acpi_dev_get_next_dep_dev(struct acpi_device *adev, struct acpi_device *prev);
>> struct acpi_device *
>> acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv);
>> struct acpi_device *
>> --
>> 2.25.1
>>

2021-01-19 05:24:33

by Daniel Scally

[permalink] [raw]
Subject: Re: [PATCH v2 5/7] gpio: gpiolib-acpi: Export acpi_get_gpiod()

On 18/01/2021 13:45, Andy Shevchenko wrote:
> On Mon, Jan 18, 2021 at 12:34:26AM +0000, Daniel Scally wrote:
>> I need to be able to translate GPIO resources in an acpi_device's _CRS
>
> ACPI device's
>
>> into gpio_descs. Those are represented in _CRS as a pathname to a GPIO
>
> into GPIO descriptor array
>
>> device plus the pin's index number: this function is perfect for that
>> purpose.
>
> ...
>
>> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
>
> Wrong header. Please use gpio/consumer.h.
>
Ack to all - thanks.

2021-01-19 13:29:00

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v2 4/7] i2c: i2c-core-acpi: Add i2c_acpi_dev_name()

On Mon, Jan 18, 2021 at 9:55 PM Laurent Pinchart
<[email protected]> wrote:
>
> Hi Daniel,
>
> Thank you for the patch.
>
> On Mon, Jan 18, 2021 at 12:34:25AM +0000, Daniel Scally wrote:
> > We want to refer to an i2c device by name before it has been
>
> s/i2c device/acpi i2c device/ ?
>
> > created by the kernel; add a function that constructs the name
> > from the acpi device instead.
> >
> > Signed-off-by: Daniel Scally <[email protected]>
> > ---
> > Changes in v2:
> >
> > - Stopped using devm_kasprintf()
> >
> > drivers/i2c/i2c-core-acpi.c | 16 ++++++++++++++++
> > include/linux/i2c.h | 5 +++++
> > 2 files changed, 21 insertions(+)
> >
> > diff --git a/drivers/i2c/i2c-core-acpi.c b/drivers/i2c/i2c-core-acpi.c
> > index 37c510d9347a..98c3ba9a2350 100644
> > --- a/drivers/i2c/i2c-core-acpi.c
> > +++ b/drivers/i2c/i2c-core-acpi.c
> > @@ -497,6 +497,22 @@ struct i2c_client *i2c_acpi_new_device(struct device *dev, int index,
> > }
> > EXPORT_SYMBOL_GPL(i2c_acpi_new_device);
> >
> > +/**
> > + * i2c_acpi_dev_name - Construct i2c device name for devs sourced from ACPI
> > + * @adev: ACPI device to construct the name for
> > + *
> > + * Constructs the name of an i2c device matching the format used by
> > + * i2c_dev_set_name() to allow users to refer to an i2c device by name even
> > + * before they have been instantiated.
> > + *
> > + * The caller is responsible for freeing the returned pointer.
> > + */
> > +char *i2c_acpi_dev_name(struct acpi_device *adev)
> > +{
> > + return kasprintf(GFP_KERNEL, I2C_DEV_NAME_FORMAT, acpi_dev_name(adev));
>
> There's a real danger of a memory leak, as the function name sounds very
> similar to dev_name() or acpi_dev_name() and those don't allocate
> memory. I'm not sure what a better name would be, but given that this
> function is only used in patch 6/7 and not in the I2C subsystem itself,
> I wonder if we should inline this kasprintf() call in the caller and
> drop this patch.

IMO if this is a one-off usage, it's better to open-code it.

2021-01-19 13:32:02

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v2 2/7] acpi: utils: Add function to fetch dependent acpi_devices

On Mon, Jan 18, 2021 at 9:51 PM Daniel Scally <[email protected]> wrote:
>
> On 18/01/2021 16:14, Rafael J. Wysocki wrote:
> > On Mon, Jan 18, 2021 at 1:37 AM Daniel Scally <[email protected]> wrote:
> >> In some ACPI tables we encounter, devices use the _DEP method to assert
> >> a dependence on other ACPI devices as opposed to the OpRegions that the
> >> specification intends. We need to be able to find those devices "from"
> >> the dependee, so add a function to parse all ACPI Devices and check if
> >> the include the handle of the dependee device in their _DEP buffer.
> > What exactly do you need this for?
>
> So, in our DSDT we have devices with _HID INT3472, plus sensors which
> refer to those INT3472's in their _DEP method. The driver binds to the
> INT3472 device, we need to find the sensors dependent on them.
>

Well, this is an interesting concept. :-)

Why does _DEP need to be used for that? Isn't there any other way to
look up the dependent sensors?

>
> > Would it be practical to look up the suppliers in acpi_dep_list instead?
> >
> > Note that supplier drivers may remove entries from there, but does
> > that matter for your use case?
>
> Ah - that may work, yes. Thank you, let me test that.

Even if that doesn't work right away, but it can be made work, I would
very much prefer that to the driver parsing _DEP for every device in
the namespace by itself.

2021-01-19 13:39:30

by Daniel Scally

[permalink] [raw]
Subject: Re: [PATCH v2 2/7] acpi: utils: Add function to fetch dependent acpi_devices


On 19/01/2021 13:15, Rafael J. Wysocki wrote:
> On Mon, Jan 18, 2021 at 9:51 PM Daniel Scally <[email protected]> wrote:
>> On 18/01/2021 16:14, Rafael J. Wysocki wrote:
>>> On Mon, Jan 18, 2021 at 1:37 AM Daniel Scally <[email protected]> wrote:
>>>> In some ACPI tables we encounter, devices use the _DEP method to assert
>>>> a dependence on other ACPI devices as opposed to the OpRegions that the
>>>> specification intends. We need to be able to find those devices "from"
>>>> the dependee, so add a function to parse all ACPI Devices and check if
>>>> the include the handle of the dependee device in their _DEP buffer.
>>> What exactly do you need this for?
>> So, in our DSDT we have devices with _HID INT3472, plus sensors which
>> refer to those INT3472's in their _DEP method. The driver binds to the
>> INT3472 device, we need to find the sensors dependent on them.
>>
> Well, this is an interesting concept. :-)
>
> Why does _DEP need to be used for that? Isn't there any other way to
> look up the dependent sensors?


If there is, I'm not aware of it, I don't see a reference to the sensor
in the INT3472 device (named "PMI0", with the corresponding sensor being
"CAM0") in DSDT  [1]

>>> Would it be practical to look up the suppliers in acpi_dep_list instead?
>>>
>>> Note that supplier drivers may remove entries from there, but does
>>> that matter for your use case?
>> Ah - that may work, yes. Thank you, let me test that.
> Even if that doesn't work right away, but it can be made work, I would
> very much prefer that to the driver parsing _DEP for every device in
> the namespace by itself.


Alright; I haven't looked too closely yet, but I think an iterator over
acpi_dep_list exported from the ACPI subsystem would also work in a
pretty similar way to the function introduced in this patch does,
without much work


[1]
https://gist.githubusercontent.com/djrscally/e64d112180517352fa3392878b0f4a7d/raw/88b90b3ea4204fd7845257b6666fdade47cc2981/dsdt.dsl

2021-01-21 10:17:02

by Daniel Scally

[permalink] [raw]
Subject: Re: [PATCH v2 2/7] acpi: utils: Add function to fetch dependent acpi_devices

Hi Rafael

On 19/01/2021 13:15, Rafael J. Wysocki wrote:
> On Mon, Jan 18, 2021 at 9:51 PM Daniel Scally <[email protected]> wrote:
>> On 18/01/2021 16:14, Rafael J. Wysocki wrote:
>>> On Mon, Jan 18, 2021 at 1:37 AM Daniel Scally <[email protected]> wrote:
>>>> In some ACPI tables we encounter, devices use the _DEP method to assert
>>>> a dependence on other ACPI devices as opposed to the OpRegions that the
>>>> specification intends. We need to be able to find those devices "from"
>>>> the dependee, so add a function to parse all ACPI Devices and check if
>>>> the include the handle of the dependee device in their _DEP buffer.
>>> What exactly do you need this for?
>> So, in our DSDT we have devices with _HID INT3472, plus sensors which
>> refer to those INT3472's in their _DEP method. The driver binds to the
>> INT3472 device, we need to find the sensors dependent on them.
>>
> Well, this is an interesting concept. :-)
>
> Why does _DEP need to be used for that? Isn't there any other way to
> look up the dependent sensors?
>
>>> Would it be practical to look up the suppliers in acpi_dep_list instead?
>>>
>>> Note that supplier drivers may remove entries from there, but does
>>> that matter for your use case?
>> Ah - that may work, yes. Thank you, let me test that.
> Even if that doesn't work right away, but it can be made work, I would
> very much prefer that to the driver parsing _DEP for every device in
> the namespace by itself.


This does work; do you prefer it in scan.c, or in utils.c (in which case
with acpi_dep_list declared as external var in internal.h)?



2021-01-21 12:04:06

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v2 2/7] acpi: utils: Add function to fetch dependent acpi_devices

On Thu, Jan 21, 2021 at 10:47 AM Daniel Scally <[email protected]> wrote:
>
> Hi Rafael
>
> On 19/01/2021 13:15, Rafael J. Wysocki wrote:
> > On Mon, Jan 18, 2021 at 9:51 PM Daniel Scally <[email protected]> wrote:
> >> On 18/01/2021 16:14, Rafael J. Wysocki wrote:
> >>> On Mon, Jan 18, 2021 at 1:37 AM Daniel Scally <[email protected]> wrote:
> >>>> In some ACPI tables we encounter, devices use the _DEP method to assert
> >>>> a dependence on other ACPI devices as opposed to the OpRegions that the
> >>>> specification intends. We need to be able to find those devices "from"
> >>>> the dependee, so add a function to parse all ACPI Devices and check if
> >>>> the include the handle of the dependee device in their _DEP buffer.
> >>> What exactly do you need this for?
> >> So, in our DSDT we have devices with _HID INT3472, plus sensors which
> >> refer to those INT3472's in their _DEP method. The driver binds to the
> >> INT3472 device, we need to find the sensors dependent on them.
> >>
> > Well, this is an interesting concept. :-)
> >
> > Why does _DEP need to be used for that? Isn't there any other way to
> > look up the dependent sensors?
> >
> >>> Would it be practical to look up the suppliers in acpi_dep_list instead?
> >>>
> >>> Note that supplier drivers may remove entries from there, but does
> >>> that matter for your use case?
> >> Ah - that may work, yes. Thank you, let me test that.
> > Even if that doesn't work right away, but it can be made work, I would
> > very much prefer that to the driver parsing _DEP for every device in
> > the namespace by itself.
>
>
> This does work; do you prefer it in scan.c, or in utils.c (in which case
> with acpi_dep_list declared as external var in internal.h)?

Let's put it in scan.c for now, because there is the lock protecting
the list in there too.

How do you want to implement this? Something like "walk the list and
run a callback for the matching entries" or do you have something else
in mind?

2021-01-21 12:11:34

by Daniel Scally

[permalink] [raw]
Subject: Re: [PATCH v2 2/7] acpi: utils: Add function to fetch dependent acpi_devices


On 21/01/2021 11:58, Rafael J. Wysocki wrote:
> On Thu, Jan 21, 2021 at 10:47 AM Daniel Scally <[email protected]> wrote:
>> Hi Rafael
>>
>> On 19/01/2021 13:15, Rafael J. Wysocki wrote:
>>> On Mon, Jan 18, 2021 at 9:51 PM Daniel Scally <[email protected]> wrote:
>>>> On 18/01/2021 16:14, Rafael J. Wysocki wrote:
>>>>> On Mon, Jan 18, 2021 at 1:37 AM Daniel Scally <[email protected]> wrote:
>>>>>> In some ACPI tables we encounter, devices use the _DEP method to assert
>>>>>> a dependence on other ACPI devices as opposed to the OpRegions that the
>>>>>> specification intends. We need to be able to find those devices "from"
>>>>>> the dependee, so add a function to parse all ACPI Devices and check if
>>>>>> the include the handle of the dependee device in their _DEP buffer.
>>>>> What exactly do you need this for?
>>>> So, in our DSDT we have devices with _HID INT3472, plus sensors which
>>>> refer to those INT3472's in their _DEP method. The driver binds to the
>>>> INT3472 device, we need to find the sensors dependent on them.
>>>>
>>> Well, this is an interesting concept. :-)
>>>
>>> Why does _DEP need to be used for that? Isn't there any other way to
>>> look up the dependent sensors?
>>>
>>>>> Would it be practical to look up the suppliers in acpi_dep_list instead?
>>>>>
>>>>> Note that supplier drivers may remove entries from there, but does
>>>>> that matter for your use case?
>>>> Ah - that may work, yes. Thank you, let me test that.
>>> Even if that doesn't work right away, but it can be made work, I would
>>> very much prefer that to the driver parsing _DEP for every device in
>>> the namespace by itself.
>>
>> This does work; do you prefer it in scan.c, or in utils.c (in which case
>> with acpi_dep_list declared as external var in internal.h)?
> Let's put it in scan.c for now, because there is the lock protecting
> the list in there too.
>
> How do you want to implement this? Something like "walk the list and
> run a callback for the matching entries" or do you have something else
> in mind?


Something like this (though with a mutex_lock()). It could be simplified
by dropping the prev stuff, but we have seen INT3472 devices with
multiple sensors declaring themselves dependent on the same device


struct acpi_device *
acpi_dev_get_next_dependent_dev(struct acpi_device *supplier,
                struct acpi_device *prev)
{
    struct acpi_dep_data *dep;
    struct acpi_device *adev;
    int ret;

    if (!supplier)
        return ERR_PTR(-EINVAL);

    if (prev) {
        /*
         * We need to find the previous device in the list, so we know
         * where to start iterating from.
         */
        list_for_each_entry(dep, &acpi_dep_list, node)
            if (dep->consumer == prev->handle &&
                dep->supplier == supplier->handle)
                break;

        dep = list_next_entry(dep, node);
    } else {
        dep = list_first_entry(&acpi_dep_list, struct acpi_dep_data,
                       node);
    }


    list_for_each_entry_from(dep, &acpi_dep_list, node) {
        if (dep->supplier == supplier->handle) {
            ret = acpi_bus_get_device(dep->consumer, &adev);
            if (ret)
                return ERR_PTR(ret);

            return adev;
        }
    }

    return NULL;
}

2021-01-21 14:43:51

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v2 2/7] acpi: utils: Add function to fetch dependent acpi_devices

On Thu, Jan 21, 2021 at 1:04 PM Daniel Scally <[email protected]> wrote:
>
>
> On 21/01/2021 11:58, Rafael J. Wysocki wrote:
> > On Thu, Jan 21, 2021 at 10:47 AM Daniel Scally <[email protected]> wrote:
> >> Hi Rafael
> >>
> >> On 19/01/2021 13:15, Rafael J. Wysocki wrote:
> >>> On Mon, Jan 18, 2021 at 9:51 PM Daniel Scally <[email protected]> wrote:
> >>>> On 18/01/2021 16:14, Rafael J. Wysocki wrote:
> >>>>> On Mon, Jan 18, 2021 at 1:37 AM Daniel Scally <[email protected]> wrote:
> >>>>>> In some ACPI tables we encounter, devices use the _DEP method to assert
> >>>>>> a dependence on other ACPI devices as opposed to the OpRegions that the
> >>>>>> specification intends. We need to be able to find those devices "from"
> >>>>>> the dependee, so add a function to parse all ACPI Devices and check if
> >>>>>> the include the handle of the dependee device in their _DEP buffer.
> >>>>> What exactly do you need this for?
> >>>> So, in our DSDT we have devices with _HID INT3472, plus sensors which
> >>>> refer to those INT3472's in their _DEP method. The driver binds to the
> >>>> INT3472 device, we need to find the sensors dependent on them.
> >>>>
> >>> Well, this is an interesting concept. :-)
> >>>
> >>> Why does _DEP need to be used for that? Isn't there any other way to
> >>> look up the dependent sensors?
> >>>
> >>>>> Would it be practical to look up the suppliers in acpi_dep_list instead?
> >>>>>
> >>>>> Note that supplier drivers may remove entries from there, but does
> >>>>> that matter for your use case?
> >>>> Ah - that may work, yes. Thank you, let me test that.
> >>> Even if that doesn't work right away, but it can be made work, I would
> >>> very much prefer that to the driver parsing _DEP for every device in
> >>> the namespace by itself.
> >>
> >> This does work; do you prefer it in scan.c, or in utils.c (in which case
> >> with acpi_dep_list declared as external var in internal.h)?
> > Let's put it in scan.c for now, because there is the lock protecting
> > the list in there too.
> >
> > How do you want to implement this? Something like "walk the list and
> > run a callback for the matching entries" or do you have something else
> > in mind?
>
>
> Something like this (though with a mutex_lock()). It could be simplified
> by dropping the prev stuff, but we have seen INT3472 devices with
> multiple sensors declaring themselves dependent on the same device
>
>
> struct acpi_device *
> acpi_dev_get_next_dependent_dev(struct acpi_device *supplier,
> struct acpi_device *prev)
> {
> struct acpi_dep_data *dep;
> struct acpi_device *adev;
> int ret;
>
> if (!supplier)
> return ERR_PTR(-EINVAL);
>
> if (prev) {
> /*
> * We need to find the previous device in the list, so we know
> * where to start iterating from.
> */
> list_for_each_entry(dep, &acpi_dep_list, node)
> if (dep->consumer == prev->handle &&
> dep->supplier == supplier->handle)
> break;
>
> dep = list_next_entry(dep, node);
> } else {
> dep = list_first_entry(&acpi_dep_list, struct acpi_dep_data,
> node);
> }
>
>
> list_for_each_entry_from(dep, &acpi_dep_list, node) {
> if (dep->supplier == supplier->handle) {
> ret = acpi_bus_get_device(dep->consumer, &adev);
> if (ret)
> return ERR_PTR(ret);
>
> return adev;
> }
> }
>
> return NULL;
> }

That would work I think, but would it be practical to modify
acpi_walk_dep_device_list() so that it runs a callback for every
consumer found instead of or in addition to the "delete from the list
and free the entry" operation?

2021-01-21 16:39:34

by Daniel Scally

[permalink] [raw]
Subject: Re: [PATCH v2 2/7] acpi: utils: Add function to fetch dependent acpi_devices


On 21/01/2021 14:39, Rafael J. Wysocki wrote:
> On Thu, Jan 21, 2021 at 1:04 PM Daniel Scally <[email protected]> wrote:
>>
>> On 21/01/2021 11:58, Rafael J. Wysocki wrote:
>>> On Thu, Jan 21, 2021 at 10:47 AM Daniel Scally <[email protected]> wrote:
>>>> Hi Rafael
>>>>
>>>> On 19/01/2021 13:15, Rafael J. Wysocki wrote:
>>>>> On Mon, Jan 18, 2021 at 9:51 PM Daniel Scally <[email protected]> wrote:
>>>>>> On 18/01/2021 16:14, Rafael J. Wysocki wrote:
>>>>>>> On Mon, Jan 18, 2021 at 1:37 AM Daniel Scally <[email protected]> wrote:
>>>>>>>> In some ACPI tables we encounter, devices use the _DEP method to assert
>>>>>>>> a dependence on other ACPI devices as opposed to the OpRegions that the
>>>>>>>> specification intends. We need to be able to find those devices "from"
>>>>>>>> the dependee, so add a function to parse all ACPI Devices and check if
>>>>>>>> the include the handle of the dependee device in their _DEP buffer.
>>>>>>> What exactly do you need this for?
>>>>>> So, in our DSDT we have devices with _HID INT3472, plus sensors which
>>>>>> refer to those INT3472's in their _DEP method. The driver binds to the
>>>>>> INT3472 device, we need to find the sensors dependent on them.
>>>>>>
>>>>> Well, this is an interesting concept. :-)
>>>>>
>>>>> Why does _DEP need to be used for that? Isn't there any other way to
>>>>> look up the dependent sensors?
>>>>>
>>>>>>> Would it be practical to look up the suppliers in acpi_dep_list instead?
>>>>>>>
>>>>>>> Note that supplier drivers may remove entries from there, but does
>>>>>>> that matter for your use case?
>>>>>> Ah - that may work, yes. Thank you, let me test that.
>>>>> Even if that doesn't work right away, but it can be made work, I would
>>>>> very much prefer that to the driver parsing _DEP for every device in
>>>>> the namespace by itself.
>>>> This does work; do you prefer it in scan.c, or in utils.c (in which case
>>>> with acpi_dep_list declared as external var in internal.h)?
>>> Let's put it in scan.c for now, because there is the lock protecting
>>> the list in there too.
>>>
>>> How do you want to implement this? Something like "walk the list and
>>> run a callback for the matching entries" or do you have something else
>>> in mind?
>>
>> Something like this (though with a mutex_lock()). It could be simplified
>> by dropping the prev stuff, but we have seen INT3472 devices with
>> multiple sensors declaring themselves dependent on the same device
>>
>>
>> struct acpi_device *
>> acpi_dev_get_next_dependent_dev(struct acpi_device *supplier,
>> struct acpi_device *prev)
>> {
>> struct acpi_dep_data *dep;
>> struct acpi_device *adev;
>> int ret;
>>
>> if (!supplier)
>> return ERR_PTR(-EINVAL);
>>
>> if (prev) {
>> /*
>> * We need to find the previous device in the list, so we know
>> * where to start iterating from.
>> */
>> list_for_each_entry(dep, &acpi_dep_list, node)
>> if (dep->consumer == prev->handle &&
>> dep->supplier == supplier->handle)
>> break;
>>
>> dep = list_next_entry(dep, node);
>> } else {
>> dep = list_first_entry(&acpi_dep_list, struct acpi_dep_data,
>> node);
>> }
>>
>>
>> list_for_each_entry_from(dep, &acpi_dep_list, node) {
>> if (dep->supplier == supplier->handle) {
>> ret = acpi_bus_get_device(dep->consumer, &adev);
>> if (ret)
>> return ERR_PTR(ret);
>>
>> return adev;
>> }
>> }
>>
>> return NULL;
>> }
> That would work I think, but would it be practical to modify
> acpi_walk_dep_device_list() so that it runs a callback for every
> consumer found instead of or in addition to the "delete from the list
> and free the entry" operation?


I think that this would work fine, if that's the way you want to go.
We'd just need to move everything inside the if (dep->supplier ==
handle) block to a new callback, and for my purposes I think also add a
way to stop parsing the list from the callback (so like have the
callbacks return int and stop parsing on a non-zero return). Do you want
to expose that ability to pass a callback outside of ACPI? Or just
export helpers to call each of the callbacks (one to fetch the next
dependent device, one to decrement the unmet dependencies counter)


Otherwise, I'd just need to update the 5 users of that function either
to use the new helper or else to also pass the decrement dependencies
callback.

2021-01-21 18:12:22

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v2 2/7] acpi: utils: Add function to fetch dependent acpi_devices

On Thu, Jan 21, 2021 at 5:34 PM Daniel Scally <[email protected]> wrote:
>
>
> On 21/01/2021 14:39, Rafael J. Wysocki wrote:
> > On Thu, Jan 21, 2021 at 1:04 PM Daniel Scally <[email protected]> wrote:
> >>
> >> On 21/01/2021 11:58, Rafael J. Wysocki wrote:
> >>> On Thu, Jan 21, 2021 at 10:47 AM Daniel Scally <[email protected]> wrote:
> >>>> Hi Rafael
> >>>>
> >>>> On 19/01/2021 13:15, Rafael J. Wysocki wrote:
> >>>>> On Mon, Jan 18, 2021 at 9:51 PM Daniel Scally <[email protected]> wrote:
> >>>>>> On 18/01/2021 16:14, Rafael J. Wysocki wrote:
> >>>>>>> On Mon, Jan 18, 2021 at 1:37 AM Daniel Scally <[email protected]> wrote:
> >>>>>>>> In some ACPI tables we encounter, devices use the _DEP method to assert
> >>>>>>>> a dependence on other ACPI devices as opposed to the OpRegions that the
> >>>>>>>> specification intends. We need to be able to find those devices "from"
> >>>>>>>> the dependee, so add a function to parse all ACPI Devices and check if
> >>>>>>>> the include the handle of the dependee device in their _DEP buffer.
> >>>>>>> What exactly do you need this for?
> >>>>>> So, in our DSDT we have devices with _HID INT3472, plus sensors which
> >>>>>> refer to those INT3472's in their _DEP method. The driver binds to the
> >>>>>> INT3472 device, we need to find the sensors dependent on them.
> >>>>>>
> >>>>> Well, this is an interesting concept. :-)
> >>>>>
> >>>>> Why does _DEP need to be used for that? Isn't there any other way to
> >>>>> look up the dependent sensors?
> >>>>>
> >>>>>>> Would it be practical to look up the suppliers in acpi_dep_list instead?
> >>>>>>>
> >>>>>>> Note that supplier drivers may remove entries from there, but does
> >>>>>>> that matter for your use case?
> >>>>>> Ah - that may work, yes. Thank you, let me test that.
> >>>>> Even if that doesn't work right away, but it can be made work, I would
> >>>>> very much prefer that to the driver parsing _DEP for every device in
> >>>>> the namespace by itself.
> >>>> This does work; do you prefer it in scan.c, or in utils.c (in which case
> >>>> with acpi_dep_list declared as external var in internal.h)?
> >>> Let's put it in scan.c for now, because there is the lock protecting
> >>> the list in there too.
> >>>
> >>> How do you want to implement this? Something like "walk the list and
> >>> run a callback for the matching entries" or do you have something else
> >>> in mind?
> >>
> >> Something like this (though with a mutex_lock()). It could be simplified
> >> by dropping the prev stuff, but we have seen INT3472 devices with
> >> multiple sensors declaring themselves dependent on the same device
> >>
> >>
> >> struct acpi_device *
> >> acpi_dev_get_next_dependent_dev(struct acpi_device *supplier,
> >> struct acpi_device *prev)
> >> {
> >> struct acpi_dep_data *dep;
> >> struct acpi_device *adev;
> >> int ret;
> >>
> >> if (!supplier)
> >> return ERR_PTR(-EINVAL);
> >>
> >> if (prev) {
> >> /*
> >> * We need to find the previous device in the list, so we know
> >> * where to start iterating from.
> >> */
> >> list_for_each_entry(dep, &acpi_dep_list, node)
> >> if (dep->consumer == prev->handle &&
> >> dep->supplier == supplier->handle)
> >> break;
> >>
> >> dep = list_next_entry(dep, node);
> >> } else {
> >> dep = list_first_entry(&acpi_dep_list, struct acpi_dep_data,
> >> node);
> >> }
> >>
> >>
> >> list_for_each_entry_from(dep, &acpi_dep_list, node) {
> >> if (dep->supplier == supplier->handle) {
> >> ret = acpi_bus_get_device(dep->consumer, &adev);
> >> if (ret)
> >> return ERR_PTR(ret);
> >>
> >> return adev;
> >> }
> >> }
> >>
> >> return NULL;
> >> }
> > That would work I think, but would it be practical to modify
> > acpi_walk_dep_device_list() so that it runs a callback for every
> > consumer found instead of or in addition to the "delete from the list
> > and free the entry" operation?
>
>
> I think that this would work fine, if that's the way you want to go.
> We'd just need to move everything inside the if (dep->supplier ==
> handle) block to a new callback, and for my purposes I think also add a
> way to stop parsing the list from the callback (so like have the
> callbacks return int and stop parsing on a non-zero return). Do you want
> to expose that ability to pass a callback outside of ACPI?

Yes.

> Or just export helpers to call each of the callbacks (one to fetch the next
> dependent device, one to decrement the unmet dependencies counter)

If you can run a callback for every matching entry, you don't really
need to have a callback to return the next matching entry. You can do
stuff for all of them in one go (note that it probably is not a good
idea to run the callback under the lock, so the for loop currently in
there is not really suitable for that).

> Otherwise, I'd just need to update the 5 users of that function either
> to use the new helper or else to also pass the decrement dependencies
> callback.

Or have a wrapper around it passing the decrement dependencies
callback for the "typical" users.

2021-01-21 21:11:04

by Daniel Scally

[permalink] [raw]
Subject: Re: [PATCH v2 2/7] acpi: utils: Add function to fetch dependent acpi_devices


On 21/01/2021 18:08, Rafael J. Wysocki wrote:
> On Thu, Jan 21, 2021 at 5:34 PM Daniel Scally <[email protected]> wrote:
>>
>> On 21/01/2021 14:39, Rafael J. Wysocki wrote:
>>> On Thu, Jan 21, 2021 at 1:04 PM Daniel Scally <[email protected]> wrote:
>>>> On 21/01/2021 11:58, Rafael J. Wysocki wrote:
>>>>> On Thu, Jan 21, 2021 at 10:47 AM Daniel Scally <[email protected]> wrote:
>>>>>> Hi Rafael
>>>>>>
>>>>>> On 19/01/2021 13:15, Rafael J. Wysocki wrote:
>>>>>>> On Mon, Jan 18, 2021 at 9:51 PM Daniel Scally <[email protected]> wrote:
>>>>>>>> On 18/01/2021 16:14, Rafael J. Wysocki wrote:
>>>>>>>>> On Mon, Jan 18, 2021 at 1:37 AM Daniel Scally <[email protected]> wrote:
>>>>>>>>>> In some ACPI tables we encounter, devices use the _DEP method to assert
>>>>>>>>>> a dependence on other ACPI devices as opposed to the OpRegions that the
>>>>>>>>>> specification intends. We need to be able to find those devices "from"
>>>>>>>>>> the dependee, so add a function to parse all ACPI Devices and check if
>>>>>>>>>> the include the handle of the dependee device in their _DEP buffer.
>>>>>>>>> What exactly do you need this for?
>>>>>>>> So, in our DSDT we have devices with _HID INT3472, plus sensors which
>>>>>>>> refer to those INT3472's in their _DEP method. The driver binds to the
>>>>>>>> INT3472 device, we need to find the sensors dependent on them.
>>>>>>>>
>>>>>>> Well, this is an interesting concept. :-)
>>>>>>>
>>>>>>> Why does _DEP need to be used for that? Isn't there any other way to
>>>>>>> look up the dependent sensors?
>>>>>>>
>>>>>>>>> Would it be practical to look up the suppliers in acpi_dep_list instead?
>>>>>>>>>
>>>>>>>>> Note that supplier drivers may remove entries from there, but does
>>>>>>>>> that matter for your use case?
>>>>>>>> Ah - that may work, yes. Thank you, let me test that.
>>>>>>> Even if that doesn't work right away, but it can be made work, I would
>>>>>>> very much prefer that to the driver parsing _DEP for every device in
>>>>>>> the namespace by itself.
>>>>>> This does work; do you prefer it in scan.c, or in utils.c (in which case
>>>>>> with acpi_dep_list declared as external var in internal.h)?
>>>>> Let's put it in scan.c for now, because there is the lock protecting
>>>>> the list in there too.
>>>>>
>>>>> How do you want to implement this? Something like "walk the list and
>>>>> run a callback for the matching entries" or do you have something else
>>>>> in mind?
>>>> Something like this (though with a mutex_lock()). It could be simplified
>>>> by dropping the prev stuff, but we have seen INT3472 devices with
>>>> multiple sensors declaring themselves dependent on the same device
>>>>
>>>>
>>>> struct acpi_device *
>>>> acpi_dev_get_next_dependent_dev(struct acpi_device *supplier,
>>>> struct acpi_device *prev)
>>>> {
>>>> struct acpi_dep_data *dep;
>>>> struct acpi_device *adev;
>>>> int ret;
>>>>
>>>> if (!supplier)
>>>> return ERR_PTR(-EINVAL);
>>>>
>>>> if (prev) {
>>>> /*
>>>> * We need to find the previous device in the list, so we know
>>>> * where to start iterating from.
>>>> */
>>>> list_for_each_entry(dep, &acpi_dep_list, node)
>>>> if (dep->consumer == prev->handle &&
>>>> dep->supplier == supplier->handle)
>>>> break;
>>>>
>>>> dep = list_next_entry(dep, node);
>>>> } else {
>>>> dep = list_first_entry(&acpi_dep_list, struct acpi_dep_data,
>>>> node);
>>>> }
>>>>
>>>>
>>>> list_for_each_entry_from(dep, &acpi_dep_list, node) {
>>>> if (dep->supplier == supplier->handle) {
>>>> ret = acpi_bus_get_device(dep->consumer, &adev);
>>>> if (ret)
>>>> return ERR_PTR(ret);
>>>>
>>>> return adev;
>>>> }
>>>> }
>>>>
>>>> return NULL;
>>>> }
>>> That would work I think, but would it be practical to modify
>>> acpi_walk_dep_device_list() so that it runs a callback for every
>>> consumer found instead of or in addition to the "delete from the list
>>> and free the entry" operation?
>>
>> I think that this would work fine, if that's the way you want to go.
>> We'd just need to move everything inside the if (dep->supplier ==
>> handle) block to a new callback, and for my purposes I think also add a
>> way to stop parsing the list from the callback (so like have the
>> callbacks return int and stop parsing on a non-zero return). Do you want
>> to expose that ability to pass a callback outside of ACPI?
> Yes.
>
>> Or just export helpers to call each of the callbacks (one to fetch the next
>> dependent device, one to decrement the unmet dependencies counter)
> If you can run a callback for every matching entry, you don't really
> need to have a callback to return the next matching entry. You can do
> stuff for all of them in one go

Well it my case it's more to return a pointer to the dep->consumer's
acpi_device for a matching entry, so my idea was where there's multiple
dependents you could use this as an iterator...but it could just be
extended to that if needed later; I don't actually need to do it right now.


> note that it probably is not a good
> idea to run the callback under the lock, so the for loop currently in
> there is not really suitable for that

No problem;  I'll tweak that then

>> Otherwise, I'd just need to update the 5 users of that function either
>> to use the new helper or else to also pass the decrement dependencies
>> callback.
> Or have a wrapper around it passing the decrement dependencies
> callback for the "typical" users.


Yeah that's what I mean by helper; I'll do that then; thanks

2021-01-28 09:03:50

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH v2 4/7] i2c: i2c-core-acpi: Add i2c_acpi_dev_name()


> > There's a real danger of a memory leak, as the function name sounds very
> > similar to dev_name() or acpi_dev_name() and those don't allocate
> > memory. I'm not sure what a better name would be, but given that this
> > function is only used in patch 6/7 and not in the I2C subsystem itself,
> > I wonder if we should inline this kasprintf() call in the caller and
> > drop this patch.
>
> IMO if this is a one-off usage, it's better to open-code it.

Sounds reasonable to me, too.


Attachments:
(No filename) (502.00 B)
signature.asc (849.00 B)
Download all attachments

2021-01-28 09:25:12

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH v2 4/7] i2c: i2c-core-acpi: Add i2c_acpi_dev_name()


> Just to clarify; "open-code" meaning inline it in the caller like
> Laurent said, right?

Yes.


Attachments:
(No filename) (105.00 B)
signature.asc (849.00 B)
Download all attachments

2021-01-28 09:30:36

by Daniel Scally

[permalink] [raw]
Subject: Re: [PATCH v2 4/7] i2c: i2c-core-acpi: Add i2c_acpi_dev_name()


On 28/01/2021 09:17, Wolfram Sang wrote:
>> Just to clarify; "open-code" meaning inline it in the caller like
>> Laurent said, right?
> Yes.
>
Thanks - will do that and drop this one then

2021-01-28 09:31:16

by Daniel Scally

[permalink] [raw]
Subject: Re: [PATCH v2 4/7] i2c: i2c-core-acpi: Add i2c_acpi_dev_name()

On 28/01/2021 09:00, Wolfram Sang wrote:
>>> There's a real danger of a memory leak, as the function name sounds very
>>> similar to dev_name() or acpi_dev_name() and those don't allocate
>>> memory. I'm not sure what a better name would be, but given that this
>>> function is only used in patch 6/7 and not in the I2C subsystem itself,
>>> I wonder if we should inline this kasprintf() call in the caller and
>>> drop this patch.
>> IMO if this is a one-off usage, it's better to open-code it.
> Sounds reasonable to me, too.
>
Just to clarify; "open-code" meaning inline it in the caller like
Laurent said, right?

2021-02-02 10:01:27

by Daniel Scally

[permalink] [raw]
Subject: Re: [PATCH v2 2/7] acpi: utils: Add function to fetch dependent acpi_devices

Hi Rafael

On 21/01/2021 21:06, Daniel Scally wrote:
>
> On 21/01/2021 18:08, Rafael J. Wysocki wrote:
>> On Thu, Jan 21, 2021 at 5:34 PM Daniel Scally <[email protected]> wrote:
>>>
>>> On 21/01/2021 14:39, Rafael J. Wysocki wrote:
>>>> On Thu, Jan 21, 2021 at 1:04 PM Daniel Scally <[email protected]> wrote:
>>>>> On 21/01/2021 11:58, Rafael J. Wysocki wrote:
>>>>>> On Thu, Jan 21, 2021 at 10:47 AM Daniel Scally <[email protected]> wrote:
>>>>>>> Hi Rafael
>>>>>>>
>>>>>>> On 19/01/2021 13:15, Rafael J. Wysocki wrote:
>>>>>>>> On Mon, Jan 18, 2021 at 9:51 PM Daniel Scally <[email protected]> wrote:
>>>>>>>>> On 18/01/2021 16:14, Rafael J. Wysocki wrote:
>>>>>>>>>> On Mon, Jan 18, 2021 at 1:37 AM Daniel Scally <[email protected]> wrote:
>>>>>>>>>>> In some ACPI tables we encounter, devices use the _DEP method to assert
>>>>>>>>>>> a dependence on other ACPI devices as opposed to the OpRegions that the
>>>>>>>>>>> specification intends. We need to be able to find those devices "from"
>>>>>>>>>>> the dependee, so add a function to parse all ACPI Devices and check if
>>>>>>>>>>> the include the handle of the dependee device in their _DEP buffer.
>>>>>>>>>> What exactly do you need this for?
>>>>>>>>> So, in our DSDT we have devices with _HID INT3472, plus sensors which
>>>>>>>>> refer to those INT3472's in their _DEP method. The driver binds to the
>>>>>>>>> INT3472 device, we need to find the sensors dependent on them.
>>>>>>>>>
>>>>>>>> Well, this is an interesting concept. :-)
>>>>>>>>
>>>>>>>> Why does _DEP need to be used for that? Isn't there any other way to
>>>>>>>> look up the dependent sensors?
>>>>>>>>
>>>>>>>>>> Would it be practical to look up the suppliers in acpi_dep_list instead?
>>>>>>>>>>
>>>>>>>>>> Note that supplier drivers may remove entries from there, but does
>>>>>>>>>> that matter for your use case?
>>>>>>>>> Ah - that may work, yes. Thank you, let me test that.
>>>>>>>> Even if that doesn't work right away, but it can be made work, I would
>>>>>>>> very much prefer that to the driver parsing _DEP for every device in
>>>>>>>> the namespace by itself.
>>>>>>> This does work; do you prefer it in scan.c, or in utils.c (in which case
>>>>>>> with acpi_dep_list declared as external var in internal.h)?
>>>>>> Let's put it in scan.c for now, because there is the lock protecting
>>>>>> the list in there too.
>>>>>>
>>>>>> How do you want to implement this? Something like "walk the list and
>>>>>> run a callback for the matching entries" or do you have something else
>>>>>> in mind?
>>>>> Something like this (though with a mutex_lock()). It could be simplified
>>>>> by dropping the prev stuff, but we have seen INT3472 devices with
>>>>> multiple sensors declaring themselves dependent on the same device
>>>>>
>>>>>
>>>>> struct acpi_device *
>>>>> acpi_dev_get_next_dependent_dev(struct acpi_device *supplier,
>>>>> struct acpi_device *prev)
>>>>> {
>>>>> struct acpi_dep_data *dep;
>>>>> struct acpi_device *adev;
>>>>> int ret;
>>>>>
>>>>> if (!supplier)
>>>>> return ERR_PTR(-EINVAL);
>>>>>
>>>>> if (prev) {
>>>>> /*
>>>>> * We need to find the previous device in the list, so we know
>>>>> * where to start iterating from.
>>>>> */
>>>>> list_for_each_entry(dep, &acpi_dep_list, node)
>>>>> if (dep->consumer == prev->handle &&
>>>>> dep->supplier == supplier->handle)
>>>>> break;
>>>>>
>>>>> dep = list_next_entry(dep, node);
>>>>> } else {
>>>>> dep = list_first_entry(&acpi_dep_list, struct acpi_dep_data,
>>>>> node);
>>>>> }
>>>>>
>>>>>
>>>>> list_for_each_entry_from(dep, &acpi_dep_list, node) {
>>>>> if (dep->supplier == supplier->handle) {
>>>>> ret = acpi_bus_get_device(dep->consumer, &adev);
>>>>> if (ret)
>>>>> return ERR_PTR(ret);
>>>>>
>>>>> return adev;
>>>>> }
>>>>> }
>>>>>
>>>>> return NULL;
>>>>> }
>>>> That would work I think, but would it be practical to modify
>>>> acpi_walk_dep_device_list() so that it runs a callback for every
>>>> consumer found instead of or in addition to the "delete from the list
>>>> and free the entry" operation?
>>>
>>> I think that this would work fine, if that's the way you want to go.
>>> We'd just need to move everything inside the if (dep->supplier ==
>>> handle) block to a new callback, and for my purposes I think also add a
>>> way to stop parsing the list from the callback (so like have the
>>> callbacks return int and stop parsing on a non-zero return). Do you want
>>> to expose that ability to pass a callback outside of ACPI?
>> Yes.
>>
>>> Or just export helpers to call each of the callbacks (one to fetch the next
>>> dependent device, one to decrement the unmet dependencies counter)
>> If you can run a callback for every matching entry, you don't really
>> need to have a callback to return the next matching entry. You can do
>> stuff for all of them in one go
>
> Well it my case it's more to return a pointer to the dep->consumer's
> acpi_device for a matching entry, so my idea was where there's multiple
> dependents you could use this as an iterator...but it could just be
> extended to that if needed later; I don't actually need to do it right now.
>
>
>> note that it probably is not a good
>> idea to run the callback under the lock, so the for loop currently in
>> there is not really suitable for that
>
> No problem;  I'll tweak that then

Slightly walking back my "No problem" here; as I understand this there's
kinda two options:

1. Walk over the (locked) list, when a match is found unlock, run the
callback and re-lock.

The problem with that idea is unless I'm mistaken there's no guarantee
that the .next pointer is still valid then (even using the *_safe()
methods) because either the next or the next + 1 entry could have been
removed whilst the list was unlocked and the callback was being ran, so
this seems a little unsafe.

2. Walk over the (locked) list twice, the first time counting matching
entries and using that to allocate a temporary buffer, then walk again
to store the matching entries into the buffer. Finally, run the callback
for everything in the buffer, free it and return.

Obviously that's a lot less efficient than the current function, which
isn't particularly palatable.

Apologies if I've missed a better option that would work fine; but
failing that do you still want me to go ahead and change
acpi_walk_dep_device_list() to do this (I'd choose #2 of the above), or
fallback to using acpi_dev_get_next_dependent_dev() described above? If
the latter, does acpi_walk_dep_device_list() maybe need re-naming to
make clear it's not a generalised function?

2021-02-02 11:33:15

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v2 2/7] acpi: utils: Add function to fetch dependent acpi_devices

On Tue, Feb 02, 2021 at 09:58:17AM +0000, Daniel Scally wrote:
> On 21/01/2021 21:06, Daniel Scally wrote:
> > On 21/01/2021 18:08, Rafael J. Wysocki wrote:

...

> > No problem;? I'll tweak that then
>
> Slightly walking back my "No problem" here; as I understand this there's
> kinda two options:
>
> 1. Walk over the (locked) list, when a match is found unlock, run the
> callback and re-lock.
>
> The problem with that idea is unless I'm mistaken there's no guarantee
> that the .next pointer is still valid then (even using the *_safe()
> methods) because either the next or the next + 1 entry could have been
> removed whilst the list was unlocked and the callback was being ran, so
> this seems a little unsafe.

It's easy to solve.
See an example in deferred_probe_work_func().

https://elixir.bootlin.com/linux/latest/source/drivers/base/dd.c#L75

> 2. Walk over the (locked) list twice, the first time counting matching
> entries and using that to allocate a temporary buffer, then walk again
> to store the matching entries into the buffer. Finally, run the callback
> for everything in the buffer, free it and return.
>
> Obviously that's a lot less efficient than the current function, which
> isn't particularly palatable.
>
> Apologies if I've missed a better option that would work fine; but
> failing that do you still want me to go ahead and change
> acpi_walk_dep_device_list() to do this (I'd choose #2 of the above), or
> fallback to using acpi_dev_get_next_dependent_dev() described above? If
> the latter, does acpi_walk_dep_device_list() maybe need re-naming to
> make clear it's not a generalised function?

--
With Best Regards,
Andy Shevchenko


2021-02-03 00:41:17

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v2 2/7] acpi: utils: Add function to fetch dependent acpi_devices

On Tue, Feb 2, 2021 at 10:58 AM Daniel Scally <[email protected]> wrote:
>
> Hi Rafael
>
> On 21/01/2021 21:06, Daniel Scally wrote:
> >
> > On 21/01/2021 18:08, Rafael J. Wysocki wrote:
> >> On Thu, Jan 21, 2021 at 5:34 PM Daniel Scally <[email protected]> wrote:
> >>>
> >>> On 21/01/2021 14:39, Rafael J. Wysocki wrote:
> >>>> On Thu, Jan 21, 2021 at 1:04 PM Daniel Scally <[email protected]> wrote:
> >>>>> On 21/01/2021 11:58, Rafael J. Wysocki wrote:
> >>>>>> On Thu, Jan 21, 2021 at 10:47 AM Daniel Scally <[email protected]> wrote:
> >>>>>>> Hi Rafael
> >>>>>>>
> >>>>>>> On 19/01/2021 13:15, Rafael J. Wysocki wrote:
> >>>>>>>> On Mon, Jan 18, 2021 at 9:51 PM Daniel Scally <[email protected]> wrote:
> >>>>>>>>> On 18/01/2021 16:14, Rafael J. Wysocki wrote:
> >>>>>>>>>> On Mon, Jan 18, 2021 at 1:37 AM Daniel Scally <[email protected]> wrote:
> >>>>>>>>>>> In some ACPI tables we encounter, devices use the _DEP method to assert
> >>>>>>>>>>> a dependence on other ACPI devices as opposed to the OpRegions that the
> >>>>>>>>>>> specification intends. We need to be able to find those devices "from"
> >>>>>>>>>>> the dependee, so add a function to parse all ACPI Devices and check if
> >>>>>>>>>>> the include the handle of the dependee device in their _DEP buffer.
> >>>>>>>>>> What exactly do you need this for?
> >>>>>>>>> So, in our DSDT we have devices with _HID INT3472, plus sensors which
> >>>>>>>>> refer to those INT3472's in their _DEP method. The driver binds to the
> >>>>>>>>> INT3472 device, we need to find the sensors dependent on them.
> >>>>>>>>>
> >>>>>>>> Well, this is an interesting concept. :-)
> >>>>>>>>
> >>>>>>>> Why does _DEP need to be used for that? Isn't there any other way to
> >>>>>>>> look up the dependent sensors?
> >>>>>>>>
> >>>>>>>>>> Would it be practical to look up the suppliers in acpi_dep_list instead?
> >>>>>>>>>>
> >>>>>>>>>> Note that supplier drivers may remove entries from there, but does
> >>>>>>>>>> that matter for your use case?
> >>>>>>>>> Ah - that may work, yes. Thank you, let me test that.
> >>>>>>>> Even if that doesn't work right away, but it can be made work, I would
> >>>>>>>> very much prefer that to the driver parsing _DEP for every device in
> >>>>>>>> the namespace by itself.
> >>>>>>> This does work; do you prefer it in scan.c, or in utils.c (in which case
> >>>>>>> with acpi_dep_list declared as external var in internal.h)?
> >>>>>> Let's put it in scan.c for now, because there is the lock protecting
> >>>>>> the list in there too.
> >>>>>>
> >>>>>> How do you want to implement this? Something like "walk the list and
> >>>>>> run a callback for the matching entries" or do you have something else
> >>>>>> in mind?
> >>>>> Something like this (though with a mutex_lock()). It could be simplified
> >>>>> by dropping the prev stuff, but we have seen INT3472 devices with
> >>>>> multiple sensors declaring themselves dependent on the same device
> >>>>>
> >>>>>
> >>>>> struct acpi_device *
> >>>>> acpi_dev_get_next_dependent_dev(struct acpi_device *supplier,
> >>>>> struct acpi_device *prev)
> >>>>> {
> >>>>> struct acpi_dep_data *dep;
> >>>>> struct acpi_device *adev;
> >>>>> int ret;
> >>>>>
> >>>>> if (!supplier)
> >>>>> return ERR_PTR(-EINVAL);
> >>>>>
> >>>>> if (prev) {
> >>>>> /*
> >>>>> * We need to find the previous device in the list, so we know
> >>>>> * where to start iterating from.
> >>>>> */
> >>>>> list_for_each_entry(dep, &acpi_dep_list, node)
> >>>>> if (dep->consumer == prev->handle &&
> >>>>> dep->supplier == supplier->handle)
> >>>>> break;
> >>>>>
> >>>>> dep = list_next_entry(dep, node);
> >>>>> } else {
> >>>>> dep = list_first_entry(&acpi_dep_list, struct acpi_dep_data,
> >>>>> node);
> >>>>> }
> >>>>>
> >>>>>
> >>>>> list_for_each_entry_from(dep, &acpi_dep_list, node) {
> >>>>> if (dep->supplier == supplier->handle) {
> >>>>> ret = acpi_bus_get_device(dep->consumer, &adev);
> >>>>> if (ret)
> >>>>> return ERR_PTR(ret);
> >>>>>
> >>>>> return adev;
> >>>>> }
> >>>>> }
> >>>>>
> >>>>> return NULL;
> >>>>> }
> >>>> That would work I think, but would it be practical to modify
> >>>> acpi_walk_dep_device_list() so that it runs a callback for every
> >>>> consumer found instead of or in addition to the "delete from the list
> >>>> and free the entry" operation?
> >>>
> >>> I think that this would work fine, if that's the way you want to go.
> >>> We'd just need to move everything inside the if (dep->supplier ==
> >>> handle) block to a new callback, and for my purposes I think also add a
> >>> way to stop parsing the list from the callback (so like have the
> >>> callbacks return int and stop parsing on a non-zero return). Do you want
> >>> to expose that ability to pass a callback outside of ACPI?
> >> Yes.
> >>
> >>> Or just export helpers to call each of the callbacks (one to fetch the next
> >>> dependent device, one to decrement the unmet dependencies counter)
> >> If you can run a callback for every matching entry, you don't really
> >> need to have a callback to return the next matching entry. You can do
> >> stuff for all of them in one go
> >
> > Well it my case it's more to return a pointer to the dep->consumer's
> > acpi_device for a matching entry, so my idea was where there's multiple
> > dependents you could use this as an iterator...but it could just be
> > extended to that if needed later; I don't actually need to do it right now.
> >
> >
> >> note that it probably is not a good
> >> idea to run the callback under the lock, so the for loop currently in
> >> there is not really suitable for that
> >
> > No problem; I'll tweak that then
>
> Slightly walking back my "No problem" here; as I understand this there's
> kinda two options:
>
> 1. Walk over the (locked) list, when a match is found unlock, run the
> callback and re-lock.

That's what I was thinking about.

> The problem with that idea is unless I'm mistaken there's no guarantee
> that the .next pointer is still valid then (even using the *_safe()
> methods) because either the next or the next + 1 entry could have been
> removed whilst the list was unlocked and the callback was being ran, so
> this seems a little unsafe.

This can be addressed by rotating the list while walking it, but that
becomes problematic if there are concurrent walkers.

OK, I guess running the callback under the lock is not really a big
deal (and for the deletion case this is actually necessary), so let's
do that.