Module Name: src
Committed By: jruoho
Date: Wed Jun 15 08:19:44 UTC 2011
Modified Files:
src/distrib/sets/lists/modules: md.amd64 md.i386
src/sys/arch/x86/pci: amdpcib_hpet.c ichlpcib_hpet.c
src/sys/dev/acpi: hpet_acpi.c
src/sys/modules: Makefile
Added Files:
src/sys/modules/hpet: Makefile hpet.ioconf
Log Message:
Modularize hpet(4). Works nicely with the multiple bus locations.
To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/distrib/sets/lists/modules/md.amd64
cvs rdiff -u -r1.25 -r1.26 src/distrib/sets/lists/modules/md.i386
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/x86/pci/amdpcib_hpet.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/x86/pci/ichlpcib_hpet.c
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/acpi/hpet_acpi.c
cvs rdiff -u -r1.71 -r1.72 src/sys/modules/Makefile
cvs rdiff -u -r0 -r1.1 src/sys/modules/hpet/Makefile \
src/sys/modules/hpet/hpet.ioconf
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/distrib/sets/lists/modules/md.amd64
diff -u src/distrib/sets/lists/modules/md.amd64:1.21 src/distrib/sets/lists/modules/md.amd64:1.22
--- src/distrib/sets/lists/modules/md.amd64:1.21 Wed Jun 15 03:22:39 2011
+++ src/distrib/sets/lists/modules/md.amd64 Wed Jun 15 08:19:43 2011
@@ -1,4 +1,4 @@
-# $NetBSD: md.amd64,v 1.21 2011/06/15 03:22:39 jruoho Exp $
+# $NetBSD: md.amd64,v 1.22 2011/06/15 08:19:43 jruoho Exp $
./@MODULEDIR@/acpiacad base-kernel-modules kmod
./@MODULEDIR@/acpiacad/acpiacad.kmod base-kernel-modules kmod
./@MODULEDIR@/acpibat base-kernel-modules kmod
@@ -57,6 +57,8 @@
./@MODULEDIR@/fujbp/fujbp.kmod base-kernel-modules kmod
./@MODULEDIR@/fujhk base-kernel-modules kmod
./@MODULEDIR@/fujhk/fujhk.kmod base-kernel-modules kmod
+./@MODULEDIR@/hpet base-kernel-modules kmod
+./@MODULEDIR@/hpet/hpet.kmod base-kernel-modules kmod
./@MODULEDIR@/hpqlb base-kernel-modules kmod
./@MODULEDIR@/hpqlb/hpqlb.kmod base-kernel-modules kmod
./@MODULEDIR@/i915drm base-kernel-modules kmod
Index: src/distrib/sets/lists/modules/md.i386
diff -u src/distrib/sets/lists/modules/md.i386:1.25 src/distrib/sets/lists/modules/md.i386:1.26
--- src/distrib/sets/lists/modules/md.i386:1.25 Wed Jun 15 03:22:39 2011
+++ src/distrib/sets/lists/modules/md.i386 Wed Jun 15 08:19:43 2011
@@ -1,4 +1,4 @@
-# $NetBSD: md.i386,v 1.25 2011/06/15 03:22:39 jruoho Exp $
+# $NetBSD: md.i386,v 1.26 2011/06/15 08:19:43 jruoho Exp $
./@MODULEDIR@/acpiacad base-kernel-modules kmod
./@MODULEDIR@/acpiacad/acpiacad.kmod base-kernel-modules kmod
./@MODULEDIR@/acpibat base-kernel-modules kmod
@@ -59,6 +59,8 @@
./@MODULEDIR@/fujbp/fujbp.kmod base-kernel-modules kmod
./@MODULEDIR@/fujhk base-kernel-modules kmod
./@MODULEDIR@/fujhk/fujhk.kmod base-kernel-modules kmod
+./@MODULEDIR@/hpet base-kernel-modules kmod
+./@MODULEDIR@/hpet/hpet.kmod base-kernel-modules kmod
./@MODULEDIR@/hpqlb base-kernel-modules kmod
./@MODULEDIR@/hpqlb/hpqlb.kmod base-kernel-modules kmod
./@MODULEDIR@/i915drm base-kernel-modules kmod
Index: src/sys/arch/x86/pci/amdpcib_hpet.c
diff -u src/sys/arch/x86/pci/amdpcib_hpet.c:1.6 src/sys/arch/x86/pci/amdpcib_hpet.c:1.7
--- src/sys/arch/x86/pci/amdpcib_hpet.c:1.6 Wed Jun 15 04:52:52 2011
+++ src/sys/arch/x86/pci/amdpcib_hpet.c Wed Jun 15 08:19:43 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: amdpcib_hpet.c,v 1.6 2011/06/15 04:52:52 jruoho Exp $ */
+/* $NetBSD: amdpcib_hpet.c,v 1.7 2011/06/15 08:19:43 jruoho Exp $ */
/*
* Copyright (c) 2006 Nicolas Joly
@@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: amdpcib_hpet.c,v 1.6 2011/06/15 04:52:52 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amdpcib_hpet.c,v 1.7 2011/06/15 08:19:43 jruoho Exp $");
#include <sys/systm.h>
#include <sys/device.h>
@@ -49,6 +49,7 @@
static int amdpcib_hpet_match(device_t , cfdata_t , void *);
static void amdpcib_hpet_attach(device_t, device_t, void *);
static int amdpcib_hpet_detach(device_t, int);
+static pcireg_t amdpcib_hpet_addr(struct pci_attach_args *);
CFATTACH_DECL_NEW(amdpcib_hpet, sizeof(struct hpet_softc),
amdpcib_hpet_match, amdpcib_hpet_attach, amdpcib_hpet_detach, NULL);
@@ -56,6 +57,23 @@
static int
amdpcib_hpet_match(device_t parent, cfdata_t match, void *aux)
{
+ struct pci_attach_args *pa = aux;
+ bus_space_handle_t bh;
+ bus_space_tag_t bt;
+ pcireg_t addr;
+
+ addr = amdpcib_hpet_addr(pa);
+
+ if (addr == 0)
+ return 0;
+
+ bt = pa->pa_memt;
+
+ if (bus_space_map(bt, addr, HPET_WINDOW_SIZE, 0, &bh) != 0)
+ return 0;
+
+ bus_space_unmap(bt, bh, HPET_WINDOW_SIZE);
+
return 1;
}
@@ -64,29 +82,28 @@
{
struct hpet_softc *sc = device_private(self);
struct pci_attach_args *pa = aux;
- pcireg_t conf, addr;
-
- aprint_naive("\n");
- aprint_normal(": HPET timer\n");
+ pcireg_t addr;
sc->sc_mapped = false;
- conf = pci_conf_read(pa->pa_pc, pa->pa_tag, 0xa0);
+ addr = amdpcib_hpet_addr(pa);
- if ((conf & 1) == 0) {
- aprint_normal_dev(self, "HPET timer is disabled\n");
+ if (addr == 0) {
+ aprint_error(": failed to get address\n");
return;
}
sc->sc_memt = pa->pa_memt;
sc->sc_mems = HPET_WINDOW_SIZE;
- addr = conf & 0xfffffc00;
-
if (bus_space_map(sc->sc_memt, addr, sc->sc_mems, 0, &sc->sc_memh)) {
- aprint_error_dev(self, "failed to map mem space\n");
+ aprint_error(": failed to map mem space\n");
return;
}
+ aprint_naive("\n");
+ aprint_normal(": high precision event timer (mem 0x%08x-0x%08x)\n",
+ addr, addr + HPET_WINDOW_SIZE);
+
sc->sc_mapped = true;
hpet_attach_subr(self);
}
@@ -109,3 +126,16 @@
return 0;
}
+
+static pcireg_t
+amdpcib_hpet_addr(struct pci_attach_args *pa)
+{
+ pcireg_t conf;
+
+ conf = pci_conf_read(pa->pa_pc, pa->pa_tag, 0xa0);
+
+ if ((conf & 1) == 0)
+ return 0;
+
+ return conf & 0xfffffc00;
+}
Index: src/sys/arch/x86/pci/ichlpcib_hpet.c
diff -u src/sys/arch/x86/pci/ichlpcib_hpet.c:1.1 src/sys/arch/x86/pci/ichlpcib_hpet.c:1.2
--- src/sys/arch/x86/pci/ichlpcib_hpet.c:1.1 Wed Jun 15 06:43:21 2011
+++ src/sys/arch/x86/pci/ichlpcib_hpet.c Wed Jun 15 08:19:43 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: ichlpcib_hpet.c,v 1.1 2011/06/15 06:43:21 jruoho Exp $ */
+/* $NetBSD: ichlpcib_hpet.c,v 1.2 2011/06/15 08:19:43 jruoho Exp $ */
/*-
* Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ichlpcib_hpet.c,v 1.1 2011/06/15 06:43:21 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ichlpcib_hpet.c,v 1.2 2011/06/15 08:19:43 jruoho Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -59,10 +59,8 @@
bt = arg->hpet_mem_t;
- if (bus_space_map(bt, arg->hpet_reg, HPET_WINDOW_SIZE, 0, &bh) != 0) {
- aprint_verbose_dev(parent, "mem space not mapped, skipping\n");
+ if (bus_space_map(bt, arg->hpet_reg, HPET_WINDOW_SIZE, 0, &bh) != 0)
return 0;
- }
bus_space_unmap(bt, bh, HPET_WINDOW_SIZE);
@@ -80,16 +78,16 @@
sc->sc_memt = arg->hpet_mem_t;
sc->sc_mems = HPET_WINDOW_SIZE;
- aprint_naive("\n");
- aprint_normal(": mem 0x%08x-0x%08x\n",
- arg->hpet_reg, arg->hpet_reg + HPET_WINDOW_SIZE);
-
if (bus_space_map(sc->sc_memt, arg->hpet_reg,
sc->sc_mems, 0, &sc->sc_memh) != 0) {
- aprint_error_dev(self, "failed to map mem space\n");
+ aprint_error(": failed to map mem space\n");
return;
}
+ aprint_naive("\n");
+ aprint_normal(": high precision event timer (mem 0x%08x-0x%08x)\n",
+ arg->hpet_reg, arg->hpet_reg + HPET_WINDOW_SIZE);
+
sc->sc_mapped = true;
hpet_attach_subr(self);
}
Index: src/sys/dev/acpi/hpet_acpi.c
diff -u src/sys/dev/acpi/hpet_acpi.c:1.9 src/sys/dev/acpi/hpet_acpi.c:1.10
--- src/sys/dev/acpi/hpet_acpi.c:1.9 Wed Jun 15 04:52:52 2011
+++ src/sys/dev/acpi/hpet_acpi.c Wed Jun 15 08:19:43 2011
@@ -1,7 +1,8 @@
-/* $NetBSD: hpet_acpi.c,v 1.9 2011/06/15 04:52:52 jruoho Exp $ */
+/* $NetBSD: hpet_acpi.c,v 1.10 2011/06/15 08:19:43 jruoho Exp $ */
/*
- * Copyright (c) 2006, 2011 Nicolas Joly
+ * Copyright (c) 2011 Jukka Ruohonen
+ * Copyright (c) 2006 Nicolas Joly
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -28,7 +29,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hpet_acpi.c,v 1.9 2011/06/15 04:52:52 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hpet_acpi.c,v 1.10 2011/06/15 08:19:43 jruoho Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -43,10 +44,12 @@
#define _COMPONENT ACPI_RESOURCE_COMPONENT
ACPI_MODULE_NAME ("acpi_hpet")
-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 bus_addr_t hpet_acpi_tab_addr(void);
+static int hpet_acpi_dev_match(device_t, cfdata_t, void *);
+static void hpet_acpi_dev_attach(device_t, device_t, void *);
+static bus_addr_t hpet_acpi_dev_addr(device_t, void *, bus_size_t *);
static int hpet_acpi_detach(device_t, int);
static const char * const hpet_acpi_ids[] = {
@@ -63,20 +66,23 @@
static int
hpet_acpi_tab_match(device_t parent, cfdata_t match, void *aux)
{
- ACPI_TABLE_HPET *hpet;
- ACPI_STATUS rv;
+ struct acpi_attach_args *aa = aux;
+ bus_space_handle_t bh;
+ bus_space_tag_t bt;
+ bus_addr_t addr;
- rv = AcpiGetTable(ACPI_SIG_HPET, 1, (ACPI_TABLE_HEADER **)&hpet);
+ addr = hpet_acpi_tab_addr();
- if (ACPI_FAILURE(rv))
+ if (addr == 0)
return 0;
- if (hpet->Address.Address == 0)
- return 0;
+ bt = aa->aa_memt;
- if (hpet->Address.SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY)
+ if (bus_space_map(bt, addr, HPET_WINDOW_SIZE, 0, &bh) != 0)
return 0;
+ bus_space_unmap(bt, bh, HPET_WINDOW_SIZE);
+
return 1;
}
@@ -85,46 +91,83 @@
{
struct hpet_softc *sc = device_private(self);
struct acpi_attach_args *aa = aux;
- ACPI_TABLE_HPET *hpet;
- ACPI_STATUS rv;
+ bus_addr_t addr;
sc->sc_mapped = false;
+ addr = hpet_acpi_tab_addr();
- rv = AcpiGetTable(ACPI_SIG_HPET, 1, (ACPI_TABLE_HEADER **)&hpet);
-
- if (ACPI_FAILURE(rv))
+ if (addr == 0) {
+ aprint_error(": failed to get address\n");
return;
+ }
sc->sc_memt = aa->aa_memt;
sc->sc_mems = HPET_WINDOW_SIZE;
- if (hpet->Address.Address == 0xfed0000000000000UL) /* A quirk. */
- hpet->Address.Address >>= 32;
-
- if (bus_space_map(sc->sc_memt, hpet->Address.Address,
- sc->sc_mems, 0, &sc->sc_memh) != 0) {
+ if (bus_space_map(sc->sc_memt, addr, sc->sc_mems, 0, &sc->sc_memh)) {
aprint_error(": failed to map mem space\n");
return;
}
- sc->sc_mapped = true;
-
aprint_naive("\n");
- aprint_normal(": mem 0x%"PRIx64"-0x%"PRIx64"\n",
- hpet->Address.Address, hpet->Address.Address + sc->sc_mems);
+ aprint_normal(": high precision event timer (mem 0x%08x-0x%08x)\n",
+ (uint32_t)addr, (uint32_t)addr + HPET_WINDOW_SIZE);
+ sc->sc_mapped = true;
hpet_attach_subr(self);
}
+static bus_addr_t
+hpet_acpi_tab_addr(void)
+{
+ 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;
+
+ if (hpet->Address.Address == 0xfed0000000000000UL) /* A quirk. */
+ hpet->Address.Address >>= 32;
+
+ return hpet->Address.Address;
+}
+
static int
hpet_acpi_dev_match(device_t parent, cfdata_t match, void *aux)
{
struct acpi_attach_args *aa = aux;
+ bus_space_handle_t bh;
+ bus_space_tag_t bt;
+ bus_size_t len = 0;
+ bus_addr_t addr;
if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
return 0;
- return acpi_match_hid(aa->aa_node->ad_devinfo, hpet_acpi_ids);
+ if (acpi_match_hid(aa->aa_node->ad_devinfo, hpet_acpi_ids) == 0)
+ return 0;
+
+ addr = hpet_acpi_dev_addr(parent, aa, &len);
+
+ if (addr == 0 || len == 0)
+ return 0;
+
+ bt = aa->aa_memt;
+
+ if (bus_space_map(bt, addr, len, 0, &bh) == 0) {
+ bus_space_unmap(bt, bh, len);
+ return 1;
+ }
+
+ return 0;
}
static void
@@ -132,44 +175,61 @@
{
struct hpet_softc *sc = device_private(self);
struct acpi_attach_args *aa = aux;
+ bus_addr_t addr;
+
+ sc->sc_mapped = false;
+ addr = hpet_acpi_dev_addr(self, aa, &sc->sc_mems);
+
+ if (addr == 0) {
+ aprint_error(": failed to get address\n");
+ return;
+ }
+
+ sc->sc_memt = aa->aa_memt;
+
+ if (bus_space_map(sc->sc_memt, addr, sc->sc_mems, 0, &sc->sc_memh)) {
+ aprint_error(": failed to map mem space\n");
+ return;
+ }
+
+ aprint_naive("\n");
+ aprint_normal(": high precision event timer (mem 0x%08x-0x%08x)\n",
+ (uint32_t)addr, (uint32_t)(addr + sc->sc_mems));
+
+ sc->sc_mapped = true;
+ hpet_attach_subr(self);
+}
+
+static bus_addr_t
+hpet_acpi_dev_addr(device_t self, void *aux, bus_size_t *len)
+{
+ struct acpi_attach_args *aa = aux;
struct acpi_resources res;
struct acpi_mem *mem;
+ bus_addr_t addr = 0;
ACPI_STATUS rv;
- sc->sc_mapped = false;
-
rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS",
&res, &acpi_resource_parse_ops_default);
if (ACPI_FAILURE(rv))
- return;
+ return 0;
mem = acpi_res_mem(&res, 0);
- if (mem == NULL) {
- aprint_error(": failed to find mem resource\n");
+ if (mem == NULL)
goto out;
- }
- if (mem->ar_length < HPET_WINDOW_SIZE) {
- aprint_error(": invalid memory region size\n");
+ if (mem->ar_length < HPET_WINDOW_SIZE)
goto out;
- }
- sc->sc_memt = aa->aa_memt;
- sc->sc_mems = mem->ar_length;
-
- if (bus_space_map(sc->sc_memt, mem->ar_base,
- sc->sc_mems, 0, &sc->sc_memh) != 0) {
- aprint_error(": failed to map mem space\n");
- goto out;
- }
-
- sc->sc_mapped = true;
- hpet_attach_subr(self);
+ addr = mem->ar_base;
+ *len = mem->ar_length;
out:
acpi_resource_cleanup(&res);
+
+ return addr;
}
static int
Index: src/sys/modules/Makefile
diff -u src/sys/modules/Makefile:1.71 src/sys/modules/Makefile:1.72
--- src/sys/modules/Makefile:1.71 Wed Jun 15 03:22:40 2011
+++ src/sys/modules/Makefile Wed Jun 15 08:19:43 2011
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.71 2011/06/15 03:22:40 jruoho Exp $
+# $NetBSD: Makefile,v 1.72 2011/06/15 08:19:43 jruoho Exp $
.include <bsd.own.mk>
@@ -92,6 +92,7 @@
SUBDIR+= amdtemp
SUBDIR+= coretemp
SUBDIR+= est
+SUBDIR+= hpet
SUBDIR+= odcm
SUBDIR+= powernow
SUBDIR+= tprof_pmi
Added files:
Index: src/sys/modules/hpet/Makefile
diff -u /dev/null src/sys/modules/hpet/Makefile:1.1
--- /dev/null Wed Jun 15 08:19:44 2011
+++ src/sys/modules/hpet/Makefile Wed Jun 15 08:19:43 2011
@@ -0,0 +1,15 @@
+# $NetBSD: Makefile,v 1.1 2011/06/15 08:19:43 jruoho Exp $
+
+.include "../Makefile.inc"
+
+.PATH: ${S}/dev/ic
+.PATH: ${S}/dev/acpi
+.PATH: ${S}/arch/x86/pci
+
+KMOD= hpet
+IOCONF= hpet.ioconf
+SRCS= hpet.c hpet_acpi.c amdpcib_hpet.c ichlpcib_hpet.c
+
+WARNS= 4
+
+.include <bsd.kmodule.mk>
Index: src/sys/modules/hpet/hpet.ioconf
diff -u /dev/null src/sys/modules/hpet/hpet.ioconf:1.1
--- /dev/null Wed Jun 15 08:19:44 2011
+++ src/sys/modules/hpet/hpet.ioconf Wed Jun 15 08:19:43 2011
@@ -0,0 +1,17 @@
+# $NetBSD: hpet.ioconf,v 1.1 2011/06/15 08:19:43 jruoho Exp $
+
+ioconf hpet
+
+include "conf/files"
+include "dev/pci/files.pci"
+include "dev/acpi/files.acpi"
+include "arch/x86/pci/files.pci"
+
+pseudo-root acpi*
+pseudo-root amdpcib*
+pseudo-root ichlpcib*
+
+hpet* at acpihpetbus?
+hpet* at acpinodebus?
+hpet* at amdpcib?
+hpet* at ichlpcib?