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 #define ACPITIMER_MAGIC 0x524d4954 /* "TIMR" */ 40 41 struct acpi_timer_softc { 42 device_t tm_dev; 43 }; 44 45 static void acpi_timer_identify(driver_t *driver, device_t parent); 46 static int acpi_timer_probe(device_t dev); 47 static int acpi_timer_attach(device_t dev); 48 49 static device_method_t acpi_timer_methods[] = { 50 /* Device interface */ 51 DEVMETHOD(device_identify, acpi_timer_identify), 52 DEVMETHOD(device_probe, acpi_timer_probe), 53 DEVMETHOD(device_attach, acpi_timer_attach), 54 55 {0, 0} 56 }; 57 58 static driver_t acpi_timer_driver = { 59 "acpi_timer", 60 acpi_timer_methods, 61 sizeof(struct acpi_timer_softc), 62 }; 63 64 devclass_t acpi_timer_devclass; 65 DRIVER_MODULE(acpi_timer, acpi, acpi_timer_driver, acpi_timer_devclass, 0, 0); 66 67 static void 68 acpi_timer_identify(driver_t *driver, device_t parent) 69 { 70 static FIXED_ACPI_DESCRIPTION_TABLE facp; 71 ACPI_BUFFER buf; 72 ACPI_STATUS status; 73 device_t dev; 74 char desc[40]; 75 76 buf.Pointer = &facp; 77 buf.Length = sizeof(facp); 78 if ((status = AcpiGetTable(ACPI_TABLE_FACP, 1, &buf)) != AE_OK) { 79 device_printf(parent, "can't locate FACP - %s\n", acpi_strerror(status)); 80 return; 81 } 82 if (buf.Length != sizeof(facp)) { 83 device_printf(parent, "invalid FACP\n"); 84 return; 85 } 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; 90 } 91 if (acpi_set_magic(dev, ACPITIMER_MAGIC)) { 92 device_printf(dev, "could not set magic\n"); 93 return; 94 } 95 96 sprintf(desc, "%d-bit timer at 3.579545MHz", facp.TmrValExt ? 32 : 24); 97 device_set_desc_copy(dev, desc); 98 } 99 100 static int 101 acpi_timer_probe(device_t dev) 102 { 103 if (acpi_get_magic(dev) == ACPITIMER_MAGIC) 104 return(0); 105 return(ENXIO); 106 } 107 108 static int 109 acpi_timer_attach(device_t dev) 110 { 111 struct acpi_timer_softc *sc; 112 113 sc = device_get_softc(dev); 114 sc->tm_dev = dev; 115 116 return(0); 117 } 118