Re: [PATCH v2 1/4] powerpc/code-patching: introduce patch_instructions()

2023-03-10 Thread Christophe Leroy


Le 10/03/2023 à 19:26, Christophe Leroy a écrit :
> 
> 
> Le 09/03/2023 à 19:02, Hari Bathini a écrit :
>> patch_instruction() entails setting up pte, patching the instruction,
>> clearing the pte and flushing the tlb. If multiple instructions need
>> to be patched, every instruction would have to go through the above
>> drill unnecessarily. Instead, introduce function patch_instructions()
>> that patches multiple instructions at one go while setting up the pte,
>> clearing the pte and flushing the tlb only once per page range of
>> instructions. Observed ~5X improvement in speed of execution using
>> patch_instructions() over patch_instructions(), when more instructions
>> are to be patched.
> 
> I get a 13% degradation on the time needed to activate ftrace on a 
> powerpc 8xx.
> 
> Before your patch, activation ftrace takes 550k timebase ticks. After 
> your patch it takes 620k timebase ticks.
> 

More details about the problem:

Before your patch, patch_instruction() is a simple, stackless function 
(Note that the first branch is noped out after startup).

0254 :
  254:  48 00 00 6c b   2c0 
  258:  7c e0 00 a6 mfmsr   r7
  25c:  7c 51 13 a6 mtspr   81,r2
  260:  3d 40 00 00 lis r10,0
262: R_PPC_ADDR16_HA.data
  264:  39 4a 00 00 addir10,r10,0
266: R_PPC_ADDR16_LO.data
  268:  7c 69 1b 78 mr  r9,r3
  26c:  3d 29 40 00 addis   r9,r9,16384
  270:  81 0a 00 08 lwz r8,8(r10)
  274:  55 29 00 26 rlwinm  r9,r9,0,0,19
  278:  81 4a 00 04 lwz r10,4(r10)
  27c:  61 29 01 25 ori r9,r9,293
  280:  91 28 00 00 stw r9,0(r8)
  284:  55 49 00 26 rlwinm  r9,r10,0,0,19
  288:  50 6a 05 3e rlwimi  r10,r3,0,20,31
  28c:  90 8a 00 00 stw r4,0(r10)
  290:  7c 00 50 6c dcbst   0,r10
  294:  7c 00 04 ac hwsync
  298:  7c 00 1f ac icbi0,r3
  29c:  7c 00 04 ac hwsync
  2a0:  4c 00 01 2c isync
  2a4:  38 60 00 00 li  r3,0
  2a8:  39 40 00 00 li  r10,0
  2ac:  91 48 00 00 stw r10,0(r8)
  2b0:  7c 00 4a 64 tlbie   r9,r0
  2b4:  7c 00 04 ac hwsync
  2b8:  7c e0 01 24 mtmsr   r7
  2bc:  4e 80 00 20 blr

  2c0:  90 83 00 00 stw r4,0(r3)
  2c4:  7c 00 18 6c dcbst   0,r3
  2c8:  7c 00 04 ac hwsync
  2cc:  7c 00 1f ac icbi0,r3
  2d0:  7c 00 04 ac hwsync
  2d4:  4c 00 01 2c isync
  2d8:  38 60 00 00 li  r3,0
  2dc:  4e 80 00 20 blr
  2e0:  38 60 ff ff li  r3,-1
  2e4:  4b ff ff c4 b   2a8 
  2e8:  38 60 ff ff li  r3,-1
  2ec:  4e 80 00 20 blr


Once your patch is there, patch_instruction() becomes a function that 
has to step up a stack in order to call __do_patch_instructions().
And __do_patch_instructions() is quite a big function.

022c <__do_patch_instructions>:
  22c:  3d 20 00 00 lis r9,0
22e: R_PPC_ADDR16_HA.data
  230:  39 29 00 00 addir9,r9,0
232: R_PPC_ADDR16_LO.data
  234:  81 69 00 04 lwz r11,4(r9)
  238:  2c 05 00 00 cmpwi   r5,0
  23c:  81 89 00 08 lwz r12,8(r9)
  240:  7c c3 32 14 add r6,r3,r6
  244:  55 6b 00 26 rlwinm  r11,r11,0,0,19
  248:  38 00 00 00 li  r0,0
  24c:  54 6a 05 3e clrlwi  r10,r3,20
  250:  21 0a 10 00 subfic  r8,r10,4096
  254:  7d 03 42 14 add r8,r3,r8
  258:  7c 69 1b 78 mr  r9,r3
  25c:  7f 88 30 40 cmplw   cr7,r8,r6
  260:  3d 29 40 00 addis   r9,r9,16384
  264:  55 29 00 26 rlwinm  r9,r9,0,0,19
  268:  61 29 01 25 ori r9,r9,293
  26c:  91 2c 00 00 stw r9,0(r12)
  270:  7d 4a 5b 78 or  r10,r10,r11
  274:  40 9d 00 08 ble cr7,27c <__do_patch_instructions+0x50>
  278:  7c c8 33 78 mr  r8,r6
  27c:  7f 83 40 40 cmplw   cr7,r3,r8
  280:  40 9c 01 2c bge cr7,3ac <__do_patch_instructions+0x180>
  284:  7c 69 18 f8 not r9,r3
  288:  7d 28 4a 14 add r9,r8,r9
  28c:  55 29 f7 fe rlwinm  r9,r9,30,31,31
  290:  7c e3 50 50 subfr7,r3,r10
  294:  80 a4 00 00 lwz r5,0(r4)
  298:  90 aa 00 00 stw r5,0(r10)
  29c:  7c 00 50 6c dcbst   0,r10
  2a0:  7c 00 04 ac hwsync
  2a4:  7c 00 1f ac icbi0,r3
  2a8:  7c 00 04 ac hwsync
  2ac:  4c 00 01 2c isync
  2b0:  38 63 00 04 addir3,r3,4
  2b4:  40 82 00 08 bne 2bc <__do_patch_instructions+0x90>
  2b8:  38 84 00 04 addir4,r4,4
  2bc:  7f 83 40 40 cmplw   cr7,r3,r8
  2c0:  40 9c 00 a4 bge cr7,364 <__do_patch_instructions+0x138>
  2c4:  2f 89 00 00 cmpwi   cr7,r9,0
  2c8:  41 9e 00 38 beq cr7,300 <__do_patch_instructions+0xd4>
  2cc:  7d 23 3a 14 add r9,r3,r7
  2d0:  81 44 00 00 lwz r10,0(r4)
  2d4:  91 49 00 00 stw r10,0(r9)
  2d8:  7c 00 48 6c dcbst   0,r9
  2dc:  7c 00 04 ac hwsync
  2e0:  7c 00 1f ac icbi0,r3
  2e4:  7c 00 04 ac  

[PATCH 0/2] ppc: simplify sysctl registration

2023-03-10 Thread Luis Chamberlain
We can simplify the way we do sysctl registration both by
reducing the number of lines and also avoiding calllers which
could do recursion. The docs are being updated to help reflect
this better [0].

[0] https://lore.kernel.org/all/20230310223947.3917711-1-mcg...@kernel.org/T/#u 


Luis Chamberlain (2):
  ppc: simplify one-level sysctl registration for
powersave_nap_ctl_table
  ppc: simplify one-level sysctl registration for
nmi_wd_lpm_factor_ctl_table

 arch/powerpc/kernel/idle.c| 10 +-
 arch/powerpc/platforms/pseries/mobility.c | 10 +-
 2 files changed, 2 insertions(+), 18 deletions(-)

-- 
2.39.1



[PATCH 2/2] ppc: simplify one-level sysctl registration for nmi_wd_lpm_factor_ctl_table

2023-03-10 Thread Luis Chamberlain
There is no need to declare an extra tables to just create directory,
this can be easily be done with a prefix path with register_sysctl().

Simplify this registration.

Signed-off-by: Luis Chamberlain 
---
 arch/powerpc/platforms/pseries/mobility.c | 10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/arch/powerpc/platforms/pseries/mobility.c 
b/arch/powerpc/platforms/pseries/mobility.c
index 4cea71aa0f41..2b58e76abef8 100644
--- a/arch/powerpc/platforms/pseries/mobility.c
+++ b/arch/powerpc/platforms/pseries/mobility.c
@@ -62,18 +62,10 @@ static struct ctl_table nmi_wd_lpm_factor_ctl_table[] = {
},
{}
 };
-static struct ctl_table nmi_wd_lpm_factor_sysctl_root[] = {
-   {
-   .procname   = "kernel",
-   .mode   = 0555,
-   .child  = nmi_wd_lpm_factor_ctl_table,
-   },
-   {}
-};
 
 static int __init register_nmi_wd_lpm_factor_sysctl(void)
 {
-   register_sysctl_table(nmi_wd_lpm_factor_sysctl_root);
+   register_sysctl("kernel", nmi_wd_lpm_factor_ctl_table);
 
return 0;
 }
-- 
2.39.1



[PATCH 1/2] ppc: simplify one-level sysctl registration for powersave_nap_ctl_table

2023-03-10 Thread Luis Chamberlain
There is no need to declare an extra tables to just create directory,
this can be easily be done with a prefix path with register_sysctl().

Simplify this registration.

Signed-off-by: Luis Chamberlain 
---
 arch/powerpc/kernel/idle.c | 10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/arch/powerpc/kernel/idle.c b/arch/powerpc/kernel/idle.c
index b9a725abc596..b1c0418b25c8 100644
--- a/arch/powerpc/kernel/idle.c
+++ b/arch/powerpc/kernel/idle.c
@@ -107,19 +107,11 @@ static struct ctl_table powersave_nap_ctl_table[] = {
},
{}
 };
-static struct ctl_table powersave_nap_sysctl_root[] = {
-   {
-   .procname   = "kernel",
-   .mode   = 0555,
-   .child  = powersave_nap_ctl_table,
-   },
-   {}
-};
 
 static int __init
 register_powersave_nap_sysctl(void)
 {
-   register_sysctl_table(powersave_nap_sysctl_root);
+   register_sysctl("kernel", powersave_nap_ctl_table);
 
return 0;
 }
-- 
2.39.1



[PATCH 6/6] bus: fsl-mc: Make remove function return void

2023-03-10 Thread Uwe Kleine-König
From: Uwe Kleine-König 

The value returned by an fsl-mc driver's remove function is mostly
ignored.  (Only an error message is printed if the value is non-zero
and then device removal continues unconditionally.)

So change the prototype of the remove function to return no value. This
way driver authors are not tempted to assume that passing an error to
the upper layer is a good idea. All drivers are adapted accordingly.
There is no intended change of behaviour, all callbacks were prepared to
return 0 before.

Signed-off-by: Uwe Kleine-König 
---
 drivers/bus/fsl-mc/dprc-driver.c| 5 ++---
 drivers/bus/fsl-mc/fsl-mc-allocator.c   | 5 ++---
 drivers/bus/fsl-mc/fsl-mc-bus.c | 5 +
 drivers/crypto/caam/caamalg_qi2.c   | 4 +---
 drivers/dma/fsl-dpaa2-qdma/dpaa2-qdma.c | 4 +---
 drivers/net/ethernet/freescale/dpaa2/dpaa2-eth.c| 4 +---
 drivers/net/ethernet/freescale/dpaa2/dpaa2-ptp.c| 4 +---
 drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c | 4 +---
 drivers/soc/fsl/dpio/dpio-driver.c  | 4 +---
 drivers/vfio/fsl-mc/vfio_fsl_mc.c   | 3 +--
 include/linux/fsl/mc.h  | 2 +-
 11 files changed, 13 insertions(+), 31 deletions(-)

diff --git a/drivers/bus/fsl-mc/dprc-driver.c b/drivers/bus/fsl-mc/dprc-driver.c
index ef4f43f67b80..595d4cecd041 100644
--- a/drivers/bus/fsl-mc/dprc-driver.c
+++ b/drivers/bus/fsl-mc/dprc-driver.c
@@ -835,13 +835,13 @@ EXPORT_SYMBOL_GPL(dprc_cleanup);
  * It tears down the interrupts that were configured for the DPRC device.
  * It destroys the interrupt pool associated with this MC bus.
  */
-static int dprc_remove(struct fsl_mc_device *mc_dev)
+static void dprc_remove(struct fsl_mc_device *mc_dev)
 {
struct fsl_mc_bus *mc_bus = to_fsl_mc_bus(mc_dev);
 
if (!mc_bus->irq_resources) {
dev_err(_dev->dev, "No irq resources, so unbinding the 
device failed\n");
-   return 0;
+   return;
}
 
if (dev_get_msi_domain(_dev->dev))
@@ -852,7 +852,6 @@ static int dprc_remove(struct fsl_mc_device *mc_dev)
dprc_cleanup(mc_dev);
 
dev_info(_dev->dev, "DPRC device unbound from driver");
-   return 0;
 }
 
 static const struct fsl_mc_device_id match_id_table[] = {
diff --git a/drivers/bus/fsl-mc/fsl-mc-allocator.c 
b/drivers/bus/fsl-mc/fsl-mc-allocator.c
index 36f70e5e418b..0ad68099684e 100644
--- a/drivers/bus/fsl-mc/fsl-mc-allocator.c
+++ b/drivers/bus/fsl-mc/fsl-mc-allocator.c
@@ -614,19 +614,18 @@ static int fsl_mc_allocator_probe(struct fsl_mc_device 
*mc_dev)
  * fsl_mc_allocator_remove - callback invoked when an allocatable device is
  * being removed from the system
  */
-static int fsl_mc_allocator_remove(struct fsl_mc_device *mc_dev)
+static void fsl_mc_allocator_remove(struct fsl_mc_device *mc_dev)
 {
int error;
 
if (mc_dev->resource) {
error = fsl_mc_resource_pool_remove_device(mc_dev);
if (error < 0)
-   return 0;
+   return;
}
 
dev_dbg(_dev->dev,
"Allocatable fsl-mc device unbound from fsl_mc_allocator 
driver");
-   return 0;
 }
 
 static const struct fsl_mc_device_id match_id_table[] = {
diff --git a/drivers/bus/fsl-mc/fsl-mc-bus.c b/drivers/bus/fsl-mc/fsl-mc-bus.c
index 1531e6101fb1..08b7dc8f2181 100644
--- a/drivers/bus/fsl-mc/fsl-mc-bus.c
+++ b/drivers/bus/fsl-mc/fsl-mc-bus.c
@@ -454,11 +454,8 @@ static int fsl_mc_driver_remove(struct device *dev)
 {
struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(dev->driver);
struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev);
-   int error;
 
-   error = mc_drv->remove(mc_dev);
-   if (error < 0)
-   dev_err(dev, "%s failed: %d\n", __func__, error);
+   mc_drv->remove(mc_dev);
 
return 0;
 }
diff --git a/drivers/crypto/caam/caamalg_qi2.c 
b/drivers/crypto/caam/caamalg_qi2.c
index 5c8d35edaa1c..9156bbe038b7 100644
--- a/drivers/crypto/caam/caamalg_qi2.c
+++ b/drivers/crypto/caam/caamalg_qi2.c
@@ -5402,7 +5402,7 @@ static int dpaa2_caam_probe(struct fsl_mc_device 
*dpseci_dev)
return err;
 }
 
-static int __cold dpaa2_caam_remove(struct fsl_mc_device *ls_dev)
+static void __cold dpaa2_caam_remove(struct fsl_mc_device *ls_dev)
 {
struct device *dev;
struct dpaa2_caam_priv *priv;
@@ -5443,8 +5443,6 @@ static int __cold dpaa2_caam_remove(struct fsl_mc_device 
*ls_dev)
free_percpu(priv->ppriv);
fsl_mc_portal_free(priv->mc_io);
kmem_cache_destroy(qi_cache);
-
-   return 0;
 }
 
 int dpaa2_caam_enqueue(struct device *dev, struct caam_request *req)
diff --git a/drivers/dma/fsl-dpaa2-qdma/dpaa2-qdma.c 
b/drivers/dma/fsl-dpaa2-qdma/dpaa2-qdma.c
index 8dd40d00a672..a42a37634881 100644
--- a/drivers/dma/fsl-dpaa2-qdma/dpaa2-qdma.c
+++ b/drivers/dma/fsl-dpaa2-qdma/dpaa2-qdma.c
@@ -765,7 +765,7 @@ 

[PATCH 0/6] bus: fsl-mc: Make remove function return void

2023-03-10 Thread Uwe Kleine-König
Hello,

many bus remove functions return an integer which is a historic
misdesign that makes driver authors assume that there is some kind of
error handling in the upper layers. This is wrong however and returning
and error code only yields an error message.

This series improves the fsl-mc bus by changing the remove callback to
return no value instead. As a preparation all drivers are changed to
return zero before so that they don't trigger the error message.

Best regards
Uwe

Uwe Kleine-König (6):
  bus: fsl-mc: Only warn once about errors on device unbind
  bus: fsl-mc: dprc: Push down error message from fsl_mc_driver_remove()
  bus: fsl-mc: fsl-mc-allocator: Drop if block with always wrong
condition
  bus: fsl-mc: fsl-mc-allocator: Improve error reporting
  soc: fsl: dpio: Suppress duplicated error reporting on device remove
  bus: fsl-mc: Make remove function return void

 drivers/bus/fsl-mc/dprc-driver.c  | 12 -
 drivers/bus/fsl-mc/fsl-mc-allocator.c | 27 ++-
 drivers/bus/fsl-mc/fsl-mc-bus.c   |  7 +
 drivers/crypto/caam/caamalg_qi2.c |  4 +--
 drivers/dma/fsl-dpaa2-qdma/dpaa2-qdma.c   |  4 +--
 .../net/ethernet/freescale/dpaa2/dpaa2-eth.c  |  4 +--
 .../net/ethernet/freescale/dpaa2/dpaa2-ptp.c  |  4 +--
 .../ethernet/freescale/dpaa2/dpaa2-switch.c   |  4 +--
 drivers/soc/fsl/dpio/dpio-driver.c|  8 +-
 drivers/vfio/fsl-mc/vfio_fsl_mc.c |  3 +--
 include/linux/fsl/mc.h|  2 +-
 11 files changed, 28 insertions(+), 51 deletions(-)


base-commit: fe15c26ee26efa11741a7b632e9f23b01aca4cc6
-- 
2.39.1



[PATCH 5/6] soc: fsl: dpio: Suppress duplicated error reporting on device remove

2023-03-10 Thread Uwe Kleine-König
Returning an error code from a fsl_mc_driver's remove callback results
in a generic error message, otherwise the value is ignored and the device
gets unbound.

As the only error path in dpaa2_dpio_remove() already emits an error
message, return zero unconditionally to suppress another (less helpful)
error report.

Signed-off-by: Uwe Kleine-König 
---
 drivers/soc/fsl/dpio/dpio-driver.c | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/soc/fsl/dpio/dpio-driver.c 
b/drivers/soc/fsl/dpio/dpio-driver.c
index 74eace3109a1..09df5302d255 100644
--- a/drivers/soc/fsl/dpio/dpio-driver.c
+++ b/drivers/soc/fsl/dpio/dpio-driver.c
@@ -297,14 +297,10 @@ static int dpaa2_dpio_remove(struct fsl_mc_device 
*dpio_dev)
 
dpio_close(dpio_dev->mc_io, 0, dpio_dev->mc_handle);
 
-   fsl_mc_portal_free(dpio_dev->mc_io);
-
-   return 0;
-
 err_open:
fsl_mc_portal_free(dpio_dev->mc_io);
 
-   return err;
+   return 0;
 }
 
 static const struct fsl_mc_device_id dpaa2_dpio_match_id_table[] = {
-- 
2.39.1



Re: [PATCH v2 4/4] powerpc/bpf: use bpf_jit_binary_pack_[alloc|finalize|free]

2023-03-10 Thread Song Liu
On Thu, Mar 9, 2023 at 10:03 AM Hari Bathini  wrote:
>
> Use bpf_jit_binary_pack_alloc in powerpc jit. The jit engine first
> writes the program to the rw buffer. When the jit is done, the program
> is copied to the final location with bpf_jit_binary_pack_finalize.
> With multiple jit_subprogs, bpf_jit_free is called on some subprograms
> that haven't got bpf_jit_binary_pack_finalize() yet. Implement custom
> bpf_jit_free() like in commit 1d5f82d9dd47 ("bpf, x86: fix freeing of
> not-finalized bpf_prog_pack") to call bpf_jit_binary_pack_finalize(),
> if necessary. While here, correct the misnomer powerpc64_jit_data to
> powerpc_jit_data as it is meant for both ppc32 and ppc64.
>
> Signed-off-by: Hari Bathini 
> ---
>  arch/powerpc/net/bpf_jit.h|   7 +-
>  arch/powerpc/net/bpf_jit_comp.c   | 104 +-
>  arch/powerpc/net/bpf_jit_comp32.c |   4 +-
>  arch/powerpc/net/bpf_jit_comp64.c |   6 +-
>  4 files changed, 83 insertions(+), 38 deletions(-)
>
> diff --git a/arch/powerpc/net/bpf_jit.h b/arch/powerpc/net/bpf_jit.h
> index d767e39d5645..a8b7480c4d43 100644
> --- a/arch/powerpc/net/bpf_jit.h
> +++ b/arch/powerpc/net/bpf_jit.h
> @@ -168,15 +168,16 @@ static inline void bpf_clear_seen_register(struct 
> codegen_context *ctx, int i)
>
>  void bpf_jit_init_reg_mapping(struct codegen_context *ctx);
>  int bpf_jit_emit_func_call_rel(u32 *image, struct codegen_context *ctx, u64 
> func);
> -int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, struct 
> codegen_context *ctx,
> +int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, u32 *fimage, struct 
> codegen_context *ctx,
>u32 *addrs, int pass, bool extra_pass);
>  void bpf_jit_build_prologue(u32 *image, struct codegen_context *ctx);
>  void bpf_jit_build_epilogue(u32 *image, struct codegen_context *ctx);
>  void bpf_jit_realloc_regs(struct codegen_context *ctx);
>  int bpf_jit_emit_exit_insn(u32 *image, struct codegen_context *ctx, int 
> tmp_reg, long exit_addr);
>
> -int bpf_add_extable_entry(struct bpf_prog *fp, u32 *image, int pass, struct 
> codegen_context *ctx,
> - int insn_idx, int jmp_off, int dst_reg);
> +int bpf_add_extable_entry(struct bpf_prog *fp, u32 *image, u32 *fimage, int 
> pass,
> + struct codegen_context *ctx, int insn_idx,
> + int jmp_off, int dst_reg);
>
>  #endif
>
> diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c
> index d1794d9f0154..ece75c829499 100644
> --- a/arch/powerpc/net/bpf_jit_comp.c
> +++ b/arch/powerpc/net/bpf_jit_comp.c
> @@ -42,10 +42,11 @@ int bpf_jit_emit_exit_insn(u32 *image, struct 
> codegen_context *ctx, int tmp_reg,
> return 0;
>  }
>
> -struct powerpc64_jit_data {
> -   struct bpf_binary_header *header;
> +struct powerpc_jit_data {
> +   struct bpf_binary_header *hdr;
> +   struct bpf_binary_header *fhdr;
> u32 *addrs;
> -   u8 *image;
> +   u8 *fimage;
> u32 proglen;
> struct codegen_context ctx;
>  };

Some comments about the f- prefix will be helpful. (Yes, I should have done
better job adding comments for the x86 counterpart..)

> @@ -62,15 +63,18 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
> u8 *image = NULL;
> u32 *code_base;
> u32 *addrs;
> -   struct powerpc64_jit_data *jit_data;
> +   struct powerpc_jit_data *jit_data;
> struct codegen_context cgctx;
> int pass;
> int flen;
> -   struct bpf_binary_header *bpf_hdr;
> +   struct bpf_binary_header *fhdr = NULL;
> +   struct bpf_binary_header *hdr = NULL;
> struct bpf_prog *org_fp = fp;
> struct bpf_prog *tmp_fp;
> bool bpf_blinded = false;
> bool extra_pass = false;
> +   u8 *fimage = NULL;
> +   u32 *fcode_base;
> u32 extable_len;
> u32 fixup_len;
>
> @@ -100,9 +104,11 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
> addrs = jit_data->addrs;
> if (addrs) {
> cgctx = jit_data->ctx;
> -   image = jit_data->image;
> -   bpf_hdr = jit_data->header;
> +   fimage = jit_data->fimage;
> +   fhdr = jit_data->fhdr;
> proglen = jit_data->proglen;
> +   hdr = jit_data->hdr;
> +   image = (void *)hdr + ((void *)fimage - (void *)fhdr);
> extra_pass = true;
> goto skip_init_ctx;
> }
> @@ -120,7 +126,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
> cgctx.stack_size = round_up(fp->aux->stack_depth, 16);
>
> /* Scouting faux-generate pass 0 */
> -   if (bpf_jit_build_body(fp, 0, , addrs, 0, false)) {
> +   if (bpf_jit_build_body(fp, NULL, NULL, , addrs, 0, false)) {
> /* We hit something illegal or unsupported. */
> fp = org_fp;
> goto out_addrs;
> @@ -135,7 +141,7 

Re: [PATCH v4 1/4] PCI: Introduce pci_dev_for_each_resource()

2023-03-10 Thread Keith Busch
On Fri, Mar 10, 2023 at 07:14:13PM +0200, Andy Shevchenko wrote:
> +#define __pci_dev_for_each_resource(dev, res, __i, vartype)  \
> + for (vartype __i = 0;   \
> + res = &(dev)->resource[__i], __i < PCI_NUM_RESOURCES;   \
> + __i++)

...

> +#define pci_dev_for_each_resource_p(dev, res)
> \
> + __pci_dev_for_each_resource(dev, res, i, unsigned int)

It looks dangerous to have a macro declare a variable when starting a new
scope. How do you know the name 'i' won't clash with something defined above?


Re: [PATCH v2 3/4] powerpc/bpf: implement bpf_arch_text_invalidate for bpf_prog_pack

2023-03-10 Thread Song Liu
On Thu, Mar 9, 2023 at 10:02 AM Hari Bathini  wrote:
>
> Implement bpf_arch_text_invalidate and use it to fill unused part of
> the bpf_prog_pack with trap instructions when a BPF program is freed.
>
> Signed-off-by: Hari Bathini 
> ---
>  arch/powerpc/net/bpf_jit_comp.c | 15 +++
>  1 file changed, 15 insertions(+)
>
> diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c
> index 0a70319116d1..d1794d9f0154 100644
> --- a/arch/powerpc/net/bpf_jit_comp.c
> +++ b/arch/powerpc/net/bpf_jit_comp.c
> @@ -293,3 +293,18 @@ void *bpf_arch_text_copy(void *dst, void *src, size_t 
> len)
>
> return ret;
>  }
> +
> +int bpf_arch_text_invalidate(void *dst, size_t len)
> +{
> +   u32 inst = BREAKPOINT_INSTRUCTION;
> +   int ret = -EINVAL;

No need to set to -EINVAL here.

> +
> +   if (WARN_ON_ONCE(core_kernel_text((unsigned long)dst)))
> +   return ret;

Just return -EINVAL instead.

> +
> +   mutex_lock(_mutex);
> +   ret = patch_instructions(dst, , true, len);
> +   mutex_unlock(_mutex);
> +
> +   return ret;
> +}
> --
> 2.39.2
>


Re: [PATCH v2 2/4] powerpc/bpf: implement bpf_arch_text_copy

2023-03-10 Thread Song Liu
On Thu, Mar 9, 2023 at 10:02 AM Hari Bathini  wrote:
>
> bpf_arch_text_copy is used to dump JITed binary to RX page, allowing
> multiple BPF programs to share the same page. Use the newly introduced
> patch_instructions() to implement it. Around 5X improvement in speed
> of execution observed, using the new patch_instructions() function
> over patch_instruction(), while running the tests from test_bpf.ko.
>
> Signed-off-by: Hari Bathini 
> ---
>  arch/powerpc/net/bpf_jit_comp.c | 23 ++-
>  1 file changed, 22 insertions(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c
> index e93aefcfb83f..0a70319116d1 100644
> --- a/arch/powerpc/net/bpf_jit_comp.c
> +++ b/arch/powerpc/net/bpf_jit_comp.c
> @@ -13,9 +13,12 @@
>  #include 
>  #include 
>  #include 
> -#include 
> +#include 
>  #include 
>
> +#include 
> +#include 
> +
>  #include "bpf_jit.h"
>
>  static void bpf_jit_fill_ill_insns(void *area, unsigned int size)
> @@ -272,3 +275,21 @@ int bpf_add_extable_entry(struct bpf_prog *fp, u32 
> *image, int pass, struct code
> ctx->exentry_idx++;
> return 0;
>  }
> +
> +void *bpf_arch_text_copy(void *dst, void *src, size_t len)
> +{
> +   void *ret = ERR_PTR(-EINVAL);
> +   int err;
> +
> +   if (WARN_ON_ONCE(core_kernel_text((unsigned long)dst)))
> +   return ret;
> +
> +   ret = dst;
> +   mutex_lock(_mutex);
> +   err = patch_instructions(dst, src, false, len);
> +   if (err)
> +   ret = ERR_PTR(err);
> +   mutex_unlock(_mutex);
> +
> +   return ret;
> +}

It seems we don't really need "ret". How about something like:

+void *bpf_arch_text_copy(void *dst, void *src, size_t len)
+{
+   int err;
+
+   if (WARN_ON_ONCE(core_kernel_text((unsigned long)dst)))
+   return ERR_PTR(-EINVAL);
+
+   mutex_lock(_mutex);
+   err = patch_instructions(dst, src, false, len);
+   mutex_unlock(_mutex);
+
+   return err ? ERR_PTR(err) : dst;
+}

Song


[PATCH V6 15/15] spi: spi-zynqmp-gqspi: Add parallel memories support in GQSPI driver

2023-03-10 Thread Amit Kumar Mahapatra
During GQSPI driver probe set ctlr->multi-cs-cap for enabling multi CS
capability of the controller. In parallel mode the controller can either
split the data between both the flash or can send the same data to both the
flashes, this is determined by the STRIPE bit. While sending commands to
the flashes the GQSPI driver send the same command to both the flashes by
resetting the STRIPE bit, but while writing/reading data to & from the
flash the GQSPI driver splits the data evenly between both the flashes by
setting the STRIPE bit.

Signed-off-by: Amit Kumar Mahapatra 
---
 drivers/spi/spi-zynqmp-gqspi.c | 39 +-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi-zynqmp-gqspi.c b/drivers/spi/spi-zynqmp-gqspi.c
index 3d2b92a88e8a..d795d17d2541 100644
--- a/drivers/spi/spi-zynqmp-gqspi.c
+++ b/drivers/spi/spi-zynqmp-gqspi.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /* Generic QSPI register offsets */
 #define GQSPI_CONFIG_OFST  0x0100
@@ -192,6 +193,7 @@ struct qspi_platform_data {
  * @op_lock:   Operational lock
  * @speed_hz:  Current SPI bus clock speed in hz
  * @has_tapdelay:  Used for tapdelay register available in qspi
+ * @is_parallel:   Used for multi CS support
  */
 struct zynqmp_qspi {
struct spi_controller *ctlr;
@@ -214,8 +216,33 @@ struct zynqmp_qspi {
struct mutex op_lock;
u32 speed_hz;
bool has_tapdelay;
+   bool is_parallel;
 };
 
+/**
+ * zynqmp_gqspi_update_stripe - For GQSPI controller data stripe capabilities
+ * @op:Pointer to mem ops
+ * Return:  Status of the data stripe
+ *
+ * Returns true if data stripe need to be enabled, else returns false
+ */
+bool zynqmp_gqspi_update_stripe(const struct spi_mem_op *op)
+{
+   if (op->cmd.opcode ==  SPINOR_OP_BE_4K ||
+   op->cmd.opcode ==  SPINOR_OP_BE_32K ||
+   op->cmd.opcode ==  SPINOR_OP_CHIP_ERASE ||
+   op->cmd.opcode ==  SPINOR_OP_SE ||
+   op->cmd.opcode ==  SPINOR_OP_BE_32K_4B ||
+   op->cmd.opcode ==  SPINOR_OP_SE_4B ||
+   op->cmd.opcode == SPINOR_OP_BE_4K_4B ||
+   op->cmd.opcode ==  SPINOR_OP_WRSR ||
+   op->cmd.opcode ==  SPINOR_OP_BRWR ||
+   (op->cmd.opcode ==  SPINOR_OP_WRSR2 && !op->addr.nbytes))
+   return false;
+
+   return true;
+}
+
 /**
  * zynqmp_gqspi_read - For GQSPI controller read operation
  * @xqspi: Pointer to the zynqmp_qspi structure
@@ -470,7 +497,14 @@ static void zynqmp_qspi_chipselect(struct spi_device 
*qspi, bool is_high)
 
genfifoentry |= GQSPI_GENFIFO_MODE_SPI;
 
-   if (qspi->cs_index_mask & GQSPI_SELECT_UPPER_CS) {
+   if ((qspi->cs_index_mask & GQSPI_SELECT_LOWER_CS) &&
+   (qspi->cs_index_mask & GQSPI_SELECT_UPPER_CS)) {
+   zynqmp_gqspi_selectslave(xqspi,
+GQSPI_SELECT_FLASH_CS_BOTH,
+GQSPI_SELECT_FLASH_BUS_BOTH);
+   if (!xqspi->is_parallel)
+   xqspi->is_parallel = true;
+   } else if (qspi->cs_index_mask & GQSPI_SELECT_UPPER_CS) {
zynqmp_gqspi_selectslave(xqspi,
 GQSPI_SELECT_FLASH_CS_UPPER,
 GQSPI_SELECT_FLASH_BUS_LOWER);
@@ -1139,6 +1173,8 @@ static int zynqmp_qspi_exec_op(struct spi_mem *mem,
}
 
if (op->data.nbytes) {
+   if (xqspi->is_parallel && zynqmp_gqspi_update_stripe(op))
+   genfifoentry |= GQSPI_GENFIFO_STRIPE;
reinit_completion(>data_completion);
if (op->data.dir == SPI_MEM_DATA_OUT) {
xqspi->txbuf = (u8 *)op->data.buf.out;
@@ -1334,6 +1370,7 @@ static int zynqmp_qspi_probe(struct platform_device *pdev)
ctlr->bits_per_word_mask = SPI_BPW_MASK(8);
ctlr->dev.of_node = np;
ctlr->auto_runtime_pm = true;
+   ctlr->multi_cs_cap = true;
 
ret = devm_spi_register_controller(>dev, ctlr);
if (ret) {
-- 
2.25.1



[PATCH V6 14/15] mtd: spi-nor: Add parallel memories support in spi-nor

2023-03-10 Thread Amit Kumar Mahapatra
The current implementation assumes that a maximum of two flashes are
connected in parallel mode. The QSPI controller splits the data evenly
between both the flashes so, both the flashes that are connected in
parallel mode should be identical.
During each operation SPI-NOR sets 0th bit for CS0 & 1st bit for CS1 in
nor->spimem->spi->cs_index_mask. The QSPI driver will then assert/de-assert
CS0 & CS1.
Write operation in parallel mode are performed in page size * 2 chunks as
each write operation results in writing both the flashes. For doubling the
address space each operation is performed at addr/2 flash offset, where
addr is the address specified by the user.

Signed-off-by: Amit Kumar Mahapatra 
---
 drivers/mtd/spi-nor/core.c  | 514 +++-
 drivers/mtd/spi-nor/core.h  |   4 +
 drivers/mtd/spi-nor/micron-st.c |   5 +
 3 files changed, 384 insertions(+), 139 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 0bc6b42f276c..18fc4a1c28d4 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -464,17 +464,29 @@ int spi_nor_read_sr(struct spi_nor *nor, u8 *sr)
op.data.nbytes = 2;
}
 
+   if (nor->flags & SNOR_F_HAS_PARALLEL)
+   op.data.nbytes = 2;
+
spi_nor_spimem_setup_op(nor, , nor->reg_proto);
 
ret = spi_mem_exec_op(nor->spimem, );
} else {
-   ret = spi_nor_controller_ops_read_reg(nor, SPINOR_OP_RDSR, sr,
- 1);
+   if (nor->flags & SNOR_F_HAS_PARALLEL)
+   ret = spi_nor_controller_ops_read_reg(nor,
+ SPINOR_OP_RDSR,
+ sr, 2);
+   else
+   ret = spi_nor_controller_ops_read_reg(nor,
+ SPINOR_OP_RDSR,
+ sr, 1);
}
 
if (ret)
dev_dbg(nor->dev, "error %d reading SR\n", ret);
 
+   if (nor->flags & SNOR_F_HAS_PARALLEL)
+   sr[0] |= sr[1];
+
return ret;
 }
 
@@ -1466,12 +1478,122 @@ static int spi_nor_erase(struct mtd_info *mtd, struct 
erase_info *instr)
if (ret)
return ret;
 
-   /* whole-chip erase? */
-   if (len == mtd->size && !(nor->flags & SNOR_F_NO_OP_CHIP_ERASE)) {
-   unsigned long timeout;
+   if (!(nor->flags & SNOR_F_HAS_PARALLEL)) {
+   /* whole-chip erase? */
+   if (len == mtd->size && !(nor->flags & 
SNOR_F_NO_OP_CHIP_ERASE)) {
+   unsigned long timeout;
+
+   while ((cur_cs_num < SNOR_FLASH_CNT_MAX) && params) {
+   nor->spimem->spi->cs_index_mask = 1 << 
cur_cs_num;
+   ret = spi_nor_write_enable(nor);
+   if (ret)
+   goto erase_err;
+
+   ret = spi_nor_erase_chip(nor);
+   if (ret)
+   goto erase_err;
+
+   /*
+* Scale the timeout linearly with the size of 
the flash, with
+* a minimum calibrated to an old 2MB flash. We 
could try to
+* pull these from CFI/SFDP, but these values 
should be good
+* enough for now.
+*/
+   timeout = max(CHIP_ERASE_2MB_READY_WAIT_JIFFIES,
+ CHIP_ERASE_2MB_READY_WAIT_JIFFIES 
*
+ (unsigned long)(params->size /
+ SZ_2M));
+   ret = spi_nor_wait_till_ready_with_timeout(nor, 
timeout);
+   if (ret)
+   goto erase_err;
+
+   cur_cs_num++;
+   params = spi_nor_get_params(nor, cur_cs_num);
+   }
+
+   /* REVISIT in some cases we could speed up erasing large regions
+* by using SPINOR_OP_SE instead of SPINOR_OP_BE_4K.  We may 
have set up
+* to use "small sector erase", but that's not always optimal.
+*/
+
+   /* "sector"-at-a-time erase */
+   } else if (spi_nor_has_uniform_erase(nor)) {
+   /* Determine the flash from which the operation need to 
start */
+   while ((cur_cs_num < SNOR_FLASH_CNT_MAX) &&
+  (addr > sz - 1) && params) {
+ 

[PATCH V6 13/15] spi: spi-zynqmp-gqspi: Add stacked memories support in GQSPI driver

2023-03-10 Thread Amit Kumar Mahapatra
GQSPI supports two chip select CS0 & CS1. Update the driver to
assert/de-assert the appropriate chip select as per the bits set in
qspi->cs_index_mask.

Signed-off-by: Amit Kumar Mahapatra 
---
 drivers/spi/spi-zynqmp-gqspi.c | 21 +
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/spi/spi-zynqmp-gqspi.c b/drivers/spi/spi-zynqmp-gqspi.c
index fb2ca9b90eab..3d2b92a88e8a 100644
--- a/drivers/spi/spi-zynqmp-gqspi.c
+++ b/drivers/spi/spi-zynqmp-gqspi.c
@@ -156,6 +156,9 @@
 #define GQSPI_FREQ_100MHZ  1
 #define GQSPI_FREQ_150MHZ  15000
 
+#define GQSPI_SELECT_LOWER_CS  BIT(0)
+#define GQSPI_SELECT_UPPER_CS  BIT(1)
+
 #define SPI_AUTOSUSPEND_TIMEOUT3000
 enum mode_type {GQSPI_MODE_IO, GQSPI_MODE_DMA};
 
@@ -467,15 +470,17 @@ static void zynqmp_qspi_chipselect(struct spi_device 
*qspi, bool is_high)
 
genfifoentry |= GQSPI_GENFIFO_MODE_SPI;
 
+   if (qspi->cs_index_mask & GQSPI_SELECT_UPPER_CS) {
+   zynqmp_gqspi_selectslave(xqspi,
+GQSPI_SELECT_FLASH_CS_UPPER,
+GQSPI_SELECT_FLASH_BUS_LOWER);
+   } else if (qspi->cs_index_mask & GQSPI_SELECT_LOWER_CS) {
+   zynqmp_gqspi_selectslave(xqspi,
+GQSPI_SELECT_FLASH_CS_LOWER,
+GQSPI_SELECT_FLASH_BUS_LOWER);
+   }
+   genfifoentry |= xqspi->genfifobus;
if (!is_high) {
-   if (!spi_get_chipselect(qspi, 0)) {
-   xqspi->genfifobus = GQSPI_GENFIFO_BUS_LOWER;
-   xqspi->genfifocs = GQSPI_GENFIFO_CS_LOWER;
-   } else {
-   xqspi->genfifobus = GQSPI_GENFIFO_BUS_UPPER;
-   xqspi->genfifocs = GQSPI_GENFIFO_CS_UPPER;
-   }
-   genfifoentry |= xqspi->genfifobus;
genfifoentry |= xqspi->genfifocs;
genfifoentry |= GQSPI_GENFIFO_CS_SETUP;
} else {
-- 
2.25.1



[PATCH V6 12/15] mtd: spi-nor: Add stacked memories support in spi-nor

2023-03-10 Thread Amit Kumar Mahapatra
Each flash that is connected in stacked mode should have a separate
parameter structure. So, the flash parameter member(*params) of the spi_nor
structure is changed to an array (*params[2]). The array is used to store
the parameters of each flash connected in stacked configuration.

The current implementation assumes that a maximum of two flashes are
connected in stacked mode and both the flashes are of same make but can
differ in sizes. So, except the sizes all other flash parameters of both
the flashes are identical.

SPI-NOR is not aware of the chip_select values, for any incoming request
SPI-NOR will decide the flash index with the help of individual flash size
and the configuration type (single/stacked). SPI-NOR will pass on the flash
index information to the SPI core & SPI driver by setting the appropriate
bit in nor->spimem->spi->cs_index_mask. For example, if nth bit of
nor->spimem->spi->cs_index_mask is set then the driver would
assert/de-assert spi->chip_slect[n].

Signed-off-by: Amit Kumar Mahapatra 
---
 drivers/mtd/spi-nor/core.c  | 282 +---
 drivers/mtd/spi-nor/core.h  |   4 +
 include/linux/mtd/spi-nor.h |  12 +-
 3 files changed, 244 insertions(+), 54 deletions(-)

diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 66b6934b4465..0bc6b42f276c 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -1441,13 +1441,18 @@ static int spi_nor_erase_multi_sectors(struct spi_nor 
*nor, u64 addr, u32 len)
 static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
 {
struct spi_nor *nor = mtd_to_spi_nor(mtd);
-   u32 addr, len;
+   struct spi_nor_flash_parameter *params;
+   u32 addr, len, offset, cur_cs_num = 0;
uint32_t rem;
int ret;
+   u64 sz;
 
dev_dbg(nor->dev, "at 0x%llx, len %lld\n", (long long)instr->addr,
(long long)instr->len);
 
+   params = spi_nor_get_params(nor, 0);
+   sz = params->size;
+
if (spi_nor_has_uniform_erase(nor)) {
div_u64_rem(instr->len, mtd->erasesize, );
if (rem)
@@ -1465,26 +1470,30 @@ static int spi_nor_erase(struct mtd_info *mtd, struct 
erase_info *instr)
if (len == mtd->size && !(nor->flags & SNOR_F_NO_OP_CHIP_ERASE)) {
unsigned long timeout;
 
-   ret = spi_nor_write_enable(nor);
-   if (ret)
-   goto erase_err;
+   while (cur_cs_num < SNOR_FLASH_CNT_MAX && params) {
+   nor->spimem->spi->cs_index_mask = 0x01 << cur_cs_num;
+   ret = spi_nor_write_enable(nor);
+   if (ret)
+   goto erase_err;
 
-   ret = spi_nor_erase_chip(nor);
-   if (ret)
-   goto erase_err;
+   ret = spi_nor_erase_chip(nor);
+   if (ret)
+   goto erase_err;
 
-   /*
-* Scale the timeout linearly with the size of the flash, with
-* a minimum calibrated to an old 2MB flash. We could try to
-* pull these from CFI/SFDP, but these values should be good
-* enough for now.
-*/
-   timeout = max(CHIP_ERASE_2MB_READY_WAIT_JIFFIES,
- CHIP_ERASE_2MB_READY_WAIT_JIFFIES *
- (unsigned long)(mtd->size / SZ_2M));
-   ret = spi_nor_wait_till_ready_with_timeout(nor, timeout);
-   if (ret)
-   goto erase_err;
+   /*
+* Scale the timeout linearly with the size of the 
flash, with
+* a minimum calibrated to an old 2MB flash. We could 
try to
+* pull these from CFI/SFDP, but these values should be 
good
+* enough for now.
+*/
+   timeout = max(CHIP_ERASE_2MB_READY_WAIT_JIFFIES,
+ CHIP_ERASE_2MB_READY_WAIT_JIFFIES *
+ (unsigned long)(params->size / SZ_2M));
+   ret = spi_nor_wait_till_ready_with_timeout(nor, 
timeout);
+   if (ret)
+   goto erase_err;
+   cur_cs_num++;
+   }
 
/* REVISIT in some cases we could speed up erasing large regions
 * by using SPINOR_OP_SE instead of SPINOR_OP_BE_4K.  We may have set up
@@ -1493,12 +1502,26 @@ static int spi_nor_erase(struct mtd_info *mtd, struct 
erase_info *instr)
 
/* "sector"-at-a-time erase */
} else if (spi_nor_has_uniform_erase(nor)) {
+   /* Determine the flash from which the operation need to start */
+   while ((cur_cs_num < SNOR_FLASH_CNT_MAX) && (addr > sz - 1) && 
params) {
+   

[PATCH V6 11/15] mtd: spi-nor: Add APIs to set/get nor->params

2023-03-10 Thread Amit Kumar Mahapatra
Supporting multi-cs in spi-nor would require the *params member of
struct spi_nor to be an array. To make the transition smoother introduced
spi_nor_get_params() & spi_nor_set_params() APIs to get & set nor->params,
added a new local variable (struct spi_nor_flash_parameter *params) to hold
the return value of the spi_nor_get_params() function call and replaced all
nor->params references with the "params".
While adding multi-cs support in further patches the *params member of the
spi_nor structure would be converted to arrays & the "idx" parameter of
the APIs would be used as array index i.e., nor->params[idx].

Signed-off-by: Amit Kumar Mahapatra 
---
 drivers/mtd/spi-nor/atmel.c  |  17 ++--
 drivers/mtd/spi-nor/core.c   | 129 ---
 drivers/mtd/spi-nor/debugfs.c|   4 +-
 drivers/mtd/spi-nor/gigadevice.c |   4 +-
 drivers/mtd/spi-nor/issi.c   |  11 ++-
 drivers/mtd/spi-nor/macronix.c   |   6 +-
 drivers/mtd/spi-nor/micron-st.c  |  34 +---
 drivers/mtd/spi-nor/otp.c|  29 ---
 drivers/mtd/spi-nor/sfdp.c   |  29 ---
 drivers/mtd/spi-nor/spansion.c   |  50 +++-
 drivers/mtd/spi-nor/sst.c|   7 +-
 drivers/mtd/spi-nor/swp.c|  22 --
 drivers/mtd/spi-nor/winbond.c|  10 ++-
 drivers/mtd/spi-nor/xilinx.c |  18 +++--
 include/linux/mtd/spi-nor.h  |  10 +++
 15 files changed, 254 insertions(+), 126 deletions(-)

diff --git a/drivers/mtd/spi-nor/atmel.c b/drivers/mtd/spi-nor/atmel.c
index 656dd80a0be7..57ca9f5ee205 100644
--- a/drivers/mtd/spi-nor/atmel.c
+++ b/drivers/mtd/spi-nor/atmel.c
@@ -23,10 +23,11 @@ static int at25fs_nor_lock(struct spi_nor *nor, loff_t ofs, 
uint64_t len)
 
 static int at25fs_nor_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len)
 {
+   struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
int ret;
 
/* We only support unlocking the whole flash array */
-   if (ofs || len != nor->params->size)
+   if (ofs || len != params->size)
return -EINVAL;
 
/* Write 0x00 to the status register to disable write protection */
@@ -50,7 +51,9 @@ static const struct spi_nor_locking_ops 
at25fs_nor_locking_ops = {
 
 static void at25fs_nor_late_init(struct spi_nor *nor)
 {
-   nor->params->locking_ops = _nor_locking_ops;
+   struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
+
+   params->locking_ops = _nor_locking_ops;
 }
 
 static const struct spi_nor_fixups at25fs_nor_fixups = {
@@ -69,11 +72,12 @@ static const struct spi_nor_fixups at25fs_nor_fixups = {
 static int atmel_nor_set_global_protection(struct spi_nor *nor, loff_t ofs,
   uint64_t len, bool is_protect)
 {
+   struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
int ret;
u8 sr;
 
/* We only support locking the whole flash array */
-   if (ofs || len != nor->params->size)
+   if (ofs || len != params->size)
return -EINVAL;
 
ret = spi_nor_read_sr(nor, nor->bouncebuf);
@@ -131,9 +135,10 @@ static int atmel_nor_global_unprotect(struct spi_nor *nor, 
loff_t ofs,
 static int atmel_nor_is_global_protected(struct spi_nor *nor, loff_t ofs,
 uint64_t len)
 {
+   struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
int ret;
 
-   if (ofs >= nor->params->size || (ofs + len) > nor->params->size)
+   if (ofs >= params->size || (ofs + len) > params->size)
return -EINVAL;
 
ret = spi_nor_read_sr(nor, nor->bouncebuf);
@@ -151,7 +156,9 @@ static const struct spi_nor_locking_ops 
atmel_nor_global_protection_ops = {
 
 static void atmel_nor_global_protection_late_init(struct spi_nor *nor)
 {
-   nor->params->locking_ops = _nor_global_protection_ops;
+   struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
+
+   params->locking_ops = _nor_global_protection_ops;
 }
 
 static const struct spi_nor_fixups atmel_nor_global_protection_fixups = {
diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
index 0a78045ca1d9..66b6934b4465 100644
--- a/drivers/mtd/spi-nor/core.c
+++ b/drivers/mtd/spi-nor/core.c
@@ -448,14 +448,15 @@ int spi_nor_read_id(struct spi_nor *nor, u8 naddr, u8 
ndummy, u8 *id,
  */
 int spi_nor_read_sr(struct spi_nor *nor, u8 *sr)
 {
+   struct spi_nor_flash_parameter *params = spi_nor_get_params(nor, 0);
int ret;
 
if (nor->spimem) {
struct spi_mem_op op = SPI_NOR_RDSR_OP(sr);
 
if (nor->reg_proto == SNOR_PROTO_8_8_8_DTR) {
-   op.addr.nbytes = nor->params->rdsr_addr_nbytes;
-   op.dummy.nbytes = nor->params->rdsr_dummy;
+   op.addr.nbytes = params->rdsr_addr_nbytes;
+   op.dummy.nbytes = params->rdsr_dummy;
/*
 * We 

[PATCH V6 10/15] mtd: spi-nor: Convert macros with inline functions

2023-03-10 Thread Amit Kumar Mahapatra
In further patches the nor->params references in
spi_nor_otp_region_len(nor) & spi_nor_otp_n_regions(nor) macros will be
replaced with spi_nor_get_params() API. To make the transition smoother,
first converting the macros into static inline functions.

Suggested-by: Michal Simek 
Signed-off-by: Amit Kumar Mahapatra 
---
 drivers/mtd/spi-nor/otp.c | 23 +--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/spi-nor/otp.c b/drivers/mtd/spi-nor/otp.c
index 00ab0d2d6d2f..3d75899de303 100644
--- a/drivers/mtd/spi-nor/otp.c
+++ b/drivers/mtd/spi-nor/otp.c
@@ -11,8 +11,27 @@
 
 #include "core.h"
 
-#define spi_nor_otp_region_len(nor) ((nor)->params->otp.org->len)
-#define spi_nor_otp_n_regions(nor) ((nor)->params->otp.org->n_regions)
+/**
+ * spi_nor_otp_region_len() - get size of one OTP region in bytes
+ * @nor:pointer to 'struct spi_nor'
+ *
+ * Return: size of one OTP region in bytes
+ */
+static inline unsigned int spi_nor_otp_region_len(struct spi_nor *nor)
+{
+   return nor->params->otp.org->len;
+}
+
+/**
+ * spi_nor_otp_n_regions() - get number of individual OTP regions
+ * @nor:pointer to 'struct spi_nor'
+ *
+ * Return: number of individual OTP regions
+ */
+static inline unsigned int spi_nor_otp_n_regions(struct spi_nor *nor)
+{
+   return nor->params->otp.org->n_regions;
+}
 
 /**
  * spi_nor_otp_read_secr() - read security register
-- 
2.25.1



[PATCH V6 09/15] spi: Add stacked and parallel memories support in SPI core

2023-03-10 Thread Amit Kumar Mahapatra
For supporting multiple CS the SPI device need to be aware of all the CS
values. So, the "chip_select" member in the spi_device structure is now an
array that holds all the CS values.

spi_device structure now has a "cs_index_mask" member. This acts as an
index to the chip_select array. If nth bit of spi->cs_index_mask is set
then the driver would assert spi->chip_select[n].

In parallel mode all the chip selects are asserted/de-asserted
simultaneously and each byte of data is stored in both devices, the even
bits in one, the odd bits in the other. The split is automatically handled
by the GQSPI controller. The GQSPI controller supports a maximum of two
flashes connected in parallel mode. A "multi-cs-cap" flag is added in the
spi controntroller data, through ctlr->multi-cs-cap the spi core will make
sure that the controller is capable of handling multiple chip selects at
once.

For supporting multiple CS via GPIO the cs_gpiod member of the spi_device
structure is now an array that holds the gpio descriptor for each
chipselect.

Multi CS support using GPIO is not tested due to unavailability of
necessary hardware setup.

Signed-off-by: Amit Kumar Mahapatra 
---
 drivers/spi/spi.c   | 225 +++-
 include/linux/spi/spi.h |  34 --
 2 files changed, 182 insertions(+), 77 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index c725b4bab7af..742bd688381c 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -612,10 +612,17 @@ static int spi_dev_check(struct device *dev, void *data)
 {
struct spi_device *spi = to_spi_device(dev);
struct spi_device *new_spi = data;
-
-   if (spi->controller == new_spi->controller &&
-   spi_get_chipselect(spi, 0) == spi_get_chipselect(new_spi, 0))
-   return -EBUSY;
+   int idx, nw_idx;
+
+   if (spi->controller == new_spi->controller) {
+   for (idx = 0; idx < SPI_CS_CNT_MAX; idx++) {
+   for (nw_idx = 0; nw_idx < SPI_CS_CNT_MAX; nw_idx++) {
+   if (spi_get_chipselect(spi, idx) ==
+   spi_get_chipselect(new_spi, nw_idx))
+   return -EBUSY;
+   }
+   }
+   }
return 0;
 }
 
@@ -629,7 +636,7 @@ static int __spi_add_device(struct spi_device *spi)
 {
struct spi_controller *ctlr = spi->controller;
struct device *dev = ctlr->dev.parent;
-   int status;
+   int status, idx;
 
/*
 * We need to make sure there's no other device with this
@@ -638,8 +645,7 @@ static int __spi_add_device(struct spi_device *spi)
 */
status = bus_for_each_dev(_bus_type, NULL, spi, spi_dev_check);
if (status) {
-   dev_err(dev, "chipselect %d already in use\n",
-   spi_get_chipselect(spi, 0));
+   dev_err(dev, "chipselect %d already in use\n", 
spi_get_chipselect(spi, 0));
return status;
}
 
@@ -649,8 +655,10 @@ static int __spi_add_device(struct spi_device *spi)
return -ENODEV;
}
 
-   if (ctlr->cs_gpiods)
-   spi_set_csgpiod(spi, 0, ctlr->cs_gpiods[spi_get_chipselect(spi, 
0)]);
+   if (ctlr->cs_gpiods) {
+   for (idx = 0; idx < SPI_CS_CNT_MAX; idx++)
+   spi_set_csgpiod(spi, idx, 
ctlr->cs_gpiods[spi_get_chipselect(spi, idx)]);
+   }
 
/*
 * Drivers may modify this initial i/o setup, but will
@@ -690,13 +698,15 @@ int spi_add_device(struct spi_device *spi)
 {
struct spi_controller *ctlr = spi->controller;
struct device *dev = ctlr->dev.parent;
-   int status;
+   int status, idx;
 
-   /* Chipselects are numbered 0..max; validate. */
-   if (spi_get_chipselect(spi, 0) >= ctlr->num_chipselect) {
-   dev_err(dev, "cs%d >= max %d\n", spi_get_chipselect(spi, 0),
-   ctlr->num_chipselect);
-   return -EINVAL;
+   for (idx = 0; idx < SPI_CS_CNT_MAX; idx++) {
+   /* Chipselects are numbered 0..max; validate. */
+   if (spi_get_chipselect(spi, idx) >= ctlr->num_chipselect) {
+   dev_err(dev, "cs%d >= max %d\n", 
spi_get_chipselect(spi, idx),
+   ctlr->num_chipselect);
+   return -EINVAL;
+   }
}
 
/* Set the bus ID string */
@@ -713,12 +723,15 @@ static int spi_add_device_locked(struct spi_device *spi)
 {
struct spi_controller *ctlr = spi->controller;
struct device *dev = ctlr->dev.parent;
+   int idx;
 
-   /* Chipselects are numbered 0..max; validate. */
-   if (spi_get_chipselect(spi, 0) >= ctlr->num_chipselect) {
-   dev_err(dev, "cs%d >= max %d\n", spi_get_chipselect(spi, 0),
-   ctlr->num_chipselect);
-   return -EINVAL;
+   for (idx 

[PATCH V6 08/15] ALSA: hda: cs35l41: Replace all spi->chip_select references with function call

2023-03-10 Thread Amit Kumar Mahapatra
Supporting multi-cs in spi drivers would require the chip_select & cs_gpiod
members of struct spi_device to be an array. But changing the type of these
members to array would break the spi driver functionality. To make the
transition smoother introduced four new APIs to get/set the
spi->chip_select & spi->cs_gpiod and replaced all spi->chip_select and
spi->cs_gpiod references with get or set API calls.
While adding multi-cs support in further patches the chip_select & cs_gpiod
members of the spi_device structure would be converted to arrays & the
"idx" parameter of the APIs would be used as array index i.e.,
spi->chip_select[idx] & spi->cs_gpiod[idx] respectively.

Signed-off-by: Amit Kumar Mahapatra 
---
 sound/pci/hda/cs35l41_hda_spi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/pci/hda/cs35l41_hda_spi.c b/sound/pci/hda/cs35l41_hda_spi.c
index 71979cfb4d7e..eb287aa5f782 100644
--- a/sound/pci/hda/cs35l41_hda_spi.c
+++ b/sound/pci/hda/cs35l41_hda_spi.c
@@ -25,7 +25,7 @@ static int cs35l41_hda_spi_probe(struct spi_device *spi)
else
return -ENODEV;
 
-   return cs35l41_hda_probe(>dev, device_name, spi->chip_select, 
spi->irq,
+   return cs35l41_hda_probe(>dev, device_name, 
spi_get_chipselect(spi, 0), spi->irq,
 devm_regmap_init_spi(spi, 
_regmap_spi));
 }
 
-- 
2.25.1



[PATCH V6 07/15] powerpc/83xx/mpc832x_rdb: Replace all spi->chip_select references with function call

2023-03-10 Thread Amit Kumar Mahapatra
Supporting multi-cs in spi drivers would require the chip_select & cs_gpiod
members of struct spi_device to be an array. But changing the type of these
members to array would break the spi driver functionality. To make the
transition smoother introduced four new APIs to get/set the
spi->chip_select & spi->cs_gpiod and replaced all spi->chip_select and
spi->cs_gpiod references with get or set API calls.
While adding multi-cs support in further patches the chip_select & cs_gpiod
members of the spi_device structure would be converted to arrays & the
"idx" parameter of the APIs would be used as array index i.e.,
spi->chip_select[idx] & spi->cs_gpiod[idx] respectively.

Signed-off-by: Amit Kumar Mahapatra 
---
 arch/powerpc/platforms/83xx/mpc832x_rdb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/platforms/83xx/mpc832x_rdb.c 
b/arch/powerpc/platforms/83xx/mpc832x_rdb.c
index caa96edf0e72..4ab1d48cd229 100644
--- a/arch/powerpc/platforms/83xx/mpc832x_rdb.c
+++ b/arch/powerpc/platforms/83xx/mpc832x_rdb.c
@@ -144,7 +144,7 @@ static int __init fsl_spi_init(struct spi_board_info 
*board_infos,
 
 static void mpc83xx_spi_cs_control(struct spi_device *spi, bool on)
 {
-   pr_debug("%s %d %d\n", __func__, spi->chip_select, on);
+   pr_debug("%s %d %d\n", __func__, spi_get_chipselect(spi, 0), on);
par_io_data_set(3, 13, on);
 }
 
-- 
2.25.1



[PATCH V6 06/15] platform/x86: serial-multi-instantiate: Replace all spi->chip_select and spi->cs_gpiod references with function call

2023-03-10 Thread Amit Kumar Mahapatra
Supporting multi-cs in spi drivers would require the chip_select & cs_gpiod
members of struct spi_device to be an array. But changing the type of these
members to array would break the spi driver functionality. To make the
transition smoother introduced four new APIs to get/set the
spi->chip_select & spi->cs_gpiod and replaced all spi->chip_select and
spi->cs_gpiod references with get or set API calls.
While adding multi-cs support in further patches the chip_select & cs_gpiod
members of the spi_device structure would be converted to arrays & the
"idx" parameter of the APIs would be used as array index i.e.,
spi->chip_select[idx] & spi->cs_gpiod[idx] respectively.

Signed-off-by: Amit Kumar Mahapatra 
Reviewed-by: Michal Simek 
---
 drivers/platform/x86/serial-multi-instantiate.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/x86/serial-multi-instantiate.c 
b/drivers/platform/x86/serial-multi-instantiate.c
index 5362f1a7b77c..270a4700d25d 100644
--- a/drivers/platform/x86/serial-multi-instantiate.c
+++ b/drivers/platform/x86/serial-multi-instantiate.c
@@ -139,7 +139,8 @@ static int smi_spi_probe(struct platform_device *pdev, 
struct smi *smi,
goto error;
}
 
-   dev_dbg(dev, "SPI device %s using chip select %u", name, 
spi_dev->chip_select);
+   dev_dbg(dev, "SPI device %s using chip select %u", name,
+   spi_get_chipselect(spi_dev, 0));
 
smi->spi_devs[i] = spi_dev;
smi->spi_num++;
-- 
2.25.1



[PATCH V6 05/15] staging: Replace all spi->chip_select and spi->cs_gpiod references with function call

2023-03-10 Thread Amit Kumar Mahapatra
Supporting multi-cs in spi drivers would require the chip_select & cs_gpiod
members of struct spi_device to be an array. But changing the type of these
members to array would break the spi driver functionality. To make the
transition smoother introduced four new APIs to get/set the
spi->chip_select & spi->cs_gpiod and replaced all spi->chip_select and
spi->cs_gpiod references with get or set API calls.
While adding multi-cs support in further patches the chip_select & cs_gpiod
members of the spi_device structure would be converted to arrays & the
"idx" parameter of the APIs would be used as array index i.e.,
spi->chip_select[idx] & spi->cs_gpiod[idx] respectively.

Signed-off-by: Amit Kumar Mahapatra 
Reviewed-by: Greg Kroah-Hartman 
Reviewed-by: Michal Simek 
---
 drivers/staging/fbtft/fbtft-core.c | 2 +-
 drivers/staging/greybus/spilib.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/fbtft/fbtft-core.c 
b/drivers/staging/fbtft/fbtft-core.c
index afaba94d1d1c..3a4abf3bae40 100644
--- a/drivers/staging/fbtft/fbtft-core.c
+++ b/drivers/staging/fbtft/fbtft-core.c
@@ -840,7 +840,7 @@ int fbtft_register_framebuffer(struct fb_info *fb_info)
sprintf(text1, ", %zu KiB buffer memory", par->txbuf.len >> 10);
if (spi)
sprintf(text2, ", spi%d.%d at %d MHz", spi->master->bus_num,
-   spi->chip_select, spi->max_speed_hz / 100);
+   spi_get_chipselect(spi, 0), spi->max_speed_hz / 
100);
dev_info(fb_info->dev,
 "%s frame buffer, %dx%d, %d KiB video memory%s, fps=%lu%s\n",
 fb_info->fix.id, fb_info->var.xres, fb_info->var.yres,
diff --git a/drivers/staging/greybus/spilib.c b/drivers/staging/greybus/spilib.c
index ad0700a0bb81..efb3bec58e15 100644
--- a/drivers/staging/greybus/spilib.c
+++ b/drivers/staging/greybus/spilib.c
@@ -237,7 +237,7 @@ static struct gb_operation *gb_spi_operation_create(struct 
gb_spilib *spi,
request = operation->request->payload;
request->count = cpu_to_le16(count);
request->mode = dev->mode;
-   request->chip_select = dev->chip_select;
+   request->chip_select = spi_get_chipselect(dev, 0);
 
gb_xfer = >transfers[0];
tx_data = gb_xfer + count;  /* place tx data after last gb_xfer */
-- 
2.25.1



[PATCH V6 04/15] mtd: devices: Replace all spi->chip_select and spi->cs_gpiod references with function call

2023-03-10 Thread Amit Kumar Mahapatra
Supporting multi-cs in spi drivers would require the chip_select & cs_gpiod
members of struct spi_device to be an array. But changing the type of these
members to array would break the spi driver functionality. To make the
transition smoother introduced four new APIs to get/set the
spi->chip_select & spi->cs_gpiod and replaced all spi->chip_select and
spi->cs_gpiod references with get or set API calls.
While adding multi-cs support in further patches the chip_select & cs_gpiod
members of the spi_device structure would be converted to arrays & the
"idx" parameter of the APIs would be used as array index i.e.,
spi->chip_select[idx] & spi->cs_gpiod[idx] respectively.

Signed-off-by: Amit Kumar Mahapatra 
Reviewed-by: Michal Simek 
---
 drivers/mtd/devices/mtd_dataflash.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/devices/mtd_dataflash.c 
b/drivers/mtd/devices/mtd_dataflash.c
index 3bbaa590c768..1d3b2a94581f 100644
--- a/drivers/mtd/devices/mtd_dataflash.c
+++ b/drivers/mtd/devices/mtd_dataflash.c
@@ -639,7 +639,7 @@ static int add_dataflash_otp(struct spi_device *spi, char 
*name, int nr_pages,
 
/* name must be usable with cmdlinepart */
sprintf(priv->name, "spi%d.%d-%s",
-   spi->master->bus_num, spi->chip_select,
+   spi->master->bus_num, spi_get_chipselect(spi, 0),
name);
 
device = >mtd;
-- 
2.25.1



[PATCH V6 03/15] iio: imu: Replace all spi->chip_select and spi->cs_gpiod references with function call

2023-03-10 Thread Amit Kumar Mahapatra
Supporting multi-cs in spi drivers would require the chip_select & cs_gpiod
members of struct spi_device to be an array. But changing the type of these
members to array would break the spi driver functionality. To make the
transition smoother introduced four new APIs to get/set the
spi->chip_select & spi->cs_gpiod and replaced all spi->chip_select and
spi->cs_gpiod references with get or set API calls.
While adding multi-cs support in further patches the chip_select & cs_gpiod
members of the spi_device structure would be converted to arrays & the
"idx" parameter of the APIs would be used as array index i.e.,
spi->chip_select[idx] & spi->cs_gpiod[idx] respectively.

Signed-off-by: Amit Kumar Mahapatra 
Acked-by: Jonathan Cameron 
Reviewed-by: Michal Simek 
---
 drivers/iio/imu/adis16400.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/imu/adis16400.c b/drivers/iio/imu/adis16400.c
index c02fc35dceb4..3eda32e12a53 100644
--- a/drivers/iio/imu/adis16400.c
+++ b/drivers/iio/imu/adis16400.c
@@ -466,7 +466,7 @@ static int adis16400_initial_setup(struct iio_dev 
*indio_dev)
 
dev_info(_dev->dev, "%s: prod_id 0x%04x at CS%d (irq 
%d)\n",
indio_dev->name, prod_id,
-   st->adis.spi->chip_select, st->adis.spi->irq);
+   spi_get_chipselect(st->adis.spi, 0), st->adis.spi->irq);
}
/* use high spi speed if possible */
if (st->variant->flags & ADIS16400_HAS_SLOW_MODE) {
-- 
2.25.1



[PATCH V6 02/15] net: Replace all spi->chip_select and spi->cs_gpiod references with function call

2023-03-10 Thread Amit Kumar Mahapatra
Supporting multi-cs in spi drivers would require the chip_select & cs_gpiod
members of struct spi_device to be an array. But changing the type of these
members to array would break the spi driver functionality. To make the
transition smoother introduced four new APIs to get/set the
spi->chip_select & spi->cs_gpiod and replaced all spi->chip_select and
spi->cs_gpiod references with get or set API calls.
While adding multi-cs support in further patches the chip_select & cs_gpiod
members of the spi_device structure would be converted to arrays & the
"idx" parameter of the APIs would be used as array index i.e.,
spi->chip_select[idx] & spi->cs_gpiod[idx] respectively.

Signed-off-by: Amit Kumar Mahapatra 
Reviewed-by: Michal Simek 
---
 drivers/net/ethernet/adi/adin1110.c| 2 +-
 drivers/net/ethernet/asix/ax88796c_main.c  | 2 +-
 drivers/net/ethernet/davicom/dm9051.c  | 2 +-
 drivers/net/ethernet/qualcomm/qca_debug.c  | 2 +-
 drivers/net/ieee802154/ca8210.c| 2 +-
 drivers/net/wan/slic_ds26522.c | 2 +-
 drivers/net/wireless/marvell/libertas/if_spi.c | 2 +-
 drivers/net/wireless/silabs/wfx/bus_spi.c  | 2 +-
 drivers/net/wireless/st/cw1200/cw1200_spi.c| 2 +-
 9 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/adi/adin1110.c 
b/drivers/net/ethernet/adi/adin1110.c
index 3f316a0f4158..f5c2d7a9abc1 100644
--- a/drivers/net/ethernet/adi/adin1110.c
+++ b/drivers/net/ethernet/adi/adin1110.c
@@ -515,7 +515,7 @@ static int adin1110_register_mdiobus(struct adin1110_priv 
*priv,
return -ENOMEM;
 
snprintf(priv->mii_bus_name, MII_BUS_ID_SIZE, "%s-%u",
-priv->cfg->name, priv->spidev->chip_select);
+priv->cfg->name, spi_get_chipselect(priv->spidev, 0));
 
mii_bus->name = priv->mii_bus_name;
mii_bus->read = adin1110_mdio_read;
diff --git a/drivers/net/ethernet/asix/ax88796c_main.c 
b/drivers/net/ethernet/asix/ax88796c_main.c
index 21376c79f671..e551ffaed20d 100644
--- a/drivers/net/ethernet/asix/ax88796c_main.c
+++ b/drivers/net/ethernet/asix/ax88796c_main.c
@@ -1006,7 +1006,7 @@ static int ax88796c_probe(struct spi_device *spi)
ax_local->mdiobus->parent = >dev;
 
snprintf(ax_local->mdiobus->id, MII_BUS_ID_SIZE,
-"ax88796c-%s.%u", dev_name(>dev), spi->chip_select);
+"ax88796c-%s.%u", dev_name(>dev), spi_get_chipselect(spi, 
0));
 
ret = devm_mdiobus_register(>dev, ax_local->mdiobus);
if (ret < 0) {
diff --git a/drivers/net/ethernet/davicom/dm9051.c 
b/drivers/net/ethernet/davicom/dm9051.c
index de7105a84747..70728b2e5f18 100644
--- a/drivers/net/ethernet/davicom/dm9051.c
+++ b/drivers/net/ethernet/davicom/dm9051.c
@@ -1123,7 +1123,7 @@ static int dm9051_mdio_register(struct board_info *db)
db->mdiobus->phy_mask = (u32)~BIT(1);
db->mdiobus->parent = >dev;
snprintf(db->mdiobus->id, MII_BUS_ID_SIZE,
-"dm9051-%s.%u", dev_name(>dev), spi->chip_select);
+"dm9051-%s.%u", dev_name(>dev), spi_get_chipselect(spi, 
0));
 
ret = devm_mdiobus_register(>dev, db->mdiobus);
if (ret)
diff --git a/drivers/net/ethernet/qualcomm/qca_debug.c 
b/drivers/net/ethernet/qualcomm/qca_debug.c
index f62c39544e08..6f2fa2a42770 100644
--- a/drivers/net/ethernet/qualcomm/qca_debug.c
+++ b/drivers/net/ethernet/qualcomm/qca_debug.c
@@ -119,7 +119,7 @@ qcaspi_info_show(struct seq_file *s, void *what)
seq_printf(s, "SPI mode : %x\n",
   qca->spi_dev->mode);
seq_printf(s, "SPI chip select  : %u\n",
-  (unsigned int)qca->spi_dev->chip_select);
+  (unsigned int)spi_get_chipselect(qca->spi_dev, 0));
seq_printf(s, "SPI legacy mode  : %u\n",
   (unsigned int)qca->legacy_mode);
seq_printf(s, "SPI burst length : %u\n",
diff --git a/drivers/net/ieee802154/ca8210.c b/drivers/net/ieee802154/ca8210.c
index e1a569b99e4a..7093a07141bb 100644
--- a/drivers/net/ieee802154/ca8210.c
+++ b/drivers/net/ieee802154/ca8210.c
@@ -2967,7 +2967,7 @@ static int ca8210_test_interface_init(struct ca8210_priv 
*priv)
sizeof(node_name),
"ca8210@%d_%d",
priv->spi->master->bus_num,
-   priv->spi->chip_select
+   spi_get_chipselect(priv->spi, 0)
);
 
test->ca8210_dfs_spi_int = debugfs_create_file(
diff --git a/drivers/net/wan/slic_ds26522.c b/drivers/net/wan/slic_ds26522.c
index 6063552cea9b..8a51cfcff99e 100644
--- a/drivers/net/wan/slic_ds26522.c
+++ b/drivers/net/wan/slic_ds26522.c
@@ -211,7 +211,7 @@ static int slic_ds26522_probe(struct spi_device *spi)
 
ret = slic_ds26522_init_configure(spi);
if (ret == 0)
-   pr_info("DS26522 cs%d configured\n", spi->chip_select);
+   pr_info("DS26522 cs%d configured\n", spi_get_chipselect(spi, 
0));
 
return ret;
 }

[PATCH V6 01/15] spi: Replace all spi->chip_select and spi->cs_gpiod references with function call

2023-03-10 Thread Amit Kumar Mahapatra
Supporting multi-cs in spi drivers would require the chip_select & cs_gpiod
members of struct spi_device to be an array. But changing the type of these
members to array would break the spi driver functionality. To make the
transition smoother introduced four new APIs to get/set the
spi->chip_select & spi->cs_gpiod and replaced all spi->chip_select and
spi->cs_gpiod references with get or set API calls.
While adding multi-cs support in further patches the chip_select & cs_gpiod
members of the spi_device structure would be converted to arrays & the
"idx" parameter of the APIs would be used as array index i.e.,
spi->chip_select[idx] & spi->cs_gpiod[idx] respectively.

Signed-off-by: Amit Kumar Mahapatra 
Acked-by: Heiko Stuebner  # Rockchip drivers
Reviewed-by: Michal Simek 
Reviewed-by: Cédric Le Goater  # Aspeed driver
Reviewed-by: Dhruva Gole  # SPI Cadence QSPI
Reviewed-by: Patrice Chotard  # spi-stm32-qspi
Acked-by: William Zhang  # bcm63xx-hsspi driver
Reviewed-by: Serge Semin  # DW SSI part
---
 drivers/spi/spi-altera-core.c |  2 +-
 drivers/spi/spi-amd.c |  4 ++--
 drivers/spi/spi-ar934x.c  |  2 +-
 drivers/spi/spi-armada-3700.c |  4 ++--
 drivers/spi/spi-aspeed-smc.c  | 13 +++--
 drivers/spi/spi-at91-usart.c  |  2 +-
 drivers/spi/spi-ath79.c   |  4 ++--
 drivers/spi/spi-atmel.c   | 26 +-
 drivers/spi/spi-au1550.c  |  4 ++--
 drivers/spi/spi-axi-spi-engine.c  |  2 +-
 drivers/spi/spi-bcm-qspi.c| 10 +-
 drivers/spi/spi-bcm2835.c | 19 ++-
 drivers/spi/spi-bcm2835aux.c  |  4 ++--
 drivers/spi/spi-bcm63xx-hsspi.c   | 30 +++---
 drivers/spi/spi-bcm63xx.c |  2 +-
 drivers/spi/spi-bcmbca-hsspi.c| 30 +++---
 drivers/spi/spi-cadence-quadspi.c |  5 +++--
 drivers/spi/spi-cadence-xspi.c|  4 ++--
 drivers/spi/spi-cadence.c |  4 ++--
 drivers/spi/spi-cavium.c  |  8 
 drivers/spi/spi-coldfire-qspi.c   |  8 
 drivers/spi/spi-davinci.c | 18 +-
 drivers/spi/spi-dln2.c|  6 +++---
 drivers/spi/spi-dw-core.c |  2 +-
 drivers/spi/spi-dw-mmio.c |  4 ++--
 drivers/spi/spi-falcon.c  |  2 +-
 drivers/spi/spi-fsi.c |  2 +-
 drivers/spi/spi-fsl-dspi.c| 16 
 drivers/spi/spi-fsl-espi.c|  6 +++---
 drivers/spi/spi-fsl-lpspi.c   |  2 +-
 drivers/spi/spi-fsl-qspi.c|  6 +++---
 drivers/spi/spi-fsl-spi.c |  2 +-
 drivers/spi/spi-geni-qcom.c   |  6 +++---
 drivers/spi/spi-gpio.c|  4 ++--
 drivers/spi/spi-gxp.c |  4 ++--
 drivers/spi/spi-hisi-sfc-v3xx.c   |  2 +-
 drivers/spi/spi-img-spfi.c| 14 +++---
 drivers/spi/spi-imx.c | 30 +++---
 drivers/spi/spi-ingenic.c |  4 ++--
 drivers/spi/spi-intel.c   |  2 +-
 drivers/spi/spi-jcore.c   |  4 ++--
 drivers/spi/spi-lantiq-ssc.c  |  6 +++---
 drivers/spi/spi-mem.c |  4 ++--
 drivers/spi/spi-meson-spicc.c |  2 +-
 drivers/spi/spi-microchip-core.c  |  6 +++---
 drivers/spi/spi-mpc512x-psc.c |  8 
 drivers/spi/spi-mpc52xx.c |  2 +-
 drivers/spi/spi-mt65xx.c  |  6 +++---
 drivers/spi/spi-mt7621.c  |  2 +-
 drivers/spi/spi-mux.c |  8 
 drivers/spi/spi-mxic.c| 10 +-
 drivers/spi/spi-mxs.c |  2 +-
 drivers/spi/spi-npcm-fiu.c| 20 ++--
 drivers/spi/spi-nxp-fspi.c| 10 +-
 drivers/spi/spi-omap-uwire.c  |  8 
 drivers/spi/spi-omap2-mcspi.c | 24 
 drivers/spi/spi-orion.c   |  4 ++--
 drivers/spi/spi-pci1.c|  4 ++--
 drivers/spi/spi-pic32-sqi.c   |  2 +-
 drivers/spi/spi-pic32.c   |  4 ++--
 drivers/spi/spi-pl022.c   |  4 ++--
 drivers/spi/spi-pxa2xx.c  |  6 +++---
 drivers/spi/spi-qcom-qspi.c   |  2 +-
 drivers/spi/spi-rb4xx.c   |  2 +-
 drivers/spi/spi-rockchip-sfc.c|  2 +-
 drivers/spi/spi-rockchip.c| 26 ++
 drivers/spi/spi-rspi.c| 10 +-
 drivers/spi/spi-s3c64xx.c |  2 +-
 drivers/spi/spi-sc18is602.c   |  4 ++--
 drivers/spi/spi-sh-msiof.c|  6 +++---
 drivers/spi/spi-sh-sci.c  |  2 +-
 drivers/spi/spi-sifive.c  |  6 +++---
 drivers/spi/spi-sn-f-ospi.c   |  2 +-
 drivers/spi/spi-st-ssc4.c |  2 +-
 drivers/spi/spi-stm32-qspi.c  | 12 ++--
 drivers/spi/spi-sun4i.c   |  2 +-
 drivers/spi/spi-sun6i.c   |  2 +-
 drivers/spi/spi-synquacer.c   |  6 +++---
 drivers/spi/spi-tegra114.c| 28 ++--
 drivers/spi/spi-tegra20-sflash.c  |  2 +-
 drivers/spi/spi-tegra20-slink.c   |  6 +++---
 drivers/spi/spi-tegra210-quad.c   |  8 
 

[PATCH V6 00/15] Add support for stacked/parallel memories

2023-03-10 Thread Amit Kumar Mahapatra
This patch is in the continuation to the discussions which happened on
'commit f89504300e94 ("spi: Stacked/parallel memories bindings")' for
adding dt-binding support for stacked/parallel memories.

This patch series updated the spi-nor, spi core and the spi drivers
to add stacked and parallel memories support.

The first patch
https://lore.kernel.org/all/20230119185342.2093323-1-amit.kumar-mahapa...@amd.com/
of the previous series got applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
But the rest of the patches in the series did not get applied due to merge
conflict, so send the remaining patches in the series after rebasing it
on top of for-next branch.
---
BRANCH: for-next

Changes in v6:
- Rebased on top of latest v6.3-rc1 and fixed merge conflicts in
  spi-mpc512x-psc.c, sfdp.c, spansion.c files and removed spi-omap-100k.c.
- Updated spi_dev_check( ) to reject new devices if any one of the
  chipselect is used by another device.

Changes in v5:
- Rebased the patches on top of v6.3-rc1 and fixed the merge conflicts.
- Fixed compilation warnings in spi-sh-msiof.c with shmobile_defconfig  

Changes in v4:
- Fixed build error in spi-pl022.c file - reported by Mark.
- Fixed build error in spi-sn-f-ospi.c file.
- Added Reviewed-by: Serge Semin  tag.
- Added two more patches to replace spi->chip_select with API calls in
  mpc832x_rdb.c & cs35l41_hda_spi.c files.

Changes in v3:
- Rebased the patches on top of
  https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
- Added a patch to convert spi_nor_otp_region_len(nor) &
  spi_nor_otp_n_regions(nor) macros into inline functions
- Added Reviewed-by & Acked-by tags

Changes in v2:
- Rebased the patches on top of v6.2-rc1
- Created separate patch to add get & set APIs for spi->chip_select &
  spi->cs_gpiod, and replaced all spi->chip_select and spi->cs_gpiod
  references with the API calls.
- Created separate patch to add get & set APIs for nor->params.
---

Amit Kumar Mahapatra (15):
  spi: Replace all spi->chip_select and spi->cs_gpiod references with
function call
  net: Replace all spi->chip_select and spi->cs_gpiod references with
function call
  iio: imu: Replace all spi->chip_select and spi->cs_gpiod references
with function call
  mtd: devices: Replace all spi->chip_select and spi->cs_gpiod
references with function call
  staging: Replace all spi->chip_select and spi->cs_gpiod references
with function call
  platform/x86: serial-multi-instantiate: Replace all spi->chip_select
and spi->cs_gpiod references with function call
  powerpc/83xx/mpc832x_rdb: Replace all spi->chip_select references with
function call
  ALSA: hda: cs35l41: Replace all spi->chip_select references with
function call
  spi: Add stacked and parallel memories support in SPI core
  mtd: spi-nor: Convert macros with inline functions
  mtd: spi-nor: Add APIs to set/get nor->params
  mtd: spi-nor: Add stacked memories support in spi-nor
  spi: spi-zynqmp-gqspi: Add stacked memories support in GQSPI driver
  mtd: spi-nor: Add parallel memories support in spi-nor
  spi: spi-zynqmp-gqspi: Add parallel memories support in GQSPI driver

 arch/powerpc/platforms/83xx/mpc832x_rdb.c |   2 +-
 drivers/iio/imu/adis16400.c   |   2 +-
 drivers/mtd/devices/mtd_dataflash.c   |   2 +-
 drivers/mtd/spi-nor/atmel.c   |  17 +-
 drivers/mtd/spi-nor/core.c| 665 +++---
 drivers/mtd/spi-nor/core.h|   8 +
 drivers/mtd/spi-nor/debugfs.c |   4 +-
 drivers/mtd/spi-nor/gigadevice.c  |   4 +-
 drivers/mtd/spi-nor/issi.c|  11 +-
 drivers/mtd/spi-nor/macronix.c|   6 +-
 drivers/mtd/spi-nor/micron-st.c   |  39 +-
 drivers/mtd/spi-nor/otp.c |  48 +-
 drivers/mtd/spi-nor/sfdp.c|  29 +-
 drivers/mtd/spi-nor/spansion.c|  50 +-
 drivers/mtd/spi-nor/sst.c |   7 +-
 drivers/mtd/spi-nor/swp.c |  22 +-
 drivers/mtd/spi-nor/winbond.c |  10 +-
 drivers/mtd/spi-nor/xilinx.c  |  18 +-
 drivers/net/ethernet/adi/adin1110.c   |   2 +-
 drivers/net/ethernet/asix/ax88796c_main.c |   2 +-
 drivers/net/ethernet/davicom/dm9051.c |   2 +-
 drivers/net/ethernet/qualcomm/qca_debug.c |   2 +-
 drivers/net/ieee802154/ca8210.c   |   2 +-
 drivers/net/wan/slic_ds26522.c|   2 +-
 .../net/wireless/marvell/libertas/if_spi.c|   2 +-
 drivers/net/wireless/silabs/wfx/bus_spi.c |   2 +-
 drivers/net/wireless/st/cw1200/cw1200_spi.c   |   2 +-
 .../platform/x86/serial-multi-instantiate.c   |   3 +-
 drivers/spi/spi-altera-core.c |   2 +-
 drivers/spi/spi-amd.c |   4 +-
 drivers/spi/spi-ar934x.c  |   2 +-
 drivers/spi/spi-armada-3700.c |   4 +-
 

Re: [PATCH v4 1/4] PCI: Introduce pci_dev_for_each_resource()

2023-03-10 Thread kernel test robot
Hi Andy,

I love your patch! Yet something to improve:

[auto build test ERROR on pci/next]
[also build test ERROR on pci/for-linus powerpc/next powerpc/fixes linus/master 
v6.3-rc1 next-20230310]
[cannot apply to soc/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:
https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/PCI-Introduce-pci_dev_for_each_resource/20230311-011642
base:   https://git.kernel.org/pub/scm/linux/kernel/git/pci/pci.git next
patch link:
https://lore.kernel.org/r/20230310171416.23356-2-andriy.shevchenko%40linux.intel.com
patch subject: [PATCH v4 1/4] PCI: Introduce pci_dev_for_each_resource()
config: m68k-allyesconfig 
(https://download.01.org/0day-ci/archive/20230311/202303110550.blo6p5ds-...@intel.com/config)
compiler: m68k-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# 
https://github.com/intel-lab-lkp/linux/commit/059b4a086017fbf2baacdbe0cc454f569f618ffd
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review 
Andy-Shevchenko/PCI-Introduce-pci_dev_for_each_resource/20230311-011642
git checkout 059b4a086017fbf2baacdbe0cc454f569f618ffd
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 
O=build_dir ARCH=m68k olddefconfig
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 
O=build_dir ARCH=m68k SHELL=/bin/bash drivers/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot 
| Link: 
https://lore.kernel.org/oe-kbuild-all/202303110550.blo6p5ds-...@intel.com/

All errors (new ones prefixed by >>):

   drivers/pnp/quirks.c: In function 'quirk_system_pci_resources':
>> drivers/pnp/quirks.c:245:17: error: implicit declaration of function 
>> 'pci_dev_for_each_resource' [-Werror=implicit-function-declaration]
 245 | pci_dev_for_each_resource(pdev, r, i) {
 | ^
>> drivers/pnp/quirks.c:245:54: error: expected ';' before '{' token
 245 | pci_dev_for_each_resource(pdev, r, i) {
 |  ^~
 |  ;
   drivers/pnp/quirks.c:233:16: warning: unused variable 'j' [-Wunused-variable]
 233 | int i, j;
 |^
   drivers/pnp/quirks.c:232:26: warning: unused variable 'res' 
[-Wunused-variable]
 232 | struct resource *res, *r;
 |  ^~~
   cc1: some warnings being treated as errors


vim +/pci_dev_for_each_resource +245 drivers/pnp/quirks.c

   228  
   229  static void quirk_system_pci_resources(struct pnp_dev *dev)
   230  {
   231  struct pci_dev *pdev = NULL;
   232  struct resource *res, *r;
   233  int i, j;
   234  
   235  /*
   236   * Some BIOSes have PNP motherboard devices with resources that
   237   * partially overlap PCI BARs.  The PNP system driver claims 
these
   238   * motherboard resources, which prevents the normal PCI driver 
from
   239   * requesting them later.
   240   *
   241   * This patch disables the PNP resources that conflict with PCI 
BARs
   242   * so they won't be claimed by the PNP system driver.
   243   */
   244  for_each_pci_dev(pdev) {
 > 245  pci_dev_for_each_resource(pdev, r, i) {
   246  unsigned long type = resource_type(r);
   247  
   248  if (type != IORESOURCE_IO || type != 
IORESOURCE_MEM ||
   249  resource_size(r) == 0)
   250  continue;
   251  
   252  if (r->flags & IORESOURCE_UNSET)
   253  continue;
   254  
   255  for (j = 0;
   256   (res = pnp_get_resource(dev, type, j)); 
j++) {
   257  if (res->start == 0 && res->end == 0)
   258  continue;
   259  
   260  /*
   261   * If the PNP region doesn't overlap 
the PCI
   262   * region at all, there's no problem.
   263   */
   264  if (!resource_overlaps(res, r))
   265  continue;
  

Re: [PATCH v4 3/4] arch/*/io.h: remove ioremap_uc in some architectures

2023-03-10 Thread Helge Deller

On 3/10/23 02:45, Baoquan He wrote:

On 03/09/23 at 03:36pm, Thomas Bogendoerfer wrote:

On Wed, Mar 08, 2023 at 09:07:09PM +0800, Baoquan He wrote:

ioremap_uc() is only meaningful on old x86-32 systems with the PAT
extension, and on ia64 with its slightly unconventional ioremap()
behavior. So remove the ioremap_uc() definition in architecutures
other than x86 and ia64. These architectures all have asm-generic/io.h
included and will have the default ioremap_uc() definition which
returns NULL.

This changes the existing behaviour, while no need to worry about
any breakage because in the only callsite of ioremap_uc(), code
has been adjusted to eliminate the impact. Please see
atyfb_setup_generic() of drivers/video/fbdev/aty/atyfb_base.c.

If any new invocation of ioremap_uc() need be added, please consider
using ioremap() intead or adding a ARCH specific version if necessary.

Acked-by: Geert Uytterhoeven 
Signed-off-by: Baoquan He 
Cc: linux-al...@vger.kernel.org
Cc: linux-hexa...@vger.kernel.org
Cc: linux-m...@lists.linux-m68k.org
Cc: linux-m...@vger.kernel.org
Cc: linux-par...@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux...@vger.kernel.org
Cc: sparcli...@vger.kernel.org
---
  Documentation/driver-api/device-io.rst | 9 +
  arch/alpha/include/asm/io.h| 1 -
  arch/hexagon/include/asm/io.h  | 3 ---
  arch/m68k/include/asm/kmap.h   | 1 -
  arch/mips/include/asm/io.h | 1 -
  arch/parisc/include/asm/io.h   | 2 --
  arch/powerpc/include/asm/io.h  | 1 -
  arch/sh/include/asm/io.h   | 2 --
  arch/sparc/include/asm/io_64.h | 1 -
  9 files changed, 5 insertions(+), 16 deletions(-)


this doesn't apply to v6.3-rc1... what tree is this based on ?


Sorry, I forgot mentioning this in cover letter. This series is
followup of below patchset, so it's on top of below patchset and based
on v6.3-rc1.

https://lore.kernel.org/all/20230301034247.136007-1-...@redhat.com/T/#u
[PATCH v5 00/17] mm: ioremap:  Convert architectures to take GENERIC_IOREMAP way


I've applied both patch series on top of v6.3-rc1 and
tested it with success on the parisc platform (32- and 64-bit kernel).

You may add to both patch series:

Acked-by: Helge Deller   # parisc

Thank you!
Helge


Re: [PATCH v2] vdso: Improve cmd_vdso_check to check all dynamic relocations

2023-03-10 Thread Fangrui Song



On 2023-03-10, Vincenzo Frascino wrote:

Hi Fangrui,

Apologize for the delay, I totally missed that you had a new version of your
patch since it was threaded with the old one.


Thank you! No worries.


On 12/21/22 23:51, Fangrui Song wrote:

The actual intention is that no dynamic relocation exists. However, some
GNU ld ports produce unneeded R_*_NONE. (If a port fails to determine
the exact .rel[a].dyn size, the trailing zeros become R_*_NONE
relocations. E.g. ld's powerpc port recently fixed
https://sourceware.org/bugzilla/show_bug.cgi?id=29540) R_*_NONE are
generally no-op in the dynamic loaders. So just ignore them.

With the change, we can remove ARCH_REL_TYPE_ABS. ARCH_REL_TYPE_ABS is a
bit misnomer as ports may check RELAVETIVE/GLOB_DAT/JUMP_SLOT which are
not called "absolute relocations". (The patch is motivated by the arm64
port missing R_AARCH64_RELATIVE.)


It makes sense to update the name, it started as "absolute relocations" but then
it evolved into something else.

A part that, did you perform any testing with the generated vDSO libraries?


I checked that the built vdso did not change (the patch just changes
some post-link verification). 


To be more sure, I used commands like
https://github.com/ClangBuiltLinux/tc-build/blob/main/kernel/build.sh#L305
to build a kernel and commands like

~/Dev/ClangBuiltLinux/boot-utils/boot-qemu.py -a arm64 -k /tmp/linux/arm64

to run an image for a couple of architectures.

The initrd images run some init scripts along with

  # buildroot/overlay-poweroff/etc/init.d/S50yolo
  cat /proc/version
  poweroff

I think these have exercised vdso.



Signed-off-by: Fangrui Song 
Reviewed-by: Christophe Leroy 
---
Change from v1:
* rebase after 8ac3b5cd3e0521d92f9755e90d140382fc292510 (lib/vdso: use "grep -E"
instead of "egrep")
* change the commit message to mention an example GNU ld bug; no longer say the
patch fixes a deprecated egrep use
---
 arch/arm/vdso/Makefile    |  3 ---
 arch/arm64/kernel/vdso/Makefile   |  3 ---
 arch/arm64/kernel/vdso32/Makefile |  3 ---
 arch/csky/kernel/vdso/Makefile    |  3 ---
 arch/loongarch/vdso/Makefile  |  3 ---
 arch/mips/vdso/Makefile   |  3 ---
 arch/powerpc/kernel/vdso/Makefile |  1 -
 arch/riscv/kernel/vdso/Makefile   |  3 ---
 arch/s390/kernel/vdso32/Makefile  |  2 --
 arch/s390/kernel/vdso64/Makefile  |  2 --
 arch/x86/entry/vdso/Makefile  |  4 
 lib/vdso/Makefile | 13 -
 12 files changed, 4 insertions(+), 39 deletions(-)

diff --git a/arch/arm/vdso/Makefile b/arch/arm/vdso/Makefile
index a7ec06ce3785..e58197bba776 100644
--- a/arch/arm/vdso/Makefile
+++ b/arch/arm/vdso/Makefile
@@ -1,8 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
 
-# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
-# the inclusion of generic Makefile.
-ARCH_REL_TYPE_ABS := R_ARM_JUMP_SLOT|R_ARM_GLOB_DAT|R_ARM_ABS32


I would still add a comment here to say why we are including the generic
Makefile to prevent that it gets accidentally removed (similar thing for every
architecture touched by this patch).

With that:

Reviewed-by: Vincenzo Frascino  # for vDSO, aarch64
Tested-by: Vincenzo Frascino  # for aarch64



Just sent v3
(https://lore.kernel.org/all/20230310190750.3323802-1-mask...@google.com/)
with the comment changes. Thanks!


 include $(srctree)/lib/vdso/Makefile
 
 hostprogs := vdsomunge
diff --git a/arch/arm64/kernel/vdso/Makefile b/arch/arm64/kernel/vdso/Makefile
index beaf9586338f..1f2427b13410 100644
--- a/arch/arm64/kernel/vdso/Makefile
+++ b/arch/arm64/kernel/vdso/Makefile
@@ -6,9 +6,6 @@
 # Heavily based on the vDSO Makefiles for other archs.
 #
 
-# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
-# the inclusion of generic Makefile.
-ARCH_REL_TYPE_ABS := R_AARCH64_JUMP_SLOT|R_AARCH64_GLOB_DAT|R_AARCH64_ABS64
 include $(srctree)/lib/vdso/Makefile
 
 obj-vdso := vgettimeofday.o note.o sigreturn.o
diff --git a/arch/arm64/kernel/vdso32/Makefile 
b/arch/arm64/kernel/vdso32/Makefile
index f59bd1a4ead6..d014162c5c71 100644
--- a/arch/arm64/kernel/vdso32/Makefile
+++ b/arch/arm64/kernel/vdso32/Makefile
@@ -3,9 +3,6 @@
 # Makefile for vdso32
 #
 
-# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
-# the inclusion of generic Makefile.
-ARCH_REL_TYPE_ABS := R_ARM_JUMP_SLOT|R_ARM_GLOB_DAT|R_ARM_ABS32
 include $(srctree)/lib/vdso/Makefile
 
 # Same as cc-*option, but using CC_COMPAT instead of CC
diff --git a/arch/csky/kernel/vdso/Makefile b/arch/csky/kernel/vdso/Makefile
index 0b6909f10667..86c8c4de1b0f 100644
--- a/arch/csky/kernel/vdso/Makefile
+++ b/arch/csky/kernel/vdso/Makefile
@@ -1,8 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
-# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
-# the inclusion of generic Makefile.
-ARCH_REL_TYPE_ABS := R_CKCORE_ADDR32|R_CKCORE_JUMP_SLOT
 include $(srctree)/lib/vdso/Makefile
 
 # Symbols present in the vdso
diff --git 

[PATCH v3] vdso: Improve cmd_vdso_check to check all dynamic relocations

2023-03-10 Thread Fangrui Song
The actual intention is that no dynamic relocation exists. However, some
GNU ld ports produce unneeded R_*_NONE. (If a port fails to determine
the exact .rel[a].dyn size, the trailing zeros become R_*_NONE
relocations. E.g. ld's powerpc port recently fixed
https://sourceware.org/bugzilla/show_bug.cgi?id=29540) R_*_NONE are
generally no-op in the dynamic loaders. So just ignore them.

With the change, we can remove ARCH_REL_TYPE_ABS. ARCH_REL_TYPE_ABS is a
bit misnomer as ports may check RELAVETIVE/GLOB_DAT/JUMP_SLOT which are
not called "absolute relocations". (The patch is motivated by the arm64
port missing R_AARCH64_RELATIVE.)

Signed-off-by: Fangrui Song 
Reviewed-by: Christophe Leroy 
Reviewed-by: Vincenzo Frascino  # for vDSO, aarch64
Tested-by: Vincenzo Frascino  # for aarch64
---
Changes from v2:
* rebase

Changes from v3:
* Add a comment before `include $(srctree)/lib/vdso/Makefile` in every touched 
arch Makefile
---
 arch/arm/vdso/Makefile|  4 +---
 arch/arm64/kernel/vdso/Makefile   |  4 +---
 arch/arm64/kernel/vdso32/Makefile |  3 ---
 arch/csky/kernel/vdso/Makefile|  4 +---
 arch/loongarch/vdso/Makefile  |  4 +---
 arch/mips/vdso/Makefile   |  4 +---
 arch/powerpc/kernel/vdso/Makefile |  2 +-
 arch/riscv/kernel/vdso/Makefile   |  4 +---
 arch/s390/kernel/vdso32/Makefile  |  3 +--
 arch/s390/kernel/vdso64/Makefile  |  3 +--
 arch/x86/entry/vdso/Makefile  |  5 +
 lib/vdso/Makefile | 13 -
 12 files changed, 14 insertions(+), 39 deletions(-)

diff --git a/arch/arm/vdso/Makefile b/arch/arm/vdso/Makefile
index a7ec06ce3785..515ca33b854c 100644
--- a/arch/arm/vdso/Makefile
+++ b/arch/arm/vdso/Makefile
@@ -1,8 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 
-# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
-# the inclusion of generic Makefile.
-ARCH_REL_TYPE_ABS := R_ARM_JUMP_SLOT|R_ARM_GLOB_DAT|R_ARM_ABS32
+# Include the generic Makefile to check the built vdso.
 include $(srctree)/lib/vdso/Makefile
 
 hostprogs := vdsomunge
diff --git a/arch/arm64/kernel/vdso/Makefile b/arch/arm64/kernel/vdso/Makefile
index beaf9586338f..fe7a53c6781f 100644
--- a/arch/arm64/kernel/vdso/Makefile
+++ b/arch/arm64/kernel/vdso/Makefile
@@ -6,9 +6,7 @@
 # Heavily based on the vDSO Makefiles for other archs.
 #
 
-# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
-# the inclusion of generic Makefile.
-ARCH_REL_TYPE_ABS := R_AARCH64_JUMP_SLOT|R_AARCH64_GLOB_DAT|R_AARCH64_ABS64
+# Include the generic Makefile to check the built vdso.
 include $(srctree)/lib/vdso/Makefile
 
 obj-vdso := vgettimeofday.o note.o sigreturn.o
diff --git a/arch/arm64/kernel/vdso32/Makefile 
b/arch/arm64/kernel/vdso32/Makefile
index f59bd1a4ead6..d014162c5c71 100644
--- a/arch/arm64/kernel/vdso32/Makefile
+++ b/arch/arm64/kernel/vdso32/Makefile
@@ -3,9 +3,6 @@
 # Makefile for vdso32
 #
 
-# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
-# the inclusion of generic Makefile.
-ARCH_REL_TYPE_ABS := R_ARM_JUMP_SLOT|R_ARM_GLOB_DAT|R_ARM_ABS32
 include $(srctree)/lib/vdso/Makefile
 
 # Same as cc-*option, but using CC_COMPAT instead of CC
diff --git a/arch/csky/kernel/vdso/Makefile b/arch/csky/kernel/vdso/Makefile
index 0b6909f10667..299e4e41ebc5 100644
--- a/arch/csky/kernel/vdso/Makefile
+++ b/arch/csky/kernel/vdso/Makefile
@@ -1,8 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
-# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
-# the inclusion of generic Makefile.
-ARCH_REL_TYPE_ABS := R_CKCORE_ADDR32|R_CKCORE_JUMP_SLOT
+# Include the generic Makefile to check the built vdso.
 include $(srctree)/lib/vdso/Makefile
 
 # Symbols present in the vdso
diff --git a/arch/loongarch/vdso/Makefile b/arch/loongarch/vdso/Makefile
index d89e2ac75f7b..461240ab4436 100644
--- a/arch/loongarch/vdso/Makefile
+++ b/arch/loongarch/vdso/Makefile
@@ -1,9 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 # Objects to go into the VDSO.
 
-# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
-# the inclusion of generic Makefile.
-ARCH_REL_TYPE_ABS := R_LARCH_32|R_LARCH_64|R_LARCH_MARK_LA|R_LARCH_JUMP_SLOT
+# Include the generic Makefile to check the built vdso.
 include $(srctree)/lib/vdso/Makefile
 
 obj-vdso-y := elf.o vgetcpu.o vgettimeofday.o sigreturn.o
diff --git a/arch/mips/vdso/Makefile b/arch/mips/vdso/Makefile
index 18af9474ed0e..eb56581f6d73 100644
--- a/arch/mips/vdso/Makefile
+++ b/arch/mips/vdso/Makefile
@@ -4,9 +4,7 @@
 # Sanitizer runtimes are unavailable and cannot be linked here.
  KCSAN_SANITIZE:= n
 
-# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
-# the inclusion of generic Makefile.
-ARCH_REL_TYPE_ABS := R_MIPS_JUMP_SLOT|R_MIPS_GLOB_DAT
+# Include the generic Makefile to check the built vdso.
 include $(srctree)/lib/vdso/Makefile
 
 obj-vdso-y := elf.o vgettimeofday.o sigreturn.o
diff --git 

Re: [PATCH v2 1/4] powerpc/code-patching: introduce patch_instructions()

2023-03-10 Thread Christophe Leroy


Le 09/03/2023 à 19:02, Hari Bathini a écrit :
> patch_instruction() entails setting up pte, patching the instruction,
> clearing the pte and flushing the tlb. If multiple instructions need
> to be patched, every instruction would have to go through the above
> drill unnecessarily. Instead, introduce function patch_instructions()
> that patches multiple instructions at one go while setting up the pte,
> clearing the pte and flushing the tlb only once per page range of
> instructions. Observed ~5X improvement in speed of execution using
> patch_instructions() over patch_instructions(), when more instructions
> are to be patched.

I get a 13% degradation on the time needed to activate ftrace on a 
powerpc 8xx.

Before your patch, activation ftrace takes 550k timebase ticks. After 
your patch it takes 620k timebase ticks.

Christophe

> 
> Signed-off-by: Hari Bathini 
> ---
>   arch/powerpc/include/asm/code-patching.h |   1 +
>   arch/powerpc/lib/code-patching.c | 151 ---
>   2 files changed, 106 insertions(+), 46 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/code-patching.h 
> b/arch/powerpc/include/asm/code-patching.h
> index 3f881548fb61..059fc4fe700e 100644
> --- a/arch/powerpc/include/asm/code-patching.h
> +++ b/arch/powerpc/include/asm/code-patching.h
> @@ -74,6 +74,7 @@ int create_cond_branch(ppc_inst_t *instr, const u32 *addr,
>   int patch_branch(u32 *addr, unsigned long target, int flags);
>   int patch_instruction(u32 *addr, ppc_inst_t instr);
>   int raw_patch_instruction(u32 *addr, ppc_inst_t instr);
> +int patch_instructions(u32 *addr, u32 *code, bool fill_inst, size_t len);
>   
>   static inline unsigned long patch_site_addr(s32 *site)
>   {
> diff --git a/arch/powerpc/lib/code-patching.c 
> b/arch/powerpc/lib/code-patching.c
> index b00112d7ad46..33857b9b53de 100644
> --- a/arch/powerpc/lib/code-patching.c
> +++ b/arch/powerpc/lib/code-patching.c
> @@ -278,77 +278,117 @@ static void unmap_patch_area(unsigned long addr)
>   flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
>   }
>   
> -static int __do_patch_instruction_mm(u32 *addr, ppc_inst_t instr)
> +static int __do_patch_instructions_mm(u32 *addr, u32 *code, bool fill_inst, 
> size_t len)
>   {
> - int err;
> - u32 *patch_addr;
> - unsigned long text_poke_addr;
> - pte_t *pte;
> - unsigned long pfn = get_patch_pfn(addr);
> - struct mm_struct *patching_mm;
> - struct mm_struct *orig_mm;
> + struct mm_struct *patching_mm, *orig_mm;
> + unsigned long text_poke_addr, pfn;
> + u32 *patch_addr, *end, *pend;
> + ppc_inst_t instr;
>   spinlock_t *ptl;
> + int ilen, err;
> + pte_t *pte;
>   
>   patching_mm = __this_cpu_read(cpu_patching_context.mm);
>   text_poke_addr = __this_cpu_read(cpu_patching_context.addr);
> - patch_addr = (u32 *)(text_poke_addr + offset_in_page(addr));
>   
>   pte = get_locked_pte(patching_mm, text_poke_addr, );
>   if (!pte)
>   return -ENOMEM;
>   
> - __set_pte_at(patching_mm, text_poke_addr, pte, pfn_pte(pfn, 
> PAGE_KERNEL), 0);
> + end = (void *)addr + len;
> + do {
> + pfn = get_patch_pfn(addr);
> + __set_pte_at(patching_mm, text_poke_addr, pte, pfn_pte(pfn, 
> PAGE_KERNEL), 0);
>   
> - /* order PTE update before use, also serves as the hwsync */
> - asm volatile("ptesync": : :"memory");
> -
> - /* order context switch after arbitrary prior code */
> - isync();
> -
> - orig_mm = start_using_temp_mm(patching_mm);
> -
> - err = __patch_instruction(addr, instr, patch_addr);
> + /* order PTE update before use, also serves as the hwsync */
> + asm volatile("ptesync": : :"memory");
>   
> - /* hwsync performed by __patch_instruction (sync) if successful */
> - if (err)
> - mb();  /* sync */
> + /* order context switch after arbitrary prior code */
> + isync();
> +
> + orig_mm = start_using_temp_mm(patching_mm);
> +
> + patch_addr = (u32 *)(text_poke_addr + offset_in_page(addr));
> + pend = (void *)addr + PAGE_SIZE - offset_in_page(addr);
> + if (end < pend)
> + pend = end;
> +
> + while (addr < pend) {
> + instr = ppc_inst_read(code);
> + ilen = ppc_inst_len(instr);
> + err = __patch_instruction(addr, instr, patch_addr);
> + /* hwsync performed by __patch_instruction (sync) if 
> successful */
> + if (err) {
> + mb();  /* sync */
> + break;
> + }
> +
> + patch_addr = (void *)patch_addr + ilen;
> + addr = (void *)addr + ilen;
> + if (!fill_inst)
> + code = (void *)code + ilen;
> + }
>   
> - /* context 

[PATCH v4 1/4] PCI: Introduce pci_dev_for_each_resource()

2023-03-10 Thread Andy Shevchenko
From: Mika Westerberg 

Instead of open-coding it everywhere introduce a tiny helper that can be
used to iterate over each resource of a PCI device, and convert the most
obvious users into it.

While at it drop doubled empty line before pdev_sort_resources().

No functional changes intended.

Suggested-by: Andy Shevchenko 
Signed-off-by: Mika Westerberg 
Signed-off-by: Andy Shevchenko 
Reviewed-by: Krzysztof Wilczyński 
---
 .clang-format |  2 ++
 arch/alpha/kernel/pci.c   |  5 ++--
 arch/arm/kernel/bios32.c  | 16 ++---
 arch/arm/mach-dove/pcie.c | 10 
 arch/arm/mach-mv78xx0/pcie.c  | 10 
 arch/arm/mach-orion5x/pci.c   | 10 
 arch/mips/pci/ops-bcm63xx.c   |  8 +++
 arch/mips/pci/pci-legacy.c|  3 +--
 arch/powerpc/kernel/pci-common.c  | 21 
 arch/powerpc/platforms/4xx/pci.c  |  8 +++
 arch/powerpc/platforms/52xx/mpc52xx_pci.c |  4 ++--
 arch/powerpc/platforms/pseries/pci.c  | 16 ++---
 arch/sh/drivers/pci/pcie-sh7786.c | 10 
 arch/sparc/kernel/leon_pci.c  |  5 ++--
 arch/sparc/kernel/pci.c   | 10 
 arch/sparc/kernel/pcic.c  |  5 ++--
 drivers/pci/remove.c  |  5 ++--
 drivers/pci/setup-bus.c   | 27 -
 drivers/pci/setup-res.c   |  4 +---
 drivers/pci/vgaarb.c  | 17 -
 drivers/pci/xen-pcifront.c|  4 +---
 drivers/pnp/quirks.c  | 29 ---
 include/linux/pci.h   | 12 ++
 23 files changed, 110 insertions(+), 131 deletions(-)

diff --git a/.clang-format b/.clang-format
index d988e9fa9b26..266abb843654 100644
--- a/.clang-format
+++ b/.clang-format
@@ -520,6 +520,8 @@ ForEachMacros:
   - 'of_property_for_each_string'
   - 'of_property_for_each_u32'
   - 'pci_bus_for_each_resource'
+  - 'pci_dev_for_each_resource'
+  - 'pci_dev_for_each_resource_p'
   - 'pci_doe_for_each_off'
   - 'pcl_for_each_chunk'
   - 'pcl_for_each_segment'
diff --git a/arch/alpha/kernel/pci.c b/arch/alpha/kernel/pci.c
index 64fbfb0763b2..4458eb7f44f0 100644
--- a/arch/alpha/kernel/pci.c
+++ b/arch/alpha/kernel/pci.c
@@ -288,11 +288,10 @@ pcibios_claim_one_bus(struct pci_bus *b)
struct pci_bus *child_bus;
 
list_for_each_entry(dev, >devices, bus_list) {
+   struct resource *r;
int i;
 
-   for (i = 0; i < PCI_NUM_RESOURCES; i++) {
-   struct resource *r = >resource[i];
-
+   pci_dev_for_each_resource(dev, r, i) {
if (r->parent || !r->start || !r->flags)
continue;
if (pci_has_flag(PCI_PROBE_ONLY) ||
diff --git a/arch/arm/kernel/bios32.c b/arch/arm/kernel/bios32.c
index e7ef2b5bea9c..5254734b23e6 100644
--- a/arch/arm/kernel/bios32.c
+++ b/arch/arm/kernel/bios32.c
@@ -142,15 +142,15 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_WINBOND2, 
PCI_DEVICE_ID_WINBOND2_89C940F,
  */
 static void pci_fixup_dec21285(struct pci_dev *dev)
 {
-   int i;
-
if (dev->devfn == 0) {
+   struct resource *r;
+
dev->class &= 0xff;
dev->class |= PCI_CLASS_BRIDGE_HOST << 8;
-   for (i = 0; i < PCI_NUM_RESOURCES; i++) {
-   dev->resource[i].start = 0;
-   dev->resource[i].end   = 0;
-   dev->resource[i].flags = 0;
+   pci_dev_for_each_resource_p(dev, r) {
+   r->start = 0;
+   r->end = 0;
+   r->flags = 0;
}
}
 }
@@ -162,13 +162,11 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_DEC, 
PCI_DEVICE_ID_DEC_21285, pci_fixup_d
 static void pci_fixup_ide_bases(struct pci_dev *dev)
 {
struct resource *r;
-   int i;
 
if ((dev->class >> 8) != PCI_CLASS_STORAGE_IDE)
return;
 
-   for (i = 0; i < PCI_NUM_RESOURCES; i++) {
-   r = dev->resource + i;
+   pci_dev_for_each_resource_p(dev, r) {
if ((r->start & ~0x80) == 0x374) {
r->start |= 2;
r->end = r->start;
diff --git a/arch/arm/mach-dove/pcie.c b/arch/arm/mach-dove/pcie.c
index 754ca381f600..58cecd79a204 100644
--- a/arch/arm/mach-dove/pcie.c
+++ b/arch/arm/mach-dove/pcie.c
@@ -142,14 +142,14 @@ static struct pci_ops pcie_ops = {
 static void rc_pci_fixup(struct pci_dev *dev)
 {
if (dev->bus->parent == NULL && dev->devfn == 0) {
-   int i;
+   struct resource *r;
 
dev->class &= 0xff;
dev->class |= PCI_CLASS_BRIDGE_HOST << 8;
-   for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
-   

[PATCH v4 4/4] pcmcia: Convert to use pci_bus_for_each_resource_p()

2023-03-10 Thread Andy Shevchenko
The pci_bus_for_each_resource_p() hides the iterator loop since
it may be not used otherwise. With this, we may drop that iterator
variable definition.

Signed-off-by: Andy Shevchenko 
Reviewed-by: Krzysztof Wilczyński 
Acked-by: Dominik Brodowski 
---
 drivers/pcmcia/rsrc_nonstatic.c | 9 +++--
 drivers/pcmcia/yenta_socket.c   | 3 +--
 2 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c
index ad1141fddb4c..9d92d4bb6239 100644
--- a/drivers/pcmcia/rsrc_nonstatic.c
+++ b/drivers/pcmcia/rsrc_nonstatic.c
@@ -934,7 +934,7 @@ static int adjust_io(struct pcmcia_socket *s, unsigned int 
action, unsigned long
 static int nonstatic_autoadd_resources(struct pcmcia_socket *s)
 {
struct resource *res;
-   int i, done = 0;
+   int done = 0;
 
if (!s->cb_dev || !s->cb_dev->bus)
return -ENODEV;
@@ -960,12 +960,9 @@ static int nonstatic_autoadd_resources(struct 
pcmcia_socket *s)
 */
if (s->cb_dev->bus->number == 0)
return -EINVAL;
-
-   for (i = 0; i < PCI_BRIDGE_RESOURCE_NUM; i++) {
-   res = s->cb_dev->bus->resource[i];
-#else
-   pci_bus_for_each_resource(s->cb_dev->bus, res, i) {
 #endif
+
+   pci_bus_for_each_resource_p(s->cb_dev->bus, res) {
if (!res)
continue;
 
diff --git a/drivers/pcmcia/yenta_socket.c b/drivers/pcmcia/yenta_socket.c
index 1365eaa20ff4..2e5bdf3db0ba 100644
--- a/drivers/pcmcia/yenta_socket.c
+++ b/drivers/pcmcia/yenta_socket.c
@@ -673,9 +673,8 @@ static int yenta_search_res(struct yenta_socket *socket, 
struct resource *res,
u32 min)
 {
struct resource *root;
-   int i;
 
-   pci_bus_for_each_resource(socket->dev->bus, root, i) {
+   pci_bus_for_each_resource_p(socket->dev->bus, root) {
if (!root)
continue;
 
-- 
2.39.1



[PATCH v4 3/4] EISA: Convert to use pci_bus_for_each_resource_p()

2023-03-10 Thread Andy Shevchenko
The pci_bus_for_each_resource_p() hides the iterator loop since
it may be not used otherwise. With this, we may drop that iterator
variable definition.

Signed-off-by: Andy Shevchenko 
Reviewed-by: Krzysztof Wilczyński 
---
 drivers/eisa/pci_eisa.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/eisa/pci_eisa.c b/drivers/eisa/pci_eisa.c
index 930c2332c3c4..907b86384396 100644
--- a/drivers/eisa/pci_eisa.c
+++ b/drivers/eisa/pci_eisa.c
@@ -20,8 +20,8 @@ static struct eisa_root_device pci_eisa_root;
 
 static int __init pci_eisa_init(struct pci_dev *pdev)
 {
-   int rc, i;
struct resource *res, *bus_res = NULL;
+   int rc;
 
if ((rc = pci_enable_device (pdev))) {
dev_err(>dev, "Could not enable device\n");
@@ -38,7 +38,7 @@ static int __init pci_eisa_init(struct pci_dev *pdev)
 * eisa_root_register() can only deal with a single io port resource,
*  so we use the first valid io port resource.
 */
-   pci_bus_for_each_resource(pdev->bus, res, i)
+   pci_bus_for_each_resource_p(pdev->bus, res)
if (res && (res->flags & IORESOURCE_IO)) {
bus_res = res;
break;
-- 
2.39.1



[PATCH v4 0/4] PCI: Add pci_dev_for_each_resource() helper and update users

2023-03-10 Thread Andy Shevchenko
Provide two new helper macros to iterate over PCI device resources and
convert users.

Looking at it, refactor existing pci_bus_for_each_resource() and convert
users accordingly.

Changelog v4:
- rebased on top of v6.3-rc1
- added tag (Krzysztof)

Changelog v3:
- rebased on top of v2 by Mika, see above
- added tag to pcmcia patch (Dominik)

Changelog v2:
- refactor to have two macros
- refactor existing pci_bus_for_each_resource() in the same way and
  convert users

Andy Shevchenko (3):
  PCI: Split pci_bus_for_each_resource_p() out of
pci_bus_for_each_resource()
  EISA: Convert to use pci_bus_for_each_resource_p()
  pcmcia: Convert to use pci_bus_for_each_resource_p()

Mika Westerberg (1):
  PCI: Introduce pci_dev_for_each_resource()

 .clang-format |  3 ++
 arch/alpha/kernel/pci.c   |  5 ++-
 arch/arm/kernel/bios32.c  | 16 +-
 arch/arm/mach-dove/pcie.c | 10 +++---
 arch/arm/mach-mv78xx0/pcie.c  | 10 +++---
 arch/arm/mach-orion5x/pci.c   | 10 +++---
 arch/mips/pci/ops-bcm63xx.c   |  8 ++---
 arch/mips/pci/pci-legacy.c|  3 +-
 arch/powerpc/kernel/pci-common.c  | 21 +++--
 arch/powerpc/platforms/4xx/pci.c  |  8 ++---
 arch/powerpc/platforms/52xx/mpc52xx_pci.c |  4 +--
 arch/powerpc/platforms/pseries/pci.c  | 16 +-
 arch/sh/drivers/pci/pcie-sh7786.c | 10 +++---
 arch/sparc/kernel/leon_pci.c  |  5 ++-
 arch/sparc/kernel/pci.c   | 10 +++---
 arch/sparc/kernel/pcic.c  |  5 ++-
 drivers/eisa/pci_eisa.c   |  4 +--
 drivers/pci/bus.c |  7 ++---
 drivers/pci/hotplug/shpchp_sysfs.c|  8 ++---
 drivers/pci/pci.c |  5 ++-
 drivers/pci/probe.c   |  2 +-
 drivers/pci/remove.c  |  5 ++-
 drivers/pci/setup-bus.c   | 37 +--
 drivers/pci/setup-res.c   |  4 +--
 drivers/pci/vgaarb.c  | 17 +++
 drivers/pci/xen-pcifront.c|  4 +--
 drivers/pcmcia/rsrc_nonstatic.c   |  9 ++
 drivers/pcmcia/yenta_socket.c |  3 +-
 drivers/pnp/quirks.c  | 29 ++
 include/linux/pci.h   | 26 +---
 30 files changed, 141 insertions(+), 163 deletions(-)

-- 
2.39.1



[PATCH v4 2/4] PCI: Split pci_bus_for_each_resource_p() out of pci_bus_for_each_resource()

2023-03-10 Thread Andy Shevchenko
Refactor pci_bus_for_each_resource() in the same way as it's done in
pci_dev_for_each_resource() case. This will allow to hide iterator
inside the loop, where it's not used otherwise.

No functional changes intended.

Signed-off-by: Andy Shevchenko 
Reviewed-by: Krzysztof Wilczyński 
---
 .clang-format  |  1 +
 drivers/pci/bus.c  |  7 +++
 drivers/pci/hotplug/shpchp_sysfs.c |  8 
 drivers/pci/pci.c  |  5 ++---
 drivers/pci/probe.c|  2 +-
 drivers/pci/setup-bus.c| 10 --
 include/linux/pci.h| 14 ++
 7 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/.clang-format b/.clang-format
index 266abb843654..81c9f055086f 100644
--- a/.clang-format
+++ b/.clang-format
@@ -520,6 +520,7 @@ ForEachMacros:
   - 'of_property_for_each_string'
   - 'of_property_for_each_u32'
   - 'pci_bus_for_each_resource'
+  - 'pci_bus_for_each_resource_p'
   - 'pci_dev_for_each_resource'
   - 'pci_dev_for_each_resource_p'
   - 'pci_doe_for_each_off'
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index 83ae838ceb5f..b48bcc965a42 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -161,13 +161,13 @@ static int pci_bus_alloc_from_region(struct pci_bus *bus, 
struct resource *res,
void *alignf_data,
struct pci_bus_region *region)
 {
-   int i, ret;
struct resource *r, avail;
resource_size_t max;
+   int ret;
 
type_mask |= IORESOURCE_TYPE_BITS;
 
-   pci_bus_for_each_resource(bus, r, i) {
+   pci_bus_for_each_resource_p(bus, r) {
resource_size_t min_used = min;
 
if (!r)
@@ -268,9 +268,8 @@ bool pci_bus_clip_resource(struct pci_dev *dev, int idx)
struct resource *res = >resource[idx];
struct resource orig_res = *res;
struct resource *r;
-   int i;
 
-   pci_bus_for_each_resource(bus, r, i) {
+   pci_bus_for_each_resource_p(bus, r) {
resource_size_t start, end;
 
if (!r)
diff --git a/drivers/pci/hotplug/shpchp_sysfs.c 
b/drivers/pci/hotplug/shpchp_sysfs.c
index 64beed7a26be..ff04f0c5e7c3 100644
--- a/drivers/pci/hotplug/shpchp_sysfs.c
+++ b/drivers/pci/hotplug/shpchp_sysfs.c
@@ -24,16 +24,16 @@
 static ssize_t show_ctrl(struct device *dev, struct device_attribute *attr, 
char *buf)
 {
struct pci_dev *pdev;
-   int index, busnr;
struct resource *res;
struct pci_bus *bus;
size_t len = 0;
+   int busnr;
 
pdev = to_pci_dev(dev);
bus = pdev->subordinate;
 
len += sysfs_emit_at(buf, len, "Free resources: memory\n");
-   pci_bus_for_each_resource(bus, res, index) {
+   pci_bus_for_each_resource_p(bus, res) {
if (res && (res->flags & IORESOURCE_MEM) &&
!(res->flags & IORESOURCE_PREFETCH)) {
len += sysfs_emit_at(buf, len,
@@ -43,7 +43,7 @@ static ssize_t show_ctrl(struct device *dev, struct 
device_attribute *attr, char
}
}
len += sysfs_emit_at(buf, len, "Free resources: prefetchable memory\n");
-   pci_bus_for_each_resource(bus, res, index) {
+   pci_bus_for_each_resource_p(bus, res) {
if (res && (res->flags & IORESOURCE_MEM) &&
   (res->flags & IORESOURCE_PREFETCH)) {
len += sysfs_emit_at(buf, len,
@@ -53,7 +53,7 @@ static ssize_t show_ctrl(struct device *dev, struct 
device_attribute *attr, char
}
}
len += sysfs_emit_at(buf, len, "Free resources: IO\n");
-   pci_bus_for_each_resource(bus, res, index) {
+   pci_bus_for_each_resource_p(bus, res) {
if (res && (res->flags & IORESOURCE_IO)) {
len += sysfs_emit_at(buf, len,
 "start = %8.8llx, length = 
%8.8llx\n",
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 7a67611dc5f4..2f8915ab41ef 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -779,9 +779,8 @@ struct resource *pci_find_parent_resource(const struct 
pci_dev *dev,
 {
const struct pci_bus *bus = dev->bus;
struct resource *r;
-   int i;
 
-   pci_bus_for_each_resource(bus, r, i) {
+   pci_bus_for_each_resource_p(bus, r) {
if (!r)
continue;
if (resource_contains(r, res)) {
@@ -799,7 +798,7 @@ struct resource *pci_find_parent_resource(const struct 
pci_dev *dev,
 * be both a positively-decoded aperture and a
 * subtractively-decoded region that contain the BAR.
 * We want the positively-decoded one, so this depends
-* on pci_bus_for_each_resource() giving us those
+* on pci_bus_for_each_resource_p() giving us those
 * 

Re: [PATCH] hwmon: Use of_property_present() for testing DT property presence

2023-03-10 Thread Guenter Roeck
On Fri, Mar 10, 2023 at 08:47:06AM -0600, Rob Herring wrote:
> It is preferred to use typed property access functions (i.e.
> of_property_read_ functions) rather than low-level
> of_get_property/of_find_property functions for reading properties. As
> part of this, convert of_get_property/of_find_property calls to the
> recently added of_property_present() helper when we just want to test
> for presence of a property and nothing more.
> 
> Signed-off-by: Rob Herring 

Applied.

Thanks,
Guenter

> ---
>  drivers/hwmon/ibmpowernv.c | 4 ++--
>  drivers/hwmon/pwm-fan.c| 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/hwmon/ibmpowernv.c b/drivers/hwmon/ibmpowernv.c
> index 8e3724728cce..594254d6a72d 100644
> --- a/drivers/hwmon/ibmpowernv.c
> +++ b/drivers/hwmon/ibmpowernv.c
> @@ -456,9 +456,9 @@ static int populate_attr_groups(struct platform_device 
> *pdev)
>*/
>   if (!of_property_read_string(np, "label", ))
>   sensor_groups[type].attr_count++;
> - if (of_find_property(np, "sensor-data-min", NULL))
> + if (of_property_present(np, "sensor-data-min"))
>   sensor_groups[type].attr_count++;
> - if (of_find_property(np, "sensor-data-max", NULL))
> + if (of_property_present(np, "sensor-data-max"))
>   sensor_groups[type].attr_count++;
>   }
>  
> diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c
> index 83a347ca35da..57928d270015 100644
> --- a/drivers/hwmon/pwm-fan.c
> +++ b/drivers/hwmon/pwm-fan.c
> @@ -427,7 +427,7 @@ static int pwm_fan_of_get_cooling_data(struct device *dev,
>   struct device_node *np = dev->of_node;
>   int num, i, ret;
>  
> - if (!of_find_property(np, "cooling-levels", NULL))
> + if (!of_property_present(np, "cooling-levels"))
>   return 0;
>  
>   ret = of_property_count_u32_elems(np, "cooling-levels");


Re: [PATCH] serial: Use of_property_read_bool() for boolean properties

2023-03-10 Thread Uwe Kleine-König
On Fri, Mar 10, 2023 at 08:47:27AM -0600, Rob Herring wrote:
> It is preferred to use typed property access functions (i.e.
> of_property_read_ functions) rather than low-level
> of_get_property/of_find_property functions for reading properties.
> Convert reading boolean properties to to of_property_read_bool().
> 
> Signed-off-by: Rob Herring 

Acked-by: Uwe Kleine-König 

Thanks
Uwe

-- 
Pengutronix e.K.   | Uwe Kleine-König|
Industrial Linux Solutions | https://www.pengutronix.de/ |


signature.asc
Description: PGP signature


[PATCH] net: Use of_property_read_bool() for boolean properties

2023-03-10 Thread Rob Herring
It is preferred to use typed property access functions (i.e.
of_property_read_ functions) rather than low-level
of_get_property/of_find_property functions for reading properties.
Convert reading boolean properties to to of_property_read_bool().

Signed-off-by: Rob Herring 
---
 drivers/net/can/cc770/cc770_platform.c  | 12 ++--
 drivers/net/ethernet/cadence/macb_main.c|  2 +-
 drivers/net/ethernet/davicom/dm9000.c   |  4 ++--
 drivers/net/ethernet/freescale/fec_main.c   |  2 +-
 drivers/net/ethernet/freescale/fec_mpc52xx.c|  2 +-
 drivers/net/ethernet/freescale/gianfar.c|  4 ++--
 drivers/net/ethernet/ibm/emac/core.c|  8 
 drivers/net/ethernet/ibm/emac/rgmii.c   |  2 +-
 drivers/net/ethernet/stmicro/stmmac/dwmac-imx.c |  3 +--
 drivers/net/ethernet/sun/niu.c  |  2 +-
 drivers/net/ethernet/ti/cpsw-phy-sel.c  |  3 +--
 drivers/net/ethernet/ti/netcp_ethss.c   |  8 +++-
 drivers/net/ethernet/via/via-velocity.c |  3 +--
 drivers/net/ethernet/xilinx/ll_temac_main.c |  9 -
 drivers/net/wan/fsl_ucc_hdlc.c  | 11 +++
 drivers/net/wireless/ti/wlcore/spi.c|  3 +--
 net/ncsi/ncsi-manage.c  |  4 ++--
 17 files changed, 35 insertions(+), 47 deletions(-)

diff --git a/drivers/net/can/cc770/cc770_platform.c 
b/drivers/net/can/cc770/cc770_platform.c
index 8d916e2ee6c2..8dcc32e4e30e 100644
--- a/drivers/net/can/cc770/cc770_platform.c
+++ b/drivers/net/can/cc770/cc770_platform.c
@@ -93,20 +93,20 @@ static int cc770_get_of_node_data(struct platform_device 
*pdev,
if (priv->can.clock.freq > 800)
priv->cpu_interface |= CPUIF_DMC;
 
-   if (of_get_property(np, "bosch,divide-memory-clock", NULL))
+   if (of_property_read_bool(np, "bosch,divide-memory-clock"))
priv->cpu_interface |= CPUIF_DMC;
-   if (of_get_property(np, "bosch,iso-low-speed-mux", NULL))
+   if (of_property_read_bool(np, "bosch,iso-low-speed-mux"))
priv->cpu_interface |= CPUIF_MUX;
 
if (!of_get_property(np, "bosch,no-comperator-bypass", NULL))
priv->bus_config |= BUSCFG_CBY;
-   if (of_get_property(np, "bosch,disconnect-rx0-input", NULL))
+   if (of_property_read_bool(np, "bosch,disconnect-rx0-input"))
priv->bus_config |= BUSCFG_DR0;
-   if (of_get_property(np, "bosch,disconnect-rx1-input", NULL))
+   if (of_property_read_bool(np, "bosch,disconnect-rx1-input"))
priv->bus_config |= BUSCFG_DR1;
-   if (of_get_property(np, "bosch,disconnect-tx1-output", NULL))
+   if (of_property_read_bool(np, "bosch,disconnect-tx1-output"))
priv->bus_config |= BUSCFG_DT1;
-   if (of_get_property(np, "bosch,polarity-dominant", NULL))
+   if (of_property_read_bool(np, "bosch,polarity-dominant"))
priv->bus_config |= BUSCFG_POL;
 
prop = of_get_property(np, "bosch,clock-out-frequency", _size);
diff --git a/drivers/net/ethernet/cadence/macb_main.c 
b/drivers/net/ethernet/cadence/macb_main.c
index 6e141a8bbf43..66e30561569e 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -4990,7 +4990,7 @@ static int macb_probe(struct platform_device *pdev)
bp->jumbo_max_len = macb_config->jumbo_max_len;
 
bp->wol = 0;
-   if (of_get_property(np, "magic-packet", NULL))
+   if (of_property_read_bool(np, "magic-packet"))
bp->wol |= MACB_WOL_HAS_MAGIC_PACKET;
device_set_wakeup_capable(>dev, bp->wol & 
MACB_WOL_HAS_MAGIC_PACKET);
 
diff --git a/drivers/net/ethernet/davicom/dm9000.c 
b/drivers/net/ethernet/davicom/dm9000.c
index b21e56de6167..05a89ab6766c 100644
--- a/drivers/net/ethernet/davicom/dm9000.c
+++ b/drivers/net/ethernet/davicom/dm9000.c
@@ -1393,9 +1393,9 @@ static struct dm9000_plat_data *dm9000_parse_dt(struct 
device *dev)
if (!pdata)
return ERR_PTR(-ENOMEM);
 
-   if (of_find_property(np, "davicom,ext-phy", NULL))
+   if (of_property_read_bool(np, "davicom,ext-phy"))
pdata->flags |= DM9000_PLATF_EXT_PHY;
-   if (of_find_property(np, "davicom,no-eeprom", NULL))
+   if (of_property_read_bool(np, "davicom,no-eeprom"))
pdata->flags |= DM9000_PLATF_NO_EEPROM;
 
ret = of_get_mac_address(np, pdata->dev_addr);
diff --git a/drivers/net/ethernet/freescale/fec_main.c 
b/drivers/net/ethernet/freescale/fec_main.c
index c73e25f8995e..f3b16a6673e2 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -4251,7 +4251,7 @@ fec_probe(struct platform_device *pdev)
if (ret)
goto failed_ipc_init;
 
-   if (of_get_property(np, "fsl,magic-packet", NULL))
+   if (of_property_read_bool(np, "fsl,magic-packet"))
fep->wol_flag |= 

[PATCH] macintosh: Use of_property_present() for testing DT property presence

2023-03-10 Thread Rob Herring
It is preferred to use typed property access functions (i.e.
of_property_read_ functions) rather than low-level
of_get_property/of_find_property functions for reading properties. As
part of this, convert of_get_property/of_find_property calls to the
recently added of_property_present() helper when we just want to test
for presence of a property and nothing more.

Signed-off-by: Rob Herring 
---
 drivers/macintosh/rack-meter.c| 2 +-
 drivers/macintosh/therm_adt746x.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/macintosh/rack-meter.c b/drivers/macintosh/rack-meter.c
index c28893e41a8b..40240bce77b0 100644
--- a/drivers/macintosh/rack-meter.c
+++ b/drivers/macintosh/rack-meter.c
@@ -387,7 +387,7 @@ static int rackmeter_probe(struct macio_dev* mdev,
   if (of_node_name_eq(np, "lightshow"))
   break;
   if (of_node_name_eq(np, "sound") &&
-  of_get_property(np, "virtual", NULL) != NULL)
+  of_property_present(np, "virtual"))
   break;
}
if (np == NULL) {
diff --git a/drivers/macintosh/therm_adt746x.c 
b/drivers/macintosh/therm_adt746x.c
index 8f5db9093c9a..384b87d661e1 100644
--- a/drivers/macintosh/therm_adt746x.c
+++ b/drivers/macintosh/therm_adt746x.c
@@ -483,7 +483,7 @@ static int probe_thermostat(struct i2c_client *client)
if (vers != 1)
return -ENXIO;
 
-   if (of_get_property(np, "hwsensor-location", NULL)) {
+   if (of_property_present(np, "hwsensor-location")) {
for (i = 0; i < 3; i++) {
sensor_location[i] = of_get_property(np,
"hwsensor-location", NULL) + offset;
-- 
2.39.2



[PATCH] serial: Use of_property_read_bool() for boolean properties

2023-03-10 Thread Rob Herring
It is preferred to use typed property access functions (i.e.
of_property_read_ functions) rather than low-level
of_get_property/of_find_property functions for reading properties.
Convert reading boolean properties to to of_property_read_bool().

Signed-off-by: Rob Herring 
---
 drivers/tty/serial/imx.c   | 14 +-
 drivers/tty/serial/mxs-auart.c |  4 ++--
 drivers/tty/serial/ucc_uart.c  |  2 +-
 3 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index 5712a4f29607..be168792b635 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -2262,20 +2262,16 @@ static int imx_uart_probe(struct platform_device *pdev)
}
sport->port.line = ret;
 
-   if (of_get_property(np, "uart-has-rtscts", NULL) ||
-   of_get_property(np, "fsl,uart-has-rtscts", NULL) /* deprecated */)
-   sport->have_rtscts = 1;
+   sport->have_rtscts = of_property_read_bool(np, "uart-has-rtscts") ||
+   of_property_read_bool(np, "fsl,uart-has-rtscts"); /* deprecated 
*/
 
-   if (of_get_property(np, "fsl,dte-mode", NULL))
-   sport->dte_mode = 1;
+   sport->dte_mode = of_property_read_bool(np, "fsl,dte-mode");
 
sport->have_rtsgpio = of_property_present(np, "rts-gpios");
 
-   if (of_get_property(np, "fsl,inverted-tx", NULL))
-   sport->inverted_tx = 1;
+   sport->inverted_tx = of_property_read_bool(np, "fsl,inverted-tx");
 
-   if (of_get_property(np, "fsl,inverted-rx", NULL))
-   sport->inverted_rx = 1;
+   sport->inverted_rx = of_property_read_bool(np, "fsl,inverted-rx");
 
if (!of_property_read_u32_array(np, "fsl,dma-info", dma_buf_conf, 2)) {
sport->rx_period_length = dma_buf_conf[0];
diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c
index ef6e7bb6105c..a368f4293967 100644
--- a/drivers/tty/serial/mxs-auart.c
+++ b/drivers/tty/serial/mxs-auart.c
@@ -1587,8 +1587,8 @@ static int mxs_auart_probe(struct platform_device *pdev)
}
s->port.line = ret;
 
-   if (of_get_property(np, "uart-has-rtscts", NULL) ||
-   of_get_property(np, "fsl,uart-has-rtscts", NULL) /* deprecated */)
+   if (of_property_read_bool(np, "uart-has-rtscts") ||
+   of_property_read_bool(np, "fsl,uart-has-rtscts") /* deprecated */)
set_bit(MXS_AUART_RTSCTS, >flags);
 
if (s->port.line >= ARRAY_SIZE(auart_port)) {
diff --git a/drivers/tty/serial/ucc_uart.c b/drivers/tty/serial/ucc_uart.c
index 32c7a5b43f8e..676840847962 100644
--- a/drivers/tty/serial/ucc_uart.c
+++ b/drivers/tty/serial/ucc_uart.c
@@ -1179,7 +1179,7 @@ static int soft_uart_init(struct platform_device *ofdev)
struct qe_firmware_info *qe_fw_info;
int ret;
 
-   if (of_find_property(np, "soft-uart", NULL)) {
+   if (of_property_read_bool(np, "soft-uart")) {
dev_dbg(>dev, "using Soft-UART mode\n");
soft_uart = 1;
} else {
-- 
2.39.2



[PATCH] PCI: Use of_property_present() for testing DT property presence

2023-03-10 Thread Rob Herring
It is preferred to use typed property access functions (i.e.
of_property_read_ functions) rather than low-level
of_get_property/of_find_property functions for reading properties. As
part of this, convert of_get_property/of_find_property calls to the
recently added of_property_present() helper when we just want to test
for presence of a property and nothing more.

Signed-off-by: Rob Herring 
---
 drivers/pci/controller/pci-tegra.c | 4 ++--
 drivers/pci/controller/pcie-mediatek.c | 2 +-
 drivers/pci/hotplug/rpaphp_core.c  | 4 ++--
 drivers/pci/of.c   | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/pci/controller/pci-tegra.c 
b/drivers/pci/controller/pci-tegra.c
index 74c109f14ff0..79630885b9c8 100644
--- a/drivers/pci/controller/pci-tegra.c
+++ b/drivers/pci/controller/pci-tegra.c
@@ -1375,7 +1375,7 @@ static int tegra_pcie_phys_get(struct tegra_pcie *pcie)
struct tegra_pcie_port *port;
int err;
 
-   if (!soc->has_gen2 || of_find_property(np, "phys", NULL) != NULL)
+   if (!soc->has_gen2 || of_property_present(np, "phys"))
return tegra_pcie_phys_get_legacy(pcie);
 
list_for_each_entry(port, >ports, list) {
@@ -1944,7 +1944,7 @@ static bool of_regulator_bulk_available(struct 
device_node *np,
for (i = 0; i < num_supplies; i++) {
snprintf(property, 32, "%s-supply", supplies[i].supply);
 
-   if (of_find_property(np, property, NULL) == NULL)
+   if (!of_property_present(np, property))
return false;
}
 
diff --git a/drivers/pci/controller/pcie-mediatek.c 
b/drivers/pci/controller/pcie-mediatek.c
index ae5ad05ddc1d..31de7a29192c 100644
--- a/drivers/pci/controller/pcie-mediatek.c
+++ b/drivers/pci/controller/pcie-mediatek.c
@@ -643,7 +643,7 @@ static int mtk_pcie_setup_irq(struct mtk_pcie_port *port,
return err;
}
 
-   if (of_find_property(dev->of_node, "interrupt-names", NULL))
+   if (of_property_present(dev->of_node, "interrupt-names"))
port->irq = platform_get_irq_byname(pdev, "pcie_irq");
else
port->irq = platform_get_irq(pdev, port->slot);
diff --git a/drivers/pci/hotplug/rpaphp_core.c 
b/drivers/pci/hotplug/rpaphp_core.c
index 491986197c47..2316de0fd198 100644
--- a/drivers/pci/hotplug/rpaphp_core.c
+++ b/drivers/pci/hotplug/rpaphp_core.c
@@ -278,7 +278,7 @@ int rpaphp_check_drc_props(struct device_node *dn, char 
*drc_name,
return -EINVAL;
}
 
-   if (of_find_property(dn->parent, "ibm,drc-info", NULL))
+   if (of_property_present(dn->parent, "ibm,drc-info"))
return rpaphp_check_drc_props_v2(dn, drc_name, drc_type,
be32_to_cpu(*my_index));
else
@@ -440,7 +440,7 @@ int rpaphp_add_slot(struct device_node *dn)
if (!of_node_name_eq(dn, "pci"))
return 0;
 
-   if (of_find_property(dn, "ibm,drc-info", NULL))
+   if (of_property_present(dn, "ibm,drc-info"))
return rpaphp_drc_info_add_slot(dn);
else
return rpaphp_drc_add_slot(dn);
diff --git a/drivers/pci/of.c b/drivers/pci/of.c
index 196834ed44fe..e085f2eca372 100644
--- a/drivers/pci/of.c
+++ b/drivers/pci/of.c
@@ -447,7 +447,7 @@ static int of_irq_parse_pci(const struct pci_dev *pdev, 
struct of_phandle_args *
return -ENODEV;
 
/* Local interrupt-map in the device node? Use it! */
-   if (of_get_property(dn, "interrupt-map", NULL)) {
+   if (of_property_present(dn, "interrupt-map")) {
pin = pci_swizzle_interrupt_pin(pdev, pin);
ppnode = dn;
}
-- 
2.39.2



[PATCH] soc: fsl: Use of_property_present() for testing DT property presence

2023-03-10 Thread Rob Herring
It is preferred to use typed property access functions (i.e.
of_property_read_ functions) rather than low-level
of_get_property/of_find_property functions for reading properties. As
part of this, convert of_get_property/of_find_property calls to the
recently added of_property_present() helper when we just want to test
for presence of a property and nothing more.

Signed-off-by: Rob Herring 
---
 drivers/soc/fsl/qbman/dpaa_sys.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/soc/fsl/qbman/dpaa_sys.c b/drivers/soc/fsl/qbman/dpaa_sys.c
index 9dd8bb571dbc..33751450047e 100644
--- a/drivers/soc/fsl/qbman/dpaa_sys.c
+++ b/drivers/soc/fsl/qbman/dpaa_sys.c
@@ -39,8 +39,7 @@ int qbman_init_private_mem(struct device *dev, int idx, 
dma_addr_t *addr,
 {
struct device_node *mem_node;
struct reserved_mem *rmem;
-   struct property *prop;
-   int len, err;
+   int err;
__be32 *res_array;
 
mem_node = of_parse_phandle(dev->of_node, "memory-region", idx);
@@ -63,8 +62,9 @@ int qbman_init_private_mem(struct device *dev, int idx, 
dma_addr_t *addr,
 * This is needed because QBMan HW does not allow the base address/
 * size to be modified once set.
 */
-   prop = of_find_property(mem_node, "reg", );
-   if (!prop) {
+   if (!of_property_present(mem_node, "reg")) {
+   struct property *prop;
+
prop = devm_kzalloc(dev, sizeof(*prop), GFP_KERNEL);
if (!prop)
return -ENOMEM;
-- 
2.39.2



[PATCH] ASoC: Use of_property_read_bool() for boolean properties

2023-03-10 Thread Rob Herring
It is preferred to use typed property access functions (i.e.
of_property_read_ functions) rather than low-level
of_get_property/of_find_property functions for reading properties.
Convert reading boolean properties to to of_property_read_bool().

Signed-off-by: Rob Herring 
---
 sound/soc/codecs/sta32x.c  | 39 +++
 sound/soc/codecs/sta350.c  | 63 +-
 sound/soc/codecs/tas5086.c |  2 +-
 sound/soc/fsl/fsl_sai.c| 12 
 sound/soc/fsl/fsl_ssi.c|  2 +-
 sound/soc/fsl/imx-card.c   |  2 +-
 sound/soc/sh/rcar/ssi.c|  4 +--
 7 files changed, 57 insertions(+), 67 deletions(-)

diff --git a/sound/soc/codecs/sta32x.c b/sound/soc/codecs/sta32x.c
index 8c86b578eba8..29af9595dac1 100644
--- a/sound/soc/codecs/sta32x.c
+++ b/sound/soc/codecs/sta32x.c
@@ -1054,35 +1054,32 @@ static int sta32x_probe_dt(struct device *dev, struct 
sta32x_priv *sta32x)
of_property_read_u8(np, "st,ch3-output-mapping",
>ch3_output_mapping);
 
-   if (of_get_property(np, "st,fault-detect-recovery", NULL))
-   pdata->fault_detect_recovery = 1;
-   if (of_get_property(np, "st,thermal-warning-recovery", NULL))
-   pdata->thermal_warning_recovery = 1;
-   if (of_get_property(np, "st,thermal-warning-adjustment", NULL))
-   pdata->thermal_warning_adjustment = 1;
-   if (of_get_property(np, "st,needs_esd_watchdog", NULL))
-   pdata->needs_esd_watchdog = 1;
+   pdata->fault_detect_recovery =
+   of_property_read_bool(np, "st,fault-detect-recovery");
+   pdata->thermal_warning_recovery =
+   of_property_read_bool(np, "st,thermal-warning-recovery");
+   pdata->thermal_warning_adjustment =
+   of_property_read_bool(np, "st,thermal-warning-adjustment");
+   pdata->needs_esd_watchdog =
+   of_property_read_bool(np, "st,needs_esd_watchdog");
 
tmp = 140;
of_property_read_u16(np, "st,drop-compensation-ns", );
pdata->drop_compensation_ns = clamp_t(u16, tmp, 0, 300) / 20;
 
/* CONFE */
-   if (of_get_property(np, "st,max-power-use-mpcc", NULL))
-   pdata->max_power_use_mpcc = 1;
-
-   if (of_get_property(np, "st,max-power-correction", NULL))
-   pdata->max_power_correction = 1;
-
-   if (of_get_property(np, "st,am-reduction-mode", NULL))
-   pdata->am_reduction_mode = 1;
-
-   if (of_get_property(np, "st,odd-pwm-speed-mode", NULL))
-   pdata->odd_pwm_speed_mode = 1;
+   pdata->max_power_use_mpcc =
+   of_property_read_bool(np, "st,max-power-use-mpcc");
+   pdata->max_power_correction =
+   of_property_read_bool(np, "st,max-power-correction");
+   pdata->am_reduction_mode =
+   of_property_read_bool(np, "st,am-reduction-mode");
+   pdata->odd_pwm_speed_mode =
+   of_property_read_bool(np, "st,odd-pwm-speed-mode");
 
/* CONFF */
-   if (of_get_property(np, "st,invalid-input-detect-mute", NULL))
-   pdata->invalid_input_detect_mute = 1;
+   pdata->invalid_input_detect_mute =
+   of_property_read_bool(np, "st,invalid-input-detect-mute");
 
sta32x->pdata = pdata;
 
diff --git a/sound/soc/codecs/sta350.c b/sound/soc/codecs/sta350.c
index 9ed13aeb3cbd..b033a5fcd6c0 100644
--- a/sound/soc/codecs/sta350.c
+++ b/sound/soc/codecs/sta350.c
@@ -1106,12 +1106,12 @@ static int sta350_probe_dt(struct device *dev, struct 
sta350_priv *sta350)
of_property_read_u8(np, "st,ch3-output-mapping",
>ch3_output_mapping);
 
-   if (of_get_property(np, "st,thermal-warning-recovery", NULL))
-   pdata->thermal_warning_recovery = 1;
-   if (of_get_property(np, "st,thermal-warning-adjustment", NULL))
-   pdata->thermal_warning_adjustment = 1;
-   if (of_get_property(np, "st,fault-detect-recovery", NULL))
-   pdata->fault_detect_recovery = 1;
+   pdata->thermal_warning_recovery =
+   of_property_read_bool(np, "st,thermal-warning-recovery");
+   pdata->thermal_warning_adjustment =
+   of_property_read_bool(np, "st,thermal-warning-adjustment");
+   pdata->fault_detect_recovery =
+   of_property_read_bool(np, "st,fault-detect-recovery");
 
pdata->ffx_power_output_mode = STA350_FFX_PM_VARIABLE_DROP_COMP;
if (!of_property_read_string(np, "st,ffx-power-output-mode",
@@ -1133,41 +1133,34 @@ static int sta350_probe_dt(struct device *dev, struct 
sta350_priv *sta350)
of_property_read_u16(np, "st,drop-compensation-ns", );
pdata->drop_compensation_ns = clamp_t(u16, tmp, 0, 300) / 20;
 
-   if (of_get_property(np, "st,overcurrent-warning-adjustment", NULL))
-   pdata->oc_warning_adjustment = 1;
+   pdata->oc_warning_adjustment =
+   of_property_read_bool(np, 

[PATCH] hwmon: Use of_property_present() for testing DT property presence

2023-03-10 Thread Rob Herring
It is preferred to use typed property access functions (i.e.
of_property_read_ functions) rather than low-level
of_get_property/of_find_property functions for reading properties. As
part of this, convert of_get_property/of_find_property calls to the
recently added of_property_present() helper when we just want to test
for presence of a property and nothing more.

Signed-off-by: Rob Herring 
---
 drivers/hwmon/ibmpowernv.c | 4 ++--
 drivers/hwmon/pwm-fan.c| 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/hwmon/ibmpowernv.c b/drivers/hwmon/ibmpowernv.c
index 8e3724728cce..594254d6a72d 100644
--- a/drivers/hwmon/ibmpowernv.c
+++ b/drivers/hwmon/ibmpowernv.c
@@ -456,9 +456,9 @@ static int populate_attr_groups(struct platform_device 
*pdev)
 */
if (!of_property_read_string(np, "label", ))
sensor_groups[type].attr_count++;
-   if (of_find_property(np, "sensor-data-min", NULL))
+   if (of_property_present(np, "sensor-data-min"))
sensor_groups[type].attr_count++;
-   if (of_find_property(np, "sensor-data-max", NULL))
+   if (of_property_present(np, "sensor-data-max"))
sensor_groups[type].attr_count++;
}
 
diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c
index 83a347ca35da..57928d270015 100644
--- a/drivers/hwmon/pwm-fan.c
+++ b/drivers/hwmon/pwm-fan.c
@@ -427,7 +427,7 @@ static int pwm_fan_of_get_cooling_data(struct device *dev,
struct device_node *np = dev->of_node;
int num, i, ret;
 
-   if (!of_find_property(np, "cooling-levels", NULL))
+   if (!of_property_present(np, "cooling-levels"))
return 0;
 
ret = of_property_count_u32_elems(np, "cooling-levels");
-- 
2.39.2



[PATCH] cpufreq: pmac32: Use of_property_read_bool() for boolean properties

2023-03-10 Thread Rob Herring
It is preferred to use typed property access functions (i.e.
of_property_read_ functions) rather than low-level
of_get_property/of_find_property functions for reading properties.
Convert reading boolean properties to to of_property_read_bool().

Signed-off-by: Rob Herring 
---
 drivers/cpufreq/pmac32-cpufreq.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/cpufreq/pmac32-cpufreq.c b/drivers/cpufreq/pmac32-cpufreq.c
index 4b8ee2014da6..7ec6d1bb4592 100644
--- a/drivers/cpufreq/pmac32-cpufreq.c
+++ b/drivers/cpufreq/pmac32-cpufreq.c
@@ -546,7 +546,7 @@ static int pmac_cpufreq_init_7447A(struct device_node 
*cpunode)
 {
struct device_node *volt_gpio_np;
 
-   if (of_get_property(cpunode, "dynamic-power-step", NULL) == NULL)
+   if (!of_property_read_bool(cpunode, "dynamic-power-step"))
return 1;
 
volt_gpio_np = of_find_node_by_name(NULL, "cpu-vcore-select");
@@ -576,7 +576,7 @@ static int pmac_cpufreq_init_750FX(struct device_node 
*cpunode)
u32 pvr;
const u32 *value;
 
-   if (of_get_property(cpunode, "dynamic-power-step", NULL) == NULL)
+   if (!of_property_read_bool(cpunode, "dynamic-power-step"))
return 1;
 
hi_freq = cur_freq;
@@ -632,7 +632,7 @@ static int __init pmac_cpufreq_setup(void)
 
/*  Check for 7447A based MacRISC3 */
if (of_machine_is_compatible("MacRISC3") &&
-   of_get_property(cpunode, "dynamic-power-step", NULL) &&
+   of_property_read_bool(cpunode, "dynamic-power-step") &&
PVR_VER(mfspr(SPRN_PVR)) == 0x8003) {
pmac_cpufreq_init_7447A(cpunode);
 
-- 
2.39.2



[PATCH] powerpc: Use of_property_read_bool() for boolean properties

2023-03-10 Thread Rob Herring
It is preferred to use typed property access functions (i.e.
of_property_read_ functions) rather than low-level
of_get_property/of_find_property functions for reading properties.
Convert reading boolean properties to to of_property_read_bool().

Signed-off-by: Rob Herring 
---
 arch/powerpc/kernel/btext.c  |  2 +-
 arch/powerpc/kernel/legacy_serial.c  |  2 +-
 arch/powerpc/platforms/4xx/pci.c | 18 +++---
 arch/powerpc/platforms/52xx/mpc52xx_common.c |  4 ++--
 arch/powerpc/platforms/52xx/mpc52xx_gpt.c|  4 ++--
 arch/powerpc/platforms/maple/setup.c |  2 +-
 arch/powerpc/platforms/pasemi/iommu.c|  2 +-
 arch/powerpc/platforms/powermac/feature.c|  2 +-
 arch/powerpc/platforms/powermac/pic.c|  4 ++--
 arch/powerpc/platforms/powermac/setup.c  |  2 +-
 arch/powerpc/platforms/powermac/smp.c|  2 +-
 arch/powerpc/platforms/pseries/vio.c |  2 +-
 arch/powerpc/sysdev/dcr.c|  2 +-
 arch/powerpc/sysdev/ehv_pic.c|  6 +-
 arch/powerpc/sysdev/fsl_soc.c|  2 +-
 arch/powerpc/sysdev/mpic.c   |  6 +++---
 arch/powerpc/sysdev/tsi108_dev.c |  2 +-
 arch/powerpc/sysdev/xive/native.c|  6 ++
 18 files changed, 30 insertions(+), 40 deletions(-)

diff --git a/arch/powerpc/kernel/btext.c b/arch/powerpc/kernel/btext.c
index 2769889219bf..19e46fd623b0 100644
--- a/arch/powerpc/kernel/btext.c
+++ b/arch/powerpc/kernel/btext.c
@@ -235,7 +235,7 @@ int __init btext_find_display(int allow_nonstdout)
return rc;
 
for_each_node_by_type(np, "display") {
-   if (of_get_property(np, "linux,opened", NULL)) {
+   if (of_property_read_bool(np, "linux,opened")) {
printk("trying %pOF ...\n", np);
rc = btext_initialize(np);
printk("result: %d\n", rc);
diff --git a/arch/powerpc/kernel/legacy_serial.c 
b/arch/powerpc/kernel/legacy_serial.c
index 1a3b7f3513b4..c9ad12461d44 100644
--- a/arch/powerpc/kernel/legacy_serial.c
+++ b/arch/powerpc/kernel/legacy_serial.c
@@ -179,7 +179,7 @@ static int __init add_legacy_soc_port(struct device_node 
*np,
return -1;
 
/* if rtas uses this device, don't try to use it as well */
-   if (of_get_property(np, "used-by-rtas", NULL) != NULL)
+   if (of_property_read_bool(np, "used-by-rtas"))
return -1;
 
/* Get the address */
diff --git a/arch/powerpc/platforms/4xx/pci.c b/arch/powerpc/platforms/4xx/pci.c
index 70a055f76e5a..3638505a138c 100644
--- a/arch/powerpc/platforms/4xx/pci.c
+++ b/arch/powerpc/platforms/4xx/pci.c
@@ -348,7 +348,7 @@ static void __init ppc4xx_probe_pci_bridge(struct 
device_node *np)
}
 
/* Check if primary bridge */
-   if (of_property_present(np, "primary"))
+   if (of_property_read_bool(np, "primary"))
primary = 1;
 
/* Get bus range if any */
@@ -530,7 +530,7 @@ static void __init ppc4xx_probe_pcix_bridge(struct 
device_node *np)
struct pci_controller *hose = NULL;
void __iomem *reg = NULL;
const int *bus_range;
-   int big_pim = 0, msi = 0, primary = 0;
+   int big_pim, msi, primary;
 
/* Fetch config space registers address */
if (of_address_to_resource(np, 0, _cfg)) {
@@ -546,16 +546,13 @@ static void __init ppc4xx_probe_pcix_bridge(struct 
device_node *np)
}
 
/* Check if it supports large PIMs (440GX) */
-   if (of_get_property(np, "large-inbound-windows", NULL))
-   big_pim = 1;
+   big_pim = of_property_read_bool(np, "large-inbound-windows");
 
/* Check if we should enable MSIs inbound hole */
-   if (of_get_property(np, "enable-msi-hole", NULL))
-   msi = 1;
+   msi = of_property_read_bool(np, "enable-msi-hole");
 
/* Check if primary bridge */
-   if (of_get_property(np, "primary", NULL))
-   primary = 1;
+   primary = of_property_read_bool(np, "primary");
 
/* Get bus range if any */
bus_range = of_get_property(np, "bus-range", NULL);
@@ -1915,14 +1912,13 @@ static void __init ppc4xx_pciex_port_setup_hose(struct 
ppc4xx_pciex_port *port)
struct resource dma_window;
struct pci_controller *hose = NULL;
const int *bus_range;
-   int primary = 0, busses;
+   int primary, busses;
void __iomem *mbase = NULL, *cfg_data = NULL;
const u32 *pval;
u32 val;
 
/* Check if primary bridge */
-   if (of_get_property(port->node, "primary", NULL))
-   primary = 1;
+   primary = of_property_read_bool(port->node, "primary");
 
/* Get bus range if any */
bus_range = of_get_property(port->node, "bus-range", NULL);
diff --git a/arch/powerpc/platforms/52xx/mpc52xx_common.c 
b/arch/powerpc/platforms/52xx/mpc52xx_common.c
index 

[PATCH] powerpc: Use of_property_present() for testing DT property presence

2023-03-10 Thread Rob Herring
It is preferred to use typed property access functions (i.e.
of_property_read_ functions) rather than low-level
of_get_property/of_find_property functions for reading properties. As
part of this, convert of_get_property/of_find_property calls to the
recently added of_property_present() helper when we just want to test
for presence of a property and nothing more.

Signed-off-by: Rob Herring 
---
 arch/powerpc/kernel/legacy_serial.c  | 8 
 arch/powerpc/platforms/44x/iss4xx.c  | 2 +-
 arch/powerpc/platforms/44x/ppc476.c  | 2 +-
 arch/powerpc/platforms/4xx/pci.c | 2 +-
 arch/powerpc/platforms/cell/spu_manage.c | 2 +-
 arch/powerpc/platforms/powermac/pic.c| 2 +-
 arch/powerpc/platforms/powernv/opal-lpc.c| 2 +-
 arch/powerpc/platforms/pseries/hotplug-cpu.c | 2 +-
 arch/powerpc/platforms/pseries/vio.c | 2 +-
 arch/powerpc/sysdev/mpic_msgr.c  | 2 +-
 10 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/arch/powerpc/kernel/legacy_serial.c 
b/arch/powerpc/kernel/legacy_serial.c
index f048c424c525..1a3b7f3513b4 100644
--- a/arch/powerpc/kernel/legacy_serial.c
+++ b/arch/powerpc/kernel/legacy_serial.c
@@ -171,11 +171,11 @@ static int __init add_legacy_soc_port(struct device_node 
*np,
/* We only support ports that have a clock frequency properly
 * encoded in the device-tree.
 */
-   if (of_get_property(np, "clock-frequency", NULL) == NULL)
+   if (!of_property_present(np, "clock-frequency"))
return -1;
 
/* if reg-offset don't try to use it */
-   if ((of_get_property(np, "reg-offset", NULL) != NULL))
+   if (of_property_present(np, "reg-offset"))
return -1;
 
/* if rtas uses this device, don't try to use it as well */
@@ -237,7 +237,7 @@ static int __init add_legacy_isa_port(struct device_node 
*np,
 * Note: Don't even try on P8 lpc, we know it's not directly mapped
 */
if (!of_device_is_compatible(isa_brg, "ibm,power8-lpc") ||
-   of_get_property(isa_brg, "ranges", NULL)) {
+   of_property_present(isa_brg, "ranges")) {
taddr = of_translate_address(np, reg);
if (taddr == OF_BAD_ADDR)
taddr = 0;
@@ -268,7 +268,7 @@ static int __init add_legacy_pci_port(struct device_node 
*np,
 * compatible UARTs on PCI need all sort of quirks (port offsets
 * etc...) that this code doesn't know about
 */
-   if (of_get_property(np, "clock-frequency", NULL) == NULL)
+   if (!of_property_present(np, "clock-frequency"))
return -1;
 
/* Get the PCI address. Assume BAR 0 */
diff --git a/arch/powerpc/platforms/44x/iss4xx.c 
b/arch/powerpc/platforms/44x/iss4xx.c
index c5f82591408c..812765cf0632 100644
--- a/arch/powerpc/platforms/44x/iss4xx.c
+++ b/arch/powerpc/platforms/44x/iss4xx.c
@@ -52,7 +52,7 @@ static void __init iss4xx_init_irq(void)
 
/* Find top level interrupt controller */
for_each_node_with_property(np, "interrupt-controller") {
-   if (of_get_property(np, "interrupts", NULL) == NULL)
+   if (!of_property_present(np, "interrupts"))
break;
}
if (np == NULL)
diff --git a/arch/powerpc/platforms/44x/ppc476.c 
b/arch/powerpc/platforms/44x/ppc476.c
index 7c91ac5a5241..70556fd10f6b 100644
--- a/arch/powerpc/platforms/44x/ppc476.c
+++ b/arch/powerpc/platforms/44x/ppc476.c
@@ -122,7 +122,7 @@ static void __init ppc47x_init_irq(void)
 
/* Find top level interrupt controller */
for_each_node_with_property(np, "interrupt-controller") {
-   if (of_get_property(np, "interrupts", NULL) == NULL)
+   if (!of_property_present(np, "interrupts"))
break;
}
if (np == NULL)
diff --git a/arch/powerpc/platforms/4xx/pci.c b/arch/powerpc/platforms/4xx/pci.c
index ca5dd7a5842a..70a055f76e5a 100644
--- a/arch/powerpc/platforms/4xx/pci.c
+++ b/arch/powerpc/platforms/4xx/pci.c
@@ -348,7 +348,7 @@ static void __init ppc4xx_probe_pci_bridge(struct 
device_node *np)
}
 
/* Check if primary bridge */
-   if (of_get_property(np, "primary", NULL))
+   if (of_property_present(np, "primary"))
primary = 1;
 
/* Get bus range if any */
diff --git a/arch/powerpc/platforms/cell/spu_manage.c 
b/arch/powerpc/platforms/cell/spu_manage.c
index f1ac4c742069..74567b32c48c 100644
--- a/arch/powerpc/platforms/cell/spu_manage.c
+++ b/arch/powerpc/platforms/cell/spu_manage.c
@@ -402,7 +402,7 @@ static int __init of_has_vicinity(void)
struct device_node *dn;
 
for_each_node_by_type(dn, "spe") {
-   if (of_find_property(dn, "vicinity", NULL))  {
+   if (of_property_present(dn, "vicinity"))  {
of_node_put(dn);
return 1;
}
diff --git 

Re: [PATCH v2] vdso: Improve cmd_vdso_check to check all dynamic relocations

2023-03-10 Thread Vincenzo Frascino
Hi Fangrui,

Apologize for the delay, I totally missed that you had a new version of your
patch since it was threaded with the old one.

On 12/21/22 23:51, Fangrui Song wrote:
> The actual intention is that no dynamic relocation exists. However, some
> GNU ld ports produce unneeded R_*_NONE. (If a port fails to determine
> the exact .rel[a].dyn size, the trailing zeros become R_*_NONE
> relocations. E.g. ld's powerpc port recently fixed
> https://sourceware.org/bugzilla/show_bug.cgi?id=29540) R_*_NONE are
> generally no-op in the dynamic loaders. So just ignore them.
> 
> With the change, we can remove ARCH_REL_TYPE_ABS. ARCH_REL_TYPE_ABS is a
> bit misnomer as ports may check RELAVETIVE/GLOB_DAT/JUMP_SLOT which are
> not called "absolute relocations". (The patch is motivated by the arm64
> port missing R_AARCH64_RELATIVE.)

It makes sense to update the name, it started as "absolute relocations" but then
it evolved into something else.

A part that, did you perform any testing with the generated vDSO libraries?

> 
> Signed-off-by: Fangrui Song 
> Reviewed-by: Christophe Leroy 
> ---
> Change from v1:
> * rebase after 8ac3b5cd3e0521d92f9755e90d140382fc292510 (lib/vdso: use "grep 
> -E"
> instead of "egrep")
> * change the commit message to mention an example GNU ld bug; no longer say 
> the
> patch fixes a deprecated egrep use
> ---
>  arch/arm/vdso/Makefile    |  3 ---
>  arch/arm64/kernel/vdso/Makefile   |  3 ---
>  arch/arm64/kernel/vdso32/Makefile |  3 ---
>  arch/csky/kernel/vdso/Makefile    |  3 ---
>  arch/loongarch/vdso/Makefile  |  3 ---
>  arch/mips/vdso/Makefile   |  3 ---
>  arch/powerpc/kernel/vdso/Makefile |  1 -
>  arch/riscv/kernel/vdso/Makefile   |  3 ---
>  arch/s390/kernel/vdso32/Makefile  |  2 --
>  arch/s390/kernel/vdso64/Makefile  |  2 --
>  arch/x86/entry/vdso/Makefile  |  4 
>  lib/vdso/Makefile | 13 -
>  12 files changed, 4 insertions(+), 39 deletions(-)
> 
> diff --git a/arch/arm/vdso/Makefile b/arch/arm/vdso/Makefile
> index a7ec06ce3785..e58197bba776 100644
> --- a/arch/arm/vdso/Makefile
> +++ b/arch/arm/vdso/Makefile
> @@ -1,8 +1,5 @@
>  # SPDX-License-Identifier: GPL-2.0
>  
> -# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
> -# the inclusion of generic Makefile.
> -ARCH_REL_TYPE_ABS := R_ARM_JUMP_SLOT|R_ARM_GLOB_DAT|R_ARM_ABS32

I would still add a comment here to say why we are including the generic
Makefile to prevent that it gets accidentally removed (similar thing for every
architecture touched by this patch).

With that:

Reviewed-by: Vincenzo Frascino  # for vDSO, aarch64
Tested-by: Vincenzo Frascino  # for aarch64

>  include $(srctree)/lib/vdso/Makefile
>  
>  hostprogs := vdsomunge
> diff --git a/arch/arm64/kernel/vdso/Makefile b/arch/arm64/kernel/vdso/Makefile
> index beaf9586338f..1f2427b13410 100644
> --- a/arch/arm64/kernel/vdso/Makefile
> +++ b/arch/arm64/kernel/vdso/Makefile
> @@ -6,9 +6,6 @@
>  # Heavily based on the vDSO Makefiles for other archs.
>  #
>  
> -# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
> -# the inclusion of generic Makefile.
> -ARCH_REL_TYPE_ABS := R_AARCH64_JUMP_SLOT|R_AARCH64_GLOB_DAT|R_AARCH64_ABS64
>  include $(srctree)/lib/vdso/Makefile
>  
>  obj-vdso := vgettimeofday.o note.o sigreturn.o
> diff --git a/arch/arm64/kernel/vdso32/Makefile 
> b/arch/arm64/kernel/vdso32/Makefile
> index f59bd1a4ead6..d014162c5c71 100644
> --- a/arch/arm64/kernel/vdso32/Makefile
> +++ b/arch/arm64/kernel/vdso32/Makefile
> @@ -3,9 +3,6 @@
>  # Makefile for vdso32
>  #
>  
> -# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
> -# the inclusion of generic Makefile.
> -ARCH_REL_TYPE_ABS := R_ARM_JUMP_SLOT|R_ARM_GLOB_DAT|R_ARM_ABS32
>  include $(srctree)/lib/vdso/Makefile
>  
>  # Same as cc-*option, but using CC_COMPAT instead of CC
> diff --git a/arch/csky/kernel/vdso/Makefile b/arch/csky/kernel/vdso/Makefile
> index 0b6909f10667..86c8c4de1b0f 100644
> --- a/arch/csky/kernel/vdso/Makefile
> +++ b/arch/csky/kernel/vdso/Makefile
> @@ -1,8 +1,5 @@
>  # SPDX-License-Identifier: GPL-2.0-only
>  
> -# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
> -# the inclusion of generic Makefile.
> -ARCH_REL_TYPE_ABS := R_CKCORE_ADDR32|R_CKCORE_JUMP_SLOT
>  include $(srctree)/lib/vdso/Makefile
>  
>  # Symbols present in the vdso
> diff --git a/arch/loongarch/vdso/Makefile b/arch/loongarch/vdso/Makefile
> index d89e2ac75f7b..1b2e0f149f55 100644
> --- a/arch/loongarch/vdso/Makefile
> +++ b/arch/loongarch/vdso/Makefile
> @@ -1,9 +1,6 @@
>  # SPDX-License-Identifier: GPL-2.0
>  # Objects to go into the VDSO.
>  
> -# Absolute relocation type $(ARCH_REL_TYPE_ABS) needs to be defined before
> -# the inclusion of generic Makefile.
> -ARCH_REL_TYPE_ABS := R_LARCH_32|R_LARCH_64|R_LARCH_MARK_LA|R_LARCH_JUMP_SLOT
>  include $(srctree)/lib/vdso/Makefile
>  
>  obj-vdso-y := elf.o vgetcpu.o vgettimeofday.o sigreturn.o
> diff 

Re: [PATCH v10 03/13] dt-bindings: Convert gpio-mmio to yaml

2023-03-10 Thread Jonas Gorski
On Mon, 6 Mar 2023 at 22:27, Sean Anderson  wrote:
>
> On 3/6/23 15:51, Jonas Gorski wrote:
> > Hi,
> >
> > On Mon, 6 Mar 2023 at 20:16, Sean Anderson  wrote:
> >>
> >> This is a generic binding for simple MMIO GPIO controllers. Although we
> >> have a single driver for these controllers, they were previously spread
> >> over several files. Consolidate them. The register descriptions are
> >> adapted from the comments in the source. There is no set order for the
> >> registers, so I have not specified one.
> >>
> >> Signed-off-by: Sean Anderson 
> >> ---
> >>
> >> Changes in v10:
> >> - New
> >>
> >>  .../bindings/gpio/brcm,bcm6345-gpio.yaml  |  16 +--
> >>  .../devicetree/bindings/gpio/gpio-mmio.yaml   | 136 ++
> >>  .../bindings/gpio/ni,169445-nand-gpio.txt |  38 -
> >>  .../devicetree/bindings/gpio/wd,mbl-gpio.txt  |  38 -
> >>  4 files changed, 137 insertions(+), 91 deletions(-)
> >>  create mode 100644 Documentation/devicetree/bindings/gpio/gpio-mmio.yaml
> >>  delete mode 100644 
> >> Documentation/devicetree/bindings/gpio/ni,169445-nand-gpio.txt
> >>  delete mode 100644 Documentation/devicetree/bindings/gpio/wd,mbl-gpio.txt
> >>
> >> diff --git a/Documentation/devicetree/bindings/gpio/brcm,bcm6345-gpio.yaml 
> >> b/Documentation/devicetree/bindings/gpio/brcm,bcm6345-gpio.yaml
> >> index 4d69f79df859..e11f4af49c52 100644
> >> --- a/Documentation/devicetree/bindings/gpio/brcm,bcm6345-gpio.yaml
> >> +++ b/Documentation/devicetree/bindings/gpio/brcm,bcm6345-gpio.yaml
> >
> > You are (re-)moving the compatible this file is named after, you might
> > want to rename the file as well then. Going by age bcm6358 would be
> > the next oldest one (bcm6318 would be the newest, despite the lowest
> > number).
>
> I can do that. Would it be fine to rename to e.g. brcm,bcm63xx-gpio.yaml?

I'm not up to date with current naming policies (if there are any at
all), but looking at what's currently there this should be fine.

Jonas


Re: [PATCH] KVM: PPC: Mark three local functions "static"

2023-03-10 Thread Michael Ellerman
Sean Christopherson  writes:
> Tag a few functions that are local and don't have a previous prototype as
> "static".
>
> No functional change intended.
>
> Reported-by: kernel test robot 
> Link: 
> https://lore.kernel.org/oe-kbuild-all/202303031630.ntviuyqo-...@intel.com
> Signed-off-by: Sean Christopherson 
> ---
>
> This was prompted by a new W=1 build warning for a commit that went in
> through the KVM tree, but said commit has made its way to Linus, so it
> shouldn't matter who grabs this.

OK thanks. I'll take this via the powerpc tree for v6.4.

cheers


Re: [PATCH v2] hvc/xen: prevent concurrent accesses to the shared ring

2023-03-10 Thread Roger Pau Monné
On Fri, Mar 10, 2023 at 10:01:39AM +1100, Michael Ellerman wrote:
> Roger Pau Monné  writes:
> > On Mon, Dec 12, 2022 at 01:36:48PM +0100, Roger Pau Monné wrote:
> >> On Fri, Dec 02, 2022 at 12:40:05PM +0100, Roger Pau Monné wrote:
> >> > On Wed, Nov 30, 2022 at 05:08:06PM -0800, Stefano Stabellini wrote:
> >> > > On Wed, 30 Nov 2022, Roger Pau Monne wrote:
> >> > > > The hvc machinery registers both a console and a tty device based on
> >> > > > the hv ops provided by the specific implementation.  Those two
> >> > > > interfaces however have different locks, and there's no single locks
> >> > > > that's shared between the tty and the console implementations, hence
> >> > > > the driver needs to protect itself against concurrent accesses.
> >> > > > Otherwise concurrent calls using the split interfaces are likely to
> >> > > > corrupt the ring indexes, leaving the console unusable.
> >> > > >
> >> > > > Introduce a lock to xencons_info to serialize accesses to the shared
> >> > > > ring.  This is only required when using the shared memory console,
> >> > > > concurrent accesses to the hypercall based console implementation are
> >> > > > not an issue.
> >> > > >
> >> > > > Note the conditional logic in domU_read_console() is slightly 
> >> > > > modified
> >> > > > so the notify_daemon() call can be done outside of the locked region:
> >> > > > it's an hypercall and there's no need for it to be done with the lock
> >> > > > held.
> >> > >
> >> > > For domU_read_console: I don't mean to block this patch but we need to
> >> > > be sure about the semantics of hv_ops.get_chars. Either it is expected
> >> > > to be already locked, then we definitely shouldn't add another lock to
> >> > > domU_read_console. Or it is not expected to be already locked, then we
> >> > > should add the lock.
> >> > >
> >> > > My impression is that it is expected to be already locked, but I think
> >> > > we need Greg or Jiri to confirm one way or the other.
> >> >
> >> > Let me move both to the 'To:' field then.
> >> >
> >> > My main concern is the usage of hv_ops.get_chars hook in
> >> > hvc_poll_get_char(), as it's not obvious to me that callers of
> >> > tty->poll_get_char hook as returned by tty_find_polling_driver() will
> >> > always do so with the tty lock held (in fact the only user right now
> >> > doesn't seem to hold the tty lock).
> >> >
> >> > > Aside from that the rest looks fine.
> >
> > I guess I could reluctantly remove the lock in the get_chars hook,
> > albeit I'm not convinced at all the lock is not needed there.
> 
> I don't know the xen driver, but other HVC backends have a lock around
> their private state in their get_chars() implementations.
> 
> See eg. hvterm_raw_get_chars().

Yes, that was one of the motivation for adding the lock also here, and
it has already been mentioned.  The other is the usage of the hooks by
callers of hvc_poll_get_char().

Thanks, Roger.


Re: [PATCH] ASoC: do not include pm_runtime.h if not used

2023-03-10 Thread Claudiu.Beznea
On 10.03.2023 09:29, Srinivas Kandagatla wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the
> content is safe
> 
> On 07/03/2023 10:30, Claudiu Beznea wrote:
>> diff --git a/sound/soc/qcom/lpass-sc7180.c b/sound/soc/qcom/lpass-sc7180.c
>> index 41db6617e2ed..dc892fac4baa 100644
>> --- a/sound/soc/qcom/lpass-sc7180.c
>> +++ b/sound/soc/qcom/lpass-sc7180.c
>> @@ -12,7 +12,6 @@
>>   #include 
>>   #include 
>>   #include 
>> -#include 
>>   #include 
>>   #include 
>>   #include 
>> diff --git a/sound/soc/qcom/lpass-sc7280.c b/sound/soc/qcom/lpass-sc7280.c
>> index d43f480cbae3..ee4a4b553e74 100644
>> --- a/sound/soc/qcom/lpass-sc7280.c
>> +++ b/sound/soc/qcom/lpass-sc7280.c
>> @@ -8,7 +8,6 @@
>>   #include 
>>   #include 
>>   #include 
>> -#include 
>>
>>   #include 
> 
> Has these been compile tested? the reason I ask is because both these
> drivers need SET_SYSTEM_SLEEP_PM_OPS macro from pm.h which was getting
> included from pm_runtime.h, now that is removed, am guessing it will
> cause a compile errors.

I remember I compiled them all. But I will double check it.

> 
> can you atleast replace this with pm.h instead of removing it totally?

Sure! Thanks for pointing it.

> 
> --srini