Date: Sat, 21 Sep 2002 00:31:48 -0700 (PDT) From: Peter Wemm <peter@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 17836 for review Message-ID: <200209210731.g8L7VmtX080015@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://people.freebsd.org/~peter/p4db/chv.cgi?CH=17836 Change 17836 by peter@peter_overcee on 2002/09/21 00:31:02 gut the acpi MD code. acpi_wakecode.S is not going to be much use in that form. Remove pnpbios sabotage hooks, since there is no pnpbios to sabotage anymore. Affected files ... .. //depot/projects/hammer/sys/x86_64/acpica/Makefile#2 delete .. //depot/projects/hammer/sys/x86_64/acpica/OsdEnvironment.c#2 edit .. //depot/projects/hammer/sys/x86_64/acpica/acpi_machdep.c#3 edit .. //depot/projects/hammer/sys/x86_64/acpica/acpi_wakecode.S#2 delete .. //depot/projects/hammer/sys/x86_64/acpica/acpi_wakeup.c#2 edit .. //depot/projects/hammer/sys/x86_64/acpica/genwakecode.sh#2 delete Differences ... ==== //depot/projects/hammer/sys/x86_64/acpica/OsdEnvironment.c#2 (text+ko) ==== @@ -33,17 +33,9 @@ #include "acpi.h" -#include <machine/pc/bios.h> - ACPI_STATUS AcpiOsInitialize(void) { - /* - * Prevent the PnP BIOS code from interfering with our own scan of - * ISA devices. - */ - PnPBIOStable = NULL; - return(0); } ==== //depot/projects/hammer/sys/x86_64/acpica/acpi_machdep.c#3 (text+ko) ==== @@ -28,308 +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 - */ - -#include <sys/selinfo.h> - -#include <machine/apm_bios.h> -#include <machine/pc/bios.h> - -#include <i386/apm/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 = { - /* open */ apmopen, - /* close */ apmclose, - /* read */ noread, - /* write */ apmwrite, - /* ioctl */ apmioctl, - /* poll */ apmpoll, - /* mmap */ nommap, - /* strategy */ nostrategy, - /* name */ "apm", - /* maj */ CDEV_MAJOR, - /* dump */ nodump, - /* psize */ nopsize, - /* flags */ 0, -}; - -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, struct thread *td) -{ - return (0); -} - -static int -apmclose(dev_t dev, int flag, int fmt, struct thread *td) -{ - return (0); -} - -static int -apmioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct thread *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, struct thread *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); } - acpi_capm_init(sc); - acpi_install_wakeup_handler(sc); return (0); } - ==== //depot/projects/hammer/sys/x86_64/acpica/acpi_wakeup.c#2 (text+ko) ==== @@ -26,320 +26,20 @@ * * $FreeBSD: src/sys/i386/acpica/acpi_wakeup.c,v 1.13 2002/08/22 21:24:00 archie Exp $ */ - #include <sys/param.h> -#include <sys/systm.h> -#include <sys/kernel.h> #include <sys/bus.h> -#include <sys/lock.h> -#include <sys/mutex.h> -#include <sys/proc.h> -#include <sys/sysctl.h> - -#include <vm/vm.h> -#include <vm/vm_param.h> -#include <vm/pmap.h> -#include <vm/vm_object.h> -#include <vm/vm_page.h> -#include <vm/vm_map.h> -#include <vm/vm_kern.h> -#include <vm/vm_extern.h> - -#include <machine/bus.h> -#include <machine/cpufunc.h> -#include <machine/segments.h> - -#include <i386/isa/intr_machdep.h> #include "acpi.h" - -#include <dev/acpica/acpica_support.h> - #include <dev/acpica/acpivar.h> -#include "acpi_wakecode.h" - -extern void initializecpu(void); - -static struct region_descriptor r_idt, r_gdt, *p_gdt; -static u_int16_t r_ldt; - -static u_int32_t r_eax, r_ebx, r_ecx, r_edx, r_ebp, r_esi, r_edi, - r_efl, r_cr0, r_cr2, r_cr3, r_cr4, ret_addr; - -static u_int16_t r_cs, r_ds, r_es, r_fs, r_gs, r_ss, r_tr; -static u_int32_t r_esp = 0; - -static void acpi_printcpu(void); -static void acpi_realmodeinst(void *arg, bus_dma_segment_t *segs, - int nsegs, int error); -static void acpi_alloc_wakeup_handler(void); - -/* XXX shut gcc up */ -extern int acpi_savecpu(void); -extern int acpi_restorecpu(void); - -__asm__(" \n\ - .text \n\ - .p2align 2, 0x90 \n\ - .type acpi_restorecpu, @function\n\ -acpi_restorecpu: \n\ - .align 4 \n\ - movl r_eax,%eax \n\ - movl r_ebx,%ebx \n\ - movl r_ecx,%ecx \n\ - movl r_edx,%edx \n\ - movl r_ebp,%ebp \n\ - movl r_esi,%esi \n\ - movl r_edi,%edi \n\ - movl r_esp,%esp \n\ - \n\ - pushl r_efl \n\ - popfl \n\ - \n\ - movl ret_addr,%eax \n\ - movl %eax,(%esp) \n\ - xorl %eax,%eax \n\ - ret \n\ - \n\ - .text \n\ - .p2align 2, 0x90 \n\ - .type acpi_savecpu, @function \n\ -acpi_savecpu: \n\ - movw %cs,r_cs \n\ - movw %ds,r_ds \n\ - movw %es,r_es \n\ - movw %fs,r_fs \n\ - movw %gs,r_gs \n\ - movw %ss,r_ss \n\ - \n\ - movl %eax,r_eax \n\ - movl %ebx,r_ebx \n\ - movl %ecx,r_ecx \n\ - movl %edx,r_edx \n\ - movl %ebp,r_ebp \n\ - movl %esi,r_esi \n\ - movl %edi,r_edi \n\ - \n\ - movl %cr0,%eax \n\ - movl %eax,r_cr0 \n\ - movl %cr2,%eax \n\ - movl %eax,r_cr2 \n\ - movl %cr3,%eax \n\ - movl %eax,r_cr3 \n\ - movl %cr4,%eax \n\ - movl %eax,r_cr4 \n\ - \n\ - pushfl \n\ - popl r_efl \n\ - \n\ - movl %esp,r_esp \n\ - \n\ - sgdt r_gdt \n\ - sidt r_idt \n\ - sldt r_ldt \n\ - str r_tr \n\ - \n\ - movl (%esp),%eax \n\ - movl %eax,ret_addr \n\ - movl $1,%eax \n\ - ret \n\ -"); - -static void -acpi_printcpu(void) -{ - - printf("======== acpi_printcpu() debug dump ========\n"); - printf("gdt[%04x:%08x] idt[%04x:%08x] ldt[%04x] tr[%04x] efl[%08x]\n", - r_gdt.rd_limit, r_gdt.rd_base, r_idt.rd_limit, r_idt.rd_base, - r_ldt, r_tr, r_efl); - printf("eax[%08x] ebx[%08x] ecx[%08x] edx[%08x]\n", - r_eax, r_ebx, r_ecx, r_edx); - printf("esi[%08x] edi[%08x] ebp[%08x] esp[%08x]\n", - r_esi, r_edi, r_ebp, r_esp); - printf("cr0[%08x] cr2[%08x] cr3[%08x] cr4[%08x]\n", - r_cr0, r_cr2, r_cr3, r_cr4); - printf("cs[%04x] ds[%04x] es[%04x] fs[%04x] gs[%04x] ss[%04x]\n", - r_cs, r_ds, r_es, r_fs, r_gs, r_ss); -} - -#define WAKECODE_FIXUP(offset, type, val) do { \ - void **addr; \ - addr = (void **)(sc->acpi_wakeaddr + offset); \ - (type *)*addr = val; \ -} while (0) - -#define WAKECODE_BCOPY(offset, type, val) do { \ - void **addr; \ - addr = (void **)(sc->acpi_wakeaddr + offset); \ - bcopy(&(val), addr, sizeof(type)); \ -} while (0) - int acpi_sleep_machdep(struct acpi_softc *sc, int state) { - ACPI_STATUS status; - vm_offset_t oldphys; - struct pmap *pm; - vm_page_t page; - static vm_page_t opage = NULL; - int ret = 0; - int pteobj_allocated = 0; - u_long ef; - - if (sc->acpi_wakeaddr == 0) { - return (0); - } - - AcpiSetFirmwareWakingVector(sc->acpi_wakephys); - - ef = read_eflags(); - disable_intr(); - - /* Create Identity Mapping */ - pm = vmspace_pmap(CURPROC->p_vmspace); - if (pm->pm_pteobj == NULL) { - pm->pm_pteobj = vm_object_allocate(OBJT_DEFAULT, PTDPTDI + 1); - pteobj_allocated = 1; - } - - oldphys = pmap_extract(pm, sc->acpi_wakephys); - if (oldphys) { - opage = PHYS_TO_VM_PAGE(oldphys); - } - page = PHYS_TO_VM_PAGE(sc->acpi_wakephys); - pmap_enter(pm, sc->acpi_wakephys, page, - VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE, 1); - - ret_addr = 0; - if (acpi_savecpu()) { - /* Execute Sleep */ - p_gdt = (struct region_descriptor *)(sc->acpi_wakeaddr + physical_gdt); - p_gdt->rd_limit = r_gdt.rd_limit; - p_gdt->rd_base = vtophys(r_gdt.rd_base); - - WAKECODE_FIXUP(physical_esp, u_int32_t, vtophys(r_esp)); - WAKECODE_FIXUP(previous_cr0, u_int32_t, r_cr0); - WAKECODE_FIXUP(previous_cr2, u_int32_t, r_cr2); - WAKECODE_FIXUP(previous_cr3, u_int32_t, r_cr3); - WAKECODE_FIXUP(previous_cr4, u_int32_t, r_cr4); - - WAKECODE_FIXUP(previous_tr, u_int16_t, r_tr); - WAKECODE_BCOPY(previous_gdt, struct region_descriptor, r_gdt); - WAKECODE_FIXUP(previous_ldt, u_int16_t, r_ldt); - WAKECODE_BCOPY(previous_idt, struct region_descriptor, r_idt); - - WAKECODE_FIXUP(where_to_recover, void, acpi_restorecpu); - - WAKECODE_FIXUP(previous_ds, u_int16_t, r_ds); - WAKECODE_FIXUP(previous_es, u_int16_t, r_es); - WAKECODE_FIXUP(previous_fs, u_int16_t, r_fs); - WAKECODE_FIXUP(previous_gs, u_int16_t, r_gs); - WAKECODE_FIXUP(previous_ss, u_int16_t, r_ss); - - if (acpi_get_verbose(sc)) { - acpi_printcpu(); - } - - wbinvd(); - - if (state == ACPI_STATE_S4 && sc->acpi_s4bios) { - status = AcpiEnterSleepStateS4Bios(); - } else { - status = AcpiEnterSleepState(state); - } - - if (status != AE_OK) { - device_printf(sc->acpi_dev, - "AcpiEnterSleepState failed - %s\n", - AcpiFormatException(status)); - ret = -1; - goto out; - } - - for (;;) ; - } else { - /* Execute Wakeup */ -#if 0 - initializecpu(); -#endif - icu_reinit(); - - if (acpi_get_verbose(sc)) { - acpi_savecpu(); - acpi_printcpu(); - } - } - -out: - pmap_remove(pm, sc->acpi_wakephys, sc->acpi_wakephys + PAGE_SIZE); - if (opage) { - pmap_enter(pm, sc->acpi_wakephys, page, - VM_PROT_READ | VM_PROT_WRITE, 0); - } - - if (pteobj_allocated) { - vm_object_deallocate(pm->pm_pteobj); - pm->pm_pteobj = NULL; - } - - write_eflags(ef); - - return (ret); -} - -static bus_dma_tag_t acpi_waketag; -static bus_dmamap_t acpi_wakemap; -static vm_offset_t acpi_wakeaddr = 0; - -static void -acpi_alloc_wakeup_handler(void) -{ - if (bus_dma_tag_create(/* parent */ NULL, /* alignment */ 2, 0, - /* lowaddr below 1MB */ 0x9ffff, - /* highaddr */ BUS_SPACE_MAXADDR, NULL, NULL, - PAGE_SIZE, 1, PAGE_SIZE, 0, &acpi_waketag) != 0) { - printf("acpi_alloc_wakeup_handler: unable to create wake tag\n"); - return; - } - - if (bus_dmamem_alloc(acpi_waketag, (void **)&acpi_wakeaddr, - BUS_DMA_NOWAIT, &acpi_wakemap)) { - printf("acpi_alloc_wakeup_handler: unable to allocate wake memory\n"); - return; - } + return (0); } -SYSINIT(acpiwakeup, SI_SUB_KMEM, SI_ORDER_ANY, acpi_alloc_wakeup_handler, 0) - -static void -acpi_realmodeinst(void *arg, bus_dma_segment_t *segs, int nsegs, int error) -{ - struct acpi_softc *sc = arg; - u_int32_t *addr; - - addr = (u_int32_t *)&wakecode[wakeup_sw32 + 2]; - *addr = segs[0].ds_addr + wakeup_32; - bcopy(wakecode, (void *)sc->acpi_wakeaddr, sizeof(wakecode)); - sc->acpi_wakephys = segs[0].ds_addr; -} - void acpi_install_wakeup_handler(struct acpi_softc *sc) { - - if (acpi_wakeaddr == 0) { - return; - } - - sc->acpi_waketag = acpi_waketag; - sc->acpi_wakeaddr = acpi_wakeaddr; - sc->acpi_wakemap = acpi_wakemap; - - bus_dmamap_load(sc->acpi_waketag, sc->acpi_wakemap, - (void *)sc->acpi_wakeaddr, PAGE_SIZE, - acpi_realmodeinst, sc, 0); } - To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe p4-projects" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200209210731.g8L7VmtX080015>