Skip to contentSkip to conversation

pinctrl: rockchip: fix editing const struct + constify rockchip_pin_ctrl

PATCH Superseded Quentin Schulz 5 participants 33 messages Jan 29, 2025 – Apr 8, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover pinctrl: rockchip: fix editing const struct + constify rockchip_pin_ctrl

While testing some WIP work done by Ilias Apalodimas on guaranteeing read-only memory areas truly are handled as read-only[1], my RK3588 Tiger couldn't reach U-Boot CLI anymore because of the pinctrl driver modifying a const struct rockchip_pin_ctrl, triggering a CPU abort.

Instead of going the lazy way and unconstify it, let's fix the actual issue in play.

The member modified in the const is only ever used for setting a member from another struct (not const that one). However this other member is never read! Therefore we can simply afford to remove it which means the sole reader of the member in the const is now gone, thus making it possible to remove the member from the const struct as well.

This also means we should be able to constify the private data of the controller device for all Rockchip devices, instead of having those only for RK356x, RK3588 and RV1126. With the constify done on top of Ilias branch[1], my PX30 Ringneck, RK3399 Puma and RK3588 Tiger all reach U-Boot CLI. No further test (like booting into Linux userspace) was done.

[1] https://source.denx.de/u-boot/custodians/u-boot-tpm/-/tree/fix_memory_permissions

---
Quentin Schulz (14):
pinctrl: rockchip: remove unused base_pin bank member
pinctrl: rockchip: remove unused nr_pins controller member
pinctrl: rockchip: constify rockchip_pin_ctrl for PX30
pinctrl: rockchip: constify rockchip_pin_ctrl for RK3036
pinctrl: rockchip: constify rockchip_pin_ctrl for RK3066
pinctrl: rockchip: constify rockchip_pin_ctrl for RK3128
pinctrl: rockchip: constify rockchip_pin_ctrl for RK3188
pinctrl: rockchip: constify rockchip_pin_ctrl for RK3228
pinctrl: rockchip: constify rockchip_pin_ctrl for RK3288
pinctrl: rockchip: constify rockchip_pin_ctrl for RK3308
pinctrl: rockchip: constify rockchip_pin_ctrl for RK3328
pinctrl: rockchip: constify rockchip_pin_ctrl for RK3368
pinctrl: rockchip: constify rockchip_pin_ctrl for RK3399
pinctrl: rockchip: constify rockchip_pin_ctrl for RV1108

 drivers/pinctrl/rockchip/pinctrl-px30.c          | 2 +-
 drivers/pinctrl/rockchip/pinctrl-rk3036.c        | 2 +-
 drivers/pinctrl/rockchip/pinctrl-rk3066.c        | 2 +-
 drivers/pinctrl/rockchip/pinctrl-rk3128.c        | 2 +-
 drivers/pinctrl/rockchip/pinctrl-rk3188.c        | 2 +-
 drivers/pinctrl/rockchip/pinctrl-rk322x.c        | 2 +-
 drivers/pinctrl/rockchip/pinctrl-rk3288.c        | 2 +-
 drivers/pinctrl/rockchip/pinctrl-rk3308.c        | 2 +-
 drivers/pinctrl/rockchip/pinctrl-rk3328.c        | 2 +-
 drivers/pinctrl/rockchip/pinctrl-rk3368.c        | 2 +-
 drivers/pinctrl/rockchip/pinctrl-rk3399.c        | 2 +-
 drivers/pinctrl/rockchip/pinctrl-rk3568.c        | 1 -
 drivers/pinctrl/rockchip/pinctrl-rk3588.c        | 1 -
 drivers/pinctrl/rockchip/pinctrl-rockchip-core.c | 2 --
 drivers/pinctrl/rockchip/pinctrl-rockchip.h      | 3 ---
 drivers/pinctrl/rockchip/pinctrl-rv1108.c        | 2 +-
 drivers/pinctrl/rockchip/pinctrl-rv1126.c        | 1 -
 17 files changed, 12 insertions(+), 20 deletions(-)

---
base-commit: a2b489b170f8382f746202c36616eaf2bc38fe86
change-id: 20250129-rockchip-pinctrl-const-f4123019a584

Best regards,

Signature · 1 line
Quentin Schulz <[email protected]>
#1 lore raw

PATCH 1/14 pinctrl: rockchip: remove unused base_pin bank member

From: Quentin Schulz <[email protected]>

Each bank has a base_pin member that is only set in the core and never used, so it can be removed.

---
 drivers/pinctrl/rockchip/pinctrl-rockchip-core.c | 1 -
 drivers/pinctrl/rockchip/pinctrl-rockchip.h      | 2 --
 2 files changed, 3 deletions(-)
drivers/pinctrl/rockchip/pinctrl-rockchip-core.c +0 -1
index d449d07d32e74d1dec1978b1405bec94887908a2..7369fe12b961290742f6ba24fb32b768531f56f9 100644
@@ -543,7 +543,6 @@ static struct rockchip_pin_ctrl *rockchip_pinctrl_get_soc_data(struct udevice *d
 		int bank_pins = 0;
 
 		bank->priv = priv;
-		bank->pin_base = ctrl->nr_pins;
 		ctrl->nr_pins += bank->nr_pins;
 
 		/* calculate iomux and drv offsets */
drivers/pinctrl/rockchip/pinctrl-rockchip.h +0 -2
index df7bc684d29fae4ec650d1e14fe88b35b03244ac..ebd008eede24af32c123634a57f50c0294e76842 100644
@@ -262,7 +262,6 @@ struct rockchip_drv {
 
 /**
  * @priv: common pinctrl private basedata
- * @pin_base: first pin number
  * @nr_pins: number of pins in this bank
  * @name: name of the bank
  * @bank_num: number of the bank, to account for holes
@@ -274,7 +273,6 @@ struct rockchip_drv {
  */
 struct rockchip_pin_bank {
 	struct rockchip_pinctrl_priv	*priv;
-	u32				pin_base;
 	u8				nr_pins;
 	char				*name;
 	u8				bank_num;
Signature · 1 line
2.48.1
Reviewed-by on v1 1/14
#2 lore raw

Re: [PATCH 01/14] pinctrl: rockchip: remove unused base_pin bank member

Quoted 6 lines · Quentin Schulz

From: Quentin Schulz <[email protected]>

Each bank has a base_pin member that is only set in the core and never used, so it can be removed.

Thanks,
- Kever

Quoted 38 lines
---
  drivers/pinctrl/rockchip/pinctrl-rockchip-core.c | 1 -
  drivers/pinctrl/rockchip/pinctrl-rockchip.h      | 2 --
  2 files changed, 3 deletions(-)
drivers/pinctrl/rockchip/pinctrl-rockchip-core.c +0 -1
index d449d07d32e74d1dec1978b1405bec94887908a2..7369fe12b961290742f6ba24fb32b768531f56f9 100644
@@ -543,7 +543,6 @@ static struct rockchip_pin_ctrl *rockchip_pinctrl_get_soc_data(struct udevice *d
  		int bank_pins = 0;
 
  		bank->priv = priv;
-		bank->pin_base = ctrl->nr_pins;
  		ctrl->nr_pins += bank->nr_pins;
 
  		/* calculate iomux and drv offsets */
drivers/pinctrl/rockchip/pinctrl-rockchip.h +0 -2
index df7bc684d29fae4ec650d1e14fe88b35b03244ac..ebd008eede24af32c123634a57f50c0294e76842 100644
@@ -262,7 +262,6 @@ struct rockchip_drv {
 
  /**
   * @priv: common pinctrl private basedata
- * @pin_base: first pin number
   * @nr_pins: number of pins in this bank
   * @name: name of the bank
   * @bank_num: number of the bank, to account for holes
@@ -274,7 +273,6 @@ struct rockchip_drv {
   */
  struct rockchip_pin_bank {
  	struct rockchip_pinctrl_priv	*priv;
-	u32				pin_base;
  	u8				nr_pins;
  	char				*name;
  	u8				bank_num;
#3 lore raw

PATCH 2/14 pinctrl: rockchip: remove unused nr_pins controller member

In reply to Quentin Schulz

From: Quentin Schulz <[email protected]>

Each controller has an nr_pins member that is set either through the rockchip_pin_ctrl struct or from the core (or both).

This is an issue because on RK3568, RK3588 and RV1126, the struct is const, this means it shouldn't be modified at all. This will trigger a CPU abort once we enforce the read-only at the MMU level in a few releases, therefore let's remove this useless (and broken, and soon breaking) code.

---
 drivers/pinctrl/rockchip/pinctrl-rk3568.c        | 1 -
 drivers/pinctrl/rockchip/pinctrl-rk3588.c        | 1 -
 drivers/pinctrl/rockchip/pinctrl-rockchip-core.c | 1 -
 drivers/pinctrl/rockchip/pinctrl-rockchip.h      | 1 -
 drivers/pinctrl/rockchip/pinctrl-rv1126.c        | 1 -
 5 files changed, 5 deletions(-)
drivers/pinctrl/rockchip/pinctrl-rk3568.c +0 -1
index 5deedc648a41950461b6a468e4852fa0a5384207..c8a91b8bb6e925e0f2e7d6cd09f8a06a58be60dd 100644
@@ -345,7 +345,6 @@ static struct rockchip_pin_bank rk3568_pin_banks[] = {
 static const struct rockchip_pin_ctrl rk3568_pin_ctrl = {
 	.pin_banks		= rk3568_pin_banks,
 	.nr_banks		= ARRAY_SIZE(rk3568_pin_banks),
-	.nr_pins		= 160,
 	.grf_mux_offset		= 0x0,
 	.pmu_mux_offset		= 0x0,
 	.iomux_routes		= rk3568_mux_route_data,
drivers/pinctrl/rockchip/pinctrl-rk3588.c +0 -1
index 98ababc7c90700c4b27359fc3625519f20437306..fd8e617b9108c7314b8fdd4bbe1dfae71f1b6449 100644
@@ -324,7 +324,6 @@ static struct rockchip_pin_bank rk3588_pin_banks[] = {
 static const struct rockchip_pin_ctrl rk3588_pin_ctrl = {
 	.pin_banks		= rk3588_pin_banks,
 	.nr_banks		= ARRAY_SIZE(rk3588_pin_banks),
-	.nr_pins		= 160,
 	.set_mux		= rk3588_set_mux,
 	.set_pull		= rk3588_set_pull,
 	.set_drive		= rk3588_set_drive,
drivers/pinctrl/rockchip/pinctrl-rockchip-core.c +0 -1
index 7369fe12b961290742f6ba24fb32b768531f56f9..b87aed709d62d1e85d0d199c2d6c92aeaec67487 100644
@@ -543,7 +543,6 @@ static struct rockchip_pin_ctrl *rockchip_pinctrl_get_soc_data(struct udevice *d
 		int bank_pins = 0;
 
 		bank->priv = priv;
-		ctrl->nr_pins += bank->nr_pins;
 
 		/* calculate iomux and drv offsets */
 		for (j = 0; j < 4; j++) {
drivers/pinctrl/rockchip/pinctrl-rockchip.h +0 -1
index ebd008eede24af32c123634a57f50c0294e76842..2910bbb570d8736487b8cb6c9f87f3e164858b5b 100644
@@ -498,7 +498,6 @@ struct rockchip_mux_route_data {
 struct rockchip_pin_ctrl {
 	struct rockchip_pin_bank	*pin_banks;
 	u32				nr_banks;
-	u32				nr_pins;
 	int				grf_mux_offset;
 	int				pmu_mux_offset;
 	int				grf_drv_offset;
drivers/pinctrl/rockchip/pinctrl-rv1126.c +0 -1
index efa2408b204b421ad1c5a36b039d8c07c5b7237e..3878a5420dcc98f591e4eefadd78a2fe98b61c7e 100644
@@ -381,7 +381,6 @@ static struct rockchip_pin_bank rv1126_pin_banks[] = {
 static const struct rockchip_pin_ctrl rv1126_pin_ctrl = {
 	.pin_banks		= rv1126_pin_banks,
 	.nr_banks		= ARRAY_SIZE(rv1126_pin_banks),
-	.nr_pins		= 130,
 	.grf_mux_offset		= 0x10004, /* mux offset from GPIO0_D0 */
 	.pmu_mux_offset		= 0x0,
 	.iomux_routes		= rv1126_mux_route_data,
Signature · 1 line
2.48.1
Reviewed-by on v1 2/14
#4 lore raw

Re: [PATCH 02/14] pinctrl: rockchip: remove unused nr_pins controller member

Quoted 5 lines · Quentin Schulz

From: Quentin Schulz <[email protected]>

Each controller has an nr_pins member that is set either through the rockchip_pin_ctrl struct or from the core (or both).

Quoted 7 lines

This is an issue because on RK3568, RK3588 and RV1126, the struct is const, this means it shouldn't be modified at all. This will trigger a CPU abort once we enforce the read-only at the MMU level in a few releases, therefore let's remove this useless (and broken, and soon breaking) code.

Thanks,
- Kever

Quoted 69 lines
---
  drivers/pinctrl/rockchip/pinctrl-rk3568.c        | 1 -
  drivers/pinctrl/rockchip/pinctrl-rk3588.c        | 1 -
  drivers/pinctrl/rockchip/pinctrl-rockchip-core.c | 1 -
  drivers/pinctrl/rockchip/pinctrl-rockchip.h      | 1 -
  drivers/pinctrl/rockchip/pinctrl-rv1126.c        | 1 -
  5 files changed, 5 deletions(-)
drivers/pinctrl/rockchip/pinctrl-rk3568.c +0 -1
index 5deedc648a41950461b6a468e4852fa0a5384207..c8a91b8bb6e925e0f2e7d6cd09f8a06a58be60dd 100644
@@ -345,7 +345,6 @@ static struct rockchip_pin_bank rk3568_pin_banks[] = {
  static const struct rockchip_pin_ctrl rk3568_pin_ctrl = {
  	.pin_banks		= rk3568_pin_banks,
  	.nr_banks		= ARRAY_SIZE(rk3568_pin_banks),
-	.nr_pins		= 160,
  	.grf_mux_offset		= 0x0,
  	.pmu_mux_offset		= 0x0,
  	.iomux_routes		= rk3568_mux_route_data,
drivers/pinctrl/rockchip/pinctrl-rk3588.c +0 -1
index 98ababc7c90700c4b27359fc3625519f20437306..fd8e617b9108c7314b8fdd4bbe1dfae71f1b6449 100644
@@ -324,7 +324,6 @@ static struct rockchip_pin_bank rk3588_pin_banks[] = {
  static const struct rockchip_pin_ctrl rk3588_pin_ctrl = {
  	.pin_banks		= rk3588_pin_banks,
  	.nr_banks		= ARRAY_SIZE(rk3588_pin_banks),
-	.nr_pins		= 160,
  	.set_mux		= rk3588_set_mux,
  	.set_pull		= rk3588_set_pull,
  	.set_drive		= rk3588_set_drive,
drivers/pinctrl/rockchip/pinctrl-rockchip-core.c +0 -1
index 7369fe12b961290742f6ba24fb32b768531f56f9..b87aed709d62d1e85d0d199c2d6c92aeaec67487 100644
@@ -543,7 +543,6 @@ static struct rockchip_pin_ctrl *rockchip_pinctrl_get_soc_data(struct udevice *d
  		int bank_pins = 0;
 
  		bank->priv = priv;
-		ctrl->nr_pins += bank->nr_pins;
 
  		/* calculate iomux and drv offsets */
  		for (j = 0; j < 4; j++) {
drivers/pinctrl/rockchip/pinctrl-rockchip.h +0 -1
index ebd008eede24af32c123634a57f50c0294e76842..2910bbb570d8736487b8cb6c9f87f3e164858b5b 100644
@@ -498,7 +498,6 @@ struct rockchip_mux_route_data {
  struct rockchip_pin_ctrl {
  	struct rockchip_pin_bank	*pin_banks;
  	u32				nr_banks;
-	u32				nr_pins;
  	int				grf_mux_offset;
  	int				pmu_mux_offset;
  	int				grf_drv_offset;
drivers/pinctrl/rockchip/pinctrl-rv1126.c +0 -1
index efa2408b204b421ad1c5a36b039d8c07c5b7237e..3878a5420dcc98f591e4eefadd78a2fe98b61c7e 100644
@@ -381,7 +381,6 @@ static struct rockchip_pin_bank rv1126_pin_banks[] = {
  static const struct rockchip_pin_ctrl rv1126_pin_ctrl = {
  	.pin_banks		= rv1126_pin_banks,
  	.nr_banks		= ARRAY_SIZE(rv1126_pin_banks),
-	.nr_pins		= 130,
  	.grf_mux_offset		= 0x10004, /* mux offset from GPIO0_D0 */
  	.pmu_mux_offset		= 0x0,
  	.iomux_routes		= rv1126_mux_route_data,
#5 lore raw

PATCH 3/14 pinctrl: rockchip: constify rockchip_pin_ctrl for PX30

In reply to Quentin Schulz

From: Quentin Schulz <[email protected]>

There's no need to modify private data from the controller, so let's make that struct const.

---
 drivers/pinctrl/rockchip/pinctrl-px30.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/rockchip/pinctrl-px30.c +1 -1
index cc7885bae40802eccfc2cad377727da9ee899139..4595d8a4a23fbf1299ab382fb92eca32527ae637 100644
@@ -324,7 +324,7 @@ static struct rockchip_pin_bank px30_pin_banks[] = {
 			    ),
 };
 
-static struct rockchip_pin_ctrl px30_pin_ctrl = {
+static const struct rockchip_pin_ctrl px30_pin_ctrl = {
 	.pin_banks		= px30_pin_banks,
 	.nr_banks		= ARRAY_SIZE(px30_pin_banks),
 	.grf_mux_offset		= 0x0,
Signature · 1 line
2.48.1
Reviewed-by on v1 3/14
#6 lore raw

Re: [PATCH 03/14] pinctrl: rockchip: constify rockchip_pin_ctrl for PX30

Quoted 6 lines · Quentin Schulz

From: Quentin Schulz <[email protected]>

There's no need to modify private data from the controller, so let's make that struct const.

Thanks,
- Kever

Quoted 18 lines
---
  drivers/pinctrl/rockchip/pinctrl-px30.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/rockchip/pinctrl-px30.c +1 -1
index cc7885bae40802eccfc2cad377727da9ee899139..4595d8a4a23fbf1299ab382fb92eca32527ae637 100644
@@ -324,7 +324,7 @@ static struct rockchip_pin_bank px30_pin_banks[] = {
  			    ),
  };
 
-static struct rockchip_pin_ctrl px30_pin_ctrl = {
+static const struct rockchip_pin_ctrl px30_pin_ctrl = {
  	.pin_banks		= px30_pin_banks,
  	.nr_banks		= ARRAY_SIZE(px30_pin_banks),
  	.grf_mux_offset		= 0x0,
#7 lore raw

PATCH 4/14 pinctrl: rockchip: constify rockchip_pin_ctrl for RK3036

In reply to Quentin Schulz

From: Quentin Schulz <[email protected]>

There's no need to modify private data from the controller, so let's make that struct const.

---
 drivers/pinctrl/rockchip/pinctrl-rk3036.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/rockchip/pinctrl-rk3036.c +1 -1
index b14386ccd937d2fcced72b6c9be6f7809194d3c1..8d0c0e0b6552a28e10758eff178e56e1dd0f865e 100644
@@ -80,7 +80,7 @@ static struct rockchip_pin_bank rk3036_pin_banks[] = {
 	PIN_BANK(2, 32, "gpio2"),
 };
 
-static struct rockchip_pin_ctrl rk3036_pin_ctrl = {
+static const struct rockchip_pin_ctrl rk3036_pin_ctrl = {
 	.pin_banks		= rk3036_pin_banks,
 	.nr_banks		= ARRAY_SIZE(rk3036_pin_banks),
 	.grf_mux_offset		= 0xa8,
Signature · 1 line
2.48.1
Reviewed-by on v1 4/14
#8 lore raw

Re: [PATCH 04/14] pinctrl: rockchip: constify rockchip_pin_ctrl for RK3036

Quoted 6 lines · Quentin Schulz

From: Quentin Schulz <[email protected]>

There's no need to modify private data from the controller, so let's make that struct const.

Thanks,
- Kever

Quoted 18 lines
---
  drivers/pinctrl/rockchip/pinctrl-rk3036.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/rockchip/pinctrl-rk3036.c +1 -1
index b14386ccd937d2fcced72b6c9be6f7809194d3c1..8d0c0e0b6552a28e10758eff178e56e1dd0f865e 100644
@@ -80,7 +80,7 @@ static struct rockchip_pin_bank rk3036_pin_banks[] = {
  	PIN_BANK(2, 32, "gpio2"),
  };
 
-static struct rockchip_pin_ctrl rk3036_pin_ctrl = {
+static const struct rockchip_pin_ctrl rk3036_pin_ctrl = {
  	.pin_banks		= rk3036_pin_banks,
  	.nr_banks		= ARRAY_SIZE(rk3036_pin_banks),
  	.grf_mux_offset		= 0xa8,
#9 lore raw

PATCH 5/14 pinctrl: rockchip: constify rockchip_pin_ctrl for RK3066

In reply to Quentin Schulz

From: Quentin Schulz <[email protected]>

There's no need to modify private data from the controller, so let's make that struct const.

---
 drivers/pinctrl/rockchip/pinctrl-rk3066.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/rockchip/pinctrl-rk3066.c +1 -1
index 60e088a9a6f0d9133cd0822a9f4816cea18a524d..f773f2a3dab86dc866965cdcfd9b56da9e777acc 100644
@@ -82,7 +82,7 @@ static struct rockchip_pin_bank rk3066_pin_banks[] = {
 	PIN_BANK(6, 16, "gpio6"),
 };
 
-static struct rockchip_pin_ctrl rk3066_pin_ctrl = {
+static const struct rockchip_pin_ctrl rk3066_pin_ctrl = {
 	.pin_banks		= rk3066_pin_banks,
 	.nr_banks		= ARRAY_SIZE(rk3066_pin_banks),
 	.grf_mux_offset		= 0xa8,
Signature · 1 line
2.48.1
Reviewed-by on v1 5/14
#10 lore raw

Re: [PATCH 05/14] pinctrl: rockchip: constify rockchip_pin_ctrl for RK3066

Quoted 6 lines · Quentin Schulz

From: Quentin Schulz <[email protected]>

There's no need to modify private data from the controller, so let's make that struct const.

Thanks,
- Kever

Quoted 18 lines
---
  drivers/pinctrl/rockchip/pinctrl-rk3066.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/rockchip/pinctrl-rk3066.c +1 -1
index 60e088a9a6f0d9133cd0822a9f4816cea18a524d..f773f2a3dab86dc866965cdcfd9b56da9e777acc 100644
@@ -82,7 +82,7 @@ static struct rockchip_pin_bank rk3066_pin_banks[] = {
  	PIN_BANK(6, 16, "gpio6"),
  };
 
-static struct rockchip_pin_ctrl rk3066_pin_ctrl = {
+static const struct rockchip_pin_ctrl rk3066_pin_ctrl = {
  	.pin_banks		= rk3066_pin_banks,
  	.nr_banks		= ARRAY_SIZE(rk3066_pin_banks),
  	.grf_mux_offset		= 0xa8,
#11 lore raw

PATCH 6/14 pinctrl: rockchip: constify rockchip_pin_ctrl for RK3128

In reply to Quentin Schulz

From: Quentin Schulz <[email protected]>

There's no need to modify private data from the controller, so let's make that struct const.

---
 drivers/pinctrl/rockchip/pinctrl-rk3128.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/rockchip/pinctrl-rk3128.c +1 -1
index d00fc3da8b234667a86d0afea10e47b700cb1e00..9f9c358694ac615f78011b196c22e1b597771c97 100644
@@ -171,7 +171,7 @@ static struct rockchip_pin_bank rk3128_pin_banks[] = {
 	PIN_BANK(3, 32, "gpio3"),
 };
 
-static struct rockchip_pin_ctrl rk3128_pin_ctrl = {
+static const struct rockchip_pin_ctrl rk3128_pin_ctrl = {
 	.pin_banks		= rk3128_pin_banks,
 	.nr_banks		= ARRAY_SIZE(rk3128_pin_banks),
 	.grf_mux_offset		= 0xa8,
Signature · 1 line
2.48.1
Reviewed-by on v1 6/14
#12 lore raw

Re: [PATCH 06/14] pinctrl: rockchip: constify rockchip_pin_ctrl for RK3128

Quoted 6 lines · Quentin Schulz

From: Quentin Schulz <[email protected]>

There's no need to modify private data from the controller, so let's make that struct const.

Thanks,
- Kever

Quoted 18 lines
---
  drivers/pinctrl/rockchip/pinctrl-rk3128.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/rockchip/pinctrl-rk3128.c +1 -1
index d00fc3da8b234667a86d0afea10e47b700cb1e00..9f9c358694ac615f78011b196c22e1b597771c97 100644
@@ -171,7 +171,7 @@ static struct rockchip_pin_bank rk3128_pin_banks[] = {
  	PIN_BANK(3, 32, "gpio3"),
  };
 
-static struct rockchip_pin_ctrl rk3128_pin_ctrl = {
+static const struct rockchip_pin_ctrl rk3128_pin_ctrl = {
  	.pin_banks		= rk3128_pin_banks,
  	.nr_banks		= ARRAY_SIZE(rk3128_pin_banks),
  	.grf_mux_offset		= 0xa8,
#13 lore raw

PATCH 7/14 pinctrl: rockchip: constify rockchip_pin_ctrl for RK3188

In reply to Quentin Schulz

From: Quentin Schulz <[email protected]>

There's no need to modify private data from the controller, so let's make that struct const.

---
 drivers/pinctrl/rockchip/pinctrl-rk3188.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/rockchip/pinctrl-rk3188.c +1 -1
index 83db51f66ae43c713a3f80a5442d1f8467a918e9..3a93db5622d70b85dafeea54e064d6df3551f35d 100644
@@ -105,7 +105,7 @@ static struct rockchip_pin_bank rk3188_pin_banks[] = {
 	PIN_BANK(3, 32, "gpio3"),
 };
 
-static struct rockchip_pin_ctrl rk3188_pin_ctrl = {
+static const struct rockchip_pin_ctrl rk3188_pin_ctrl = {
 	.pin_banks		= rk3188_pin_banks,
 	.nr_banks		= ARRAY_SIZE(rk3188_pin_banks),
 	.grf_mux_offset		= 0x60,
Signature · 1 line
2.48.1
Reviewed-by on v1 7/14
#14 lore raw

Re: [PATCH 07/14] pinctrl: rockchip: constify rockchip_pin_ctrl for RK3188

Quoted 6 lines · Quentin Schulz

From: Quentin Schulz <[email protected]>

There's no need to modify private data from the controller, so let's make that struct const.

Thanks,
- Kever

Quoted 18 lines
---
  drivers/pinctrl/rockchip/pinctrl-rk3188.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/rockchip/pinctrl-rk3188.c +1 -1
index 83db51f66ae43c713a3f80a5442d1f8467a918e9..3a93db5622d70b85dafeea54e064d6df3551f35d 100644
@@ -105,7 +105,7 @@ static struct rockchip_pin_bank rk3188_pin_banks[] = {
  	PIN_BANK(3, 32, "gpio3"),
  };
 
-static struct rockchip_pin_ctrl rk3188_pin_ctrl = {
+static const struct rockchip_pin_ctrl rk3188_pin_ctrl = {
  	.pin_banks		= rk3188_pin_banks,
  	.nr_banks		= ARRAY_SIZE(rk3188_pin_banks),
  	.grf_mux_offset		= 0x60,
#15 lore raw

PATCH 8/14 pinctrl: rockchip: constify rockchip_pin_ctrl for RK3228

In reply to Quentin Schulz

From: Quentin Schulz <[email protected]>

There's no need to modify private data from the controller, so let's make that struct const.

---
 drivers/pinctrl/rockchip/pinctrl-rk322x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/rockchip/pinctrl-rk322x.c +1 -1
index b804597c048415f3875222b201442fc025b35658..a80978685d4c84edf4297e24958b52a147b3c1f7 100644
@@ -257,7 +257,7 @@ static struct rockchip_pin_bank rk3228_pin_banks[] = {
 	PIN_BANK(3, 32, "gpio3"),
 };
 
-static struct rockchip_pin_ctrl rk3228_pin_ctrl = {
+static const struct rockchip_pin_ctrl rk3228_pin_ctrl = {
 	.pin_banks		= rk3228_pin_banks,
 	.nr_banks		= ARRAY_SIZE(rk3228_pin_banks),
 	.grf_mux_offset		= 0x0,
Signature · 1 line
2.48.1
Reviewed-by on v1 8/14
#16 lore raw

Re: [PATCH 08/14] pinctrl: rockchip: constify rockchip_pin_ctrl for RK3228

Quoted 6 lines · Quentin Schulz

From: Quentin Schulz <[email protected]>

There's no need to modify private data from the controller, so let's make that struct const.

Thanks,
- Kever

Quoted 18 lines
---
  drivers/pinctrl/rockchip/pinctrl-rk322x.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/rockchip/pinctrl-rk322x.c +1 -1
index b804597c048415f3875222b201442fc025b35658..a80978685d4c84edf4297e24958b52a147b3c1f7 100644
@@ -257,7 +257,7 @@ static struct rockchip_pin_bank rk3228_pin_banks[] = {
  	PIN_BANK(3, 32, "gpio3"),
  };
 
-static struct rockchip_pin_ctrl rk3228_pin_ctrl = {
+static const struct rockchip_pin_ctrl rk3228_pin_ctrl = {
  	.pin_banks		= rk3228_pin_banks,
  	.nr_banks		= ARRAY_SIZE(rk3228_pin_banks),
  	.grf_mux_offset		= 0x0,
#17 lore raw

PATCH 9/14 pinctrl: rockchip: constify rockchip_pin_ctrl for RK3288

In reply to Quentin Schulz

From: Quentin Schulz <[email protected]>

There's no need to modify private data from the controller, so let's make that struct const.

---
 drivers/pinctrl/rockchip/pinctrl-rk3288.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/rockchip/pinctrl-rk3288.c +1 -1
index 3870c1b7a341f998cc0b3cfcaa3a0acbdd0daa39..d3ad1f70e5d60929fafff533c41bd66d1afb3401 100644
@@ -212,7 +212,7 @@ static struct rockchip_pin_bank rk3288_pin_banks[] = {
 	PIN_BANK(8, 16, "gpio8"),
 };
 
-static struct rockchip_pin_ctrl rk3288_pin_ctrl = {
+static const struct rockchip_pin_ctrl rk3288_pin_ctrl = {
 	.pin_banks		= rk3288_pin_banks,
 	.nr_banks		= ARRAY_SIZE(rk3288_pin_banks),
 	.grf_mux_offset		= 0x0,
Signature · 1 line
2.48.1
Reviewed-by on v1 9/14
#18 lore raw

Re: [PATCH 09/14] pinctrl: rockchip: constify rockchip_pin_ctrl for RK3288

Quoted 6 lines · Quentin Schulz

From: Quentin Schulz <[email protected]>

There's no need to modify private data from the controller, so let's make that struct const.

Thanks,
- Kever

Quoted 18 lines
---
  drivers/pinctrl/rockchip/pinctrl-rk3288.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/rockchip/pinctrl-rk3288.c +1 -1
index 3870c1b7a341f998cc0b3cfcaa3a0acbdd0daa39..d3ad1f70e5d60929fafff533c41bd66d1afb3401 100644
@@ -212,7 +212,7 @@ static struct rockchip_pin_bank rk3288_pin_banks[] = {
  	PIN_BANK(8, 16, "gpio8"),
  };
 
-static struct rockchip_pin_ctrl rk3288_pin_ctrl = {
+static const struct rockchip_pin_ctrl rk3288_pin_ctrl = {
  	.pin_banks		= rk3288_pin_banks,
  	.nr_banks		= ARRAY_SIZE(rk3288_pin_banks),
  	.grf_mux_offset		= 0x0,
#19 lore raw

PATCH 10/14 pinctrl: rockchip: constify rockchip_pin_ctrl for RK3308

In reply to Quentin Schulz

From: Quentin Schulz <[email protected]>

There's no need to modify private data from the controller, so let's make that struct const.

---
 drivers/pinctrl/rockchip/pinctrl-rk3308.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/rockchip/pinctrl-rk3308.c +1 -1
index 2cd91b10a3bdbb55cf1e1a56a1b3a240a2899047..5c0e34a7baad835c54f6975017d7e183db5cd84d 100644
@@ -421,7 +421,7 @@ static struct rockchip_pin_bank rk3308_pin_banks[] = {
 					     IOMUX_8WIDTH_2BIT),
 };
 
-static struct rockchip_pin_ctrl rk3308_pin_ctrl = {
+static const struct rockchip_pin_ctrl rk3308_pin_ctrl = {
 	.pin_banks		= rk3308_pin_banks,
 	.nr_banks		= ARRAY_SIZE(rk3308_pin_banks),
 	.grf_mux_offset		= 0x0,
Signature · 1 line
2.48.1
Reviewed-by on v1 10/14
#20 lore raw

Re: [PATCH 10/14] pinctrl: rockchip: constify rockchip_pin_ctrl for RK3308

Quoted 6 lines · Quentin Schulz

From: Quentin Schulz <[email protected]>

There's no need to modify private data from the controller, so let's make that struct const.

Thanks,
- Kever

Quoted 18 lines
---
  drivers/pinctrl/rockchip/pinctrl-rk3308.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/rockchip/pinctrl-rk3308.c +1 -1
index 2cd91b10a3bdbb55cf1e1a56a1b3a240a2899047..5c0e34a7baad835c54f6975017d7e183db5cd84d 100644
@@ -421,7 +421,7 @@ static struct rockchip_pin_bank rk3308_pin_banks[] = {
  					     IOMUX_8WIDTH_2BIT),
  };
 
-static struct rockchip_pin_ctrl rk3308_pin_ctrl = {
+static const struct rockchip_pin_ctrl rk3308_pin_ctrl = {
  	.pin_banks		= rk3308_pin_banks,
  	.nr_banks		= ARRAY_SIZE(rk3308_pin_banks),
  	.grf_mux_offset		= 0x0,
#21 lore raw

PATCH 11/14 pinctrl: rockchip: constify rockchip_pin_ctrl for RK3328

In reply to Quentin Schulz

From: Quentin Schulz <[email protected]>

There's no need to modify private data from the controller, so let's make that struct const.

---
 drivers/pinctrl/rockchip/pinctrl-rk3328.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/rockchip/pinctrl-rk3328.c +1 -1
index 47c2e923a1bb5292bdbe934a91fdb78404c37327..cc9f20a2e43e66d19375b5a112a4abddd81fa2ff 100644
@@ -285,7 +285,7 @@ static struct rockchip_pin_bank rk3328_pin_banks[] = {
 			     0),
 };
 
-static struct rockchip_pin_ctrl rk3328_pin_ctrl = {
+static const struct rockchip_pin_ctrl rk3328_pin_ctrl = {
 	.pin_banks		= rk3328_pin_banks,
 	.nr_banks		= ARRAY_SIZE(rk3328_pin_banks),
 	.grf_mux_offset		= 0x0,
Signature · 1 line
2.48.1
Reviewed-by on v1 11/14
#22 lore raw

Re: [PATCH 11/14] pinctrl: rockchip: constify rockchip_pin_ctrl for RK3328

Quoted 6 lines · Quentin Schulz

From: Quentin Schulz <[email protected]>

There's no need to modify private data from the controller, so let's make that struct const.

Thanks,
- Kever

Quoted 18 lines
---
  drivers/pinctrl/rockchip/pinctrl-rk3328.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/rockchip/pinctrl-rk3328.c +1 -1
index 47c2e923a1bb5292bdbe934a91fdb78404c37327..cc9f20a2e43e66d19375b5a112a4abddd81fa2ff 100644
@@ -285,7 +285,7 @@ static struct rockchip_pin_bank rk3328_pin_banks[] = {
  			     0),
  };
 
-static struct rockchip_pin_ctrl rk3328_pin_ctrl = {
+static const struct rockchip_pin_ctrl rk3328_pin_ctrl = {
  	.pin_banks		= rk3328_pin_banks,
  	.nr_banks		= ARRAY_SIZE(rk3328_pin_banks),
  	.grf_mux_offset		= 0x0,
#23 lore raw

PATCH 12/14 pinctrl: rockchip: constify rockchip_pin_ctrl for RK3368

In reply to Quentin Schulz

From: Quentin Schulz <[email protected]>

There's no need to modify private data from the controller, so let's make that struct const.

---
 drivers/pinctrl/rockchip/pinctrl-rk3368.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/rockchip/pinctrl-rk3368.c +1 -1
index 9ae06ed19e9cda76f6d466fce2e01f48520a668a..aaf24719a16e191478ea407846bd50fc4cd29210 100644
@@ -152,7 +152,7 @@ static struct rockchip_pin_bank rk3368_pin_banks[] = {
 	PIN_BANK(3, 32, "gpio3"),
 };
 
-static struct rockchip_pin_ctrl rk3368_pin_ctrl = {
+static const struct rockchip_pin_ctrl rk3368_pin_ctrl = {
 	.pin_banks		= rk3368_pin_banks,
 	.nr_banks		= ARRAY_SIZE(rk3368_pin_banks),
 	.grf_mux_offset		= 0x0,
Signature · 1 line
2.48.1
Reviewed-by on v1 12/14
#24 lore raw

Re: [PATCH 12/14] pinctrl: rockchip: constify rockchip_pin_ctrl for RK3368

Quoted 6 lines · Quentin Schulz

From: Quentin Schulz <[email protected]>

There's no need to modify private data from the controller, so let's make that struct const.

Thanks,
- Kever

Quoted 18 lines
---
  drivers/pinctrl/rockchip/pinctrl-rk3368.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/rockchip/pinctrl-rk3368.c +1 -1
index 9ae06ed19e9cda76f6d466fce2e01f48520a668a..aaf24719a16e191478ea407846bd50fc4cd29210 100644
@@ -152,7 +152,7 @@ static struct rockchip_pin_bank rk3368_pin_banks[] = {
  	PIN_BANK(3, 32, "gpio3"),
  };
 
-static struct rockchip_pin_ctrl rk3368_pin_ctrl = {
+static const struct rockchip_pin_ctrl rk3368_pin_ctrl = {
  	.pin_banks		= rk3368_pin_banks,
  	.nr_banks		= ARRAY_SIZE(rk3368_pin_banks),
  	.grf_mux_offset		= 0x0,
#25 lore raw

PATCH 13/14 pinctrl: rockchip: constify rockchip_pin_ctrl for RK3399

In reply to Quentin Schulz

From: Quentin Schulz <[email protected]>

There's no need to modify private data from the controller, so let's make that struct const.

---
 drivers/pinctrl/rockchip/pinctrl-rk3399.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/rockchip/pinctrl-rk3399.c +1 -1
index b7a5092c032ba3bac0889921d9421bf0d3cd7277..928ed59aec6903fafa97ef6c3f95ad22422475fc 100644
@@ -279,7 +279,7 @@ static struct rockchip_pin_bank rk3399_pin_banks[] = {
 			   ),
 };
 
-static struct rockchip_pin_ctrl rk3399_pin_ctrl = {
+static const struct rockchip_pin_ctrl rk3399_pin_ctrl = {
 	.pin_banks		= rk3399_pin_banks,
 	.nr_banks		= ARRAY_SIZE(rk3399_pin_banks),
 	.grf_mux_offset		= 0xe000,
Signature · 1 line
2.48.1
Reviewed-by on v1 13/14
#26 lore raw

Re: [PATCH 13/14] pinctrl: rockchip: constify rockchip_pin_ctrl for RK3399

Quoted 6 lines · Quentin Schulz

From: Quentin Schulz <[email protected]>

There's no need to modify private data from the controller, so let's make that struct const.

Thanks,
- Kever

Quoted 18 lines
---
  drivers/pinctrl/rockchip/pinctrl-rk3399.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/rockchip/pinctrl-rk3399.c +1 -1
index b7a5092c032ba3bac0889921d9421bf0d3cd7277..928ed59aec6903fafa97ef6c3f95ad22422475fc 100644
@@ -279,7 +279,7 @@ static struct rockchip_pin_bank rk3399_pin_banks[] = {
  			   ),
  };
 
-static struct rockchip_pin_ctrl rk3399_pin_ctrl = {
+static const struct rockchip_pin_ctrl rk3399_pin_ctrl = {
  	.pin_banks		= rk3399_pin_banks,
  	.nr_banks		= ARRAY_SIZE(rk3399_pin_banks),
  	.grf_mux_offset		= 0xe000,
#27 lore raw

PATCH 14/14 pinctrl: rockchip: constify rockchip_pin_ctrl for RV1108

In reply to Quentin Schulz

From: Quentin Schulz <[email protected]>

There's no need to modify private data from the controller, so let's make that struct const.

---
 drivers/pinctrl/rockchip/pinctrl-rv1108.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/rockchip/pinctrl-rv1108.c +1 -1
index 3eff5f59598c0d9ea9393a1b5e1a82efa8449eb6..780da1e946ea6361fb4c3cad0299296051cee77a 100644
@@ -263,7 +263,7 @@ static struct rockchip_pin_bank rv1108_pin_banks[] = {
 	PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 0, 0, 0, 0),
 };
 
-static struct rockchip_pin_ctrl rv1108_pin_ctrl = {
+static const struct rockchip_pin_ctrl rv1108_pin_ctrl = {
 	.pin_banks		= rv1108_pin_banks,
 	.nr_banks		= ARRAY_SIZE(rv1108_pin_banks),
 	.grf_mux_offset		= 0x10,
Signature · 1 line
2.48.1
Reviewed-by on v1 14/14
#28 lore raw

Re: [PATCH 14/14] pinctrl: rockchip: constify rockchip_pin_ctrl for RV1108

Quoted 6 lines · Quentin Schulz

From: Quentin Schulz <[email protected]>

There's no need to modify private data from the controller, so let's make that struct const.

Thanks,
- Kever

Quoted 18 lines
---
  drivers/pinctrl/rockchip/pinctrl-rv1108.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/rockchip/pinctrl-rv1108.c +1 -1
index 3eff5f59598c0d9ea9393a1b5e1a82efa8449eb6..780da1e946ea6361fb4c3cad0299296051cee77a 100644
@@ -263,7 +263,7 @@ static struct rockchip_pin_bank rv1108_pin_banks[] = {
  	PIN_BANK_IOMUX_FLAGS(3, 32, "gpio3", 0, 0, 0, 0),
  };
 
-static struct rockchip_pin_ctrl rv1108_pin_ctrl = {
+static const struct rockchip_pin_ctrl rv1108_pin_ctrl = {
  	.pin_banks		= rv1108_pin_banks,
  	.nr_banks		= ARRAY_SIZE(rv1108_pin_banks),
  	.grf_mux_offset		= 0x10,
#29 lore raw
In reply to Quentin Schulz

Hi Quentin,

Quoted 21 lines · Quentin Schulz

While testing some WIP work done by Ilias Apalodimas on guaranteeing read-only memory areas truly are handled as read-only[1], my RK3588 Tiger couldn't reach U-Boot CLI anymore because of the pinctrl driver modifying a const struct rockchip_pin_ctrl, triggering a CPU abort.

Instead of going the lazy way and unconstify it, let's fix the actual issue in play.

The member modified in the const is only ever used for setting a member from another struct (not const that one). However this other member is never read! Therefore we can simply afford to remove it which means the sole reader of the member in the const is now gone, thus making it possible to remove the member from the const struct as well.

This also means we should be able to constify the private data of the controller device for all Rockchip devices, instead of having those only for RK356x, RK3588 and RV1126. With the constify done on top of Ilias branch[1], my PX30 Ringneck, RK3399 Puma and RK3588 Tiger all reach U-Boot CLI. No further test (like booting into Linux userspace) was done.

Quoted 7 lines

[1] https://source.denx.de/u-boot/custodians/u-boot-tpm/-/tree/fix_memory_permissions

---
Quentin Schulz (14):
pinctrl: rockchip: remove unused base_pin bank member
pinctrl: rockchip: remove unused nr_pins controller member

pin_base and nr_pins is used after my "rockchip: pinctrl: Add support for pinmux status cmd" series [1].

The pin_base should probably be moved to udevice priv data or similar. nr_pins can probably also be moved to udevice priv data or constify in driver data.

Do you want me to re-work/re-store these fields in a different way once I finally send a v3 of that series?

[1] https://patchwork.ozlabs.org/project/uboot/cover/[email protected]/

Regards,
Jonas

Quoted 36 lines

pinctrl: rockchip: constify rockchip_pin_ctrl for PX30
pinctrl: rockchip: constify rockchip_pin_ctrl for RK3036
pinctrl: rockchip: constify rockchip_pin_ctrl for RK3066
pinctrl: rockchip: constify rockchip_pin_ctrl for RK3128
pinctrl: rockchip: constify rockchip_pin_ctrl for RK3188
pinctrl: rockchip: constify rockchip_pin_ctrl for RK3228
pinctrl: rockchip: constify rockchip_pin_ctrl for RK3288
pinctrl: rockchip: constify rockchip_pin_ctrl for RK3308
pinctrl: rockchip: constify rockchip_pin_ctrl for RK3328
pinctrl: rockchip: constify rockchip_pin_ctrl for RK3368
pinctrl: rockchip: constify rockchip_pin_ctrl for RK3399
pinctrl: rockchip: constify rockchip_pin_ctrl for RV1108

 drivers/pinctrl/rockchip/pinctrl-px30.c          | 2 +-
 drivers/pinctrl/rockchip/pinctrl-rk3036.c        | 2 +-
 drivers/pinctrl/rockchip/pinctrl-rk3066.c        | 2 +-
 drivers/pinctrl/rockchip/pinctrl-rk3128.c        | 2 +-
 drivers/pinctrl/rockchip/pinctrl-rk3188.c        | 2 +-
 drivers/pinctrl/rockchip/pinctrl-rk322x.c        | 2 +-
 drivers/pinctrl/rockchip/pinctrl-rk3288.c        | 2 +-
 drivers/pinctrl/rockchip/pinctrl-rk3308.c        | 2 +-
 drivers/pinctrl/rockchip/pinctrl-rk3328.c        | 2 +-
 drivers/pinctrl/rockchip/pinctrl-rk3368.c        | 2 +-
 drivers/pinctrl/rockchip/pinctrl-rk3399.c        | 2 +-
 drivers/pinctrl/rockchip/pinctrl-rk3568.c        | 1 -
 drivers/pinctrl/rockchip/pinctrl-rk3588.c        | 1 -
 drivers/pinctrl/rockchip/pinctrl-rockchip-core.c | 2 --
 drivers/pinctrl/rockchip/pinctrl-rockchip.h      | 3 ---
 drivers/pinctrl/rockchip/pinctrl-rv1108.c        | 2 +-
 drivers/pinctrl/rockchip/pinctrl-rv1126.c        | 1 -
 17 files changed, 12 insertions(+), 20 deletions(-)

---
base-commit: a2b489b170f8382f746202c36616eaf2bc38fe86
change-id: 20250129-rockchip-pinctrl-const-f4123019a584

Best regards,

#30 lore raw

Hi Jonas,

Quoted 35 lines · Jonas Karlman

Hi Quentin,

Quoted 21 lines · Quentin Schulz

While testing some WIP work done by Ilias Apalodimas on guaranteeing read-only memory areas truly are handled as read-only[1], my RK3588 Tiger couldn't reach U-Boot CLI anymore because of the pinctrl driver modifying a const struct rockchip_pin_ctrl, triggering a CPU abort.

Instead of going the lazy way and unconstify it, let's fix the actual issue in play.

The member modified in the const is only ever used for setting a member from another struct (not const that one). However this other member is never read! Therefore we can simply afford to remove it which means the sole reader of the member in the const is now gone, thus making it possible to remove the member from the const struct as well.

This also means we should be able to constify the private data of the controller device for all Rockchip devices, instead of having those only for RK356x, RK3588 and RV1126. With the constify done on top of Ilias branch[1], my PX30 Ringneck, RK3399 Puma and RK3588 Tiger all reach U-Boot CLI. No further test (like booting into Linux userspace) was done.

Quoted 7 lines

[1] https://source.denx.de/u-boot/custodians/u-boot-tpm/-/tree/fix_memory_permissions

---
Quentin Schulz (14):
pinctrl: rockchip: remove unused base_pin bank member
pinctrl: rockchip: remove unused nr_pins controller member

pin_base and nr_pins is used after my "rockchip: pinctrl: Add support for pinmux status cmd" series [1].

Quoted 7 lines

The pin_base should probably be moved to udevice priv data or similar. nr_pins can probably also be moved to udevice priv data or constify in driver data.

Do you want me to re-work/re-store these fields in a different way once I finally send a v3 of that series?

What I can suggest is to remove the setting of ctrl->nr_pins as I believe we shouldn't be modifying it and we don't need to store it, even in your patch series as we discussed on IRC, and keep pin_base from the bank.

What I can offer instead is to use a local variable to replace the one from the controller struct.

"""

drivers/pinctrl/rockchip/pinctrl-rockchip-core.c +5 -3
index d449d07d32e..14aba6f370b 100644
@@ -531,20 +531,22 @@ static struct rockchip_pin_ctrl *rockchip_pinctrl_get_soc_data(struct udevice *d
 	struct rockchip_pin_ctrl *ctrl =
 			(struct rockchip_pin_ctrl *)dev_get_driver_data(dev);
 	struct rockchip_pin_bank *bank;
-	int grf_offs, pmu_offs, drv_grf_offs, drv_pmu_offs, i, j;
+	int grf_offs, pmu_offs, drv_grf_offs, drv_pmu_offs, ctrl_nr_pins, i, j;
 
 	grf_offs = ctrl->grf_mux_offset;
 	pmu_offs = ctrl->pmu_mux_offset;
 	drv_pmu_offs = ctrl->pmu_drv_offset;
 	drv_grf_offs = ctrl->grf_drv_offset;
 	bank = ctrl->pin_banks;
+	ctrl_nr_pins = 0;
+
 
 	for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
 		int bank_pins = 0;
 
 		bank->priv = priv;
-		bank->pin_base = ctrl->nr_pins;
-		ctrl->nr_pins += bank->nr_pins;
+		bank->pin_base = ctrl_nr_pins;
+		ctrl_nr_pins += bank->nr_pins;
 
 		/* calculate iomux and drv offsets */
 		for (j = 0; j < 4; j++) {

"""

Something like that to replace patches 1 and 2. This should allow you to keep working on your other patch series without me making it too much more difficult for you to rebase?

We need this patch series in before https://lore.kernel.org/u-boot/[email protected]/T/#t gets is otherwise we don't be able to boot anymore on RK356x, RK3588 and RV1126. I don't think there's going to be much bikeshedding or controversy about my series here (in v2 if you agree with the above diff), the pinctrl series from last August seems like it could be opening many can of worms so better not rebase this series on top of that series. Do you agree with that?

Cheers,
Quentin

#31 lore raw

Hi Quentin,

Quoted 89 lines · Quentin Schulz

Hi Jonas,

Quoted 35 lines · Jonas Karlman

Hi Quentin,

Quoted 21 lines · Quentin Schulz

While testing some WIP work done by Ilias Apalodimas on guaranteeing read-only memory areas truly are handled as read-only[1], my RK3588 Tiger couldn't reach U-Boot CLI anymore because of the pinctrl driver modifying a const struct rockchip_pin_ctrl, triggering a CPU abort.

Instead of going the lazy way and unconstify it, let's fix the actual issue in play.

The member modified in the const is only ever used for setting a member from another struct (not const that one). However this other member is never read! Therefore we can simply afford to remove it which means the sole reader of the member in the const is now gone, thus making it possible to remove the member from the const struct as well.

This also means we should be able to constify the private data of the controller device for all Rockchip devices, instead of having those only for RK356x, RK3588 and RV1126. With the constify done on top of Ilias branch[1], my PX30 Ringneck, RK3399 Puma and RK3588 Tiger all reach U-Boot CLI. No further test (like booting into Linux userspace) was done.

Quoted 7 lines

[1] https://source.denx.de/u-boot/custodians/u-boot-tpm/-/tree/fix_memory_permissions

---
Quentin Schulz (14):
pinctrl: rockchip: remove unused base_pin bank member
pinctrl: rockchip: remove unused nr_pins controller member

pin_base and nr_pins is used after my "rockchip: pinctrl: Add support for pinmux status cmd" series [1].

Quoted 7 lines

The pin_base should probably be moved to udevice priv data or similar. nr_pins can probably also be moved to udevice priv data or constify in driver data.

Do you want me to re-work/re-store these fields in a different way once I finally send a v3 of that series?

What I can suggest is to remove the setting of ctrl->nr_pins as I believe we shouldn't be modifying it and we don't need to store it, even in your patch series as we discussed on IRC, and keep pin_base from the bank.

What I can offer instead is to use a local variable to replace the one from the controller struct.

"""

drivers/pinctrl/rockchip/pinctrl-rockchip-core.c +5 -3
index d449d07d32e..14aba6f370b 100644
@@ -531,20 +531,22 @@ static struct rockchip_pin_ctrl 
 *rockchip_pinctrl_get_soc_data(struct udevice *d
  	struct rockchip_pin_ctrl *ctrl =
  			(struct rockchip_pin_ctrl *)dev_get_driver_data(dev);
  	struct rockchip_pin_bank *bank;
-	int grf_offs, pmu_offs, drv_grf_offs, drv_pmu_offs, i, j;
+	int grf_offs, pmu_offs, drv_grf_offs, drv_pmu_offs, ctrl_nr_pins, i, j;
 
  	grf_offs = ctrl->grf_mux_offset;
  	pmu_offs = ctrl->pmu_mux_offset;
  	drv_pmu_offs = ctrl->pmu_drv_offset;
  	drv_grf_offs = ctrl->grf_drv_offset;
  	bank = ctrl->pin_banks;
+	ctrl_nr_pins = 0;
+
 
  	for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
  		int bank_pins = 0;
 
  		bank->priv = priv;
-		bank->pin_base = ctrl->nr_pins;
-		ctrl->nr_pins += bank->nr_pins;
+		bank->pin_base = ctrl_nr_pins;
+		ctrl_nr_pins += bank->nr_pins;
 
  		/* calculate iomux and drv offsets */

for (j = 0; j < 4; j++) {
"""

Quoted 3 lines

Something like that to replace patches 1 and 2. This should allow you to keep working on your other patch series without me making it too much more difficult for you to rebase?

Thanks for taking a look, and I agree this should help when I pick up and re-spin my series.

Quoted 9 lines

We need this patch series in before
https://lore.kernel.org/u-boot/[email protected]/T/#t
gets is otherwise we don't be able to boot anymore on RK356x, RK3588 and RV1126. I don't think there's going to be much bikeshedding or controversy about my series here (in v2 if you agree with the above diff), the pinctrl series from last August seems like it could be opening many can of worms so better not rebase this series on top of that series. Do you agree with that?

I fully agree, better to get this in first, I will try to re-spin my series on top of this sometime later once this has landed.

Regards,
Jonas

Quoted 3 lines

Cheers,
Quentin

#32 lore raw

Hi Jonas,

Quoted 110 lines · Jonas Karlman

Hi Quentin,

Quoted 87 lines · Quentin Schulz

Hi Jonas,

Quoted 35 lines · Jonas Karlman

Hi Quentin,

Quoted 21 lines · Quentin Schulz

While testing some WIP work done by Ilias Apalodimas on guaranteeing read-only memory areas truly are handled as read-only[1], my RK3588 Tiger couldn't reach U-Boot CLI anymore because of the pinctrl driver modifying a const struct rockchip_pin_ctrl, triggering a CPU abort.

Instead of going the lazy way and unconstify it, let's fix the actual issue in play.

The member modified in the const is only ever used for setting a member from another struct (not const that one). However this other member is never read! Therefore we can simply afford to remove it which means the sole reader of the member in the const is now gone, thus making it possible to remove the member from the const struct as well.

This also means we should be able to constify the private data of the controller device for all Rockchip devices, instead of having those only for RK356x, RK3588 and RV1126. With the constify done on top of Ilias branch[1], my PX30 Ringneck, RK3399 Puma and RK3588 Tiger all reach U-Boot CLI. No further test (like booting into Linux userspace) was done.

Quoted 7 lines

[1] https://source.denx.de/u-boot/custodians/u-boot-tpm/-/tree/fix_memory_permissions

---
Quentin Schulz (14):
pinctrl: rockchip: remove unused base_pin bank member
pinctrl: rockchip: remove unused nr_pins controller member

pin_base and nr_pins is used after my "rockchip: pinctrl: Add support for pinmux status cmd" series [1].

Quoted 7 lines

The pin_base should probably be moved to udevice priv data or similar. nr_pins can probably also be moved to udevice priv data or constify in driver data.

Do you want me to re-work/re-store these fields in a different way once I finally send a v3 of that series?

What I can suggest is to remove the setting of ctrl->nr_pins as I believe we shouldn't be modifying it and we don't need to store it, even in your patch series as we discussed on IRC, and keep pin_base from the bank.

What I can offer instead is to use a local variable to replace the one from the controller struct.

"""

drivers/pinctrl/rockchip/pinctrl-rockchip-core.c +5 -3
index d449d07d32e..14aba6f370b 100644
@@ -531,20 +531,22 @@ static struct rockchip_pin_ctrl
 *rockchip_pinctrl_get_soc_data(struct udevice *d
      struct rockchip_pin_ctrl *ctrl =
                      (struct rockchip_pin_ctrl *)dev_get_driver_data(dev);
      struct rockchip_pin_bank *bank;
-     int grf_offs, pmu_offs, drv_grf_offs, drv_pmu_offs, i, j;
+     int grf_offs, pmu_offs, drv_grf_offs, drv_pmu_offs, ctrl_nr_pins, i, j;
 
      grf_offs = ctrl->grf_mux_offset;
      pmu_offs = ctrl->pmu_mux_offset;
      drv_pmu_offs = ctrl->pmu_drv_offset;
      drv_grf_offs = ctrl->grf_drv_offset;
      bank = ctrl->pin_banks;
+     ctrl_nr_pins = 0;
+
 
      for (i = 0; i < ctrl->nr_banks; ++i, ++bank) {
              int bank_pins = 0;
 
              bank->priv = priv;
-             bank->pin_base = ctrl->nr_pins;
-             ctrl->nr_pins += bank->nr_pins;
+             bank->pin_base = ctrl_nr_pins;
+             ctrl_nr_pins += bank->nr_pins;
 
              /* calculate iomux and drv offsets */
              for (j = 0; j < 4; j++) {
Quoted 5 lines

"""

Something like that to replace patches 1 and 2. This should allow you to keep working on your other patch series without me making it too much more difficult for you to rebase?

Thanks for taking a look, and I agree this should help when I pick up and re-spin my series.

Quoted 9 lines

We need this patch series in before
https://lore.kernel.org/u-boot/[email protected]/T/#t
gets is otherwise we don't be able to boot anymore on RK356x, RK3588 and RV1126. I don't think there's going to be much bikeshedding or controversy about my series here (in v2 if you agree with the above diff), the pinctrl series from last August seems like it could be opening many can of worms so better not rebase this series on top of that series. Do you agree with that?

Quoted 2 lines

I fully agree, better to get this in first, I will try to re-spin my series on top of this sometime later once this has landed.

Ok, I'll post this after the weekend in case I get more review comments. Keep in mind that i'll hide it behind a Kconfig option for now, since we seem to have enough cases of code writing const variables

Cheers
/Ilias

Quoted 8 lines

Regards,
Jonas

Quoted 3 lines

Cheers,
Quentin