Commit ea185bbda732dae6b6a5a44699f90c83e21f1494

Authored by bellard
1 parent 83acc96b

use bdrv_media_changed()


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2122 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 14 additions and 24 deletions
hw/fdc.c
@@ -66,7 +66,6 @@ typedef enum fdrive_type_t { @@ -66,7 +66,6 @@ typedef enum fdrive_type_t {
66 66
67 typedef enum fdrive_flags_t { 67 typedef enum fdrive_flags_t {
68 FDRIVE_MOTOR_ON = 0x01, /* motor on/off */ 68 FDRIVE_MOTOR_ON = 0x01, /* motor on/off */
69 - FDRIVE_REVALIDATE = 0x02, /* Revalidated */  
70 } fdrive_flags_t; 69 } fdrive_flags_t;
71 70
72 typedef enum fdisk_flags_t { 71 typedef enum fdisk_flags_t {
@@ -236,7 +235,6 @@ static void fd_revalidate (fdrive_t *drv) @@ -236,7 +235,6 @@ static void fd_revalidate (fdrive_t *drv)
236 int nb_heads, max_track, last_sect, ro; 235 int nb_heads, max_track, last_sect, ro;
237 236
238 FLOPPY_DPRINTF("revalidate\n"); 237 FLOPPY_DPRINTF("revalidate\n");
239 - drv->drflags &= ~FDRIVE_REVALIDATE;  
240 if (drv->bs != NULL && bdrv_is_inserted(drv->bs)) { 238 if (drv->bs != NULL && bdrv_is_inserted(drv->bs)) {
241 ro = bdrv_is_read_only(drv->bs); 239 ro = bdrv_is_read_only(drv->bs);
242 bdrv_get_geometry_hint(drv->bs, &nb_heads, &max_track, &last_sect); 240 bdrv_get_geometry_hint(drv->bs, &nb_heads, &max_track, &last_sect);
@@ -291,7 +289,6 @@ static void fd_revalidate (fdrive_t *drv) @@ -291,7 +289,6 @@ static void fd_revalidate (fdrive_t *drv)
291 drv->max_track = 0; 289 drv->max_track = 0;
292 drv->flags &= ~FDISK_DBL_SIDES; 290 drv->flags &= ~FDISK_DBL_SIDES;
293 } 291 }
294 - drv->drflags |= FDRIVE_REVALIDATE;  
295 } 292 }
296 293
297 /* Motor control */ 294 /* Motor control */
@@ -488,19 +485,6 @@ static CPUWriteMemoryFunc *fdctrl_mem_write[3] = { @@ -488,19 +485,6 @@ static CPUWriteMemoryFunc *fdctrl_mem_write[3] = {
488 fdctrl_write_mem, 485 fdctrl_write_mem,
489 }; 486 };
490 487
491 -static void fd_change_cb (void *opaque)  
492 -{  
493 - fdrive_t *drv = opaque;  
494 -  
495 - FLOPPY_DPRINTF("disk change\n");  
496 - fd_revalidate(drv);  
497 -#if 0  
498 - fd_recalibrate(drv);  
499 - fdctrl_reset_fifo(drv->fdctrl);  
500 - fdctrl_raise_irq(drv->fdctrl, 0x20);  
501 -#endif  
502 -}  
503 -  
504 fdctrl_t *fdctrl_init (int irq_lvl, int dma_chann, int mem_mapped, 488 fdctrl_t *fdctrl_init (int irq_lvl, int dma_chann, int mem_mapped,
505 uint32_t io_base, 489 uint32_t io_base,
506 BlockDriverState **fds) 490 BlockDriverState **fds)
@@ -529,10 +513,6 @@ fdctrl_t *fdctrl_init (int irq_lvl, int dma_chann, int mem_mapped, @@ -529,10 +513,6 @@ fdctrl_t *fdctrl_init (int irq_lvl, int dma_chann, int mem_mapped,
529 } 513 }
530 for (i = 0; i < 2; i++) { 514 for (i = 0; i < 2; i++) {
531 fd_init(&fdctrl->drives[i], fds[i]); 515 fd_init(&fdctrl->drives[i], fds[i]);
532 - if (fds[i]) {  
533 - bdrv_set_change_cb(fds[i],  
534 - &fd_change_cb, &fdctrl->drives[i]);  
535 - }  
536 } 516 }
537 fdctrl_reset(fdctrl, 0); 517 fdctrl_reset(fdctrl, 0);
538 fdctrl->state = FD_CTRL_ACTIVE; 518 fdctrl->state = FD_CTRL_ACTIVE;
@@ -760,18 +740,28 @@ static void fdctrl_write_rate (fdctrl_t *fdctrl, uint32_t value) @@ -760,18 +740,28 @@ static void fdctrl_write_rate (fdctrl_t *fdctrl, uint32_t value)
760 // fdctrl.precomp = (value >> 2) & 0x07; 740 // fdctrl.precomp = (value >> 2) & 0x07;
761 } 741 }
762 742
  743 +static int fdctrl_media_changed(fdrive_t *drv)
  744 +{
  745 + int ret;
  746 + if (!drv->bs)
  747 + return 0;
  748 + ret = bdrv_media_changed(drv->bs);
  749 + if (ret) {
  750 + fd_revalidate(drv);
  751 + }
  752 + return ret;
  753 +}
  754 +
763 /* Digital input register : 0x07 (read-only) */ 755 /* Digital input register : 0x07 (read-only) */
764 static uint32_t fdctrl_read_dir (fdctrl_t *fdctrl) 756 static uint32_t fdctrl_read_dir (fdctrl_t *fdctrl)
765 { 757 {
766 uint32_t retval = 0; 758 uint32_t retval = 0;
767 759
768 - if (drv0(fdctrl)->drflags & FDRIVE_REVALIDATE ||  
769 - drv1(fdctrl)->drflags & FDRIVE_REVALIDATE) 760 + if (fdctrl_media_changed(drv0(fdctrl)) ||
  761 + fdctrl_media_changed(drv1(fdctrl)))
770 retval |= 0x80; 762 retval |= 0x80;
771 if (retval != 0) 763 if (retval != 0)
772 FLOPPY_DPRINTF("Floppy digital input register: 0x%02x\n", retval); 764 FLOPPY_DPRINTF("Floppy digital input register: 0x%02x\n", retval);
773 - drv0(fdctrl)->drflags &= ~FDRIVE_REVALIDATE;  
774 - drv1(fdctrl)->drflags &= ~FDRIVE_REVALIDATE;  
775 765
776 return retval; 766 return retval;
777 } 767 }