Fixed bugs in pl080
PATCH 2/3 The swidth and dwidth of pl080 are not equal.
In reply to Tao DingThe amount of data transmitted each time is the maximum value between s and w, but it should be noted that the remaining transmission amount is less than the width.
Configure swidth to 1 byte, width to 4 bytes, and transfer size to 4.
Configuration
../configure --target-list=arm-softmmu --enable-debug
Reproducer
./qemu-system-arm -M versatilepb -m 128M -nographic -S \
-device loader,addr=0x00000000,data=0x44332211,data-len=4 \
-device loader,addr=0x00001000,data=0x00000000,data-len=4 \
-device loader,addr=0x10130030,data=0x00000001,data-len=4 \
-device loader,addr=0x10130100,data=0x00000000,data-len=4 \
-device loader,addr=0x10130104,data=0x00001000,data-len=4 \
-device loader,addr=0x10130108,data=0x00000000,data-len=4 \
-device loader,addr=0x1013010C,data=0x9e47f004,data-len=4 \
-device loader,addr=0x10130110,data=0x0000c001,data-len=4 Qemu monitor
(qemu) xp /1wx 0x00001000
00001000: 0x00002211The result correctly after fixed
(qemu) xp /1wx 0x00001000
00001000: 0x44332211--- hw/dma/pl080.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-)
hw/dma/pl080.c +20 -12
@@ -160,26 +160,34 @@ again:/* Transfer one element. */ /* ??? Should transfer multiple elements for a burst request. */ -/* ??? Unclear what the proper behavior is when source and -destination widths are different. */ swidth =1 << ((ch->ctrl >>18 ) &7 ); dwidth =1 << ((ch->ctrl >>21 ) &7 ); -for (n =0 ; n < dwidth; n+= swidth) { + xsize = (dwidth < swidth) ? swidth : dwidth; + xsize = (xsize < size * swidth) ? xsize : (size * swidth); +for (n =0 ; n < xsize; n += swidth) {address_space_read (&s->downstream_as, ch->src,MEMTXATTRS_UNSPECIFIED , buff + n, swidth); -if (ch->ctrl &PL080_CCTRL_SI ) +if (ch->ctrl &PL080_CCTRL_SI ) { ch->src += swidth; + } } - xsize = (dwidth < swidth) ? swidth : dwidth; -/* ??? This may pad the value incorrectly for dwidth < 32. */ -for (n =0 ; n < xsize; n += dwidth) { -address_space_write (&s->downstream_as, ch->dest + n, -MEMTXATTRS_UNSPECIFIED , buff + n, dwidth); -if (ch->ctrl &PL080_CCTRL_DI ) - ch->dest += swidth; +if (xsize < dwidth) { +address_space_write (&s->downstream_as, ch->dest, +MEMTXATTRS_UNSPECIFIED , buff, xsize); +if (ch->ctrl &PL080_CCTRL_DI ) { + ch->dest += dwidth; + } + }else { +for (n =0 ; n < xsize; n += dwidth) { +address_space_write (&s->downstream_as, ch->dest, +MEMTXATTRS_UNSPECIFIED , buff + n, dwidth); +if (ch->ctrl &PL080_CCTRL_DI ) { + ch->dest += dwidth; + } + } } - size--; + size -= xsize / swidth; ch->ctrl = (ch->ctrl &0xfffff000 ) | size;if (size ==0 ) {/* Transfer complete. */
Signature · 1 line
2.43.0
PATCH 1/3 An interrupt is generated after the DMA transfer complete.
In reply to Tao DingPL080 cannot trigger interrupt correctly. Reproduce this problem in a simple way.
In the versatilpb board, the interrupt output of pl080 is connected to the 17th interrupt input of pl190. By reading the status register of pl190, determined whether there is an interrupt generated for the corresponding input.
The basic address of pl080 is 0x10130000, and the basic address of pl190 is 0x10140000. Read the value of the address through the qemu monitor.
Configuration
../configure --target-list=arm-softmmu --enable-debug
Reproducer
./qemu-system-arm -M versatilepb -m 128M -nographic -S \
-device loader,addr=0x00000000,data=0x11223344,data-len=4 \
-device loader,addr=0x00001000,data=0x00000000,data-len=4 \
-device loader,addr=0x10130030,data=0x00000001,data-len=4 \
-device loader,addr=0x10130100,data=0x00000000,data-len=4 \
-device loader,addr=0x10130104,data=0x00001000,data-len=4 \
-device loader,addr=0x10130108,data=0x00000000,data-len=4 \
-device loader,addr=0x1013010C,data=0x9e4bf001,data-len=4 \
-device loader,addr=0x10130110,data=0x0000c001,data-len=4Qemu monitor
(qemu) xp /1wx 0x10140008
10140008: 0x00000000The result correctly after fixed
(qemu) xp /1wx 0x10140008
10140008: 0x00020000--- hw/dma/pl080.c | 1 + 1 file changed, 1 insertion(+)
hw/dma/pl080.c +1 -0
@@ -212,6 +212,7 @@ again:if (--s->running) s->running =1 ; } +pl080_update (s); } static uint64_t pl080_read(void *opaque, hwaddr offset,
Signature · 1 line
2.43.0
PATCH 3/3 The LLI of pl080 should be aligned with 4 bytes.
In reply to Tao DingWhen the bit0 of the LLI register is configured as master 1, it can cause incorrect data reading, and even lead to qemu crash.
Constructed 1 LLI item. The initial LLI register points to the address of the LLI item. But the bit 0 of the LLI register is 1, which mean read from Master1 port.
According to the description in the PL080 manual, the address for the next LLI should be word aligned.
Configuration
../configure --target-list=arm-softmmu --enable-debug
Reproducer
./qemu-system-arm -M versatilepb -m 128M -nographic -S \
-device loader,addr=0x00002000,data=0x00000004,data-len=4 \
-device loader,addr=0x00002004,data=0x00001004,data-len=4 \
-device loader,addr=0x00002008,data=0x00000000,data-len=4 \
-device loader,addr=0x0000200c,data=0x9e4bf001,data-len=4 \
-device loader,addr=0x00000000,data=0x44332211,data-len=4 \
-device loader,addr=0x00000004,data=0x88776655,data-len=4 \
-device loader,addr=0x00001000,data=0x00000000,data-len=4 \
-device loader,addr=0x00001004,data=0x00000000,data-len=4 \
-device loader,addr=0x10130030,data=0x00000001,data-len=4 \
-device loader,addr=0x10130100,data=0x00000000,data-len=4 \
-device loader,addr=0x10130104,data=0x00001000,data-len=4 \
-device loader,addr=0x10130108,data=0x00002001,data-len=4 \
-device loader,addr=0x1013010C,data=0x1e4bf001,data-len=4 \
-device loader,addr=0x10130110,data=0x0000c001,data-len=4 Qemu Crash.
The result correctly after fixed
(qemu) xp /1wx 0x00001000
00001000: 0x44332211
(qemu) xp /1wx 0x00001004
00001004: 0x88776655--- hw/dma/pl080.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
hw/dma/pl080.c +7 -5
@@ -102,6 +102,7 @@ static void pl080_run(PL080State *s)int size;uint8_t buff[4 ];uint32_t req; +uint32_t next_lli; s->tc_mask =0 ;for (c =0 ; c < s->nchannels; c++) {
@@ -191,21 +192,22 @@ again: ch->ctrl = (ch->ctrl &0xfffff000 ) | size;if (size ==0 ) {/* Transfer complete. */ -if (ch->lli) { + next_lli = (ch->lli & ~3 ); +if (next_lli) { ch->src =address_space_ldl_le (&s->downstream_as, - ch->lli, + next_lli,MEMTXATTRS_UNSPECIFIED ,NULL ); ch->dest =address_space_ldl_le (&s->downstream_as, - ch->lli +4 , + next_lli +4 ,MEMTXATTRS_UNSPECIFIED ,NULL ); ch->ctrl =address_space_ldl_le (&s->downstream_as, - ch->lli +12 , + next_lli +12 ,MEMTXATTRS_UNSPECIFIED ,NULL ); ch->lli =address_space_ldl_le (&s->downstream_as, - ch->lli +8 , + next_lli +8 ,MEMTXATTRS_UNSPECIFIED ,NULL ); }else {
Signature · 1 line
2.43.0
cover Fixed bugs in pl080
Hi all,
When I tested pl080 using the existing dmatest tool in Linux,
I found that pl080 could not output the results correctly.
The main issues involved are inconsistent source and destination bit widths, misalignment of LLI, which can lead to incorrect data and even cause qemu crashes.
Tao Ding (3):
An interrupt is generated after the DMA transfer complete. The swidth and dwidth of pl080 are not equal. The LLI of pl080 should be aligned with 4 bytes.
hw/dma/pl080.c | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-)
base-commit: 1fd5ff9d76d23ab23a68419cbc76d5ee33e8b455
Signature · 1 line
2.43.0
Re: [PATCH v1 3/3] The LLI of pl080 should be aligned with 4 bytes.
In reply to Tao DingQuoted 29 lines · Tao Ding
When the bit0 of the LLI register is configured as master 1, it can cause incorrect data reading, and even lead to qemu crash.
Constructed 1 LLI item. The initial LLI register points to the address of the LLI item. But the bit 0 of the LLI register is 1, which mean read from Master1 port.
According to the description in the PL080 manual, the address for the next LLI should be word aligned.Configuration
../configure --target-list=arm-softmmu --enable-debug Reproducer ./qemu-system-arm -M versatilepb -m 128M -nographic -S \ -device loader,addr=0x00002000,data=0x00000004,data-len=4 \ -device loader,addr=0x00002004,data=0x00001004,data-len=4 \ -device loader,addr=0x00002008,data=0x00000000,data-len=4 \ -device loader,addr=0x0000200c,data=0x9e4bf001,data-len=4 \ -device loader,addr=0x00000000,data=0x44332211,data-len=4 \ -device loader,addr=0x00000004,data=0x88776655,data-len=4 \ -device loader,addr=0x00001000,data=0x00000000,data-len=4 \ -device loader,addr=0x00001004,data=0x00000000,data-len=4 \ -device loader,addr=0x10130030,data=0x00000001,data-len=4 \ -device loader,addr=0x10130100,data=0x00000000,data-len=4 \ -device loader,addr=0x10130104,data=0x00001000,data-len=4 \ -device loader,addr=0x10130108,data=0x00002001,data-len=4 \ -device loader,addr=0x1013010C,data=0x1e4bf001,data-len=4 \ -device loader,addr=0x10130110,data=0x0000c001,data-len=4Qemu Crash.
Quoted 8 lines
The result correctly after fixed
(qemu) xp /1wx 0x00001000 00001000: 0x44332211 (qemu) xp /1wx 0x00001004 00001004: 0x88776655Signed-off-by Tao Ding <[email protected]>---
The crash only happens because of a different PL080 bug where we weren't correctly handling invalid swidth and dwidth values, which is fixed by this patch I sent last week:
https://patchew.org/QEMU/[email protected]/
but we are certainly mishandling the LLI register here.
thanks
-- PMM
Re: [PATCH v1 2/3] The swidth and dwidth of pl080 are not equal.
In reply to Tao DingQuoted 37 lines · Tao Ding
The amount of data transmitted each time is the maximum value between s and w, but it should be noted that the remaining transmission amount is less than the width.
Configure swidth to 1 byte, width to 4 bytes, and transfer size to 4.
Configuration
../configure --target-list=arm-softmmu --enable-debug Reproducer ./qemu-system-arm -M versatilepb -m 128M -nographic -S \ -device loader,addr=0x00000000,data=0x44332211,data-len=4 \ -device loader,addr=0x00001000,data=0x00000000,data-len=4 \ -device loader,addr=0x10130030,data=0x00000001,data-len=4 \ -device loader,addr=0x10130100,data=0x00000000,data-len=4 \ -device loader,addr=0x10130104,data=0x00001000,data-len=4 \ -device loader,addr=0x10130108,data=0x00000000,data-len=4 \ -device loader,addr=0x1013010C,data=0x9e47f004,data-len=4 \ -device loader,addr=0x10130110,data=0x0000c001,data-len=4Qemu monitor
(qemu) xp /1wx 0x00001000 00001000: 0x00002211The result correctly after fixed
(qemu) xp /1wx 0x00001000 00001000: 0x44332211Signed-off-by Tao Ding <[email protected]>--- hw/dma/pl080.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-)hw/dma/pl080.c +0
-0
hw/dma/pl080.c again: · line 165
Quoted 9 lines
hw/dma/pl080.c +1
-3@@ -160,26 +160,34 @@ again:/* Transfer one element. */ /* ??? Should transfer multiple elements for a burst request. */ -/* ??? Unclear what the proper behavior is when source and -destination widths are different. */ swidth =1 << ((ch->ctrl >>18 ) &7 ); dwidth =1 << ((ch->ctrl >>21 ) &7 ); -for (n =0 ; n < dwidth; n+= swidth) { + xsize = (dwidth < swidth) ? swidth : dwidth;
I think this can be more clearly written as
xsize = MAX(swidth, dwidth);
since we're editing the line anyway.
hw/dma/pl080.c again: · line 166
Quoted 1 line
hw/dma/pl080.c +1
-0+ xsize = (xsize < size * swidth) ? xsize : (size * swidth);
xsize = MIN(xsize, size * swidth);
So this is handling the case where our destination width is larger than the remaining amount the transfer size says we should be reading from the source, which is cases like
"source width = 1, dest width = 4, transfer count not a multiple of 4". The TRM is unfortunately very vague about what the hardware does here. I think the hardware designers considered this to be a programming error:
in the "Software considerations" section of the TRM one of the items is:
* If the source width is less than the destination width, the TransferSize value multiplied by the source width must be an integral multiple of the destination width.
Quoted 11 lines
hw/dma/pl080.c +3
-4+for (n =0 ; n < xsize; n += swidth) {address_space_read (&s->downstream_as, ch->src,MEMTXATTRS_UNSPECIFIED , buff + n, swidth); -if (ch->ctrl &PL080_CCTRL_SI ) +if (ch->ctrl &PL080_CCTRL_SI ) { ch->src += swidth; + } } - xsize = (dwidth < swidth) ? swidth : dwidth; -/* ??? This may pad the value incorrectly for dwidth < 32. */ -for (n =0 ; n < xsize; n += dwidth) {
hw/dma/pl080.c again: · line 179
Quoted 10 lines
hw/dma/pl080.c +6
-4-address_space_write (&s->downstream_as, ch->dest + n, -MEMTXATTRS_UNSPECIFIED , buff + n, dwidth); -if (ch->ctrl &PL080_CCTRL_DI ) - ch->dest += swidth; +if (xsize < dwidth) { +address_space_write (&s->downstream_as, ch->dest, +MEMTXATTRS_UNSPECIFIED , buff, xsize); +if (ch->ctrl &PL080_CCTRL_DI ) { + ch->dest += dwidth; + }
Here we choose to handle the "swidth and tsize say we should read e.g. 2 bytes from the source but dwidth is e.g. 4" case by performing a 2 byte write to the destination. I don't think this is what the hardware would do.
There is this interesting bit in the "software considerations" section:
* While writing, the TransferSize bit-field is like a control register because it determines how many transfers the DMAC performs. However, during read-back, TransferSize behaves like a status register because it returns the number of remaining transfers in terms of source width. So when TransferSize is read back, it returns the number of destination-transfer-completed stored in a separate counter called TrfSizeDst multiplied by a factor.
My best guess from stuff like this is that the way the PL080 works internally is that for each dest-write it needs to do for the transfer it does the appropriate number of source-reads. If the guest misprograms it such that that means it reads more than (transferwidth * swidth) that will result in reading more data from the source than intended, but that would be a software bug.
I would suggest doing something like that, but at any rate commenting and doing a LOG_GUEST_ERROR if there's a mismatch in swidth/dwidth/tsize such that we wouldn't have enough bytes to do a full destination-write.
hw/dma/pl080.c again: · line 190
Quoted 12 lines
hw/dma/pl080.c +9
-1+ }else { +for (n =0 ; n < xsize; n += dwidth) { +address_space_write (&s->downstream_as, ch->dest, +MEMTXATTRS_UNSPECIFIED , buff + n, dwidth); +if (ch->ctrl &PL080_CCTRL_DI ) { + ch->dest += dwidth; + } + } } - size--; + size -= xsize / swidth;
This change is correct (the transfer size field in the control register is supposed to count down by 1 for each swidth-sized data unit we transfer, and our loop can do more than one swidth read), and probably the most important bugfix in this patch, because it's the one that matters for normal correct use of the PL080.
Quoted 5 lines
hw/dma/pl080.c +0
-1ch->ctrl = (ch->ctrl &0xfffff000 ) | size;if (size ==0 ) {/* Transfer complete. */ --2.43.0
thanks
-- PMM
Quoted 11 lines · Tao Ding
Hi all,
When I tested pl080 using the existing dmatest tool in Linux,
I found that pl080 could not output the results correctly.
The main issues involved are inconsistent source and destination bit widths, misalignment of LLI, which can lead to incorrect data and even cause qemu crashes.Tao Ding (3):
An interrupt is generated after the DMA transfer complete. The swidth and dwidth of pl080 are not equal. The LLI of pl080 should be aligned with 4 bytes.
Hi; I've taken patches 1 and 3 into target-arm.next (with some adjustments to the commit messages). I had some review comments on patch 2.
thanks
-- PMM
Re: [PATCH v1 2/3] The swidth and dwidth of pl080 are not equal.
In reply to Peter MaydellThank you for your valuable review.
I agree with your suggestion, it is necessary to satisfy that transfersize * swidth is an integer multiple of dwidth. So, some of the code is actually redundant in this patch. Before that, swidth,dwidth and transfersize will be checked, and if the conditions are not met, there will be qemu_log_mask(LOG_GUEST_ERROR).
Can I modify this patch and submit it as patch v2.
Quoted 110 lines
Quoted 9 lines
--- hw/dma/pl080.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-)hw/dma/pl080.c +0
-0hw/dma/pl080.c again: · line 165
Quoted 9 lines
hw/dma/pl080.c +1
-3@@ -160,26 +160,34 @@ again:/* Transfer one element. */ /* ??? Should transfer multiple elements for a burst request. */ -/* ??? Unclear what the proper behavior is when source and -destination widths are different. */ swidth =1 << ((ch->ctrl >>18 ) &7 ); dwidth =1 << ((ch->ctrl >>21 ) &7 ); -for (n =0 ; n < dwidth; n+= swidth) { + xsize = (dwidth < swidth) ? swidth : dwidth;I think this can be more clearly written as
xsize = MAX(swidth, dwidth);since we're editing the line anyway.
hw/dma/pl080.c again: · line 166
Quoted 1 line
hw/dma/pl080.c +1
-0+ xsize = (xsize < size * swidth) ? xsize : (size * swidth);xsize = MIN(xsize, size * swidth);So this is handling the case where our destination width is larger than the remaining amount the transfer size says we should be reading from the source, which is cases like
"source width = 1, dest width = 4, transfer count not a multiple of 4". The TRM is unfortunately very vague about what the hardware does here. I think the hardware designers considered this to be a programming error:
in the "Software considerations" section of the TRM one of the items is:* If the source width is less than the destination width, the TransferSize value multiplied by the source width must be an integral multiple of the destination width.
Quoted 11 lines
hw/dma/pl080.c +3
-4+for (n =0 ; n < xsize; n += swidth) {address_space_read (&s->downstream_as, ch->src,MEMTXATTRS_UNSPECIFIED , buff + n, swidth); -if (ch->ctrl &PL080_CCTRL_SI ) +if (ch->ctrl &PL080_CCTRL_SI ) { ch->src += swidth; + } } - xsize = (dwidth < swidth) ? swidth : dwidth; -/* ??? This may pad the value incorrectly for dwidth < 32. */ -for (n =0 ; n < xsize; n += dwidth) {hw/dma/pl080.c again: · line 179
Quoted 10 lines
hw/dma/pl080.c +6
-4-address_space_write (&s->downstream_as, ch->dest + n, -MEMTXATTRS_UNSPECIFIED , buff + n, dwidth); -if (ch->ctrl &PL080_CCTRL_DI ) - ch->dest += swidth; +if (xsize < dwidth) { +address_space_write (&s->downstream_as, ch->dest, +MEMTXATTRS_UNSPECIFIED , buff, xsize); +if (ch->ctrl &PL080_CCTRL_DI ) { + ch->dest += dwidth; + }Here we choose to handle the "swidth and tsize say we should read e.g. 2 bytes from the source but dwidth is e.g. 4" case by performing a 2 byte write to the destination. I don't think this is what the hardware would do.
There is this interesting bit in the "software considerations" section:
* While writing, the TransferSize bit-field is like a control register because it determines how many transfers the DMAC performs. However, during read-back, TransferSize behaves like a status register because it returns the number of remaining transfers in terms of source width. So when TransferSize is read back, it returns the number of destination-transfer-completed stored in a separate counter called TrfSizeDst multiplied by a factor.
My best guess from stuff like this is that the way the PL080 works internally is that for each dest-write it needs to do for the transfer it does the appropriate number of source-reads. If the guest misprograms it such that that means it reads more than (transferwidth * swidth) that will result in reading more data from the source than intended, but that would be a software bug.
I would suggest doing something like that, but at any rate commenting and doing a
LOG_GUEST_ERRORif there's a mismatch in swidth/dwidth/tsize such that we wouldn't have enough bytes to do a full destination-write.hw/dma/pl080.c again: · line 190
Quoted 12 lines
hw/dma/pl080.c +9
-1+ }else { +for (n =0 ; n < xsize; n += dwidth) { +address_space_write (&s->downstream_as, ch->dest, +MEMTXATTRS_UNSPECIFIED , buff + n, dwidth); +if (ch->ctrl &PL080_CCTRL_DI ) { + ch->dest += dwidth; + } + } } - size--; + size -= xsize / swidth;This change is correct (the transfer size field in the control register is supposed to count down by 1 for each swidth-sized data unit we transfer, and our loop can do more than one swidth read), and probably the most important bugfix in this patch, because it's the one that matters for normal correct use of the PL080.
Quoted 5 lines
hw/dma/pl080.c +0
-1ch->ctrl = (ch->ctrl &0xfffff000 ) | size;if (size ==0 ) {/* Transfer complete. */ --2.43.0
thanks
-- PMM
v2 cover Fix transfer size register decrement
When source and destination widths are different, the transfer size register was not being decremented correctly, causing data corruption.
Compared to the previous version(PATCH v1 2/3), simplified the code and
the judgment of constraint relationships between size, swidth, and dwidth has been added.
Tao Ding (1):
Fix transfer size register decrement in pl080
hw/dma/pl080.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
base-commit: 8e711856d7639cbffa51405f2cc2366e3d9e3a23
Signature · 1 line
2.43.0
PATCH v2 1/1 Fix transfer size register decrement in pl080
Configure swidth to 1 byte, width to 4 bytes, and transfer size to 4.
Configuration
../configure --target-list=arm-softmmu --enable-debug
Reproducer
./qemu-system-arm -M versatilepb -m 128M -nographic -S \
-device loader,addr=0x00000000,data=0x44332211,data-len=4 \
-device loader,addr=0x00001000,data=0x00000000,data-len=4 \
-device loader,addr=0x10130030,data=0x00000001,data-len=4 \
-device loader,addr=0x10130100,data=0x00000000,data-len=4 \
-device loader,addr=0x10130104,data=0x00001000,data-len=4 \
-device loader,addr=0x10130108,data=0x00000000,data-len=4 \
-device loader,addr=0x1013010C,data=0x9e47f004,data-len=4 \
-device loader,addr=0x10130110,data=0x0000c001,data-len=4 Qemu monitor
(qemu) xp /1wx 0x00001000
00001000: 0x00002211The result correctly after fixed
(qemu) xp /1wx 0x00001000
00001000: 0x44332211--- hw/dma/pl080.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
hw/dma/pl080.c +11 -6
@@ -179,23 +179,28 @@ again: c, extract32(ch->ctrl, 21, 3));continue ; } - -for (n =0 ; n < dwidth; n+= swidth) { +if ((size * swidth) % dwidth) { +qemu_log_mask (LOG_GUEST_ERROR , +"pl080: channel %d: transfer size mismatch: size=%d swidth=%d dwidth=%d\n" , + c, size, swidth, dwidth); +continue ; + } + xsize =MAX (swidth, dwidth); +for (n =0 ; n < xsize; n += swidth) {address_space_read (&s->downstream_as, ch->src,MEMTXATTRS_UNSPECIFIED , buff + n, swidth);if (ch->ctrl &PL080_CCTRL_SI ) ch->src += swidth; } - xsize = (dwidth < swidth) ? swidth : dwidth;/* ??? This may pad the value incorrectly for dwidth < 32. */ for (n =0 ; n < xsize; n += dwidth) { -address_space_write (&s->downstream_as, ch->dest + n, +address_space_write (&s->downstream_as, ch->dest,MEMTXATTRS_UNSPECIFIED , buff + n, dwidth);if (ch->ctrl &PL080_CCTRL_DI ) - ch->dest += swidth; + ch->dest += dwidth; } - size--; + size -= xsize / swidth; ch->ctrl = (ch->ctrl &0xfffff000 ) | size;if (size ==0 ) {/* Transfer complete. */
Signature · 1 line
2.43.0
Re: [PATCH v2 1/1] Fix transfer size register decrement in pl080
Quoted 20 lines · Tao Ding
Configure swidth to 1 byte, width to 4 bytes, and transfer size to 4.
Configuration
../configure --target-list=arm-softmmu --enable-debug Reproducer ./qemu-system-arm -M versatilepb -m 128M -nographic -S \ -device loader,addr=0x00000000,data=0x44332211,data-len=4 \ -device loader,addr=0x00001000,data=0x00000000,data-len=4 \ -device loader,addr=0x10130030,data=0x00000001,data-len=4 \ -device loader,addr=0x10130100,data=0x00000000,data-len=4 \ -device loader,addr=0x10130104,data=0x00001000,data-len=4 \ -device loader,addr=0x10130108,data=0x00000000,data-len=4 \ -device loader,addr=0x1013010C,data=0x9e47f004,data-len=4 \ -device loader,addr=0x10130110,data=0x0000c001,data-len=4Qemu monitor
(qemu) xp /1wx 0x00001000 00001000: 0x00002211
Quoted 8 lines
The result correctly after fixed
(qemu) xp /1wx 0x00001000 00001000: 0x44332211Suggested-by Peter Maydell <[email protected]>Signed-off-by Tao Ding <[email protected]>--- hw/dma/pl080.c | 17 +++++++++++------
Thanks for this patch; I've applied it to target-arm.next (with an expansion to the commit message to describe the bugs it is fixing).
-- PMM