qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* Re: [Qemu-devel] enabling bus-master IDE driver
@ 2004-11-05 15:37 Juergen Keil
  2004-11-05 15:43 ` zitu
  2004-11-05 15:45 ` zitu
  0 siblings, 2 replies; 42+ messages in thread
From: Juergen Keil @ 2004-11-05 15:37 UTC (permalink / raw)
  To: qemu-devel



> Quoting zitu <zitu@free.fr>:
> > >
> > > Does that mean that the patch doesn't work?  Do I have to do something 
else
> > > to make dma work?
> >
> > I think this patch is almost complete for linux and solaris guests. Some
> > more work/init is needed inside XP/NT/2K. Anyone around with this
> > knowledge ?
> 
> answering to myself... :)
> 
> WIN_WRITEDMA_EXT & WIN_READDMA_EXT cases are not defined in hw/ide.c

Aha, and Windows uses these commands, on small HDDs <= 128GB ?


> I have no idea where to start to write a patch for these... :(
> 
> Until these and the atapi_dma are set/defined, no dma should work IMHO.
> And this seems not to be OS dependant.
> 
> Which means the linux figures I got were wrong ???

The *_EXT versions are apparently for HDDs with capacities >128GB, these
need 48-bit LBA addresses to access the HDD space over the 128GB mark.

I guess that Solaris/Linux uses the commands with the smaller 28-bit
LBA disk addresses for small disks with capacities <= 128GB.

An interesting experiment would be to setup a QEMU HDD image > 128GB,
then try Solaris x86/Linux with such a big disk and check if it still
works.  Probably not.

^ permalink raw reply	[flat|nested] 42+ messages in thread
* Re: [Qemu-devel] enabling bus-master IDE driver
@ 2004-11-26 10:48 Juergen Keil
  2004-11-28 20:09 ` Juergen Lock
  0 siblings, 1 reply; 42+ messages in thread
From: Juergen Keil @ 2004-11-26 10:48 UTC (permalink / raw)
  To: qemu-devel



> On Tue, Nov 23, 2004 at 04:03:39PM +0000, Norikatsu Shigemura wrote:
> > On Tue, 16 Nov 2004 20:41:35 +0100
> > Juergen Lock <qemu-l@jelal.kn-bremen.de> wrote:
> > > > > It now says "Current Transfer Mode: Multi-Word DMA Mode 2".
> > > > > I'm not real sure how I test to see if disk access is faster,
> > > > > or by how much, but this appears to be progress for XP.
> > > > Windows 2000 isn't that verbose - it simply prints "DMA mode".
> > > > Interesting that XP has enabled "Multi-Word DMA Mode 2".
> > > >...
> > > FreeBSD guests (at least 5.3-BETA1) say they use WDMA2, which i guess
> > > is the same:
> > 
> > 	Your patch works quite good.  I confirmed that it works on
> > 	Windows XP SP2 and FreeBSD 5.3-RELEASE as guest OSs, and
> > 	host's cpu loadavg reduced(MAX: 97% -> 30% on boot, etc..).
> > 
> > # http://people.FreeBSD.org/~nork/qemu/qemu05.png  but Japanese
> > 
> > 	May I commit your patch as ports/emulators/qemu/files/patch-hw::ide.c?
> > 
> Mmmh actually I was waiting for words from people in the know about
> this, like is WDMA2 really the best we're gonna get?  Since linux guests'
> DMA was reported to be faster without the patch...

FreeBSD identifies QEMU's pci-ide controller as an "Intel PIIX3" chipset,
and has built-in knowledge that the PIIX3 does not support UDMA modes.
WDMA2 is the fastest dma transfer rate that is supported by the PIIX3
(according to freebsd source, I didn't verify this but I guess it's correct).
So that's why freebsd is using WDMA2.

See function ata_intel_ident() in sys/dev/ata/ata-chipcet.c:

http://www.freebsd.org/cgi/cvsweb.cgi/src/sys/dev/ata/ata-chipset.c?rev=1.92&con
tent-type=text/x-cvsweb-markup



I don't think that you'll notice a difference in speed or performance inside
qemu between multiword dma and ultra dma modes.  qemu does not emulate the
ide hardware at such a low level that the dma transfer modes on the bus
matters.  The important thing is that the ide dma commands are used, so that
the hw/ide.c will move data to/from pc memory.  If a pio mode is used
the guest os' interrupt handler moves the data word-by-word to or from the
ide controller hardware, using emulated x86 instructions, and that is quite
expensive.

         -------------
         
Btw. FreeBSD 5.2.1 does not enable DMA on the QEMU-HDD, it uses PIO4 mode.

Trying to enable DMA with "atacontrol mode 0 WDMA2 BIOSPIO" crashes
the FreeBSD kernel (-> a FreeBSD kernel problem).

Problem: PCI busmastering is not enabled in the PCI command register.
It seems the BIOS is supposed to enable busmastering, but bochs bios
apparently doesn't enable pci-ide busmastering.  ata-pci.c function
ata_pci_attach() does not set ctrl->r_io1 which would be needed in
ata_pci_allocated() to allocate and enable DMA (ctrl->dmainit() is not
called).

As a workaround, always enable busmastering on qemu's pci-ide device.

Default to WDMA2 mode (the real Intel PIIX3 hardware which we
emulate does not support UDMA modes).

(The following patch needs to be applied on top of the previous version
of the pci-ide busmastering dma patch)

diff -ru /home/jk/src/qemu-cvs/hw/ide.c ./hw/ide.c
--- /home/jk/src/qemu-cvs/hw/ide.c      2004-11-18 22:23:13.000000000 +0100
+++ ./hw/ide.c  2004-11-21 11:26:56.143862000 +0100
@@ -430,7 +430,7 @@
         put_le16(p + 59, 0x100 | s->mult_sectors);
     put_le16(p + 60, s->nb_sectors);
     put_le16(p + 61, s->nb_sectors >> 16);
-    put_le16(p + 63, 0x07 /*| 0x4 << 8*/); /* Multiword DMA supported/selected 
*/
+    put_le16(p + 63, 0x07 | 0x4 << 8); /* Multiword DMA supported/selected */
     put_le16(p + 64, 0x03); /* PIO modes 3,4 supported */
     put_le16(p + 80, (1 << 1) | (1 << 2));
     put_le16(p + 82, (1 << 14));
@@ -439,7 +439,7 @@
     put_le16(p + 85, (1 << 14));
     put_le16(p + 86, 0);
     put_le16(p + 87, (1 << 14));
-    put_le16(p + 88, 0x3f | 0x20 << 8); /* UltraDMA modes supported/selected */
+    put_le16(p + 88, 0x3f /*| 0x20 << 8*/); /* UltraDMA modes 
supported/selected */
     put_le16(p + 93, 1 | (1 << 1) | (1 << 3) | (1 << 13) | (1 << 14));
 }
 
@@ -462,7 +462,7 @@
     put_le16(p + 48, 1); /* dword I/O (XXX: should not be set on CDROM) */
     put_le16(p + 49, 1 << 8 | 1 << 9); /* DMA and LBA supported */
     put_le16(p + 53, 7); /* words 64-70, 54-58, 88 valid */
-    put_le16(p + 63, 0x07 /*| 0x4 << 8*/); /* Multiword DMA supported/selected 
*/
+    put_le16(p + 63, 0x07 | 0x4 << 8); /* Multiword DMA supported/selected */
     put_le16(p + 64, 0x03); /* PIO modes 3,4 supported */
     put_le16(p + 65, 0xb4); /* minimum DMA multiword tx cycle time */
     put_le16(p + 66, 0xb4); /* recommended DMA multiword tx cycle time */
@@ -473,7 +473,7 @@
     put_le16(p + 72, 30); /* in ns */
 
     put_le16(p + 80, 0x1e); /* support up to ATA/ATAPI-4 */
-    put_le16(p + 88, 0x3f | 0x20 << 8); /* UltraDMA modes supported/selected */
+    put_le16(p + 88, 0x3f /*| 0x20 << 8*/); /* UltraDMA modes 
supported/selected */
 }
 
 static void ide_set_signature(IDEState *s)
@@ -2192,6 +2192,12 @@
     ide_init2(&d->ide_if[2], 16, hd_table[2], hd_table[3]);
 }
 
+
+// PCI 0x04: command(word), 0x06(word): status
+#define PCI_COMMAND_IOACCESS                0x0001
+#define PCI_COMMAND_MEMACCESS               0x0002
+#define PCI_COMMAND_BUSMASTER               0x0004
+
 /* hd_table must contain 4 block drivers */
 /* NOTE: for the PIIX3, the IRQs and IOports are hardcoded */
 void pci_piix3_ide_init(PCIBus *bus, BlockDriverState **hd_table)
@@ -2209,6 +2215,8 @@
     pci_conf[0x01] = 0x80;
     pci_conf[0x02] = 0x10;
     pci_conf[0x03] = 0x70;
+    pci_conf[0x04] = PCI_COMMAND_IOACCESS | PCI_COMMAND_MEMACCESS \
+       | PCI_COMMAND_BUSMASTER;
     pci_conf[0x09] = 0x8a; // programming interface = PCI_IDE bus master is sup
ported
     pci_conf[0x0a] = 0x01; // class_sub = PCI_IDE
     pci_conf[0x0b] = 0x01; // class_base = PCI_mass_storage

^ permalink raw reply	[flat|nested] 42+ messages in thread
* Re: [Qemu-devel] enabling bus-master IDE driver
@ 2004-11-12 19:07 Juergen Keil
  2004-11-16 19:41 ` Juergen Lock
  0 siblings, 1 reply; 42+ messages in thread
From: Juergen Keil @ 2004-11-12 19:07 UTC (permalink / raw)
  To: qemu-devel



> > +    put_le16(p + 63, 0x07 /*| 0x4 << 8*/); /* Multiword DMA 
supported/selected */
...
> > +    put_le16(p + 88, 0x3f | 0x20 << 8); /* UltraDMA modes 
supported/selected */

> This is interesting..
> 
> I carefully applied these changes to my ide.c and retried:
> 
> Host: Linux 2.6 (Fedora Core 2)
> Guest: XP corp.
> It now says "Current Transfer Mode: Multi-Word DMA Mode 2".
> I'm not real sure how I test to see if disk access is faster,
> or by how much, but this appears to be progress for XP.

Windows 2000 isn't that verbose - it simply prints "DMA mode".

Interesting that XP has enabled "Multi-Word DMA Mode 2".

Setting word 63 to a value of 0x07 should announce the support
for multiword dma modes 0..2.  And no multiword dma mode is
selected.  The commented out "0x4 << 8" part would enable 
multiword dma mode 2.  I've commented it out becuase qemu's hdd
is supposed to support ultra dma modes.


I did change the value for word 88 - the ultra dma modes.
CVS HEAD sets it to ultra dma modes 0..4 supported, and ultra dma
mode 5 selected.  I'm not sure, but it sounds wrong to select
a dma mode that is not supported by the drive.

CVS HEAD:   put_le16(p + 88, 0x1f | (1 << 13));


I've changed it to ultra dma modes 0..5 supported, and ultra dma
mode 5 selected:

            put_le16(p + 88, 0x3f | 0x20 << 8);


Maybe windows checks the ata/atapi version field in word 80?
qemu's hdd only supports ata/atapi-1 and ata/atapi-2.  Ultra dma
might not exist in the ata/atapi-2 standard.

^ permalink raw reply	[flat|nested] 42+ messages in thread
* Re: [Qemu-devel] enabling bus-master IDE driver
@ 2004-11-12 14:27 Juergen Keil
  2004-11-12 18:02 ` Jason Brittain
  0 siblings, 1 reply; 42+ messages in thread
From: Juergen Keil @ 2004-11-12 14:27 UTC (permalink / raw)
  To: qemu-devel



> I just pulled the latest source from CVS (today's), and tried
> looking at DMA again.
> 
> Host: Linux 2.6 (Fedora Core 2)
> Guest: XP corp.
> It still says the primary IDE channel is in PIO mode, and
> doesn't seem any faster.

I guess Windows 2000/XP is confused about the fact that a qemu hdd now
supports ultra dma modes, but no multiword dma modes.  Maybe the windows
ata driver gives up on dma as soon as it notices that the hdd drive does
not support any multiword dma modes?

Try to add a "put_le16(p + 63, 0x07);" to hw/ide.c ide_identify() and
ide_atapi_identify().  This announces support for multiword dma modes 0-2.
This change appears to enable DMA on Win 2000.


I'm currently using the following changes (note: this diff is against the
previous version of ide.c, qemu-cvs already contains a few of these changes),
and seem to get DMA with Win ME, Win 2000 and Solaris x86.


Index: hw/ide.c
===================================================================
RCS file: /cvsroot/qemu/qemu/hw/ide.c,v
retrieving revision 1.28
diff -u -B -r1.28 ide.c
--- hw/ide.c    9 Oct 2004 20:27:55 -0000       1.28
+++ hw/ide.c    12 Nov 2004 14:15:25 -0000
@@ -416,10 +416,10 @@
     put_le16(p + 47, 0x8000 | MAX_MULT_SECTORS);
 #endif
     put_le16(p + 48, 1); /* dword I/O */
-    put_le16(p + 49, 1 << 9); /* LBA supported, no DMA */
+    put_le16(p + 49, 1 << 8 | 1 << 9); /* DMA and LBA supported */
     put_le16(p + 51, 0x200); /* PIO transfer cycle */
     put_le16(p + 52, 0x200); /* DMA transfer cycle */
-    put_le16(p + 53, 1); /* words 54-58 are valid */
+    put_le16(p + 53, 1 | 1 << 2); /* words 54-58,88 are valid */
     put_le16(p + 54, s->cylinders);
     put_le16(p + 55, s->heads);
     put_le16(p + 56, s->sectors);
@@ -430,6 +430,8 @@
         put_le16(p + 59, 0x100 | s->mult_sectors);
     put_le16(p + 60, s->nb_sectors);
     put_le16(p + 61, s->nb_sectors >> 16);
+    put_le16(p + 63, 0x07 /*| 0x4 << 8*/); /* Multiword DMA supported/selected 
*/
+    put_le16(p + 64, 0x3f); /* PIO modes supported */
     put_le16(p + 80, (1 << 1) | (1 << 2));
     put_le16(p + 82, (1 << 14));
     put_le16(p + 83, (1 << 14));
@@ -437,6 +439,8 @@
     put_le16(p + 85, (1 << 14));
     put_le16(p + 86, 0);
     put_le16(p + 87, (1 << 14));
+    put_le16(p + 88, 0x3f | 0x20 << 8); /* UltraDMA modes supported/selected */
+    put_le16(p + 93, 1 | (1 << 1) | (1 << 3) | (1 << 13) | (1 << 14));
 }
 
 static void ide_atapi_identify(IDEState *s)
@@ -456,10 +460,10 @@
     padstr((uint8_t *)(p + 23), QEMU_VERSION, 8); /* firmware version */
     padstr((uint8_t *)(p + 27), "QEMU CD-ROM", 40); /* model */
     put_le16(p + 48, 1); /* dword I/O (XXX: should not be set on CDROM) */
-    put_le16(p + 49, 1 << 9); /* LBA supported, no DMA */
-    put_le16(p + 53, 3); /* words 64-70, 54-58 valid */
-    put_le16(p + 63, 0x103); /* DMA modes XXX: may be incorrect */
-    put_le16(p + 64, 1); /* PIO modes */
+    put_le16(p + 49, 1 << 8 | 1 << 9); /* DMA and LBA supported */
+    put_le16(p + 53, 7); /* words 64-70, 54-58, 88 valid */
+    put_le16(p + 63, 0x07 /*| 0x4 << 8*/); /* Multiword DMA supported/selected 
*/
+    put_le16(p + 64, 0x3f); /* PIO modes supported */
     put_le16(p + 65, 0xb4); /* minimum DMA multiword tx cycle time */
     put_le16(p + 66, 0xb4); /* recommended DMA multiword tx cycle time */
     put_le16(p + 67, 0x12c); /* minimum PIO cycle time without flow control */
@@ -469,6 +473,7 @@
     put_le16(p + 72, 30); /* in ns */
 
     put_le16(p + 80, 0x1e); /* support up to ATA/ATAPI-4 */
+    put_le16(p + 88, 0x3f | 0x20 << 8); /* UltraDMA modes supported/selected */
 }
 
 static void ide_set_signature(IDEState *s)
@@ -498,6 +503,10 @@
 static inline void ide_set_irq(IDEState *s)
 {
     if (!(s->cmd & IDE_CMD_DISABLE_IRQ)) {
+       BMDMAState *bm = s->bmdma;
+       if(bm)
+           bm->status |= BM_STATUS_INT;
+
 #ifdef TARGET_PPC
         if (s->openpic) 
             openpic_set_irq(s->openpic, s->irq, 1);
@@ -1560,7 +1569,7 @@
             case 0x82: /* write cache disable */
             case 0xaa: /* read look-ahead enable */
             case 0x55: /* read look-ahead disable */
-                s->status = READY_STAT;
+                s->status = READY_STAT | SEEK_STAT;
                 ide_set_irq(s);
                 break;
             default:
@@ -2174,6 +2183,7 @@
     pci_conf[0x01] = 0x80;
     pci_conf[0x02] = 0x10;
     pci_conf[0x03] = 0x70;
+    pci_conf[0x09] = 0x8a; // programming interface = PCI_IDE bus master is 
supported
     pci_conf[0x0a] = 0x01; // class_sub = PCI_IDE
     pci_conf[0x0b] = 0x01; // class_base = PCI_mass_storage
     pci_conf[0x0e] = 0x00; // header_type

^ permalink raw reply	[flat|nested] 42+ messages in thread
* [Qemu-devel] enabling bus-master IDE driver
@ 2004-11-04 20:35 Simon Frew
  2004-11-05 13:32 ` zitu
  0 siblings, 1 reply; 42+ messages in thread
From: Simon Frew @ 2004-11-04 20:35 UTC (permalink / raw)
  To: qemu-devel

Hi, I'm new, just started using qemu; my configuration is:
host: smp linux 2.4.27 kernel (knoppix 3.6)
guest: win2k + sp2
hardware: amd athlon 1.8 1GB ram

Running qemu with 512mb ram.  Seems to work fine, but guest o/s installation
was very slow.  So after reading through previous posts on here I found the
patch posted previously to enable dma for ide, and have applied that to 
ide.c
and rebuilt qemu.  Then in windows go to device manager and see what it 
thinks
is installed.  Device manager says I have a Intel 82371SB PCI Bus Master IDE
controller.  So I right-click on "Primary IDE channel" and look in
properties->advanced settings.  Transfer Mode is set to "DMA if available"
and current transfer mode says "PIO mode".  So it still seems to be in PIO 
mode!

Does that mean that the patch doesn't work?  Do I have to do something else
to make dma work?

The patch I've used is here:
http://lists.gnu.org/archive/html/qemu-devel/2004-09/msg00099.html

qemu version is 0.6.0 downloaded yesterday.

I installed qemu as a non-root user and am not running as root.
I have changed the rtc timer as it asked when I started it the first time.
qemu invocation is
qemu -m 512 -hda disk.img -cdrom /dev/cdrom -boot c
where disk.img is the w2k disk image built by installing windows.

Please can someone tell me how to fully enable dma for disk access?
I really want to improve the performance because it's slow.

_________________________________________________________________
Stay in touch with absent friends - get MSN Messenger 
http://www.msn.co.uk/messenger

^ permalink raw reply	[flat|nested] 42+ messages in thread

end of thread, other threads:[~2004-11-28 20:11 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-11-05 15:37 [Qemu-devel] enabling bus-master IDE driver Juergen Keil
2004-11-05 15:43 ` zitu
2004-11-05 15:45 ` zitu
2004-11-05 15:52   ` Jens Axboe
2004-11-05 16:10     ` zitu
2004-11-05 17:30       ` Damien Mascord
  -- strict thread matches above, loose matches on Subject: below --
2004-11-26 10:48 Juergen Keil
2004-11-28 20:09 ` Juergen Lock
2004-11-12 19:07 Juergen Keil
2004-11-16 19:41 ` Juergen Lock
2004-11-23  5:12   ` Norikatsu Shigemura
2004-11-25 21:12     ` Juergen Lock
2004-11-12 14:27 Juergen Keil
2004-11-12 18:02 ` Jason Brittain
2004-11-04 20:35 Simon Frew
2004-11-05 13:32 ` zitu
2004-11-05 15:02   ` zitu
2004-11-06  1:53     ` Jason Brittain
2004-11-06 14:27       ` Johannes Schindelin
2004-11-06 21:52         ` Jason Brittain
2004-11-07  9:03           ` Jens Axboe
2004-11-07  9:21             ` Jens Axboe
2004-11-07  9:38               ` Jens Axboe
2004-11-07 11:01                 ` Hetz Ben Hamo
2004-11-07 11:16                   ` Jens Axboe
2004-11-08 10:15                     ` zitu
2004-11-08 16:51                       ` Andreas Bollhalder
2004-11-09  7:38                     ` Paul Jakma
2004-11-09 10:28                       ` Hetz Ben Hamo
2004-11-09 13:53                         ` Paul Jakma
2004-11-11 17:29                     ` Jason Brittain
2004-11-11 19:06                       ` Jens Axboe
2004-11-11 19:02                         ` Jason Brittain
2004-11-11 19:16                           ` Jens Axboe
2004-11-12  8:42                             ` Jens Axboe
2004-11-07 11:02             ` James Boddington
2004-11-10  1:41             ` James Boddington
2004-11-06 21:57         ` James Boddington
2004-11-06 22:11           ` James Boddington
2004-11-06 23:46             ` zitu
2004-11-07  0:41               ` jeebs
2004-11-07  7:12               ` Jason Brittain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).