Add MTRR support.

This commit is contained in:
fvdl 2002-06-18 08:35:14 +00:00
parent 7a777905af
commit 0b5350133b
3 changed files with 82 additions and 5 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: machdep.c,v 1.10 2002/06/12 19:13:27 fvdl Exp $ */
/* $NetBSD: machdep.c,v 1.11 2002/06/18 08:35:14 fvdl Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998, 2000 The NetBSD Foundation, Inc.
@ -123,6 +123,7 @@
#include <machine/specialreg.h>
#include <machine/bootinfo.h>
#include <machine/fpu.h>
#include <machine/mtrr.h>
#include <dev/isa/isareg.h>
#include <machine/isa_machdep.h>
@ -141,7 +142,7 @@ char machine[] = "x86_64"; /* cpu "architecture" */
char machine_arch[] = "x86_64"; /* machine == machine_arch */
u_int cpu_serial[3];
char cpu_model[] = "VirtuHammer x86-64";
char cpu_model[] = "Hammer x86-64";
char bootinfo[BOOTINFO_MAXSIZE];
@ -189,6 +190,8 @@ int mem_cluster_cnt;
*/
u_int64_t cpu_tsc_freq;
struct mtrr_funcs *mtrr_funcs;
int cpu_dump __P((void));
int cpu_dumpsize __P((void));
u_long cpu_dump_mempagecnt __P((void));
@ -201,6 +204,7 @@ void init_x86_64 __P((vaddr_t));
void
cpu_startup()
{
struct cpu_info *ci = curcpu();
caddr_t v, v2;
unsigned long sz;
int x;
@ -249,6 +253,12 @@ cpu_startup()
cpu_serial[2] / 65536, cpu_serial[2] % 65536);
}
if (cpu_feature & CPUID_MTRR) {
mtrr_funcs = &i686_mtrr_funcs;
i686_mtrr_init_first();
mtrr_init_cpu(ci);
}
format_bytes(pbuf, sizeof(pbuf), ptoa(physmem));
printf("total memory = %s\n", pbuf);

View File

@ -1,4 +1,4 @@
/* $NetBSD: sys_machdep.c,v 1.3 2002/05/28 23:11:39 fvdl Exp $ */
/* $NetBSD: sys_machdep.c,v 1.4 2002/06/18 08:35:14 fvdl Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -68,6 +68,7 @@
#include <machine/psl.h>
#include <machine/reg.h>
#include <machine/sysarch.h>
#include <machine/mtrr.h>
#if defined(PERFCTRS) && 0
#include <machine/pmc.h>
@ -80,6 +81,8 @@ int x86_64_iopl __P((struct proc *, void *, register_t *));
int x86_64_get_ioperm __P((struct proc *, void *, register_t *));
int x86_64_set_ioperm __P((struct proc *, void *, register_t *));
#endif
int x86_64_get_mtrr __P((struct proc *, void *, register_t *));
int x86_64_set_mtrr __P((struct proc *, void *, register_t *));
/* XXXfvdl disabled USER_LDT stuff until I check this stuff */
@ -350,6 +353,60 @@ x86_64_set_ioperm(p, args, retval)
#endif
int
x86_64_get_mtrr(struct proc *p, void *args, register_t *retval)
{
struct x86_64_get_mtrr_args ua;
int error, n;
if (mtrr_funcs == NULL)
return ENOSYS;
error = copyin(args, &ua, sizeof ua);
if (error != 0)
return error;
error = copyin(ua.n, &n, sizeof n);
if (error != 0)
return error;
error = mtrr_get(ua.mtrrp, &n, p, MTRR_GETSET_USER);
copyout(&n, ua.n, sizeof (int));
return error;
}
int
x86_64_set_mtrr(struct proc *p, void *args, register_t *retval)
{
int error, n;
struct x86_64_set_mtrr_args ua;
if (mtrr_funcs == NULL)
return ENOSYS;
error = suser(p->p_ucred, &p->p_acflag);
if (error != 0)
return error;
error = copyin(args, &ua, sizeof ua);
if (error != 0)
return error;
error = copyin(ua.n, &n, sizeof n);
if (error != 0)
return error;
error = mtrr_set(ua.mtrrp, &n, p, MTRR_GETSET_USER);
if (n != 0)
mtrr_commit();
copyout(&n, ua.n, sizeof n);
return error;
}
int
sys_sysarch(p, v, retval)
struct proc *p;
@ -386,6 +443,13 @@ sys_sysarch(p, v, retval)
break;
#endif
case X86_64_GET_MTRR:
error = x86_64_get_mtrr(p, SCARG(uap, parms), retval);
break;
case X86_64_SET_MTRR:
error = x86_64_set_mtrr(p, SCARG(uap, parms), retval);
break;
#if defined(PERFCTRS) && 0
case X86_64_PMC_INFO:
error = pmc_info(p, SCARG(uap, parms), retval);
@ -399,7 +463,6 @@ sys_sysarch(p, v, retval)
error = pmc_read(p, SCARG(uap, parms), retval);
break;
#endif
default:
error = EINVAL;
break;

View File

@ -1,4 +1,4 @@
/* $NetBSD: vm_machdep.c,v 1.7 2002/06/04 12:58:13 fvdl Exp $ */
/* $NetBSD: vm_machdep.c,v 1.8 2002/06/18 08:35:14 fvdl Exp $ */
/*-
* Copyright (c) 1995 Charles M. Hannum. All rights reserved.
@ -66,6 +66,7 @@
#include <machine/reg.h>
#include <machine/specialreg.h>
#include <machine/fpu.h>
#include <machine/mtrr.h>
void setredzone __P((u_short *, caddr_t));
@ -190,6 +191,9 @@ cpu_exit(p)
if (fpuproc == p)
fpuproc = 0;
if (p->p_md.md_flags & MDP_USEDMTRR)
mtrr_clean(p);
/*
* No need to do user LDT cleanup here; it's handled in
* pmap_destroy().