From: Antonio Borneo <antonio.borneo@foss.st.com>
To: Linus Walleij <linus.walleij@linaro.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Maxime Coquelin <mcoquelin.stm32@gmail.com>,
Alexandre Torgue <alexandre.torgue@foss.st.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>, <linux-gpio@vger.kernel.org>,
<devicetree@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>
Cc: "Antonio Borneo" <antonio.borneo@foss.st.com>,
linux-kernel@vger.kernel.org,
"Clément Le Goffic" <clement.legoffic@foss.st.com>,
"Stephane Danieau" <stephane.danieau@foss.st.com>,
"Amelie Delaunay" <amelie.delaunay@foss.st.com>,
"Fabien Dessenne" <fabien.dessenne@foss.st.com>,
"Valentin Caron" <valentin.caron@foss.st.com>,
"Gatien Chevallier" <gatien.chevallier@foss.st.com>,
"Cheick Traore" <cheick.traore@foss.st.com>,
linux-stm32@st-md-mailman.stormreply.com
Subject: [PATCH 08/14] pinctrl: stm32: Add RIF support for stm32mp257
Date: Tue, 22 Oct 2024 17:56:52 +0200 [thread overview]
Message-ID: <20241022155658.1647350-9-antonio.borneo@foss.st.com> (raw)
In-Reply-To: <20241022155658.1647350-1-antonio.borneo@foss.st.com>
On SoC stm32mp257, GPIO supports security and isolation compliant
with the Resource Isolation Framework (RIF). Each GPIO line can be
assigned to different security and compartment domains.
Add the generic code to handle the RIF configuration set by the
secure world and initialize the GPIO valid mask accordingly.
Enable the RIF support for stm32mp257.
Co-developed-by: Gatien Chevallier <gatien.chevallier@foss.st.com>
Signed-off-by: Gatien Chevallier <gatien.chevallier@foss.st.com>
Signed-off-by: Antonio Borneo <antonio.borneo@foss.st.com>
---
drivers/pinctrl/stm32/pinctrl-stm32.c | 121 ++++++++++++++++++++-
drivers/pinctrl/stm32/pinctrl-stm32.h | 1 +
drivers/pinctrl/stm32/pinctrl-stm32mp257.c | 4 +
3 files changed, 125 insertions(+), 1 deletion(-)
diff --git a/drivers/pinctrl/stm32/pinctrl-stm32.c b/drivers/pinctrl/stm32/pinctrl-stm32.c
index 5b9c637ca0c93..b6e7e34508592 100644
--- a/drivers/pinctrl/stm32/pinctrl-stm32.c
+++ b/drivers/pinctrl/stm32/pinctrl-stm32.c
@@ -6,6 +6,7 @@
*
* Heavily based on Mediatek's pinctrl driver
*/
+#include <linux/bitfield.h>
#include <linux/clk.h>
#include <linux/gpio/driver.h>
#include <linux/hwspinlock.h>
@@ -35,6 +36,8 @@
#include "../pinctrl-utils.h"
#include "pinctrl-stm32.h"
+#define STM32_GPIO_CID1 1
+
#define STM32_GPIO_MODER 0x00
#define STM32_GPIO_TYPER 0x04
#define STM32_GPIO_SPEEDR 0x08
@@ -48,12 +51,22 @@
#define STM32_GPIO_SECCFGR 0x30
#define STM32_GPIO_DELAYRL 0x40
#define STM32_GPIO_ADVCFGRL 0x48
+#define STM32_GPIO_CIDCFGR(x) (0x50 + (0x8 * (x)))
+#define STM32_GPIO_SEMCR(x) (0x54 + (0x8 * (x)))
#define STM32_GPIO_ADVCFGR_DLYPATH_POS 0
#define STM32_GPIO_ADVCFGR_DE_POS 1
#define STM32_GPIO_ADVCFGR_INVCLK_POS 2
#define STM32_GPIO_ADVCFGR_RET_POS 3
+#define STM32_GPIO_CIDCFGR_CFEN BIT(0)
+#define STM32_GPIO_CIDCFGR_SEMEN BIT(1)
+#define STM32_GPIO_CIDCFGR_SCID_MASK GENMASK(5, 4)
+#define STM32_GPIO_CIDCFGR_SEMWL_CID1 BIT(16 + STM32_GPIO_CID1)
+
+#define STM32_GPIO_SEMCR_SEM_MUTEX BIT(0)
+#define STM32_GPIO_SEMCR_SEMCID_MASK GENMASK(5, 4)
+
/* custom bitfield to backup pin status */
#define STM32_GPIO_BKP_MODE_SHIFT 0
#define STM32_GPIO_BKP_MODE_MASK GENMASK(1, 0)
@@ -126,6 +139,7 @@ struct stm32_gpio_bank {
u8 irq_type[STM32_GPIO_PINS_PER_BANK];
bool secure_control;
bool io_sync_control;
+ bool rif_control;
};
struct stm32_pinctrl {
@@ -233,6 +247,80 @@ static void stm32_gpio_backup_delay(struct stm32_gpio_bank *bank, u32 offset, u3
bank->pin_backup[offset] |= delay << STM32_GPIO_BKP_DELAY_SHIFT;
}
+/* RIF functions */
+
+static bool stm32_gpio_rif_valid(struct stm32_gpio_bank *bank, unsigned int gpio_nr)
+{
+ u32 cid;
+
+ cid = readl_relaxed(bank->base + STM32_GPIO_CIDCFGR(gpio_nr));
+
+ if (!(cid & STM32_GPIO_CIDCFGR_CFEN))
+ return true;
+
+ if (!(cid & STM32_GPIO_CIDCFGR_SEMEN)) {
+ if (FIELD_GET(STM32_GPIO_CIDCFGR_SCID_MASK, cid) == STM32_GPIO_CID1)
+ return true;
+
+ return false;
+ }
+
+ if (cid & STM32_GPIO_CIDCFGR_SEMWL_CID1)
+ return true;
+
+ return false;
+}
+
+static bool stm32_gpio_rif_acquire_semaphore(struct stm32_gpio_bank *bank, unsigned int gpio_nr)
+{
+ u32 cid, sem;
+
+ cid = readl_relaxed(bank->base + STM32_GPIO_CIDCFGR(gpio_nr));
+
+ if (!(cid & STM32_GPIO_CIDCFGR_CFEN))
+ return true;
+
+ if (!(cid & STM32_GPIO_CIDCFGR_SEMEN)) {
+ if (FIELD_GET(STM32_GPIO_CIDCFGR_SCID_MASK, cid) == STM32_GPIO_CID1)
+ return true;
+
+ return false;
+ }
+
+ if (!(cid & STM32_GPIO_CIDCFGR_SEMWL_CID1))
+ return false;
+
+ sem = readl_relaxed(bank->base + STM32_GPIO_SEMCR(gpio_nr));
+ if (sem & STM32_GPIO_SEMCR_SEM_MUTEX) {
+ if (FIELD_GET(STM32_GPIO_SEMCR_SEMCID_MASK, sem) == STM32_GPIO_CID1)
+ return true;
+
+ return false;
+ }
+
+ writel_relaxed(STM32_GPIO_SEMCR_SEM_MUTEX, bank->base + STM32_GPIO_SEMCR(gpio_nr));
+
+ sem = readl_relaxed(bank->base + STM32_GPIO_SEMCR(gpio_nr));
+ if (sem & STM32_GPIO_SEMCR_SEM_MUTEX &&
+ FIELD_GET(STM32_GPIO_SEMCR_SEMCID_MASK, sem) == STM32_GPIO_CID1)
+ return true;
+
+ return false;
+}
+
+static void stm32_gpio_rif_release_semaphore(struct stm32_gpio_bank *bank, unsigned int gpio_nr)
+{
+ u32 cid;
+
+ cid = readl_relaxed(bank->base + STM32_GPIO_CIDCFGR(gpio_nr));
+
+ if (!(cid & STM32_GPIO_CIDCFGR_CFEN))
+ return;
+
+ if (cid & STM32_GPIO_CIDCFGR_SEMEN)
+ writel_relaxed(0, bank->base + STM32_GPIO_SEMCR(gpio_nr));
+}
+
/* GPIO functions */
static inline void __stm32_gpio_set(struct stm32_gpio_bank *bank,
@@ -259,9 +347,26 @@ static int stm32_gpio_request(struct gpio_chip *chip, unsigned offset)
return -EINVAL;
}
+ if (bank->rif_control) {
+ if (!stm32_gpio_rif_acquire_semaphore(bank, offset)) {
+ dev_err(pctl->dev, "pin %d not available.\n", pin);
+ return -EINVAL;
+ }
+ }
+
return pinctrl_gpio_request(chip, offset);
}
+static void stm32_gpio_free(struct gpio_chip *chip, unsigned int offset)
+{
+ struct stm32_gpio_bank *bank = gpiochip_get_data(chip);
+
+ pinctrl_gpio_free(chip, offset);
+
+ if (bank->rif_control)
+ stm32_gpio_rif_release_semaphore(bank, offset);
+}
+
static int stm32_gpio_get(struct gpio_chip *chip, unsigned offset)
{
struct stm32_gpio_bank *bank = gpiochip_get_data(chip);
@@ -342,12 +447,25 @@ static int stm32_gpio_init_valid_mask(struct gpio_chip *chip,
}
}
+ if (bank->rif_control) {
+ for (i = 0; i < ngpios; i++) {
+ if (!test_bit(i, valid_mask))
+ continue;
+
+ if (stm32_gpio_rif_valid(bank, i))
+ continue;
+
+ dev_dbg(pctl->dev, "RIF semaphore ownership conflict, GPIO %u", i);
+ clear_bit(i, valid_mask);
+ }
+ }
+
return 0;
}
static const struct gpio_chip stm32_gpio_template = {
.request = stm32_gpio_request,
- .free = pinctrl_gpio_free,
+ .free = stm32_gpio_free,
.get = stm32_gpio_get,
.set = stm32_gpio_set,
.direction_input = pinctrl_gpio_direction_input,
@@ -1529,6 +1647,7 @@ static int stm32_gpiolib_register_bank(struct stm32_pinctrl *pctl, struct fwnode
bank->bank_ioport_nr = bank_ioport_nr;
bank->secure_control = pctl->match_data->secure_control;
bank->io_sync_control = pctl->match_data->io_sync_control;
+ bank->rif_control = pctl->match_data->rif_control;
spin_lock_init(&bank->lock);
if (pctl->domain) {
diff --git a/drivers/pinctrl/stm32/pinctrl-stm32.h b/drivers/pinctrl/stm32/pinctrl-stm32.h
index 9b319036f206d..b8caebc55cfc5 100644
--- a/drivers/pinctrl/stm32/pinctrl-stm32.h
+++ b/drivers/pinctrl/stm32/pinctrl-stm32.h
@@ -65,6 +65,7 @@ struct stm32_pinctrl_match_data {
const unsigned int npins;
bool secure_control;
bool io_sync_control;
+ bool rif_control;
};
int stm32_pctl_probe(struct platform_device *pdev);
diff --git a/drivers/pinctrl/stm32/pinctrl-stm32mp257.c b/drivers/pinctrl/stm32/pinctrl-stm32mp257.c
index 293b7acd82a3e..a374918030788 100644
--- a/drivers/pinctrl/stm32/pinctrl-stm32mp257.c
+++ b/drivers/pinctrl/stm32/pinctrl-stm32mp257.c
@@ -2543,12 +2543,16 @@ static struct stm32_pinctrl_match_data stm32mp257_match_data = {
.pins = stm32mp257_pins,
.npins = ARRAY_SIZE(stm32mp257_pins),
.io_sync_control = true,
+ .secure_control = true,
+ .rif_control = true,
};
static struct stm32_pinctrl_match_data stm32mp257_z_match_data = {
.pins = stm32mp257_z_pins,
.npins = ARRAY_SIZE(stm32mp257_z_pins),
.io_sync_control = true,
+ .secure_control = true,
+ .rif_control = true,
};
static const struct of_device_id stm32mp257_pctrl_match[] = {
--
2.34.1
next prev parent reply other threads:[~2024-10-22 15:59 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-22 15:56 [PATCH 00/14] pinctrl: stm32: Add new features and support for more SoC Antonio Borneo
2024-10-22 15:56 ` [PATCH 01/14] pinctrl: stm32: Declare stm32_pmx_get_mode() as static Antonio Borneo
2024-10-22 15:56 ` [PATCH 02/14] pinctrl: stm32: Manage irq affinity settings Antonio Borneo
2024-10-22 15:56 ` [PATCH 03/14] pinctrl: stm32: Handle RSVD pin configuration Antonio Borneo
2024-10-22 15:56 ` [PATCH 04/14] dt-bindings: pinctrl: stm32: add RSVD mux function Antonio Borneo
2024-10-23 8:46 ` Krzysztof Kozlowski
2024-10-23 8:47 ` Krzysztof Kozlowski
2024-10-23 8:56 ` Antonio Borneo
2024-10-24 13:22 ` Krzysztof Kozlowski
2024-10-22 15:56 ` [PATCH 05/14] pinctrl: stm32: Rework stm32_pconf_parse_conf() Antonio Borneo
2024-10-22 15:56 ` [PATCH 06/14] pinctrl: stm32: Support IO synchronization parameters Antonio Borneo
2024-10-22 15:56 ` [PATCH 07/14] dt-bindings: pinctrl: stm32: support " Antonio Borneo
2024-10-23 8:49 ` Krzysztof Kozlowski
2024-10-24 22:38 ` Linus Walleij
2024-10-31 13:42 ` Antonio Borneo
2024-11-01 10:24 ` Linus Walleij
2024-10-22 15:56 ` Antonio Borneo [this message]
2024-10-22 15:56 ` [PATCH 09/14] pinctrl: stm32: Allow compile as module for stm32mp257 Antonio Borneo
2024-10-22 15:56 ` [PATCH 10/14] pinctrl: stm32: Add stm32mp215 pinctrl support Antonio Borneo
2024-10-22 15:56 ` [PATCH 11/14] dt-bindings: pinctrl: stm32: support for stm32mp215 and additional packages Antonio Borneo
2024-10-23 8:51 ` Krzysztof Kozlowski
2024-10-23 10:08 ` Antonio Borneo
2024-10-24 13:25 ` Krzysztof Kozlowski
2024-10-22 15:56 ` [PATCH 12/14] pinctrl: stm32: Add stm32mp235 pinctrl support Antonio Borneo
2024-10-22 15:56 ` [PATCH 13/14] dt-bindings: pinctrl: stm32: add support for stm32mp235 Antonio Borneo
2024-10-23 8:52 ` Krzysztof Kozlowski
2024-10-22 15:56 ` [PATCH 14/14] pinctrl: stm32: Add new package to stm32mp257 pinctrl support Antonio Borneo
2024-10-24 22:20 ` [PATCH 00/14] pinctrl: stm32: Add new features and support for more SoC Linus Walleij
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241022155658.1647350-9-antonio.borneo@foss.st.com \
--to=antonio.borneo@foss.st.com \
--cc=alexandre.torgue@foss.st.com \
--cc=amelie.delaunay@foss.st.com \
--cc=catalin.marinas@arm.com \
--cc=cheick.traore@foss.st.com \
--cc=clement.legoffic@foss.st.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=fabien.dessenne@foss.st.com \
--cc=gatien.chevallier@foss.st.com \
--cc=krzk+dt@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=robh@kernel.org \
--cc=stephane.danieau@foss.st.com \
--cc=valentin.caron@foss.st.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®