Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/x86_64/x86_64 Add MTRR support.



details:   https://anonhg.NetBSD.org/src/rev/1acb498dc2c1
branches:  trunk
changeset: 532961:1acb498dc2c1
user:      fvdl <fvdl%NetBSD.org@localhost>
date:      Tue Jun 18 08:35:14 2002 +0000

description:
Add MTRR support.

diffstat:

 sys/arch/x86_64/x86_64/machdep.c     |  14 ++++++-
 sys/arch/x86_64/x86_64/sys_machdep.c |  67 ++++++++++++++++++++++++++++++++++-
 sys/arch/x86_64/x86_64/vm_machdep.c  |   6 ++-
 3 files changed, 82 insertions(+), 5 deletions(-)

diffs (192 lines):

diff -r 40fd09c374e3 -r 1acb498dc2c1 sys/arch/x86_64/x86_64/machdep.c
--- a/sys/arch/x86_64/x86_64/machdep.c  Tue Jun 18 08:34:57 2002 +0000
+++ b/sys/arch/x86_64/x86_64/machdep.c  Tue Jun 18 08:35:14 2002 +0000
@@ -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_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 @@
  */
 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
 cpu_startup()
 {
+       struct cpu_info *ci = curcpu();
        caddr_t v, v2;
        unsigned long sz;
        int x;
@@ -249,6 +253,12 @@
                        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);
 
diff -r 40fd09c374e3 -r 1acb498dc2c1 sys/arch/x86_64/x86_64/sys_machdep.c
--- a/sys/arch/x86_64/x86_64/sys_machdep.c      Tue Jun 18 08:34:57 2002 +0000
+++ b/sys/arch/x86_64/x86_64/sys_machdep.c      Tue Jun 18 08:35:14 2002 +0000
@@ -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_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 */
 
@@ -351,6 +354,60 @@
 #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;
        void *v;
@@ -386,6 +443,13 @@
                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 @@
                error = pmc_read(p, SCARG(uap, parms), retval);
                break;
 #endif
-
        default:
                error = EINVAL;
                break;
diff -r 40fd09c374e3 -r 1acb498dc2c1 sys/arch/x86_64/x86_64/vm_machdep.c
--- a/sys/arch/x86_64/x86_64/vm_machdep.c       Tue Jun 18 08:34:57 2002 +0000
+++ b/sys/arch/x86_64/x86_64/vm_machdep.c       Tue Jun 18 08:35:14 2002 +0000
@@ -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 @@
        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().



Home | Main Index | Thread Index | Old Index