Skip to contentSkip to conversation

i2c: i801: Allow ACPI SystemIO OpRegion to conflict with PCI BAR

PATCH Superseded Mika Westerberg 6 participants 23 messages Apr 28, 2016 – May 7, 2016 1 message not in the archive

Subsystems (3)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: i801: Allow ACPI SystemIO OpRegion to conflict with PCI BAR

Many Intel systems the BIOS declares a SystemIO OpRegion below the SMBus PCI device as can be seen in ACPI DSDT table from Lenovo Yoga 900:

  Device (SBUS)
  {
      OperationRegion (SMBI, SystemIO, (SBAR << 0x05), 0x10)
      Field (SMBI, ByteAcc, NoLock, Preserve)
      {
          HSTS,   8,
          Offset (0x02),
          HCON,   8,
          HCOM,   8,
          TXSA,   8,
          DAT0,   8,
          DAT1,   8,
          HBDR,   8,
          PECR,   8,
          RXSA,   8,
          SDAT,   16
      }

There are also bunch of ASL methods that that the BIOS can use to access these fields. Most of the systems in question ASL methods accessing the SMBI OpRegion are never used.

Now, because of this SMBI OpRegion many systems fail to load the SMBus driver with an error looking like one below:

ACPI Warning: SystemIO range 0x0000000000003040-0x000000000000305F

       conflicts with OpRegion 0x0000000000003040-0x000000000000304F
       (\_SB.PCI0.SBUS.SMBI) (20160108/utaddress-255)

ACPI: If an ACPI driver is available for this device, you should use
it instead of the native driver

The reason is that this SMBI OpRegion conflicts with the PCI BAR used by the SMBus driver.

It turns out that we can install a custom SystemIO address space handler for the SMBus device to intercept all accesses through that OpRegion. This allows us to share the PCI BAR with the ASL code if it for some reason is using it. We do not expect that this OpRegion handler will ever be called but if it is we print a warning and execute the read/write operation under a lock which prevents ASL and OS from messing each other.

---
 drivers/i2c/busses/i2c-i801.c | 83 ++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 79 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-i801.c +79 -4
index 5652bf6ce9be..7c0957870ee8 100644
@@ -247,6 +247,9 @@ struct i801_priv {
 	struct platform_device *mux_pdev;
 #endif
 	struct platform_device *tco_pdev;
+
+	/* Serialize ACPI ASL and OS access to the registers */
+	struct mutex acpi_lock;
 };
 
 #define FEATURE_SMBUS_PEC	(1 << 0)
@@ -721,6 +724,7 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr,
 	struct i801_priv *priv = i2c_get_adapdata(adap);
 
 	pm_runtime_get_sync(&priv->pci_dev->dev);
+	mutex_lock(&priv->acpi_lock);
 
 	hwpec = (priv->features & FEATURE_SMBUS_PEC) && (flags & I2C_CLIENT_PEC)
 		&& size != I2C_SMBUS_QUICK
@@ -820,6 +824,7 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr,
 	}
 
 out:
+	mutex_unlock(&priv->acpi_lock);
 	pm_runtime_mark_last_busy(&priv->pci_dev->dev);
 	pm_runtime_put_autosuspend(&priv->pci_dev->dev);
 	return ret;
@@ -1260,6 +1265,75 @@ static void i801_add_tco(struct i801_priv *priv)
 	priv->tco_pdev = pdev;
 }
 
+#ifdef CONFIG_ACPI
+static acpi_status
+i801_acpi_io_handler(u32 function, acpi_physical_address address, u32 bits,
+		     u64 *value, void *handler_context, void *region_context)
+{
+	struct i801_priv *priv = handler_context;
+	struct pci_dev *pdev = priv->pci_dev;
+	acpi_status status;
+
+	dev_warn_once(&pdev->dev,
+		      "BIOS is accessing SMBus registers from ASL\n");
+
+	/*
+	 * ASL code is trying to access the I/O port. Make sure we do not
+	 * access the bus at the same time from OS side by taking the lock
+	 * here.
+	 */
+	pm_runtime_get_sync(&pdev->dev);
+	mutex_lock(&priv->acpi_lock);
+
+	if (function == ACPI_READ) {
+		u32 val = (u32)*value;
+		status = acpi_os_read_port(address, &val, bits);
+		if (ACPI_SUCCESS(status))
+			*value = val;
+	} else {
+		status = acpi_os_write_port(address, (u32)*value, bits);
+	}
+
+	mutex_unlock(&priv->acpi_lock);
+	pm_runtime_mark_last_busy(&pdev->dev);
+	pm_runtime_put_autosuspend(&pdev->dev);
+
+	return status;
+}
+
+static int i801_acpi_probe(struct i801_priv *priv)
+{
+	struct acpi_device *adev;
+	acpi_status status;
+
+	adev = ACPI_COMPANION(&priv->pci_dev->dev);
+	if (adev) {
+		status = acpi_install_address_space_handler(adev->handle,
+				ACPI_ADR_SPACE_SYSTEM_IO, i801_acpi_io_handler,
+				NULL, priv);
+		if (ACPI_SUCCESS(status))
+			return 0;
+	}
+
+	return acpi_check_resource_conflict(&priv->pci_dev->resource[SMBBAR]);
+}
+
+static void i801_acpi_remove(struct i801_priv *priv)
+{
+	struct acpi_device *adev;
+
+	adev = ACPI_COMPANION(&priv->pci_dev->dev);
+	if (!adev)
+		return;
+
+	acpi_remove_address_space_handler(adev->handle,
+		ACPI_ADR_SPACE_SYSTEM_IO, i801_acpi_io_handler);
+}
+#else
+static inline int i801_acpi_probe(struct i801_priv *priv) { return 0; }
+static inline void i801_acpi_remove(struct i801_priv *priv) { }
+#endif
+
 static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
 {
 	unsigned char temp;
@@ -1277,6 +1351,7 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
 	priv->adapter.dev.parent = &dev->dev;
 	ACPI_COMPANION_SET(&priv->adapter.dev, ACPI_COMPANION(&dev->dev));
 	priv->adapter.retries = 3;
+	mutex_init(&priv->acpi_lock);
 
 	priv->pci_dev = dev;
 	switch (dev->device) {
@@ -1339,10 +1414,9 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
 		return -ENODEV;
 	}
 
-	err = acpi_check_resource_conflict(&dev->resource[SMBBAR]);
-	if (err) {
-		return -ENODEV;
-	}
+	err = i801_acpi_probe(priv);
+	if (err)
+		return err;
 
 	err = pcim_iomap_regions(dev, 1 << SMBBAR,
 				 dev_driver_string(&dev->dev));
@@ -1439,6 +1513,7 @@ static void i801_remove(struct pci_dev *dev)
 	pm_runtime_forbid(&dev->dev);
 	pm_runtime_get_noresume(&dev->dev);
 
+	i801_acpi_remove(priv);
 	i801_del_mux(priv);
 	i2c_del_adapter(&priv->adapter);
 	pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
Signature · 1 line
2.8.0.rc3
Tested-by on v1 1/1
#1 lore raw
Quoted 37 lines · Mika Westerberg

Many Intel systems the BIOS declares a SystemIO OpRegion below the SMBus PCI device as can be seen in ACPI DSDT table from Lenovo Yoga 900:

  Device (SBUS)
  {
      OperationRegion (SMBI, SystemIO, (SBAR << 0x05), 0x10)
      Field (SMBI, ByteAcc, NoLock, Preserve)
      {
          HSTS,   8,
          Offset (0x02),
          HCON,   8,
          HCOM,   8,
          TXSA,   8,
          DAT0,   8,
          DAT1,   8,
          HBDR,   8,
          PECR,   8,
          RXSA,   8,
          SDAT,   16
      }

There are also bunch of ASL methods that that the BIOS can use to access these fields. Most of the systems in question ASL methods accessing the SMBI OpRegion are never used.

Now, because of this SMBI OpRegion many systems fail to load the SMBus driver with an error looking like one below:

ACPI Warning: SystemIO range 0x0000000000003040-0x000000000000305F

       conflicts with OpRegion 0x0000000000003040-0x000000000000304F
       (\_SB.PCI0.SBUS.SMBI) (20160108/utaddress-255)

ACPI: If an ACPI driver is available for this device, you should use
it instead of the native driver

The reason is that this SMBI OpRegion conflicts with the PCI BAR used by the SMBus driver.

Quoted 6 lines

It turns out that we can install a custom SystemIO address space handler for the SMBus device to intercept all accesses through that OpRegion. This allows us to share the PCI BAR with the ASL code if it for some reason is using it. We do not expect that this OpRegion handler will ever be called but if it is we print a warning and execute the read/write operation under a lock which prevents ASL and OS from messing each other.

This successfully works around:

https://bugzilla.kernel.org/show_bug.cgi?id=110041

but the BIOS people should still fix their ASL. Sigh.

On the Dell laptop, the observable effect is that the driver loads and finds the iTCO thing.

Pali, this may be considerably more useful on your laptop.

--Andy

#2 lore raw
Quoted 38 lines · Andy Lutomirski
Quoted 37 lines · Mika Westerberg

Many Intel systems the BIOS declares a SystemIO OpRegion below the SMBus PCI device as can be seen in ACPI DSDT table from Lenovo Yoga 900:

Device (SBUS)

 {
     OperationRegion (SMBI, SystemIO, (SBAR << 0x05), 0x10)
     Field (SMBI, ByteAcc, NoLock, Preserve)
     {
         HSTS,   8,
         Offset (0x02),
         HCON,   8,
         HCOM,   8,
         TXSA,   8,
         DAT0,   8,
         DAT1,   8,
         HBDR,   8,
         PECR,   8,
         RXSA,   8,
         SDAT,   16
     }

There are also bunch of ASL methods that that the BIOS can use to access these fields. Most of the systems in question ASL methods accessing the SMBI OpRegion are never used.

Now, because of this SMBI OpRegion many systems fail to load the SMBus driver with an error looking like one below:

ACPI Warning: SystemIO range 0x0000000000003040-0x000000000000305F

      conflicts with OpRegion 0x0000000000003040-0x000000000000304F
      (\_SB.PCI0.SBUS.SMBI) (20160108/utaddress-255)

ACPI: If an ACPI driver is available for this device, you should use
it instead of the native driver

The reason is that this SMBI OpRegion conflicts with the PCI BAR used by the SMBus driver.

Quoted 8 lines
Quoted 6 lines

It turns out that we can install a custom SystemIO address space handler for the SMBus device to intercept all accesses through that OpRegion. This allows us to share the PCI BAR with the ASL code if it for some reason is using it. We do not expect that this OpRegion handler will ever be called but if it is we print a warning and execute the read/write operation under a lock which prevents ASL and OS from messing each other.

Thanks for testing!

Quoted 5 lines

This successfully works around:

https://bugzilla.kernel.org/show_bug.cgi?id=110041

but the BIOS people should still fix their ASL. Sigh.

For what it's worth Kabylake BIOS should not have this OpRegion anymore.

#12 lore raw
In reply to Andy Lutomirski
Quoted 49 lines · On Thursday 28 April 2016 11:34:38 Andy Lutomirski wrote:
Quoted 37 lines · Mika Westerberg

Many Intel systems the BIOS declares a SystemIO OpRegion below the SMBus PCI device as can be seen in ACPI DSDT table from Lenovo Yoga 900:

Device (SBUS)

 {
     OperationRegion (SMBI, SystemIO, (SBAR << 0x05), 0x10)
     Field (SMBI, ByteAcc, NoLock, Preserve)
     {
         HSTS,   8,
         Offset (0x02),
         HCON,   8,
         HCOM,   8,
         TXSA,   8,
         DAT0,   8,
         DAT1,   8,
         HBDR,   8,
         PECR,   8,
         RXSA,   8,
         SDAT,   16
     }

There are also bunch of ASL methods that that the BIOS can use to access these fields. Most of the systems in question ASL methods accessing the SMBI OpRegion are never used.

Now, because of this SMBI OpRegion many systems fail to load the SMBus driver with an error looking like one below:

ACPI Warning: SystemIO range 0x0000000000003040-0x000000000000305F

      conflicts with OpRegion 0x0000000000003040-0x000000000000304F
      (\_SB.PCI0.SBUS.SMBI) (20160108/utaddress-255)

ACPI: If an ACPI driver is available for this device, you should use
it instead of the native driver

The reason is that this SMBI OpRegion conflicts with the PCI BAR used by the SMBus driver.

Quoted 6 lines

It turns out that we can install a custom SystemIO address space handler for the SMBus device to intercept all accesses through that OpRegion. This allows us to share the PCI BAR with the ASL code if it for some reason is using it. We do not expect that this OpRegion handler will ever be called but if it is we print a warning and execute the read/write operation under a lock which prevents ASL and OS from messing each other.

This successfully works around:

Quoted 8 lines

https://bugzilla.kernel.org/show_bug.cgi?id=110041

but the BIOS people should still fix their ASL. Sigh.

On the Dell laptop, the observable effect is that the driver loads and finds the iTCO thing.

Pali, this may be considerably more useful on your laptop.

Andy, I am right that I will be able to load i2c-i801.ko driver without acpi_enforce_resources=lax parameter?

If yes, then it sounds good! Finally I would be able to bind lis3lv02d_i2c.ko driver for accelerometer which is on my E6440 machine.

Andy, is there any way to tell i2c-i801.ko driver that on i2c bus (which that driver exports) is present some i2c device? Months ago I got list of Latitude machines on which i2c address is that accelerometer present.

It is possible to hardcode that mapping (DMI name of laptop --> i2c address) into dell-laptop driver, so i2c-i801.ko and lis3lv02d_i2c.ko will be automatically loaded and lis3l binded correctly to i801 i2c address?

Signature · 6 lines
Pali Rohár
[email protected]
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#13 lore raw
Quoted 54 lines · Pali Rohár
Quoted 53 lines · On Thursday 28 April 2016 11:34:38 Andy Lutomirski wrote:
Quoted 37 lines · Mika Westerberg

Many Intel systems the BIOS declares a SystemIO OpRegion below the SMBus PCI device as can be seen in ACPI DSDT table from Lenovo Yoga 900:

Device (SBUS)

 {
     OperationRegion (SMBI, SystemIO, (SBAR << 0x05), 0x10)
     Field (SMBI, ByteAcc, NoLock, Preserve)
     {
         HSTS,   8,
         Offset (0x02),
         HCON,   8,
         HCOM,   8,
         TXSA,   8,
         DAT0,   8,
         DAT1,   8,
         HBDR,   8,
         PECR,   8,
         RXSA,   8,
         SDAT,   16
     }

There are also bunch of ASL methods that that the BIOS can use to access these fields. Most of the systems in question ASL methods accessing the SMBI OpRegion are never used.

Now, because of this SMBI OpRegion many systems fail to load the SMBus driver with an error looking like one below:

ACPI Warning: SystemIO range 0x0000000000003040-0x000000000000305F

      conflicts with OpRegion 0x0000000000003040-0x000000000000304F
      (\_SB.PCI0.SBUS.SMBI) (20160108/utaddress-255)

ACPI: If an ACPI driver is available for this device, you should use
it instead of the native driver

The reason is that this SMBI OpRegion conflicts with the PCI BAR used by the SMBus driver.

Quoted 6 lines

It turns out that we can install a custom SystemIO address space handler for the SMBus device to intercept all accesses through that OpRegion. This allows us to share the PCI BAR with the ASL code if it for some reason is using it. We do not expect that this OpRegion handler will ever be called but if it is we print a warning and execute the read/write operation under a lock which prevents ASL and OS from messing each other.

This successfully works around:

https://bugzilla.kernel.org/show_bug.cgi?id=110041

but the BIOS people should still fix their ASL. Sigh.

Quoted 7 lines
Quoted 4 lines

On the Dell laptop, the observable effect is that the driver loads and finds the iTCO thing.

Pali, this may be considerably more useful on your laptop.

Andy, I am right that I will be able to load i2c-i801.ko driver without acpi_enforce_resources=lax parameter?

Yes, and it works on my laptop.

Quoted 11 lines

If yes, then it sounds good! Finally I would be able to bind lis3lv02d_i2c.ko driver for accelerometer which is on my E6440 machine.

Andy, is there any way to tell i2c-i801.ko driver that on i2c bus (which that driver exports) is present some i2c device? Months ago I got list of Latitude machines on which i2c address is that accelerometer present.

It is possible to hardcode that mapping (DMI name of laptop --> i2c address) into dell-laptop driver, so i2c-i801.ko and lis3lv02d_i2c.ko will be automatically loaded and lis3l binded correctly to i801 i2c address?

I don't know how this part works, but I doubt that doing it in dell-laptop will be convenient. After all, dell-laptop can load before i2c-i801.

Jean and Wolfram: is there a quirk mechanism to add i2c devices that aren't directly enumerable but are known to exist due to DMI?

--Andy
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer Acked-by on v1 1/1
#22 lore raw
In reply to Mika Westerberg
Quoted 44 lines · Mika Westerberg

Many Intel systems the BIOS declares a SystemIO OpRegion below the SMBus PCI device as can be seen in ACPI DSDT table from Lenovo Yoga 900:

  Device (SBUS)
  {
      OperationRegion (SMBI, SystemIO, (SBAR << 0x05), 0x10)
      Field (SMBI, ByteAcc, NoLock, Preserve)
      {
          HSTS,   8,
          Offset (0x02),
          HCON,   8,
          HCOM,   8,
          TXSA,   8,
          DAT0,   8,
          DAT1,   8,
          HBDR,   8,
          PECR,   8,
          RXSA,   8,
          SDAT,   16
      }

There are also bunch of ASL methods that that the BIOS can use to access these fields. Most of the systems in question ASL methods accessing the SMBI OpRegion are never used.

Now, because of this SMBI OpRegion many systems fail to load the SMBus driver with an error looking like one below:

ACPI Warning: SystemIO range 0x0000000000003040-0x000000000000305F

       conflicts with OpRegion 0x0000000000003040-0x000000000000304F
       (\_SB.PCI0.SBUS.SMBI) (20160108/utaddress-255)

ACPI: If an ACPI driver is available for this device, you should use
it instead of the native driver

The reason is that this SMBI OpRegion conflicts with the PCI BAR used by the SMBus driver.

It turns out that we can install a custom SystemIO address space handler for the SMBus device to intercept all accesses through that OpRegion. This allows us to share the PCI BAR with the ASL code if it for some reason is using it. We do not expect that this OpRegion handler will ever be called but if it is we print a warning and execute the read/write operation under a lock which prevents ASL and OS from messing each other.

Quoted 2 lines

If it addresses any public BZ bugs, it would be good to add Link: tags for those and maybe Reported-by: for the reporters?

Quoted 147 lines
---
 drivers/i2c/busses/i2c-i801.c | 83 ++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 79 insertions(+), 4 deletions(-)
drivers/i2c/busses/i2c-i801.c +79 -5
index 5652bf6ce9be..7c0957870ee8 100644
@@ -247,6 +247,9 @@ struct i801_priv {
        struct platform_device *mux_pdev;
 #endif
        struct platform_device *tco_pdev;
+
+       /* Serialize ACPI ASL and OS access to the registers */
+       struct mutex acpi_lock;
 };
 
 #define FEATURE_SMBUS_PEC      (1 << 0)
@@ -721,6 +724,7 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr,
        struct i801_priv *priv = i2c_get_adapdata(adap);
 
        pm_runtime_get_sync(&priv->pci_dev->dev);
+       mutex_lock(&priv->acpi_lock);
 
        hwpec = (priv->features & FEATURE_SMBUS_PEC) && (flags & I2C_CLIENT_PEC)
                && size != I2C_SMBUS_QUICK
@@ -820,6 +824,7 @@ static s32 i801_access(struct i2c_adapter *adap, u16 addr,
        }
 
 out:
+       mutex_unlock(&priv->acpi_lock);
        pm_runtime_mark_last_busy(&priv->pci_dev->dev);
        pm_runtime_put_autosuspend(&priv->pci_dev->dev);
        return ret;
@@ -1260,6 +1265,75 @@ static void i801_add_tco(struct i801_priv *priv)
        priv->tco_pdev = pdev;
 }
 
+#ifdef CONFIG_ACPI
+static acpi_status
+i801_acpi_io_handler(u32 function, acpi_physical_address address, u32 bits,
+                    u64 *value, void *handler_context, void *region_context)
+{
+       struct i801_priv *priv = handler_context;
+       struct pci_dev *pdev = priv->pci_dev;
+       acpi_status status;
+
+       dev_warn_once(&pdev->dev,
+                     "BIOS is accessing SMBus registers from ASL\n");
+
+       /*
+        * ASL code is trying to access the I/O port. Make sure we do not
+        * access the bus at the same time from OS side by taking the lock
+        * here.
+        */
+       pm_runtime_get_sync(&pdev->dev);
+       mutex_lock(&priv->acpi_lock);
+
+       if (function == ACPI_READ) {
+               u32 val = (u32)*value;
+               status = acpi_os_read_port(address, &val, bits);
+               if (ACPI_SUCCESS(status))
+                       *value = val;
+       } else {
+               status = acpi_os_write_port(address, (u32)*value, bits);
+       }
+
+       mutex_unlock(&priv->acpi_lock);
+       pm_runtime_mark_last_busy(&pdev->dev);
+       pm_runtime_put_autosuspend(&pdev->dev);
+
+       return status;
+}
+
+static int i801_acpi_probe(struct i801_priv *priv)
+{
+       struct acpi_device *adev;
+       acpi_status status;
+
+       adev = ACPI_COMPANION(&priv->pci_dev->dev);
+       if (adev) {
+               status = acpi_install_address_space_handler(adev->handle,
+                               ACPI_ADR_SPACE_SYSTEM_IO, i801_acpi_io_handler,
+                               NULL, priv);
+               if (ACPI_SUCCESS(status))
+                       return 0;
+       }
+
+       return acpi_check_resource_conflict(&priv->pci_dev->resource[SMBBAR]);
+}
+
+static void i801_acpi_remove(struct i801_priv *priv)
+{
+       struct acpi_device *adev;
+
+       adev = ACPI_COMPANION(&priv->pci_dev->dev);
+       if (!adev)
+               return;
+
+       acpi_remove_address_space_handler(adev->handle,
+               ACPI_ADR_SPACE_SYSTEM_IO, i801_acpi_io_handler);
+}
+#else
+static inline int i801_acpi_probe(struct i801_priv *priv) { return 0; }
+static inline void i801_acpi_remove(struct i801_priv *priv) { }
+#endif
+
 static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
 {
        unsigned char temp;
@@ -1277,6 +1351,7 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
        priv->adapter.dev.parent = &dev->dev;
        ACPI_COMPANION_SET(&priv->adapter.dev, ACPI_COMPANION(&dev->dev));
        priv->adapter.retries = 3;
+       mutex_init(&priv->acpi_lock);
 
        priv->pci_dev = dev;
        switch (dev->device) {
@@ -1339,10 +1414,9 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
                return -ENODEV;
        }
 
-       err = acpi_check_resource_conflict(&dev->resource[SMBBAR]);
-       if (err) {
-               return -ENODEV;
-       }
+       err = i801_acpi_probe(priv);
+       if (err)
+               return err;
 
        err = pcim_iomap_regions(dev, 1 << SMBBAR,
                                 dev_driver_string(&dev->dev));
@@ -1439,6 +1513,7 @@ static void i801_remove(struct pci_dev *dev)
        pm_runtime_forbid(&dev->dev);
        pm_runtime_get_noresume(&dev->dev);
 
+       i801_acpi_remove(priv);
        i801_del_mux(priv);
        i2c_del_adapter(&priv->adapter);
        pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
--

2.8.0.rc3

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#14 lore raw
In reply to Andy Lutomirski
Quoted 71 lines · On Friday 29 April 2016 20:10:23 Andy Lutomirski wrote:
Quoted 69 lines · Pali Rohár
Quoted 68 lines · On Thursday 28 April 2016 11:34:38 Andy Lutomirski wrote:
Quoted 48 lines · Mika Westerberg

Many Intel systems the BIOS declares a SystemIO OpRegion below the SMBus

PCI device as can be seen in ACPI DSDT table from Lenovo Yoga 900:
Device (SBUS)
{

     OperationRegion (SMBI, SystemIO, (SBAR << 0x05), 0x10)
     Field (SMBI, ByteAcc, NoLock, Preserve)
     {
     
         HSTS,   8,
         Offset (0x02),
         HCON,   8,
         HCOM,   8,
         TXSA,   8,
         DAT0,   8,
         DAT1,   8,
         HBDR,   8,
         PECR,   8,
         RXSA,   8,
         SDAT,   16
     
     }

There are also bunch of ASL methods that that the BIOS can use to access these fields. Most of the systems in question ASL methods accessing the SMBI OpRegion are never used.

Now, because of this SMBI OpRegion many systems fail to load the SMBus

driver with an error looking like one below:
ACPI Warning: SystemIO range
0x0000000000003040-0x000000000000305F

      conflicts with OpRegion
      0x0000000000003040-0x000000000000304F
      (\_SB.PCI0.SBUS.SMBI) (20160108/utaddress-255)

ACPI: If an ACPI driver is available for this device, you should use

it instead of the native driver

The reason is that this SMBI OpRegion conflicts with the PCI BAR used by the SMBus driver.

Quoted 7 lines

It turns out that we can install a custom SystemIO address space handler for the SMBus device to intercept all accesses through that OpRegion. This allows us to share the PCI BAR with the ASL code if it for some reason is using it. We do not expect that this OpRegion handler will ever be called but if it is we print a warning and execute the read/write operation under a lock which prevents ASL and OS from messing each other.

This successfully works around:

https://bugzilla.kernel.org/show_bug.cgi?id=110041

but the BIOS people should still fix their ASL. Sigh.

On the Dell laptop, the observable effect is that the driver loads and finds the iTCO thing.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Pali, this may be considerably more useful on your laptop.

Andy, I am right that I will be able to load i2c-i801.ko driver without acpi_enforce_resources=lax parameter?

Yes, and it works on my laptop.

Looks like it is working also on my laptop.

Quoted 14 lines
Quoted 9 lines

If yes, then it sounds good! Finally I would be able to bind lis3lv02d_i2c.ko driver for accelerometer which is on my E6440 machine.

Andy, is there any way to tell i2c-i801.ko driver that on i2c bus (which that driver exports) is present some i2c device? Months ago I got list of Latitude machines on which i2c address is that accelerometer present.

Quoted 4 lines

It is possible to hardcode that mapping (DMI name of laptop --> i2c address) into dell-laptop driver, so i2c-i801.ko and lis3lv02d_i2c.ko will be automatically loaded and lis3l binded correctly to i801 i2c address?

Quoted 6 lines

I don't know how this part works, but I doubt that doing it in dell-laptop will be convenient. After all, dell-laptop can load before i2c-i801.

Jean and Wolfram: is there a quirk mechanism to add i2c devices that aren't directly enumerable but are known to exist due to DMI?

Maybe something like i2c_register_board_info()?

Signature · 2 lines
Pali Rohár
[email protected]
#15 lore raw
Quoted 95 lines · Pali Rohár
Quoted 71 lines · On Friday 29 April 2016 20:10:23 Andy Lutomirski wrote:
Quoted 69 lines · Pali Rohár
Quoted 68 lines · On Thursday 28 April 2016 11:34:38 Andy Lutomirski wrote:
Quoted 48 lines · Mika Westerberg

Many Intel systems the BIOS declares a SystemIO OpRegion below the SMBus

PCI device as can be seen in ACPI DSDT table from Lenovo Yoga 900:
Device (SBUS)
{

     OperationRegion (SMBI, SystemIO, (SBAR << 0x05), 0x10)
     Field (SMBI, ByteAcc, NoLock, Preserve)
     {

         HSTS,   8,
         Offset (0x02),
         HCON,   8,
         HCOM,   8,
         TXSA,   8,
         DAT0,   8,
         DAT1,   8,
         HBDR,   8,
         PECR,   8,
         RXSA,   8,
         SDAT,   16

     }

There are also bunch of ASL methods that that the BIOS can use to access these fields. Most of the systems in question ASL methods accessing the SMBI OpRegion are never used.

Now, because of this SMBI OpRegion many systems fail to load the SMBus

driver with an error looking like one below:
ACPI Warning: SystemIO range
0x0000000000003040-0x000000000000305F

      conflicts with OpRegion
      0x0000000000003040-0x000000000000304F
      (\_SB.PCI0.SBUS.SMBI) (20160108/utaddress-255)

ACPI: If an ACPI driver is available for this device, you should use

it instead of the native driver

The reason is that this SMBI OpRegion conflicts with the PCI BAR used by the SMBus driver.

Quoted 7 lines

It turns out that we can install a custom SystemIO address space handler for the SMBus device to intercept all accesses through that OpRegion. This allows us to share the PCI BAR with the ASL code if it for some reason is using it. We do not expect that this OpRegion handler will ever be called but if it is we print a warning and execute the read/write operation under a lock which prevents ASL and OS from messing each other.

This successfully works around:

https://bugzilla.kernel.org/show_bug.cgi?id=110041

but the BIOS people should still fix their ASL. Sigh.

On the Dell laptop, the observable effect is that the driver loads and finds the iTCO thing.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Pali, this may be considerably more useful on your laptop.

Andy, I am right that I will be able to load i2c-i801.ko driver without acpi_enforce_resources=lax parameter?

Yes, and it works on my laptop.

Looks like it is working also on my laptop.

Quoted 14 lines
Quoted 13 lines

If yes, then it sounds good! Finally I would be able to bind lis3lv02d_i2c.ko driver for accelerometer which is on my E6440 machine.

Andy, is there any way to tell i2c-i801.ko driver that on i2c bus (which that driver exports) is present some i2c device? Months ago I got list of Latitude machines on which i2c address is that accelerometer present.

It is possible to hardcode that mapping (DMI name of laptop --> i2c address) into dell-laptop driver, so i2c-i801.ko and lis3lv02d_i2c.ko will be automatically loaded and lis3l binded correctly to i801 i2c address?

Quoted 8 lines
Quoted 6 lines

I don't know how this part works, but I doubt that doing it in dell-laptop will be convenient. After all, dell-laptop can load before i2c-i801.

Jean and Wolfram: is there a quirk mechanism to add i2c devices that aren't directly enumerable but are known to exist due to DMI?

Maybe something like i2c_register_board_info()?

Maybe. i think that wants to be called before the adapter shows up, though.

--Andy
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#16 lore raw
Quoted 100 lines · Andy Lutomirski
Quoted 99 lines · Pali Rohár
Quoted 71 lines · On Friday 29 April 2016 20:10:23 Andy Lutomirski wrote:
Quoted 69 lines · Pali Rohár
Quoted 68 lines · On Thursday 28 April 2016 11:34:38 Andy Lutomirski wrote:
Quoted 48 lines · Mika Westerberg

Many Intel systems the BIOS declares a SystemIO OpRegion below the SMBus

PCI device as can be seen in ACPI DSDT table from Lenovo Yoga 900:
Device (SBUS)
{

     OperationRegion (SMBI, SystemIO, (SBAR << 0x05), 0x10)
     Field (SMBI, ByteAcc, NoLock, Preserve)
     {

         HSTS,   8,
         Offset (0x02),
         HCON,   8,
         HCOM,   8,
         TXSA,   8,
         DAT0,   8,
         DAT1,   8,
         HBDR,   8,
         PECR,   8,
         RXSA,   8,
         SDAT,   16

     }

There are also bunch of ASL methods that that the BIOS can use to access these fields. Most of the systems in question ASL methods accessing the SMBI OpRegion are never used.

Now, because of this SMBI OpRegion many systems fail to load the SMBus

driver with an error looking like one below:
ACPI Warning: SystemIO range
0x0000000000003040-0x000000000000305F

      conflicts with OpRegion
      0x0000000000003040-0x000000000000304F
      (\_SB.PCI0.SBUS.SMBI) (20160108/utaddress-255)

ACPI: If an ACPI driver is available for this device, you should use

it instead of the native driver

The reason is that this SMBI OpRegion conflicts with the PCI BAR used by the SMBus driver.

Quoted 7 lines

It turns out that we can install a custom SystemIO address space handler for the SMBus device to intercept all accesses through that OpRegion. This allows us to share the PCI BAR with the ASL code if it for some reason is using it. We do not expect that this OpRegion handler will ever be called but if it is we print a warning and execute the read/write operation under a lock which prevents ASL and OS from messing each other.

This successfully works around:

https://bugzilla.kernel.org/show_bug.cgi?id=110041

but the BIOS people should still fix their ASL. Sigh.

On the Dell laptop, the observable effect is that the driver loads and finds the iTCO thing.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Pali, this may be considerably more useful on your laptop.

Andy, I am right that I will be able to load i2c-i801.ko driver without acpi_enforce_resources=lax parameter?

Yes, and it works on my laptop.

Looks like it is working also on my laptop.

Quoted 18 lines
Quoted 9 lines

If yes, then it sounds good! Finally I would be able to bind lis3lv02d_i2c.ko driver for accelerometer which is on my E6440 machine.

Andy, is there any way to tell i2c-i801.ko driver that on i2c bus (which that driver exports) is present some i2c device? Months ago I got list of Latitude machines on which i2c address is that accelerometer present.

Quoted 4 lines

It is possible to hardcode that mapping (DMI name of laptop --> i2c address) into dell-laptop driver, so i2c-i801.ko and lis3lv02d_i2c.ko will be automatically loaded and lis3l binded correctly to i801 i2c address?

I don't know how this part works, but I doubt that doing it in dell-laptop will be convenient. After all, dell-laptop can load before i2c-i801.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Jean and Wolfram: is there a quirk mechanism to add i2c devices that aren't directly enumerable but are known to exist due to DMI?

Maybe something like i2c_register_board_info()?

Maybe. i think that wants to be called before the adapter shows up, though.

i2c_probe_optional_slaves may be a more appropriate place to put this.

Also, is there any indication in your DSDT that this thing exists?

--Andy
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
In reply to Mika Westerberg
Quoted 46 lines · Mika Westerberg
Quoted 45 lines · Andy Lutomirski
Quoted 43 lines · Mika Westerberg

Many Intel systems the BIOS declares a SystemIO OpRegion below the SMBus PCI device as can be seen in ACPI DSDT table from Lenovo Yoga 900:

Device (SBUS)

 {
     OperationRegion (SMBI, SystemIO, (SBAR << 0x05), 0x10)
     Field (SMBI, ByteAcc, NoLock, Preserve)
     {
         HSTS,   8,
         Offset (0x02),
         HCON,   8,
         HCOM,   8,
         TXSA,   8,
         DAT0,   8,
         DAT1,   8,
         HBDR,   8,
         PECR,   8,
         RXSA,   8,
         SDAT,   16
     }

There are also bunch of ASL methods that that the BIOS can use to access these fields. Most of the systems in question ASL methods accessing the SMBI OpRegion are never used.

Now, because of this SMBI OpRegion many systems fail to load the SMBus driver with an error looking like one below:

ACPI Warning: SystemIO range 0x0000000000003040-0x000000000000305F

      conflicts with OpRegion 0x0000000000003040-0x000000000000304F
      (\_SB.PCI0.SBUS.SMBI) (20160108/utaddress-255)

ACPI: If an ACPI driver is available for this device, you should use
it instead of the native driver

The reason is that this SMBI OpRegion conflicts with the PCI BAR used by the SMBus driver.

It turns out that we can install a custom SystemIO address space handler for the SMBus device to intercept all accesses through that OpRegion. This allows us to share the PCI BAR with the ASL code if it for some reason is using it. We do not expect that this OpRegion handler will ever be called but if it is we print a warning and execute the read/write operation under a lock which prevents ASL and OS from messing each other.

Quoted 3 lines
Quoted 1 line

Thanks for testing!

A question, though: there's nothing that keeps i801_access from being called in between consecutive ACPI accesses. Could this confuse the ASL code? Would it be helpful if i801_access were to save away the old register state and restore it when it's done in the event that an opregion access has been seen so that the ASL-configured state doesn't get stomped on?

Also, what happens if i801_access happens while the i801 master is busy with an ASL-initiated transaction? Will it wait for the transaction to finish?

If this is a problem, an alternative approach might be to virtualize the registers as seen by ACPI and to only load them into the real registers when a transaction starts.

Also, what happens if the opregion is declared globally instead of in the scope of the ACPI companion? Does that happen? If so, it might make sense to deny loading the driver unless in lax mode.

--Andy

#17 lore raw
In reply to Andy Lutomirski
Quoted 114 lines · On Saturday 30 April 2016 02:56:14 Andy Lutomirski wrote:
Quoted 112 lines · Andy Lutomirski
Quoted 109 lines · Pali Rohár
Quoted 76 lines · On Friday 29 April 2016 20:10:23 Andy Lutomirski wrote:

On Fri, Apr 29, 2016 at 2:03 AM, Pali Rohár
<[email protected]>

Quoted 72 lines · wrote:
Quoted 71 lines · On Thursday 28 April 2016 11:34:38 Andy Lutomirski wrote:
Quoted 49 lines · Mika Westerberg

Many Intel systems the BIOS declares a SystemIO OpRegion below the SMBus

PCI device as can be seen in ACPI DSDT table from Lenovo Yoga 900:
Device (SBUS)
{

     OperationRegion (SMBI, SystemIO, (SBAR << 0x05), 0x10)
     Field (SMBI, ByteAcc, NoLock, Preserve)
     {
     
         HSTS,   8,
         Offset (0x02),
         HCON,   8,
         HCOM,   8,
         TXSA,   8,
         DAT0,   8,
         DAT1,   8,
         HBDR,   8,
         PECR,   8,
         RXSA,   8,
         SDAT,   16
     
     }

There are also bunch of ASL methods that that the BIOS can use to access these fields. Most of the systems in question ASL methods accessing the SMBI OpRegion are never used.

Now, because of this SMBI OpRegion many systems fail to load the SMBus

driver with an error looking like one below:
ACPI Warning: SystemIO range
0x0000000000003040-0x000000000000305F

      conflicts with OpRegion
      0x0000000000003040-0x000000000000304F
      (\_SB.PCI0.SBUS.SMBI) (20160108/utaddress-255)

ACPI: If an ACPI driver is available for this device, you should use

it instead of the native driver

The reason is that this SMBI OpRegion conflicts with the PCI BAR used by the SMBus driver.

Quoted 8 lines

It turns out that we can install a custom SystemIO address space handler for the SMBus device to intercept all accesses through that OpRegion. This allows us to share the PCI BAR with the ASL code if it for some reason is using it. We do not expect that this OpRegion handler will ever be called but if it is we print a warning and execute the read/write operation under a lock which prevents ASL and OS from messing each other.

9350

This successfully works around:

https://bugzilla.kernel.org/show_bug.cgi?id=110041

but the BIOS people should still fix their ASL. Sigh.

On the Dell laptop, the observable effect is that the driver loads and finds the iTCO thing.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Pali, this may be considerably more useful on your laptop.

Andy, I am right that I will be able to load i2c-i801.ko driver without acpi_enforce_resources=lax parameter?

Yes, and it works on my laptop.

Looks like it is working also on my laptop.

Quoted 14 lines
Quoted 9 lines

If yes, then it sounds good! Finally I would be able to bind lis3lv02d_i2c.ko driver for accelerometer which is on my E6440 machine.

Andy, is there any way to tell i2c-i801.ko driver that on i2c bus (which that driver exports) is present some i2c device? Months ago I got list of Latitude machines on which i2c address is that accelerometer present.

Quoted 4 lines

It is possible to hardcode that mapping (DMI name of laptop --> i2c address) into dell-laptop driver, so i2c-i801.ko and lis3lv02d_i2c.ko will be automatically loaded and lis3l binded correctly to i801 i2c address?

Quoted 7 lines

I don't know how this part works, but I doubt that doing it in dell-laptop will be convenient. After all, dell-laptop can load before i2c-i801.

Jean and Wolfram: is there a quirk mechanism to add i2c devices that aren't directly enumerable but are known to exist due to DMI?

Maybe something like i2c_register_board_info()?

Quoted 7 lines
Quoted 2 lines

Maybe. i think that wants to be called before the adapter shows up, though.

i2c_probe_optional_slaves may be a more appropriate place to put this.

Also, is there any indication in your DSDT that this thing exists?

No :-( There is nothing which can tell us presence of accelerometer. Dell people told me that on Latitude machines E6540, E6440, E6440 ATG, E5250, E5450 and E5550 is accelerometer present on 0x29 address. So there is no other way than hardcode those DMI strings and do manual configuration...

Maybe it should go into dell-smo8800.ko driver. That one is ACPI and from DSDT provides IRQ number (issued when laptop. fall)...

So maybe, we can guess, when SMO ACPI device is present there is accelerometer on i2c bus, but we do not know exact address...

Signature · 2 lines
Pali Rohár
[email protected]
#4 lore raw
In reply to Andy Lutomirski
Quoted 6 lines · Andy Lutomirski

A question, though: there's nothing that keeps i801_access from being called in between consecutive ACPI accesses. Could this confuse the ASL code? Would it be helpful if i801_access were to save away the old register state and restore it when it's done in the event that an opregion access has been seen so that the ASL-configured state doesn't get stomped on?

Looking at those ASL methods of Lenovo Yoga 900 for example they seem to initialize the hardware, do the transaction and cleanup in one go. That's also what the i2c-i801.c driver is doing as far as I can say. So in that sense they should not mess with each other.

Of course this all breaks if the ASL code expects the state to survive between transactions.

Quoted 3 lines

Also, what happens if i801_access happens while the i801 master is busy with an ASL-initiated transaction? Will it wait for the transaction to finish?

Yes, it should since ->acpi_lock is taken by i801_acpi_io_handler().

Quoted 7 lines

If this is a problem, an alternative approach might be to virtualize the registers as seen by ACPI and to only load them into the real registers when a transaction starts.

Also, what happens if the opregion is declared globally instead of in the scope of the ACPI companion? Does that happen? If so, it might make sense to deny loading the driver unless in lax mode.

I don't know if that happens but it is certainly possible.

Actually reading ACPI 6.1 spec again, chapter 5.5.2.4.3 says this:

If a platform uses a PCI BAR Target operation region, an ACPI OS will not load a native device driver for the associated PCI function. For example, if any of the BARs in a PCI function are associated with a PCI BAR Target operation region, then the OS will assume that the PCI function is to be entirely under the control of the ACPI system firmware. No driver will be loaded.

So what we are currently doing (preventing the driver from loading) is the right thing to do according the above. Maybe we can change that warning into debug/info message instead?

#23 lore raw
In reply to Rafael J. Wysocki
Quoted 46 lines · Rafael J. Wysocki
Quoted 44 lines · Mika Westerberg

Many Intel systems the BIOS declares a SystemIO OpRegion below the SMBus PCI device as can be seen in ACPI DSDT table from Lenovo Yoga 900:

  Device (SBUS)
  {
      OperationRegion (SMBI, SystemIO, (SBAR << 0x05), 0x10)
      Field (SMBI, ByteAcc, NoLock, Preserve)
      {
          HSTS,   8,
          Offset (0x02),
          HCON,   8,
          HCOM,   8,
          TXSA,   8,
          DAT0,   8,
          DAT1,   8,
          HBDR,   8,
          PECR,   8,
          RXSA,   8,
          SDAT,   16
      }

There are also bunch of ASL methods that that the BIOS can use to access these fields. Most of the systems in question ASL methods accessing the SMBI OpRegion are never used.

Now, because of this SMBI OpRegion many systems fail to load the SMBus driver with an error looking like one below:

ACPI Warning: SystemIO range 0x0000000000003040-0x000000000000305F

       conflicts with OpRegion 0x0000000000003040-0x000000000000304F
       (\_SB.PCI0.SBUS.SMBI) (20160108/utaddress-255)

ACPI: If an ACPI driver is available for this device, you should use
it instead of the native driver

The reason is that this SMBI OpRegion conflicts with the PCI BAR used by the SMBus driver.

It turns out that we can install a custom SystemIO address space handler for the SMBus device to intercept all accesses through that OpRegion. This allows us to share the PCI BAR with the ASL code if it for some reason is using it. We do not expect that this OpRegion handler will ever be called but if it is we print a warning and execute the read/write operation under a lock which prevents ASL and OS from messing each other.

Quoted 4 lines
Quoted 2 lines

Thanks!

Quoted 2 lines

If it addresses any public BZ bugs, it would be good to add Link: tags for those and maybe Reported-by: for the reporters?

Good point. I can add those.

However, after reading ACPI 6.1 spec again, I'm having second thoughts about this patch. See my other email to Andy on this thread.

#5 lore raw
In reply to Mika Westerberg
Quoted 41 lines · Mika Westerberg
Quoted 6 lines · Andy Lutomirski

A question, though: there's nothing that keeps i801_access from being called in between consecutive ACPI accesses. Could this confuse the ASL code? Would it be helpful if i801_access were to save away the old register state and restore it when it's done in the event that an opregion access has been seen so that the ASL-configured state doesn't get stomped on?

Looking at those ASL methods of Lenovo Yoga 900 for example they seem to initialize the hardware, do the transaction and cleanup in one go. That's also what the i2c-i801.c driver is doing as far as I can say. So in that sense they should not mess with each other.

Of course this all breaks if the ASL code expects the state to survive between transactions.

Quoted 3 lines

Also, what happens if i801_access happens while the i801 master is busy with an ASL-initiated transaction? Will it wait for the transaction to finish?

Yes, it should since ->acpi_lock is taken by i801_acpi_io_handler().

Quoted 7 lines

If this is a problem, an alternative approach might be to virtualize the registers as seen by ACPI and to only load them into the real registers when a transaction starts.

Also, what happens if the opregion is declared globally instead of in the scope of the ACPI companion? Does that happen? If so, it might make sense to deny loading the driver unless in lax mode.

I don't know if that happens but it is certainly possible.

Actually reading ACPI 6.1 spec again, chapter 5.5.2.4.3 says this:

If a platform uses a PCI BAR Target operation region, an ACPI OS will not load a native device driver for the associated PCI function. For example, if any of the BARs in a PCI function are associated with a PCI BAR Target operation region, then the OS will assume that the PCI function is to be entirely under the control of the ACPI system firmware. No driver will be loaded.

Quoted 2 lines

So what we are currently doing (preventing the driver from loading) is the right thing to do according the above.

In general, that is the right thing to do. That's why we do it as a rule. :-)

However, in this particular case we actually know that the opregion declaration is bogus at least on some systems. So, this is a workaround for a known defect in some systems' ACPI tables.

Quoted 1 line

Maybe we can change that warning into debug/info message instead?

I wouldn't do that if it affected other cases in which opregion declarations were actually correct.

#6 lore raw
Quoted 8 lines · Rafael J. Wysocki
Quoted 2 lines

So what we are currently doing (preventing the driver from loading) is the right thing to do according the above.

In general, that is the right thing to do. That's why we do it as a rule. :-)

However, in this particular case we actually know that the opregion declaration is bogus at least on some systems. So, this is a workaround for a known defect in some systems' ACPI tables.

Fair enough :)

#7 lore raw
In reply to Mika Westerberg
Quoted 8 lines · Mika Westerberg
Quoted 6 lines · Andy Lutomirski

A question, though: there's nothing that keeps i801_access from being called in between consecutive ACPI accesses. Could this confuse the ASL code? Would it be helpful if i801_access were to save away the old register state and restore it when it's done in the event that an opregion access has been seen so that the ASL-configured state doesn't get stomped on?

Quoted 5 lines

Looking at those ASL methods of Lenovo Yoga 900 for example they seem to initialize the hardware, do the transaction and cleanup in one go. That's also what the i2c-i801.c driver is doing as far as I can say. So in that sense they should not mess with each other.

Is your locking actually sufficient to get that right? You're taking acpi_lock, which is private to the driver, so you're only holding it during actual opregion access AFAICT. That means that, if one thread is in the ACPI interpreter in one of these blocks and another thread is in the driver, they could still interleave their accesses. Am I missing something?

Quoted 8 lines

Of course this all breaks if the ASL code expects the state to survive between transactions.

Quoted 3 lines

Also, what happens if i801_access happens while the i801 master is busy with an ASL-initiated transaction? Will it wait for the transaction to finish?

Yes, it should since ->acpi_lock is taken by i801_acpi_io_handler().

But i801_acpi_io_handler has no concept of a transaction AFAICT.

Quoted 20 lines
Quoted 8 lines

If this is a problem, an alternative approach might be to virtualize the registers as seen by ACPI and to only load them into the real registers when a transaction starts.

Also, what happens if the opregion is declared globally instead of in the scope of the ACPI companion? Does that happen? If so, it might make sense to deny loading the driver unless in lax mode.

I don't know if that happens but it is certainly possible.

Actually reading ACPI 6.1 spec again, chapter 5.5.2.4.3 says this:

If a platform uses a PCI BAR Target operation region, an ACPI OS will not load a native device driver for the associated PCI function. For example, if any of the BARs in a PCI function are associated with a PCI BAR Target operation region, then the OS will assume that the PCI function is to be entirely under the control of the ACPI system firmware. No driver will be loaded.

Quoted 3 lines

So what we are currently doing (preventing the driver from loading) is the right thing to do according the above. Maybe we can change that warning into debug/info message instead?

Is there a way to ask the ACPI core to tell you the scope of the conflict? This is more a question for Rafael and the ACPI folks: this patch installs an io handler for a region in the scope of the ACPI companion of the device, but what if the ASL code does IO using an opregion declared outside the scope of the device? Or is the opregion handler for memory actually global?

Given that this seems to be purely hypothetical, this may not be a big deal.

--Andy

#8 lore raw
Quoted 16 lines · Andy Lutomirski
Quoted 8 lines · Mika Westerberg
Quoted 6 lines · Andy Lutomirski

A question, though: there's nothing that keeps i801_access from being called in between consecutive ACPI accesses. Could this confuse the ASL code? Would it be helpful if i801_access were to save away the old register state and restore it when it's done in the event that an opregion access has been seen so that the ASL-configured state doesn't get stomped on?

Quoted 5 lines

Looking at those ASL methods of Lenovo Yoga 900 for example they seem to initialize the hardware, do the transaction and cleanup in one go. That's also what the i2c-i801.c driver is doing as far as I can say. So in that sense they should not mess with each other.

Quoted 6 lines

Is your locking actually sufficient to get that right? You're taking acpi_lock, which is private to the driver, so you're only holding it during actual opregion access AFAICT. That means that, if one thread is in the ACPI interpreter in one of these blocks and another thread is in the driver, they could still interleave their accesses. Am I missing something?

No, you are right.

Quoted 10 lines
Quoted 8 lines

Of course this all breaks if the ASL code expects the state to survive between transactions.

Quoted 3 lines

Also, what happens if i801_access happens while the i801 master is busy with an ASL-initiated transaction? Will it wait for the transaction to finish?

Yes, it should since ->acpi_lock is taken by i801_acpi_io_handler().

But i801_acpi_io_handler has no concept of a transaction AFAICT.

Indeed it only handles access one-by-one not by transaction. So if the ASL code is in middle of a transaction and i2c-i801.c starts one as well it will mess the registers.

Back to drawing board :-/

#9 lore raw
Quoted 35 lines · Mika Westerberg
Quoted 16 lines · Andy Lutomirski
Quoted 8 lines · Mika Westerberg
Quoted 6 lines · Andy Lutomirski

A question, though: there's nothing that keeps i801_access from being called in between consecutive ACPI accesses. Could this confuse the ASL code? Would it be helpful if i801_access were to save away the old register state and restore it when it's done in the event that an opregion access has been seen so that the ASL-configured state doesn't get stomped on?

Quoted 5 lines

Looking at those ASL methods of Lenovo Yoga 900 for example they seem to initialize the hardware, do the transaction and cleanup in one go. That's also what the i2c-i801.c driver is doing as far as I can say. So in that sense they should not mess with each other.

Quoted 6 lines

Is your locking actually sufficient to get that right? You're taking acpi_lock, which is private to the driver, so you're only holding it during actual opregion access AFAICT. That means that, if one thread is in the ACPI interpreter in one of these blocks and another thread is in the driver, they could still interleave their accesses. Am I missing something?

No, you are right.

Quoted 9 lines
Quoted 8 lines

Of course this all breaks if the ASL code expects the state to survive between transactions.

Quoted 3 lines

Also, what happens if i801_access happens while the i801 master is busy with an ASL-initiated transaction? Will it wait for the transaction to finish?

Yes, it should since ->acpi_lock is taken by i801_acpi_io_handler().

Quoted 7 lines
Quoted 1 line

But i801_acpi_io_handler has no concept of a transaction AFAICT.

Indeed it only handles access one-by-one not by transaction. So if the ASL code is in middle of a transaction and i2c-i801.c starts one as well it will mess the registers.

Back to drawing board :-/

:-/

I can try to test using the ACPI debugger maybe, but my laptop with this problem doesn't have any calls to the offending ASL at all, so just booting it won't exercise any of the interesting cases at all.

Signature · 2 lines
Andy Lutomirski
AMA Capital Management, LLC
#10 lore raw
In reply to Mika Westerberg
Quoted 35 lines · Mika Westerberg
Quoted 16 lines · Andy Lutomirski
Quoted 8 lines · Mika Westerberg
Quoted 6 lines · Andy Lutomirski

A question, though: there's nothing that keeps i801_access from being called in between consecutive ACPI accesses. Could this confuse the ASL code? Would it be helpful if i801_access were to save away the old register state and restore it when it's done in the event that an opregion access has been seen so that the ASL-configured state doesn't get stomped on?

Quoted 5 lines

Looking at those ASL methods of Lenovo Yoga 900 for example they seem to initialize the hardware, do the transaction and cleanup in one go. That's also what the i2c-i801.c driver is doing as far as I can say. So in that sense they should not mess with each other.

Quoted 6 lines

Is your locking actually sufficient to get that right? You're taking acpi_lock, which is private to the driver, so you're only holding it during actual opregion access AFAICT. That means that, if one thread is in the ACPI interpreter in one of these blocks and another thread is in the driver, they could still interleave their accesses. Am I missing something?

No, you are right.

Quoted 9 lines
Quoted 8 lines

Of course this all breaks if the ASL code expects the state to survive between transactions.

Quoted 3 lines

Also, what happens if i801_access happens while the i801 master is busy with an ASL-initiated transaction? Will it wait for the transaction to finish?

Yes, it should since ->acpi_lock is taken by i801_acpi_io_handler().

Quoted 7 lines
Quoted 1 line

But i801_acpi_io_handler has no concept of a transaction AFAICT.

Indeed it only handles access one-by-one not by transaction. So if the ASL code is in middle of a transaction and i2c-i801.c starts one as well it will mess the registers.

Back to drawing board :-/

It doesn't look like trying to make it safe for both the driver and AML to use the same range of addresses is a realistic goal. At least the benefit will not outweigh the resulting complexity if the opregion is actually never used by AML in practice.

So, why don't we have a flag that will make i801_access() return an error on every invocation when set (the callers of it should be able to cope with that or they are broken IMO) and why don't we set it when AML accesses the opregion first time?

Yes, that will prevent the driver from actually working *when* AML turns out to use the opregion, but IMO that's a bit more friendly than preventing the driver from loading at all.

#11 lore raw
Quoted 9 lines · Rafael J. Wysocki

It doesn't look like trying to make it safe for both the driver and AML to use the same range of addresses is a realistic goal. At least the benefit will not outweigh the resulting complexity if the opregion is actually never used by AML in practice.

So, why don't we have a flag that will make i801_access() return an error on every invocation when set (the callers of it should be able to cope with that or they are broken IMO) and why don't we set it when AML accesses the opregion first time?

Yeah, that occured to me also yesterday evening :)

Quoted 3 lines

Yes, that will prevent the driver from actually working *when* AML turns out to use the opregion, but IMO that's a bit more friendly than preventing the driver from loading at all.

I agree. If nobody objects, I'm going to create v2 of the patch that prevents further driver access if AML touches the OpRegion.

#18 lore raw
In reply to Andy Lutomirski
Quoted 11 lines · On Friday 29 April 2016 17:56:14 Andy Lutomirski wrote:
Quoted 8 lines · Andy Lutomirski
Quoted 5 lines · Pali Rohár
Quoted 2 lines · On Friday 29 April 2016 20:10:23 Andy Lutomirski wrote:

Jean and Wolfram: is there a quirk mechanism to add i2c devices that aren't directly enumerable but are known to exist due to DMI?

Maybe something like i2c_register_board_info()?

Maybe. i think that wants to be called before the adapter shows up, though.

i2c_probe_optional_slaves may be a more appropriate place to put this.

I cannot find function i2c_probe_optional_slaves. Where is it?

Signature · 2 lines
Pali Rohár
[email protected]
#20 lore raw
In reply to a message not in the archive
Quoted 20 lines · On Friday 06 May 2016 21:00:25 Andy Lutomirski wrote:
Quoted 3 lines · Pali Rohár
Quoted 2 lines · On Friday 29 April 2016 17:56:14 Andy Lutomirski wrote:

On Fri, Apr 29, 2016 at 2:42 PM, Andy Lutomirski
<[email protected]>

Quoted 2 lines · wrote:
Quoted 2 lines
Quoted 2 lines

On Fri, Apr 29, 2016 at 2:00 PM, Pali Rohár
<[email protected]>

Quoted 9 lines · wrote:
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines · On Friday 29 April 2016 20:10:23 Andy Lutomirski wrote:
Quoted 3 lines

Jean and Wolfram: is there a quirk mechanism to add i2c devices that aren't directly enumerable but are known to exist due to DMI?

Maybe something like i2c_register_board_info()?

Maybe. i think that wants to be called before the adapter shows up,

Quoted 8 lines

though.

Quoted 4 lines
Quoted 2 lines

i2c_probe_optional_slaves may be a more appropriate place to put this.

I cannot find function i2c_probe_optional_slaves. Where is it?

Sorry, I meant i801_probe_optional_slaves.

Hm... that could probably work. I will look at dell-smo8800.c and lis3lv02d_i2c.c and i2c-i801.c how to interconnect all those devices...

Signature · 2 lines
Pali Rohár
[email protected]
#21 lore raw
In reply to Andy Lutomirski

Hi Andy, Pali,

Quoted 11 lines · Andy Lutomirski
Quoted 8 lines · Andy Lutomirski
Quoted 5 lines · Pali Rohár
Quoted 2 lines · On Friday 29 April 2016 20:10:23 Andy Lutomirski wrote:

Jean and Wolfram: is there a quirk mechanism to add i2c devices that aren't directly enumerable but are known to exist due to DMI?

Maybe something like i2c_register_board_info()?

Maybe. i think that wants to be called before the adapter shows up, though.

i2c_probe_optional_slaves may be a more appropriate place to put this.

I can't find any function by that name in the vanilla kernel.

Someone wrote Documentation/i2c/instantiating-devices to explain the different options to declare an I2C slave device on the system.

In this specific case I suspect option #2 is appropriate, using i2c_new_probed_device() (or even i2c_new_device() if you are 100% certain.)

Signature · 2 lines
Jean Delvare
SUSE L3 Support