attimer_acpi.c revision 1.15
11.15Sthorpej/* $NetBSD: attimer_acpi.c,v 1.15 2021/01/29 15:49:55 thorpej Exp $ */ 21.1Scube 31.1Scube/* 41.1Scube * Copyright (c) 2005 The NetBSD Foundation, Inc. 51.1Scube * All rights reserved. 61.1Scube * 71.1Scube * This code is derived from software contributed to The NetBSD Foundation 81.6Sxtraeme * by Quentin Garnier. 91.1Scube * 101.1Scube * Redistribution and use in source and binary forms, with or without 111.1Scube * modification, are permitted provided that the following conditions 121.1Scube * are met: 131.1Scube * 1. Redistributions of source code must retain the above copyright 141.1Scube * notice, this list of conditions and the following disclaimer. 151.1Scube * 2. Redistributions in binary form must reproduce the above copyright 161.1Scube * notice, this list of conditions and the following disclaimer in the 171.1Scube * documentation and/or other materials provided with the distribution. 181.1Scube * 191.1Scube * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.1Scube * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.1Scube * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.1Scube * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.1Scube * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.1Scube * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.1Scube * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.1Scube * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.1Scube * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.1Scube * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.1Scube * POSSIBILITY OF SUCH DAMAGE. 301.1Scube */ 311.1Scube 321.1Scube/* 331.1Scube * Copyright (c) 2002 Jared D. McNeill <jmcneill@invisible.ca> 341.1Scube * All rights reserved. 351.1Scube * 361.1Scube * Redistribution and use in source and binary forms, with or without 371.1Scube * modification, are permitted provided that the following conditions 381.1Scube * are met: 391.1Scube * 1. Redistributions of source code must retain the above copyright 401.1Scube * notice, this list of conditions and the following disclaimer. 411.1Scube * 2. The name of the author may not be used to endorse or promote products 421.1Scube * derived from this software without specific prior written permission. 431.1Scube * 441.1Scube * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 451.1Scube * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 461.1Scube * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 471.1Scube * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 481.1Scube * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 491.1Scube * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 501.1Scube * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 511.1Scube * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 521.1Scube * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 531.1Scube * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 541.1Scube * SUCH DAMAGE. 551.1Scube */ 561.1Scube 571.1Scube/* 581.1Scube * ACPI attimer(4) attachment based on lpt_acpi.c by Jared D. McNeill. 591.1Scube */ 601.1Scube 611.1Scube#include <sys/cdefs.h> 621.15Sthorpej__KERNEL_RCSID(0, "$NetBSD: attimer_acpi.c,v 1.15 2021/01/29 15:49:55 thorpej Exp $"); 631.1Scube 641.1Scube#include <sys/param.h> 651.14Sjruoho#include <sys/device.h> 661.1Scube#include <sys/systm.h> 671.1Scube 681.1Scube#include <dev/acpi/acpivar.h> 691.1Scube 701.1Scube#include <dev/ic/attimervar.h> 711.1Scube 721.10Scubestatic int attimer_acpi_match(device_t, cfdata_t, void *); 731.8Sdyoungstatic void attimer_acpi_attach(device_t, device_t, void *); 741.1Scube 751.13SdyoungCFATTACH_DECL3_NEW(attimer_acpi, sizeof(struct attimer_softc), 761.13Sdyoung attimer_acpi_match, attimer_acpi_attach, attimer_detach, NULL, NULL, NULL, 771.13Sdyoung DVF_DETACH_SHUTDOWN); 781.1Scube 791.1Scube/* 801.1Scube * Supported device IDs 811.1Scube */ 821.1Scube 831.15Sthorpejstatic const struct device_compatible_entry compat_data[] = { 841.15Sthorpej { .compat = "PNP0100" }, /* AT Timer */ 851.15Sthorpej DEVICE_COMPAT_EOL 861.1Scube}; 871.1Scube 881.1Scube/* 891.1Scube * attimer_acpi_match: autoconf(9) match routine 901.1Scube */ 911.1Scubestatic int 921.10Scubeattimer_acpi_match(device_t parent, cfdata_t match, void *aux) 931.1Scube{ 941.1Scube struct acpi_attach_args *aa = aux; 951.1Scube 961.15Sthorpej return acpi_compatible_match(aa, compat_data); 971.1Scube} 981.1Scube 991.1Scube/* 1001.1Scube * attimer_acpi_attach: autoconf(9) attach routine 1011.1Scube */ 1021.1Scubestatic void 1031.8Sdyoungattimer_acpi_attach(device_t parent, device_t self, void *aux) 1041.1Scube{ 1051.8Sdyoung struct attimer_softc *sc = device_private(self); 1061.1Scube struct acpi_attach_args *aa = aux; 1071.1Scube struct acpi_resources res; 1081.1Scube struct acpi_io *io; 1091.1Scube ACPI_STATUS rv; 1101.1Scube 1111.10Scube sc->sc_dev = self; 1121.10Scube 1131.1Scube /* parse resources */ 1141.10Scube rv = acpi_resource_parse(sc->sc_dev, aa->aa_node->ad_handle, "_CRS", 1151.1Scube &res, &acpi_resource_parse_ops_default); 1161.1Scube if (ACPI_FAILURE(rv)) 1171.1Scube return; 1181.1Scube 1191.1Scube /* find our i/o registers */ 1201.1Scube io = acpi_res_io(&res, 0); 1211.1Scube if (io == NULL) { 1221.10Scube aprint_error_dev(self, 1231.10Scube "unable to find i/o register resource\n"); 1241.1Scube goto out; 1251.1Scube } 1261.1Scube 1271.1Scube sc->sc_iot = aa->aa_iot; 1281.9Sdyoung sc->sc_size = io->ar_length; 1291.9Sdyoung if (bus_space_map(sc->sc_iot, io->ar_base, sc->sc_size, 1301.9Sdyoung 0, &sc->sc_ioh) != 0) { 1311.10Scube aprint_error_dev(self, "can't map i/o space\n"); 1321.1Scube goto out; 1331.1Scube } 1341.1Scube 1351.1Scube attimer_attach(sc); 1361.1Scube 1371.1Scube out: 1381.1Scube acpi_resource_cleanup(&res); 1391.1Scube} 140