1 /*- 2 * Copyright (c) 2000 Michael Smith 3 * Copyright (c) 2000 BSDi 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * $FreeBSD$ 28 */ 29 30 #include "opt_acpi.h" 31 #include <sys/param.h> 32 #include <sys/kernel.h> 33 #include <sys/bus.h> 34 35 #include "acpi.h" 36 37 #include <dev/acpica/acpivar.h> 38 39 /* 40 * Hooks for the ACPI CA debugging infrastructure 41 */ 42 #define _COMPONENT ACPI_SYSTEM 43 MODULE_NAME("TIMER") 44 45 #define ACPITIMER_MAGIC 0x524d4954 /* "TIMR" */ 46 47 struct acpi_timer_softc { 48 device_t tm_dev; 49 }; 50 51 static void acpi_timer_identify(driver_t *driver, device_t parent); 52 static int acpi_timer_probe(device_t dev); 53 static int acpi_timer_attach(device_t dev); 54 55 static device_method_t acpi_timer_methods[] = { 56 /* Device interface */ 57 DEVMETHOD(device_identify, acpi_timer_identify), 58 DEVMETHOD(device_probe, acpi_timer_probe), 59 DEVMETHOD(device_attach, acpi_timer_attach), 60 61 {0, 0} 62 }; 63 64 static driver_t acpi_timer_driver = { 65 "acpi_timer", 66 acpi_timer_methods, 67 sizeof(struct acpi_timer_softc), 68 }; 69 70 devclass_t acpi_timer_devclass; 71 DRIVER_MODULE(acpi_timer, acpi, acpi_timer_driver, acpi_timer_devclass, 0, 0); 72 73 static void 74 acpi_timer_identify(driver_t *driver, device_t parent) 75 { 76 device_t dev; 77 char desc[40]; 78 79 FUNCTION_TRACE(__func__); 80 81 if (acpi_disabled("timer")) 82 return_VOID; 83 84 if (AcpiGbl_FADT == NULL) 85 return_VOID; 86 87 if ((dev = BUS_ADD_CHILD(parent, 0, "acpi_timer", 0)) == NULL) { 88 device_printf(parent, "could not add acpi_timer0\n"); 89 return_VOID; 90 } 91 if (acpi_set_magic(dev, ACPITIMER_MAGIC)) { 92 device_printf(dev, "could not set magic\n"); 93 return_VOID; 94 } 95 96 sprintf(desc, "%d-bit timer at 3.579545MHz", AcpiGbl_FADT->TmrValExt ? 32 : 24); 97 device_set_desc_copy(dev, desc); 98 99 return_VOID; 100 } 101 102 static int 103 acpi_timer_probe(device_t dev) 104 { 105 if (acpi_get_magic(dev) == ACPITIMER_MAGIC) 106 return(0); 107 return(ENXIO); 108 } 109 110 static int 111 acpi_timer_attach(device_t dev) 112 { 113 struct acpi_timer_softc *sc; 114 115 FUNCTION_TRACE(__func__); 116 117 sc = device_get_softc(dev); 118 sc->tm_dev = dev; 119 120 return_VALUE(0); 121 } 122