Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between pci_enable_device and pcim_enable_device?

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?
like image 496
Tar Avatar asked Mar 01 '15 16:03

Tar


1 Answers

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.

like image 177
Sam Protsenko Avatar answered Sep 19 '22 19:09

Sam Protsenko