Re: [SeaBIOS] [PATCH 6/6] Use timer_check() instead of using floppy_motor_counter in BDA for the timeout check in floppy_wait_irq()

2018-02-04 Thread Nikolay Nikolov
This is the same as patch 7 from the previous series, except it also
removes the line "SET_BDA(floppy_motor_counter, FLOPPY_MOTOR_TICKS);"
from floppy_enable_controller().

Nikolay

On Sun, 2018-02-04 at 17:27 +0200, Nikolay Nikolov wrote:
> The problem with using floppy_motor_counter was that, after it
> reaches 0,
> it immediately stops the floppy motors, which is not what is supposed
> to
> happen on real hardware. Instead, after a timeout (like in the end of
> every floppy operation, regardless of the result - success, timeout
> or
> error), the floppy motors must be kept spinning for additional 2
> seconds
> (the FLOPPY_MOTOR_TICKS). So, now the floppy_motor_counter is
> initialized
> to 255 (the max value) in the beginning of the floppy operation (in
> floppy_turn_on_motor()). For IRQ timeouts, a different timeout is
> used,
> specified by the new FLOPPY_IRQ_TIMEOUT constant (currently set to 5
> seconds - a fairly conservative value, but should work reliably on
> most
> floppies).
> 
> After the floppy operation, floppy_turn_off_motor_delayed() resets
> the
> floppy_motor_counter to 2 seconds (FLOPPY_MOTOR_TICKS).
> 
> This is also consistent with what other PC BIOSes do.
> 
> Signed-off-by: Nikolay Nikolov 
> ---
>  src/hw/floppy.c | 9 +
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/src/hw/floppy.c b/src/hw/floppy.c
> index 77dbade..3012b3a 100644
> --- a/src/hw/floppy.c
> +++ b/src/hw/floppy.c
> @@ -34,6 +34,7 @@
>  #define FLOPPY_GAPLEN 0x1B
>  #define FLOPPY_FORMAT_GAPLEN 0x6c
>  #define FLOPPY_PIO_TIMEOUT 1000
> +#define FLOPPY_IRQ_TIMEOUT 5000
>  
>  #define FLOPPY_DOR_MOTOR_D 0x80 // Set to turn drive 3's motor
> ON
>  #define FLOPPY_DOR_MOTOR_C 0x40 // Set to turn drive 2's motor
> ON
> @@ -221,8 +222,9 @@ floppy_wait_irq(void)
>  {
>  u8 frs = GET_BDA(floppy_recalibration_status);
>  SET_BDA(floppy_recalibration_status, frs & ~FRS_IRQ);
> +u32 end = timer_calc(FLOPPY_IRQ_TIMEOUT);
>  for (;;) {
> -if (!GET_BDA(floppy_motor_counter)) {
> +if (timer_check(end)) {
>  warn_timeout();
>  floppy_disable_controller();
>  return DISK_RET_ETIMEOUT;
> @@ -324,7 +326,6 @@ static int
>  floppy_enable_controller(void)
>  {
>  dprintf(2, "Floppy_enable_controller\n");
> -SET_BDA(floppy_motor_counter, FLOPPY_MOTOR_TICKS);
>  // Clear the reset bit (enter reset state), but set 'enable IRQ
> and DMA'
>  floppy_dor_mask(FLOPPY_DOR_RESET, FLOPPY_DOR_IRQ);
>  // Set the reset bit (normal operation) and keep 'enable IRQ and
> DMA' on
> @@ -348,8 +349,8 @@ floppy_drive_pio(u8 floppyid, int command, u8
> *param)
>  return ret;
>  }
>  
> -// reset the disk motor timeout value of INT 08
> -SET_BDA(floppy_motor_counter, FLOPPY_MOTOR_TICKS);
> +// set the disk motor timeout value of INT 08 to the highest
> value
> +SET_BDA(floppy_motor_counter, 255);
>  
>  // Turn on motor of selected drive, DMA & int enabled, normal
> operation
>  floppy_dor_write((floppyid ? FLOPPY_DOR_MOTOR_B :
> FLOPPY_DOR_MOTOR_A) | FLOPPY_DOR_IRQ | FLOPPY_DOR_RESET | floppyid);

___
SeaBIOS mailing list
SeaBIOS@seabios.org
https://mail.coreboot.org/mailman/listinfo/seabios


[SeaBIOS] [PATCH 6/6] Use timer_check() instead of using floppy_motor_counter in BDA for the timeout check in floppy_wait_irq()

2018-02-04 Thread Nikolay Nikolov
The problem with using floppy_motor_counter was that, after it reaches 0,
it immediately stops the floppy motors, which is not what is supposed to
happen on real hardware. Instead, after a timeout (like in the end of
every floppy operation, regardless of the result - success, timeout or
error), the floppy motors must be kept spinning for additional 2 seconds
(the FLOPPY_MOTOR_TICKS). So, now the floppy_motor_counter is initialized
to 255 (the max value) in the beginning of the floppy operation (in
floppy_turn_on_motor()). For IRQ timeouts, a different timeout is used,
specified by the new FLOPPY_IRQ_TIMEOUT constant (currently set to 5
seconds - a fairly conservative value, but should work reliably on most
floppies).

After the floppy operation, floppy_turn_off_motor_delayed() resets the
floppy_motor_counter to 2 seconds (FLOPPY_MOTOR_TICKS).

This is also consistent with what other PC BIOSes do.

Signed-off-by: Nikolay Nikolov 
---
 src/hw/floppy.c | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/hw/floppy.c b/src/hw/floppy.c
index 77dbade..3012b3a 100644
--- a/src/hw/floppy.c
+++ b/src/hw/floppy.c
@@ -34,6 +34,7 @@
 #define FLOPPY_GAPLEN 0x1B
 #define FLOPPY_FORMAT_GAPLEN 0x6c
 #define FLOPPY_PIO_TIMEOUT 1000
+#define FLOPPY_IRQ_TIMEOUT 5000
 
 #define FLOPPY_DOR_MOTOR_D 0x80 // Set to turn drive 3's motor ON
 #define FLOPPY_DOR_MOTOR_C 0x40 // Set to turn drive 2's motor ON
@@ -221,8 +222,9 @@ floppy_wait_irq(void)
 {
 u8 frs = GET_BDA(floppy_recalibration_status);
 SET_BDA(floppy_recalibration_status, frs & ~FRS_IRQ);
+u32 end = timer_calc(FLOPPY_IRQ_TIMEOUT);
 for (;;) {
-if (!GET_BDA(floppy_motor_counter)) {
+if (timer_check(end)) {
 warn_timeout();
 floppy_disable_controller();
 return DISK_RET_ETIMEOUT;
@@ -324,7 +326,6 @@ static int
 floppy_enable_controller(void)
 {
 dprintf(2, "Floppy_enable_controller\n");
-SET_BDA(floppy_motor_counter, FLOPPY_MOTOR_TICKS);
 // Clear the reset bit (enter reset state), but set 'enable IRQ and DMA'
 floppy_dor_mask(FLOPPY_DOR_RESET, FLOPPY_DOR_IRQ);
 // Set the reset bit (normal operation) and keep 'enable IRQ and DMA' on
@@ -348,8 +349,8 @@ floppy_drive_pio(u8 floppyid, int command, u8 *param)
 return ret;
 }
 
-// reset the disk motor timeout value of INT 08
-SET_BDA(floppy_motor_counter, FLOPPY_MOTOR_TICKS);
+// set the disk motor timeout value of INT 08 to the highest value
+SET_BDA(floppy_motor_counter, 255);
 
 // Turn on motor of selected drive, DMA & int enabled, normal operation
 floppy_dor_write((floppyid ? FLOPPY_DOR_MOTOR_B : FLOPPY_DOR_MOTOR_A) | 
FLOPPY_DOR_IRQ | FLOPPY_DOR_RESET | floppyid);
-- 
2.14.3


___
SeaBIOS mailing list
SeaBIOS@seabios.org
https://mail.coreboot.org/mailman/listinfo/seabios


[SeaBIOS] [PATCH 6/6] Use timer_check() instead of using floppy_motor_counter in BDA for the timeout check in floppy_wait_irq()

2018-02-03 Thread Nikolay Nikolov
The problem with using floppy_motor_counter was that, after it reaches 0,
it immediately stops the floppy motors, which is not what is supposed to
happen on real hardware. Instead, after a timeout (like in the end of
every floppy operation, regardless of the result - success, timeout or
error), the floppy motors must be kept spinning for additional 2 seconds
(the FLOPPY_MOTOR_TICKS). So, now the floppy_motor_counter is initialized
to 255 (the max value) in the beginning of the floppy operation (in
floppy_turn_on_motor()). For IRQ timeouts, a different timeout is used,
specified by the new FLOPPY_IRQ_TIMEOUT constant (currently set to 5
seconds - a fairly conservative value, but should work reliably on most
floppies).

After the floppy operation, floppy_turn_off_motor_delayed() resets the
floppy_motor_counter to 2 seconds (FLOPPY_MOTOR_TICKS).

This is also consistent with what other PC BIOSes do.

Signed-off-by: Nikolay Nikolov 
---
 src/hw/floppy.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/hw/floppy.c b/src/hw/floppy.c
index acaff3f..6714402 100644
--- a/src/hw/floppy.c
+++ b/src/hw/floppy.c
@@ -34,6 +34,7 @@
 #define FLOPPY_GAPLEN 0x1B
 #define FLOPPY_FORMAT_GAPLEN 0x6c
 #define FLOPPY_PIO_TIMEOUT 1000
+#define FLOPPY_IRQ_TIMEOUT 5000
 
 #define FLOPPY_DOR_MOTOR_D 0x80 // Set to turn drive 3's motor ON
 #define FLOPPY_DOR_MOTOR_C 0x40 // Set to turn drive 2's motor ON
@@ -221,8 +222,9 @@ floppy_wait_irq(void)
 {
 u8 frs = GET_BDA(floppy_recalibration_status);
 SET_BDA(floppy_recalibration_status, frs & ~FRS_IRQ);
+u32 end = timer_calc(FLOPPY_IRQ_TIMEOUT);
 for (;;) {
-if (!GET_BDA(floppy_motor_counter)) {
+if (timer_check(end)) {
 warn_timeout();
 floppy_disable_controller();
 return DISK_RET_ETIMEOUT;
@@ -340,8 +342,8 @@ floppy_enable_controller(void)
 static void
 floppy_turn_on_motor(u8 floppyid)
 {
-// reset the disk motor timeout value of INT 08
-SET_BDA(floppy_motor_counter, FLOPPY_MOTOR_TICKS);
+// set the disk motor timeout value of INT 08 to the highest value
+SET_BDA(floppy_motor_counter, 255);
 
 // Turn on motor of selected drive, DMA & int enabled, normal operation
 floppy_dor_write((floppyid ? FLOPPY_DOR_MOTOR_B : FLOPPY_DOR_MOTOR_A) | 
FLOPPY_DOR_IRQ | FLOPPY_DOR_RESET | floppyid);
-- 
2.14.3


___
SeaBIOS mailing list
SeaBIOS@seabios.org
https://mail.coreboot.org/mailman/listinfo/seabios