acpi_timer.c (231226) | acpi_timer.c (231295) |
---|---|
1/*- 2 * Copyright (c) 2000, 2001 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: --- 12 unchanged lines hidden (view full) --- 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 28#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2000, 2001 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: --- 12 unchanged lines hidden (view full) --- 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 28#include <sys/cdefs.h> |
29__FBSDID("$FreeBSD: head/sys/dev/acpica/acpi_timer.c 231226 2012-02-08 20:31:42Z jkim $"); | 29__FBSDID("$FreeBSD: head/sys/dev/acpica/acpi_timer.c 231295 2012-02-09 17:38:08Z jkim $"); |
30 31#include "opt_acpi.h" 32#include <sys/param.h> 33#include <sys/bus.h> 34#include <sys/eventhandler.h> 35#include <sys/kernel.h> 36#include <sys/module.h> 37#include <sys/sysctl.h> --- 25 unchanged lines hidden (view full) --- 63static bus_space_tag_t acpi_timer_bst; 64static eventhandler_tag acpi_timer_eh; 65 66static u_int acpi_timer_frequency = 14318182 / 4; 67 68static void acpi_timer_identify(driver_t *driver, device_t parent); 69static int acpi_timer_probe(device_t dev); 70static int acpi_timer_attach(device_t dev); | 30 31#include "opt_acpi.h" 32#include <sys/param.h> 33#include <sys/bus.h> 34#include <sys/eventhandler.h> 35#include <sys/kernel.h> 36#include <sys/module.h> 37#include <sys/sysctl.h> --- 25 unchanged lines hidden (view full) --- 63static bus_space_tag_t acpi_timer_bst; 64static eventhandler_tag acpi_timer_eh; 65 66static u_int acpi_timer_frequency = 14318182 / 4; 67 68static void acpi_timer_identify(driver_t *driver, device_t parent); 69static int acpi_timer_probe(device_t dev); 70static int acpi_timer_attach(device_t dev); |
71static int acpi_timer_suspend(device_t); | |
72static void acpi_timer_resume_handler(struct timecounter *); | 71static void acpi_timer_resume_handler(struct timecounter *); |
72static void acpi_timer_suspend_handler(struct timecounter *); |
|
73static u_int acpi_timer_get_timecount(struct timecounter *tc); 74static u_int acpi_timer_get_timecount_safe(struct timecounter *tc); 75static int acpi_timer_sysctl_freq(SYSCTL_HANDLER_ARGS); 76static void acpi_timer_boot_test(void); 77 78static int acpi_timer_test(void); 79 80static device_method_t acpi_timer_methods[] = { 81 DEVMETHOD(device_identify, acpi_timer_identify), 82 DEVMETHOD(device_probe, acpi_timer_probe), 83 DEVMETHOD(device_attach, acpi_timer_attach), | 73static u_int acpi_timer_get_timecount(struct timecounter *tc); 74static u_int acpi_timer_get_timecount_safe(struct timecounter *tc); 75static int acpi_timer_sysctl_freq(SYSCTL_HANDLER_ARGS); 76static void acpi_timer_boot_test(void); 77 78static int acpi_timer_test(void); 79 80static device_method_t acpi_timer_methods[] = { 81 DEVMETHOD(device_identify, acpi_timer_identify), 82 DEVMETHOD(device_probe, acpi_timer_probe), 83 DEVMETHOD(device_attach, acpi_timer_attach), |
84 DEVMETHOD(device_suspend, acpi_timer_suspend), | |
85 86 {0, 0} 87}; 88 89static driver_t acpi_timer_driver = { 90 "acpi_timer", 91 acpi_timer_methods, 92 0, --- 151 unchanged lines hidden (view full) --- 244 return (ENXIO); 245 } 246 rid = 0; 247 acpi_timer_reg = bus_alloc_resource_any(dev, rtype, &rid, RF_ACTIVE); 248 if (acpi_timer_reg == NULL) 249 return (ENXIO); 250 acpi_timer_bsh = rman_get_bushandle(acpi_timer_reg); 251 acpi_timer_bst = rman_get_bustag(acpi_timer_reg); | 84 85 {0, 0} 86}; 87 88static driver_t acpi_timer_driver = { 89 "acpi_timer", 90 acpi_timer_methods, 91 0, --- 151 unchanged lines hidden (view full) --- 243 return (ENXIO); 244 } 245 rid = 0; 246 acpi_timer_reg = bus_alloc_resource_any(dev, rtype, &rid, RF_ACTIVE); 247 if (acpi_timer_reg == NULL) 248 return (ENXIO); 249 acpi_timer_bsh = rman_get_bushandle(acpi_timer_reg); 250 acpi_timer_bst = rman_get_bustag(acpi_timer_reg); |
251 252 /* Register suspend event handler. */ 253 if (EVENTHANDLER_REGISTER(power_suspend, acpi_timer_suspend_handler, 254 &acpi_timer_timecounter, EVENTHANDLER_PRI_LAST) == NULL) 255 device_printf(dev, "failed to register suspend event handler\n"); 256 |
|
252 return (0); 253} 254 255static void 256acpi_timer_resume_handler(struct timecounter *newtc) 257{ 258 struct timecounter *tc; 259 --- 4 unchanged lines hidden (view full) --- 264 "restoring timecounter, %s -> %s\n", 265 tc->tc_name, newtc->tc_name); 266 (void)newtc->tc_get_timecount(newtc); 267 (void)newtc->tc_get_timecount(newtc); 268 timecounter = newtc; 269 } 270} 271 | 257 return (0); 258} 259 260static void 261acpi_timer_resume_handler(struct timecounter *newtc) 262{ 263 struct timecounter *tc; 264 --- 4 unchanged lines hidden (view full) --- 269 "restoring timecounter, %s -> %s\n", 270 tc->tc_name, newtc->tc_name); 271 (void)newtc->tc_get_timecount(newtc); 272 (void)newtc->tc_get_timecount(newtc); 273 timecounter = newtc; 274 } 275} 276 |
272static int 273acpi_timer_suspend(device_t dev) | 277static void 278acpi_timer_suspend_handler(struct timecounter *newtc) |
274{ | 279{ |
275 struct timecounter *newtc, *tc; 276 int error; | 280 struct timecounter *tc; |
277 | 281 |
278 error = bus_generic_suspend(dev); | 282 /* Deregister existing resume event handler. */ |
279 if (acpi_timer_eh != NULL) { 280 EVENTHANDLER_DEREGISTER(power_resume, acpi_timer_eh); 281 acpi_timer_eh = NULL; 282 } | 283 if (acpi_timer_eh != NULL) { 284 EVENTHANDLER_DEREGISTER(power_resume, acpi_timer_eh); 285 acpi_timer_eh = NULL; 286 } |
287 288 KASSERT(newtc == &acpi_timer_timecounter, 289 ("acpi_timer_suspend_handler: wrong timecounter")); 290 |
|
283 tc = timecounter; | 291 tc = timecounter; |
284 newtc = &acpi_timer_timecounter; | |
285 if (tc != newtc) { 286 if (bootverbose) | 292 if (tc != newtc) { 293 if (bootverbose) |
287 device_printf(dev, "switching timecounter, %s -> %s\n", | 294 device_printf(acpi_timer_dev, 295 "switching timecounter, %s -> %s\n", |
288 tc->tc_name, newtc->tc_name); 289 (void)acpi_timer_read(); 290 (void)acpi_timer_read(); 291 timecounter = newtc; 292 acpi_timer_eh = EVENTHANDLER_REGISTER(power_resume, 293 acpi_timer_resume_handler, tc, EVENTHANDLER_PRI_LAST); 294 } | 296 tc->tc_name, newtc->tc_name); 297 (void)acpi_timer_read(); 298 (void)acpi_timer_read(); 299 timecounter = newtc; 300 acpi_timer_eh = EVENTHANDLER_REGISTER(power_resume, 301 acpi_timer_resume_handler, tc, EVENTHANDLER_PRI_LAST); 302 } |
295 return (error); | |
296} 297 298/* 299 * Fetch current time value from reliable hardware. 300 */ 301static u_int 302acpi_timer_get_timecount(struct timecounter *tc) 303{ --- 146 unchanged lines hidden --- | 303} 304 305/* 306 * Fetch current time value from reliable hardware. 307 */ 308static u_int 309acpi_timer_get_timecount(struct timecounter *tc) 310{ --- 146 unchanged lines hidden --- |