Subject: Mapping kernel virtual addresses to physical for DMA device
To: None <port-pmax@sun-lamp.cs.berkeley.edu>
From: Jonathan Stone <jonathan@DSG.Stanford.EDU>
List: port-pmax
Date: 08/25/1994 14:26:30
I'm porting a driver for a Turbochannel interface that does  DMA
to and from mbuf clusters. I need to map kernel (virtual) addresses
to physical addresses, to set the physical addresses in the DMA
descriptor lists for the board.

I couldn't find any code that maps from kernel addresses to physical
addresses, that handles mbufs _and_ ordinary KSEG0 addresses, I wrote
some.

Is there already code that does what the following does? If not, does
the code below violate some abstraction boundary?  Also, is
vm_offset_t the most appropriate type for physical and virtual
addresses?

And in which source files should it go?



vm_offset_t
pmax_kvtophys(vm_offset_t kvaddr)
{
	pt_entry_t *pte;
	vm_offset_t phys;

        if (kvaddr >= MACH_CACHED_MEMORY_ADDR &&
	    kvaddr < MACH_UNCACHED_MEMORY_ADDR) {
		phys = MACH_CACHED_TO_PHYS(kvaddr);
	} else if (kvaddr >= MACH_UNCACHED_MEMORY_ADDR &&
		   kvaddr < MACH_KSEG2_ADDR) {
		phys = MACH_UNCACHED_TO_PHYS(kvaddr);
	} else if (kvaddr >= MACH_UNCACHED_MEMORY_ADDR &&
		   kvaddr < VM_MAX_KERNEL_ADDRESS) {
		pte = kvtopte(kvaddr);
		phys = ((pte->pt_pte.pg_pfnum) << PGSHIFT) +
			(kvaddr & PGOFSET);
	} else {
		printf("Virtual address %x: cannot map to physical\n",
		       kvaddr);
		panic("non-kernel address to kvtophys\n");
                phys = 0;
        }
        return(phys);
}

------------------------------------------------------------------------------