summaryrefslogtreecommitdiffstats
path: root/sys/amd64/acpica/acpi_machdep.c
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>2003-05-01 01:05:25 +0000
committerpeter <peter@FreeBSD.org>2003-05-01 01:05:25 +0000
commit45949ccde13fb04ed597a5aef80b678ba16bcab7 (patch)
treedd665cefeba0e426ad2b212b76851de96f1ad18b /sys/amd64/acpica/acpi_machdep.c
parent1fd7bc609e9a5249f7b7b558405e1c39aca79796 (diff)
downloadFreeBSD-src-45949ccde13fb04ed597a5aef80b678ba16bcab7.zip
FreeBSD-src-45949ccde13fb04ed597a5aef80b678ba16bcab7.tar.gz
Commit MD parts of a loosely functional AMD64 port. This is based on
a heavily stripped down FreeBSD/i386 (brutally stripped down actually) to attempt to get a stable base to start from. There is a lot missing still. Worth noting: - The kernel runs at 1GB in order to cheat with the pmap code. pmap uses a variation of the PAE code in order to avoid having to worry about 4 levels of page tables yet. - It boots in 64 bit "long mode" with a tiny trampoline embedded in the i386 loader. This simplifies locore.s greatly. - There are still quite a few fragments of i386-specific code that have not been translated yet, and some that I cheated and wrote dumb C versions of (bcopy etc). - It has both int 0x80 for syscalls (but using registers for argument passing, as is native on the amd64 ABI), and the 'syscall' instruction for syscalls. int 0x80 preserves all registers, 'syscall' does not. - I have tried to minimize looking at the NetBSD code, except in a couple of places (eg: to find which register they use to replace the trashed %rcx register in the syscall instruction). As a result, there is not a lot of similarity. I did look at NetBSD a few times while debugging to get some ideas about what I might have done wrong in my first attempt.
Diffstat (limited to 'sys/amd64/acpica/acpi_machdep.c')
-rw-r--r--sys/amd64/acpica/acpi_machdep.c297
1 files changed, 1 insertions, 296 deletions
diff --git a/sys/amd64/acpica/acpi_machdep.c b/sys/amd64/acpica/acpi_machdep.c
index 6d48588..66c71f4 100644
--- a/sys/amd64/acpica/acpi_machdep.c
+++ b/sys/amd64/acpica/acpi_machdep.c
@@ -28,315 +28,20 @@
#include <sys/param.h>
#include <sys/bus.h>
-#include <sys/conf.h>
-#include <sys/fcntl.h>
-#include <sys/uio.h>
#include "acpi.h"
-
#include <dev/acpica/acpivar.h>
-#include <dev/acpica/acpiio.h>
-
-static device_t acpi_dev;
-
-/*
- * APM driver emulation
- */
-
-#if __FreeBSD_version < 500000
-#include <sys/select.h>
-#else
-#include <sys/selinfo.h>
-#endif
-
-#include <machine/apm_bios.h>
-#include <machine/pc/bios.h>
-
-#include <i386/bios/apm.h>
-
-static struct apm_softc apm_softc;
-
-static d_open_t apmopen;
-static d_close_t apmclose;
-static d_write_t apmwrite;
-static d_ioctl_t apmioctl;
-static d_poll_t apmpoll;
-
-#define CDEV_MAJOR 39
-static struct cdevsw apm_cdevsw = {
- .d_open = apmopen,
- .d_close = apmclose,
- .d_write = apmwrite,
- .d_ioctl = apmioctl,
- .d_poll = apmpoll,
- .d_name = "apm",
- .d_maj = CDEV_MAJOR,
-};
-
-static int
-acpi_capm_convert_battstate(struct acpi_battinfo *battp)
-{
- int state;
-
- state = 0xff; /* XXX unknown */
-
- if (battp->state & ACPI_BATT_STAT_DISCHARG) {
- if (battp->cap >= 50) {
- state = 0; /* high */
- } else {
- state = 1; /* low */
- }
- }
- if (battp->state & ACPI_BATT_STAT_CRITICAL) {
- state = 2; /* critical */
- }
- if (battp->state & ACPI_BATT_STAT_CHARGING) {
- state = 3; /* charging */
- }
- return (state);
-}
-
-static int
-acpi_capm_convert_battflags(struct acpi_battinfo *battp)
-{
- int flags;
-
- flags = 0;
-
- if (battp->cap >= 50) {
- flags |= APM_BATT_HIGH;
- } else {
- if (battp->state & ACPI_BATT_STAT_CRITICAL) {
- flags |= APM_BATT_CRITICAL;
- } else {
- flags |= APM_BATT_LOW;
- }
- }
- if (battp->state & ACPI_BATT_STAT_CHARGING) {
- flags |= APM_BATT_CHARGING;
- }
- if (battp->state == ACPI_BATT_STAT_NOT_PRESENT) {
- flags = APM_BATT_NOT_PRESENT;
- }
-
- return (flags);
-}
-
-static int
-acpi_capm_get_info(apm_info_t aip)
-{
- int acline;
- struct acpi_battinfo batt;
-
- aip->ai_infoversion = 1;
- aip->ai_major = 1;
- aip->ai_minor = 2;
- aip->ai_status = apm_softc.active;
- aip->ai_capabilities= 0xff00; /* XXX unknown */
-
- if (acpi_acad_get_acline(&acline)) {
- aip->ai_acline = 0xff; /* unknown */
- } else {
- aip->ai_acline = acline; /* on/off */
- }
-
- if (acpi_battery_get_battinfo(-1, &batt)) {
- aip->ai_batt_stat = 0xff; /* unknown */
- aip->ai_batt_life = 0xff; /* unknown */
- aip->ai_batt_time = -1; /* unknown */
- aip->ai_batteries = 0;
- } else {
- aip->ai_batt_stat = acpi_capm_convert_battstate(&batt);
- aip->ai_batt_life = batt.cap;
- aip->ai_batt_time = (batt.min == -1) ? -1 : batt.min * 60;
- aip->ai_batteries = acpi_battery_get_units();
- }
-
- return (0);
-}
-
-static int
-acpi_capm_get_pwstatus(apm_pwstatus_t app)
-{
- int batt_unit;
- int acline;
- struct acpi_battinfo batt;
-
- if (app->ap_device != PMDV_ALLDEV &&
- (app->ap_device < PMDV_BATT0 || app->ap_device > PMDV_BATT_ALL)) {
- return (1);
- }
-
- if (app->ap_device == PMDV_ALLDEV) {
- batt_unit = -1; /* all units */
- } else {
- batt_unit = app->ap_device - PMDV_BATT0;
- }
-
- if (acpi_battery_get_battinfo(batt_unit, &batt)) {
- return (1);
- }
-
- app->ap_batt_stat = acpi_capm_convert_battstate(&batt);
- app->ap_batt_flag = acpi_capm_convert_battflags(&batt);
- app->ap_batt_life = batt.cap;
- app->ap_batt_time = (batt.min == -1) ? -1 : batt.min * 60;
-
- if (acpi_acad_get_acline(&acline)) {
- app->ap_acline = 0xff; /* unknown */
- } else {
- app->ap_acline = acline; /* on/off */
- }
-
- return (0);
-}
-
-static int
-apmopen(dev_t dev, int flag, int fmt, d_thread_t *td)
-{
- return (0);
-}
-
-static int
-apmclose(dev_t dev, int flag, int fmt, d_thread_t *td)
-{
- return (0);
-}
-
-static int
-apmioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, d_thread_t *td)
-{
- int error = 0;
- struct acpi_softc *acpi_sc;
- struct apm_info info;
- apm_info_old_t aiop;
-
- if ((acpi_sc = device_get_softc(acpi_dev)) == NULL) {
- return (ENXIO);
- }
-
- switch (cmd) {
- case APMIO_SUSPEND:
- if (!(flag & FWRITE))
- return (EPERM);
- if (apm_softc.active)
- acpi_SetSleepState(acpi_sc, acpi_sc->acpi_suspend_sx);
- else
- error = EINVAL;
- break;
-
- case APMIO_STANDBY:
- if (!(flag & FWRITE))
- return (EPERM);
- if (apm_softc.active)
- acpi_SetSleepState(acpi_sc, acpi_sc->acpi_standby_sx);
- else
- error = EINVAL;
- break;
-
- case APMIO_GETINFO_OLD:
- if (acpi_capm_get_info(&info))
- error = ENXIO;
- aiop = (apm_info_old_t)addr;
- aiop->ai_major = info.ai_major;
- aiop->ai_minor = info.ai_minor;
- aiop->ai_acline = info.ai_acline;
- aiop->ai_batt_stat = info.ai_batt_stat;
- aiop->ai_batt_life = info.ai_batt_life;
- aiop->ai_status = info.ai_status;
- break;
-
- case APMIO_GETINFO:
- if (acpi_capm_get_info((apm_info_t)addr))
- error = ENXIO;
-
- break;
-
- case APMIO_GETPWSTATUS:
- if (acpi_capm_get_pwstatus((apm_pwstatus_t)addr))
- error = ENXIO;
- break;
-
- case APMIO_ENABLE:
- if (!(flag & FWRITE))
- return (EPERM);
- apm_softc.active = 1;
- break;
-
- case APMIO_DISABLE:
- if (!(flag & FWRITE))
- return (EPERM);
- apm_softc.active = 0;
- break;
-
- case APMIO_HALTCPU:
- break;
-
- case APMIO_NOTHALTCPU:
- break;
-
- case APMIO_DISPLAY:
- if (!(flag & FWRITE))
- return (EPERM);
- break;
-
- case APMIO_BIOS:
- if (!(flag & FWRITE))
- return (EPERM);
- bzero(addr, sizeof(struct apm_bios_arg));
- break;
-
- default:
- error = EINVAL;
- break;
- }
-
- return (error);
-}
-
-static int
-apmwrite(dev_t dev, struct uio *uio, int ioflag)
-{
-
- return (uio->uio_resid);
-}
-
-static int
-apmpoll(dev_t dev, int events, d_thread_t *td)
-{
- return (0);
-}
-
-static void
-acpi_capm_init(struct acpi_softc *sc)
-{
-
- make_dev(&apm_cdevsw, 0, 0, 5, 0664, "apm");
-}
int
acpi_machdep_init(device_t dev)
{
struct acpi_softc *sc;
- acpi_dev = dev;
- if ((sc = device_get_softc(acpi_dev)) == NULL) {
+ if ((sc = device_get_softc(dev)) == NULL) {
return (ENXIO);
}
- /*
- * XXX: Prevent the PnP BIOS code from interfering with
- * our own scan of ISA devices.
- */
- PnPBIOStable = NULL;
-
- acpi_capm_init(sc);
-
acpi_install_wakeup_handler(sc);
-#ifdef SMP
- acpi_SetIntrModel(ACPI_INTR_APIC);
-#endif
return (0);
}
-
OpenPOWER on IntegriCloud