2020-10-29 08:27:01

by Evan Green

[permalink] [raw]
Subject: [PATCH v3 0/4] nvmem: qfprom: Avoid untouchable regions

Certain fuses are protected by the XPU such that the AP cannot
access them. Attempting to do so causes an SError. Introduce an
SoC-specific compatible string, and introduce support into the
nvmem core to avoid accessing specified regions. Then use those
new elements in the qfprom driver to avoid SErrors when usermode
accesses certain registers.

Changes in v3:
- Fixed example (Doug and rob-bot)
- Use min()/max() macros instead of defining my own (Doug)
- Comment changes to indicate sorting (Doug)
- Add function to validate keepouts are proper (Doug)

Changes in v2:
- Add other soc compatible strings (Doug)
- Fix compatible string definition (Doug)
- Introduced keepout regions into the core (Srini)
- Use new core support in qfprom (Srini)

Evan Green (4):
dt-bindings: nvmem: Add soc qfprom compatible strings
arm64: dts: qcom: sc7180: Add soc-specific qfprom compat string
nvmem: core: Add support for keepout regions
nvmem: qfprom: Don't touch certain fuses

.../bindings/nvmem/qcom,qfprom.yaml | 17 +-
arch/arm64/boot/dts/qcom/sc7180.dtsi | 2 +-
drivers/nvmem/core.c | 153 +++++++++++++++++-
drivers/nvmem/qfprom.c | 30 ++++
include/linux/nvmem-provider.h | 17 ++
5 files changed, 211 insertions(+), 8 deletions(-)

--
2.26.2


2020-10-29 10:03:42

by Evan Green

[permalink] [raw]
Subject: [PATCH v3 2/4] arm64: dts: qcom: sc7180: Add soc-specific qfprom compat string

Add the soc-specific compatible string so that it can be matched
more specifically now that the driver cares which SoC it's on.

Signed-off-by: Evan Green <[email protected]>
Reviewed-by: Douglas Anderson <[email protected]>
---

(no changes since v1)

arch/arm64/boot/dts/qcom/sc7180.dtsi | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/boot/dts/qcom/sc7180.dtsi b/arch/arm64/boot/dts/qcom/sc7180.dtsi
index 6fcffd588a7d6..f5ef2cb6e68c2 100644
--- a/arch/arm64/boot/dts/qcom/sc7180.dtsi
+++ b/arch/arm64/boot/dts/qcom/sc7180.dtsi
@@ -660,7 +660,7 @@ gcc: clock-controller@100000 {
};

qfprom: efuse@784000 {
- compatible = "qcom,qfprom";
+ compatible = "qcom,sc7180-qfprom", "qcom,qfprom";
reg = <0 0x00784000 0 0x8ff>,
<0 0x00780000 0 0x7a0>,
<0 0x00782000 0 0x100>,
--
2.26.2

2020-10-29 10:03:44

by Evan Green

[permalink] [raw]
Subject: [PATCH v3 4/4] nvmem: qfprom: Don't touch certain fuses

Some fuse ranges are protected by the XPU such that the AP cannot
access them. Attempting to do so causes an SError. Use the newly
introduced per-soc compatible string, and the newly introduced
nvmem keepout support to attach the set of regions
we should not access.

Signed-off-by: Evan Green <[email protected]>
Reviewed-by: Douglas Anderson <[email protected]>
---

(no changes since v2)

Changes in v2:
- Use new core support in qfprom (Srini)

drivers/nvmem/qfprom.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)

diff --git a/drivers/nvmem/qfprom.c b/drivers/nvmem/qfprom.c
index 5e9e60e2e591d..6cace24dfbf73 100644
--- a/drivers/nvmem/qfprom.c
+++ b/drivers/nvmem/qfprom.c
@@ -12,6 +12,7 @@
#include <linux/mod_devicetable.h>
#include <linux/nvmem-provider.h>
#include <linux/platform_device.h>
+#include <linux/property.h>
#include <linux/regulator/consumer.h>

/* Blow timer clock frequency in Mhz */
@@ -88,6 +89,28 @@ struct qfprom_touched_values {
u32 timer_val;
};

+/**
+ * struct qfprom_soc_compatible_data - Data matched against the SoC
+ * compatible string.
+ *
+ * @keepout: Array of keepout regions for this SoC.
+ * @nkeepout: Number of elements in the keepout array.
+ */
+struct qfprom_soc_compatible_data {
+ const struct nvmem_keepout *keepout;
+ unsigned int nkeepout;
+};
+
+static const struct nvmem_keepout sc7180_qfprom_keepout[] = {
+ {.start = 0x128, .end = 0x148},
+ {.start = 0x220, .end = 0x228}
+};
+
+static const struct qfprom_soc_compatible_data sc7180_qfprom = {
+ .keepout = sc7180_qfprom_keepout,
+ .nkeepout = ARRAY_SIZE(sc7180_qfprom_keepout)
+};
+
/**
* qfprom_disable_fuse_blowing() - Undo enabling of fuse blowing.
* @priv: Our driver data.
@@ -281,6 +304,7 @@ static int qfprom_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev;
struct resource *res;
struct nvmem_device *nvmem;
+ const struct qfprom_soc_compatible_data *soc_data;
struct qfprom_priv *priv;
int ret;

@@ -299,6 +323,11 @@ static int qfprom_probe(struct platform_device *pdev)
econfig.priv = priv;

priv->dev = dev;
+ soc_data = device_get_match_data(dev);
+ if (soc_data) {
+ econfig.keepout = soc_data->keepout;
+ econfig.nkeepout = soc_data->nkeepout;
+ }

/*
* If more than one region is provided then the OS has the ability
@@ -354,6 +383,7 @@ static int qfprom_probe(struct platform_device *pdev)

static const struct of_device_id qfprom_of_match[] = {
{ .compatible = "qcom,qfprom",},
+ { .compatible = "qcom,sc7180-qfprom", .data = &sc7180_qfprom},
{/* sentinel */},
};
MODULE_DEVICE_TABLE(of, qfprom_of_match);
--
2.26.2

2020-11-02 15:59:57

by Srinivas Kandagatla

[permalink] [raw]
Subject: Re: [PATCH v3 0/4] nvmem: qfprom: Avoid untouchable regions



On 29/10/2020 00:28, Evan Green wrote:
> Certain fuses are protected by the XPU such that the AP cannot
> access them. Attempting to do so causes an SError. Introduce an
> SoC-specific compatible string, and introduce support into the
> nvmem core to avoid accessing specified regions. Then use those
> new elements in the qfprom driver to avoid SErrors when usermode
> accesses certain registers.
>
> Changes in v3:
> - Fixed example (Doug and rob-bot)
> - Use min()/max() macros instead of defining my own (Doug)
> - Comment changes to indicate sorting (Doug)
> - Add function to validate keepouts are proper (Doug)
>
> Changes in v2:
> - Add other soc compatible strings (Doug)
> - Fix compatible string definition (Doug)
> - Introduced keepout regions into the core (Srini)
> - Use new core support in qfprom (Srini)
>
> Evan Green (4):
> dt-bindings: nvmem: Add soc qfprom compatible strings
> arm64: dts: qcom: sc7180: Add soc-specific qfprom compat string
> nvmem: core: Add support for keepout regions
> nvmem: qfprom: Don't touch certain fuses

Except dts patch, I have applied all the patches, dts patch should go
via arm-soc tree!


--srini

>
> .../bindings/nvmem/qcom,qfprom.yaml | 17 +-
> arch/arm64/boot/dts/qcom/sc7180.dtsi | 2 +-
> drivers/nvmem/core.c | 153 +++++++++++++++++-
> drivers/nvmem/qfprom.c | 30 ++++
> include/linux/nvmem-provider.h | 17 ++
> 5 files changed, 211 insertions(+), 8 deletions(-)
>

2020-11-02 22:39:02

by Bjorn Andersson

[permalink] [raw]
Subject: Re: [PATCH v3 0/4] nvmem: qfprom: Avoid untouchable regions

On Mon 02 Nov 09:58 CST 2020, Srinivas Kandagatla wrote:

>
>
> On 29/10/2020 00:28, Evan Green wrote:
> > Certain fuses are protected by the XPU such that the AP cannot
> > access them. Attempting to do so causes an SError. Introduce an
> > SoC-specific compatible string, and introduce support into the
> > nvmem core to avoid accessing specified regions. Then use those
> > new elements in the qfprom driver to avoid SErrors when usermode
> > accesses certain registers.
> >
> > Changes in v3:
> > - Fixed example (Doug and rob-bot)
> > - Use min()/max() macros instead of defining my own (Doug)
> > - Comment changes to indicate sorting (Doug)
> > - Add function to validate keepouts are proper (Doug)
> >
> > Changes in v2:
> > - Add other soc compatible strings (Doug)
> > - Fix compatible string definition (Doug)
> > - Introduced keepout regions into the core (Srini)
> > - Use new core support in qfprom (Srini)
> >
> > Evan Green (4):
> > dt-bindings: nvmem: Add soc qfprom compatible strings
> > arm64: dts: qcom: sc7180: Add soc-specific qfprom compat string
> > nvmem: core: Add support for keepout regions
> > nvmem: qfprom: Don't touch certain fuses
>
> Except dts patch, I have applied all the patches, dts patch should go via
> arm-soc tree!
>

And I've picked the dts patch.

Thank you,
Bjorn

>
> --srini
>
> >
> > .../bindings/nvmem/qcom,qfprom.yaml | 17 +-
> > arch/arm64/boot/dts/qcom/sc7180.dtsi | 2 +-
> > drivers/nvmem/core.c | 153 +++++++++++++++++-
> > drivers/nvmem/qfprom.c | 30 ++++
> > include/linux/nvmem-provider.h | 17 ++
> > 5 files changed, 211 insertions(+), 8 deletions(-)
> >