在哪里可以找到在Debian Stretch上构建网络驱动程序的pci_find_device()声明



我正在尝试构建一个网络驱动程序。然而,当我尝试构建时,它会说:

error: implicit declaration of function ‘pci_find_device

这是我的司机:

#define REALTEK_VENDER_ID  0x10EC
#define REALTEK_DEVICE_ID   0x8139
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/stddef.h>
#include <linux/pci.h>
int init_module(void)
{
struct pci_dev *pdev;
pdev = pci_find_device(REALTEK_VENDER_ID, REALTEK_DEVICE_ID, NULL);
if(!pdev)
printk("<1>Device not foundn");
else
printk("<1>Device foundn");
return 0;
}
MODULE_LICENSE("GPL");

这是我的Makefile

obj-m += ethDriver.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

当我构建时,我会得到以下错误:

ethDriver.c: In function ‘init_module’:
/home/xxx/ethDriver/ethDriver.c:13:12: error: implicit declaration of function ‘pci_find_device’ [-Werror=implicit-function-declaration]
pdev = pci_find_device(REALTEK_VENDER_ID, REALTEK_DEVICE_ID, NULL);
^~~~~~~~~~~~~~~
/home/xxx/ethDriver/ethDriver.c:13:10: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
pdev = pci_find_device(REALTEK_VENDER_ID, REALTEK_DEVICE_ID, NULL);
^
cc1: some warnings being treated as errors
/usr/src/linux-headers-4.9.0-3-common/scripts/Makefile.build:315: recipe for target '/home/xxx/ethDriver/ethDriver.o' failed
make[4]: *** [/home/xxx/ethDriver/ethDriver.o] Error 1
/usr/src/linux-headers-4.9.0-3-common/Makefile:1507: recipe for target '_module_/home/xxx/ethDriver' failed
make[3]: *** [_module_/home/xxx/ethDriver] Error 2
Makefile:150: recipe for target 'sub-make' failed
make[2]: *** [sub-make] Error 2
Makefile:8: recipe for target 'all' failed
make[1]: *** [all] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-4.9.0-3-amd64'
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 2

内核v2.6.34中删除了pci_find_device()函数。

来自Documentation/PCI/pci.rst:

过时的函数

尝试时可能会遇到以下几种功能将旧的驱动程序移植到新的PCI接口。他们不再是存在于内核中,因为它们与热插拔或PCI不兼容域或具有正常锁定。

pci_find_device() Superseded by pci_get_device()
pci_find_subsys() Superseded by pci_get_subsys()
pci_find_slot()   Superseded by pci_get_domain_bus_and_slot()
pci_get_slot()    Superseded by pci_get_domain_bus_and_slot()

您需要使用pci_get_device(),它也应该包含在<linux/pci.h>中。

/**
* pci_get_device - begin or continue searching for a PCI device by vendor/device id
* @vendor: PCI vendor id to match, or %PCI_ANY_ID to match all vendor ids
* @device: PCI device id to match, or %PCI_ANY_ID to match all device ids
* @from: Previous PCI device found in search, or %NULL for new search.
*
* Iterates through the list of known PCI devices.  If a PCI device is
* found with a matching @vendor and @device, the reference count to the
* device is incremented and a pointer to its device structure is returned.
* Otherwise, %NULL is returned.  A new search is initiated by passing %NULL
* as the @from argument.  Otherwise if @from is not %NULL, searches continue
* from next device on the global list.  The reference count for @from is
* always decremented if it is not %NULL.
*/
struct pci_dev *pci_get_device(unsigned int vendor, unsigned int device,
struct pci_dev *from)
{
return pci_get_subsys(vendor, device, PCI_ANY_ID, PCI_ANY_ID, from);
}
EXPORT_SYMBOL(pci_get_device);

附言:你的#define有错别字,应该是VENDOR,而不是VENDER

最新更新