Skip to contentSkip to conversation

ipu6: get rid of all the IS_ENABLED(CONFIG_ACPI)

PATCH In review Ricardo Ribalda 2 participants 9 messages Dec 16, 2024 – Dec 19, 2024

Subsystems (5)
Media (V4L/DVB) USB ACPI Driver core +1 more subsystems
lore
Share & tools
lore
#0 lore raw

v5 cover ipu6: get rid of all the IS_ENABLED(CONFIG_ACPI)

We want to be able to compile_test the ipu6 driver in situations with !ACPI.

In order to do this we had to add some conditional #ifs, which lead to false positives on the static analysers.

Let's implement some helpers when !ACPI in the acpi headers to make the code more easier to maintain.

To: Rafael J. Wysocki <[email protected]>
To: Len Brown <[email protected]>
To: Robert Moore <[email protected]>
To: Rafael J. Wysocki <[email protected]>

Changes in v5:
- Remove Fixes tag
- redefine acpi_get_physical_device_location() to return bool
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4 (Thanks Sakari & Mauro):
- Squash the two ipu changes and merge everything via ACPI
- Space after ;
- move acpi_device_handle to avoid fwd declaration.
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Prefer static inlines to macros (Thanks Rafael).
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Add helpers in acpi to avoid conditional compilation
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Ricardo Ribalda (7):
ACPI: bus: change the prototype for acpi_get_physical_device_location
ACPI: bus: implement for_each_acpi_dev_match when !ACPI
ACPI: bus: implement acpi_get_physical_device_location when !ACPI
ACPI: header: implement acpi_device_handle when !ACPI
ACPI: bus: implement for_each_acpi_consumer_dev when !ACPI
ACPI: bus: implement acpi_device_hid when !ACPI
media: ipu-bridge: Remove unneeded conditional compilations

 drivers/acpi/mipi-disco-img.c        |  3 +--
 drivers/acpi/scan.c                  |  4 +---
 drivers/acpi/utils.c                 |  7 +++----
 drivers/base/physical_location.c     |  4 +---
 drivers/media/pci/intel/ipu-bridge.c | 29 ++++-------------------------
 drivers/usb/core/usb-acpi.c          |  3 +--
 include/acpi/acpi_bus.h              | 23 ++++++++++++++++++++---
 include/linux/acpi.h                 |  5 +++++
 8 files changed, 36 insertions(+), 42 deletions(-)

---
base-commit: d216d9cb4dd854ef0a2ec1701f403facb298af51
change-id: 20241122-fix-ipu-a2fe28908964

Best regards,

Signature · 1 line
Ricardo Ribalda <[email protected]>
#1 lore raw

PATCH v5 1/7 ACPI: bus: change the prototype for acpi_get_physical_device_location

It generally is not OK to use acpi_status and/or AE_ error codes without CONFIG_ACPI and they really only should be used in drivers/acpi/ (and not everywhere in there for that matter).

So acpi_get_physical_device_location() needs to be redefined to return something different from acpi_status (preferably bool) in order to be used in !CONFIG_ACPI code.

---
 drivers/acpi/mipi-disco-img.c        | 3 +--
 drivers/acpi/scan.c                  | 4 +---
 drivers/acpi/utils.c                 | 7 +++----
 drivers/base/physical_location.c     | 4 +---
 drivers/media/pci/intel/ipu-bridge.c | 4 ++--
 drivers/usb/core/usb-acpi.c          | 3 +--
 include/acpi/acpi_bus.h              | 2 +-
 7 files changed, 10 insertions(+), 17 deletions(-)
drivers/acpi/mipi-disco-img.c +1 -2
index 92b658f92dc0..5b85989f96be 100644
@@ -624,8 +624,7 @@ static void init_crs_csi2_swnodes(struct crs_csi2 *csi2)
 	if (!fwnode_property_present(adev_fwnode, "rotation")) {
 		struct acpi_pld_info *pld;
 
-		status = acpi_get_physical_device_location(handle, &pld);
-		if (ACPI_SUCCESS(status)) {
+		if (acpi_get_physical_device_location(handle, &pld)) {
 			swnodes->dev_props[NEXT_PROPERTY(prop_index, DEV_ROTATION)] =
 					PROPERTY_ENTRY_U32("rotation",
 							   pld->rotation * 45U);
drivers/acpi/scan.c +1 -3
index 74dcccdc6482..93d340027b7f 100644
@@ -723,10 +723,8 @@ int acpi_tie_acpi_dev(struct acpi_device *adev)
 static void acpi_store_pld_crc(struct acpi_device *adev)
 {
 	struct acpi_pld_info *pld;
-	acpi_status status;
 
-	status = acpi_get_physical_device_location(adev->handle, &pld);
-	if (ACPI_FAILURE(status))
+	if (!acpi_get_physical_device_location(adev->handle, &pld))
 		return;
 
 	adev->pld_crc = crc32(~0, pld, sizeof(*pld));
drivers/acpi/utils.c +3 -4
index 6de542d99518..526563a0d188 100644
@@ -494,7 +494,7 @@ bool acpi_device_dep(acpi_handle target, acpi_handle match)
 }
 EXPORT_SYMBOL_GPL(acpi_device_dep);
 
-acpi_status
+bool
 acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld)
 {
 	acpi_status status;
@@ -502,9 +502,8 @@ acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld
 	union acpi_object *output;
 
 	status = acpi_evaluate_object(handle, "_PLD", NULL, &buffer);
-
 	if (ACPI_FAILURE(status))
-		return status;
+		return false;
 
 	output = buffer.pointer;
 
@@ -523,7 +522,7 @@ acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld
 
 out:
 	kfree(buffer.pointer);
-	return status;
+	return ACPI_SUCCESS(status);
 }
 EXPORT_SYMBOL(acpi_get_physical_device_location);
 
drivers/base/physical_location.c +1 -3
index 951819e71b4a..5db06e825c94 100644
@@ -13,13 +13,11 @@
 bool dev_add_physical_location(struct device *dev)
 {
 	struct acpi_pld_info *pld;
-	acpi_status status;
 
 	if (!has_acpi_companion(dev))
 		return false;
 
-	status = acpi_get_physical_device_location(ACPI_HANDLE(dev), &pld);
-	if (ACPI_FAILURE(status))
+	if (!acpi_get_physical_device_location(ACPI_HANDLE(dev), &pld))
 		return false;
 
 	dev->physical_location =
drivers/media/pci/intel/ipu-bridge.c +2 -2
index a0e9a71580b5..6cc2614b8f86 100644
@@ -259,12 +259,12 @@ static enum v4l2_fwnode_orientation ipu_bridge_parse_orientation(struct acpi_dev
 {
 	enum v4l2_fwnode_orientation orientation;
 	struct acpi_pld_info *pld = NULL;
-	acpi_status status = AE_ERROR;
+	bool status = false;
 
 #if IS_ENABLED(CONFIG_ACPI)
 	status = acpi_get_physical_device_location(adev->handle, &pld);
 #endif
-	if (ACPI_FAILURE(status)) {
+	if (!status) {
 		dev_warn(ADEV_DEV(adev), "_PLD call failed, using default orientation\n");
 		return V4L2_FWNODE_ORIENTATION_EXTERNAL;
 	}
drivers/usb/core/usb-acpi.c +1 -2
index 03c22114214b..935c0efea0b6 100644
@@ -213,8 +213,7 @@ usb_acpi_get_connect_type(struct usb_port *port_dev, acpi_handle *handle)
 	 * no connectable, the port would be not used.
 	 */
 
-	status = acpi_get_physical_device_location(handle, &pld);
-	if (ACPI_SUCCESS(status) && pld)
+	if (acpi_get_physical_device_location(handle, &pld) && pld)
 		port_dev->location = USB_ACPI_LOCATION_VALID |
 			pld->group_token << 8 | pld->group_position;
 
include/acpi/acpi_bus.h +1 -1
index b2e377b7f337..19f92852e127 100644
@@ -43,7 +43,7 @@ acpi_status
 acpi_evaluate_ost(acpi_handle handle, u32 source_event, u32 status_code,
 		  struct acpi_buffer *status_buf);
 
-acpi_status
+bool
 acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld);
 
 bool acpi_has_method(acpi_handle handle, char *name);
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
#2 lore raw

PATCH v5 2/7 ACPI: bus: implement for_each_acpi_dev_match when !ACPI

In reply to Ricardo Ribalda

Provide an implementation of for_each_acpi_dev_match that can be used when CONFIG_ACPI is not set.

The condition false && hid && uid && hrv is used to avoid "variable not used" warnings.

---
 include/acpi/acpi_bus.h | 3 +++
 1 file changed, 3 insertions(+)
include/acpi/acpi_bus.h +3 -0
index 19f92852e127..a9b5a5204781 100644
@@ -1003,6 +1003,9 @@ static inline int unregister_acpi_bus_type(void *bus) { return 0; }
 
 static inline int acpi_wait_for_acpi_ipmi(void) { return 0; }
 
+#define for_each_acpi_dev_match(adev, hid, uid, hrv)			\
+	for (adev = NULL; false && (hid) && (uid) && (hrv); )
+
 #endif				/* CONFIG_ACPI */
 
 #endif /*__ACPI_BUS_H__*/
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
#3 lore raw

PATCH v5 3/7 ACPI: bus: implement acpi_get_physical_device_location when !ACPI

In reply to Ricardo Ribalda

Provide an implementation of acpi_get_physical_device_location that can be used when CONFIG_ACPI is not set.

---
 include/acpi/acpi_bus.h | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
include/acpi/acpi_bus.h +9 -3
index a9b5a5204781..f38e8b1c8e1f 100644
@@ -43,9 +43,6 @@ acpi_status
 acpi_evaluate_ost(acpi_handle handle, u32 source_event, u32 status_code,
 		  struct acpi_buffer *status_buf);
 
-bool
-acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld);
-
 bool acpi_has_method(acpi_handle handle, char *name);
 acpi_status acpi_execute_simple_method(acpi_handle handle, char *method,
 				       u64 arg);
@@ -60,6 +57,9 @@ bool acpi_check_dsm(acpi_handle handle, const guid_t *guid, u64 rev, u64 funcs);
 union acpi_object *acpi_evaluate_dsm(acpi_handle handle, const guid_t *guid,
 			u64 rev, u64 func, union acpi_object *argv4);
 #ifdef CONFIG_ACPI
+bool
+acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld);
+
 static inline union acpi_object *
 acpi_evaluate_dsm_typed(acpi_handle handle, const guid_t *guid, u64 rev,
 			u64 func, union acpi_object *argv4,
@@ -1003,6 +1003,12 @@ static inline int unregister_acpi_bus_type(void *bus) { return 0; }
 
 static inline int acpi_wait_for_acpi_ipmi(void) { return 0; }
 
+static inline bool
+acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld)
+{
+	return false;
+}
+
 #define for_each_acpi_dev_match(adev, hid, uid, hrv)			\
 	for (adev = NULL; false && (hid) && (uid) && (hrv); )
 
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
#4 lore raw

PATCH v5 4/7 ACPI: header: implement acpi_device_handle when !ACPI

In reply to Ricardo Ribalda

Provide an implementation of acpi_device_handle that can be used when CONFIG_ACPI is not set.

---
 include/linux/acpi.h | 5 +++++
 1 file changed, 5 insertions(+)
include/linux/acpi.h +5 -0
index 05f39fbfa485..fb88f21bffb2 100644
@@ -854,6 +854,11 @@ static inline struct fwnode_handle *acpi_fwnode_handle(struct acpi_device *adev)
 	return NULL;
 }
 
+static inline acpi_handle acpi_device_handle(struct acpi_device *adev)
+{
+	return NULL;
+}
+
 static inline bool has_acpi_companion(struct device *dev)
 {
 	return false;
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
#5 lore raw

PATCH v5 5/7 ACPI: bus: implement for_each_acpi_consumer_dev when !ACPI

In reply to Ricardo Ribalda

Provide an implementation of for_each_acpi_consumer_dev that can be use used when CONFIG_ACPI is not set.

The expression false && supplier is used to avoid "variable not used" warnings.

---
 include/acpi/acpi_bus.h | 3 +++
 1 file changed, 3 insertions(+)
include/acpi/acpi_bus.h +3 -0
index f38e8b1c8e1f..68c0e2fb029f 100644
@@ -1009,6 +1009,9 @@ acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld
 	return false;
 }
 
+#define for_each_acpi_consumer_dev(supplier, consumer)			\
+	for (consumer = NULL; false && (supplier);)
+
 #define for_each_acpi_dev_match(adev, hid, uid, hrv)			\
 	for (adev = NULL; false && (hid) && (uid) && (hrv); )
 
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
#6 lore raw

PATCH v5 6/7 ACPI: bus: implement acpi_device_hid when !ACPI

In reply to Ricardo Ribalda

Provide an implementation of acpi_device_hid that can be used when CONFIG_ACPI is not set.

---
 include/acpi/acpi_bus.h | 5 +++++
 1 file changed, 5 insertions(+)
include/acpi/acpi_bus.h +5 -0
index 68c0e2fb029f..aad1a95e6863 100644
@@ -1003,6 +1003,11 @@ static inline int unregister_acpi_bus_type(void *bus) { return 0; }
 
 static inline int acpi_wait_for_acpi_ipmi(void) { return 0; }
 
+static inline const char *acpi_device_hid(struct acpi_device *device)
+{
+	return "";
+}
+
 static inline bool
 acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld)
 {
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
#7 lore raw

PATCH v5 7/7 media: ipu-bridge: Remove unneeded conditional compilations

In reply to Ricardo Ribalda

The ACPI headers have introduced implementations for some of their functions when the kernel is not configured with ACPI.

Let's use them instead of our conditional compilation. It is easier to maintain and less prone to errors.

---
 drivers/media/pci/intel/ipu-bridge.c | 29 ++++-------------------------
 1 file changed, 4 insertions(+), 25 deletions(-)
drivers/media/pci/intel/ipu-bridge.c +4 -25
index 6cc2614b8f86..be84c100d732 100644
@@ -2,6 +2,7 @@
 /* Author: Dan Scally <[email protected]> */
 
 #include <linux/acpi.h>
+#include <acpi/acpi_bus.h>
 #include <linux/cleanup.h>
 #include <linux/device.h>
 #include <linux/i2c.h>
@@ -107,7 +108,6 @@ static const char * const ipu_vcm_types[] = {
 	"lc898212axb",
 };
 
-#if IS_ENABLED(CONFIG_ACPI)
 /*
  * Used to figure out IVSC acpi device by ipu_bridge_get_ivsc_acpi_dev()
  * instead of device and driver match to probe IVSC device.
@@ -127,11 +127,11 @@ static struct acpi_device *ipu_bridge_get_ivsc_acpi_dev(struct acpi_device *adev
 		const struct acpi_device_id *acpi_id = &ivsc_acpi_ids[i];
 		struct acpi_device *consumer, *ivsc_adev;
 
-		acpi_handle handle = acpi_device_handle(adev);
+		acpi_handle handle = acpi_device_handle(ACPI_PTR(adev));
 		for_each_acpi_dev_match(ivsc_adev, acpi_id->id, NULL, -1)
 			/* camera sensor depends on IVSC in DSDT if exist */
 			for_each_acpi_consumer_dev(ivsc_adev, consumer)
-				if (consumer->handle == handle) {
+				if (ACPI_PTR(consumer->handle) == handle) {
 					acpi_dev_put(consumer);
 					return ivsc_adev;
 				}
@@ -139,12 +139,6 @@ static struct acpi_device *ipu_bridge_get_ivsc_acpi_dev(struct acpi_device *adev
 
 	return NULL;
 }
-#else
-static struct acpi_device *ipu_bridge_get_ivsc_acpi_dev(struct acpi_device *adev)
-{
-	return NULL;
-}
-#endif
 
 static int ipu_bridge_match_ivsc_dev(struct device *dev, const void *adev)
 {
@@ -259,12 +253,8 @@ static enum v4l2_fwnode_orientation ipu_bridge_parse_orientation(struct acpi_dev
 {
 	enum v4l2_fwnode_orientation orientation;
 	struct acpi_pld_info *pld = NULL;
-	bool status = false;
 
-#if IS_ENABLED(CONFIG_ACPI)
-	status = acpi_get_physical_device_location(adev->handle, &pld);
-#endif
-	if (!status) {
+	if (!acpi_get_physical_device_location(ACPI_PTR(adev->handle), &pld)) {
 		dev_warn(ADEV_DEV(adev), "_PLD call failed, using default orientation\n");
 		return V4L2_FWNODE_ORIENTATION_EXTERNAL;
 	}
@@ -498,9 +488,7 @@ static void ipu_bridge_create_connection_swnodes(struct ipu_bridge *bridge,
 	if (sensor->csi_dev) {
 		const char *device_hid = "";
 
-#if IS_ENABLED(CONFIG_ACPI)
 		device_hid = acpi_device_hid(sensor->ivsc_adev);
-#endif
 
 		snprintf(sensor->ivsc_name, sizeof(sensor->ivsc_name), "%s-%u",
 			 device_hid, sensor->link);
@@ -671,11 +659,7 @@ static int ipu_bridge_connect_sensor(const struct ipu_sensor_config *cfg,
 	struct acpi_device *adev = NULL;
 	int ret;
 
-#if IS_ENABLED(CONFIG_ACPI)
 	for_each_acpi_dev_match(adev, cfg->hid, NULL, -1) {
-#else
-	while (true) {
-#endif
 		if (!ACPI_PTR(adev->status.enabled))
 			continue;
 
@@ -768,15 +752,10 @@ static int ipu_bridge_ivsc_is_ready(void)
 	unsigned int i;
 
 	for (i = 0; i < ARRAY_SIZE(ipu_supported_sensors); i++) {
-#if IS_ENABLED(CONFIG_ACPI)
 		const struct ipu_sensor_config *cfg =
 			&ipu_supported_sensors[i];
 
 		for_each_acpi_dev_match(sensor_adev, cfg->hid, NULL, -1) {
-#else
-		while (true) {
-			sensor_adev = NULL;
-#endif
 			if (!ACPI_PTR(sensor_adev->status.enabled))
 				continue;
 
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
#8 lore raw
In reply to Ricardo Ribalda
Quoted 59 lines · Ricardo Ribalda

We want to be able to compile_test the ipu6 driver in situations with !ACPI.

In order to do this we had to add some conditional #ifs, which lead to false positives on the static analysers.

Let's implement some helpers when !ACPI in the acpi headers to make the code more easier to maintain.

To: Rafael J. Wysocki <[email protected]>
To: Len Brown <[email protected]>
To: Robert Moore <[email protected]>
To: Rafael J. Wysocki <[email protected]>

Changes in v5:
- Remove Fixes tag
- redefine acpi_get_physical_device_location() to return bool
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4 (Thanks Sakari & Mauro):
- Squash the two ipu changes and merge everything via ACPI
- Space after ;
- move acpi_device_handle to avoid fwd declaration.
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Prefer static inlines to macros (Thanks Rafael).
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Add helpers in acpi to avoid conditional compilation
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Ricardo Ribalda (7):
ACPI: bus: change the prototype for acpi_get_physical_device_location
ACPI: bus: implement for_each_acpi_dev_match when !ACPI
ACPI: bus: implement acpi_get_physical_device_location when !ACPI
ACPI: header: implement acpi_device_handle when !ACPI
ACPI: bus: implement for_each_acpi_consumer_dev when !ACPI
ACPI: bus: implement acpi_device_hid when !ACPI
media: ipu-bridge: Remove unneeded conditional compilations

 drivers/acpi/mipi-disco-img.c        |  3 +--
 drivers/acpi/scan.c                  |  4 +---
 drivers/acpi/utils.c                 |  7 +++----
 drivers/base/physical_location.c     |  4 +---
 drivers/media/pci/intel/ipu-bridge.c | 29 ++++-------------------------
 drivers/usb/core/usb-acpi.c          |  3 +--
 include/acpi/acpi_bus.h              | 23 ++++++++++++++++++++---
 include/linux/acpi.h                 |  5 +++++
 8 files changed, 36 insertions(+), 42 deletions(-)
Quoted 1 line

---

Series applied as 6.14 material, thanks!