diff --git a/sys/arch/amd64/conf/files.amd64 b/sys/arch/amd64/conf/files.amd64 index 02907b7b1d91..081c668f3b0e 100644 --- a/sys/arch/amd64/conf/files.amd64 +++ b/sys/arch/amd64/conf/files.amd64 @@ -1,4 +1,4 @@ -# $NetBSD: files.amd64,v 1.32 2007/03/05 16:51:00 drochner Exp $ +# $NetBSD: files.amd64,v 1.33 2007/03/08 14:26:26 njoly Exp $ # # new style config file for amd64 architecture # @@ -117,7 +117,14 @@ file arch/x86/pci/pchb_rnd.c pchb & rnd # PCI-ISA bridges device pcib: isabus attach pcib at pci -file arch/amd64/pci/pcib.c pcib +file arch/amd64/pci/pcib.c pcib | amdpcib + +device amdpcib {} : isabus +attach amdpcib at pci +file arch/amd64/pci/amdpcib.c amdpcib + +attach hpet at amdpcib with amdpcib_hpet +file arch/amd64/pci/amdpcib_hpet.c amdpcib_hpet device aapic attach aapic at pci diff --git a/sys/arch/amd64/pci/amdpcib.c b/sys/arch/amd64/pci/amdpcib.c new file mode 100644 index 000000000000..948eafd7b5f0 --- /dev/null +++ b/sys/arch/amd64/pci/amdpcib.c @@ -0,0 +1,89 @@ +/* $NetBSD: amdpcib.c,v 1.1 2007/03/08 14:26:27 njoly Exp $ */ + +/* + * Copyright (c) 2006 Nicolas Joly + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__KERNEL_RCSID(0, "$NetBSD: amdpcib.c,v 1.1 2007/03/08 14:26:27 njoly Exp $"); + +#include +#include + +#include +#include +#include + +struct amdpcib_softc { + struct device sc_dev; + + bus_space_tag_t sc_memt; + bus_space_handle_t sc_memh; +}; + +static int amdpcib_match(struct device *, struct cfdata *, void *); +static void amdpcib_attach(struct device *, struct device *, void *); +static int amdpcib_search(device_t, cfdata_t, const int *, void *); + + +extern void pcibattach(struct device *, struct device *, void *); + +CFATTACH_DECL(amdpcib, sizeof(struct amdpcib_softc), amdpcib_match, + amdpcib_attach, NULL, NULL); + +static int +amdpcib_match(struct device *parent, struct cfdata *match, void *aux) { + struct pci_attach_args *pa = aux; + + if ((PCI_VENDOR(pa->pa_id) == PCI_VENDOR_AMD) && + (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_AMD_PBC8111_LPC)) + return 2; + + return 0; +} + +static void +amdpcib_attach(struct device *parent, struct device *self, void *aux) { + struct amdpcib_softc *sc; + struct pci_attach_args *pa; + + sc = (struct amdpcib_softc *)self; + pa = (struct pci_attach_args *)aux; + + pcibattach(parent, self, aux); + + config_search_loc(amdpcib_search, &sc->sc_dev, "amdpcib", NULL, pa); +} + +static int +amdpcib_search(device_t parent, cfdata_t cf, const int *locs, void *aux) { + + if (config_match(parent, cf, aux)) + config_attach_loc(parent, cf, locs, aux, NULL); + + return 0; +} diff --git a/sys/arch/amd64/pci/amdpcib_hpet.c b/sys/arch/amd64/pci/amdpcib_hpet.c new file mode 100644 index 000000000000..b1d392227b3b --- /dev/null +++ b/sys/arch/amd64/pci/amdpcib_hpet.c @@ -0,0 +1,90 @@ +/* $NetBSD: amdpcib_hpet.c,v 1.1 2007/03/08 14:26:27 njoly Exp $ */ + +/* + * Copyright (c) 2006 Nicolas Joly + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__KERNEL_RCSID(0, "$NetBSD: amdpcib_hpet.c,v 1.1 2007/03/08 14:26:27 njoly Exp $"); + +#include +#include + +#include +#include + +#include + +#include +#include +#include + +#include + + +static int amdpcib_hpet_match(struct device *, struct cfdata *, void *); +static void amdpcib_hpet_attach(struct device *, struct device *, void *); + +CFATTACH_DECL(amdpcib_hpet, sizeof(struct hpet_softc), amdpcib_hpet_match, + amdpcib_hpet_attach, NULL, NULL); + +static int +amdpcib_hpet_match(struct device *parent, struct cfdata *match, void *aux) { + return 1; +} + +static void +amdpcib_hpet_attach(struct device *parent, struct device *self, void *aux) { + struct hpet_softc *sc; + struct pci_attach_args *pa; + pcireg_t conf, addr; + + sc = (struct hpet_softc *)self; + pa = (struct pci_attach_args *)aux; + + aprint_naive("\n"); + aprint_normal(": HPET timer\n"); + + conf = pci_conf_read(pa->pa_pc, pa->pa_tag, 0xa0); + if ((conf & 1) == 0) { + printf("%s: HPET timer is disabled\n", sc->sc_dev.dv_xname); + return; + } + + sc->sc_memt = pa->pa_memt; + + addr = conf & 0xfffffc00; + if (bus_space_map(sc->sc_memt, addr, 1024, 0, + &sc->sc_memh)) { + printf("%s: failed to map mem\n", sc->sc_dev.dv_xname); + return; + } + +#ifdef __HAVE_TIMECOUNTER + hpet_attach_subr(sc); +#endif +} diff --git a/sys/conf/files b/sys/conf/files index c4cc5ae1f695..e54c5e884ed1 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1,4 +1,4 @@ -# $NetBSD: files,v 1.833 2007/03/06 11:28:45 dillo Exp $ +# $NetBSD: files,v 1.834 2007/03/08 14:26:27 njoly Exp $ # @(#)files.newconf 7.5 (Berkeley) 5/10/93 @@ -958,6 +958,9 @@ file dev/ic/lm700x.c lm700x define acpipmtimer file dev/ic/acpipmtimer.c acpipmtimer +device hpet +file dev/ic/hpet.c hpet needs-flag + # Definitions for wscons # device attributes: display, display with emulator, keyboard, and mouse # diff --git a/sys/dev/acpi/files.acpi b/sys/dev/acpi/files.acpi index 9fbb2aaa5e14..31a2caea6362 100644 --- a/sys/dev/acpi/files.acpi +++ b/sys/dev/acpi/files.acpi @@ -1,4 +1,4 @@ -# $NetBSD: files.acpi,v 1.41 2007/01/09 13:41:30 cube Exp $ +# $NetBSD: files.acpi,v 1.42 2007/03/08 14:26:28 njoly Exp $ include "dev/acpi/acpica/files.acpica" @@ -95,3 +95,8 @@ file dev/acpi/attimer_acpi.c attimer_acpi # Yamaha OPL3-SAx attach ym at acpinodebus with ym_acpi 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 + diff --git a/sys/dev/acpi/hpet_acpi.c b/sys/dev/acpi/hpet_acpi.c new file mode 100644 index 000000000000..2c2a19fb15dd --- /dev/null +++ b/sys/dev/acpi/hpet_acpi.c @@ -0,0 +1,118 @@ +/* $NetBSD: hpet_acpi.c,v 1.1 2007/03/08 14:26:28 njoly Exp $ */ + +/* + * Copyright (c) 2006 Nicolas Joly + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__KERNEL_RCSID(0, "$NetBSD: hpet_acpi.c,v 1.1 2007/03/08 14:26:28 njoly Exp $"); + +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include + +#include + +static int hpet_acpi_match(struct device *, struct cfdata *, void *); +static void hpet_acpi_attach(struct device *, struct device *, void *); + + +CFATTACH_DECL(hpet_acpi, sizeof(struct hpet_softc), hpet_acpi_match, + hpet_acpi_attach, NULL, NULL); + +/* + * Supported device IDs + */ + +static const char * const hpet_acpi_ids[] = { + "PNP0103", + NULL +}; + +/* + * hpet_acpi_match: autoconf(9) match routine + */ +static int +hpet_acpi_match(struct device *parent, struct cfdata *match, + void *aux) +{ + struct acpi_attach_args *aa = aux; + + if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE) + return 0; + + return acpi_match_hid(aa->aa_node->ad_devinfo, hpet_acpi_ids); +} + +static void +hpet_acpi_attach(struct device *parent, struct device *self, void *aux) +{ + struct hpet_softc *sc = (struct hpet_softc *)self; + struct acpi_attach_args *aa = aux; + struct acpi_resources res; + struct acpi_mem *mem; + ACPI_STATUS rv; + + aprint_naive("\n"); + aprint_normal("\n"); + + /* parse resources */ + rv = acpi_resource_parse(&sc->sc_dev, 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("%s: unable to find mem register resource\n", + sc->sc_dev.dv_xname); + 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("%s: can't map mem space\n", sc->sc_dev.dv_xname); + goto out; + } + + hpet_attach_subr(sc); + + out: + acpi_resource_cleanup(&res); +} diff --git a/sys/dev/ic/hpet.c b/sys/dev/ic/hpet.c new file mode 100644 index 000000000000..28188ffc0d85 --- /dev/null +++ b/sys/dev/ic/hpet.c @@ -0,0 +1,92 @@ +/* $NetBSD: hpet.c,v 1.1 2007/03/08 14:26:28 njoly Exp $ */ + +/* + * Copyright (c) 2006 Nicolas Joly + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * High Precision Event Timer. + */ + +#include +__KERNEL_RCSID(0, "$NetBSD: hpet.c,v 1.1 2007/03/08 14:26:28 njoly Exp $"); + +#include +#include +#include + +#include +#include + +#include + +#include +#include + +static u_int hpet_get_timecount(struct timecounter *); + +void +hpet_attach_subr(struct hpet_softc *sc) { + struct timecounter *tc; + uint32_t val; + + tc = &sc->sc_tc; + + tc->tc_name = sc->sc_dev.dv_xname; + tc->tc_get_timecount = hpet_get_timecount; + tc->tc_quality = 2000; + + /* XXX Only 32-bits supported for now */ + val = bus_space_read_4(sc->sc_memt, sc->sc_memh, HPET_INFO); + if ((val & HPET_INFO_64BITS) != 0) { + aprint_normal("%s: Found 64-bits HPET, will only use lowest" + " 32-bits\n", sc->sc_dev.dv_xname); + } + tc->tc_counter_mask = 0xffffffff; + + /* Get frequency */ + val = bus_space_read_4(sc->sc_memt, sc->sc_memh, HPET_PERIOD); + tc->tc_frequency = 1000000000000000ULL / val; + + /* Enable timer */ + val = bus_space_read_4(sc->sc_memt, sc->sc_memh, HPET_CONFIG); + if ((val & HPET_CONFIG_ENABLE) == 0) { + val |= HPET_CONFIG_ENABLE; + bus_space_write_4(sc->sc_memt, sc->sc_memh, HPET_CONFIG, val); + } + + tc->tc_priv = sc; + tc_init(tc); +} + +static u_int +hpet_get_timecount(struct timecounter *tc) { + struct hpet_softc *sc = tc->tc_priv; + + return bus_space_read_4(sc->sc_memt, sc->sc_memh, HPET_MCOUNT); +} + diff --git a/sys/dev/ic/hpetreg.h b/sys/dev/ic/hpetreg.h new file mode 100644 index 000000000000..16648a20bf17 --- /dev/null +++ b/sys/dev/ic/hpetreg.h @@ -0,0 +1,41 @@ +/* $NetBSD: hpetreg.h,v 1.1 2007/03/08 14:26:28 njoly Exp $ */ + +/* + * Copyright (c) 2006 Nicolas Joly + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _DEV_IC_HPETREG_H_ +#define _DEV_IC_HPETREG_H_ + +#define HPET_INFO 0x00 +#define HPET_INFO_64BITS 0x2000 +#define HPET_PERIOD 0x04 +#define HPET_CONFIG 0x10 +#define HPET_CONFIG_ENABLE 0x0001 +#define HPET_MCOUNT 0xf0 + +#endif /* _DEV_IC_HPETREG_H_ */ diff --git a/sys/dev/ic/hpetvar.h b/sys/dev/ic/hpetvar.h new file mode 100644 index 000000000000..f96c58468af9 --- /dev/null +++ b/sys/dev/ic/hpetvar.h @@ -0,0 +1,45 @@ +/* $NetBSD: hpetvar.h,v 1.1 2007/03/08 14:26:29 njoly Exp $ */ + +/* + * Copyright (c) 2006 Nicolas Joly + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _DEV_IC_HPETVAR_H_ +#define _DEV_IC_HPETVAR_H_ + +struct hpet_softc { + struct device sc_dev; + + bus_space_tag_t sc_memt; + bus_space_handle_t sc_memh; + + struct timecounter sc_tc; +}; + +void hpet_attach_subr(struct hpet_softc *); + +#endif /* _DEV_IC_HPETVAR_H_ */