LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
LinkBack Search this Thread
Old 01-19-2012, 03:54 AM   #1
nskid11
LQ Newbie
 
Registered: Aug 2010
Posts: 4

Rep: Reputation: 0
Help / Advice On Creating a Kernel Module


Yello,

I'm trying to write a kernel module for an embedded system that has a CPU with two cores, what I'm basically trying to do is allow a Linux program on CoreA to read buffers that are being written to by a bare metal encoder running on CoreB. The buffers and variables I need to be able to access have fixed memory locations in L3(SDRAM) and L2 Cache (Shared onchip SRAM), the larger buffers and variables will be read on the Linux side, some of the others will need to be able to change bytes.

Now my main question is where or not it's possible to get the kernel process to pass to the Linux process a pointer so the linux process can read the buffer directly rather then have to copy the data. I know that the kernel module can directly address memory but I don't if I can then pass that to the Linux process. So can someone point me in the right direction, thanks

The way I was assuming it could be done was by using ioctl to return a pointer to a variable in the kernel module that already points to the right area of memory area, something to the effect of the code below, but having never written a kernel module before, and none of the documentation talking about directly addressing memory I need my assumptions confirmed.

Kernel Module:
Code:
static unsigned char *streambuffer = (unsigned char*)0x02800000;

int encoder_icc_ioctl (struct inode *inode, struct file* filp, unsigned int cmd, unsigned long arg)
{
     switch (cmd)
     {
         case (SOME_COMMAND):
         {

            return &streambuffer;
         }
     }
}
Linux Program:
Code:
unsigned char **streambufferpointer = ioctl(...);
The CPU and the uClinux kernel for it both use one address range for all 3 caches, which each cache appearing in different parts of that range, 0x02800000 is a direct pointer to the buffer stored in L3 cache. I know that works because we tested the output to a Proc file, its getting a pointer to that address to a Linux process that I'm not sure on, as I don't know how this process would handle the kernel and user address spaces.

If it can't be done then please say, I would rather not have to copy the buffers if possible, but if its unavoidable that's fine. Thanks for the help.
 
Old 01-20-2012, 10:12 AM   #2
nskid11
LQ Newbie
 
Registered: Aug 2010
Posts: 4

Original Poster
Rep: Reputation: 0
Nevermind, finally got to the point where I needed this to work and have spent all day with it and worked it out ^^

Kernel Module:
Code:
static unsigned char *gStreamBuf[NUM_INSTANCES][NUM_STREAM_BUFFERS];	// Points to the stream buffer in SDRAM

...

static int __init encoder_icc_init (void)
{
	// Points gStreamBuf to the stream buffers in L3 cache
	gStreamBuf[0][0] = (unsigned char *)0x02800000;

...

}

long encoder_icc_ioctl (struct file *filp, unsigned int cmd, unsigned long arg)
{
	switch (cmd)
	{

...

		case (1):
		{
			eInstanceFlags[1].active = ~eInstanceFlags[1].active;
			printk ("Encoder ICC Module: Buffer Address %x\n", (unsigned int) &gStreamBuf[0][0]);
			printk ("Encoder ICC Module: Buffer Pointer %x\n", (unsigned int) gStreamBuf[0][0]);

			ret = put_user ((unsigned int)gStreamBuf[0][0], (unsigned int*) arg);
			if (ret)
			{
				return -EFAULT;
			}
			else
			{
				return 0;
			}
		}
		break;

...

	}
}
Linux Program:
Code:
unsigned char *gStreamBuf;

int main() {

...

ret = ioctl(fd, 1, (unsigned int) &gStreamBuf);

...

}
I've skipped out all the code for creating and opening the device driver / kernel module so thats just the code to do what I was aiming for.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Install older kernel module into newer kernel - no symbol version for module bayoulinux Linux - Kernel 4 10-26-2011 04:32 AM
Where to begin creating a kernel module for a networked storage device dahweeds Linux - Newbie 1 05-15-2009 03:57 AM
dpkg-buildpackage: Errors Creating Kernel Module Package jhwilliams Ubuntu 0 01-19-2009 10:44 PM
Debian :trouble creating a kernel module covertops Linux - Newbie 2 03-21-2005 08:31 AM
creating Makefile with multiple kernel module files b123coder Programming 0 12-26-2004 08:41 AM


All times are GMT -5. The time now is 12:30 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration