Example of PCI registration and logoff in Linux system

Source: Internet
Author: User

1. Pci_driver structure
struct Pci_driver {
struct List_head node;
const char *name;
const struct PCI_DEVICE_ID *id_table; /* Must be non-null-probe to be called */
Int (*probe) (struct Pci_dev *dev, const struct pci_device_id *id); /* New Device inserted */
void (*remove) (struct Pci_dev *dev); /* Device removed (NULL if not a hot-plug capable driver) */
Int (*suspend) (struct Pci_dev *dev, pm_message_t State); /* Device suspended */
Int (*suspend_late) (struct Pci_dev *dev, pm_message_t State);
Int (*resume_early) (struct Pci_dev *dev);
Int (*resume) (struct Pci_dev *dev); /* Device woken up */
void (*shutdown) (struct Pci_dev *dev);
Int (*sriov_configure) (struct pci_dev *dev, int num_vfs); /* PF Pdev */
const struct Pci_error_handlers *err_handler;
struct Device_driver driver;
struct Pci_dynids dynids;
};

1. Name, as follows:
# ls/sys/bus/pci/drivers/
JMicron IDE promise_ide ata_piix e100 e1000e IGB Ixgbe

2. id_table
is a pointer to the ID number of the PCI device that describes the number of the current PCI device and is generally used as an input parameter for probe. As the following table:


/* Ixgbe_pci_tbl-pci Device ID Table
*
* Wildcard Entries (pci_any_id) should come last
* Last entry must is all 0s
*
* {Vendor ID, Device ID, Subvendor ID, subdevice ID,
* Class, Class Mask, private data (not used)}
*/
Static define_pci_device_table (IXGBE_PCI_TBL) = {
{Pci_vdevice (INTEL, ixgbe_dev_id_82598), board_82598},
{Pci_vdevice (INTEL, Ixgbe_dev_id_82598af_dual_port), board_82598},
{Pci_vdevice (INTEL, Ixgbe_dev_id_82598af_single_port), board_82598},
{Pci_vdevice (INTEL, Ixgbe_dev_id_82598at), board_82598},
{Pci_vdevice (INTEL, IXGBE_DEV_ID_82598AT2), board_82598},
{Pci_vdevice (INTEL, ixgbe_dev_id_82598eb_cx4), board_82598},
{Pci_vdevice (INTEL, Ixgbe_dev_id_82598_cx4_dual_port), board_82598},
{Pci_vdevice (INTEL, Ixgbe_dev_id_82598_da_dual_port), board_82598},
{Pci_vdevice (INTEL, Ixgbe_dev_id_82598_sr_dual_port_em), board_82598},
{Pci_vdevice (INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598},
{Pci_vdevice (INTEL, Ixgbe_dev_id_82598eb_sfp_lom), board_82598},
{Pci_vdevice (INTEL, IXGBE_DEV_ID_82598_BX), board_82598},
{Pci_vdevice (INTEL, ixgbe_dev_id_82599_kx4), board_82599},
{Pci_vdevice (INTEL, Ixgbe_dev_id_82599_xaui_lom), board_82599},
{Pci_vdevice (INTEL, IXGBE_DEV_ID_82599_KR), board_82599},
{Pci_vdevice (INTEL, IXGBE_DEV_ID_82599_SFP), board_82599},
{Pci_vdevice (INTEL, Ixgbe_dev_id_82599_sfp_em), board_82599},
{Pci_vdevice (INTEL, Ixgbe_dev_id_82599_kx4_mezz), board_82599},
{Pci_vdevice (INTEL, ixgbe_dev_id_82599_cx4), board_82599},
{Pci_vdevice (INTEL, Ixgbe_dev_id_82599_backplane_fcoe), board_82599},
{Pci_vdevice (INTEL, Ixgbe_dev_id_82599_sfp_fcoe), board_82599},
{Pci_vdevice (INTEL, Ixgbe_dev_id_82599_t3_lom), board_82599},
{Pci_vdevice (INTEL, Ixgbe_dev_id_82599_combo_backplane), board_82599},
{Pci_vdevice (INTEL, ixgbe_dev_id_x540t), board_x540},
{Pci_vdevice (INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599},
{Pci_vdevice (INTEL, Ixgbe_dev_id_82599_ls), board_82599},
{Pci_vdevice (INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599},
{Pci_vdevice (INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599},
{Pci_vdevice (INTEL, ixgbe_dev_id_x540t1), board_x540},
/* Required last entry */
{0,}
};
Module_device_table (PCI, IXGBE_PCI_TBL);

The PCI_DEVICE_ID structure is as follows:
struct PCI_DEVICE_ID {
__U32 Vendor, device; /* Vendor and device ID or pci_any_id*/
__u32 Subvendor, Subdevice; /* Subsystem ID ' s or pci_any_id */
__u32 class, Class_mask; /* (CLASS,SUBCLASS,PROG-IF) triplet */
kernel_ulong_t Driver_data; /* Data Private to the driver */
};

3. Probe

Int (*probe) (struct Pci_dev *dev, const struct PCI_DEVICE_ID *id)

Point to the probe function pointer in the PCI driver, which is called by the PCI core when it has a struct pci_dev that it thinks the driver wants to control.
A pointer to pci_device_id, the PCI core is used to make this decision, and the defendant passes it to this function, if this PCI driver needs to pass this to its struct pci_dev,
It should be initializing the device and returning 0, if the driver does not want to own the device, or generates an error, it should return a negative error value.

4. Remove
void (*remove) (struct Pci_dev *dev)
Pointer to the function that the PCI core invokes when the struct Pci_dev is removed from the system, or when the PCI driver is unloaded from the kernel.

5. Suspend
Int (*suspend) (struct Pci_dev *dev, pm_message_t State)
A function pointer that is called by the PCI core when the struct Pci_dev is suspended, which is passed when the state variable is suspended, is optional

6. Resume
Int (*resume) (struct pci_def *dev)
When the Pci_dev defendant recovers the function pointer of the PCI core call, it must be called after the Suspend function is executed, and the function is optional.

7. Shutdown
void (*shutdown) (struct Pci_dev *dev)
When this device needs to be closed, the function that this function pointer points to will be called.

8. Ixgbe Registration

static struct Pci_driver Ixgbe_driver = {
. Name = Ixgbe_driver_name,
. id_table = Ixgbe_pci_tbl,
. Probe = Ixgbe_probe,
. remove = __devexit_p (Ixgbe_remove),
#ifdef CONFIG_PM
. Suspend = Ixgbe_suspend,
. Resume = Ixgbe_resume,
#endif
#ifndef Use_reboot_notifier
. Shutdown = Ixgbe_shutdown,
#endif
#ifdef have_pci_ers
. Err_handler = &ixgbe_err_handler
#endif
};
static int __init ixgbe_init_module (void)
{
int ret;
...
ret = Pci_register_driver (&ixgbe_driver);
return ret;
}
Module_init (Ixgbe_init_module);

9. Ixgbe Logoff
static void __exit ixgbe_exit_module (void)
{
Pci_unregister_driver (&ixgbe_driver);
...
}
Module_exit (Ixgbe_exit_module);

Http://blog.chinaunix.net/uid-7187477-id-3220913.html

Example of PCI registration and logoff in Linux system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.