Module Name:    src
Committed By:   jmcneill
Date:           Thu Aug 19 14:59:24 UTC 2010

Modified Files:
        src/sys/dev/acpi: wb_acpi.c

Log Message:
add pmf support


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/acpi/wb_acpi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/wb_acpi.c
diff -u src/sys/dev/acpi/wb_acpi.c:1.2 src/sys/dev/acpi/wb_acpi.c:1.3
--- src/sys/dev/acpi/wb_acpi.c:1.2	Fri Mar  5 14:00:17 2010
+++ src/sys/dev/acpi/wb_acpi.c	Thu Aug 19 14:59:24 2010
@@ -1,4 +1,4 @@
-/* $NetBSD: wb_acpi.c,v 1.2 2010/03/05 14:00:17 jruoho Exp $ */
+/* $NetBSD: wb_acpi.c,v 1.3 2010/08/19 14:59:24 jmcneill Exp $ */
 
 /*
  * Copyright (c) 2009 Jared D. McNeill <jmcne...@invisible.ca>
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: wb_acpi.c,v 1.2 2010/03/05 14:00:17 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wb_acpi.c,v 1.3 2010/08/19 14:59:24 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -44,12 +44,17 @@
 static int	wb_acpi_match(device_t, cfdata_t, void *);
 static void	wb_acpi_attach(device_t, device_t, void *);
 static int	wb_acpi_detach(device_t, int);
+static bool	wb_acpi_suspend(device_t, const pmf_qual_t *);
+static bool	wb_acpi_resume(device_t, const pmf_qual_t *);
 
 struct wb_acpi_softc {
 	struct wb_softc sc_wb;
 	isa_chipset_tag_t sc_ic;
 	void *sc_ih;
 	int sc_ioh_length;
+
+	ACPI_HANDLE sc_crs, sc_srs;
+	ACPI_BUFFER sc_crs_buffer;
 };
 
 CFATTACH_DECL_NEW(wb_acpi, sizeof(struct wb_acpi_softc),
@@ -96,6 +101,16 @@
 	if (ACPI_FAILURE(rv))
 		return;
 
+	AcpiGetHandle(aa->aa_node->ad_handle, "_CRS", &sc->sc_crs);
+	AcpiGetHandle(aa->aa_node->ad_handle, "_SRS", &sc->sc_srs);
+	if (sc->sc_crs && sc->sc_srs) {
+		sc->sc_crs_buffer.Pointer = NULL;
+		sc->sc_crs_buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
+		rv = AcpiGetCurrentResources(sc->sc_crs, &sc->sc_crs_buffer);
+		if (ACPI_FAILURE(rv))
+			sc->sc_crs = sc->sc_srs = NULL;
+	}
+
 	io = acpi_res_io(&res, 0);
 	irq = acpi_res_irq(&res, 0);
 	if (io == NULL || irq == NULL) {
@@ -125,6 +140,8 @@
 	sc->sc_wb.wb_irq = irq->ar_irq;
 	sc->sc_wb.wb_base = io->ar_base;
 	wb_attach(&sc->sc_wb);
+
+	pmf_device_register(self, wb_acpi_suspend, wb_acpi_resume);
 	
 cleanup:
 	acpi_resource_cleanup(&res);
@@ -136,6 +153,11 @@
 	struct wb_acpi_softc *sc = device_private(self);
 	int rv;
 
+	pmf_device_deregister(self);
+
+	if (sc->sc_crs_buffer.Pointer)
+		ACPI_FREE(sc->sc_crs_buffer.Pointer);
+
 	rv = wb_detach(&sc->sc_wb, flags);
 	if (rv)
 		return rv;
@@ -149,3 +171,27 @@
 
 	return 0;
 }
+
+static bool
+wb_acpi_suspend(device_t self, const pmf_qual_t *qual)
+{
+	struct wb_acpi_softc *sc = device_private(self);
+
+	return wb_suspend(&sc->sc_wb);
+}
+
+static bool
+wb_acpi_resume(device_t self, const pmf_qual_t *qual)
+{
+	struct wb_acpi_softc *sc = device_private(self);
+	ACPI_STATUS rv;
+
+	if (sc->sc_crs && sc->sc_srs) {
+		rv = AcpiSetCurrentResources(sc->sc_srs, &sc->sc_crs_buffer);
+		if (ACPI_FAILURE(rv))
+			printf("%s: _SRS failed: %s\n",
+			    device_xname(self), AcpiFormatException(rv));
+	}
+
+	return wb_resume(&sc->sc_wb);
+}

Reply via email to