Comments on: Writing a PCI device driver for Linux https://olegkutkov.me/2021/01/07/writing-a-pci-device-driver-for-linux/ Programming, electronics and diy projects Mon, 20 May 2024 13:27:15 +0000 hourly 1 https://wordpress.org/?v=6.5.3 By: sk https://olegkutkov.me/2021/01/07/writing-a-pci-device-driver-for-linux/#comment-4152 Mon, 20 May 2024 13:27:15 +0000 https://olegkutkov.me/?p=1575#comment-4152 Can you please give some insight for pcie hot plug details and it’s working.

]]>
By: Paul https://olegkutkov.me/2021/01/07/writing-a-pci-device-driver-for-linux/#comment-1675 Fri, 26 May 2023 07:12:47 +0000 https://olegkutkov.me/?p=1575#comment-1675 Hi Oleg,
Thank you for an excellent resource, it has been very helpful to me and encouraged me to experiment.
One thing I found, in the character driver the last parameter for unregister_chrdev_region(MKDEV(dev_major, 0), MINORMASK) should perhaps be MAXDEV?
Best regards
Paul

]]>
By: Gnanaguru Ganesan https://olegkutkov.me/2021/01/07/writing-a-pci-device-driver-for-linux/#comment-1067 Mon, 04 Oct 2021 05:43:48 +0000 https://olegkutkov.me/?p=1575#comment-1067 Hi,

I’ve gone through it and I’m planning to learn PCIe Card Reader. There I’ve understood that /drivers/misc/cardreader/rtsx_pci.ko (while rtsx_pci.ko = rtsx_pcr.o rts5209.o rts5229.o rtl8411.o rts5227.o rts5249.o rts5260.o rts5261.o rts5228.o) is the PCIe Card Reader Hardware that is available in Laptop and /drivers/mmc/host/rtsx_pci_sdmmc.ko is the MMC card interface via PCIe Card Reader.

In that rtsx_pci.ko has used module_pci_driver, while rtsx_pci_sdmmc.ko uses module_platform_driver. Why is that so? What does it mean by Platform device driver? Why haven’t they used pci_register_driver directly?

Kindly to clarify the doubt sir. I was unable to find answers anywhere.

]]>
By: Bernardo https://olegkutkov.me/2021/01/07/writing-a-pci-device-driver-for-linux/#comment-1064 Sun, 05 Sep 2021 23:07:09 +0000 https://olegkutkov.me/?p=1575#comment-1064 Your blog is a great resource.

I’m porting a pcie device driver and it used to call of_node_full_name() in the probe function. I need to read the device tree but every attempt to read has failed.

Something like this:

static int probe(struct pci_dev *pdev, const struct pci_device_id *id)
{
pr_info(“Found PCI device: %s\n”, of_node_full_name(pdev->dev.of_node));
}

Could you include some example how to?

Thank you.

]]>
By: Oleg Kutkov https://olegkutkov.me/2021/01/07/writing-a-pci-device-driver-for-linux/#comment-1040 Tue, 11 May 2021 21:24:18 +0000 https://olegkutkov.me/?p=1575#comment-1040 In reply to Alfred Wilkinson.

You’re welcome 🙂

]]>
By: Alfred Wilkinson https://olegkutkov.me/2021/01/07/writing-a-pci-device-driver-for-linux/#comment-1039 Tue, 11 May 2021 13:44:01 +0000 https://olegkutkov.me/?p=1575#comment-1039 Super helpful THANKS!!!!

When I used this as a template I found that the MSI free routine at unload would seg fault.

I debugged this down to two things… you should use pci_irq_vector() to get the actual assigned IRQ vector to assign to the handler.

retval = pci_alloc_irq_vectors(dev, 1, 1, PCI_IRQ_MSI);
irq = pci_irq_vector(dev, 0);
retval = request_irq(irq, irq_fnc, 0, “name”, dev);

and number two you need to free the IRQ before deallocating from the PCI layer.
release_device()

irq = pci_irq_vector(dev,0);
free_irq(irq, pdev);
pci_free_irq_vectors(pdev);

Again thanks for documenting this SUPER helpful.

]]>
By: Oleg Kutkov https://olegkutkov.me/2021/01/07/writing-a-pci-device-driver-for-linux/#comment-1037 Thu, 06 May 2021 11:49:54 +0000 https://olegkutkov.me/?p=1575#comment-1037 In reply to Hamed.

This function is called on character device read.
For example cat /dev/mydriver will open your character device and call ‘read’ function. In the case of my driver, lirdev_read is called.

]]>
By: m.fkh https://olegkutkov.me/2021/01/07/writing-a-pci-device-driver-for-linux/#comment-1036 Thu, 06 May 2021 11:12:03 +0000 https://olegkutkov.me/?p=1575#comment-1036 Hi,
I want to get the best performance of pcie device.
Can you guide me?

Thanks

]]>
By: Hamed https://olegkutkov.me/2021/01/07/writing-a-pci-device-driver-for-linux/#comment-1035 Thu, 06 May 2021 10:47:58 +0000 https://olegkutkov.me/?p=1575#comment-1035 Hi,
Thanks for the reply .
How can I call the lirdev_read function at the user level in lir941_linux_driver?

]]>
By: Oleg Kutkov https://olegkutkov.me/2021/01/07/writing-a-pci-device-driver-for-linux/#comment-1029 Thu, 29 Apr 2021 20:15:19 +0000 https://olegkutkov.me/?p=1575#comment-1029 In reply to Hamed.

Sure. It’s Linux device drivers 3rd edition book,
Linux kernel PCI documentation: https://www.kernel.org/doc/html/latest/PCI/pci.html
And existing PCI device drivers, just as an example.

]]>