[comp.sys.amiga.tech] SCSI and DMA

dolfing@cs.utwente.nl (Hans Dolfing) (11/10/90)

Because we are currently building a SCSI- interface for an A500, I would 
like to ask a few questions. Our system is a normal A500, Kickstart 1.2,
with 1M and no other extensions. The SCSI-interface is connected to the
expansion-bus.

The problem is how to transfer data from an SCSI- device to memory.
This can be done with DMA or with the CPU. It is no big deal to use
the CPU for data-transfers from a SCSI-device to chip or fast-mem, but
data-transfer with the CPU blocks the processing of other tasks.
Recently, Dave Haynie discussed this topic in 'comp.sys.amiga' but
he didn't explained the Amiga specific problem of chip and fast-mem. 

Problem:
-------

Although the DMA is intended to handle data-transfer between external 
devices and memory (without blocking the CPU), I see 2 major problems.

1. The use of DMA is limited to the chip-mem and the custom-chip
   registers from $dff000 till $e00000.

   All expansion cards (including SCSI-controllers) are adressed from
   $e80000 till $efffff. As far as I know, these adresses cannot be
   reached using DMA.

2. All DMA is done with 7.14 MHz (Custom chip clock-frequency), even
   in a A3000.

Possible solutions:
----------------------

Although there are solutions (see solution 1 and 2), I would like to
know if there are better solutions.

1. Just use the CPU for all data-transfers from a SCSI-device to
   memory. This blocks the execution of tasks during the transfer but
   because we can reach transfer-rates of 1.4 Megabyte/sec, even with
   a 68000, the blocking should not last long. With a faster processor
   (680x0) the blocking due to the transfer should be even shorter (in
	an A3000, three times shorter).

2. There is a possible solution which uses DMA for data-transfer. It is
   not very elegant and I don't like it at all ( see questions).

   Because of the memory-mapped I/O of the Amiga, it ?may? be possible
   to map an adress-range of the controllerboard to chip-mem where
   DMA can be used for transferring data. This adress-range should have
   a fixed size ( e.g. 16K) so that DMA can read/write blocks of 16K
   at once.

   Reading resp. writing data become a problem when the destination
   resp. source adress of the data is not in chip-mem (which is very
   likely when you have a lot of fast-mem).

   If data has to be read, DMA has to be used to transfer data to a buffer
   in chip-mem, followed by a CPU action which moves the read data to its
   final destination	adress. Therefore, the CPU is still blocking the
   other tasks!


Questions:
----------

Maybe somebody is so kind and can answer the following questions:

1. Are there better solutions than the presented ones and how do they
   work?

2. Is it possible to use DMA for data-transfer from a SCSI-device
   to both chip and fast-mem !without! buffering in chip-mem and how
   can I build it?

3. If it is necessary to use both DMA and the CPU for most data-transfers,
   wouldn't it be better to use !only! the CPU?. This is especially
   true for an A3000 where the processor is 3 times faster than the
   DMA (Problem 2, solution 1). 

4. Does the new SCSI-custom chip in a A3000 provide facilities for DMA
   to and from fast-mem?
____

	Hans Dolfing	(dolfing@cs.utwente.nl)

daveh@cbmvax.commodore.com (Dave Haynie) (11/13/90)

In article <1990Nov9.185100.24053@cs.utwente.nl> dolfing@cs.utwente.nl (Hans Dolfing) writes:

>Because we are currently building a SCSI- interface for an A500, I would 
>like to ask a few questions. Our system is a normal A500, Kickstart 1.2,
>with 1M and no other extensions. The SCSI-interface is connected to the
>expansion-bus.

>Recently, Dave Haynie discussed this topic in 'comp.sys.amiga' but
>he didn't explained the Amiga specific problem of chip and fast-mem. 

With hard disk DMA, Chip and Fast memory are identical, execept, of course,
for the speed.  You're confusing the standard multiple bus master 68000
style DMA used from the expansion bus with Chip bus "DMA", in which various
Chip bus units respond to a specified Agnus address at a specificed Chip bus
slot.

>Problem:
>-------

>Although the DMA is intended to handle data-transfer between external 
>devices and memory (without blocking the CPU), I see 2 major problems.

DMA, from the expansion bus or A500 expansion port, does block the CPU while
it's on.  Of course, CPU copying also blocks the CPU from doing other things.
Since the single ended DMA used for I/O is naturally at least twice as fast as
the CPU, it's a win over CPU driven copying even though it does take time from
the CPU.  As I mentioned before, the time taken to service 1.5 MB/sec. SCSI
is from about 50% of the CPU time on an A500/A2000 to 3.5% on an A3000.

>1. The use of DMA is limited to the chip-mem and the custom-chip
>   registers from $dff000 till $e00000.

That's CHIP BUS DMA.  That can only physically happen on the Chip bus, the
memory mapping is just incidental.  This is not what anyone is talking about
when they discuss DMA driven hard disks.

>2. All DMA is done with 7.14 MHz (Custom chip clock-frequency), even
>   in a A3000.

Incorrect; the A3000's DMA controller masters the 68030 bus at full 68030
speeds.  If you're really planning to build any hard disk controller for the
A500, you'll need to read up a bit more on the difference between the expansion
and the chip bus.  Simply speaking, the chip bus is a closed system and you
can't add any hardware that uses any chip bus features.  All A500 expansion
devices hang onto the A500 expansion port, which is essentially a 68000 bus.
So when you talk of DMA in the context of an expanion device of some kind, your
are talking about the standard 68000 style of bus sharing, via the BR*, BG*, 
and BGACK* three wire interface.

>1. Just use the CPU for all data-transfers from a SCSI-device to
>   memory. This blocks the execution of tasks during the transfer but
>   because we can reach transfer-rates of 1.4 Megabyte/sec, even with
>   a 68000, the blocking should not last long. 

Re-read my DMA article, if you have it.  First of all, 1.4 MB/s is a PEAK
rate.  So, unless you buffer your data, you will block for significantly
longer than a full speed transfer much of the time if you read that SCSI 
chip directly.  Secondly, the reason for using DMA is that it only takes 1/2
the bus activity to transfer the same amount of data into memory.

>   With a faster processor (680x0) the blocking due to the transfer should 
>   be even shorter (in an A3000, three times shorter).

Not quite.  If you assume the "write" 1/2 of a "CPU reads SCSI" goes away,
since the A3000 has some very fast memory, then the blocking-due-to-copy-loop
time can be at best cut in half.  The other waste, blocking-due-to-waiting
for-SCSI-ready, will be the same in either system.  If you're reading the
data from the SCSI chip 16 bits at a time, you can't saturate the A500/Zorro II
bus.  If you're reading 8 bits at a time, then yes, you could triple your
speed on the A3000, but with a little effort, nearly double it on the A500
by funneling two 8 bit SCSI accesses into one 16 bit bus access.  Most of the
CPU read SCSI devices at least do this funneling nowadays.

>2. There is a possible solution which uses DMA for data-transfer. It is
>   not very elegant and I don't like it at all ( see questions).

>   Because of the memory-mapped I/O of the Amiga, it ?may? be possible
>   to map an adress-range of the controllerboard to chip-mem where
>   DMA can be used for transferring data. This adress-range should have
>   a fixed size ( e.g. 16K) so that DMA can read/write blocks of 16K
>   at once.

No, as I mentioned before, that's impossible.  Memory mapping is not the
issue.  A device that's physically located on the chip bus, and assigned
a proper chip bus slot (like Floppy, Audio, Display, etc) can use Agnus
"DMA".  There is no way you can drop any kind of expansion device into
that tightly coupled system and expect it to work.

>1. Are there better solutions than the presented ones and how do they
>   work?

All DMA expansion devices use some kind of DMA controller and buffer.  Your
device driver initiates a transfer by telling the DMA device where the data
should go, and pointing the SCSI device at that data.  The SCSI chip will
either fill a buffer, perhaps block sized, or start filling a FIFO.  At the
appropriate point, the DMA device will master the Amiga bus, start reading the
data dumped by the SCSI chip and dumping it in the appropriate Amiga main
memory location.  If the DMA device gets ahead of the SCSI read (on C-A
hard disk controllers, it always does), it'll give back the bus until there's
more data to send.  When it has completed the transfer, it'll interrupt the
CPU, which then signals the device driver task that it's done with the disk
request.

>2. Is it possible to use DMA for data-transfer from a SCSI-device
>   to both chip and fast-mem !without! buffering in chip-mem and how
>   can I build it?

A proper DMA device looks much like a 68000 on the A500 or Zorro II bus.
Commodore builds custom parts, while some other companies use standard 68000
bus DMA controllers from Signetics or Motorola.

>3. If it is necessary to use both DMA and the CPU for most data-transfers,
>   wouldn't it be better to use !only! the CPU?. This is especially
>   true for an A3000 where the processor is 3 times faster than the
>   DMA (Problem 2, solution 1). 

First of all, don't even bother thinking about the A3000.  The A3000's DMA
controller runs around 5x-10x faster than any A500 or Zorro II bus device
would in the A3000.  Even a Zorro III DMA controller would have a hard time
improving on the A3000's DMA, and no improvements would come cheap.

>4. Does the new SCSI-custom chip in a A3000 provide facilities for DMA
>   to and from fast-mem?

I think it probably can DMA to and from Fast memory.  But if you're doing
memory to memory copies, the 68030 can do them just as fast as any DMA 
controller.  DMA controllers only win when you have to pay for copy loops,
like you do on the 68000 (they get cached on the '030) or you can have 
single bus crossing DMA, like all Amiga DMA hard disk controllers.  Don't 
get locked into the IBM PC way of thinking about DMA; the Amiga has real
multimastered DMA.

>	Hans Dolfing	(dolfing@cs.utwente.nl)


-- 
Dave Haynie Commodore-Amiga (Amiga 3000) "The Crew That Never Rests"
   {uunet|pyramid|rutgers}!cbmvax!daveh      PLINK: hazy     BIX: hazy
	Standing on the shoulders of giants leaves me cold	-REM