Re: PCI device driver question



OK, after doing some research, it appears that I can use the char
device read and write functions in the pci device driver. To summarize
what I have, I have written a pci device driver. In userspace, I want
to be able to access the pci device driver, read from memory, and write
to memory. I have recently found out that I can try to read/write from
using file operations.

Right now, this is what the file operations section of the pci device
driver looks like:

static int test_open(struct inode *inode, struct file *filp){
return 0;
}

static int test_release(struct inode *inode, struct file *filp){
return 0;
}

static ssize test_read(struct file *filp, char __user *buf, size_t
count, loff_t *f_pos){
// Code goes here

return 0;
}

static ssize test_write(struct file *filp, char __user *buf, size_t
count, loff_t *f_pos){
// Code goes here

return 0;
}

static struct file_operations test_fops = {
..open = test_open,
..read = test_read.
..write = test_write,
..release = test_release,
}

My questions are:
1) What do I put in for the read and write functions in the pci device
driver? I know that in write, I want to be able to use the function
void writel(unsigned value, char* address) in order to write to the
specified address. Similarly, for the read function, I want to be able
to use the function readl(char* address) to read the data from the
address.

2) In userspace code, how do I use fread and fwrite to a specific
memory location in the pci?



elliotng.ee@xxxxxxxxx wrote:
I cannot find any good documentations on sys_open, sys_read, etc. What
are the parameters required to utilize those questions?

Let me rephrase what I wrote before. I have implemented a pci device
driver. I have the __init, __exit, probe, and remove functions just
like standard pci device drivers. Originally, in my probe function, I
tested the pci device driver by reading/writing to different base
address. On the FPGA, I had a simple test program involving LED's to
verify that I have read/write to the specific memory address.

Now, instead of writing/reading from the pci device driver, I want to
be able to do the reading/writing from the userspace. From the
userspace, I want to input a file using stdio that contains the data to
be written. I will then write out the data to the pci device driver.

My questions are:
a) In the pci device driver, do I need a write and read functions? Are
the functions similar to the char device driver read/write functions?
b) In the userspace, how do I access the pci device driver? The
previous poster mentioned to use sys_open, sys_read, sys_write, etc.
What are the parameters needed to utilize sys_open, sys_read,
sys_write, etc.? Do I need to know major/minor numbers?


ellis@xxxxxxx wrote:
In article <1166736838.855581.113720@xxxxxxxxxxxxxxxxxxxxxxxxxxx>,
elliotng.ee@xxxxxxxxx <elliotng.ee@xxxxxxxxx> wrote:

Now instead of hard-coding what to write in the memory region, I want
to input a file, read the file, and write the appropriate contents to
the memory region. What are the appropriate steps to do that? It seems
as though that I cannot use the library stdio in pci device drivers. Is
there another library that contains file IO?

Look in the kernel source for examples of sys_open, sys_read, etc.

--
http://www.spinics.net/lists/

.



Relevant Pages

  • PCI DMA
    ... I've got several questions about DMA usage in a PCI device driver: ... When I launch a master write access, I'm doing a software polling on ... the PC memory in order to know when the data is present. ...
    (comp.os.linux.development.system)
  • Re: PCI device driver question
    ... Now, instead of writing/reading from the pci device driver, I want to ... be able to do the reading/writing from the userspace. ... What are the parameters needed to utilize sys_open, sys_read, ... as though that I cannot use the library stdio in pci device drivers. ...
    (comp.os.linux.development.system)