diff options
author | Federico G. Schwindt <fgsch@cvs.openbsd.org> | 2007-10-22 03:08:54 +0000 |
---|---|---|
committer | Federico G. Schwindt <fgsch@cvs.openbsd.org> | 2007-10-22 03:08:54 +0000 |
commit | d69e7e7d6e618c28d4b1141d46816e29b42e3cfd (patch) | |
tree | 8e98025059ee2218dfab9e8db7e5bd41da5043d5 /sys/dev/pci | |
parent | ff1490a1b56af957f4295645d64b637a8eaf02f0 (diff) |
Add pci_set_powerstate() to change the pm state for a given device.
ok by many.
Diffstat (limited to 'sys/dev/pci')
-rw-r--r-- | sys/dev/pci/pci.c | 19 | ||||
-rw-r--r-- | sys/dev/pci/pcivar.h | 3 |
2 files changed, 20 insertions, 2 deletions
diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c index fa79de1ffcc..8a56aef3468 100644 --- a/sys/dev/pci/pci.c +++ b/sys/dev/pci/pci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pci.c,v 1.50 2007/05/21 22:10:45 kettenis Exp $ */ +/* $OpenBSD: pci.c,v 1.51 2007/10/22 03:08:53 fgsch Exp $ */ /* $NetBSD: pci.c,v 1.31 1997/06/06 23:48:04 thorpej Exp $ */ /* @@ -410,6 +410,23 @@ pci_find_device(struct pci_attach_args *pa, return (0); } +int +pci_set_powerstate(pci_chipset_tag_t pc, pcitag_t tag, int state) +{ + pcireg_t reg; + int offset; + + if (pci_get_capability(pc, tag, PCI_CAP_PWRMGMT, &offset, 0)) { + reg = pci_conf_read(pc, tag, offset + PCI_PMCSR); + if ((reg & PCI_PMCSR_STATE_MASK) != state) { + pci_conf_write(pc, tag, offset + PCI_PMCSR, + (reg & ~PCI_PMCSR_STATE_MASK) | state); + return (reg & PCI_PMCSR_STATE_MASK); + } + } + return (state); +} + #ifndef PCI_MACHDEP_ENUMERATE_BUS /* * Generic PCI bus enumeration routine. Used unless machine-dependent diff --git a/sys/dev/pci/pcivar.h b/sys/dev/pci/pcivar.h index c369df9b949..1e2ed3bbea5 100644 --- a/sys/dev/pci/pcivar.h +++ b/sys/dev/pci/pcivar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pcivar.h,v 1.54 2007/08/01 21:43:03 deraadt Exp $ */ +/* $OpenBSD: pcivar.h,v 1.55 2007/10/22 03:08:53 fgsch Exp $ */ /* $NetBSD: pcivar.h,v 1.23 1997/06/06 23:48:05 thorpej Exp $ */ /* @@ -223,6 +223,7 @@ struct pci_matchid { }; int pci_matchbyid(struct pci_attach_args *, const struct pci_matchid *, int); +int pci_set_powerstate(pci_chipset_tag_t, pcitag_t, int); /* * Helper functions for autoconfiguration. |