Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 | /* * acpi_system.c - ACPI System Driver ($Revision: 45 $) * * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ #include <linux/config.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/init.h> #include <linux/types.h> #include <linux/spinlock.h> #include <linux/poll.h> #include <linux/delay.h> #include <linux/sysrq.h> #include <linux/pm.h> #include <linux/device.h> #include <linux/suspend.h> #include <asm/uaccess.h> #include <asm/acpi.h> #include "acpi_bus.h" #include "acpi_drivers.h" #ifdef CONFIG_X86 #ifdef CONFIG_ACPI_SLEEP #include <linux/mc146818rtc.h> #endif #endif #define _COMPONENT ACPI_SYSTEM_COMPONENT ACPI_MODULE_NAME ("acpi_system") #define PREFIX "ACPI: " extern FADT_DESCRIPTOR acpi_fadt; static int acpi_system_add (struct acpi_device *device); static int acpi_system_remove (struct acpi_device *device, int type); static struct acpi_driver acpi_system_driver = { name: ACPI_SYSTEM_DRIVER_NAME, class: ACPI_SYSTEM_CLASS, ids: ACPI_SYSTEM_HID, ops: { add: acpi_system_add, remove: acpi_system_remove }, }; struct acpi_system { acpi_handle handle; u8 states[ACPI_S_STATE_COUNT]; }; /* Global vars for handling event proc entry */ static spinlock_t acpi_system_event_lock = SPIN_LOCK_UNLOCKED; int event_is_open = 0; extern struct list_head acpi_bus_event_list; extern wait_queue_head_t acpi_bus_event_queue; /* -------------------------------------------------------------------------- System Sleep -------------------------------------------------------------------------- */ #ifdef CONFIG_PM static void acpi_power_off (void) { acpi_enter_sleep_state_prep(ACPI_STATE_S5); ACPI_DISABLE_IRQS(); acpi_enter_sleep_state(ACPI_STATE_S5); } #endif /*CONFIG_PM*/ #ifdef CONFIG_ACPI_SLEEP /** * acpi_system_restore_state - OS-specific restoration of state * @state: sleep state we're exiting * * Note that if we're coming back from S4, the memory image should have already * been loaded from the disk and is already in place. (Otherwise how else would we * be here?). */ acpi_status acpi_system_restore_state ( u32 state) { /* restore processor state * We should only be here if we're coming back from STR or STD. * And, in the case of the latter, the memory image should have already * been loaded from disk. */ if (state > ACPI_STATE_S1) acpi_restore_state_mem(); /* wait for power to come back */ mdelay(10); #ifdef HAVE_NEW_DEVICE_MODEL /* turn all the devices back on */ device_resume(RESUME_POWER_ON); /* enable interrupts once again */ ACPI_ENABLE_IRQS(); /* restore device context */ device_resume(RESUME_RESTORE_STATE); #endif if (dmi_broken & BROKEN_INIT_AFTER_S1) { printk("Broken toshiba laptop -> kicking interrupts\n"); init_8259A(0); } return AE_OK; } /** * acpi_system_save_state - save OS specific state and power down devices * @state: sleep state we're entering. * * This handles saving all context to memory, and possibly disk. * First, we call to the device driver layer to save device state. * Once we have that, we save whatevery processor and kernel state we * need to memory. * If we're entering S4, we then write the memory image to disk. * * Only then is it safe for us to power down devices, since we may need * the disks and upstream buses to write to. */ acpi_status acpi_system_save_state( u32 state) { int error = 0; #ifdef HAVE_NEW_DEVICE_MODEL /* Send notification to devices that they will be suspended. * If any device or driver cannot make the transition, either up * or down, we'll get an error back. */ error = device_suspend(state, SUSPEND_NOTIFY); if (error) return AE_ERROR; #endif if (state < ACPI_STATE_S5) { #ifdef HAVE_NEW_DEVICE_MODEL /* Tell devices to stop I/O and actually save their state. * It is theoretically possible that something could fail, * so handle that gracefully.. */ error = device_suspend(state, SUSPEND_SAVE_STATE); if (error) { /* tell devices to restore state if they have * it saved and to start taking I/O requests. */ device_resume(RESUME_RESTORE_STATE); return error; } #endif /* flush caches */ wbinvd(); /* Do arch specific saving of state. */ if (state > ACPI_STATE_S1) { error = acpi_save_state_mem(); if (!error && (state == ACPI_STATE_S4)) error = acpi_save_state_disk(); #ifdef HAVE_NEW_DEVICE_MODEL if (error) { device_resume(RESUME_RESTORE_STATE); return error; } #endif } } #ifdef HAVE_NEW_DEVICE_MODEL /* disable interrupts * Note that acpi_suspend -- our caller -- will do this once we return. * But, we want it done early, so we don't get any suprises during * the device suspend sequence. */ ACPI_DISABLE_IRQS(); /* Unconditionally turn off devices. * Obvious if we enter a sleep state. * If entering S5 (soft off), this should put devices in a * quiescent state. */ error = device_suspend(state, SUSPEND_POWER_DOWN); /* We're pretty screwed if we got an error from this. * We try to recover by simply calling our own restore_state * function; see above for definition. * * If it's S5 though, go through with it anyway.. */ if (error && state != ACPI_STATE_S5) acpi_system_restore_state(state); #endif return error ? AE_ERROR : AE_OK; } /**************************************************************************** * * FUNCTION: acpi_system_suspend * * PARAMETERS: %state: Sleep state to enter. * * RETURN: acpi_status, whether or not we successfully entered and * exited sleep. * * DESCRIPTION: Perform OS-specific action to enter sleep state. * This is the final step in going to sleep, per spec. If we * know we're coming back (i.e. not entering S5), we save the * processor flags. [ We'll have to save and restore them anyway, * so we use the arch-agnostic save_flags and restore_flags * here.] We then set the place to return to in arch-specific * globals using arch_set_return_point. Finally, we call the * ACPI function to write the proper values to I/O ports. * ****************************************************************************/ acpi_status acpi_system_suspend( u32 state) { acpi_status status = AE_ERROR; unsigned long flags = 0; save_flags(flags); switch (state) { case ACPI_STATE_S1: barrier(); status = acpi_enter_sleep_state(state); break; case ACPI_STATE_S2: case ACPI_STATE_S3: do_suspend_magic(0); break; } acpi_restore_register_state(); restore_flags(flags); return status; } /** * acpi_suspend - OS-agnostic system suspend/resume support (S? states) * @state: state we're entering * */ acpi_status acpi_suspend ( u32 state) { acpi_status status; /* get out if state is invalid */ if (state < ACPI_STATE_S1 || state > ACPI_STATE_S5) return AE_ERROR; freeze_processes(); /* do we have a wakeup address for S2 and S3? */ if (state == ACPI_STATE_S2 || state == ACPI_STATE_S3) { if (!acpi_wakeup_address) return AE_ERROR; acpi_set_firmware_waking_vector((ACPI_PHYSICAL_ADDRESS) acpi_wakeup_address); } acpi_enter_sleep_state_prep(state); status = acpi_system_save_state(state); if (!ACPI_SUCCESS(status)) return status; /* disable interrupts and flush caches */ ACPI_DISABLE_IRQS(); wbinvd(); /* perform OS-specific sleep actions */ status = acpi_system_suspend(state); /* Even if we failed to go to sleep, all of the devices are in an suspended * mode. So, we run these unconditionaly to make sure we have a usable system * no matter what. */ acpi_system_restore_state(state); acpi_leave_sleep_state(state); /* make sure interrupts are enabled */ ACPI_ENABLE_IRQS(); /* reset firmware waking vector */ acpi_set_firmware_waking_vector((ACPI_PHYSICAL_ADDRESS) 0); thaw_processes(); return status; } #endif /* CONFIG_ACPI_SLEEP */ /* -------------------------------------------------------------------------- FS Interface (/proc) -------------------------------------------------------------------------- */ #include <linux/compatmac.h> #include <linux/proc_fs.h> static int acpi_system_read_info ( char *page, char **start, off_t off, int count, int *eof, void *data) { struct acpi_system *system = (struct acpi_system *) data; char *p = page; int size = 0; u32 i = 0; ACPI_FUNCTION_TRACE("acpi_system_read_info"); if (!system || (off != 0)) goto end; p += sprintf(p, "version: %x\n", ACPI_CA_VERSION); p += sprintf(p, "states: "); for (i=0; i<ACPI_S_STATE_COUNT; i++) { if (system->states[i]) p += sprintf(p, "S%d ", i); } p += sprintf(p, "\n"); end: size = (p - page); if (size <= off+count) *eof = 1; *start = page + off; size -= off; if (size>count) size = count; if (size<0) size = 0; return_VALUE(size); } static int acpi_system_open_event(struct inode *inode, struct file *file); static ssize_t acpi_system_read_event (struct file*, char*, size_t, loff_t*); static int acpi_system_close_event(struct inode *inode, struct file *file); static unsigned int acpi_system_poll_event(struct file *file, poll_table *wait); static struct file_operations acpi_system_event_ops = { open: acpi_system_open_event, read: acpi_system_read_event, release: acpi_system_close_event, poll: acpi_system_poll_event, }; static int acpi_system_open_event(struct inode *inode, struct file *file) { spin_lock_irq (&acpi_system_event_lock); if(event_is_open) goto out_busy; event_is_open = 1; spin_unlock_irq (&acpi_system_event_lock); return 0; out_busy: spin_unlock_irq (&acpi_system_event_lock); return -EBUSY; } static ssize_t acpi_system_read_event ( struct file *file, char *buffer, size_t count, loff_t *ppos) { int result = 0; char outbuf[ACPI_MAX_STRING]; int size = 0; struct acpi_bus_event event; ACPI_FUNCTION_TRACE("acpi_system_read_event"); memset(&event, 0, sizeof(struct acpi_bus_event)); if (count < ACPI_MAX_STRING) goto end; if ((file->f_flags & O_NONBLOCK) && (list_empty(&acpi_bus_event_list))) return_VALUE(-EAGAIN); result = acpi_bus_receive_event(&event); if (0 != result) { size = sprintf(outbuf, "error\n"); goto end; } size = sprintf(outbuf, "%s %s %08x %08x\n", event.device_class?event.device_class:"<unknown>", event.bus_id?event.bus_id:"<unknown>", event.type, event.data); end: if (copy_to_user(buffer, outbuf, size)) return_VALUE(-EFAULT); *ppos += size; return_VALUE(size); } static int acpi_system_close_event(struct inode *inode, struct file *file) { spin_lock_irq (&acpi_system_event_lock); event_is_open = 0; spin_unlock_irq (&acpi_system_event_lock); return 0; } static unsigned int acpi_system_poll_event( struct file *file, poll_table *wait) { poll_wait(file, &acpi_bus_event_queue, wait); if (!list_empty(&acpi_bus_event_list)) return POLLIN | POLLRDNORM; return 0; } static ssize_t acpi_system_read_dsdt (struct file*, char*, size_t, loff_t*); static struct file_operations acpi_system_dsdt_ops = { read: acpi_system_read_dsdt, }; static ssize_t acpi_system_read_dsdt ( struct file *file, char *buffer, size_t count, loff_t *ppos) { acpi_status status = AE_OK; acpi_buffer dsdt = {ACPI_ALLOCATE_BUFFER, NULL}; void *data = 0; size_t size = 0; ACPI_FUNCTION_TRACE("acpi_system_read_dsdt"); status = acpi_get_table(ACPI_TABLE_DSDT, 1, &dsdt); if (ACPI_FAILURE(status)) return_VALUE(-ENODEV); if (*ppos < dsdt.length) { data = dsdt.pointer + file->f_pos; size = dsdt.length - file->f_pos; if (size > count) size = count; if (copy_to_user(buffer, data, size)) { kfree(dsdt.pointer); return_VALUE(-EFAULT); } } kfree(dsdt.pointer); *ppos += size; return_VALUE(size); } static ssize_t acpi_system_read_fadt (struct file*, char*, size_t, loff_t*); static struct file_operations acpi_system_fadt_ops = { read: acpi_system_read_fadt, }; static ssize_t acpi_system_read_fadt ( struct file *file, char *buffer, size_t count, loff_t *ppos) { acpi_status status = AE_OK; acpi_buffer fadt = {ACPI_ALLOCATE_BUFFER, NULL}; void *data = 0; size_t size = 0; ACPI_FUNCTION_TRACE("acpi_system_read_fadt"); status = acpi_get_table(ACPI_TABLE_FADT, 1, &fadt); if (ACPI_FAILURE(status)) return_VALUE(-ENODEV); if (*ppos < fadt.length) { data = fadt.pointer + file->f_pos; size = fadt.length - file->f_pos; if (size > count) size = count; if (copy_to_user(buffer, data, size)) { kfree(fadt.pointer); return_VALUE(-EFAULT); } } kfree(fadt.pointer); *ppos += size; return_VALUE(size); } #ifdef ACPI_DEBUG static int acpi_system_read_debug ( char *page, char **start, off_t off, int count, int *eof, void *data) { char *p = page; int size = 0; if (off != 0) goto end; switch ((unsigned long) data) { case 0: p += sprintf(p, "0x%08x\n", acpi_dbg_layer); break; case 1: p += sprintf(p, "0x%08x\n", acpi_dbg_level); break; default: p += sprintf(p, "Invalid debug option\n"); break; } end: size = (p - page); if (size <= off+count) *eof = 1; *start = page + off; size -= off; if (size>count) size = count; if (size<0) size = 0; return size; } static int acpi_system_write_debug ( struct file *file, const char *buffer, unsigned long count, void *data) { char debug_string[12] = {'\0'}; ACPI_FUNCTION_TRACE("acpi_system_write_debug"); if (count > sizeof(debug_string) - 1) return_VALUE(-EINVAL); if (copy_from_user(debug_string, buffer, count)) return_VALUE(-EFAULT); debug_string[count] = '\0'; switch ((unsigned long) data) { case 0: acpi_dbg_layer = simple_strtoul(debug_string, NULL, 0); break; case 1: acpi_dbg_level = simple_strtoul(debug_string, NULL, 0); break; default: return_VALUE(-EINVAL); } return_VALUE(count); } #endif /* ACPI_DEBUG */ #ifdef CONFIG_ACPI_SLEEP static int acpi_system_read_sleep ( char *page, char **start, off_t off, int count, int *eof, void *data) { struct acpi_system *system = (struct acpi_system *) data; char *p = page; int size; int i; ACPI_FUNCTION_TRACE("acpi_system_read_sleep"); if (!system || (off != 0)) goto end; for (i = 0; i <= ACPI_STATE_S5; i++) { if (system->states[i]) p += sprintf(p,"S%d ", i); } p += sprintf(p, "\n"); end: size = (p - page); if (size <= off+count) *eof = 1; *start = page + off; size -= off; if (size>count) size = count; if (size<0) size = 0; return_VALUE(size); } static int acpi_system_write_sleep ( struct file *file, const char *buffer, unsigned long count, void *data) { acpi_status status = AE_OK; struct acpi_system *system = (struct acpi_system *) data; char state_string[12] = {'\0'}; u32 state = 0; ACPI_FUNCTION_TRACE("acpi_system_write_sleep"); if (!system || (count > sizeof(state_string) - 1)) return_VALUE(-EINVAL); if (copy_from_user(state_string, buffer, count)) return_VALUE(-EFAULT); state_string[count] = '\0'; state = simple_strtoul(state_string, NULL, 0); if (!system->states[state]) return_VALUE(-ENODEV); #ifdef CONFIG_SOFTWARE_SUSPEND if (state == 4) { /* We are working from process context, that's why we may call it directly. */ do_software_suspend(); return_VALUE(count); } #endif status = acpi_suspend(state); if (ACPI_FAILURE(status)) return_VALUE(-ENODEV); return_VALUE(count); } static int acpi_system_read_alarm ( char *page, char **start, off_t off, int count, int *eof, void *context) { char *p = page; int size = 0; u32 sec, min, hr; u32 day, mo, yr; ACPI_FUNCTION_TRACE("acpi_system_read_alarm"); if (off != 0) goto end; spin_lock(&rtc_lock); sec = CMOS_READ(RTC_SECONDS_ALARM); min = CMOS_READ(RTC_MINUTES_ALARM); hr = CMOS_READ(RTC_HOURS_ALARM); #if 0 /* If we ever get an FACP with proper values... */ if (acpi_gbl_FADT->day_alrm) day = CMOS_READ(acpi_gbl_FADT->day_alrm); else day = CMOS_READ(RTC_DAY_OF_MONTH); if (acpi_gbl_FADT->mon_alrm) mo = CMOS_READ(acpi_gbl_FADT->mon_alrm); else mo = CMOS_READ(RTC_MONTH);; if (acpi_gbl_FADT->century) yr = CMOS_READ(acpi_gbl_FADT->century) * 100 + CMOS_READ(RTC_YEAR); else yr = CMOS_READ(RTC_YEAR); #else day = CMOS_READ(RTC_DAY_OF_MONTH); mo = CMOS_READ(RTC_MONTH); yr = CMOS_READ(RTC_YEAR); #endif spin_unlock(&rtc_lock); BCD_TO_BIN(sec); BCD_TO_BIN(min); BCD_TO_BIN(hr); BCD_TO_BIN(day); BCD_TO_BIN(mo); BCD_TO_BIN(yr); p += sprintf(p,"%4.4u-", yr); p += (mo > 12) ? sprintf(p, "**-") : sprintf(p, "%2.2u-", mo); p += (day > 31) ? sprintf(p, "** ") : sprintf(p, "%2.2u ", day); p += (hr > 23) ? sprintf(p, "**:") : sprintf(p, "%2.2u:", hr); p += (min > 59) ? sprintf(p, "**:") : sprintf(p, "%2.2u:", min); p += (sec > 59) ? sprintf(p, "**\n") : sprintf(p, "%2.2u\n", sec); end: size = p - page; if (size < count) *eof = 1; else if (size > count) size = count; if (size < 0) size = 0; *start = page; return_VALUE(size); } static int get_date_field ( char **p, u32 *value) { char *next = NULL; char *string_end = NULL; int result = -EINVAL; /* * Try to find delimeter, only to insert null. The end of the * string won't have one, but is still valid. */ next = strpbrk(*p, "- :"); if (next) *next++ = '\0'; *value = simple_strtoul(*p, &string_end, 10); /* Signal success if we got a good digit */ if (string_end != *p) result = 0; if (next) *p = next; return result; } static int acpi_system_write_alarm ( struct file *file, const char *buffer, unsigned long count, void *data) { int result = 0; char alarm_string[30] = {'\0'}; char *p = alarm_string; u32 sec, min, hr, day, mo, yr; int adjust = 0; unsigned char rtc_control = 0; ACPI_FUNCTION_TRACE("acpi_system_write_alarm"); if (count > sizeof(alarm_string) - 1) return_VALUE(-EINVAL); if (copy_from_user(alarm_string, buffer, count)) return_VALUE(-EFAULT); alarm_string[count] = '\0'; /* check for time adjustment */ if (alarm_string[0] == '+') { p++; adjust = 1; } if ((result = get_date_field(&p, &yr))) goto end; if ((result = get_date_field(&p, &mo))) goto end; if ((result = get_date_field(&p, &day))) goto end; if ((result = get_date_field(&p, &hr))) goto end; if ((result = get_date_field(&p, &min))) goto end; if ((result = get_date_field(&p, &sec))) goto end; if (sec > 59) { min += 1; sec -= 60; } if (min > 59) { hr += 1; min -= 60; } if (hr > 23) { day += 1; hr -= 24; } if (day > 31) { mo += 1; day -= 31; } if (mo > 12) { yr += 1; mo -= 12; } spin_lock_irq(&rtc_lock); rtc_control = CMOS_READ(RTC_CONTROL); if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { BIN_TO_BCD(yr); BIN_TO_BCD(mo); BIN_TO_BCD(day); BIN_TO_BCD(hr); BIN_TO_BCD(min); BIN_TO_BCD(sec); } if (adjust) { yr += CMOS_READ(RTC_YEAR); mo += CMOS_READ(RTC_MONTH); day += CMOS_READ(RTC_DAY_OF_MONTH); hr += CMOS_READ(RTC_HOURS); min += CMOS_READ(RTC_MINUTES); sec += CMOS_READ(RTC_SECONDS); } spin_unlock_irq(&rtc_lock); if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { BCD_TO_BIN(yr); BCD_TO_BIN(mo); BCD_TO_BIN(day); BCD_TO_BIN(hr); BCD_TO_BIN(min); BCD_TO_BIN(sec); } if (sec > 59) { min++; sec -= 60; } if (min > 59) { hr++; min -= 60; } if (hr > 23) { day++; hr -= 24; } if (day > 31) { mo++; day -= 31; } if (mo > 12) { yr++; mo -= 12; } if (!(rtc_control & RTC_DM_BINARY) || RTC_ALWAYS_BCD) { BIN_TO_BCD(yr); BIN_TO_BCD(mo); BIN_TO_BCD(day); BIN_TO_BCD(hr); BIN_TO_BCD(min); BIN_TO_BCD(sec); } spin_lock_irq(&rtc_lock); /* write the fields the rtc knows about */ CMOS_WRITE(hr, RTC_HOURS_ALARM); CMOS_WRITE(min, RTC_MINUTES_ALARM); CMOS_WRITE(sec, RTC_SECONDS_ALARM); /* * If the system supports an enhanced alarm it will have non-zero * offsets into the CMOS RAM here -- which for some reason are pointing * to the RTC area of memory. */ #if 0 if (acpi_gbl_FADT->day_alrm) CMOS_WRITE(day, acpi_gbl_FADT->day_alrm); if (acpi_gbl_FADT->mon_alrm) CMOS_WRITE(mo, acpi_gbl_FADT->mon_alrm); if (acpi_gbl_FADT->century) CMOS_WRITE(yr/100, acpi_gbl_FADT->century); #endif /* enable the rtc alarm interrupt */ if (!(rtc_control & RTC_AIE)) { rtc_control |= RTC_AIE; CMOS_WRITE(rtc_control,RTC_CONTROL); CMOS_READ(RTC_INTR_FLAGS); } spin_unlock_irq(&rtc_lock); acpi_hw_bit_register_write(ACPI_BITREG_RT_CLOCK_ENABLE, 1, ACPI_MTX_LOCK); file->f_pos += count; result = 0; end: return_VALUE(result ? result : count); } #endif /*CONFIG_ACPI_SLEEP*/ static int acpi_system_add_fs ( struct acpi_device *device) { struct proc_dir_entry *entry = NULL; ACPI_FUNCTION_TRACE("acpi_system_add_fs"); if (!device) return_VALUE(-EINVAL); /* 'info' [R] */ entry = create_proc_entry(ACPI_SYSTEM_FILE_INFO, S_IRUGO, acpi_device_dir(device)); if (!entry) ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unable to create '%s' fs entry\n", ACPI_SYSTEM_FILE_INFO)); else { entry->read_proc = acpi_system_read_info; entry->data = acpi_driver_data(device); } /* 'dsdt' [R] */ entry = create_proc_entry(ACPI_SYSTEM_FILE_DSDT, S_IRUSR, acpi_device_dir(device)); if (!entry) ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unable to create '%s' fs entry\n", ACPI_SYSTEM_FILE_DSDT)); else entry->proc_fops = &acpi_system_dsdt_ops; /* 'fadt' [R] */ entry = create_proc_entry(ACPI_SYSTEM_FILE_FADT, S_IRUSR, acpi_device_dir(device)); if (!entry) ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unable to create '%s' fs entry\n", ACPI_SYSTEM_FILE_FADT)); else entry->proc_fops = &acpi_system_fadt_ops; /* 'event' [R] */ entry = create_proc_entry(ACPI_SYSTEM_FILE_EVENT, S_IRUSR, acpi_device_dir(device)); if (!entry) ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unable to create '%s' fs entry\n", ACPI_SYSTEM_FILE_EVENT)); else entry->proc_fops = &acpi_system_event_ops; #ifdef CONFIG_ACPI_SLEEP /* 'sleep' [R/W]*/ entry = create_proc_entry(ACPI_SYSTEM_FILE_SLEEP, S_IFREG|S_IRUGO|S_IWUSR, acpi_device_dir(device)); if (!entry) ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unable to create '%s' fs entry\n", ACPI_SYSTEM_FILE_SLEEP)); else { entry->read_proc = acpi_system_read_sleep; entry->write_proc = acpi_system_write_sleep; entry->data = acpi_driver_data(device); } /* 'alarm' [R/W] */ entry = create_proc_entry(ACPI_SYSTEM_FILE_ALARM, S_IFREG|S_IRUGO|S_IWUSR, acpi_device_dir(device)); if (!entry) ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unable to create '%s' fs entry\n", ACPI_SYSTEM_FILE_ALARM)); else { entry->read_proc = acpi_system_read_alarm; entry->write_proc = acpi_system_write_alarm; entry->data = acpi_driver_data(device); } #endif /*CONFIG_ACPI_SLEEP*/ #ifdef ACPI_DEBUG /* 'debug_layer' [R/W] */ entry = create_proc_entry(ACPI_SYSTEM_FILE_DEBUG_LAYER, S_IFREG|S_IRUGO|S_IWUSR, acpi_device_dir(device)); if (!entry) ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unable to create '%s' fs entry\n", ACPI_SYSTEM_FILE_DEBUG_LAYER)); else { entry->read_proc = acpi_system_read_debug; entry->write_proc = acpi_system_write_debug; entry->data = (void *) 0; } /* 'debug_level' [R/W] */ entry = create_proc_entry(ACPI_SYSTEM_FILE_DEBUG_LEVEL, S_IFREG|S_IRUGO|S_IWUSR, acpi_device_dir(device)); if (!entry) ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unable to create '%s' fs entry\n", ACPI_SYSTEM_FILE_DEBUG_LEVEL)); else { entry->read_proc = acpi_system_read_debug; entry->write_proc = acpi_system_write_debug; entry->data = (void *) 1; } #endif /*ACPI_DEBUG*/ return_VALUE(0); } static int acpi_system_remove_fs ( struct acpi_device *device) { ACPI_FUNCTION_TRACE("acpi_system_remove_fs"); if (!device) return_VALUE(-EINVAL); remove_proc_entry(ACPI_SYSTEM_FILE_INFO, acpi_device_dir(device)); remove_proc_entry(ACPI_SYSTEM_FILE_DSDT, acpi_device_dir(device)); remove_proc_entry(ACPI_SYSTEM_FILE_EVENT, acpi_device_dir(device)); #ifdef CONFIG_ACPI_SLEEP remove_proc_entry(ACPI_SYSTEM_FILE_SLEEP, acpi_device_dir(device)); remove_proc_entry(ACPI_SYSTEM_FILE_ALARM, acpi_device_dir(device)); #endif #ifdef ACPI_DEBUG remove_proc_entry(ACPI_SYSTEM_FILE_DEBUG_LAYER, acpi_device_dir(device)); remove_proc_entry(ACPI_SYSTEM_FILE_DEBUG_LEVEL, acpi_device_dir(device)); #endif return_VALUE(0); } /* -------------------------------------------------------------------------- Driver Interface -------------------------------------------------------------------------- */ #if defined(CONFIG_MAGIC_SYSRQ) && defined(CONFIG_PM) /* Simple wrapper calling power down function. */ static void acpi_sysrq_power_off(int key, struct pt_regs *pt_regs, struct kbd_struct *kbd, struct tty_struct *tty) { acpi_power_off(); } struct sysrq_key_op sysrq_acpi_poweroff_op = { handler: &acpi_sysrq_power_off, help_msg: "Off", action_msg: "Power Off\n" }; #endif /* CONFIG_MAGIC_SYSRQ */ static int acpi_system_add ( struct acpi_device *device) { int result = 0; acpi_status status = AE_OK; struct acpi_system *system = NULL; u8 i = 0; ACPI_FUNCTION_TRACE("acpi_system_add"); if (!device) return_VALUE(-EINVAL); system = kmalloc(sizeof(struct acpi_system), GFP_KERNEL); if (!system) return_VALUE(-ENOMEM); memset(system, 0, sizeof(struct acpi_system)); system->handle = device->handle; sprintf(acpi_device_name(device), "%s", ACPI_SYSTEM_DEVICE_NAME); sprintf(acpi_device_class(device), "%s", ACPI_SYSTEM_CLASS); acpi_driver_data(device) = system; result = acpi_system_add_fs(device); if (0 != result) goto end; printk(KERN_INFO PREFIX "%s [%s] (supports", acpi_device_name(device), acpi_device_bid(device)); for (i=0; i<ACPI_S_STATE_COUNT; i++) { u8 type_a, type_b; status = acpi_hw_get_sleep_type_data(i, &type_a, &type_b); if (ACPI_SUCCESS(status)) { system->states[i] = 1; printk(" S%d", i); } } printk(")\n"); #ifdef CONFIG_SOFTWARE_SUSPEND printk(KERN_INFO "Software suspend => we can do S4."); system->states[4] = 1; #endif #ifdef CONFIG_PM /* Install the soft-off (S5) handler. */ if (system->states[ACPI_STATE_S5]) { pm_power_off = acpi_power_off; register_sysrq_key('o', &sysrq_acpi_poweroff_op); } #endif end: if (0 != result) kfree(system); return_VALUE(result); } static int acpi_system_remove ( struct acpi_device *device, int type) { struct acpi_system *system = NULL; ACPI_FUNCTION_TRACE("acpi_system_remove"); if (!device || !acpi_driver_data(device)) return_VALUE(-EINVAL); system = (struct acpi_system *) acpi_driver_data(device); #ifdef CONFIG_PM /* Remove the soft-off (S5) handler. */ if (system->states[ACPI_STATE_S5]) { unregister_sysrq_key('o', &sysrq_acpi_poweroff_op); pm_power_off = NULL; } #endif acpi_system_remove_fs(device); kfree(system); return 0; } int __init acpi_system_init (void) { int result = 0; ACPI_FUNCTION_TRACE("acpi_system_init"); result = acpi_bus_register_driver(&acpi_system_driver); if (0 > result) return_VALUE(-ENODEV); return_VALUE(0); } void __exit acpi_system_exit (void) { ACPI_FUNCTION_TRACE("acpi_system_exit"); acpi_bus_unregister_driver(&acpi_system_driver); return_VOID; } |