acpi_apm.c (168191) | acpi_apm.c (170976) |
---|---|
1/*- 2 * Copyright (c) 2001 Mitsuru IWASAKI 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2001 Mitsuru IWASAKI 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/sys/i386/acpica/acpi_machdep.c 168191 2007-03-31 23:23:42Z jhb $"); | 28__FBSDID("$FreeBSD: head/sys/i386/acpica/acpi_machdep.c 170976 2007-06-21 22:50:37Z njl $"); |
29 30#include <sys/param.h> 31#include <sys/bus.h> 32#include <sys/condvar.h> 33#include <sys/conf.h> 34#include <sys/fcntl.h> 35#include <sys/kernel.h> | 29 30#include <sys/param.h> 31#include <sys/bus.h> 32#include <sys/condvar.h> 33#include <sys/conf.h> 34#include <sys/fcntl.h> 35#include <sys/kernel.h> |
36#include <sys/malloc.h> 37#include <sys/poll.h> |
|
36#include <sys/sysctl.h> 37#include <sys/uio.h> 38#include <vm/vm.h> 39#include <vm/pmap.h> 40 41#include <contrib/dev/acpica/acpi.h> 42#include <dev/acpica/acpivar.h> 43#include <dev/acpica/acpiio.h> 44 45/* 46 * APM driver emulation 47 */ 48 | 38#include <sys/sysctl.h> 39#include <sys/uio.h> 40#include <vm/vm.h> 41#include <vm/pmap.h> 42 43#include <contrib/dev/acpica/acpi.h> 44#include <dev/acpica/acpivar.h> 45#include <dev/acpica/acpiio.h> 46 47/* 48 * APM driver emulation 49 */ 50 |
49#include <sys/selinfo.h> 50 | |
51#include <machine/apm_bios.h> 52#include <machine/pc/bios.h> 53 54#include <i386/bios/apm.h> 55 56SYSCTL_DECL(_debug_acpi); 57 58uint32_t acpi_resume_beep; 59TUNABLE_INT("debug.acpi.resume_beep", &acpi_resume_beep); 60SYSCTL_UINT(_debug_acpi, OID_AUTO, resume_beep, CTLFLAG_RW, &acpi_resume_beep, 61 0, "Beep the PC speaker when resuming"); 62uint32_t acpi_reset_video; 63TUNABLE_INT("hw.acpi.reset_video", &acpi_reset_video); 64 65static int intr_model = ACPI_INTR_PIC; 66static int apm_active; | 51#include <machine/apm_bios.h> 52#include <machine/pc/bios.h> 53 54#include <i386/bios/apm.h> 55 56SYSCTL_DECL(_debug_acpi); 57 58uint32_t acpi_resume_beep; 59TUNABLE_INT("debug.acpi.resume_beep", &acpi_resume_beep); 60SYSCTL_UINT(_debug_acpi, OID_AUTO, resume_beep, CTLFLAG_RW, &acpi_resume_beep, 61 0, "Beep the PC speaker when resuming"); 62uint32_t acpi_reset_video; 63TUNABLE_INT("hw.acpi.reset_video", &acpi_reset_video); 64 65static int intr_model = ACPI_INTR_PIC; 66static int apm_active; |
67static struct clonedevs *apm_clones; |
|
67 | 68 |
68static d_open_t apmopen; 69static d_close_t apmclose; 70static d_write_t apmwrite; 71static d_ioctl_t apmioctl; 72static d_poll_t apmpoll; | 69MALLOC_DEFINE(M_APMDEV, "apmdev", "APM device emulation"); |
73 | 70 |
71static d_open_t apmopen; 72static d_close_t apmclose; 73static d_write_t apmwrite; 74static d_ioctl_t apmioctl; 75static d_poll_t apmpoll; 76static d_kqfilter_t apmkqfilter; 77static void apmreadfiltdetach(struct knote *kn); 78static int apmreadfilt(struct knote *kn, long hint); 79static struct filterops apm_readfiltops = 80 { 1, NULL, apmreadfiltdetach, apmreadfilt }; 81 |
|
74static struct cdevsw apm_cdevsw = { 75 .d_version = D_VERSION, | 82static struct cdevsw apm_cdevsw = { 83 .d_version = D_VERSION, |
84 .d_flags = D_TRACKCLOSE, |
|
76 .d_open = apmopen, 77 .d_close = apmclose, 78 .d_write = apmwrite, 79 .d_ioctl = apmioctl, 80 .d_poll = apmpoll, 81 .d_name = "apm", | 85 .d_open = apmopen, 86 .d_close = apmclose, 87 .d_write = apmwrite, 88 .d_ioctl = apmioctl, 89 .d_poll = apmpoll, 90 .d_name = "apm", |
91 .d_kqfilter = apmkqfilter |
|
82}; 83 84static int 85acpi_capm_convert_battstate(struct acpi_battinfo *battp) 86{ 87 int state; 88 89 state = APM_UNKNOWN; --- 107 unchanged lines hidden (view full) --- 197 if (acpi_acad_get_acline(&acline)) 198 app->ap_acline = APM_UNKNOWN; 199 else 200 app->ap_acline = acline; /* on/off */ 201 202 return (0); 203} 204 | 92}; 93 94static int 95acpi_capm_convert_battstate(struct acpi_battinfo *battp) 96{ 97 int state; 98 99 state = APM_UNKNOWN; --- 107 unchanged lines hidden (view full) --- 207 if (acpi_acad_get_acline(&acline)) 208 app->ap_acline = APM_UNKNOWN; 209 else 210 app->ap_acline = acline; /* on/off */ 211 212 return (0); 213} 214 |
215/* Create single-use devices for /dev/apm and /dev/apmctl. */ 216static void 217apm_clone(void *arg, struct ucred *cred, char *name, int namelen, 218 struct cdev **dev) 219{ 220 int ctl_dev, unit; 221 222 if (*dev != NULL) 223 return; 224 if (strcmp(name, "apmctl") == 0) 225 ctl_dev = TRUE; 226 else if (strcmp(name, "apm") == 0) 227 ctl_dev = FALSE; 228 else 229 return; 230 231 /* Always create a new device and unit number. */ 232 unit = -1; 233 if (clone_create(&apm_clones, &apm_cdevsw, &unit, dev, 0)) { 234 if (ctl_dev) { 235 *dev = make_dev(&apm_cdevsw, unit2minor(unit), 236 UID_ROOT, GID_OPERATOR, 0660, "apmctl%d", unit); 237 } else { 238 *dev = make_dev(&apm_cdevsw, unit2minor(unit), 239 UID_ROOT, GID_OPERATOR, 0664, "apm%d", unit); 240 } 241 if (*dev != NULL) { 242 dev_ref(*dev); 243 (*dev)->si_flags |= SI_CHEAPCLONE; 244 } 245 } 246} 247 248/* Create a struct for tracking per-device suspend notification. */ 249static struct apm_clone_data * 250apm_create_clone(struct cdev *dev, struct acpi_softc *acpi_sc) 251{ 252 struct apm_clone_data *clone; 253 254 clone = malloc(sizeof(*clone), M_APMDEV, M_WAITOK); 255 clone->cdev = dev; 256 clone->acpi_sc = acpi_sc; 257 clone->notify_status = APM_EV_NONE; 258 bzero(&clone->sel_read, sizeof(clone->sel_read)); 259 knlist_init(&clone->sel_read.si_note, &acpi_mutex, NULL, NULL, NULL); 260 261 /* 262 * The acpi device is always managed by devd(8) and is considered 263 * writable (i.e., ack is required to allow suspend to proceed.) 264 */ 265 if (strcmp("acpi", devtoname(dev)) == 0) 266 clone->flags = ACPI_EVF_DEVD | ACPI_EVF_WRITE; 267 else 268 clone->flags = ACPI_EVF_NONE; 269 270 ACPI_LOCK(acpi); 271 STAILQ_INSERT_TAIL(&acpi_sc->apm_cdevs, clone, entries); 272 ACPI_UNLOCK(acpi); 273 return (clone); 274} 275 276/* XXX Kernel should be updated to allow calls to destroy_dev() in close(). */ 277static void 278apm_destroy_clone(void *arg) 279{ 280 281 destroy_dev((struct cdev *)arg); 282} 283 |
|
205static int 206apmopen(struct cdev *dev, int flag, int fmt, d_thread_t *td) 207{ | 284static int 285apmopen(struct cdev *dev, int flag, int fmt, d_thread_t *td) 286{ |
287 struct acpi_softc *acpi_sc; 288 struct apm_clone_data *clone; 289 290 acpi_sc = devclass_get_softc(devclass_find("acpi"), 0); 291 clone = apm_create_clone(dev, acpi_sc); 292 dev->si_drv1 = clone; 293 294 /* If the device is opened for write, record that. */ 295 if ((flag & FWRITE) != 0) 296 clone->flags |= ACPI_EVF_WRITE; 297 |
|
208 return (0); 209} 210 211static int 212apmclose(struct cdev *dev, int flag, int fmt, d_thread_t *td) 213{ | 298 return (0); 299} 300 301static int 302apmclose(struct cdev *dev, int flag, int fmt, d_thread_t *td) 303{ |
304 struct apm_clone_data *clone; 305 struct acpi_softc *acpi_sc; 306 307 clone = dev->si_drv1; 308 acpi_sc = clone->acpi_sc; 309 310 /* We are about to lose a reference so check if suspend should occur */ 311 if (acpi_sc->acpi_next_sstate != 0 && 312 clone->notify_status != APM_EV_ACKED) 313 acpi_AckSleepState(clone, 0); 314 315 /* Remove this clone's data from the list and free it. */ 316 ACPI_LOCK(acpi); 317 STAILQ_REMOVE(&acpi_sc->apm_cdevs, clone, apm_clone_data, entries); 318 knlist_destroy(&clone->sel_read.si_note); 319 ACPI_UNLOCK(acpi); 320 free(clone, M_APMDEV); 321 AcpiOsExecute(OSL_GPE_HANDLER, apm_destroy_clone, dev); |
|
214 return (0); 215} 216 217static int 218apmioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, d_thread_t *td) 219{ | 322 return (0); 323} 324 325static int 326apmioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, d_thread_t *td) 327{ |
220 int error = 0; | 328 int error; 329 struct apm_clone_data *clone; |
221 struct acpi_softc *acpi_sc; | 330 struct acpi_softc *acpi_sc; |
222 struct apm_info info; | 331 struct apm_info info; 332 struct apm_event_info *ev_info; |
223 apm_info_old_t aiop; 224 | 333 apm_info_old_t aiop; 334 |
225 acpi_sc = devclass_get_softc(devclass_find("acpi"), 0); | 335 error = 0; 336 clone = dev->si_drv1; 337 acpi_sc = clone->acpi_sc; |
226 227 switch (cmd) { 228 case APMIO_SUSPEND: 229 if ((flag & FWRITE) == 0) 230 return (EPERM); | 338 339 switch (cmd) { 340 case APMIO_SUSPEND: 341 if ((flag & FWRITE) == 0) 342 return (EPERM); |
231 if (apm_active) 232 acpi_SetSleepState(acpi_sc, acpi_sc->acpi_suspend_sx); 233 else 234 error = EINVAL; | 343 if (acpi_sc->acpi_next_sstate == 0) { 344 if (acpi_sc->acpi_suspend_sx != ACPI_STATE_S5) { 345 error = acpi_ReqSleepState(acpi_sc, 346 acpi_sc->acpi_suspend_sx); 347 } else { 348 printf( 349 "power off via apm suspend not supported\n"); 350 error = ENXIO; 351 } 352 } else 353 error = acpi_AckSleepState(clone, 0); |
235 break; 236 case APMIO_STANDBY: 237 if ((flag & FWRITE) == 0) 238 return (EPERM); | 354 break; 355 case APMIO_STANDBY: 356 if ((flag & FWRITE) == 0) 357 return (EPERM); |
239 if (apm_active) 240 acpi_SetSleepState(acpi_sc, acpi_sc->acpi_standby_sx); 241 else 242 error = EINVAL; | 358 if (acpi_sc->acpi_next_sstate == 0) { 359 if (acpi_sc->acpi_standby_sx != ACPI_STATE_S5) { 360 error = acpi_ReqSleepState(acpi_sc, 361 acpi_sc->acpi_standby_sx); 362 } else { 363 printf( 364 "power off via apm standby not supported\n"); 365 error = ENXIO; 366 } 367 } else 368 error = acpi_AckSleepState(clone, 0); |
243 break; | 369 break; |
370 case APMIO_NEXTEVENT: 371 printf("apm nextevent start\n"); 372 ACPI_LOCK(acpi); 373 if (acpi_sc->acpi_next_sstate != 0 && clone->notify_status == 374 APM_EV_NONE) { 375 ev_info = (struct apm_event_info *)addr; 376 if (acpi_sc->acpi_next_sstate <= ACPI_STATE_S3) 377 ev_info->type = PMEV_STANDBYREQ; 378 else 379 ev_info->type = PMEV_SUSPENDREQ; 380 ev_info->index = 0; 381 clone->notify_status = APM_EV_NOTIFIED; 382 printf("apm event returning %d\n", ev_info->type); 383 } else 384 error = EAGAIN; 385 ACPI_UNLOCK(acpi); 386 break; |
|
244 case APMIO_GETINFO_OLD: 245 if (acpi_capm_get_info(&info)) 246 error = ENXIO; 247 aiop = (apm_info_old_t)addr; 248 aiop->ai_major = info.ai_major; 249 aiop->ai_minor = info.ai_minor; 250 aiop->ai_acline = info.ai_acline; 251 aiop->ai_batt_stat = info.ai_batt_stat; --- 43 unchanged lines hidden (view full) --- 295apmwrite(struct cdev *dev, struct uio *uio, int ioflag) 296{ 297 return (uio->uio_resid); 298} 299 300static int 301apmpoll(struct cdev *dev, int events, d_thread_t *td) 302{ | 387 case APMIO_GETINFO_OLD: 388 if (acpi_capm_get_info(&info)) 389 error = ENXIO; 390 aiop = (apm_info_old_t)addr; 391 aiop->ai_major = info.ai_major; 392 aiop->ai_minor = info.ai_minor; 393 aiop->ai_acline = info.ai_acline; 394 aiop->ai_batt_stat = info.ai_batt_stat; --- 43 unchanged lines hidden (view full) --- 438apmwrite(struct cdev *dev, struct uio *uio, int ioflag) 439{ 440 return (uio->uio_resid); 441} 442 443static int 444apmpoll(struct cdev *dev, int events, d_thread_t *td) 445{ |
446 struct apm_clone_data *clone; 447 int revents; 448 449 revents = 0; 450 ACPI_LOCK(acpi); 451 clone = dev->si_drv1; 452 if (clone->acpi_sc->acpi_next_sstate) 453 revents |= events & (POLLIN | POLLRDNORM); 454 else 455 selrecord(td, &clone->sel_read); 456 ACPI_UNLOCK(acpi); 457 return (revents); 458} 459 460static int 461apmkqfilter(struct cdev *dev, struct knote *kn) 462{ 463 struct apm_clone_data *clone; 464 465 ACPI_LOCK(acpi); 466 clone = dev->si_drv1; 467 kn->kn_hook = clone; 468 kn->kn_fop = &apm_readfiltops; 469 knlist_add(&clone->sel_read.si_note, kn, 0); 470 ACPI_UNLOCK(acpi); |
|
303 return (0); 304} 305 306static void | 471 return (0); 472} 473 474static void |
307acpi_capm_init(struct acpi_softc *sc) | 475apmreadfiltdetach(struct knote *kn) |
308{ | 476{ |
309 make_dev(&apm_cdevsw, 0, 0, 5, 0664, "apm"); | 477 struct apm_clone_data *clone; 478 479 ACPI_LOCK(acpi); 480 clone = kn->kn_hook; 481 knlist_remove(&clone->sel_read.si_note, kn, 0); 482 ACPI_UNLOCK(acpi); |
310} 311 | 483} 484 |
485static int 486apmreadfilt(struct knote *kn, long hint) 487{ 488 struct apm_clone_data *clone; 489 int sleeping; 490 491 ACPI_LOCK(acpi); 492 clone = kn->kn_hook; 493 sleeping = clone->acpi_sc->acpi_next_sstate ? 1 : 0; 494 ACPI_UNLOCK(acpi); 495 return (sleeping); 496} 497 |
|
312int 313acpi_machdep_init(device_t dev) 314{ | 498int 499acpi_machdep_init(device_t dev) 500{ |
315 struct acpi_softc *sc; | 501 struct acpi_softc *acpi_sc; |
316 | 502 |
317 sc = devclass_get_softc(devclass_find("acpi"), 0); 318 acpi_capm_init(sc); | 503 acpi_sc = devclass_get_softc(devclass_find("acpi"), 0); |
319 | 504 |
320 acpi_install_wakeup_handler(sc); | 505 /* Create a clone for /dev/acpi also. */ 506 STAILQ_INIT(&acpi_sc->apm_cdevs); 507 acpi_sc->acpi_clone = apm_create_clone(acpi_sc->acpi_dev_t, acpi_sc); 508 clone_setup(&apm_clones); 509 EVENTHANDLER_REGISTER(dev_clone, apm_clone, 0, 1000); 510 acpi_install_wakeup_handler(acpi_sc); |
321 322 if (intr_model == ACPI_INTR_PIC) 323 BUS_CONFIG_INTR(dev, AcpiGbl_FADT.SciInterrupt, 324 INTR_TRIGGER_LEVEL, INTR_POLARITY_LOW); 325 else 326 acpi_SetIntrModel(intr_model); 327 | 511 512 if (intr_model == ACPI_INTR_PIC) 513 BUS_CONFIG_INTR(dev, AcpiGbl_FADT.SciInterrupt, 514 INTR_TRIGGER_LEVEL, INTR_POLARITY_LOW); 515 else 516 acpi_SetIntrModel(intr_model); 517 |
328 SYSCTL_ADD_UINT(&sc->acpi_sysctl_ctx, 329 SYSCTL_CHILDREN(sc->acpi_sysctl_tree), OID_AUTO, | 518 SYSCTL_ADD_UINT(&acpi_sc->acpi_sysctl_ctx, 519 SYSCTL_CHILDREN(acpi_sc->acpi_sysctl_tree), OID_AUTO, |
330 "reset_video", CTLFLAG_RW, &acpi_reset_video, 0, 331 "Call the VESA reset BIOS vector on the resume path"); 332 333 return (0); 334} 335 336void 337acpi_SetDefaultIntrModel(int model) --- 32 unchanged lines hidden --- | 520 "reset_video", CTLFLAG_RW, &acpi_reset_video, 0, 521 "Call the VESA reset BIOS vector on the resume path"); 522 523 return (0); 524} 525 526void 527acpi_SetDefaultIntrModel(int model) --- 32 unchanged lines hidden --- |