Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/pci GC pci_{g, s}et_powerstate into pci_powerstate()....



details:   https://anonhg.NetBSD.org/src/rev/faf6e7b1c8bf
branches:  trunk
changeset: 566427:faf6e7b1c8bf
user:      christos <christos%NetBSD.org@localhost>
date:      Sat May 08 23:41:40 2004 +0000

description:
GC pci_{g,s}et_powerstate into pci_powerstate(). Idea from mycroft and gimpy.
Nothing uses them yet.

diffstat:

 sys/dev/pci/pci.c    |  77 ++++++++++++++++++++++++---------------------------
 sys/dev/pci/pcivar.h |   5 +--
 2 files changed, 39 insertions(+), 43 deletions(-)

diffs (151 lines):

diff -r 6cb0aa6271f2 -r faf6e7b1c8bf sys/dev/pci/pci.c
--- a/sys/dev/pci/pci.c Sat May 08 23:40:01 2004 +0000
+++ b/sys/dev/pci/pci.c Sat May 08 23:41:40 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pci.c,v 1.83 2004/04/23 21:13:07 itojun Exp $  */
+/*     $NetBSD: pci.c,v 1.84 2004/05/08 23:41:40 christos Exp $        */
 
 /*
  * Copyright (c) 1995, 1996, 1997, 1998
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pci.c,v 1.83 2004/04/23 21:13:07 itojun Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci.c,v 1.84 2004/05/08 23:41:40 christos Exp $");
 
 #include "opt_pci.h"
 
@@ -483,78 +483,75 @@
  */
 
 int
-pci_set_powerstate(pci_chipset_tag_t pc, pcitag_t tag, int newstate)
+pci_powerstate(pci_chipset_tag_t pc, pcitag_t tag, const int *newstate,
+    int *oldstate)
 {
        int offset;
        pcireg_t value, cap, now;
 
        if (!pci_get_capability(pc, tag, PCI_CAP_PWRMGMT, &offset, &value))
-               return (EOPNOTSUPP);
+               return EOPNOTSUPP;
 
        cap = value >> 16;
        value = pci_conf_read(pc, tag, offset + PCI_PMCSR);
-       now    = value & PCI_PMCSR_STATE_MASK;
+       now = value & PCI_PMCSR_STATE_MASK;
        value &= ~PCI_PMCSR_STATE_MASK;
-       switch (newstate) {
+       if (oldstate) {
+               switch (now) {
+               case PCI_PMCSR_STATE_D0:
+                       *oldstate = PCI_PWR_D0;
+                       break;
+               case PCI_PMCSR_STATE_D1:
+                       *oldstate = PCI_PWR_D1;
+                       break;
+               case PCI_PMCSR_STATE_D2:
+                       *oldstate = PCI_PWR_D2;
+                       break;
+               case PCI_PMCSR_STATE_D3:
+                       *oldstate = PCI_PWR_D3;
+                       break;
+               default:
+                       return EINVAL;
+               }
+       }
+       if (newstate == NULL)
+               return 0;
+       switch (*newstate) {
        case PCI_PWR_D0:
                if (now == PCI_PMCSR_STATE_D0)
-                       return (0);
+                       return 0;
                value |= PCI_PMCSR_STATE_D0;
                break;
        case PCI_PWR_D1:
                if (now == PCI_PMCSR_STATE_D1)
-                       return (0);
+                       return 0;
                if (now == PCI_PMCSR_STATE_D2 || now == PCI_PMCSR_STATE_D3)
-                       return (EINVAL);
+                       return EINVAL;
                if (!(cap & PCI_PMCR_D1SUPP))
-                       return (EOPNOTSUPP);
+                       return EOPNOTSUPP;
                value |= PCI_PMCSR_STATE_D1;
                break;
        case PCI_PWR_D2:
                if (now == PCI_PMCSR_STATE_D2)
-                       return (0);
+                       return 0;
                if (now == PCI_PMCSR_STATE_D3)
-                       return (EINVAL);
+                       return EINVAL;
                if (!(cap & PCI_PMCR_D2SUPP))
-                       return (EOPNOTSUPP);
+                       return EOPNOTSUPP;
                value |= PCI_PMCSR_STATE_D2;
                break;
        case PCI_PWR_D3:
                if (now == PCI_PMCSR_STATE_D3)
-                       return (0);
+                       return 0;
                value |= PCI_PMCSR_STATE_D3;
                break;
        default:
-               return (EINVAL);
+               return EINVAL;
        }
        pci_conf_write(pc, tag, offset + PCI_PMCSR, value);
        DELAY(1000);
 
-       return (0);
-}
-
-int
-pci_get_powerstate(pci_chipset_tag_t pc, pcitag_t tag)
-{
-       int offset;
-       pcireg_t value;
-
-       if (!pci_get_capability(pc, tag, PCI_CAP_PWRMGMT, &offset, &value))
-               return (PCI_PWR_D0);
-       value = pci_conf_read(pc, tag, offset + PCI_PMCSR);
-       value &= PCI_PMCSR_STATE_MASK;
-       switch (value) {
-       case PCI_PMCSR_STATE_D0:
-               return (PCI_PWR_D0);
-       case PCI_PMCSR_STATE_D1:
-               return (PCI_PWR_D1);
-       case PCI_PMCSR_STATE_D2:
-               return (PCI_PWR_D2);
-       case PCI_PMCSR_STATE_D3:
-               return (PCI_PWR_D3);
-       }
-
-       return (PCI_PWR_D0);
+       return 0;
 }
 
 /*
diff -r 6cb0aa6271f2 -r faf6e7b1c8bf sys/dev/pci/pcivar.h
--- a/sys/dev/pci/pcivar.h      Sat May 08 23:40:01 2004 +0000
+++ b/sys/dev/pci/pcivar.h      Sat May 08 23:41:40 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pcivar.h,v 1.60 2004/04/23 21:13:07 itojun Exp $       */
+/*     $NetBSD: pcivar.h,v 1.61 2004/05/08 23:41:40 christos Exp $     */
 
 /*
  * Copyright (c) 1996, 1997 Christopher G. Demetriou.  All rights reserved.
@@ -228,8 +228,7 @@
 #define PCI_PWR_D1     1
 #define PCI_PWR_D2     2
 #define PCI_PWR_D3     3
-int    pci_set_powerstate __P((pci_chipset_tag_t, pcitag_t, int));
-int    pci_get_powerstate __P((pci_chipset_tag_t, pcitag_t));
+int    pci_powerstate __P((pci_chipset_tag_t, pcitag_t, const int *, int *));
 
 /*
  * Vital Product Data (PCI 2.2)



Home | Main Index | Thread Index | Old Index