I am attempting to access a given memory-region on an am335x-processor in Linux. The idea is to first designate physical addresses, then access said addresses using ioremap
. I have been googling the issue for some time, but cannot seem to find any good solutions.
The functions to do these tasks are as follows:
Function to obtain physical addresses:
static int initPaddr(struct regref **reg, long unsigned int *base, int count)
{
int i;
reg = kmalloc(sizeof(struct regref*) * count, GFP_KERNEL);
for(i = 0; i < count; i++)
reg[i] = kmalloc(sizeof(struct regref), GFP_KERNEL);
for(i = 0; i < count; i++)
reg[i]->paddr = REG_ADDR(base, regArray[i]);
return 0;
}
Function to register virtual addresses:
static int initVaddr(struct regref **reg, int blocksize, int count)
{
int i;
for(i = 0; i < count; i++)
reg[i]->vaddr = (unsigned long*) ioremap( (unsigned long) reg[i]->paddr, blocksize);
return 0;
}
Here regArray[]
is just an array that hold all the relevant physical addresses and the struct regref
is defined in the following way:
struct regref = {
long unsigned int *paddr;
long unsigned int *vaddr;
};
To code does compile, but when I try to load it, I end up getting the following error:
Unable to handle kernel paging request at virtual address 702f7373
Where the address may vary.
I assume I am doing something wrong, but fail to see exactly what that might be. Of course the code can be a lot better too, but I'd like to solve this issue before making further changes. Does anyone have any suggestions?
Turns out the mistake was not in the code above, but somewhere else. The code above is a working example for the use of
ioremap()
.