hw/dma/i8257: 3 trivial fixes
cover hw/dma/i8257: 3 trivial fixes
Trivial fixes related to the 8257 DMAC integrated in the PIIX southbridge, helping with sound on Malta board.
Philippe Mathieu-Daudé (3):
hw/dma/i8257: Read the mask from the RWAMB port hw/dma/i8257: Zero the reserved bits of the mask register hw/dma/i8257: Honor the command register group-disable bit
hw/dma/i8257.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
Signature · 1 line
2.55.0
PATCH 1/3 hw/dma/i8257: Read the mask from the RWAMB port
The 82C37-compatible register layout, as documented in the PIIX3 datasheet, has the write-only request register at I/O 0x09 and the read/write-all-mask register at 0x0F.
Move the mask read to the latter.
--- hw/dma/i8257.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/dma/i8257.c +1 -1
@@ -281,7 +281,7 @@ static uint64_t i8257_read_cont(void *opaque, hwaddr nport, unsigned size) val = d->status; d->status &=0xf0 ;break ; -case 0x01 :/* mask */ +case 0x07 :/* read all mask bits (RWAMB) */ val = d->mask;break ;default :
Signature · 1 line
2.55.0
Re: [PATCH 1/3] hw/dma/i8257: Read the mask from the RWAMB port
Quoted 16 lines · Philippe Mathieu-Daudé
The 82C37-compatible register layout, as documented in the PIIX3 datasheet, has the write-only request register at I/O
0x09and the read/write-all-mask register at0x0F.
Move the mask read to the latter.Fixes 9eb153f18f6 ("dma clean up - added missing read accesses")Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/dma/i8257.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/dma/i8257.c +0
-0
hw/dma/i8257.c static uint64_t i8257_read_cont(void *opaque, hwaddr nport, unsigned size) · line 287
Quoted 8 lines
hw/dma/i8257.c +1
-1@@ -281,7 +281,7 @@ static uint64_t i8257_read_cont(void *opaque, hwaddr nport, unsigned size) val = d->status; d->status &=0xf0 ;break ; -case 0x01 :/* mask */ +case 0x07 :/* read all mask bits (RWAMB) */ val = d->mask;break ;default :
Indeed, looks like this has been wrong for a very long time: I presume there is no regression on x86 here?
ATB,
Mark.
PATCH 2/3 hw/dma/i8257: Zero the reserved bits of the mask register
In reply to Philippe Mathieu-DaudéThe 82C37-compatible read/write-all-mask register has four channel-mask bits; the upper nibble is reserved and reads as zero (PIIX3 datasheet, section 2.5.1.5).
The model reset it to all ones and exposed the reserved nibble. Keep only bits [3:0] in reset, write and read paths.
--- hw/dma/i8257.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
hw/dma/i8257.c +4 -3
@@ -242,7 +242,8 @@ static void i8257_write_cont(void *opaque, hwaddr nport, uint64_t data,case 0x05 :/* reset */ d->flip_flop =0 ; - d->mask = ~0 ; +/* bits [3:0] mask the four channels; bits [7:4] are reserved 0 */ + d->mask =0x0f ; d->status =0 ; d->command =0 ;break ;
@@ -253,7 +254,7 @@ static void i8257_write_cont(void *opaque, hwaddr nport, uint64_t data,break ;case 0x07 :/* write mask for all channels */ - d->mask = data; + d->mask = data &0x0f ;i8257_dma_run (d);break ;
@@ -282,7 +283,7 @@ static uint64_t i8257_read_cont(void *opaque, hwaddr nport, unsigned size) d->status &=0xf0 ;break ;case 0x07 :/* read all mask bits (RWAMB) */ - val = d->mask; + val = d->mask &0x0f ;break ;default : val =0 ;
Signature · 1 line
2.55.0
Re: [PATCH 2/3] hw/dma/i8257: Zero the reserved bits of the mask register
Quoted 8 lines · Philippe Mathieu-Daudé
The 82C37-compatible read/write-all-mask register has four channel-mask bits; the upper nibble is reserved and reads as zero (PIIX3 datasheet, section 2.5.1.5).
The model reset it to all ones and exposed the reserved nibble. Keep only bits [3:0] in reset, write and read paths.Fixes 27503323968 ("Soundblaster 16 support")Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Out of interest, does this solve a bug in that a guest OS functions incorrectly without the top nibble being all zero? Or is it just bring the emulated device in line with the behaviour described in the datasheet?
Quoted 28 lines
--- hw/dma/i8257.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)hw/dma/i8257.c +3
-2@@ -242,7 +242,8 @@ static void i8257_write_cont(void *opaque, hwaddr nport, uint64_t data,case 0x05 :/* reset */ d->flip_flop =0 ; - d->mask = ~0 ; +/* bits [3:0] mask the four channels; bits [7:4] are reserved 0 */ + d->mask =0x0f ; d->status =0 ; d->command =0 ;break ;@@ -253,7 +254,7 @@ static void i8257_write_cont(void *opaque, hwaddr nport, uint64_t data,break ;case 0x07 :/* write mask for all channels */ - d->mask = data; + d->mask = data &0x0f ;i8257_dma_run (d);break ;
hw/dma/i8257.c static uint64_t i8257_read_cont(void *opaque, hwaddr nport, unsigned size) · line 286
Quoted 5 lines
hw/dma/i8257.c +1
-1@@ -282,7 +283,7 @@ static uint64_t i8257_read_cont(void *opaque, hwaddr nport, unsigned size) d->status &=0xf0 ;break ;case 0x07 :/* read all mask bits (RWAMB) */ - val = d->mask; + val = d->mask &0x0f ;
Is this one actually needed if the above hunks guarantee that all writes only affect bits 0-3?
hw/dma/i8257.c static uint64_t i8257_read_cont(void *opaque, hwaddr nport, unsigned size) · line 289
Quoted 3 lines
hw/dma/i8257.c +0
-0break ;default : val =0 ;
ATB,
Mark.
PATCH 3/3 hw/dma/i8257: Honor the command register group-disable bit
In reply to Philippe Mathieu-DaudéCommand bit 2 of the 82C37-compatible DMA controller disables the channel group (PIIX3 datasheet, section 2.5.1.1). The model accepted but ignored it.
Gate servicing on that bit and re-run the engine after a command write so re-enabling resumes pending requests.
--- hw/dma/i8257.c | 7 +++++++ 1 file changed, 7 insertions(+)
hw/dma/i8257.c +7 -0
@@ -195,6 +195,8 @@ static void i8257_write_cont(void *opaque, hwaddr nport, uint64_t data,return ; } d->command = data; +/* A pending request may be serviced once the group is enabled. */ +i8257_dma_run (d);break ;case 0x01 :
@@ -355,6 +357,11 @@ static void i8257_dma_run(void *opaque)int ichan;int rearm =0 ; +/* PIIX3 DCOM bit 2 disables the channel group. */ +if (d->command &CMD_BLOCK_CONTROLLER ) { +return ; + } +if (d->running) { rearm =1 ; goto out;
Signature · 1 line
2.55.0
Re: [PATCH 3/3] hw/dma/i8257: Honor the command register group-disable bit
Quoted 26 lines · Philippe Mathieu-Daudé
Command bit 2 of the 82C37-compatible DMA controller disables the channel group (PIIX3 datasheet, section 2.5.1.1). The model accepted but ignored it.
Gate servicing on that bit and re-run the engine after a command write so re-enabling resumes pending requests.Fixes 27503323968 ("Soundblaster 16 support")Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/dma/i8257.c | 7 +++++++ 1 file changed, 7 insertions(+)hw/dma/i8257.c +2
-0@@ -195,6 +195,8 @@ static void i8257_write_cont(void *opaque, hwaddr nport, uint64_t data,return ; } d->command = data; +/* A pending request may be serviced once the group is enabled. */ +i8257_dma_run (d);break ;case 0x01 :
hw/dma/i8257.c static void i8257_dma_run(void *opaque) · line 364
Quoted 8 lines
hw/dma/i8257.c +5
-0@@ -355,6 +357,11 @@ static void i8257_dma_run(void *opaque)int ichan;int rearm =0 ; +/* PIIX3 DCOM bit 2 disables the channel group. */ +if (d->command &CMD_BLOCK_CONTROLLER ) { +return ; + } +
Minor nit: the comment specifically mentions PIIX3 however this seems to be the expected behaviour of the standard i8257 chip as per https://wiki.osdev.org/ISA_DMA#The_Other_Registers.
hw/dma/i8257.c static void i8257_dma_run(void *opaque) · line 367
Quoted 3 lines
hw/dma/i8257.c +0
-0if (d->running) { rearm =1 ; goto out;
Otherwise:
ATB,
Mark.