i3c: Remove the const qualifier from i2c_msg pointer in i2c_xfers API
Subsystems (4)
PATCH 1/2 i3c: Remove the const qualifier from i2c_msg pointer in i2c_xfers API
The change is necessary to enable the use of the i2c_get_dma_safe_msg_buf() API, which requires a non-const struct i2c_msg * to operate. The i2c_get_dma_safe_msg_buf() function ensures safe handling of I2C messages when using DMA, making it essential for scenarios where DMA transfers are involved. By removing the const qualifier, this patch allows drivers to prepare and manage DMA-safe buffers directly.
--- drivers/i3c/master/dw-i3c-master.c | 2 +- drivers/i3c/master/i3c-master-cdns.c | 2 +- drivers/i3c/master/mipi-i3c-hci/core.c | 2 +- drivers/i3c/master/svc-i3c-master.c | 2 +- include/linux/i3c/master.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-)
drivers/i3c/master/dw-i3c-master.c +1 -1
@@ -1079,7 +1079,7 @@ static void dw_i3c_master_detach_i3c_dev(struct i3c_dev_desc *dev) }static int dw_i3c_master_i2c_xfers (struct i2c_dev_desc *dev, -const struct i2c_msg *i2c_xfers, +struct i2c_msg *i2c_xfers,int i2c_nxfers) {struct dw_i3c_i2c_dev_data *data =i2c_dev_get_master_data (dev);
drivers/i3c/master/i3c-master-cdns.c +1 -1
@@ -813,7 +813,7 @@ static int cdns_i3c_master_priv_xfers(struct i3c_dev_desc *dev, }static int cdns_i3c_master_i2c_xfers (struct i2c_dev_desc *dev, -const struct i2c_msg *xfers,int nxfers) +struct i2c_msg *xfers,int nxfers) {struct i3c_master_controller *m =i2c_dev_get_master (dev);struct cdns_i3c_master *master =to_cdns_i3c_master (m);
drivers/i3c/master/mipi-i3c-hci/core.c +1 -1
@@ -367,7 +367,7 @@ static int i3c_hci_priv_xfers(struct i3c_dev_desc *dev, }static int i3c_hci_i2c_xfers (struct i2c_dev_desc *dev, -const struct i2c_msg *i2c_xfers,int nxfers) +struct i2c_msg *i2c_xfers,int nxfers) {struct i3c_master_controller *m =i2c_dev_get_master (dev);struct i3c_hci *hci =to_i3c_hci (m);
drivers/i3c/master/svc-i3c-master.c +1 -1
@@ -1584,7 +1584,7 @@ static int svc_i3c_master_priv_xfers(struct i3c_dev_desc *dev, }static int svc_i3c_master_i2c_xfers (struct i2c_dev_desc *dev, -const struct i2c_msg *xfers, +struct i2c_msg *xfers,int nxfers) {struct i3c_master_controller *m =i2c_dev_get_master (dev);
include/linux/i3c/master.h +1 -1
@@ -475,7 +475,7 @@ struct i3c_master_controller_ops {int (*attach_i2c_dev)(struct i2c_dev_desc *dev);void (*detach_i2c_dev)(struct i2c_dev_desc *dev);int (*i2c_xfers)(struct i2c_dev_desc *dev, -const struct i2c_msg *xfers,int nxfers); +struct i2c_msg *xfers,int nxfers);int (*request_ibi)(struct i3c_dev_desc *dev,const struct i3c_ibi_setup *req);void (*free_ibi)(struct i3c_dev_desc *dev);
Signature · 1 line
2.25.1
PATCH 2/2 i3c: mipi-i3c-hci: Use DMA-safe buffer for I2C transfers
The i2c_get_dma_safe_msg_buf function is used to ensure safe handling of I2C messages in HCI DMA mode.
--- drivers/i3c/master/mipi-i3c-hci/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i3c/master/mipi-i3c-hci/core.c +1 -1
@@ -382,7 +382,7 @@ static int i3c_hci_i2c_xfers(struct i2c_dev_desc *dev,return -ENOMEM ;for (i =0 ; i < nxfers; i++) { - xfer[i].data = i2c_xfers[i].buf; + xfer[i].data =i2c_get_dma_safe_msg_buf (&i2c_xfers[i],1 ); xfer[i].data_len = i2c_xfers[i].len; xfer[i].rnw = i2c_xfers[i].flags &I2C_M_RD ; hci->cmd->prep_i2c_xfer (hci, dev, &xfer[i]);
Signature · 1 line
2.25.1
Quoted 9 lines · Billy Tsai
The change is necessary to enable the use of the
i2c_get_dma_safe_msg_buf()API, which requires a non-conststruct i2c_msg *to operate. Thei2c_get_dma_safe_msg_buf()function ensures safe handling of I2C messages when using DMA, making it essential for scenarios where DMA transfers are involved. By removing theconstqualifier, this patch allows drivers to prepare and manage DMA-safe buffers directly.Signed-off-by Billy Tsai <[email protected]>
Makes sense to me:
Re: [PATCH v1 2/2] i3c: mipi-i3c-hci: Use DMA-safe buffer for I2C transfers
In reply to Billy Tsaidrivers/i3c/master/mipi-i3c-hci/core.c static int i3c_hci_i2c_xfers(struct i2c_dev_desc *dev, · line 385
Quoted 3 lines
drivers/i3c/master/mipi-i3c-hci/core.c +1
-1- xfer[i].data = i2c_xfers[i].buf; + xfer[i].data =i2c_get_dma_safe_msg_buf (&i2c_xfers[i],1 );
Where is a 'get' there also should be a 'put'.
Good Change Billy. Thanks for bringing this to i3c.
Quoted 22 lines · Billy Tsai
The change is necessary to enable the use of the
i2c_get_dma_safe_msg_buf()API, which requires a non-conststruct i2c_msg *to operate. Thei2c_get_dma_safe_msg_buf()function ensures safe handling of I2C messages when using DMA, making it essential for scenarios where DMA transfers are involved. By removing theconstqualifier, this patch allows drivers to prepare and manage DMA-safe buffers directly.Signed-off-by Billy Tsai <[email protected]>--- drivers/i3c/master/dw-i3c-master.c | 2 +- drivers/i3c/master/i3c-master-cdns.c | 2 +- drivers/i3c/master/mipi-i3c-hci/core.c | 2 +- drivers/i3c/master/svc-i3c-master.c | 2 +- include/linux/i3c/master.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-)drivers/i3c/master/dw-i3c-master.c +0
-0
drivers/i3c/master/dw-i3c-master.c static void dw_i3c_master_detach_i3c_dev(struct i3c_dev_desc *dev) · line 1082
Quoted 5 lines
drivers/i3c/master/dw-i3c-master.c +1
-1@@ -1079,7 +1079,7 @@ static void dw_i3c_master_detach_i3c_dev(struct i3c_dev_desc *dev) } static int dw_i3c_master_i2c_xfers(struct i2c_dev_desc *dev, - const struct i2c_msg *i2c_xfers, + struct i2c_msg *i2c_xfers,
what we need is only i2c_xfers->buf to be DMA-safe, not the *i2c_xfers. Right ?
Quoted 16 lines
drivers/i3c/master/dw-i3c-master.c +0
-0int i2c_nxfers) {struct dw_i3c_i2c_dev_data *data =i2c_dev_get_master_data (dev);drivers/i3c/master/i3c-master-cdns.c +1
-1@@ -813,7 +813,7 @@ static int cdns_i3c_master_priv_xfers(struct i3c_dev_desc *dev, }static int cdns_i3c_master_i2c_xfers (struct i2c_dev_desc *dev, -const struct i2c_msg *xfers,int nxfers) +struct i2c_msg *xfers,int nxfers) {struct i3c_master_controller *m =i2c_dev_get_master (dev);
Quoted 1 line
struct cdns_i3c_master *master = to_cdns_i3c_master(m);
we only need to use i2c_get_dma_safe_msg_buf() for the xfers[i].buf being used inside the driver as a protection ? Also I guess same change is required for all the vendor drivers. But Not sure if it's feasible with this patch ?
Quoted 39 lines
drivers/i3c/master/mipi-i3c-hci/core.c +1
-1@@ -367,7 +367,7 @@ static int i3c_hci_priv_xfers(struct i3c_dev_desc *dev, }static int i3c_hci_i2c_xfers (struct i2c_dev_desc *dev, -const struct i2c_msg *i2c_xfers,int nxfers) +struct i2c_msg *i2c_xfers,int nxfers) {struct i3c_master_controller *m =i2c_dev_get_master (dev);struct i3c_hci *hci =to_i3c_hci (m);drivers/i3c/master/svc-i3c-master.c +1
-1@@ -1584,7 +1584,7 @@ static int svc_i3c_master_priv_xfers(struct i3c_dev_desc *dev, }static int svc_i3c_master_i2c_xfers (struct i2c_dev_desc *dev, -const struct i2c_msg *xfers, +struct i2c_msg *xfers,int nxfers) {struct i3c_master_controller *m =i2c_dev_get_master (dev);include/linux/i3c/master.h +1
-1@@ -475,7 +475,7 @@ struct i3c_master_controller_ops {int (*attach_i2c_dev)(struct i2c_dev_desc *dev);void (*detach_i2c_dev)(struct i2c_dev_desc *dev);int (*i2c_xfers)(struct i2c_dev_desc *dev, -const struct i2c_msg *xfers,int nxfers); +struct i2c_msg *xfers,int nxfers);int (*request_ibi)(struct i3c_dev_desc *dev,const struct i3c_ibi_setup *req);void (*free_ibi)(struct i3c_dev_desc *dev);
Signature · 3 lines
linux-i3c mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-i3c
Re: [PATCH v1 2/2] i3c: mipi-i3c-hci: Use DMA-safe buffer for I2C transfers
In reply to Billy TsaiQuoted 13 lines · Billy Tsai
The
i2c_get_dma_safe_msg_buffunction is used to ensure safe handling of I2C messages in HCI DMA mode.Signed-off-by Billy Tsai <[email protected]>--- drivers/i3c/master/mipi-i3c-hci/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/i3c/master/mipi-i3c-hci/core.c +0
-0
drivers/i3c/master/mipi-i3c-hci/core.c static int i3c_hci_i2c_xfers(struct i2c_dev_desc *dev, · line 385
Quoted 5 lines
drivers/i3c/master/mipi-i3c-hci/core.c +1
-1@@ -382,7 +382,7 @@ static int i3c_hci_i2c_xfers(struct i2c_dev_desc *dev,return -ENOMEM ;for (i =0 ; i < nxfers; i++) { - xfer[i].data = i2c_xfers[i].buf; + xfer[i].data =i2c_get_dma_safe_msg_buf (&i2c_xfers[i],1 );
Should be i2c_xfers[i].buf ? IIUC, it's iterating over many message buffers upto nxfers.
Quoted 3 lines
drivers/i3c/master/mipi-i3c-hci/core.c +0
-0xfer[i].data_len = i2c_xfers[i].len; xfer[i].rnw = i2c_xfers[i].flags &I2C_M_RD ; hci->cmd->prep_i2c_xfer (hci, dev, &xfer[i]);
Signature · 3 lines
linux-i3c mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-i3c
Quoted 3 lines
what we need is only
i2c_xfers->bufto be DMA-safe, not the*i2c_xfers. Right ?
Yes.
Quoted 2 lines
Also I guess same change is required for all the vendor drivers. But Not sure if it's feasible with this patch ?
I also wondered if the I3C core should maybe provide this, but then I saw that currently only the mipi-hci driver uses DMA and concluded that per-driver is better. At least for now.
Re: [PATCH v1 2/2] i3c: mipi-i3c-hci: Use DMA-safe buffer for I2C transfers
In reply to Billy TsaiQuoted 13 lines · Billy Tsai
The
i2c_get_dma_safe_msg_buffunction is used to ensure safe handling of I2C messages in HCI DMA mode.Signed-off-by Billy Tsai <[email protected]>--- drivers/i3c/master/mipi-i3c-hci/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/i3c/master/mipi-i3c-hci/core.c +0
-0
drivers/i3c/master/mipi-i3c-hci/core.c static int i3c_hci_i2c_xfers(struct i2c_dev_desc *dev, · line 388
Quoted 8 lines
drivers/i3c/master/mipi-i3c-hci/core.c +1
-1@@ -382,7 +382,7 @@ static int i3c_hci_i2c_xfers(struct i2c_dev_desc *dev,return -ENOMEM ;for (i =0 ; i < nxfers; i++) { - xfer[i].data = i2c_xfers[i].buf; + xfer[i].data =i2c_get_dma_safe_msg_buf (&i2c_xfers[i],1 ); xfer[i].data_len = i2c_xfers[i].len; xfer[i].rnw = i2c_xfers[i].flags &I2C_M_RD ; hci->cmd->prep_i2c_xfer (hci, dev, &xfer[i]);
This allow to remove calls to i3c_hci_alloc_safe_xfer_buf() and i3c_hci_free_safe_xfer_buf() in i3c_hci_i2c_xfers().
I was pondering the i2c_get_dma_safe_msg_buf() when making commit 4afd72876942 ("i3c: mipi-i3c-hci: Add DMA bounce buffer for private transfers") but decided to reuse the same (own) helper for both i3c_hci_priv_xfers() and i3c_hci_i2c_xfers().
In that sense I'd modify the commit log a bit that instead of ensuring safe handling patch switches from custom helper to i2c_get_dma_safe_msg_buf() and i2c_put_dma_safe_msg_buf() (please note the comment from Wolfram).
Quoted 7 lines · Billy Tsai
The change is necessary to enable the use of the
i2c_get_dma_safe_msg_buf()API, which requires a non-conststruct i2c_msg *to operate. Thei2c_get_dma_safe_msg_buf()function ensures safe handling of I2C messages when using DMA, making it essential for scenarios where DMA transfers are involved. By removing theconstqualifier, this patch allows drivers to prepare and manage DMA-safe buffers directly.
Why not modify i2c_get_dma_safe_msg_buf() to accept 'const struct i2c_msg' instead?
Quoted 8 lines
Signed-off-by Billy Tsai <[email protected]>--- drivers/i3c/master/dw-i3c-master.c | 2 +- drivers/i3c/master/i3c-master-cdns.c | 2 +- drivers/i3c/master/mipi-i3c-hci/core.c | 2 +- drivers/i3c/master/svc-i3c-master.c | 2 +- include/linux/i3c/master.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-)
Re: [PATCH v1 2/2] i3c: mipi-i3c-hci: Use DMA-safe buffer for I2C transfers
In reply to Wolfram SangQuoted 6 lines
Quoted 4 lines
- xfer[i].data = i2c_xfers[i].buf;
+ xfer[i].data =
i2c_get_dma_safe_msg_buf(&i2c_xfers[i], 1);Where is a 'get' there also should be a 'put'.
Thanks.
I will add the i2c_put_dma_safe_msg_buf in the next version.
Billy Tsai
Looks good to me.
Quoted 9 lines · Billy Tsai
The change is necessary to enable the use of the
i2c_get_dma_safe_msg_buf()API, which requires a non-conststruct i2c_msg *to operate. Thei2c_get_dma_safe_msg_buf()function ensures safe handling of I2C messages when using DMA, making it essential for scenarios where DMA transfers are involved. By removing theconstqualifier, this patch allows drivers to prepare and manage DMA-safe buffers directly.Signed-off-by Billy Tsai <[email protected]>
Quoted 73 lines
--- drivers/i3c/master/dw-i3c-master.c | 2 +- drivers/i3c/master/i3c-master-cdns.c | 2 +- drivers/i3c/master/mipi-i3c-hci/core.c | 2 +- drivers/i3c/master/svc-i3c-master.c | 2 +- include/linux/i3c/master.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-)drivers/i3c/master/dw-i3c-master.c +1
-1@@ -1079,7 +1079,7 @@ static void dw_i3c_master_detach_i3c_dev(struct i3c_dev_desc *dev) }static int dw_i3c_master_i2c_xfers (struct i2c_dev_desc *dev, -const struct i2c_msg *i2c_xfers, +struct i2c_msg *i2c_xfers,int i2c_nxfers) {struct dw_i3c_i2c_dev_data *data =i2c_dev_get_master_data (dev);drivers/i3c/master/i3c-master-cdns.c +1
-1@@ -813,7 +813,7 @@ static int cdns_i3c_master_priv_xfers(struct i3c_dev_desc *dev, }static int cdns_i3c_master_i2c_xfers (struct i2c_dev_desc *dev, -const struct i2c_msg *xfers,int nxfers) +struct i2c_msg *xfers,int nxfers) {struct i3c_master_controller *m =i2c_dev_get_master (dev);struct cdns_i3c_master *master =to_cdns_i3c_master (m);drivers/i3c/master/mipi-i3c-hci/core.c +1
-1@@ -367,7 +367,7 @@ static int i3c_hci_priv_xfers(struct i3c_dev_desc *dev, }static int i3c_hci_i2c_xfers (struct i2c_dev_desc *dev, -const struct i2c_msg *i2c_xfers,int nxfers) +struct i2c_msg *i2c_xfers,int nxfers) {struct i3c_master_controller *m =i2c_dev_get_master (dev);struct i3c_hci *hci =to_i3c_hci (m);drivers/i3c/master/svc-i3c-master.c +1
-1@@ -1584,7 +1584,7 @@ static int svc_i3c_master_priv_xfers(struct i3c_dev_desc *dev, }static int svc_i3c_master_i2c_xfers (struct i2c_dev_desc *dev, -const struct i2c_msg *xfers, +struct i2c_msg *xfers,int nxfers) {struct i3c_master_controller *m =i2c_dev_get_master (dev);include/linux/i3c/master.h +1
-1@@ -475,7 +475,7 @@ struct i3c_master_controller_ops {int (*attach_i2c_dev)(struct i2c_dev_desc *dev);void (*detach_i2c_dev)(struct i2c_dev_desc *dev);int (*i2c_xfers)(struct i2c_dev_desc *dev, -const struct i2c_msg *xfers,int nxfers); +struct i2c_msg *xfers,int nxfers);int (*request_ibi)(struct i3c_dev_desc *dev,const struct i3c_ibi_setup *req);void (*free_ibi)(struct i3c_dev_desc *dev);