Subject: Re: How do I allocate physically contiguous RAM?
To: Dave Huang <khym@bga.com>
From: Jonathan Stone <jonathan@DSG.Stanford.EDU>
List: port-mac68k
Date: 10/29/1997 16:18:41
>[ This is on the mac68k port, BTW... ]

>I'm trying to write an ethernet driver, and would like to get a 32K
>chunk or so of page-aligned, physically contiguous memory (for DMA
>porpoises).

>If I allocate a chunk of 8*NBPG bytes with
>malloc(), are they guaranteed to be contiguous?

For kerenl malloc()? In general, no. They are guaranteed to be
contiguous in kernel virtual address space, but (in general) the
underlying pages could be _anywhere_ in the physical address space.
Unless the mac68k port uses transparent translation in kernel mode (i
doubt it), the pages you get from kernel malloc() will be MMU-mapped.
(UTSL will show you the answer for sure.)

If the mac port already has hooks to allocate physically-contigous
memory, use them. (it will need them for bus-dma at some point; ask
your portmaster nicely.).

Otherwise, a quick-and-dirty hack is to steal the pages during kernel
initialization time, before they're given to the VM system.  This
isn't clean and it makes your driver inherently MD, so it's a bad idea
unless you really have no other choice.


>Also, where should I look for info on writing a network device driver?
>In particular, I'm looking for info on these "mbuf chain" things, and
>what the IFF_OACTIVE bit is supposed to mean, exactly. Any other
>useful info would help though :)

The Red Daemon Book.  Even the Black Daemon book is a reasonable
intro, but it's out of date in many places.  The 4bsd documentation
also (smm/18.net) has a pretty good intro to mbufs and how the socket,
protocol, and if layers fitted together. That's even more out of date,
but the price is hard to beat.