Module Name:    src
Committed By:   jruoho
Date:           Tue Jun 14 13:59:24 UTC 2011

Modified Files:
        src/share/man/man4/man4.x86: hpet.4
        src/sys/arch/amd64/conf: GENERIC
        src/sys/arch/i386/conf: ALL GENERIC
        src/sys/dev/acpi: acpi.c acpivar.h files.acpi hpet_acpi.c

Log Message:
Try to attach hpet(4) also via a specific HPET table. Fixes PR kern/43702.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/share/man/man4/man4.x86/hpet.4
cvs rdiff -u -r1.319 -r1.320 src/sys/arch/amd64/conf/GENERIC
cvs rdiff -u -r1.307 -r1.308 src/sys/arch/i386/conf/ALL
cvs rdiff -u -r1.1032 -r1.1033 src/sys/arch/i386/conf/GENERIC
cvs rdiff -u -r1.244 -r1.245 src/sys/dev/acpi/acpi.c
cvs rdiff -u -r1.69 -r1.70 src/sys/dev/acpi/acpivar.h
cvs rdiff -u -r1.89 -r1.90 src/sys/dev/acpi/files.acpi
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/acpi/hpet_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/share/man/man4/man4.x86/hpet.4
diff -u src/share/man/man4/man4.x86/hpet.4:1.2 src/share/man/man4/man4.x86/hpet.4:1.3
--- src/share/man/man4/man4.x86/hpet.4:1.2	Sun Mar 13 04:58:55 2011
+++ src/share/man/man4/man4.x86/hpet.4	Tue Jun 14 13:59:24 2011
@@ -1,4 +1,4 @@
-.\"	$NetBSD: hpet.4,v 1.2 2011/03/13 04:58:55 jruoho Exp $
+.\"	$NetBSD: hpet.4,v 1.3 2011/06/14 13:59:24 jruoho Exp $
 .\"
 .\" Copyright (c) 2010 Jukka Ruohonen <[email protected]>
 .\" All rights reserved.
@@ -24,14 +24,15 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd March 13, 2011
+.Dd June 14, 2011
 .Dt HPET 4 x86
 .Os
 .Sh NAME
 .Nm hpet
 .Nd High Precision Event Timer
 .Sh SYNOPSIS
-.Cd "hpet* at acpi?"
+.Cd "hpet* at acpihpetbus?"
+.Cd "hpet* at acpinodebus?"
 .Cd "hpet* at amdpcib?"
 .Cd "hpet* at ichlpcib?"
 .Sh DESCRIPTION

Index: src/sys/arch/amd64/conf/GENERIC
diff -u src/sys/arch/amd64/conf/GENERIC:1.319 src/sys/arch/amd64/conf/GENERIC:1.320
--- src/sys/arch/amd64/conf/GENERIC:1.319	Sat May 28 16:58:51 2011
+++ src/sys/arch/amd64/conf/GENERIC	Tue Jun 14 13:59:23 2011
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.319 2011/05/28 16:58:51 ryo Exp $
+# $NetBSD: GENERIC,v 1.320 2011/06/14 13:59:23 jruoho Exp $
 #
 # GENERIC machine description file
 #
@@ -22,7 +22,7 @@
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident 		"GENERIC-$Revision: 1.319 $"
+#ident 		"GENERIC-$Revision: 1.320 $"
 
 maxusers	64		# estimated number of users
 
@@ -301,7 +301,8 @@
 fujbp*		at acpi?		# Fujitsu Brightness & Pointer
 fujhk*		at acpi?		# Fujitsu Hotkeys
 hpqlb*		at acpi?		# HP Quick Launch Buttons
-hpet*		at acpi?		# High Precision Event Timer
+hpet*		at acpihpetbus?		# High Precision Event Timer (table)
+hpet*		at acpinodebus?		# High Precision Event Timer (device)
 joy*		at acpi?		# Joystick/Game port
 #lpt*		at acpi?		# Parallel port
 mpu*		at acpi?		# Roland MPU-401 MIDI UART

Index: src/sys/arch/i386/conf/ALL
diff -u src/sys/arch/i386/conf/ALL:1.307 src/sys/arch/i386/conf/ALL:1.308
--- src/sys/arch/i386/conf/ALL:1.307	Sat May 28 13:01:49 2011
+++ src/sys/arch/i386/conf/ALL	Tue Jun 14 13:59:23 2011
@@ -1,4 +1,4 @@
-# $NetBSD: ALL,v 1.307 2011/05/28 13:01:49 ryo Exp $
+# $NetBSD: ALL,v 1.308 2011/06/14 13:59:23 jruoho Exp $
 # From NetBSD: GENERIC,v 1.787 2006/10/01 18:37:54 bouyer Exp
 #
 # ALL machine description file
@@ -17,7 +17,7 @@
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident 		"ALL-$Revision: 1.307 $"
+#ident 		"ALL-$Revision: 1.308 $"
 
 maxusers	64		# estimated number of users
 
@@ -377,7 +377,8 @@
 fujbp*		at acpi?		# Fujitsu Brightness & Pointer
 fujhk*		at acpi?		# Fujitsu Hotkeys
 hpqlb*		at acpi?		# HP Quick Launch Buttons
-hpet*		at acpi?		# High Precision Event Timer
+hpet*		at acpihpetbus?		# High Precision Event Timer (table)
+hpet*		at acpinodebus?		# High Precision Event Timer (device)
 joy*		at acpi?		# Joystick/Game port
 lpt*		at acpi?		# Parallel port
 mpu*		at acpi?		# Roland MPU-401 MIDI UART

Index: src/sys/arch/i386/conf/GENERIC
diff -u src/sys/arch/i386/conf/GENERIC:1.1032 src/sys/arch/i386/conf/GENERIC:1.1033
--- src/sys/arch/i386/conf/GENERIC:1.1032	Sat May 28 13:01:49 2011
+++ src/sys/arch/i386/conf/GENERIC	Tue Jun 14 13:59:23 2011
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.1032 2011/05/28 13:01:49 ryo Exp $
+# $NetBSD: GENERIC,v 1.1033 2011/06/14 13:59:23 jruoho Exp $
 #
 # GENERIC machine description file
 #
@@ -22,7 +22,7 @@
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident 		"GENERIC-$Revision: 1.1032 $"
+#ident 		"GENERIC-$Revision: 1.1033 $"
 
 maxusers	64		# estimated number of users
 
@@ -366,7 +366,8 @@
 fujbp*		at acpi?		# Fujitsu Brightness & Pointer
 fujhk*		at acpi?		# Fujitsu Hotkeys
 hpqlb*		at acpi?		# HP Quick Launch Buttons
-hpet*		at acpi?		# High Precision Event Timer
+hpet*		at acpihpetbus?		# High Precision Event Timer (table)
+hpet*		at acpinodebus?		# High Precision Event Timer (device)
 joy*		at acpi?		# Joystick/Game port
 #lpt*		at acpi?		# Parallel port
 mpu*		at acpi?		# Roland MPU-401 MIDI UART

Index: src/sys/dev/acpi/acpi.c
diff -u src/sys/dev/acpi/acpi.c:1.244 src/sys/dev/acpi/acpi.c:1.245
--- src/sys/dev/acpi/acpi.c:1.244	Mon Jun 13 09:37:23 2011
+++ src/sys/dev/acpi/acpi.c	Tue Jun 14 13:59:23 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi.c,v 1.244 2011/06/13 09:37:23 jruoho Exp $	*/
+/*	$NetBSD: acpi.c,v 1.245 2011/06/14 13:59:23 jruoho Exp $	*/
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -100,7 +100,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.244 2011/06/13 09:37:23 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.245 2011/06/14 13:59:23 jruoho Exp $");
 
 #include "opt_acpi.h"
 #include "opt_pcifixup.h"
@@ -554,6 +554,9 @@
 	if (sc->sc_apmbus == child)
 		sc->sc_apmbus = NULL;
 
+	if (sc->sc_hpet == child)
+		sc->sc_hpet = NULL;
+
 	if (sc->sc_wdrt == child)
 		sc->sc_wdrt = NULL;
 
@@ -752,6 +755,16 @@
 acpi_rescan(device_t self, const char *ifattr, const int *locators)
 {
 	struct acpi_softc *sc = device_private(self);
+	struct acpi_attach_args aa;
+
+	/*
+	 * Try to attach hpet(4) first via a specific table.
+	 */
+	aa.aa_memt = sc->sc_memt;
+
+	if (ifattr_match(ifattr, "acpihpetbus") && sc->sc_hpet == NULL)
+		sc->sc_hpet = config_found_ia(sc->sc_dev,
+		    "acpihpetbus", &aa, NULL);
 
 	/*
 	 * A two-pass scan for acpinodebus.
@@ -761,6 +774,9 @@
 		acpi_rescan_nodes(sc);
 	}
 
+	/*
+	 * Attach APM emulation and acpiwdrt(4).
+	 */
 	if (ifattr_match(ifattr, "acpiapmbus") && sc->sc_apmbus == NULL)
 		sc->sc_apmbus = config_found_ia(sc->sc_dev,
 		    "acpiapmbus", NULL, NULL);
@@ -810,6 +826,7 @@
 static void
 acpi_rescan_nodes(struct acpi_softc *sc)
 {
+	const char * const hpet_ids[] = { "PNP0103", NULL };
 	struct acpi_attach_args aa;
 	struct acpi_devnode *ad;
 	ACPI_DEVICE_INFO *di;
@@ -855,6 +872,9 @@
 		if (acpi_match_hid(di, acpi_ignored_ids) != 0)
 			continue;
 
+		if (acpi_match_hid(di, hpet_ids) != 0 && sc->sc_hpet != NULL)
+			continue;
+
 		aa.aa_node = ad;
 		aa.aa_iot = sc->sc_iot;
 		aa.aa_memt = sc->sc_memt;

Index: src/sys/dev/acpi/acpivar.h
diff -u src/sys/dev/acpi/acpivar.h:1.69 src/sys/dev/acpi/acpivar.h:1.70
--- src/sys/dev/acpi/acpivar.h:1.69	Sun Feb 20 06:45:32 2011
+++ src/sys/dev/acpi/acpivar.h	Tue Jun 14 13:59:23 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpivar.h,v 1.69 2011/02/20 06:45:32 jruoho Exp $	*/
+/*	$NetBSD: acpivar.h,v 1.70 2011/06/14 13:59:23 jruoho Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -149,8 +149,8 @@
 struct acpi_softc {
 	device_t		 sc_dev;	/* base device info */
 	device_t		 sc_apmbus;	/* APM pseudo-bus */
-
-	device_t		 sc_wdrt;	/* WDRT watchdog */
+	device_t		 sc_hpet;	/* hpet(4) pseudo-bus */
+	device_t		 sc_wdrt;	/* acpiwdrt(4) pseudo-bus */
 
 	struct acpi_devnode	*sc_root;	/* root of the device tree */
 

Index: src/sys/dev/acpi/files.acpi
diff -u src/sys/dev/acpi/files.acpi:1.89 src/sys/dev/acpi/files.acpi:1.90
--- src/sys/dev/acpi/files.acpi:1.89	Sun Jun 12 07:25:43 2011
+++ src/sys/dev/acpi/files.acpi	Tue Jun 14 13:59:23 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: files.acpi,v 1.89 2011/06/12 07:25:43 jruoho Exp $
+#	$NetBSD: files.acpi,v 1.90 2011/06/14 13:59:23 jruoho Exp $
 
 include "dev/acpi/acpica/files.acpica"
 
@@ -10,9 +10,10 @@
 define	acpiapmbus { }
 define	acpinodebus { }
 define	acpiecdtbus { }
+define	acpihpetbus { }
 define	acpiwdrtbus { }
 
-device	acpi: acpica, acpiapmbus, acpinodebus, acpiecdtbus, acpiwdrtbus, sysmon_power, sysmon_taskq
+device	acpi: acpica, acpiapmbus, acpinodebus, acpiecdtbus, acpihpetbus, acpiwdrtbus, sysmon_power, sysmon_taskq
 attach	acpi at acpibus
 file	dev/acpi/acpi.c			acpi
 file	dev/acpi/acpi_debug.c		acpi
@@ -130,8 +131,9 @@
 file	dev/acpi/ym_acpi.c		ym_acpi
 
 # High Precision Event Timer
-attach 	hpet at acpinodebus with hpet_acpi
-file 	dev/acpi/hpet_acpi.c		hpet_acpi
+attach 	hpet at acpinodebus with hpet_acpi_dev
+attach 	hpet at acpihpetbus with hpet_acpi_tab
+file 	dev/acpi/hpet_acpi.c		hpet_acpi_dev|hpet_acpi_tab
 
 # ASUS hotkey device
 device	asus: sysmon_envsys, sysmon_power

Index: src/sys/dev/acpi/hpet_acpi.c
diff -u src/sys/dev/acpi/hpet_acpi.c:1.5 src/sys/dev/acpi/hpet_acpi.c:1.6
--- src/sys/dev/acpi/hpet_acpi.c:1.5	Fri Mar  5 14:00:17 2010
+++ src/sys/dev/acpi/hpet_acpi.c	Tue Jun 14 13:59:23 2011
@@ -1,7 +1,7 @@
-/* $NetBSD: hpet_acpi.c,v 1.5 2010/03/05 14:00:17 jruoho Exp $ */
+/* $NetBSD: hpet_acpi.c,v 1.6 2011/06/14 13:59:23 jruoho Exp $ */
 
 /*
- * Copyright (c) 2006 Nicolas Joly
+ * Copyright (c) 2006, 2011 Nicolas Joly
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -27,41 +27,91 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  */
-
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hpet_acpi.c,v 1.5 2010/03/05 14:00:17 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hpet_acpi.c,v 1.6 2011/06/14 13:59:23 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
-#include <sys/systm.h>
 #include <sys/time.h>
 #include <sys/timetc.h>
 
 #include <dev/acpi/acpivar.h>
-
 #include <dev/ic/hpetvar.h>
 
-static int	hpet_acpi_match(device_t, cfdata_t, void *);
-static void	hpet_acpi_attach(device_t, device_t, void *);
+#define _COMPONENT	ACPI_RESOURCE_COMPONENT
+ACPI_MODULE_NAME	("acpi_hpet")
 
+#define HPET_MEM_WIDTH	0x3ff   /* Expected memory region size. */
 
-CFATTACH_DECL_NEW(hpet_acpi, sizeof(struct hpet_softc), hpet_acpi_match,
-    hpet_acpi_attach, NULL, NULL);
-
-/*
- * Supported device IDs
- */
+static int		hpet_acpi_dev_match(device_t, cfdata_t, void *);
+static void		hpet_acpi_dev_attach(device_t, device_t, void *);
+static int		hpet_acpi_tab_match(device_t, cfdata_t, void *);
+static void		hpet_acpi_tab_attach(device_t, device_t, void *);
 
 static const char * const hpet_acpi_ids[] = {
 	"PNP0103",
-	NULL
+        NULL
 };
 
-/*
- * hpet_acpi_match: autoconf(9) match routine
- */
+CFATTACH_DECL_NEW(hpet_acpi_tab, sizeof(struct hpet_softc),
+    hpet_acpi_tab_match, hpet_acpi_tab_attach, NULL, NULL);
+
+CFATTACH_DECL_NEW(hpet_acpi_dev, sizeof(struct hpet_softc),
+    hpet_acpi_dev_match, hpet_acpi_dev_attach, NULL, NULL);
+
 static int
-hpet_acpi_match(device_t parent, cfdata_t match, void *aux)
+hpet_acpi_tab_match(device_t parent, cfdata_t match, void *aux)
+{
+	ACPI_TABLE_HPET *hpet;
+	ACPI_STATUS rv;
+
+	rv = AcpiGetTable(ACPI_SIG_HPET, 1, (ACPI_TABLE_HEADER **)&hpet);
+
+	if (ACPI_FAILURE(rv))
+		return 0;
+
+	if (hpet->Address.Address == 0)
+		return 0;
+
+	if (hpet->Address.SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY)
+		return 0;
+
+	return 1;
+}
+
+static void
+hpet_acpi_tab_attach(device_t parent, device_t self, void *aux)
+{
+	struct hpet_softc *sc = device_private(self);
+	struct acpi_attach_args *aa = aux;
+	ACPI_TABLE_HPET *hpet;
+	ACPI_STATUS rv;
+
+	rv = AcpiGetTable(ACPI_SIG_HPET, 1, (ACPI_TABLE_HEADER **)&hpet);
+
+	if (ACPI_FAILURE(rv))
+		return;
+
+	sc->sc_memt = aa->aa_memt;
+
+	if (hpet->Address.Address == 0xfed0000000000000UL) /* A quirk. */
+		hpet->Address.Address >>= 32;
+
+	if (bus_space_map(sc->sc_memt, hpet->Address.Address,
+		HPET_MEM_WIDTH, 0, &sc->sc_memh) != 0) {
+		aprint_error(": failed to map mem space\n");
+		return;
+	}
+
+	aprint_naive("\n");
+	aprint_normal(": mem 0x%"PRIx64"-0x%"PRIx64"\n",
+	    hpet->Address.Address, hpet->Address.Address + HPET_MEM_WIDTH);
+
+	hpet_attach_subr(self);
+}
+
+static int
+hpet_acpi_dev_match(device_t parent, cfdata_t match, void *aux)
 {
 	struct acpi_attach_args *aa = aux;
 
@@ -72,7 +122,7 @@
 }
 
 static void
-hpet_acpi_attach(device_t parent, device_t self, void *aux)
+hpet_acpi_dev_attach(device_t parent, device_t self, void *aux)
 {
 	struct hpet_softc *sc = device_private(self);
 	struct acpi_attach_args *aa = aux;
@@ -80,29 +130,34 @@
 	struct acpi_mem *mem;
 	ACPI_STATUS rv;
 
-	/* parse resources */
 	rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS",
 	    &res, &acpi_resource_parse_ops_default);
+
 	if (ACPI_FAILURE(rv))
 		return;
 
-	/* find our mem registers */
 	mem = acpi_res_mem(&res, 0);
+
 	if (mem == NULL) {
-		aprint_error_dev(self,
-		    "unable to find mem register resource\n");
+		aprint_error(": failed to find mem resource\n");
+		goto out;
+	}
+
+	if (mem->ar_length < HPET_MEM_WIDTH) {
+		aprint_error(": invalid memory region size\n");
 		goto out;
 	}
 
 	sc->sc_memt = aa->aa_memt;
-	if (bus_space_map(sc->sc_memt, mem->ar_base, mem->ar_length,
-		    0, &sc->sc_memh)) {
-		aprint_error_dev(self, "can't map mem space\n");
+
+	if (bus_space_map(sc->sc_memt, mem->ar_base,
+		mem->ar_length, 0, &sc->sc_memh) != 0) {
+		aprint_error(": failed to map mem space\n");
 		goto out;
 	}
 
 	hpet_attach_subr(self);
 
- out:
+out:
 	acpi_resource_cleanup(&res);
 }

Reply via email to