These functions convert from virtual addresses (as the CPU uses them) to PCI bus addresses and back. This is necessary since the memory may be mapped non-linear by the PMMU even when not using virtual memory (it is on the MILAN).
It is required that a resource (ie. a region of memory or IO space on a PCI card) is mapped contiguously, so that a simple offset can be used when copying to/from memory on a PCI card.
These functions might be limited to TOS or TOS-like operating systems. If an operating systems uses a different memory layout, it may need to provide its own functions which drivers can use.
When using these functions, the driver does not need to care about DMA offsets at all.
get_pagesize:
Input:
none
Output:
D0.L active pagesize or 0 if paging is not active
virt_to_bus:
Input:
D0.L device handle
D1.L address in virtual CPU space
A0.L pointer to mem-struct for results
Output:
D0.L error code
If D0.L indicates no error, mem-struct is filled as follows:
mem-struct:
DS.L 1 ;PCI bus address
DS.L 1 ;length of contiguous mapped area, 0 if no DMA is possible
;at this address
This function is the reverse of virt_to_bus. It might be slow, so the driver should avoid using it if it can determine the address by other means.
bus_to_virt:
Input:
D0.L device handle
D1.L PCI bus address
A0.L pointer to mem-struct for results
Output:
D0.L error code
If D0.L indicates no error, mem-struct is filled as follows:
mem-struct:
DS.L 1 ;CPU (virtual) address
DS.L 1 ;length of contiguous mapped area
The following two functions do not depend on a special device, thus they do not get a device handle.
virt_to_phys:
Input:
D0.L address in virtual CPU space
A0.L pointer to mem-struct for results
Output:
D0.L error code
If D0.L indicates no error, mem-struct is filled as follows:
mem-struct:
DS.L 1 ;physical CPU address
DS.L 1 ;length of contiguous mapped area, 0 if not mapped
This function is the reverse of virt_to_bus. It might be slow, so the driver should avoid using it if it can determine the address by other means.
phys_to_virt:
Input:
D0.L physical CPU address
A0.L pointer to mem-struct for results
Output:
D0.L error code
If D0.L indicates no error, mem-struct is filled as follows:
mem-struct:
DS.L 1 ;CPU (virtual) address
DS.L 1 ;length of contiguous mapped area