Source-Changes-HG archive

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

[src/trunk]: src Modularize hpet(4). Works nicely with the multiple bus locat...



details:   https://anonhg.NetBSD.org/src/rev/423d61b3ca67
branches:  trunk
changeset: 766090:423d61b3ca67
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Wed Jun 15 08:19:43 2011 +0000

description:
Modularize hpet(4). Works nicely with the multiple bus locations.

diffstat:

 distrib/sets/lists/modules/md.amd64 |    4 +-
 distrib/sets/lists/modules/md.i386  |    4 +-
 sys/arch/x86/pci/amdpcib_hpet.c     |   54 ++++++++--
 sys/arch/x86/pci/ichlpcib_hpet.c    |   18 +-
 sys/dev/acpi/hpet_acpi.c            |  182 +++++++++++++++++++++++------------
 sys/modules/Makefile                |    3 +-
 sys/modules/hpet/Makefile           |   15 ++
 sys/modules/hpet/hpet.ioconf        |   17 +++
 8 files changed, 211 insertions(+), 86 deletions(-)

diffs (truncated from 509 to 300 lines):

diff -r bc2245a28385 -r 423d61b3ca67 distrib/sets/lists/modules/md.amd64
--- a/distrib/sets/lists/modules/md.amd64       Wed Jun 15 08:04:49 2011 +0000
+++ b/distrib/sets/lists/modules/md.amd64       Wed Jun 15 08:19:43 2011 +0000
@@ -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
diff -r bc2245a28385 -r 423d61b3ca67 distrib/sets/lists/modules/md.i386
--- a/distrib/sets/lists/modules/md.i386        Wed Jun 15 08:04:49 2011 +0000
+++ b/distrib/sets/lists/modules/md.i386        Wed Jun 15 08:19:43 2011 +0000
@@ -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
diff -r bc2245a28385 -r 423d61b3ca67 sys/arch/x86/pci/amdpcib_hpet.c
--- a/sys/arch/x86/pci/amdpcib_hpet.c   Wed Jun 15 08:04:49 2011 +0000
+++ b/sys/arch/x86/pci/amdpcib_hpet.c   Wed Jun 15 08:19:43 2011 +0000
@@ -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;
+}
diff -r bc2245a28385 -r 423d61b3ca67 sys/arch/x86/pci/ichlpcib_hpet.c
--- a/sys/arch/x86/pci/ichlpcib_hpet.c  Wed Jun 15 08:04:49 2011 +0000
+++ b/sys/arch/x86/pci/ichlpcib_hpet.c  Wed Jun 15 08:19:43 2011 +0000
@@ -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);
 }
diff -r bc2245a28385 -r 423d61b3ca67 sys/dev/acpi/hpet_acpi.c
--- a/sys/dev/acpi/hpet_acpi.c  Wed Jun 15 08:04:49 2011 +0000
+++ b/sys/dev/acpi/hpet_acpi.c  Wed Jun 15 08:19:43 2011 +0000
@@ -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_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 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_dev_addr(device_t, void *, bus_size_t *);
 static int             hpet_acpi_detach(device_t, int);
 
 static const char * const hpet_acpi_ids[] = {
@@ -63,6 +66,60 @@
 static int
 hpet_acpi_tab_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_addr_t addr;
+
+       addr = hpet_acpi_tab_addr();
+
+       if (addr == 0)
+               return 0;
+
+       bt = aa->aa_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;
+}
+
+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;
+       bus_addr_t addr;
+
+       sc->sc_mapped = false;
+       addr = hpet_acpi_tab_addr();
+
+       if (addr == 0) {
+               aprint_error(": failed to get address\n");
+               return;
+       }
+
+       sc->sc_memt = aa->aa_memt;
+       sc->sc_mems = HPET_WINDOW_SIZE;
+
+       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 + 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;
 
@@ -77,54 +134,40 @@
        if (hpet->Address.SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY)
                return 0;
 
-       return 1;
-}
-



Home | Main Index | Thread Index | Old Index