How to allocate buffer memory at physical address in linux?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How to allocate buffer memory at physical address in linux?



I am trying to create a char device driver which can write a buffer at specific physical address(e.g.0x1000-0000). Can someone please help.



Here is a sample of the driver program which I have written.



//include files


#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/uaccess.h>



//device name

#define test_NAME "test"


//need to store this memory at a physical location
static char device_memory[100];



//open function


int test_open (struct inode *my_inode, struct file *my_file)

printk(KERN_INFO "Inside the test_open function...n");
return 0;



//close device function


int test_close (struct inode *my_inode, struct file *my_file)

printk(KERN_INFO "Inside the test_close function...n");
return 0;



//read function


ssize_t test_read (struct file *my_file, char __user *userbuff, size_t
nRead, loff_t *nReadOffset)

int notCopied;

notCopied = copy_to_user(userbuff, device_memory, nRead);
printk("Inside the test_read function...n");
return (nRead - notCopied);



//write function


ssize_t test_write (struct file *my_file, const char __user *userbuff,
size_t nWrite, loff_t *nWriteOffset)

int notCopied;

notCopied = copy_from_user(device_memory, userbuff, nWrite);
printk("Inside the test_write function...n");
return (nWrite - notCopied);


static struct file_operations test_fops =
.owner = THIS_MODULE,
.open = test_open,
.release = test_close,
.read = test_read,
.write = test_write,
;

int init_module(void)

int retval;
retval = register_chrdev(120, test_NAME, &test_fops);
if (retval != 0)

printk(KERN_INFO "Failed to register test driver...n");
return -1;


printk(KERN_INFO "test registration succeeded...n");
return 0;


void cleanup_module(void)

unregister_chrdev(120, test_NAME);
printk(KERN_INFO "test unregistered successfully...n");
return;



MODULE_LICENSE("GPL");
MODULE_AUTHOR("SK110");
MODULE_DESCRIPTION("Driver for a test (virtual) device.");





@jww Added code sample. Please suggest how to store memory at physical address.
– sk110
Aug 11 at 8:43





Refer to gby's answer to this question
– yashC
Aug 13 at 9:43









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard