|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights ! 7: * Reserved. This file contains Original Code and/or Modifications of ! 8: * Original Code as defined in and that are subject to the Apple Public ! 9: * Source License Version 1.1 (the "License"). You may not use this file ! 10: * except in compliance with the License. Please obtain a copy of the ! 11: * License at http://www.apple.com/publicsource and read it before using ! 12: * this file. ! 13: * ! 14: * The Original Code and all software distributed under the License are ! 15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ! 16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ! 17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ! 18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the ! 19: * License for the specific language governing rights and limitations ! 20: * under the License. ! 21: * ! 22: * @APPLE_LICENSE_HEADER_END@ ! 23: */ ! 24: ! 25: /* ! 26: * Copyright 1994 NeXT Computer, Inc. ! 27: * All rights reserved. ! 28: */ ! 29: ! 30: #ifdef KERNEL_PRIVATE ! 31: ! 32: #import <mach/mach_types.h> ! 33: ! 34: #import <machdep/i386/seg.h> ! 35: #import <machdep/i386/bios.h> ! 36: ! 37: #import <kern/power.h> ! 38: ! 39: #import <architecture/i386/frame.h> ! 40: ! 41: /* APM 1.0 */ ! 42: #define APM_BIOS_CODE 0x53 ! 43: #define APM_BIOS_IDLE 0x05 ! 44: #define APM_BIOS_BUSY 0x06 ! 45: #define APM_BIOS_SETSTATE 0x07 ! 46: #define APM_BIOS_DISABLE 0x08 ! 47: #define APM_BIOS_DEFAULT 0x09 ! 48: #define APM_BIOS_GETSTATUS 0x0A ! 49: #define APM_BIOS_GETEVENT 0x0B ! 50: ! 51: /* APM 1.1 */ ! 52: #define APM_BIOS_GETSTATE 0x0C ! 53: #define APM_BIOS_ENBL_DEVICE 0x0D ! 54: #define APM_BIOS_VERSION 0x0E ! 55: #define APM_BIOS_ENGAGE 0x0F ! 56: ! 57: static unsigned long APM_BIOS_addr; ! 58: ! 59: static inline void ! 60: initBIOSBuf( ! 61: biosBuf_t *bb, ! 62: unsigned char code ! 63: ) ! 64: { ! 65: union { ! 66: unsigned short data; ! 67: sel_t sel; ! 68: } u; ! 69: ! 70: bb->eax.r.h = APM_BIOS_CODE; ! 71: bb->eax.r.l = code; ! 72: u.sel = APMCODE32_SEL; ! 73: bb->cs = u.data; ! 74: u.sel = KDS_SEL; ! 75: bb->ds = u.data; ! 76: bb->addr = APM_BIOS_addr; ! 77: } ! 78: ! 79: static inline PMReturn ! 80: BIOSToPM( ! 81: int biosReturn ! 82: ) ! 83: { ! 84: if (biosReturn == 0x00) ! 85: return PM_R_UNKNOWN; ! 86: else ! 87: return (PMReturn)pm_err(biosReturn); ! 88: } ! 89: ! 90: /* ! 91: * Inlines for APM BIOS calls. ! 92: */ ! 93: ! 94: static inline PMReturn ! 95: APMBIOS_Idle() ! 96: { ! 97: biosBuf_t bb; ! 98: ! 99: initBIOSBuf(&bb, APM_BIOS_IDLE); ! 100: bios32(&bb); ! 101: if ((bb.flags & EFL_CF) == 0) ! 102: return PM_R_SUCCESS; ! 103: else ! 104: return BIOSToPM(bb.eax.r.h); ! 105: } ! 106: ! 107: static inline PMReturn ! 108: APMBIOS_Busy() ! 109: { ! 110: biosBuf_t bb; ! 111: ! 112: initBIOSBuf(&bb, APM_BIOS_BUSY); ! 113: bios32(&bb); ! 114: if ((bb.flags & EFL_CF) == 0) ! 115: return PM_R_SUCCESS; ! 116: else ! 117: return BIOSToPM(bb.eax.r.h); ! 118: } ! 119: ! 120: static inline PMReturn ! 121: APMBIOS_SetPowerState( ! 122: unsigned short deviceID, ! 123: unsigned short stateID ! 124: ) ! 125: { ! 126: biosBuf_t bb; ! 127: ! 128: initBIOSBuf(&bb, APM_BIOS_SETSTATE); ! 129: bb.ebx.rx = deviceID; ! 130: bb.ecx.rx = stateID; ! 131: bios32(&bb); ! 132: if ((bb.flags & EFL_CF) == 0) ! 133: return PM_R_SUCCESS; ! 134: else ! 135: return BIOSToPM(bb.eax.r.h); ! 136: } ! 137: ! 138: static inline PMReturn ! 139: APMBIOS_GetPowerStatus( ! 140: unsigned char *line_status, ! 141: unsigned char *batt_status, ! 142: unsigned char *batt_life ! 143: ) ! 144: { ! 145: biosBuf_t bb; ! 146: ! 147: initBIOSBuf(&bb, APM_BIOS_GETSTATUS); ! 148: bb.ebx.rx = 0x0001; ! 149: bios32(&bb); ! 150: if ((bb.flags & EFL_CF) == 0) { ! 151: *line_status = bb.ebx.r.h; ! 152: *batt_status = bb.ebx.r.l; ! 153: *batt_life = bb.ecx.r.l; ! 154: return PM_R_SUCCESS; ! 155: } ! 156: return BIOSToPM(bb.eax.r.h); ! 157: } ! 158: ! 159: static inline PMReturn ! 160: APMBIOS_GetPowerEvent( ! 161: unsigned short *event_code ! 162: ) ! 163: { ! 164: biosBuf_t bb; ! 165: ! 166: initBIOSBuf(&bb, APM_BIOS_GETEVENT); ! 167: bios32(&bb); ! 168: if ((bb.flags & EFL_CF) == 0) { ! 169: *event_code = bb.ebx.rx; ! 170: return PM_R_SUCCESS; ! 171: } ! 172: return BIOSToPM(bb.eax.r.h); ! 173: } ! 174: ! 175: static inline PMReturn ! 176: APMBIOS_SetSystemPowerManagement( ! 177: int enabled ! 178: ) ! 179: { ! 180: biosBuf_t bb; ! 181: ! 182: initBIOSBuf(&bb, APM_BIOS_DISABLE); ! 183: bb.ecx.rx = enabled ? 1 : 0; ! 184: bb.ebx.rx = 0xFFFF; // entire system ! 185: bios32(&bb); ! 186: if ((bb.flags & EFL_CF) == 0) ! 187: return PM_R_SUCCESS; ! 188: return BIOSToPM(bb.eax.r.h); ! 189: } ! 190: ! 191: static inline PMReturn ! 192: APMBIOS_RestoreDefaults(void) ! 193: { ! 194: biosBuf_t bb; ! 195: ! 196: initBIOSBuf(&bb, APM_BIOS_DEFAULT); ! 197: bb.ebx.rx = 0xFFFF; ! 198: bios32(&bb); ! 199: if ((bb.flags & EFL_CF) == 0) ! 200: return PM_R_SUCCESS; ! 201: return BIOSToPM(bb.eax.r.h); ! 202: } ! 203: ! 204: ! 205: #endif /* KERNEL_PRIVATE */ ! 206:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.