hpet_acpi.c revision 1.1
11.1Snjoly/* $NetBSD: hpet_acpi.c,v 1.1 2007/03/08 14:26:28 njoly Exp $ */ 21.1Snjoly 31.1Snjoly/* 41.1Snjoly * Copyright (c) 2006 Nicolas Joly 51.1Snjoly * All rights reserved. 61.1Snjoly * 71.1Snjoly * Redistribution and use in source and binary forms, with or without 81.1Snjoly * modification, are permitted provided that the following conditions 91.1Snjoly * are met: 101.1Snjoly * 1. Redistributions of source code must retain the above copyright 111.1Snjoly * notice, this list of conditions and the following disclaimer. 121.1Snjoly * 2. Redistributions in binary form must reproduce the above copyright 131.1Snjoly * notice, this list of conditions and the following disclaimer in the 141.1Snjoly * documentation and/or other materials provided with the distribution. 151.1Snjoly * 3. The name of the author may not be used to endorse or promote products 161.1Snjoly * derived from this software without specific prior written permission. 171.1Snjoly * 181.1Snjoly * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS 191.1Snjoly * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 201.1Snjoly * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 211.1Snjoly * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 221.1Snjoly * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 231.1Snjoly * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 241.1Snjoly * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 251.1Snjoly * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 261.1Snjoly * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 271.1Snjoly * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 281.1Snjoly * POSSIBILITY OF SUCH DAMAGE. 291.1Snjoly */ 301.1Snjoly 311.1Snjoly#include <sys/cdefs.h> 321.1Snjoly__KERNEL_RCSID(0, "$NetBSD: hpet_acpi.c,v 1.1 2007/03/08 14:26:28 njoly Exp $"); 331.1Snjoly 341.1Snjoly#include <sys/param.h> 351.1Snjoly#include <sys/systm.h> 361.1Snjoly#include <sys/errno.h> 371.1Snjoly#include <sys/device.h> 381.1Snjoly 391.1Snjoly#include <machine/bus.h> 401.1Snjoly 411.1Snjoly#include <dev/acpi/acpica.h> 421.1Snjoly#include <dev/acpi/acpireg.h> 431.1Snjoly#include <dev/acpi/acpivar.h> 441.1Snjoly 451.1Snjoly#include <sys/time.h> 461.1Snjoly#include <sys/timetc.h> 471.1Snjoly 481.1Snjoly#include <dev/ic/hpetvar.h> 491.1Snjoly 501.1Snjolystatic int hpet_acpi_match(struct device *, struct cfdata *, void *); 511.1Snjolystatic void hpet_acpi_attach(struct device *, struct device *, void *); 521.1Snjoly 531.1Snjoly 541.1SnjolyCFATTACH_DECL(hpet_acpi, sizeof(struct hpet_softc), hpet_acpi_match, 551.1Snjoly hpet_acpi_attach, NULL, NULL); 561.1Snjoly 571.1Snjoly/* 581.1Snjoly * Supported device IDs 591.1Snjoly */ 601.1Snjoly 611.1Snjolystatic const char * const hpet_acpi_ids[] = { 621.1Snjoly "PNP0103", 631.1Snjoly NULL 641.1Snjoly}; 651.1Snjoly 661.1Snjoly/* 671.1Snjoly * hpet_acpi_match: autoconf(9) match routine 681.1Snjoly */ 691.1Snjolystatic int 701.1Snjolyhpet_acpi_match(struct device *parent, struct cfdata *match, 711.1Snjoly void *aux) 721.1Snjoly{ 731.1Snjoly struct acpi_attach_args *aa = aux; 741.1Snjoly 751.1Snjoly if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE) 761.1Snjoly return 0; 771.1Snjoly 781.1Snjoly return acpi_match_hid(aa->aa_node->ad_devinfo, hpet_acpi_ids); 791.1Snjoly} 801.1Snjoly 811.1Snjolystatic void 821.1Snjolyhpet_acpi_attach(struct device *parent, struct device *self, void *aux) 831.1Snjoly{ 841.1Snjoly struct hpet_softc *sc = (struct hpet_softc *)self; 851.1Snjoly struct acpi_attach_args *aa = aux; 861.1Snjoly struct acpi_resources res; 871.1Snjoly struct acpi_mem *mem; 881.1Snjoly ACPI_STATUS rv; 891.1Snjoly 901.1Snjoly aprint_naive("\n"); 911.1Snjoly aprint_normal("\n"); 921.1Snjoly 931.1Snjoly /* parse resources */ 941.1Snjoly rv = acpi_resource_parse(&sc->sc_dev, aa->aa_node->ad_handle, "_CRS", 951.1Snjoly &res, &acpi_resource_parse_ops_default); 961.1Snjoly if (ACPI_FAILURE(rv)) 971.1Snjoly return; 981.1Snjoly 991.1Snjoly /* find our mem registers */ 1001.1Snjoly mem = acpi_res_mem(&res, 0); 1011.1Snjoly if (mem == NULL) { 1021.1Snjoly aprint_error("%s: unable to find mem register resource\n", 1031.1Snjoly sc->sc_dev.dv_xname); 1041.1Snjoly goto out; 1051.1Snjoly } 1061.1Snjoly 1071.1Snjoly sc->sc_memt = aa->aa_memt; 1081.1Snjoly if (bus_space_map(sc->sc_memt, mem->ar_base, mem->ar_length, 1091.1Snjoly 0, &sc->sc_memh)) { 1101.1Snjoly aprint_error("%s: can't map mem space\n", sc->sc_dev.dv_xname); 1111.1Snjoly goto out; 1121.1Snjoly } 1131.1Snjoly 1141.1Snjoly hpet_attach_subr(sc); 1151.1Snjoly 1161.1Snjoly out: 1171.1Snjoly acpi_resource_cleanup(&res); 1181.1Snjoly} 119