All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Machek <pavel@suse.cz>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>,
	Mikael Pettersson <mikpe@csd.uu.se>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] restore sysenter MSRs at resume
Date: Mon, 12 May 2003 22:15:49 +0200	[thread overview]
Message-ID: <20030512201549.GA4848@elf.ucw.cz> (raw)
In-Reply-To: <Pine.LNX.4.44.0305111706370.22268-100000@home.transmeta.com>

Hi!

> > Some laptops also lose all the AGP settings in the chipset.
> 
> Well, that's definitely a driver issue, and should be handled that way. I
> suspect even the MTRR's should be handled as a driver, since unlike things
> like the SYSENTER things, it really _is_ a driver already and is
> conditional on kernel configuration etc.

Here's a patch, it simply adds mtrrs into as "sys" device...

Please apply,
								Pavel

Index: linux/arch/i386/kernel/cpu/mtrr/main.c
===================================================================
--- linux.orig/arch/i386/kernel/cpu/mtrr/main.c	2003-01-05 22:58:19.000000000 +0100
+++ linux/arch/i386/kernel/cpu/mtrr/main.c	2003-05-12 22:06:05.000000000 +0200
@@ -2,6 +2,7 @@
 
     Copyright (C) 1997-2000  Richard Gooch
     Copyright (c) 2002	     Patrick Mochel
+    Copyright (c) 2003	     Nigel Cunningham & Pavel Machek 
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Library General Public
@@ -35,6 +36,7 @@
 #include <linux/init.h>
 #include <linux/pci.h>
 #include <linux/smp.h>
+#include <linux/suspend.h>
 
 #include <asm/mtrr.h>
 
@@ -644,6 +646,104 @@
     "write-protect",            /* 5 */
     "write-back",               /* 6 */
 };
+ 
+#ifdef CONFIG_PM
+struct mtrr_suspend_state
+{
+     mtrr_type ltype;
+     unsigned long lbase;
+     unsigned int lsize;
+};
+
+/* We return a pointer ptr on an area of *ptr bytes
+   beginning at ptr+sizeof(int)
+   This buffer has to be saved in some way during suspension */
+static int *mtrr_save_state(void)
+{
+     int i, len;
+     int *ptr = NULL;
+     static struct mtrr_suspend_state *mtrr_suspend_buffer=NULL;
+     
+     if(!mtrr_suspend_buffer)
+     {
+	  len = num_var_ranges * sizeof (struct mtrr_suspend_state) + sizeof(int);
+	  ptr = kmalloc (len, GFP_KERNEL);
+	  if (ptr == NULL)
+	       return(NULL);
+	  *ptr = len;
+	  ptr++;
+	  mtrr_suspend_buffer = (struct mtrr_suspend_state *)ptr;
+	  ptr--;
+     }
+     for (i = 0; i < num_var_ranges; ++i,mtrr_suspend_buffer++)
+	  mtrr_if->get (i,
+		       &(mtrr_suspend_buffer->lbase),
+		       &(mtrr_suspend_buffer->lsize),
+		       &(mtrr_suspend_buffer->ltype));
+     return(ptr);
+}
+
+/* We restore mtrrs from buffer ptr */
+static void mtrr_restore_state(int *ptr)
+{
+     int i, len;
+     struct mtrr_suspend_state *mtrr_suspend_buffer;
+     
+     len = num_var_ranges * sizeof (struct mtrr_suspend_state) + sizeof(int);
+     if(*ptr != len)
+     {
+	  printk ("mtrr: Resuming failed due to different number of MTRRs\n");
+	  return;
+     }
+     ptr++;
+     mtrr_suspend_buffer=(struct mtrr_suspend_state *)ptr;
+     for (i = 0; i < num_var_ranges; ++i,mtrr_suspend_buffer++)     
+	  if (mtrr_suspend_buffer->lsize)	  
+	       set_mtrr(i,
+			mtrr_suspend_buffer->lbase,
+			mtrr_suspend_buffer->lsize,
+			mtrr_suspend_buffer->ltype);
+}
+
+static void *mtrr_state;
+
+static int mtrr_suspend(struct device *dev, u32 state, u32 level)
+{
+	if (level == SUSPEND_SAVE_STATE)
+		mtrr_state = mtrr_save_state();
+	return 0;
+}
+
+static int mtrr_resume(struct device *dev, u32 level)
+{
+	if (level == RESUME_POWER_ON)
+		mtrr_restore_state(mtrr_state);
+	return 0;
+}
+
+static struct device_driver mtrr_driver = {
+	.name		= "mtrr",
+	.bus		= &system_bus_type,
+	.suspend	= mtrr_suspend,
+	.resume		= mtrr_resume,
+};
+
+static struct sys_device device_mtrr = {
+	.name		= "mtrr",
+	.id		= 0,
+	.dev		= {
+		.name	= "mtrr",
+		.driver	= &mtrr_driver,
+	},
+};
 
+static int __init init_mtrr_devicefs(void)
+{
+	driver_register(&mtrr_driver);
+	return sys_device_register(&device_mtrr);
+}
+
+device_initcall(init_mtrr_devicefs);
+#endif
 core_initcall(mtrr_init);
 
								Pavel
-- 
When do you have a heart between your knees?
[Johanka's followup: and *two* hearts?]

  parent reply	other threads:[~2003-05-12 20:05 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-10 16:41 [PATCH] restore sysenter MSRs at resume mikpe
2003-05-11 19:01 ` Linus Torvalds
2003-05-11 19:08   ` Pavel Machek
2003-05-11 19:28     ` Nigel Cunningham
2003-05-12 11:30       ` Pavel Machek
2003-05-12 19:33         ` Nigel Cunningham
2003-05-12 19:54           ` Pavel Machek
2003-05-11 21:04   ` Alan Cox
2003-05-12  0:07     ` Linus Torvalds
2003-05-12 11:13       ` Alan Cox
2003-05-12 20:15       ` Pavel Machek [this message]
  -- strict thread matches above, loose matches on Subject: below --
2003-05-06 19:52 [BUG] 2.5.69 oops at sysenter_past_esp mikpe
2003-05-06 22:35 ` Dave Jones
2003-05-07  9:33   ` [PATCH] restore sysenter MSRs at resume mikpe
2003-05-07 14:41     ` Linus Torvalds
2003-05-07 17:23       ` mikpe
2003-05-07 17:39         ` Linus Torvalds
2003-05-08 21:47           ` Pavel Machek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030512201549.GA4848@elf.ucw.cz \
    --to=pavel@suse.cz \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mikpe@csd.uu.se \
    --cc=torvalds@transmeta.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.