^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* -*- linux-c -*- ------------------------------------------------------- *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 1991, 1992 Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2007 rPath, Inc. - All Rights Reserved
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright 2009 Intel Corporation; author H. Peter Anvin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Original APM BIOS checking by Stephen Rothwell, May 1994
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * (sfr@canb.auug.org.au)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * ----------------------------------------------------------------------- */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Get APM BIOS information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "boot.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) int query_apm_bios(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) struct biosregs ireg, oreg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) /* APM BIOS installation check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) initregs(&ireg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) ireg.ah = 0x53;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) intcall(0x15, &ireg, &oreg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) if (oreg.flags & X86_EFLAGS_CF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) return -1; /* No APM BIOS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) if (oreg.bx != 0x504d) /* "PM" signature */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) if (!(oreg.cx & 0x02)) /* 32 bits supported? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /* Disconnect first, just in case */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) ireg.al = 0x04;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) intcall(0x15, &ireg, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) /* 32-bit connect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) ireg.al = 0x03;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) intcall(0x15, &ireg, &oreg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) boot_params.apm_bios_info.cseg = oreg.ax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) boot_params.apm_bios_info.offset = oreg.ebx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) boot_params.apm_bios_info.cseg_16 = oreg.cx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) boot_params.apm_bios_info.dseg = oreg.dx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) boot_params.apm_bios_info.cseg_len = oreg.si;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) boot_params.apm_bios_info.cseg_16_len = oreg.hsi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) boot_params.apm_bios_info.dseg_len = oreg.di;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) if (oreg.flags & X86_EFLAGS_CF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /* Redo the installation check as the 32-bit connect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) some BIOSes return different flags this way... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) ireg.al = 0x00;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) intcall(0x15, &ireg, &oreg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) if ((oreg.eflags & X86_EFLAGS_CF) || oreg.bx != 0x504d) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /* Failure with 32-bit connect, try to disconnect and ignore */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) ireg.al = 0x04;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) intcall(0x15, &ireg, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) boot_params.apm_bios_info.version = oreg.ax;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) boot_params.apm_bios_info.flags = oreg.cx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)