1
votes

I need to phisically power off my PCI device in linux. I have find the functions I need, but it seems to write a kernel mode application to use that library, because I have find it in kernel headers.

I have found this function int pci_set_power_state(struct pci_dev *dev, pci_power_t state) in drivers/pci/pci.c and I don't know how to use it.

Also, I've read in documentation, that device driver in general is not used to switch device to d3cold, because the device simply switches off and don't work at all (yes, there are some devices, that can be switched off not completely, and are able to send a wake up call, but this is another story...) and I think, that I need to communicate with PCI bus.

I don't know where to look for an answer, please guide my quest.

2
I hardly understand the context. Are you having some issue with some device? Do you want to manage the device via userspace? Does the device have a driver in kernel? Be more elaborative. - 0andriy
I want to switch off any power of any PCI-device. In my situation it has driver, but i don't know either it compiled in kernel or not. Kernel or userspace is not important, but userspace application is more comfortable to me. - Roman Kovtuh

2 Answers

2
votes

Potential Method #1 I think you can do it with these commands:

disable

echo 0 > /sys/bus/pci/slots/$NUMBER/power

enable

echo 1 > /sys/bus/pci/slots/$NUMBER/power

Where $NUMBER is the number of the PCI slot.

lspci -vv may help to identify the device. This is not very well documented...

0
votes

Another way is to send shutdown notification to pci device. I take nvm device for example

  1. read bar0 value by lspci, offset is 10h.

    lspci -s 01:00.0 -xxxx. For example you got value: 0xfc1f4004

  2. read memory whose addr is 0xfc1f4000

  3. write 1 in bit 14 of 0xfc1f4014

Offset 14h: CC – Controller Configuration. Bit 15:14 = 01b Normal shutdown notification