Results 1 to 8 of 8
I have read a few short discussions on implemented memory mapping in a driver but I am still puzzled. What I want to do is have a piece of memory ...
- 08-10-2005 #1Just Joined!
- Join Date
- Apr 2005
- Posts
- 6
Driver MMAP support for direct access from User space
I have read a few short discussions on implemented memory mapping in a driver but I am still puzzled. What I want to do is have a piece of memory in the driver that is updated when an IRQ comes in and then the user process, which memory maps that driver's memory, polls it for "real time" response.
Is this a correct understanding, I allocate memory in the module that address is used as the physical address when I call remap_page_range? Oh the Kernel is 2.6. Why I am asking this is the discussions also mention the address in kernel space is logical not physical.
Thanks,
- 08-10-2005 #2
What kind of information would you like to be placed in this memory region after receiving an interrupt? Just the fact that you've gotten interrupted or what?
- 08-10-2005 #3Just Joined!
- Join Date
- Apr 2005
- Posts
- 6
shared memory
I am just looking to put in the driver memory that an interrupt has occurred and the user process polls that memory instead of the other methods for faster response.
Thanks,
- 08-10-2005 #4
Just write an interrupt handler function that does the following:
1. Handles whatever needs to be handled for the particular interrupt
2. If you want a running count, increase whatever stats variable you have
3. Awake any reading user processes
Then change the read() method for your device to sleep until data has arrived.
- 08-10-2005 #5Just Joined!
- Join Date
- Apr 2005
- Posts
- 6
deterministic behavior
I need deterministic behavior so to do that the user program is tied to one CPU.
Thanks,
- 08-10-2005 #6
can you give me some more context as to the overall scope of this driver?
- 08-10-2005 #7Just Joined!
- Join Date
- Apr 2005
- Posts
- 6
Goal for Interrupt Handler and an attempt that does not work
What is trying to be done is when a ISR is called a variable is set. A user level process memory maps that driver/module's variable and polls it to check for an interrupt occurrence. This is an attempt to get the fastest response as possible to an IRQ assertion in User space.
I added these lines in the module:
static int Airtiger2Driver_mmap(struct file* pFile, struct vm_area_struct* pVma)
{
static const char* function = NAME "_ioctl";
ENTER("(%p,%p)",pFile,pVma);
int status;
unsigned long offset = pVma->vm_pgoff << PAGE_SHIFT;
status = remap_page_range(pVma,
(unsigned long)pBuffer + offset, // from start
(unsigned long)pBuffer + PAGE_SIZE + offset, // to end
PAGE_SIZE,
PAGE_SHARED);
if (status != 0)
return (-EAGAIN);
return SUCCESS;
}
...
static int Airtiger2DriverInit(void)
{
...
pBuffer = kmalloc(PAGE_SIZE,GFP_KERNEL);
pBuffer[0] = 0x000000AA;
pBuffer[1] = 0x000000BB;
pBuffer[2] = 0x000000CC;
pBuffer[3] = 0x00000123;
...
and this in the user level code to test it:
// open driver
int fDriver;
fDriver = open(DRIVER, 0);
if (fDriver < 0) {
printf("Can't open device file: %s\n", DRIVER);
goto byebyeWithError;
}
// memory map
UINT32* pBuffer;
pBuffer = (UINT32*)mmap(0,PAGE_SIZE,PROT_READ,MAP_SHARED,fDr iver,0);
printf("pBuffer @ %p\n",pBuffer);
printf("[0]=%08x [1]=%08x [2]=%08x [3]=%08x\n",
pBuffer[0], pBuffer[1], pBuffer[2], pBuffer[3]);
munmap(0,PAGE_SIZE);
and this is the output:
pBuffer @ 0x2a9556c000
[0]=00000000 [1]=00000000 [2]=00000000 [3]=00000000
Thanks,
- 08-10-2005 #8
Seriously, I think a better way to do this is to implement a read/open/whatever method that sleeps, and have the interrupt handler wake it up. This eliminates the need to mmap() anything.


Reply With Quote
