Allocating memory for DMA on 64 bit system
Hi
I have a problem with allocating high memory in my kernel driver running at a 64 bit 4 GB ram (Linux RedHatEnteprise 5). I have reserved 40 Mb of memory by using the mem= parameter (mem=4056), so there should be some memory available for DMA. The driver is working perfect at a 32 bit system but when running at a 64 bit system I have problem writing and reading information from the allocated memory. (I have to set the mem to 2048 for getting the driver to work on a 64 bit system)
Here is some code to better explain what my driver do.
// (1 Mb) Memory to allocate each cycle
const unsigned long alloc_size = 0x100000;
// Calculate the start position for the high memory
const unsigned long phy_highmem = num_physpages << PAGE_SHIFT;
void* remapped = ioremap(phy_highmem, alloc_size);
// Verify that the memory area is accessible to us
if(!testMemory(remapped, page_size))
{
printk(KERN_ERR The memory test failed, this indicates that we are accessing memory areas that are forbidden, please check that there is enough high memory left.\n");
goto fail_init;
}
iounmap((void*)remapped); ...
...
bool testMemory(void* memory, unsigned long size) {
unsigned index;
char c;
// Insert a value in the memory to verify that it is accessible
for(index = 0; index < size; index++)
{
c = index&0xff;
iowrite8(c, memory + index);
if(c != (char)ioread8(memory + index))
{
printk(KERN_ERR ERROR: Did not manage to insert the value [%d] at index [%d]\n", (int)c, index);
return false;
}
}
return true;
}
I hope someone can explain to me what I clearly don’t understand! :o)
Best redards,
Per