Skip to contentSkip to conversation

drivers/soc/litex: remove 8-bit subregister option

PATCH Superseded Gabriel Somlo 2 participants 3 messages May 21, 2021 – May 26, 2021 Litex platform

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers/soc/litex: remove 8-bit subregister option

Since upstream LiteX recommends that Linux support be limited to designs configured with 32-bit CSR subregisters (see commit a2b71fde in upstream LiteX, https://github.com/enjoy-digital/litex), remove the option to select 8-bit subregisters, significantly reducing the complexity of LiteX CSR (MMIO register) accessor methods.

NOTE: for details on the underlying mechanics of LiteX CSR registers, see https://github.com/enjoy-digital/litex/wiki/CSR-Bus or the original LiteX accessors (litex/soc/software/include/hw/common.h in the upstream repository).

Cc Stafford Horne <[email protected]>
Cc Florent Kermarrec <[email protected]>
Cc Mateusz Holenko <[email protected]>
Cc Joel Stanley <[email protected]>
---
 drivers/soc/litex/Kconfig |  12 -----
 include/linux/litex.h     | 100 +++++++-------------------------------
 2 files changed, 17 insertions(+), 95 deletions(-)
drivers/soc/litex/Kconfig +0 -12
index e7011d665b15..e6ba3573a772 100644
@@ -17,16 +17,4 @@ config LITEX_SOC_CONTROLLER
 	  All drivers that use functions from litex.h must depend on
 	  LITEX.
 
-config LITEX_SUBREG_SIZE
-	int "Size of a LiteX CSR subregister, in bytes"
-	depends on LITEX
-	range 1 4
-	default 4
-	help
-	LiteX MMIO registers (referred to as Configuration and Status
-	registers, or CSRs) are spread across adjacent 8- or 32-bit
-	subregisters, located at 32-bit aligned MMIO addresses. Use
-	this to select the appropriate size (1 or 4 bytes) matching
-	your particular LiteX build.
-
 endmenu
include/linux/litex.h +17 -83

145 lines not on this page · raw message

Signature · 1 line
2.31.1
#1 lore raw
Quoted 21 lines · Gabriel Somlo

Since upstream LiteX recommends that Linux support be limited to designs configured with 32-bit CSR subregisters (see commit a2b71fde in upstream LiteX, https://github.com/enjoy-digital/litex), remove the option to select 8-bit subregisters, significantly reducing the complexity of LiteX CSR (MMIO register) accessor methods.

NOTE: for details on the underlying mechanics of LiteX CSR registers, see https://github.com/enjoy-digital/litex/wiki/CSR-Bus or the original LiteX accessors (litex/soc/software/include/hw/common.h in the upstream repository).

Cc Stafford Horne <[email protected]>
Cc Florent Kermarrec <[email protected]>
Cc Mateusz Holenko <[email protected]>
Cc Joel Stanley <[email protected]>
---
 drivers/soc/litex/Kconfig |  12 -----
 include/linux/litex.h     | 100 +++++++-------------------------------
 2 files changed, 17 insertions(+), 95 deletions(-)

...

include/linux/litex.h static inline u32 _read_litex_subregister(void __iomem *addr) · line 67

Quoted 6 lines

static inline void litex_write64(void __iomem *reg, u64 val) {

include/linux/litex.h +2 -1
-	_litex_set_reg(reg, sizeof(u64), val);
+	_write_litex_subregister(val >> LITEX_SUBREG_SIZE_BIT, reg);
+	_write_litex_subregister(val, reg + LITEX_SUBREG_ALIGN);
 }

I wonder if it would be more clear to remove the macros and just write as:

static inline void litex_write64(void __iomem *reg, u64 val)

{
	_litex_set_reg(reg, sizeof(u64), val);
	_write_litex_subregister(val >> 32, reg);
	_write_litex_subregister(val, reg + 0x4);
}
Quoted 14 lines

static inline u8 litex_read8(void __iomem *reg)
{

include/linux/litex.h +2 -2
-	return _litex_get_reg(reg, sizeof(u8));
+	return _read_litex_subregister(reg);
 }
 
 static inline u16 litex_read16(void __iomem *reg)
 {
-	return _litex_get_reg(reg, sizeof(u16));
+	return _read_litex_subregister(reg);
 }
 
 static inline u32 litex_read32(void __iomem *reg)
 {

include/linux/litex.h static inline u32 _read_litex_subregister(void __iomem *addr) · line 88

Quoted 10 lines
include/linux/litex.h +3 -2
-	return _litex_get_reg(reg, sizeof(u32));
+	return _read_litex_subregister(reg);
 }
 
 static inline u64 litex_read64(void __iomem *reg)
 {
-	return _litex_get_reg(reg, sizeof(u64));
+	return ((u64)_read_litex_subregister(reg) << LITEX_SUBREG_SIZE_BIT) |
+		_read_litex_subregister(reg + LITEX_SUBREG_ALIGN);
 }

Same here.

This all looks good to me. Just a bit of style preference/question for discussion, for me it's easier to read without the macro's but it just may be me. The macro's make sense when they could change, but now it's just something to double check when reading the code.

Though they are used here in the init code which we could remove too now:

pr_info("LiteX SoC Controller driver initialized: subreg:%d, align:%d",
LITEX_SUBREG_SIZE, LITEX_SUBREG_ALIGN);

-Stafford

Quoted 4 lines

#endif /* _LINUX_LITEX_H */

Signature · 1 line
2.31.1
#2 lore raw
Quoted 73 lines · Stafford Horne
Quoted 21 lines · Gabriel Somlo

Since upstream LiteX recommends that Linux support be limited to designs configured with 32-bit CSR subregisters (see commit a2b71fde in upstream LiteX, https://github.com/enjoy-digital/litex), remove the option to select 8-bit subregisters, significantly reducing the complexity of LiteX CSR (MMIO register) accessor methods.

NOTE: for details on the underlying mechanics of LiteX CSR registers, see https://github.com/enjoy-digital/litex/wiki/CSR-Bus or the original LiteX accessors (litex/soc/software/include/hw/common.h in the upstream repository).

Cc Stafford Horne <[email protected]>
Cc Florent Kermarrec <[email protected]>
Cc Mateusz Holenko <[email protected]>
Cc Joel Stanley <[email protected]>
---
 drivers/soc/litex/Kconfig |  12 -----
 include/linux/litex.h     | 100 +++++++-------------------------------
 2 files changed, 17 insertions(+), 95 deletions(-)

...

include/linux/litex.h static inline u32 _read_litex_subregister(void __iomem *addr) · line 67

Quoted 6 lines

static inline void litex_write64(void __iomem *reg, u64 val) {

include/linux/litex.h +2 -1
-	_litex_set_reg(reg, sizeof(u64), val);
+	_write_litex_subregister(val >> LITEX_SUBREG_SIZE_BIT, reg);
+	_write_litex_subregister(val, reg + LITEX_SUBREG_ALIGN);
 }

I wonder if it would be more clear to remove the macros and just write as:

static inline void litex_write64(void __iomem *reg, u64 val)

{
	_litex_set_reg(reg, sizeof(u64), val);
	_write_litex_subregister(val >> 32, reg);
	_write_litex_subregister(val, reg + 0x4);
}
Quoted 14 lines

static inline u8 litex_read8(void __iomem *reg)
{

include/linux/litex.h +2 -2
-	return _litex_get_reg(reg, sizeof(u8));
+	return _read_litex_subregister(reg);
 }
 
 static inline u16 litex_read16(void __iomem *reg)
 {
-	return _litex_get_reg(reg, sizeof(u16));
+	return _read_litex_subregister(reg);
 }
 
 static inline u32 litex_read32(void __iomem *reg)
 {

include/linux/litex.h static inline u32 _read_litex_subregister(void __iomem *addr) · line 88

Quoted 10 lines
include/linux/litex.h +3 -2
-	return _litex_get_reg(reg, sizeof(u32));
+	return _read_litex_subregister(reg);
 }
 
 static inline u64 litex_read64(void __iomem *reg)
 {
-	return _litex_get_reg(reg, sizeof(u64));
+	return ((u64)_read_litex_subregister(reg) << LITEX_SUBREG_SIZE_BIT) |
+		_read_litex_subregister(reg + LITEX_SUBREG_ALIGN);
 }

Same here.

This all looks good to me. Just a bit of style preference/question for discussion, for me it's easier to read without the macro's but it just may be me. The macro's make sense when they could change, but now it's just something to double check when reading the code.

Quoted 4 lines

Though they are used here in the init code which we could remove too now:

pr_info("LiteX SoC Controller driver initialized: subreg:%d, align:%d",
LITEX_SUBREG_SIZE, LITEX_SUBREG_ALIGN);

Since nobody else seems to have any strong feelings on the topic, I'll just send out a v2 with the changes suggested above in a few minutes.

Thanks,
--Gabriel