Skip to contentSkip to conversation

gpio: Fixes for Granite Rapids vGPIO driver

PATCH Applied Mika Westerberg 3 participants 11 messages Dec 4, 2024 – Dec 10, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover gpio: Fixes for Granite Rapids vGPIO driver

Hi,

This series includes several fixes for the Granite Rapids vGPIO driver found during validation.

Alan Borzeszkowski (5):
gpio: graniterapids: Fix vGPIO driver crash
gpio: graniterapids: Fix incorrect BAR assignment
gpio: graniterapids: Determine if GPIO pad can be used by driver
gpio: graniterapids: Check if GPIO line can be used for IRQs
gpio: graniterapids: Fix GPIO Ack functionality

Shankar Bandal (2):
gpio: graniterapids: Fix invalid GPI_IS register offset
gpio: graniterapids: Fix invalid RXEVCFG register bitmask

 drivers/gpio/gpio-graniterapids.c | 52 ++++++++++++++++++++++++-------
 1 file changed, 41 insertions(+), 11 deletions(-)
Signature · 1 line
2.45.2
#1 lore raw

PATCH 1/7 gpio: graniterapids: Fix vGPIO driver crash

From: Alan Borzeszkowski <[email protected]>

Move setting irq_chip.name from probe() function to the initialization of "irq_chip" struct in order to fix vGPIO driver crash during bootup.

Crash was caused by unauthorized modification of irq_chip.name field where irq_chip struct was initialized as const.

This behavior is a consequence of suboptimal implementation of gpio_irq_chip_set_chip(), which should be changed to avoid casting away const qualifier.

Crash log:

BUG: unable to handle page fault for address: ffffffffc0ba81c0
/#PF: supervisor write access in kernel mode
/#PF: error_code(0x0003) - permissions violation
CPU: 33 UID: 0 PID: 1075 Comm: systemd-udevd Not tainted 6.12.0-rc6-00077-g2e1b3cc9d7f7 #1
Hardware name: Intel Corporation Kaseyville RP/Kaseyville RP, BIOS KVLDCRB1.PGS.0026.D73.2410081258 10/08/2024
RIP: 0010:gnr_gpio_probe+0x171/0x220 [gpio_graniterapids]
---
 drivers/gpio/gpio-graniterapids.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-graniterapids.c +1 -1
index f2e911a3d2ca..9da2999dc30f 100644
@@ -234,6 +234,7 @@ static int gnr_gpio_irq_set_type(struct irq_data *d, unsigned int type)
 }
 
 static const struct irq_chip gnr_gpio_irq_chip = {
+	.name		= "gpio-graniterapids",
 	.irq_ack	= gnr_gpio_irq_ack,
 	.irq_mask	= gnr_gpio_irq_mask,
 	.irq_unmask	= gnr_gpio_irq_unmask,
@@ -324,7 +325,6 @@ static int gnr_gpio_probe(struct platform_device *pdev)
 
 	girq = &priv->gc.irq;
 	gpio_irq_chip_set_chip(girq, &gnr_gpio_irq_chip);
-	girq->chip->name	= dev_name(dev);
 	girq->parent_handler	= NULL;
 	girq->num_parents	= 0;
 	girq->parents		= NULL;
Signature · 1 line
2.45.2
#2 lore raw

PATCH 2/7 gpio: graniterapids: Fix incorrect BAR assignment

In reply to Mika Westerberg

From: Alan Borzeszkowski <[email protected]>

Base Address of vGPIO MMIO register is provided directly by the BIOS instead of using offsets. Update address assignment to reflect this change in driver.

---
 drivers/gpio/gpio-graniterapids.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/gpio/gpio-graniterapids.c +9 -4
index 9da2999dc30f..d2b542b536b6 100644
@@ -32,7 +32,7 @@
 #define GNR_PINS_PER_REG 32
 #define GNR_NUM_REGS DIV_ROUND_UP(GNR_NUM_PINS, GNR_PINS_PER_REG)
 
-#define GNR_CFG_BAR		0x00
+#define GNR_CFG_PADBAR		0x00
 #define GNR_CFG_LOCK_OFFSET	0x04
 #define GNR_GPI_STATUS_OFFSET	0x20
 #define GNR_GPI_ENABLE_OFFSET	0x24
@@ -50,6 +50,7 @@
  * struct gnr_gpio - Intel Granite Rapids-D vGPIO driver state
  * @gc: GPIO controller interface
  * @reg_base: base address of the GPIO registers
+ * @pad_base: base address of the vGPIO pad configuration registers
  * @ro_bitmap: bitmap of read-only pins
  * @lock: guard the registers
  * @pad_backup: backup of the register state for suspend
@@ -57,6 +58,7 @@
 struct gnr_gpio {
 	struct gpio_chip gc;
 	void __iomem *reg_base;
+	void __iomem *pad_base;
 	DECLARE_BITMAP(ro_bitmap, GNR_NUM_PINS);
 	raw_spinlock_t lock;
 	u32 pad_backup[];
@@ -65,7 +67,7 @@ struct gnr_gpio {
 static void __iomem *gnr_gpio_get_padcfg_addr(const struct gnr_gpio *priv,
 					      unsigned int gpio)
 {
-	return priv->reg_base + gpio * sizeof(u32);
+	return priv->pad_base + gpio * sizeof(u32);
 }
 
 static int gnr_gpio_configure_line(struct gpio_chip *gc, unsigned int gpio,
@@ -292,6 +294,7 @@ static int gnr_gpio_probe(struct platform_device *pdev)
 	struct gnr_gpio *priv;
 	void __iomem *regs;
 	int irq, ret;
+	u32 offset;
 
 	priv = devm_kzalloc(dev, struct_size(priv, pad_backup, num_backup_pins), GFP_KERNEL);
 	if (!priv)
@@ -303,6 +306,10 @@ static int gnr_gpio_probe(struct platform_device *pdev)
 	if (IS_ERR(regs))
 		return PTR_ERR(regs);
 
+	priv->reg_base = regs;
+	offset = readl(priv->reg_base + GNR_CFG_PADBAR);
+	priv->pad_base = priv->reg_base + offset;
+
 	irq = platform_get_irq(pdev, 0);
 	if (irq < 0)
 		return irq;
@@ -312,8 +319,6 @@ static int gnr_gpio_probe(struct platform_device *pdev)
 	if (ret)
 		return dev_err_probe(dev, ret, "failed to request interrupt\n");
 
-	priv->reg_base = regs + readl(regs + GNR_CFG_BAR);
-
 	gnr_gpio_init_pin_ro_bits(dev, priv->reg_base + GNR_CFG_LOCK_OFFSET,
 				  priv->ro_bitmap);
 
Signature · 1 line
2.45.2
#3 lore raw

PATCH 3/7 gpio: graniterapids: Fix invalid GPI_IS register offset

In reply to Mika Westerberg

From: Shankar Bandal <[email protected]>

Update GPI Interrupt Status register offset to correct value.

---
 drivers/gpio/gpio-graniterapids.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-graniterapids.c +1 -1
index d2b542b536b6..be907784ccdb 100644
@@ -34,7 +34,7 @@
 
 #define GNR_CFG_PADBAR		0x00
 #define GNR_CFG_LOCK_OFFSET	0x04
-#define GNR_GPI_STATUS_OFFSET	0x20
+#define GNR_GPI_STATUS_OFFSET	0x14
 #define GNR_GPI_ENABLE_OFFSET	0x24
 
 #define GNR_CFG_DW_RX_MASK	GENMASK(25, 22)
Signature · 1 line
2.45.2
#4 lore raw

PATCH 4/7 gpio: graniterapids: Fix invalid RXEVCFG register bitmask

In reply to Mika Westerberg

From: Shankar Bandal <[email protected]>

Correct RX Level/Edge Configuration register (RXEVCFG) bitmask.

---
 drivers/gpio/gpio-graniterapids.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-graniterapids.c +1 -1
index be907784ccdb..ec2931a65723 100644
@@ -37,7 +37,7 @@
 #define GNR_GPI_STATUS_OFFSET	0x14
 #define GNR_GPI_ENABLE_OFFSET	0x24
 
-#define GNR_CFG_DW_RX_MASK	GENMASK(25, 22)
+#define GNR_CFG_DW_RX_MASK	GENMASK(23, 22)
 #define GNR_CFG_DW_RX_DISABLE	FIELD_PREP(GNR_CFG_DW_RX_MASK, 2)
 #define GNR_CFG_DW_RX_EDGE	FIELD_PREP(GNR_CFG_DW_RX_MASK, 1)
 #define GNR_CFG_DW_RX_LEVEL	FIELD_PREP(GNR_CFG_DW_RX_MASK, 0)
Signature · 1 line
2.45.2
#5 lore raw

PATCH 5/7 gpio: graniterapids: Determine if GPIO pad can be used by driver

In reply to Mika Westerberg

From: Alan Borzeszkowski <[email protected]>

Add check of HOSTSW_MODE bit to determine if GPIO pad can be used by the driver.

---
 drivers/gpio/gpio-graniterapids.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
drivers/gpio/gpio-graniterapids.c +16 -0
index ec2931a65723..b12abe77299c 100644
@@ -37,6 +37,7 @@
 #define GNR_GPI_STATUS_OFFSET	0x14
 #define GNR_GPI_ENABLE_OFFSET	0x24
 
+#define GNR_CFG_DW_HOSTSW_MODE	BIT(27)
 #define GNR_CFG_DW_RX_MASK	GENMASK(23, 22)
 #define GNR_CFG_DW_RX_DISABLE	FIELD_PREP(GNR_CFG_DW_RX_MASK, 2)
 #define GNR_CFG_DW_RX_EDGE	FIELD_PREP(GNR_CFG_DW_RX_MASK, 1)
@@ -90,6 +91,20 @@ static int gnr_gpio_configure_line(struct gpio_chip *gc, unsigned int gpio,
 	return 0;
 }
 
+static int gnr_gpio_request(struct gpio_chip *gc, unsigned int gpio)
+{
+	struct gnr_gpio *priv = gpiochip_get_data(gc);
+	u32 dw;
+
+	dw = readl(gnr_gpio_get_padcfg_addr(priv, gpio));
+	if (!(dw & GNR_CFG_DW_HOSTSW_MODE)) {
+		dev_warn(gc->parent, "GPIO %u is not owned by host", gpio);
+		return -EBUSY;
+	}
+
+	return 0;
+}
+
 static int gnr_gpio_get(struct gpio_chip *gc, unsigned int gpio)
 {
 	const struct gnr_gpio *priv = gpiochip_get_data(gc);
@@ -141,6 +156,7 @@ static int gnr_gpio_direction_output(struct gpio_chip *gc, unsigned int gpio, in
 
 static const struct gpio_chip gnr_gpio_chip = {
 	.owner		  = THIS_MODULE,
+	.request	  = gnr_gpio_request,
 	.get		  = gnr_gpio_get,
 	.set		  = gnr_gpio_set,
 	.get_direction    = gnr_gpio_get_direction,
Signature · 1 line
2.45.2
#6 lore raw

PATCH 6/7 gpio: graniterapids: Check if GPIO line can be used for IRQs

In reply to Mika Westerberg

From: Alan Borzeszkowski <[email protected]>

GPIO line can only be used as interrupt if its INTSEL register is programmed by the BIOS.

---
 drivers/gpio/gpio-graniterapids.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/gpio/gpio-graniterapids.c +12 -3
index b12abe77299c..3a972d460fe2 100644
@@ -39,6 +39,7 @@
 
 #define GNR_CFG_DW_HOSTSW_MODE	BIT(27)
 #define GNR_CFG_DW_RX_MASK	GENMASK(23, 22)
+#define GNR_CFG_DW_INTSEL_MASK	GENMASK(21, 14)
 #define GNR_CFG_DW_RX_DISABLE	FIELD_PREP(GNR_CFG_DW_RX_MASK, 2)
 #define GNR_CFG_DW_RX_EDGE	FIELD_PREP(GNR_CFG_DW_RX_MASK, 1)
 #define GNR_CFG_DW_RX_LEVEL	FIELD_PREP(GNR_CFG_DW_RX_MASK, 0)
@@ -227,10 +228,18 @@ static void gnr_gpio_irq_unmask(struct irq_data *d)
 static int gnr_gpio_irq_set_type(struct irq_data *d, unsigned int type)
 {
 	struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
-	irq_hw_number_t pin = irqd_to_hwirq(d);
-	u32 mask = GNR_CFG_DW_RX_MASK;
+	struct gnr_gpio *priv = gpiochip_get_data(gc);
+	irq_hw_number_t hwirq = irqd_to_hwirq(d);
+	u32 reg;
 	u32 set;
 
+	/* Allow interrupts only if Interrupt Select field is non-zero */
+	reg = readl(gnr_gpio_get_padcfg_addr(priv, hwirq));
+	if (!(reg & GNR_CFG_DW_INTSEL_MASK)) {
+		dev_dbg(gc->parent, "GPIO %lu cannot be used as IRQ", hwirq);
+		return -EPERM;
+	}
+
 	/* Falling edge and level low triggers not supported by the GPIO controller */
 	switch (type) {
 	case IRQ_TYPE_NONE:
@@ -248,7 +257,7 @@ static int gnr_gpio_irq_set_type(struct irq_data *d, unsigned int type)
 		return -EINVAL;
 	}
 
-	return gnr_gpio_configure_line(gc, pin, mask, set);
+	return gnr_gpio_configure_line(gc, hwirq, GNR_CFG_DW_RX_MASK, set);
 }
 
 static const struct irq_chip gnr_gpio_irq_chip = {
Signature · 1 line
2.45.2
#7 lore raw

PATCH 7/7 gpio: graniterapids: Fix GPIO Ack functionality

In reply to Mika Westerberg

From: Alan Borzeszkowski <[email protected]>

Interrupt status (GPI_IS) register is cleared by writing 1 to it, not 0.

---
 drivers/gpio/gpio-graniterapids.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-graniterapids.c +1 -1
index 3a972d460fe2..ad6a045fd3d2 100644
@@ -185,7 +185,7 @@ static void gnr_gpio_irq_ack(struct irq_data *d)
 	guard(raw_spinlock_irqsave)(&priv->lock);
 
 	reg = readl(addr);
-	reg &= ~BIT(bit_idx);
+	reg |= BIT(bit_idx);
 	writel(reg, addr);
 }
 
Signature · 1 line
2.45.2
#8 lore raw
In reply to Mika Westerberg
Quoted 17 lines · Mika Westerberg

Hi,

This series includes several fixes for the Granite Rapids vGPIO driver found during validation.

Alan Borzeszkowski (5):
gpio: graniterapids: Fix vGPIO driver crash
gpio: graniterapids: Fix incorrect BAR assignment
gpio: graniterapids: Determine if GPIO pad can be used by driver
gpio: graniterapids: Check if GPIO line can be used for IRQs
gpio: graniterapids: Fix GPIO Ack functionality

Shankar Bandal (2):
gpio: graniterapids: Fix invalid GPI_IS register offset
gpio: graniterapids: Fix invalid RXEVCFG register bitmask

Quoted 6 lines
 drivers/gpio/gpio-graniterapids.c | 52 ++++++++++++++++++++++++-------
 1 file changed, 41 insertions(+), 11 deletions(-)

--
2.45.2

Andy: any comments on these? I'm willing to take it for the next rc this week.

Bart

#10 lore raw
In reply to Mika Westerberg

From: Bartosz Golaszewski <[email protected]>

Quoted 11 lines · Mika Westerberg

This series includes several fixes for the Granite Rapids vGPIO driver found during validation.

Alan Borzeszkowski (5):
gpio: graniterapids: Fix vGPIO driver crash
gpio: graniterapids: Fix incorrect BAR assignment
gpio: graniterapids: Determine if GPIO pad can be used by driver
gpio: graniterapids: Check if GPIO line can be used for IRQs
gpio: graniterapids: Fix GPIO Ack functionality

[...]

Applied, thanks!

[1/7] gpio: graniterapids: Fix vGPIO driver crash

      commit: eb9640fd1ce666610b77f5997596e9570a36378f
[2/7] gpio: graniterapids: Fix incorrect BAR assignment
      commit: 7382d2f0e802077c36495e325da8d253a15fb441
[3/7] gpio: graniterapids: Fix invalid GPI_IS register offset
      commit: 0fe329b55231cca489f9bed1db0e778d077fdaf9
[4/7] gpio: graniterapids: Fix invalid RXEVCFG register bitmask
      commit: 15636b00a055474033426b94b6372728b2163a1e
[5/7] gpio: graniterapids: Determine if GPIO pad can be used by driver
      commit: 0588504d28dedde6789aec17a6ece6fa8e477725
[6/7] gpio: graniterapids: Check if GPIO line can be used for IRQs
      commit: c0ec4890d6454980c53c3cc164140115c4a671f2
[7/7] gpio: graniterapids: Fix GPIO Ack functionality
      commit: 0bb18e34abdde7bf58fca8542e2dcf621924ea19

Best regards,

Signature · 1 line
Bartosz Golaszewski <[email protected]>