关于编译pci设备驱动程序出现的问题
我的代码源程序如下:
#ifndef _PCI_H
#define _PCI_H
#include <linux/types.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include <linux/errno.h>
#include <asm/segment.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/pci.h>
#define PCI_VENDOR_ID_netb 0x10ee
#define PCI_DEVICE_ID_netb 0x1000
unsigned int pci_major = 250;
static ssize_t read_pci(struct file *file,char *buf,ssize_t count,loff_t *ppos)
{
int left;
// if ((verify_area(VERIFY_WRITE,buf,count) == -EFAULT )
// return -EFAULT;
for(left = count ; left > 0 ; left--)
{
__put_user(1,buf,1);
buf++;
}
return count;
}
static ssize_t write_pci(struct file *file,char *buf,ssize_t count,loff_t *ppos)
{
return count;
}
static int ioctl_pci(struct inode *inode, struct file * file, unsigned int count, unsigned long count1)
{
return 0;
}
static int open_pci(struct inode *inode,struct file *file )
{
//MOD_INC_USE_COUNT;
return 0;
}
static void release_pci(struct inode *inode,struct file *file )
{
//MOD_DEC_USE_COUNT;
return;
}
static struct file_operations pci_fops ={
owner:THIS_MODULE,
NULL,
read:read_pci,
write:write_pci,
NULL,
NULL,
ioctl:ioctl_pci,
NULL,
open:open_pci,
NULL,
release:release_pci,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
};
static int init_module(struct pci_dev *dev){
/*找这块设备是否存在*/
dev = pci_find_device(PCI_VENDOR_ID_netb,
PCI_DEVICE_ID_netb,dev);
if(dev==0){
//printk(KERN_INFO "pci: can't get major number\n");
return -1;
};
/*启动pci设备*/
if(pci_enable_device(dev)) {;}
/*注册设备*/
register_chrdev(pci_major,"pci",&pci_fops);
}
void cleanup_module(void)
{
unregister_chrdev(pci_major,"pci");
}
#endif
程序使用gcc -DMODULE -D__KERNEL__ -DLINUX pci.c编译
出现了如下错误信息:
cpci.c: At top level:
cpci.c:21: warning: `struct file' declared inside parameter list
cpci.c:21: warning: its scope is only this definition or declaration, which is probably not what you want
cpci.c:36: warning: `struct file' declared inside parameter list
cpci.c:41: warning: `struct file' declared inside parameter list
cpci.c:41: warning: `struct inode' declared inside parameter list
cpci.c:46: warning: `struct file' declared inside parameter list
cpci.c:46: warning: `struct inode' declared inside parameter list
cpci.c:52: warning: `struct file' declared inside parameter list
cpci.c:52: warning: `struct inode' declared inside parameter list
cpci.c:59: variable `cpci_fops' has initializer but incomplete type
cpci.c:60: unknown field `owner' specified in initializer
cpci.c:60: warning: excess elements in struct initializer
cpci.c:60: warning: (near initialization for `cpci_fops')
cpci.c:61: warning: excess elements in struct initializer
cpci.c:61: warning: (near initialization for `cpci_fops')
cpci.c:62: unknown field `read' specified in initializer
cpci.c:62: warning: excess elements in struct initializer
cpci.c:62: warning: (near initialization for `cpci_fops')
cpci.c:63: unknown field `write' specified in initializer
cpci.c:63: warning: excess elements in struct initializer
cpci.c:63: warning: (near initialization for `cpci_fops')
cpci.c:64: warning: excess elements in struct initializer
cpci.c:64: warning: (near initialization for `cpci_fops')
cpci.c:65: warning: excess elements in struct initializer
cpci.c:65: warning: (near initialization for `cpci_fops')
cpci.c:66: unknown field `ioctl' specified in initializer
cpci.c:66: warning: excess elements in struct initializer
cpci.c:66: warning: (near initialization for `cpci_fops')
cpci.c:67: warning: excess elements in struct initializer
cpci.c:67: warning: (near initialization for `cpci_fops')
cpci.c:68: unknown field `open' specified in initializer
cpci.c:68: warning: excess elements in struct initializer
cpci.c:68: warning: (near initialization for `cpci_fops')
cpci.c:69: warning: excess elements in struct initializer
cpci.c:69: warning: (near initialization for `cpci_fops')
cpci.c:70: unknown field `release' specified in initializer
cpci.c:70: warning: excess elements in struct initializer
cpci.c:70: warning: (near initialization for `cpci_fops')
cpci.c:71: warning: excess elements in struct initializer
cpci.c:71: warning: (near initialization for `cpci_fops')
cpci.c:72: warning: excess elements in struct initializer
cpci.c:72: warning: (near initialization for `cpci_fops')
cpci.c:73: warning: excess elements in struct initializer
cpci.c:73: warning: (near initialization for `cpci_fops')
cpci.c:74: warning: excess elements in struct initializer
cpci.c:74: warning: (near initialization for `cpci_fops')
cpci.c:75: warning: excess elements in struct initializer
cpci.c:75: warning: (near initialization for `cpci_fops')
cpci.c:76: warning: excess elements in struct initializer
cpci.c:76: warning: (near initialization for `cpci_fops')
cpci.c:78: warning: excess elements in struct initializer
cpci.c:78: warning: (near initialization for `cpci_fops')
cpci.c:81: warning: `struct pci_dev' declared inside parameter list
cpci.c: In function `init_module':
cpci.c:84: warning: assignment makes pointer from integer without a cast
cpci.c: At top level:
cpci.c:59: storage size of `cpci_fops' isn't known
make: *** [cpci] Error 1
如何改进呢?
问题点数:50、回复次数:2Top
1 楼hs_guanqi(关七)回复于 2005-04-20 00:21:22 得分 30
老问题了,要加上-I/usr/src/linux/include,
头文件要使用kernel的Top
2 楼gettext(冰雪之崖)回复于 2005-04-20 07:44:52 得分 20
or -I /usr/src/linux-2.4/include/Top




