Skip to content

Commit

Permalink
IFC
Browse files Browse the repository at this point in the history
  • Loading branch information
netchild committed Apr 14, 2012
2 parents 61b4bb0 + bc585f5 commit e3f875a
Show file tree
Hide file tree
Showing 1,815 changed files with 176,167 additions and 230,307 deletions.
2 changes: 1 addition & 1 deletion src/sys/Makefile
Expand Up @@ -11,7 +11,7 @@ SUBDIR= boot
CSCOPEDIRS= boot bsm cam cddl compat conf contrib crypto ddb dev fs gdb \
geom gnu isa kern libkern modules net net80211 netatalk \
netgraph netinet netinet6 netipsec netipx netnatm netncp \
netsmb nfs nfsclient nfsserver nlm opencrypto \
netsmb nfs nfsclient nfsserver nlm ofed opencrypto \
pci rpc security sys ufs vm xdr xen ${CSCOPE_ARCHDIR}
.if !defined(CSCOPE_ARCHDIR)
.if defined(ALL_ARCH)
Expand Down
27 changes: 13 additions & 14 deletions src/sys/amd64/acpica/acpi_switch.S
Expand Up @@ -120,15 +120,6 @@ ENTRY(acpi_restorecpu)
#undef SDT_SYSTSS
#undef SDT_SYSBSY

/* Restore other callee saved registers. */
movq PCB_R15(%rdi), %r15
movq PCB_R14(%rdi), %r14
movq PCB_R13(%rdi), %r13
movq PCB_R12(%rdi), %r12
movq PCB_RBP(%rdi), %rbp
movq PCB_RSP(%rdi), %rsp
movq PCB_RBX(%rdi), %rbx

/* Restore debug registers. */
movq PCB_DR0(%rdi), %rax
movq %rax, %dr0
Expand All @@ -145,6 +136,7 @@ ENTRY(acpi_restorecpu)

/* Restore FPU state. */
fninit
movq WAKEUP_CTX(fpusave), %rbx
movq WAKEUP_CTX(xsmask), %rax
testq %rax, %rax
jz 1f
Expand All @@ -153,19 +145,26 @@ ENTRY(acpi_restorecpu)
movl $XCR0, %ecx
/* xsetbv */
.byte 0x0f, 0x01, 0xd1
movq WAKEUP_CTX(fpusave), %rcx
/* xrstor (%rcx) */
.byte 0x0f, 0xae, 0x29
/* xrstor (%rbx) */
.byte 0x0f, 0xae, 0x2b
jmp 2f
1:
movq WAKEUP_CTX(fpusave), %rcx
fxrstor (%rcx)
fxrstor (%rbx)
2:

/* Reload CR0. */
movq PCB_CR0(%rdi), %rax
movq %rax, %cr0

/* Restore other callee saved registers. */
movq PCB_R15(%rdi), %r15
movq PCB_R14(%rdi), %r14
movq PCB_R13(%rdi), %r13
movq PCB_R12(%rdi), %r12
movq PCB_RBP(%rdi), %rbp
movq PCB_RSP(%rdi), %rsp
movq PCB_RBX(%rdi), %rbx

/* Restore return address. */
movq PCB_RIP(%rdi), %rax
movq %rax, (%rsp)
Expand Down
24 changes: 17 additions & 7 deletions src/sys/amd64/acpica/acpi_wakecode.S
Expand Up @@ -30,7 +30,9 @@
*/

#include <machine/asmacros.h>
#include <machine/ppireg.h>
#include <machine/specialreg.h>
#include <machine/timerreg.h>

#include "assym.s"

Expand Down Expand Up @@ -71,13 +73,21 @@ wakeup_start:
testb $~0, resume_beep - wakeup_start
jz 1f
movb $0, resume_beep - wakeup_start
movb $0xc0, %al
outb %al, $0x42
movb $0x04, %al
outb %al, $0x42
inb $0x61, %al
orb $0x3, %al
outb %al, $0x61

/* Set PIC timer2 to beep. */
movb $(TIMER_SEL2 | TIMER_SQWAVE | TIMER_16BIT), %al
outb %al, $TIMER_MODE

/* Turn on speaker. */
inb $IO_PPI, %al
orb $PIT_SPKR, %al
outb %al, $IO_PPI

/* Set frequency. */
movw $0x4c0, %ax
outb %al, $TIMER_CNTR2
shrw $8, %ax
outb %al, $TIMER_CNTR2
1:

/* Re-initialize video BIOS if the reset_video tunable is set. */
Expand Down
40 changes: 20 additions & 20 deletions src/sys/amd64/acpica/acpi_wakeup.c
Expand Up @@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$");

#include <sys/param.h>
#include <sys/bus.h>
#include <sys/eventhandler.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/memrange.h>
Expand All @@ -40,6 +41,7 @@ __FBSDID("$FreeBSD$");
#include <vm/vm.h>
#include <vm/pmap.h>

#include <machine/clock.h>
#include <machine/intr_machdep.h>
#include <x86/mca.h>
#include <machine/pcb.h>
Expand Down Expand Up @@ -74,7 +76,7 @@ static struct pcb **susppcbs;
static void **suspfpusave;
#endif

int acpi_restorecpu(vm_offset_t, struct pcb *);
int acpi_restorecpu(uint64_t, vm_offset_t);

static void *acpi_alloc_wakeup_handler(void);
static void acpi_stop_beep(void *);
Expand All @@ -92,11 +94,12 @@ static void acpi_wakeup_cpus(struct acpi_softc *, const cpuset_t *);
*addr = val; \
} while (0)

/* Turn off bits 1&2 of the PIT, stopping the beep. */
static void
acpi_stop_beep(void *arg)
{
outb(0x61, inb(0x61) & ~0x3);

if (acpi_resume_beep != 0)
timer_spkr_release();
}

#ifdef SMP
Expand Down Expand Up @@ -220,7 +223,7 @@ acpi_sleep_machdep(struct acpi_softc *sc, int state)
#ifdef SMP
cpuset_t wakeup_cpus;
#endif
register_t cr3, rf;
register_t rf;
ACPI_STATUS status;
int ret;

Expand All @@ -234,19 +237,14 @@ acpi_sleep_machdep(struct acpi_softc *sc, int state)
CPU_CLR(PCPU_GET(cpuid), &wakeup_cpus);
#endif

if (acpi_resume_beep != 0)
timer_spkr_acquire();

AcpiSetFirmwareWakingVector(WAKECODE_PADDR(sc));

rf = intr_disable();
intr_suspend();

/*
* Temporarily switch to the kernel pmap because it provides
* an identity mapping (setup at boot) for the low physical
* memory region containing the wakeup code.
*/
cr3 = rcr3();
load_cr3(KPML4phys);

if (savectx(susppcbs[0])) {
ctx_fpusave(suspfpusave[0]);
#ifdef SMP
Expand All @@ -272,7 +270,7 @@ acpi_sleep_machdep(struct acpi_softc *sc, int state)
if (state == ACPI_STATE_S4 && sc->acpi_s4bios)
status = AcpiEnterSleepStateS4bios();
else
status = AcpiEnterSleepState(state);
status = AcpiEnterSleepState(state, acpi_sleep_flags);

if (status != AE_OK) {
device_printf(sc->acpi_dev,
Expand All @@ -285,13 +283,14 @@ acpi_sleep_machdep(struct acpi_softc *sc, int state)
ia32_pause();
} else {
pmap_init_pat();
load_cr3(susppcbs[0]->pcb_cr3);
initializecpu();
PCPU_SET(switchtime, 0);
PCPU_SET(switchticks, ticks);
#ifdef SMP
if (!CPU_EMPTY(&wakeup_cpus))
acpi_wakeup_cpus(sc, &wakeup_cpus);
#endif
acpi_resync_clock(sc);
ret = 0;
}

Expand All @@ -301,7 +300,6 @@ acpi_sleep_machdep(struct acpi_softc *sc, int state)
restart_cpus(wakeup_cpus);
#endif

load_cr3(cr3);
mca_resume();
intr_resume();
intr_restore(rf);
Expand All @@ -312,10 +310,6 @@ acpi_sleep_machdep(struct acpi_softc *sc, int state)
mem_range_softc.mr_op->reinit != NULL)
mem_range_softc.mr_op->reinit(&mem_range_softc);

/* If we beeped, turn it off after a delay. */
if (acpi_resume_beep)
timeout(acpi_stop_beep, NULL, 3 * hz);

return (ret);
}

Expand All @@ -332,12 +326,18 @@ acpi_alloc_wakeup_handler(void)
* and ROM area (0xa0000 and above). The temporary page tables must be
* page-aligned.
*/
wakeaddr = contigmalloc(4 * PAGE_SIZE, M_DEVBUF, M_NOWAIT, 0x500,
wakeaddr = contigmalloc(4 * PAGE_SIZE, M_DEVBUF, M_WAITOK, 0x500,
0xa0000, PAGE_SIZE, 0ul);
if (wakeaddr == NULL) {
printf("%s: can't alloc wake memory\n", __func__);
return (NULL);
}
if (EVENTHANDLER_REGISTER(power_resume, acpi_stop_beep, NULL,
EVENTHANDLER_PRI_LAST) == NULL) {
printf("%s: can't register event handler\n", __func__);
contigfree(wakeaddr, 4 * PAGE_SIZE, M_DEVBUF);
return (NULL);
}
susppcbs = malloc(mp_ncpus * sizeof(*susppcbs), M_DEVBUF, M_WAITOK);
suspfpusave = malloc(mp_ncpus * sizeof(void *), M_DEVBUF, M_WAITOK);
for (i = 0; i < mp_ncpus; i++) {
Expand Down
7 changes: 2 additions & 5 deletions src/sys/amd64/amd64/apic_vector.S
Expand Up @@ -300,13 +300,10 @@ IDTVEC(cpustop)
IDTVEC(cpususpend)
PUSH_FRAME

call cpususpend_handler
movq lapic, %rax
movl $0, LA_EOI(%rax) /* End Of Interrupt to APIC */

call cpususpend_handler

POP_FRAME
jmp doreti_iret
jmp doreti

/*
* Executed by a CPU when it receives a RENDEZVOUS IPI from another CPU.
Expand Down
2 changes: 1 addition & 1 deletion src/sys/amd64/amd64/cpu_switch.S
Expand Up @@ -76,7 +76,7 @@ ENTRY(cpu_throw)
movq PCPU(CURPMAP),%rdx
LK btrl %eax,PM_ACTIVE(%rdx) /* clear old */
1:
movq TD_PCB(%rsi),%r8 /* newtd->td_proc */
movq TD_PCB(%rsi),%r8 /* newtd->td_pcb */
movq PCB_CR3(%r8),%rdx
movq %rdx,%cr3 /* new address space */
jmp swact
Expand Down
2 changes: 1 addition & 1 deletion src/sys/amd64/amd64/identcpu.c
Expand Up @@ -303,7 +303,7 @@ printcpuinfo(void)
"\034OSXSAVE" /* OS-Enabled State Management*/
"\035AVX" /* Advanced Vector Extensions */
"\036F16C" /* Half-precision conversions */
"\037<b30>"
"\037RDRAND" /* RDRAND Instruction */
"\040HV" /* Hypervisor */
);
}
Expand Down
29 changes: 28 additions & 1 deletion src/sys/amd64/amd64/initcpu.c
Expand Up @@ -79,6 +79,27 @@ SYSCTL_UINT(_hw, OID_AUTO, via_feature_rng, CTLFLAG_RD,
SYSCTL_UINT(_hw, OID_AUTO, via_feature_xcrypt, CTLFLAG_RD,
&via_feature_xcrypt, 0, "VIA xcrypt feature available in CPU");

static void
init_amd(void)
{

/*
* Work around Erratum 721 for Family 10h and 12h processors.
* These processors may incorrectly update the stack pointer
* after a long series of push and/or near-call instructions,
* or a long series of pop and/or near-return instructions.
*
* http://support.amd.com/us/Processor_TechDocs/41322_10h_Rev_Gd.pdf
* http://support.amd.com/us/Processor_TechDocs/44739_12h_Rev_Gd.pdf
*/
switch (CPUID_TO_FAMILY(cpu_id)) {
case 0x10:
case 0x12:
wrmsr(0xc0011029, rdmsr(0xc0011029) | 1);
break;
}
}

/*
* Initialize special VIA features
*/
Expand Down Expand Up @@ -135,8 +156,14 @@ initializecpu(void)
wrmsr(MSR_EFER, msr);
pg_nx = PG_NX;
}
if (cpu_vendor_id == CPU_VENDOR_CENTAUR)
switch (cpu_vendor_id) {
case CPU_VENDOR_AMD:
init_amd();
break;
case CPU_VENDOR_CENTAUR:
init_via();
break;
}
}

void
Expand Down

0 comments on commit e3f875a

Please sign in to comment.