8

This book's PCI chapter explain about:

int pci_enable_device(struct pci_dev *dev);

however there's also:

int pcim_enable_device (struct pci_dev * pdev);

But besides stating it's a "Managed pci_enable_device", it has no explanation.

  1. So what's the difference between these two?
  2. What does it mean, that it's "managed"?
  3. Which one I should use?
Tar
  • 8,529
  • 9
  • 56
  • 127

1 Answers1

13

pcim_enable_device() is a managed version of pci_enable_device(). Means that if you call pci_enable_device(), you also need to call pci_disable_device() in the end. In case of pcim_enable_device(), managed framework will take care of disable operation for you.

In new kernel versions it is recommended to use such managed functions in order to get rid of error handling in your driver code. See this article to get a clue about device resource management (or devres) API. This particular function (pcim_enable_device) was introduced in this patch. If you want to read more about devres framework, see Documentation/driver-model/devres.txt

The book you mentioned ("Linux Device Drivers, 3rd edition") doesn't have any explanation for managed functions, because it was written before those functions were implemented.

Sam Protsenko
  • 14,045
  • 4
  • 59
  • 75
  • Do you have a recommendation of an updated/new book on this topic? – Tar Mar 01 '15 at 16:59
  • 2
    Well, there is LDD4 coming: http://shop.oreilly.com/product/0636920030867.do . But I can't remember any book describing managed functions right now. Actually you don't need one, just look into `Documentation/driver-model/devres.txt` file in your kernel sources. In the end it boils down to next: you use managed function instead of not managed one, and don't call any resource freeing functions in the end. Once your driver is about to be exit/unloaded, **devres** framework will call resource free function for you automatically. – Sam Protsenko Mar 01 '15 at 17:08
  • 3
    Be noted as well that `pcim_enable_device()` on release does much more than just `pci_disable_device()`. – 0andriy Mar 01 '15 at 18:03