Skip to contentSkip to conversation

Add Intel Input Output Manager driver

PATCH Superseded Rajmohan Mani 2 participants 10 messages Jul 16, 2020 – Jul 24, 2020

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add Intel Input Output Manager driver

Hi,

This patch series add support for Intel Input Output Manager (IOM) driver, which is leveraged by the Intel PMC USB mux control driver.

This patch series has a dependency on the following 4 patches, that are in Greg's usb-next branch.
https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git/tree/?h=usb-next

ffe82945d8eb usb: typec: intel_pmc_mux: Add support for USB4 cab9219d2af4 usb: typec: intel_pmc_mux: Definitions for response status bits 1a1be50b5ebd usb: typec: Add data structure for Enter_USB message 6701911bb1c1 usb: typec: Combine the definitions for Accessory and USB modes

Heikki Krogerus (1):
usb: typec: intel_pmc_mux: Check the port status before connect

Rajmohan Mani (1):
platform/x86: Add Intel Input Output Manager (IOM) driver

 drivers/platform/x86/Kconfig                |  16 +++
 drivers/platform/x86/Makefile               |   1 +
 drivers/platform/x86/intel_iom.c            | 133 ++++++++++++++++++++
 drivers/usb/typec/mux/Kconfig               |   1 +
 drivers/usb/typec/mux/intel_pmc_mux.c       |  73 +++++++++--
 include/linux/platform_data/x86/intel_iom.h |  62 +++++++++
 6 files changed, 276 insertions(+), 10 deletions(-)
 create mode 100644 drivers/platform/x86/intel_iom.c
 create mode 100644 include/linux/platform_data/x86/intel_iom.h
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/2 platform/x86: Add Intel Input Output Manager (IOM) driver

Input Output Manager (IOM) is part of the Tiger Lake SoC that configures the Type-C Sub System (TCSS). IOM is a micro controller that handles Type-C topology, configuration and PM functions of various Type-C devices connected on the platform.

This driver helps read relevant information such as Type-C port status (whether a device is connected to a Type-C port or not) and the activity type on the Type-C ports (such as USB, Display Port, Thunderbolt), for consumption by other drivers.

Currently intel_iom_port_status() API is exported by this driver, that has information about the Type-C port status and port activity type.

---
 drivers/platform/x86/Kconfig                |  16 +++
 drivers/platform/x86/Makefile               |   1 +
 drivers/platform/x86/intel_iom.c            | 133 ++++++++++++++++++++
 include/linux/platform_data/x86/intel_iom.h |  62 +++++++++
 4 files changed, 212 insertions(+)
 create mode 100644 drivers/platform/x86/intel_iom.c
 create mode 100644 include/linux/platform_data/x86/intel_iom.h
drivers/platform/x86/Kconfig +16 -0
index 0581a54cf562..271feddb20ef 100644
@@ -816,6 +816,22 @@ config INTEL_INT0002_VGPIO
 	  To compile this driver as a module, choose M here: the module will
 	  be called intel_int0002_vgpio.
 
+config INTEL_IOM
+	tristate "Intel Input Output Manager (IOM) driver"
+	depends on ACPI && PCI
+	help
+	  This driver helps read relevant information such as Type-C port
+	  status (whether a device is connected to a Type-C port or not)
+	  and the activity type on the Type-C ports (such as USB, Display
+	  Port, Thunderbolt), for consumption by other drivers.
+
+	  Currently intel_iom_port_status() API is exported by this driver,
+	  that has information about the Type-C port status and port activity
+	  type.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called intel_iom.
+
 config INTEL_MENLOW
 	tristate "Thermal Management driver for Intel menlow platform"
 	depends on ACPI_THERMAL
drivers/platform/x86/Makefile +1 -0
index 2b85852a1a87..d71e4620a7c6 100644
@@ -76,6 +76,7 @@ intel_cht_int33fe-objs			:= intel_cht_int33fe_common.o \
 					   intel_cht_int33fe_microb.o
 obj-$(CONFIG_INTEL_HID_EVENT)		+= intel-hid.o
 obj-$(CONFIG_INTEL_INT0002_VGPIO)	+= intel_int0002_vgpio.o
+obj-$(CONFIG_INTEL_IOM)			+= intel_iom.o
 obj-$(CONFIG_INTEL_MENLOW)		+= intel_menlow.o
 obj-$(CONFIG_INTEL_OAKTRAIL)		+= intel_oaktrail.o
 obj-$(CONFIG_INTEL_VBTN)		+= intel-vbtn.o
drivers/platform/x86/intel_iom.c new file +133 -0

133 lines not on this page · raw message

include/linux/platform_data/x86/intel_iom.h new file +62 -0

62 lines not on this page · raw message

Signature · 1 line
2.20.1
#2 lore raw

Re: [PATCH 1/2] platform/x86: Add Intel Input Output Manager (IOM) driver

Quoted 14 lines · Rajmohan Mani

Input Output Manager (IOM) is part of the Tiger Lake SoC that configures the Type-C Sub System (TCSS). IOM is a micro controller that handles Type-C topology, configuration and PM functions of various Type-C devices connected on the platform.

This driver helps read relevant information such as Type-C port status (whether a device is connected to a Type-C port or not) and the activity type on the Type-C ports (such as USB, Display Port, Thunderbolt), for consumption by other drivers.

Currently intel_iom_port_status() API is exported by this driver, that has information about the Type-C port status and port activity type.

Quoted 6 lines
---
 drivers/platform/x86/Kconfig                |  16 +++
 drivers/platform/x86/Makefile               |   1 +
 drivers/platform/x86/intel_iom.c            | 133 ++++++++++++++++++++
 include/linux/platform_data/x86/intel_iom.h |  62 +++++++++

Why do you need a .h file for a single .c file that no one else shares this data? Just put it all in the .c file please.

Quoted 67 lines
 4 files changed, 212 insertions(+)
 create mode 100644 drivers/platform/x86/intel_iom.c
 create mode 100644 include/linux/platform_data/x86/intel_iom.h
drivers/platform/x86/Kconfig +16 -0
index 0581a54cf562..271feddb20ef 100644
@@ -816,6 +816,22 @@ config INTEL_INT0002_VGPIO
 	  To compile this driver as a module, choose M here: the module will
 	  be called intel_int0002_vgpio.
 
+config INTEL_IOM
+	tristate "Intel Input Output Manager (IOM) driver"
+	depends on ACPI && PCI
+	help
+	  This driver helps read relevant information such as Type-C port
+	  status (whether a device is connected to a Type-C port or not)
+	  and the activity type on the Type-C ports (such as USB, Display
+	  Port, Thunderbolt), for consumption by other drivers.
+
+	  Currently intel_iom_port_status() API is exported by this driver,
+	  that has information about the Type-C port status and port activity
+	  type.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called intel_iom.
+
 config INTEL_MENLOW
 	tristate "Thermal Management driver for Intel menlow platform"
 	depends on ACPI_THERMAL
drivers/platform/x86/Makefile +1 -0
index 2b85852a1a87..d71e4620a7c6 100644
@@ -76,6 +76,7 @@ intel_cht_int33fe-objs			:= intel_cht_int33fe_common.o \
 					   intel_cht_int33fe_microb.o
 obj-$(CONFIG_INTEL_HID_EVENT)		+= intel-hid.o
 obj-$(CONFIG_INTEL_INT0002_VGPIO)	+= intel_int0002_vgpio.o
+obj-$(CONFIG_INTEL_IOM)			+= intel_iom.o
 obj-$(CONFIG_INTEL_MENLOW)		+= intel_menlow.o
 obj-$(CONFIG_INTEL_OAKTRAIL)		+= intel_oaktrail.o
 obj-$(CONFIG_INTEL_VBTN)		+= intel-vbtn.o
drivers/platform/x86/intel_iom.c new file +18 -0
new file mode 100644
index 000000000000..ece0fe720b2d
@@ -0,0 +1,133 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Intel Core SoC Input Output Manager (IOM) driver.
+ *
+ * This driver provides access to the Input Output Manager (IOM) (that
+ * is part of Tiger Lake SoC) registers that can be used to know about
+ * Type-C Sub System related information (such as Type-C port status,
+ * activity type on Type-C ports).
+ *
+ * Copyright (C) 2020, Intel Corporation
+ * Author: Rajmohan Mani <[email protected]>
+ */
+
+#include <linux/io.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/platform_data/x86/intel_iom.h>
+#include <linux/platform_device.h>

drivers/platform/x86/intel_iom.c line 28

Quoted 10 lines
drivers/platform/x86/intel_iom.c new file +10 -0
+#include <linux/slab.h>
+
+#define IOM_PORT_STATUS_OFFSET				0x560
+
+struct intel_iom {
+	struct device *dev;
+	void __iomem *regbar;
+};
+
+static struct intel_iom iom_dev;

Why just one? Why is this static?

Quoted 4 lines
drivers/platform/x86/intel_iom.c new file +4 -0
+
+/**
+ * intel_iom_get() - Get IOM device instance
+ *

drivers/platform/x86/intel_iom.c line 42

Quoted 10 lines
drivers/platform/x86/intel_iom.c new file +10 -0
+ * This function returns the IOM device instance. This also ensures that
+ * this driver cannot be unloaded while the caller has the instance.
+ *
+ * Call intel_iom_put() to release the instance.
+ *
+ * Returns IOM device instance on success or error pointer otherwise.
+ */
+struct intel_iom *intel_iom_get(void)
+{
+	struct device *dev = get_device(iom_dev.dev);

Wht if dev is NULL?

drivers/platform/x86/intel_iom.c line 45

Quoted 3 lines
drivers/platform/x86/intel_iom.c new file +3 -0
+
+	/* Prevent this driver from being unloaded while in use */
+	if (!try_module_get(dev->driver->owner)) {

Why are you poking around in a random device's driver's owner?

That's not ok. And probably totally racy.

Handle module reference counts properly, not like this.

And why does it even matter that you incremented the module reference count? What is that "protecting" you from?

drivers/platform/x86/intel_iom.c line 52

Quoted 7 lines
drivers/platform/x86/intel_iom.c new file +7 -0
+		put_device(iom_dev.dev);
+		return ERR_PTR(-EBUSY);
+	}
+
+	return &iom_dev;
+}
+EXPORT_SYMBOL_GPL(intel_iom_get);

Who calls this function?

Quoted 6 lines
drivers/platform/x86/intel_iom.c new file +6 -0
+
+/**
+ * intel_iom_put() - Put IOM device instance
+ * @iom: IOM device instance
+ *
+ * This function releases the IOM device instance created using

drivers/platform/x86/intel_iom.c line 68

Quoted 10 lines
drivers/platform/x86/intel_iom.c new file +10 -0
+ * intel_iom_get() and allows the driver to be unloaded.
+ *
+ * Call intel_iom_put() to release the instance.
+ */
+void intel_iom_put(struct intel_iom *iom)
+{
+	if (!iom)
+		return;
+
+	module_put(iom->dev->driver->owner);

And if the device doesn't have a driver? boom :(

Don't do this.

Quoted 19 lines
drivers/platform/x86/intel_iom.c new file +19 -0
+	put_device(iom->dev);
+}
+EXPORT_SYMBOL_GPL(intel_iom_put);
+
+/**
+ * intel_iom_port_status() - Get status bits for the Type-C port
+ * @iom: IOM device instance
+ * @port: Type-C port number
+ * @status: pointer to receive the status bits
+ *
+ * Returns 0 on success, error otherwise.
+ */
+int intel_iom_port_status(struct intel_iom *iom, u8 port, u32 *status)
+{
+	void __iomem *reg;
+
+	if (!iom)
+		return -ENODEV;
+

drivers/platform/x86/intel_iom.c line 97

Quoted 10 lines
drivers/platform/x86/intel_iom.c new file +10 -0
+	if (!status || (port > IOM_MAX_PORTS - 1))
+		return -EINVAL;
+
+	reg = iom->regbar + IOM_PORT_STATUS_OFFSET + IOM_REG_LEN * port;
+
+	*status = ioread32(reg);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(intel_iom_port_status);

So the whole driver is here just to read, directly from memory, a single 32 bit value? Doesn't that seem like a lot of overkill? Why can't the caller just do this themselves?

greg k-h

#3 lore raw

RE: [PATCH 1/2] platform/x86: Add Intel Input Output Manager (IOM) driver

Hi Greg,

Thanks for the reviews.

Quoted 39 lines

-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Thursday, July 16, 2020 12:10 AM
To: Mani, Rajmohan <[email protected]>
Cc: Darren Hart <[email protected]>; Andy Shevchenko <[email protected]>; Mika Westerberg <[email protected]>; Dmitry Torokhov <[email protected]>; Lee Jones <[email protected]>; Ayman Bagabas <[email protected]>; Masahiro Yamada <[email protected]>; Joseph, Jithu <[email protected]>; Blaž Hrastnik <[email protected]>; Srinivas Pandruvada <[email protected]>; [email protected]; [email protected]; Heikki Krogerus <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 1/2] platform/x86: Add Intel Input Output Manager (IOM) driver

Quoted 13 lines · Rajmohan Mani

Input Output Manager (IOM) is part of the Tiger Lake SoC that configures the Type-C Sub System (TCSS). IOM is a micro controller that handles Type-C topology, configuration and PM functions of various Type-C devices connected on the platform.

This driver helps read relevant information such as Type-C port status (whether a device is connected to a Type-C port or not) and the activity type on the Type-C ports (such as USB, Display Port, Thunderbolt), for consumption by other drivers.

Currently intel_iom_port_status() API is exported by this driver, that has information about the Type-C port status and port activity type.

Quoted 6 lines
---
 drivers/platform/x86/Kconfig                |  16 +++
 drivers/platform/x86/Makefile               |   1 +
 drivers/platform/x86/intel_iom.c            | 133 ++++++++++++++++++++
 include/linux/platform_data/x86/intel_iom.h |  62 +++++++++
Quoted 3 lines

Why do you need a .h file for a single .c file that no one else shares this data? Just put it all in the .c file please.

The APIs exported by this driver, are used by the caller (Intel PMC USB mux control driver), hence the need for header file.

Quoted 75 lines

drivers/platform/x86/Makefile intel_cht_int33fe-objs :=

Quoted 37 lines
 4 files changed, 212 insertions(+)
 create mode 100644 drivers/platform/x86/intel_iom.c  create mode

100644 include/linux/platform_data/x86/intel_iom.h

(quoted diff) +0 -0

b/drivers/platform/x86/Kconfig index 0581a54cf562..271feddb20ef 100644

drivers/platform/x86/Kconfig +16 -0
@@ -816,6 +816,22 @@ config INTEL_INT0002_VGPIO
 	  To compile this driver as a module, choose M here: the module will
 	  be called intel_int0002_vgpio.
 
+config INTEL_IOM
+	tristate "Intel Input Output Manager (IOM) driver"
+	depends on ACPI && PCI
+	help
+	  This driver helps read relevant information such as Type-C port
+	  status (whether a device is connected to a Type-C port or not)
+	  and the activity type on the Type-C ports (such as USB, Display
+	  Port, Thunderbolt), for consumption by other drivers.
+
+	  Currently intel_iom_port_status() API is exported by this driver,
+	  that has information about the Type-C port status and port activity
+	  type.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called intel_iom.
+
 config INTEL_MENLOW
 	tristate "Thermal Management driver for Intel menlow platform"
 	depends on ACPI_THERMAL
(quoted diff) +0 -0

b/drivers/platform/x86/Makefile index 2b85852a1a87..d71e4620a7c6 100644

drivers/platform/x86/Makefile +0 -0
@@ -76,6 +76,7 @@ intel_cht_int33fe-objs			:=

intel_cht_int33fe_common.o \

Quoted 37 lines
drivers/platform/x86/Makefile +1 -0
 					   intel_cht_int33fe_microb.o
 obj-$(CONFIG_INTEL_HID_EVENT)		+= intel-hid.o
 obj-$(CONFIG_INTEL_INT0002_VGPIO)	+= intel_int0002_vgpio.o
+obj-$(CONFIG_INTEL_IOM)			+= intel_iom.o
 obj-$(CONFIG_INTEL_MENLOW)		+= intel_menlow.o
 obj-$(CONFIG_INTEL_OAKTRAIL)		+= intel_oaktrail.o
 obj-$(CONFIG_INTEL_VBTN)		+= intel-vbtn.o
drivers/platform/x86/intel_iom.c new file +23 -0
new file mode 100644
index 000000000000..ece0fe720b2d
@@ -0,0 +1,133 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Intel Core SoC Input Output Manager (IOM) driver.
+ *
+ * This driver provides access to the Input Output Manager (IOM)
+(that
+ * is part of Tiger Lake SoC) registers that can be used to know
+about
+ * Type-C Sub System related information (such as Type-C port status,
+ * activity type on Type-C ports).
+ *
+ * Copyright (C) 2020, Intel Corporation
+ * Author: Rajmohan Mani <[email protected]>  */
+
+#include <linux/io.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/platform_data/x86/intel_iom.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+#define IOM_PORT_STATUS_OFFSET				0x560
+
Quoted 9 lines

drivers/platform/x86/intel_iom.c line 28

Quoted 6 lines
drivers/platform/x86/intel_iom.c new file +6 -0
+struct intel_iom {
+	struct device *dev;
+	void __iomem *regbar;
+};
+
+static struct intel_iom iom_dev;

Why just one? Why is this static?

There is just one IOM device in the system.

Quoted 8 lines
Quoted 8 lines
drivers/platform/x86/intel_iom.c new file +8 -0
+
+/**
+ * intel_iom_get() - Get IOM device instance
+ *
+ * This function returns the IOM device instance. This also ensures
+that
+ * this driver cannot be unloaded while the caller has the instance.
+ *
Quoted 9 lines

drivers/platform/x86/intel_iom.c line 42

Quoted 6 lines
drivers/platform/x86/intel_iom.c new file +6 -0
+ * Call intel_iom_put() to release the instance.
+ *
+ * Returns IOM device instance on success or error pointer otherwise.
+ */
+struct intel_iom *intel_iom_get(void) {
+	struct device *dev = get_device(iom_dev.dev);

Wht if dev is NULL?

Ack. Will add a check for NULL.

Quoted 10 lines

drivers/platform/x86/intel_iom.c line 45

Quoted 3 lines
drivers/platform/x86/intel_iom.c new file +3 -0
+
+	/* Prevent this driver from being unloaded while in use */
+	if (!try_module_get(dev->driver->owner)) {

Why are you poking around in a random device's driver's owner?

That's not ok. And probably totally racy.

Handle module reference counts properly, not like this.

Ack. Will use THIS_MODULE here.

Quoted 3 lines

And why does it even matter that you incremented the module reference count? What is that "protecting" you from?

To prevent this driver from being unloaded, while it is being used.

Quoted 10 lines

drivers/platform/x86/intel_iom.c line 52

Quoted 7 lines
drivers/platform/x86/intel_iom.c new file +7 -0
+		put_device(iom_dev.dev);
+		return ERR_PTR(-EBUSY);
+	}
+
+	return &iom_dev;
+}
+EXPORT_SYMBOL_GPL(intel_iom_get);

Who calls this function?

Intel PMC USB mux control driver, in this case.
The callers are expected to call intel_iom_get() before using the intel_iom_port_status(), after which intel_iom_put() can be called to release the IOM device instance.

Quoted 18 lines
Quoted 5 lines
drivers/platform/x86/intel_iom.c new file +5 -0
+
+/**
+ * intel_iom_put() - Put IOM device instance
+ * @iom: IOM device instance
+ *

drivers/platform/x86/intel_iom.c line 68

Quoted 10 lines
drivers/platform/x86/intel_iom.c new file +10 -0
+ * This function releases the IOM device instance created using
+ * intel_iom_get() and allows the driver to be unloaded.
+ *
+ * Call intel_iom_put() to release the instance.
+ */
+void intel_iom_put(struct intel_iom *iom) {
+	if (!iom)
+		return;
+
+	module_put(iom->dev->driver->owner);

And if the device doesn't have a driver? boom :(

Quoted 2 lines

Don't do this.

Ack. Will use THIS_MODULE here.

Quoted 24 lines
Quoted 13 lines
drivers/platform/x86/intel_iom.c new file +13 -0
+	put_device(iom->dev);
+}
+EXPORT_SYMBOL_GPL(intel_iom_put);
+
+/**
+ * intel_iom_port_status() - Get status bits for the Type-C port
+ * @iom: IOM device instance
+ * @port: Type-C port number
+ * @status: pointer to receive the status bits
+ *
+ * Returns 0 on success, error otherwise.
+ */
+int intel_iom_port_status(struct intel_iom *iom, u8 port, u32

drivers/platform/x86/intel_iom.c

Quoted 10 lines
drivers/platform/x86/intel_iom.c new file +10 -0
+*status) {
+	void __iomem *reg;
+
+	if (!iom)
+		return -ENODEV;
+
+	if (!status || (port > IOM_MAX_PORTS - 1))
+		return -EINVAL;
+
+	reg = iom->regbar + IOM_PORT_STATUS_OFFSET + IOM_REG_LEN *

port;

Quoted 9 lines

drivers/platform/x86/intel_iom.c line 97

Quoted 6 lines
drivers/platform/x86/intel_iom.c new file +6 -0
+
+	*status = ioread32(reg);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(intel_iom_port_status);

So the whole driver is here just to read, directly from memory, a single 32 bit value?

Yes.

Quoted 3 lines

Doesn't that seem like a lot of overkill? Why can't the caller just do this themselves?

Ack.
Intel PMC USB mux device is part of the PCH, while IOM is part of the SoC. So I thought it made sense to keep these 2 devices / drivers apart, despite the overkill. Heikki also agreed with this approach, given the above.

Quoted 1 line

greg k-h

#4 lore raw

Re: [PATCH 1/2] platform/x86: Add Intel Input Output Manager (IOM) driver

Quoted 135 lines · Rajmohan

Hi Greg,

Thanks for the reviews.

Quoted 39 lines

-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Thursday, July 16, 2020 12:10 AM
To: Mani, Rajmohan <[email protected]>
Cc: Darren Hart <[email protected]>; Andy Shevchenko <[email protected]>; Mika Westerberg <[email protected]>; Dmitry Torokhov <[email protected]>; Lee Jones <[email protected]>; Ayman Bagabas <[email protected]>; Masahiro Yamada <[email protected]>; Joseph, Jithu <[email protected]>; Blaž Hrastnik <[email protected]>; Srinivas Pandruvada <[email protected]>; [email protected]; [email protected]; Heikki Krogerus <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 1/2] platform/x86: Add Intel Input Output Manager (IOM) driver

Quoted 13 lines · Rajmohan Mani

Input Output Manager (IOM) is part of the Tiger Lake SoC that configures the Type-C Sub System (TCSS). IOM is a micro controller that handles Type-C topology, configuration and PM functions of various Type-C devices connected on the platform.

This driver helps read relevant information such as Type-C port status (whether a device is connected to a Type-C port or not) and the activity type on the Type-C ports (such as USB, Display Port, Thunderbolt), for consumption by other drivers.

Currently intel_iom_port_status() API is exported by this driver, that has information about the Type-C port status and port activity type.

Quoted 6 lines
---
 drivers/platform/x86/Kconfig                |  16 +++
 drivers/platform/x86/Makefile               |   1 +
 drivers/platform/x86/intel_iom.c            | 133 ++++++++++++++++++++
 include/linux/platform_data/x86/intel_iom.h |  62 +++++++++
Quoted 3 lines

Why do you need a .h file for a single .c file that no one else shares this data? Just put it all in the .c file please.

The APIs exported by this driver, are used by the caller (Intel PMC USB mux control driver), hence the need for header file.

Quoted 75 lines

drivers/platform/x86/Makefile intel_cht_int33fe-objs :=

Quoted 37 lines
 4 files changed, 212 insertions(+)
 create mode 100644 drivers/platform/x86/intel_iom.c  create mode

100644 include/linux/platform_data/x86/intel_iom.h

(quoted diff) +0 -0

b/drivers/platform/x86/Kconfig index 0581a54cf562..271feddb20ef 100644

drivers/platform/x86/Kconfig +16 -0
@@ -816,6 +816,22 @@ config INTEL_INT0002_VGPIO
 	  To compile this driver as a module, choose M here: the module will
 	  be called intel_int0002_vgpio.
 
+config INTEL_IOM
+	tristate "Intel Input Output Manager (IOM) driver"
+	depends on ACPI && PCI
+	help
+	  This driver helps read relevant information such as Type-C port
+	  status (whether a device is connected to a Type-C port or not)
+	  and the activity type on the Type-C ports (such as USB, Display
+	  Port, Thunderbolt), for consumption by other drivers.
+
+	  Currently intel_iom_port_status() API is exported by this driver,
+	  that has information about the Type-C port status and port activity
+	  type.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called intel_iom.
+
 config INTEL_MENLOW
 	tristate "Thermal Management driver for Intel menlow platform"
 	depends on ACPI_THERMAL
(quoted diff) +0 -0

b/drivers/platform/x86/Makefile index 2b85852a1a87..d71e4620a7c6 100644

drivers/platform/x86/Makefile +0 -0
@@ -76,6 +76,7 @@ intel_cht_int33fe-objs			:=

intel_cht_int33fe_common.o \

Quoted 37 lines
drivers/platform/x86/Makefile +1 -0
 					   intel_cht_int33fe_microb.o
 obj-$(CONFIG_INTEL_HID_EVENT)		+= intel-hid.o
 obj-$(CONFIG_INTEL_INT0002_VGPIO)	+= intel_int0002_vgpio.o
+obj-$(CONFIG_INTEL_IOM)			+= intel_iom.o
 obj-$(CONFIG_INTEL_MENLOW)		+= intel_menlow.o
 obj-$(CONFIG_INTEL_OAKTRAIL)		+= intel_oaktrail.o
 obj-$(CONFIG_INTEL_VBTN)		+= intel-vbtn.o
drivers/platform/x86/intel_iom.c new file +23 -0
new file mode 100644
index 000000000000..ece0fe720b2d
@@ -0,0 +1,133 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Intel Core SoC Input Output Manager (IOM) driver.
+ *
+ * This driver provides access to the Input Output Manager (IOM)
+(that
+ * is part of Tiger Lake SoC) registers that can be used to know
+about
+ * Type-C Sub System related information (such as Type-C port status,
+ * activity type on Type-C ports).
+ *
+ * Copyright (C) 2020, Intel Corporation
+ * Author: Rajmohan Mani <[email protected]>  */
+
+#include <linux/io.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/platform_data/x86/intel_iom.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+#define IOM_PORT_STATUS_OFFSET				0x560
+
Quoted 9 lines

drivers/platform/x86/intel_iom.c line 28

Quoted 6 lines
drivers/platform/x86/intel_iom.c new file +6 -0
+struct intel_iom {
+	struct device *dev;
+	void __iomem *regbar;
+};
+
+static struct intel_iom iom_dev;

Why just one? Why is this static?

Quoted 1 line

There is just one IOM device in the system.

For today, yes, no need to force yourself to have to change this in the future. Just use a normal per-instance variable instead please, if you really need it.

Quoted 6 lines
Quoted 6 lines

drivers/platform/x86/intel_iom.c line 45

Quoted 3 lines
drivers/platform/x86/intel_iom.c new file +3 -0
+
+	/* Prevent this driver from being unloaded while in use */
+	if (!try_module_get(dev->driver->owner)) {

Why are you poking around in a random device's driver's owner?

Quoted 6 lines
Quoted 4 lines

That's not ok. And probably totally racy.

Handle module reference counts properly, not like this.

Ack. Will use THIS_MODULE here.

No, that is not the answer, and is always wrong to use :(

Quoted 5 lines
Quoted 3 lines

And why does it even matter that you incremented the module reference count? What is that "protecting" you from?

To prevent this driver from being unloaded, while it is being used.

Why does that matter? Shouldn't normal reference counting and dependancies be all that you need?

Quoted 11 lines
Quoted 10 lines

drivers/platform/x86/intel_iom.c line 52

Quoted 7 lines
drivers/platform/x86/intel_iom.c new file +7 -0
+		put_device(iom_dev.dev);
+		return ERR_PTR(-EBUSY);
+	}
+
+	return &iom_dev;
+}
+EXPORT_SYMBOL_GPL(intel_iom_get);

Who calls this function?

Quoted 4 lines

Intel PMC USB mux control driver, in this case.
The callers are expected to call intel_iom_get() before using the intel_iom_port_status(), after which intel_iom_put() can be called to release the IOM device instance.

Why not just have a single call if all this driver does is support one thing. The reference counting shouldn't be needed at all, right?

Quoted 17 lines
Quoted 17 lines
Quoted 4 lines
drivers/platform/x86/intel_iom.c new file +4 -0
+/**
+ * intel_iom_put() - Put IOM device instance
+ * @iom: IOM device instance
+ *

drivers/platform/x86/intel_iom.c line 68

Quoted 10 lines
drivers/platform/x86/intel_iom.c new file +10 -0
+ * This function releases the IOM device instance created using
+ * intel_iom_get() and allows the driver to be unloaded.
+ *
+ * Call intel_iom_put() to release the instance.
+ */
+void intel_iom_put(struct intel_iom *iom) {
+	if (!iom)
+		return;
+
+	module_put(iom->dev->driver->owner);

And if the device doesn't have a driver? boom :(

Quoted 4 lines
Quoted 2 lines

Don't do this.

Ack. Will use THIS_MODULE here.

Again, no, that will be even more incorrect.

Quoted 34 lines
Quoted 24 lines
Quoted 13 lines
drivers/platform/x86/intel_iom.c new file +13 -0
+	put_device(iom->dev);
+}
+EXPORT_SYMBOL_GPL(intel_iom_put);
+
+/**
+ * intel_iom_port_status() - Get status bits for the Type-C port
+ * @iom: IOM device instance
+ * @port: Type-C port number
+ * @status: pointer to receive the status bits
+ *
+ * Returns 0 on success, error otherwise.
+ */
+int intel_iom_port_status(struct intel_iom *iom, u8 port, u32

drivers/platform/x86/intel_iom.c

Quoted 10 lines
drivers/platform/x86/intel_iom.c new file +10 -0
+*status) {
+	void __iomem *reg;
+
+	if (!iom)
+		return -ENODEV;
+
+	if (!status || (port > IOM_MAX_PORTS - 1))
+		return -EINVAL;
+
+	reg = iom->regbar + IOM_PORT_STATUS_OFFSET + IOM_REG_LEN *

port;

Quoted 9 lines

drivers/platform/x86/intel_iom.c line 97

Quoted 6 lines
drivers/platform/x86/intel_iom.c new file +6 -0
+
+	*status = ioread32(reg);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(intel_iom_port_status);

So the whole driver is here just to read, directly from memory, a single 32 bit value?

Quoted 1 line

Yes.

Ok, then this whole driver could be about 90% smaller and more obvious. Don't add the reference counting, the static variables and all the other stuff just to get a 32bit number.

As it is, this feels like an excuse to get paid per lines of code :(

greg k-h

#5 lore raw

RE: [PATCH 1/2] platform/x86: Add Intel Input Output Manager (IOM) driver

Hi Greg,

Quoted 2 lines

Subject: Re: [PATCH 1/2] platform/x86: Add Intel Input Output Manager (IOM) driver

...

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

drivers/platform/x86/intel_iom.c line 28

Quoted 6 lines
drivers/platform/x86/intel_iom.c new file +6 -0
+struct intel_iom {
+	struct device *dev;
+	void __iomem *regbar;
+};
+
+static struct intel_iom iom_dev;

Why just one? Why is this static?

Quoted 5 lines
Quoted 1 line

There is just one IOM device in the system.

For today, yes, no need to force yourself to have to change this in the future. Just use a normal per-instance variable instead please, if you really need it.

Ack

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

drivers/platform/x86/intel_iom.c line 45

Quoted 3 lines
drivers/platform/x86/intel_iom.c new file +3 -0
+
+	/* Prevent this driver from being unloaded while in use */
+	if (!try_module_get(dev->driver->owner)) {

Why are you poking around in a random device's driver's owner?

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

That's not ok. And probably totally racy.

Handle module reference counts properly, not like this.

Ack. Will use THIS_MODULE here.

No, that is not the answer, and is always wrong to use :(

This should not matter anymore, as I find reference counting may not be needed.

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

And why does it even matter that you incremented the module reference count? What is that "protecting" you from?

To prevent this driver from being unloaded, while it is being used.

Why does that matter? Shouldn't normal reference counting and dependancies be all that you need?

I find just dependencies are enough to prevent the driver from being unloaded.

With Intel PMC USB mux control driver, not using intel_iom_get()/intel_iom_put(), just invoking intel_iom_port_status() is enough for rmmod to report failure (citing the use by intel_pmc_mux) in unloading the IOM driver.

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

drivers/platform/x86/intel_iom.c line 52

Quoted 7 lines
drivers/platform/x86/intel_iom.c new file +7 -0
+		put_device(iom_dev.dev);
+		return ERR_PTR(-EBUSY);
+	}
+
+	return &iom_dev;
+}
+EXPORT_SYMBOL_GPL(intel_iom_get);

Who calls this function?

Quoted 8 lines
Quoted 4 lines

Intel PMC USB mux control driver, in this case.
The callers are expected to call intel_iom_get() before using the intel_iom_port_status(), after which intel_iom_put() can be called to release the IOM device instance.

Why not just have a single call if all this driver does is support one thing. The reference counting shouldn't be needed at all, right?

Ack. That looks to be the case, based on my findings.

Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 4 lines
drivers/platform/x86/intel_iom.c new file +4 -0
+/**
+ * intel_iom_put() - Put IOM device instance
+ * @iom: IOM device instance
+ *

drivers/platform/x86/intel_iom.c line 68

Quoted 10 lines
drivers/platform/x86/intel_iom.c new file +10 -0
+ * This function releases the IOM device instance created using
+ * intel_iom_get() and allows the driver to be unloaded.
+ *
+ * Call intel_iom_put() to release the instance.
+ */
+void intel_iom_put(struct intel_iom *iom) {
+	if (!iom)
+		return;
+
+	module_put(iom->dev->driver->owner);

And if the device doesn't have a driver? boom :(

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Don't do this.

Ack. Will use THIS_MODULE here.

Again, no, that will be even more incorrect.

This shouldn't be relevant anymore.

Quoted 35 lines
Quoted 35 lines
Quoted 34 lines
Quoted 13 lines
drivers/platform/x86/intel_iom.c new file +13 -0
+	put_device(iom->dev);
+}
+EXPORT_SYMBOL_GPL(intel_iom_put);
+
+/**
+ * intel_iom_port_status() - Get status bits for the Type-C port
+ * @iom: IOM device instance
+ * @port: Type-C port number
+ * @status: pointer to receive the status bits
+ *
+ * Returns 0 on success, error otherwise.
+ */
+int intel_iom_port_status(struct intel_iom *iom, u8 port, u32

drivers/platform/x86/intel_iom.c

Quoted 10 lines
drivers/platform/x86/intel_iom.c new file +10 -0
+*status) {
+	void __iomem *reg;
+
+	if (!iom)
+		return -ENODEV;
+
+	if (!status || (port > IOM_MAX_PORTS - 1))
+		return -EINVAL;
+
+	reg = iom->regbar + IOM_PORT_STATUS_OFFSET + IOM_REG_LEN *

port;

drivers/platform/x86/intel_iom.c line 97

Quoted 6 lines
drivers/platform/x86/intel_iom.c new file +6 -0
+
+	*status = ioread32(reg);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(intel_iom_port_status);

So the whole driver is here just to read, directly from memory, a single
32 bit value?

Quoted 6 lines
Quoted 1 line

Yes.

Ok, then this whole driver could be about 90% smaller and more obvious. Don't add the reference counting, the static variables and all the other stuff just to get a 32bit number.

Ack

#6 lore raw

PATCH 2/2 usb: typec: intel_pmc_mux: Check the port status before connect

In reply to Rajmohan Mani

From: Heikki Krogerus <[email protected]>

The PMC microcontroller that we use for configuration, does not supply any status information back. For port status we need to talk to another controller on the board called IOM (I/O manager).

By checking the port status before configuring the muxes, we can make sure that we do not reconfigure the port after bootup when the system firmware (for example BIOS) has already configured it.

Using the status information also to check if DisplayPort HPD is still asserted when the cable plug is disconnected, and clearing it if it is.

---
 drivers/usb/typec/mux/Kconfig         |  1 +
 drivers/usb/typec/mux/intel_pmc_mux.c | 73 +++++++++++++++++++++++----
 2 files changed, 64 insertions(+), 10 deletions(-)
drivers/usb/typec/mux/Kconfig +1 -0
index a4dbd11f8ee2..46f5512de63d 100644
@@ -12,6 +12,7 @@ config TYPEC_MUX_PI3USB30532
 config TYPEC_MUX_INTEL_PMC
 	tristate "Intel PMC mux control"
 	depends on INTEL_SCU_IPC
+	depends on INTEL_IOM
 	select USB_ROLE_SWITCH
 	help
 	  Driver for USB muxes controlled by Intel PMC FW. Intel PMC FW can
drivers/usb/typec/mux/intel_pmc_mux.c +63 -10

192 lines not on this page · raw message

Signature · 1 line
2.20.1
#7 lore raw

Re: [PATCH 2/2] usb: typec: intel_pmc_mux: Check the port status before connect

Quoted 12 lines · Rajmohan Mani

From: Heikki Krogerus <[email protected]>

The PMC microcontroller that we use for configuration, does not supply any status information back. For port status we need to talk to another controller on the board called IOM (I/O manager).

By checking the port status before configuring the muxes, we can make sure that we do not reconfigure the port after bootup when the system firmware (for example BIOS) has already configured it.

Quoted 5 lines

Using the status information also to check if DisplayPort HPD is still asserted when the cable plug is disconnected, and clearing it if it is.

You can't just forward on patches from others without also adding your signed-off-by to them, right?

Please fix up this series and try again.

thanks,

greg k-h

#8 lore raw

RE: [PATCH 2/2] usb: typec: intel_pmc_mux: Check the port status before connect

Hi Greg,

Quoted 29 lines

-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Thursday, July 16, 2020 12:05 AM
To: Mani, Rajmohan <[email protected]>
Cc: Darren Hart <[email protected]>; Andy Shevchenko <[email protected]>; Mika Westerberg <[email protected]>; Dmitry Torokhov <[email protected]>; Lee Jones <[email protected]>; Ayman Bagabas <[email protected]>; Masahiro Yamada <[email protected]>; Joseph, Jithu <[email protected]>; Blaž Hrastnik <[email protected]>; Srinivas Pandruvada <[email protected]>; [email protected]; [email protected]; Heikki Krogerus <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 2/2] usb: typec: intel_pmc_mux: Check the port status before connect

Quoted 10 lines · Rajmohan Mani

From: Heikki Krogerus <[email protected]>

The PMC microcontroller that we use for configuration, does not supply any status information back. For port status we need to talk to another controller on the board called IOM (I/O manager).

By checking the port status before configuring the muxes, we can make sure that we do not reconfigure the port after bootup when the system firmware (for example BIOS) has already configured it.

Quoted 9 lines
Quoted 5 lines

Using the status information also to check if DisplayPort HPD is still asserted when the cable plug is disconnected, and clearing it if it is.

You can't just forward on patches from others without also adding your signed-off-by to them, right?

Sorry I missed this.

Quoted 2 lines

Please fix up this series and try again.

Ack. Will fix this with v2.

Quoted 3 lines

thanks,

greg k-h

#9 lore raw

Re: [PATCH 2/2] usb: typec: intel_pmc_mux: Check the port status before connect

Quoted 41 lines · Rajmohan

Hi Greg,

Quoted 29 lines

-----Original Message-----
From: Greg Kroah-Hartman <[email protected]>
Sent: Thursday, July 16, 2020 12:05 AM
To: Mani, Rajmohan <[email protected]>
Cc: Darren Hart <[email protected]>; Andy Shevchenko <[email protected]>; Mika Westerberg <[email protected]>; Dmitry Torokhov <[email protected]>; Lee Jones <[email protected]>; Ayman Bagabas <[email protected]>; Masahiro Yamada <[email protected]>; Joseph, Jithu <[email protected]>; Blaž Hrastnik <[email protected]>; Srinivas Pandruvada <[email protected]>; [email protected]; [email protected]; Heikki Krogerus <[email protected]>; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 2/2] usb: typec: intel_pmc_mux: Check the port status before connect

Quoted 10 lines · Rajmohan Mani

From: Heikki Krogerus <[email protected]>

The PMC microcontroller that we use for configuration, does not supply any status information back. For port status we need to talk to another controller on the board called IOM (I/O manager).

By checking the port status before configuring the muxes, we can make sure that we do not reconfigure the port after bootup when the system firmware (for example BIOS) has already configured it.

Quoted 9 lines
Quoted 5 lines

Using the status information also to check if DisplayPort HPD is still asserted when the cable plug is disconnected, and clearing it if it is.

You can't just forward on patches from others without also adding your signed-off-by to them, right?

Quoted 6 lines

Sorry I missed this.

Quoted 2 lines

Please fix up this series and try again.

Ack. Will fix this with v2.

Stop and go talk to the proper people in Intel for how to submit patches to the kernel as you are not following the rules they have documented for you.

thanks,

greg k-h