Skip to contentSkip to conversation

ipu6: get rid of all the IS_ENABLED(CONFIG_ACPI)

PATCH Superseded Ricardo Ribalda 2 participants 10 messages Nov 22, 2024 – Dec 10, 2024

Subsystems (3)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 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.

We can land the first patch of this series ASAP to fix the current smatch warning.

To: Mauro Carvalho Chehab <[email protected]>
To: Rafael J. Wysocki <[email protected]>
To: Len Brown <[email protected]>
To: Robert Moore <[email protected]>
To: Rafael J. Wysocki <[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):
media: ipu-bridge: Fix warning when !ACPI
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/media/pci/intel/ipu-bridge.c | 23 ++---------------------
 include/acpi/acpi_bus.h              | 16 +++++++++++++---
 include/linux/acpi.h                 |  1 +
 3 files changed, 16 insertions(+), 24 deletions(-)

---
base-commit: 72ad4ff638047bbbdf3232178fea4bec1f429319
change-id: 20241122-fix-ipu-a2fe28908964

Best regards,

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

PATCH v2 1/7 media: ipu-bridge: Fix warning when !ACPI

One of the quirks that we introduced to build with !ACPI && COMPILE_TEST
throws the following smatch warning:
drivers/media/pci/intel/ipu-bridge.c:752 ipu_bridge_ivsc_is_ready() warn: iterator 'i' not incremented

Fix it by replacing the condition.

---
 drivers/media/pci/intel/ipu-bridge.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/pci/intel/ipu-bridge.c +1 -1
index a0e9a71580b5..be82bc3e27d0 100644
@@ -774,7 +774,7 @@ static int ipu_bridge_ivsc_is_ready(void)
 
 		for_each_acpi_dev_match(sensor_adev, cfg->hid, NULL, -1) {
 #else
-		while (true) {
+		while (false) {
 			sensor_adev = NULL;
 #endif
 			if (!ACPI_PTR(sensor_adev->status.enabled))
Signature · 1 line
2.47.0.371.ga323438b13-goog
#2 lore raw

PATCH v2 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 b2e377b7f337..eaafca41cf02 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.0.371.ga323438b13-goog
#3 lore raw

PATCH v2 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 | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
include/acpi/acpi_bus.h +5 -3
index eaafca41cf02..4888231422ea 100644
@@ -43,9 +43,6 @@ acpi_status
 acpi_evaluate_ost(acpi_handle handle, u32 source_event, u32 status_code,
 		  struct acpi_buffer *status_buf);
 
-acpi_status
-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
+acpi_status
+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,8 @@ static inline int unregister_acpi_bus_type(void *bus) { return 0; }
 
 static inline int acpi_wait_for_acpi_ipmi(void) { return 0; }
 
+#define acpi_get_physical_device_location(handle, pld) (AE_ERROR)
+
 #define for_each_acpi_dev_match(adev, hid, uid, hrv)			\
 	for (adev = NULL; false && (hid) && (uid) && (hrv);)
 
Signature · 1 line
2.47.0.371.ga323438b13-goog
#4 lore raw

Re: [PATCH v2 3/7] ACPI: bus: implement acpi_get_physical_device_location when !ACPI

Quoted 34 lines · 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 | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
include/acpi/acpi_bus.h +3 -3
index eaafca41cf02..4888231422ea 100644
@@ -43,9 +43,6 @@ acpi_status
 acpi_evaluate_ost(acpi_handle handle, u32 source_event, u32 status_code,
                  struct acpi_buffer *status_buf);
 
-acpi_status
-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
+acpi_status
+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,

include/acpi/acpi_bus.h static inline int unregister_acpi_bus_type(void *bus) { return 0; } · line 1006

Quoted 4 lines
include/acpi/acpi_bus.h +1 -0
@@ -1003,6 +1003,8 @@ static inline int unregister_acpi_bus_type(void *bus) { return 0; }
 
 static inline int acpi_wait_for_acpi_ipmi(void) { return 0; }
 
+#define acpi_get_physical_device_location(handle, pld) (AE_ERROR)

This is a function, so static inline please.

Analogously in patches [4,6/7].

And you can merge patches [2-6/7] together into one patch, as far as I'm concerned.

Quoted 6 lines
include/acpi/acpi_bus.h +1 -1
+
 #define for_each_acpi_dev_match(adev, hid, uid, hrv)                   \
        for (adev = NULL; false && (hid) && (uid) && (hrv);)
 
 
--
#5 lore raw

Re: [PATCH v2 3/7] ACPI: bus: implement acpi_get_physical_device_location when !ACPI

Quoted 39 lines · Rafael J. Wysocki
Quoted 37 lines · 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 | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
include/acpi/acpi_bus.h +3 -3
index eaafca41cf02..4888231422ea 100644
@@ -43,9 +43,6 @@ acpi_status
 acpi_evaluate_ost(acpi_handle handle, u32 source_event, u32 status_code,
                  struct acpi_buffer *status_buf);
 
-acpi_status
-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
+acpi_status
+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,8 @@ static inline int unregister_acpi_bus_type(void *bus) { return 0; }
 
 static inline int acpi_wait_for_acpi_ipmi(void) { return 0; }
 
Quoted 8 lines

include/acpi/acpi_bus.h static inline int unregister_acpi_bus_type(void *bus) { return 0; } · line 1006

Quoted 1 line
include/acpi/acpi_bus.h +1 -0
+#define acpi_get_physical_device_location(handle, pld) (AE_ERROR)

This is a function, so static inline please.

Analogously in patches [4,6/7].

And you can merge patches [2-6/7] together into one patch, as far as I'm concerned.

I was trying to avoid some extra ACPI_PTR and a forward declaration... But overall I think it looks nicers with static inlines.

I have kept the patches separately. Feel free to squash them if your prefer that way

Thanks!

Quoted 7 lines
Quoted 7 lines
include/acpi/acpi_bus.h +1 -1
+
 #define for_each_acpi_dev_match(adev, hid, uid, hrv)                   \
        for (adev = NULL; false && (hid) && (uid) && (hrv);)
 
 
--
Signature · 1 line
Ricardo Ribalda
#6 lore raw

PATCH v2 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 | 1 +
 1 file changed, 1 insertion(+)
include/linux/acpi.h +1 -0
index 4d5ee84c468b..85d7649ac17d 100644
@@ -777,6 +777,7 @@ const char *acpi_get_subsystem_id(acpi_handle handle);
 
 #define acpi_disabled 1
 
+#define acpi_device_handle(adev)	(NULL)
 #define ACPI_COMPANION(dev)		(NULL)
 #define ACPI_COMPANION_SET(dev, adev)	do { } while (0)
 #define ACPI_HANDLE(dev)		(NULL)
Signature · 1 line
2.47.0.371.ga323438b13-goog
#7 lore raw

PATCH v2 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 4888231422ea..57298c7cfb5d 100644
@@ -1005,6 +1005,9 @@ static inline int acpi_wait_for_acpi_ipmi(void) { return 0; }
 
 #define acpi_get_physical_device_location(handle, pld) (AE_ERROR)
 
+#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.0.371.ga323438b13-goog
#8 lore raw

PATCH v2 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 | 2 ++
 1 file changed, 2 insertions(+)
include/acpi/acpi_bus.h +2 -0
index 57298c7cfb5d..cb1b38245f15 100644
@@ -1003,6 +1003,8 @@ static inline int unregister_acpi_bus_type(void *bus) { return 0; }
 
 static inline int acpi_wait_for_acpi_ipmi(void) { return 0; }
 
+#define acpi_device_hid(device) ""
+
 #define acpi_get_physical_device_location(handle, pld) (AE_ERROR)
 
 #define for_each_acpi_consumer_dev(supplier, consumer)			\
Signature · 1 line
2.47.0.371.ga323438b13-goog
#9 lore raw

PATCH v2 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 | 23 ++---------------------
 1 file changed, 2 insertions(+), 21 deletions(-)
drivers/media/pci/intel/ipu-bridge.c +2 -21
index be82bc3e27d0..6bdf42f6769f 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.
@@ -131,7 +131,7 @@ static struct acpi_device *ipu_bridge_get_ivsc_acpi_dev(struct acpi_device *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)
 {
@@ -261,9 +255,7 @@ static enum v4l2_fwnode_orientation ipu_bridge_parse_orientation(struct acpi_dev
 	struct acpi_pld_info *pld = NULL;
 	acpi_status status = AE_ERROR;
 
-#if IS_ENABLED(CONFIG_ACPI)
 	status = acpi_get_physical_device_location(adev->handle, &pld);
-#endif
 	if (ACPI_FAILURE(status)) {
 		dev_warn(ADEV_DEV(adev), "_PLD call failed, using default orientation\n");
 		return V4L2_FWNODE_ORIENTATION_EXTERNAL;
@@ -498,9 +490,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 +661,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 +754,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 (false) {
-			sensor_adev = NULL;
-#endif
 			if (!ACPI_PTR(sensor_adev->status.enabled))
 				continue;
 
Signature · 1 line
2.47.0.371.ga323438b13-goog