What's the difference between pci_enable_device and pcim_enable_device?
Asked Answered
N

1

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?
Nominee answered 1/3, 2015 at 16:29 Comment(0)
M
14

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.

Monorail answered 1/3, 2015 at 16:41 Comment(3)
Do you have a recommendation of an updated/new book on this topic?Nominee
Well, there is LDD4 coming: 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.Monorail
Be noted as well that pcim_enable_device() on release does much more than just pci_disable_device().Ember

© 2022 - 2024 — McMap. All rights reserved.