Skip to contentSkip to conversation

mfd: intel-m10-bmc: fix the register access range

PATCH Superseded Xu Yilun 2 participants 7 messages Jan 20, 2021 – Jan 22, 2021

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Xu Yilun

author maintainer
#0 lore raw

PATCH 1/2 mfd: intel-m10-bmc: fix the register access range

This patch fixes the max register address of MAX 10 BMC. The range 0x20000000 ~ 0x200000fc are for control registers of the QSPI flash controller, which are not accessible to host.

---
 include/linux/mfd/intel-m10-bmc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/mfd/intel-m10-bmc.h +1 -1
index c8ef2f1..06da62c 100644
@@ -11,7 +11,7 @@
 
 #define M10BMC_LEGACY_SYS_BASE		0x300400
 #define M10BMC_SYS_BASE			0x300800
-#define M10BMC_MEM_END			0x200000fc
+#define M10BMC_MEM_END			0x1fffffff
 
 /* Register offset of system registers */
 #define NIOS2_FW_VERSION		0x0
Signature · 1 line
2.7.4
author maintainer
#1 lore raw

PATCH 2/2 mfd: intel-m10-bmc: add access table configuration to the regmap

From: Matthew Gerlach <[email protected]>

This patch adds access tables to the MAX 10 BMC regmap. This prevents the host from accessing the unwanted I/O space. It also filters out the invalid outputs when reading the regmap debugfs interface.

---
 drivers/mfd/intel-m10-bmc.c       | 14 ++++++++++++++
 include/linux/mfd/intel-m10-bmc.h |  5 ++++-
 2 files changed, 18 insertions(+), 1 deletion(-)
drivers/mfd/intel-m10-bmc.c +14 -0
index b84579b..0ae3053 100644
@@ -23,10 +23,24 @@ static struct mfd_cell m10bmc_pacn3000_subdevs[] = {
 	{ .name = "n3000bmc-secure" },
 };
 
+static const struct regmap_range m10bmc_regmap_range[] = {
+	regmap_reg_range(M10BMC_LEGACY_SYS_BASE + M10BMC_BUILD_VER,
+			 M10BMC_LEGACY_SYS_BASE + M10BMC_BUILD_VER),
+	regmap_reg_range(M10BMC_SYS_BASE, M10BMC_SYS_END),
+	regmap_reg_range(M10BMC_FLASH_BASE, M10BMC_FLASH_END),
+};
+
+static const struct regmap_access_table m10bmc_access_table = {
+	.yes_ranges	= m10bmc_regmap_range,
+	.n_yes_ranges	= ARRAY_SIZE(m10bmc_regmap_range),
+};
+
 static struct regmap_config intel_m10bmc_regmap_config = {
 	.reg_bits = 32,
 	.val_bits = 32,
 	.reg_stride = 4,
+	.wr_table = &m10bmc_access_table,
+	.rd_table = &m10bmc_access_table,
 	.max_register = M10BMC_MEM_END,
 };
 
include/linux/mfd/intel-m10-bmc.h +4 -1
index 06da62c..4ba88ed 100644
@@ -11,7 +11,10 @@
 
 #define M10BMC_LEGACY_SYS_BASE		0x300400
 #define M10BMC_SYS_BASE			0x300800
-#define M10BMC_MEM_END			0x1fffffff
+#define M10BMC_SYS_END			0x300fff
+#define M10BMC_FLASH_BASE		0x10000000
+#define M10BMC_FLASH_END		0x1fffffff
+#define M10BMC_MEM_END			M10BMC_FLASH_END
 
 /* Register offset of system registers */
 #define NIOS2_FW_VERSION		0x0
Signature · 1 line
2.7.4
reviewer
#2 lore raw

Re: [PATCH 2/2] mfd: intel-m10-bmc: add access table configuration to the regmap

Quoted 18 lines · Xu Yilun

From: Matthew Gerlach <[email protected]>

This patch adds access tables to the MAX 10 BMC regmap. This prevents the host from accessing the unwanted I/O space. It also filters out the invalid outputs when reading the regmap debugfs interface.

---
 drivers/mfd/intel-m10-bmc.c       | 14 ++++++++++++++
 include/linux/mfd/intel-m10-bmc.h |  5 ++++-
 2 files changed, 18 insertions(+), 1 deletion(-)
drivers/mfd/intel-m10-bmc.c +0 -0
index b84579b..0ae3053 100644

drivers/mfd/intel-m10-bmc.c static struct mfd_cell m10bmc_pacn3000_subdevs[] = { · line 28

Quoted 6 lines
drivers/mfd/intel-m10-bmc.c +3 -0
@@ -23,10 +23,24 @@ static struct mfd_cell m10bmc_pacn3000_subdevs[] = {
 	{ .name = "n3000bmc-secure" },
 };
 
+static const struct regmap_range m10bmc_regmap_range[] = {
+	regmap_reg_range(M10BMC_LEGACY_SYS_BASE + M10BMC_BUILD_VER,
+			 M10BMC_LEGACY_SYS_BASE + M10BMC_BUILD_VER),

If this is the only value in the legacy map to be accessed, could it have its own #define ?

Something like

#define M10BMC_LEGACY_BUILD_VER ?

Quoted 5 lines
drivers/mfd/intel-m10-bmc.c +5 -0
+	regmap_reg_range(M10BMC_SYS_BASE, M10BMC_SYS_END),
+	regmap_reg_range(M10BMC_FLASH_BASE, M10BMC_FLASH_END),
+};
+
+static const struct regmap_access_table m10bmc_access_table = {

drivers/mfd/intel-m10-bmc.c static struct mfd_cell m10bmc_pacn3000_subdevs[] = { · line 43

Quoted 10 lines
drivers/mfd/intel-m10-bmc.c +6 -0
+	.yes_ranges	= m10bmc_regmap_range,
+	.n_yes_ranges	= ARRAY_SIZE(m10bmc_regmap_range),
+};
+
 static struct regmap_config intel_m10bmc_regmap_config = {
 	.reg_bits = 32,
 	.val_bits = 32,
 	.reg_stride = 4,
+	.wr_table = &m10bmc_access_table,
+	.rd_table = &m10bmc_access_table,

The legacy build ver should only be read, so shouldn't these tables be different ?

Tom

Quoted 19 lines
drivers/mfd/intel-m10-bmc.c +0 -0
 	.max_register = M10BMC_MEM_END,
 };
 
include/linux/mfd/intel-m10-bmc.h +4 -1
index 06da62c..4ba88ed 100644
@@ -11,7 +11,10 @@
 
 #define M10BMC_LEGACY_SYS_BASE		0x300400
 #define M10BMC_SYS_BASE			0x300800
-#define M10BMC_MEM_END			0x1fffffff
+#define M10BMC_SYS_END			0x300fff
+#define M10BMC_FLASH_BASE		0x10000000
+#define M10BMC_FLASH_END		0x1fffffff
+#define M10BMC_MEM_END			M10BMC_FLASH_END
 
 /* Register offset of system registers */
 #define NIOS2_FW_VERSION		0x0
author maintainer
#3 lore raw

Re: [PATCH 2/2] mfd: intel-m10-bmc: add access table configuration to the regmap

Quoted 29 lines · Tom Rix
Quoted 18 lines · Xu Yilun

From: Matthew Gerlach <[email protected]>

This patch adds access tables to the MAX 10 BMC regmap. This prevents the host from accessing the unwanted I/O space. It also filters out the invalid outputs when reading the regmap debugfs interface.

---
 drivers/mfd/intel-m10-bmc.c       | 14 ++++++++++++++
 include/linux/mfd/intel-m10-bmc.h |  5 ++++-
 2 files changed, 18 insertions(+), 1 deletion(-)
drivers/mfd/intel-m10-bmc.c +0 -0
index b84579b..0ae3053 100644

drivers/mfd/intel-m10-bmc.c static struct mfd_cell m10bmc_pacn3000_subdevs[] = { · line 28

Quoted 6 lines
drivers/mfd/intel-m10-bmc.c +3 -0
@@ -23,10 +23,24 @@ static struct mfd_cell m10bmc_pacn3000_subdevs[] = {
 	{ .name = "n3000bmc-secure" },
 };
 
+static const struct regmap_range m10bmc_regmap_range[] = {
+	regmap_reg_range(M10BMC_LEGACY_SYS_BASE + M10BMC_BUILD_VER,
+			 M10BMC_LEGACY_SYS_BASE + M10BMC_BUILD_VER),

If this is the only value in the legacy map to be accessed, could it have its own #define ?

Quoted 3 lines

Something like

#define M10BMC_LEGACY_BUILD_VER ?

Yes, it could be more clear. I'll change it.

Quoted 10 lines
Quoted 10 lines
drivers/mfd/intel-m10-bmc.c +9 -0
+	regmap_reg_range(M10BMC_SYS_BASE, M10BMC_SYS_END),
+	regmap_reg_range(M10BMC_FLASH_BASE, M10BMC_FLASH_END),
+};
+
+static const struct regmap_access_table m10bmc_access_table = {
+	.yes_ranges	= m10bmc_regmap_range,
+	.n_yes_ranges	= ARRAY_SIZE(m10bmc_regmap_range),
+};
+
Quoted 8 lines

drivers/mfd/intel-m10-bmc.c static struct mfd_cell m10bmc_pacn3000_subdevs[] = { · line 43

Quoted 6 lines
drivers/mfd/intel-m10-bmc.c +2 -0
 static struct regmap_config intel_m10bmc_regmap_config = {
 	.reg_bits = 32,
 	.val_bits = 32,
 	.reg_stride = 4,
+	.wr_table = &m10bmc_access_table,
+	.rd_table = &m10bmc_access_table,

The legacy build ver should only be read, so shouldn't these tables be different ?

I'm not sure if a register could be regarded as writable if hardware ensures writing it has no effect but makes no harm. Usually these registers are marked as RO in spec.

I think it could be quite common case in hardware design. But it could be trivial if we pick every such register out of wr_table. I just want to define the valid reg range.

So could I keep the current implementation?

Thanks,
Yilun

reviewer
#4 lore raw

Re: [PATCH 2/2] mfd: intel-m10-bmc: add access table configuration to the regmap

Quoted 53 lines · Xu Yilun
Quoted 22 lines · Tom Rix
Quoted 21 lines · Xu Yilun

From: Matthew Gerlach <[email protected]>

This patch adds access tables to the MAX 10 BMC regmap. This prevents the host from accessing the unwanted I/O space. It also filters out the invalid outputs when reading the regmap debugfs interface.

---
 drivers/mfd/intel-m10-bmc.c       | 14 ++++++++++++++
 include/linux/mfd/intel-m10-bmc.h |  5 ++++-
 2 files changed, 18 insertions(+), 1 deletion(-)
drivers/mfd/intel-m10-bmc.c +0 -0
index b84579b..0ae3053 100644
@@ -23,10 +23,24 @@ static struct mfd_cell m10bmc_pacn3000_subdevs[] = {
 	{ .name = "n3000bmc-secure" },
 };
 
Quoted 8 lines

drivers/mfd/intel-m10-bmc.c static struct mfd_cell m10bmc_pacn3000_subdevs[] = { · line 28

Quoted 3 lines
drivers/mfd/intel-m10-bmc.c +3 -0
+static const struct regmap_range m10bmc_regmap_range[] = {
+	regmap_reg_range(M10BMC_LEGACY_SYS_BASE + M10BMC_BUILD_VER,
+			 M10BMC_LEGACY_SYS_BASE + M10BMC_BUILD_VER),

If this is the only value in the legacy map to be accessed, could it have its own #define ?

Something like

#define M10BMC_LEGACY_BUILD_VER ?

Yes, it could be more clear. I'll change it.

Quoted 8 lines
Quoted 8 lines
drivers/mfd/intel-m10-bmc.c +8 -0
+	regmap_reg_range(M10BMC_SYS_BASE, M10BMC_SYS_END),
+	regmap_reg_range(M10BMC_FLASH_BASE, M10BMC_FLASH_END),
+};
+
+static const struct regmap_access_table m10bmc_access_table = {
+	.yes_ranges	= m10bmc_regmap_range,
+	.n_yes_ranges	= ARRAY_SIZE(m10bmc_regmap_range),
+};
Quoted 8 lines

drivers/mfd/intel-m10-bmc.c static struct mfd_cell m10bmc_pacn3000_subdevs[] = { · line 43

Quoted 7 lines
drivers/mfd/intel-m10-bmc.c +3 -0
+
 static struct regmap_config intel_m10bmc_regmap_config = {
 	.reg_bits = 32,
 	.val_bits = 32,
 	.reg_stride = 4,
+	.wr_table = &m10bmc_access_table,
+	.rd_table = &m10bmc_access_table,

The legacy build ver should only be read, so shouldn't these tables be different ?

I'm not sure if a register could be regarded as writable if hardware ensures writing it has no effect but makes no harm. Usually these registers are marked as RO in spec.

Quoted 5 lines

I think it could be quite common case in hardware design. But it could be trivial if we pick every such register out of wr_table. I just want to define the valid reg range.

So could I keep the current implementation?

I mean that the write table would not have first element the read table has because it has the single ro entry.

The other ranges i am sure have ro's and are not worth breaking apart.

If something like

.wr_table = &m10bmc_access_table[1] doesn't work or looks to hacky, i don't mind leaving it as-is.

Tom

Quoted 4 lines

Thanks,
Yilun

author maintainer
#5 lore raw

Re: [PATCH 2/2] mfd: intel-m10-bmc: add access table configuration to the regmap

Quoted 61 lines · Tom Rix
Quoted 53 lines · Xu Yilun
Quoted 22 lines · Tom Rix
Quoted 21 lines · Xu Yilun

From: Matthew Gerlach <[email protected]>

This patch adds access tables to the MAX 10 BMC regmap. This prevents the host from accessing the unwanted I/O space. It also filters out the invalid outputs when reading the regmap debugfs interface.

---
 drivers/mfd/intel-m10-bmc.c       | 14 ++++++++++++++
 include/linux/mfd/intel-m10-bmc.h |  5 ++++-
 2 files changed, 18 insertions(+), 1 deletion(-)
drivers/mfd/intel-m10-bmc.c +0 -0
index b84579b..0ae3053 100644
@@ -23,10 +23,24 @@ static struct mfd_cell m10bmc_pacn3000_subdevs[] = {
 	{ .name = "n3000bmc-secure" },
 };
 
Quoted 8 lines

drivers/mfd/intel-m10-bmc.c static struct mfd_cell m10bmc_pacn3000_subdevs[] = { · line 28

Quoted 3 lines
drivers/mfd/intel-m10-bmc.c +3 -0
+static const struct regmap_range m10bmc_regmap_range[] = {
+	regmap_reg_range(M10BMC_LEGACY_SYS_BASE + M10BMC_BUILD_VER,
+			 M10BMC_LEGACY_SYS_BASE + M10BMC_BUILD_VER),

If this is the only value in the legacy map to be accessed, could it have its own #define ?

Something like

#define M10BMC_LEGACY_BUILD_VER ?

Yes, it could be more clear. I'll change it.

Quoted 8 lines
Quoted 8 lines
drivers/mfd/intel-m10-bmc.c +8 -0
+	regmap_reg_range(M10BMC_SYS_BASE, M10BMC_SYS_END),
+	regmap_reg_range(M10BMC_FLASH_BASE, M10BMC_FLASH_END),
+};
+
+static const struct regmap_access_table m10bmc_access_table = {
+	.yes_ranges	= m10bmc_regmap_range,
+	.n_yes_ranges	= ARRAY_SIZE(m10bmc_regmap_range),
+};
Quoted 8 lines

drivers/mfd/intel-m10-bmc.c static struct mfd_cell m10bmc_pacn3000_subdevs[] = { · line 43

Quoted 7 lines
drivers/mfd/intel-m10-bmc.c +3 -0
+
 static struct regmap_config intel_m10bmc_regmap_config = {
 	.reg_bits = 32,
 	.val_bits = 32,
 	.reg_stride = 4,
+	.wr_table = &m10bmc_access_table,
+	.rd_table = &m10bmc_access_table,

The legacy build ver should only be read, so shouldn't these tables be different ?

I'm not sure if a register could be regarded as writable if hardware ensures writing it has no effect but makes no harm. Usually these registers are marked as RO in spec.

Quoted 5 lines

I think it could be quite common case in hardware design. But it could be trivial if we pick every such register out of wr_table. I just want to define the valid reg range.

So could I keep the current implementation?

Quoted 7 lines

I mean that the write table would not have first element the read table has because it has the single ro entry.

The other ranges i am sure have ro's and are not worth breaking apart.

If something like

.wr_table = &m10bmc_access_table[1] doesn't work or looks to hacky, i don't mind leaving it as-is.

It looks hacky to me.

If the first one has to be marked RO, I think it could be like:

static const struct regmap_range m10bmc_regmap_ro_range[] = {
regmap_reg_range(M10BMC_LEGACY_BUILD_VER, M10BMC_LEGACY_BUILD_VER),
};

  static const struct regmap_range m10bmc_regmap_range[] = {
	regmap_reg_range(M10BMC_LEGACY_BUILD_VER, M10BMC_LEGACY_BUILD_VER),
	regmap_reg_range(...),
	...

};

  static const struct regmap_access_table m10bmc_write_table = {
	.yes_ranges     = m10bmc_regmap_range,
	.n_yes_ranges   = ARRAY_SIZE(m10bmc_regmap_range),
	.no_range	= m10bmc_regmap_ro_range,
	.n_no_range	= ARRAY_SIZE(m10bmc_regmap_ro_range),

};

static const struct regmap_access_table m10bmc_read_table = {
.yes_ranges = m10bmc_regmap_range,
.n_yes_ranges = ARRAY_SIZE(m10bmc_regmap_range),
};

But I think this is unnecessary. I feel it is indicating all the other registers are RW in spec, actually they are not. So I tend to keep it simple, just tell the valid range.

Thanks,
Yilun

reviewer Reviewed-by on v1 1/2
#6 lore raw
In reply to Xu Yilun

A side note..

I think it would be good if the intel-m10-bmc.* files were tracked in the MAINTAINERS files.

I was surprised the Lee was the only reviewer.  Maybe Yilun or Matt should also be added.

Quoted 14 lines · Xu Yilun

This patch fixes the max register address of MAX 10 BMC. The range 0x20000000 ~ 0x200000fc are for control registers of the QSPI flash controller, which are not accessible to host.

---
 include/linux/mfd/intel-m10-bmc.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/mfd/intel-m10-bmc.h +0 -0
index c8ef2f1..06da62c 100644

include/linux/mfd/intel-m10-bmc.h line 14

Quoted 5 lines
include/linux/mfd/intel-m10-bmc.h +1 -1
@@ -11,7 +11,7 @@
 
 #define M10BMC_LEGACY_SYS_BASE		0x300400
 #define M10BMC_SYS_BASE			0x300800
-#define M10BMC_MEM_END			0x200000fc
+#define M10BMC_MEM_END			0x1fffffff
Quoted 3 lines
include/linux/mfd/intel-m10-bmc.h +0 -0
 /* Register offset of system registers */
 #define NIOS2_FW_VERSION		0x0