Skip to contentSkip to conversation

: Hardware State Notification

PATCH In review Antonino A. Daplas 2 participants 9 messages Jun 21, 2004 – Jun 29, 2004

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 3/3 : Hardware State Notification

Hi,

**This patch is more of an RFC. BenH probably has similar code.

This patch adds a method (con_notify) that will notify console drivers of impending console switches, passing them with the about-to-be-old (last) vc structure and about-to-be-new (wanted) vc structure. The console drivers can then elect to pass selected information to low-level drivers.

This is important to fbcon so it can detect a switch from a graphics console to a text console and vice versa. This will give underlying drivers a chance to update its hardware state. This is added via the method fbcon_state_switch(). Fbcon will, however, do a set_par if the _state_switch method is not availabe and if switching from a KD_GRAPHICS console.

Also updated rivafb to take advantage of this method. With this, switching to/from X with XFree86/Org nv driver works. Usually it hangs without the option usefbdev, or gets a Sig11 if with option usefbdev.

(Unfortunately it doesn't work for nVidia's binary nvidia driver, switching to the console is possible, switching back to X will hang the machine).

Diff is against linux-2.6.7-mm1

Tony

drivers/char/vt.c +3 -0
diff -Naur linux-2.6.7-mm1-orig/drivers/char/vt.c linux-2.6.7-mm1/drivers/char/vt.c
@@ -617,6 +617,9 @@
 		hide_cursor(currcons);
 		if (fg_console != new_console) {
 			struct vc_data **display = vc_cons[new_console].d->vc_display_fg;
+			if (sw->con_notify)
+				sw->con_notify(vc_cons[fg_console].d,
+					       vc_cons[new_console].d);
 			old_console = (*display) ? (*display)->vc_num : fg_console;
 			*display = vc_cons[new_console].d;
 			fg_console = new_console;
drivers/video/console/fbcon.c +26 -0
diff -Naur linux-2.6.7-mm1-orig/drivers/video/console/fbcon.c linux-2.6.7-mm1/drivers/video/console/fbcon.c
@@ -2428,6 +2428,31 @@
 	return 0;
 }
 
+static void fbcon_notify(struct vc_data *old_vc, struct vc_data *new_vc)
+{
+	struct fb_info *old_info = registered_fb[(int) con2fb_map[old_vc->vc_num]];
+	struct fb_info *new_info = registered_fb[(int) con2fb_map[new_vc->vc_num]];
+	int old_vcmode = vt_cons[old_vc->vc_num]->vc_mode;
+	int new_vcmode = vt_cons[new_vc->vc_num]->vc_mode;
+
+	if (old_info != new_info || vt_cons[old_vc->vc_num]->vc_mode != 
+	    vt_cons[new_vc->vc_num]->vc_mode) {
+	    if (old_info && old_info->fbops->fb_state_switch)
+		old_info->fbops->fb_state_switch(old_info, 1, 
+						 (old_vcmode == KD_GRAPHICS) ? 1 : 0);
+	    /*
+	     * If old console is in graphics, we call a set_par by default 
+	     */
+	    else if (old_vcmode == KD_GRAPHICS && old_info &&
+		     old_info->fbops->fb_set_par)
+		old_info->fbops->fb_set_par(old_info);
+
+	    if (new_info && new_info->fbops->fb_state_switch)
+		new_info->fbops->fb_state_switch(new_info, 0,
+						 (new_vcmode == KD_GRAPHICS) ? 1 : 0);
+	}
+}
+
 /*
  *  The console `switch' structure for the frame buffer based console
  */
@@ -2453,6 +2478,7 @@
 	.con_screen_pos 	= fbcon_screen_pos,
 	.con_getxy 		= fbcon_getxy,
 	.con_resize             = fbcon_resize,
+	.con_notify             = fbcon_notify,
 };
 
 static struct notifier_block fbcon_event_notifier = {
drivers/video/riva/fbdev.c +56 -14

146 lines not on this page · raw message

drivers/video/riva/rivafb.h +3 -0
diff -Naur linux-2.6.7-mm1-orig/drivers/video/riva/rivafb.h linux-2.6.7-mm1/drivers/video/riva/rivafb.h
@@ -50,6 +50,7 @@
 
 	struct riva_regs initial_state;	/* initial startup video mode */
 	struct riva_regs current_state;
+	struct riva_regs save_state;
 	struct vgastate state;
 	atomic_t ref_count;
 	u32 cursor_data[32 * 32/4];
@@ -60,6 +61,8 @@
 	Bool SecondCRTC;
 	int FlatPanel;
 	struct pci_dev *pdev;
+	int bus;
+	int reset;
 #ifdef CONFIG_MTRR
 	struct { int vram; int vram_valid; } mtrr;
 #endif
include/linux/console.h +1 -0
diff -Naur linux-2.6.7-mm1-orig/include/linux/console.h linux-2.6.7-mm1/include/linux/console.h
@@ -50,6 +50,7 @@
 	void	(*con_invert_region)(struct vc_data *, u16 *, int);
 	u16    *(*con_screen_pos)(struct vc_data *, int);
 	unsigned long (*con_getxy)(struct vc_data *, unsigned long, int *, int *);
+	void    (*con_notify)(struct vc_data *, struct vc_data *);
 };
 
 extern const struct consw *conswitchp;

-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com

#1 lore raw
Quoted 8 lines · Antonino A. Daplas

Hi,

**This patch is more of an RFC. BenH probably has similar code.

This patch adds a method (con_notify) that will notify console drivers of impending console switches, passing them with the about-to-be-old (last) vc structure and about-to-be-new (wanted) vc structure. The console drivers can then elect to pass selected information to low-level drivers.

Oops, try this one.

Tony

drivers/char/vt.c +3 -0
diff -Naur linux-2.6.7-mm1-orig/drivers/char/vt.c linux-2.6.7-mm1/drivers/char/vt.c
@@ -617,6 +617,9 @@
 		hide_cursor(currcons);
 		if (fg_console != new_console) {
 			struct vc_data **display = vc_cons[new_console].d->vc_display_fg;
+			if (sw->con_notify)
+				sw->con_notify(vc_cons[fg_console].d,
+					       vc_cons[new_console].d);
 			old_console = (*display) ? (*display)->vc_num : fg_console;
 			*display = vc_cons[new_console].d;
 			fg_console = new_console;
drivers/video/console/fbcon.c +26 -0
diff -Naur linux-2.6.7-mm1-orig/drivers/video/console/fbcon.c linux-2.6.7-mm1/drivers/video/console/fbcon.c
@@ -2428,6 +2428,31 @@
 	return 0;
 }
 
+static void fbcon_notify(struct vc_data *old_vc, struct vc_data *new_vc)
+{
+	struct fb_info *old_info = registered_fb[(int) con2fb_map[old_vc->vc_num]];
+	struct fb_info *new_info = registered_fb[(int) con2fb_map[new_vc->vc_num]];
+	int old_vcmode = vt_cons[old_vc->vc_num]->vc_mode;
+	int new_vcmode = vt_cons[new_vc->vc_num]->vc_mode;
+
+	if (old_info != new_info || vt_cons[old_vc->vc_num]->vc_mode != 
+	    vt_cons[new_vc->vc_num]->vc_mode) {
+	    if (old_info && old_info->fbops->fb_state_switch)
+		old_info->fbops->fb_state_switch(old_info, 1, 
+						 (old_vcmode == KD_GRAPHICS) ? 1 : 0);
+	    /*
+	     * If old console is in graphics, we call a set_par by default 
+	     */
+	    else if (old_vcmode == KD_GRAPHICS && old_info &&
+		     old_info->fbops->fb_set_par)
+		old_info->fbops->fb_set_par(old_info);
+
+	    if (new_info && new_info->fbops->fb_state_switch)
+		new_info->fbops->fb_state_switch(new_info, 0,
+						 (new_vcmode == KD_GRAPHICS) ? 1 : 0);
+	}
+}
+
 /*
  *  The console `switch' structure for the frame buffer based console
  */
@@ -2453,6 +2478,7 @@
 	.con_screen_pos 	= fbcon_screen_pos,
 	.con_getxy 		= fbcon_getxy,
 	.con_resize             = fbcon_resize,
+	.con_notify             = fbcon_notify,
 };
 
 static struct notifier_block fbcon_event_notifier = {
drivers/video/riva/fbdev.c +56 -14

146 lines not on this page · raw message

drivers/video/riva/rivafb.h +3 -0
diff -Naur linux-2.6.7-mm1-orig/drivers/video/riva/rivafb.h linux-2.6.7-mm1/drivers/video/riva/rivafb.h
@@ -50,6 +50,7 @@
 
 	struct riva_regs initial_state;	/* initial startup video mode */
 	struct riva_regs current_state;
+	struct riva_regs save_state;
 	struct vgastate state;
 	atomic_t ref_count;
 	u32 cursor_data[32 * 32/4];
@@ -60,6 +61,8 @@
 	Bool SecondCRTC;
 	int FlatPanel;
 	struct pci_dev *pdev;
+	int bus;
+	int reset;
 #ifdef CONFIG_MTRR
 	struct { int vram; int vram_valid; } mtrr;
 #endif
include/linux/console.h +1 -0
diff -Naur linux-2.6.7-mm1-orig/include/linux/console.h linux-2.6.7-mm1/include/linux/console.h
@@ -50,6 +50,7 @@
 	void	(*con_invert_region)(struct vc_data *, u16 *, int);
 	u16    *(*con_screen_pos)(struct vc_data *, int);
 	unsigned long (*con_getxy)(struct vc_data *, unsigned long, int *, int *);
+	void    (*con_notify)(struct vc_data *, struct vc_data *);
 };
 
 extern const struct consw *conswitchp;
include/linux/fb.h +3 -0
diff -Naur linux-2.6.7-mm1-orig/include/linux/fb.h linux-2.6.7-mm1/include/linux/fb.h
@@ -501,6 +501,9 @@
 
 	/* perform fb specific mmap */
 	int (*fb_mmap)(struct fb_info *info, struct file *file, struct vm_area_struct *vma);
+
+	/* hardware state change */
+	void (*fb_state_switch)(struct fb_info *info, int out, int vc_mode);
 };
 
 /* FBINFO_* = fb_info.flags bit flags */

-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com

#2 lore raw
In reply to Antonino A. Daplas
Quoted 15 lines · Antonino A. Daplas

Hi,

**This patch is more of an RFC. BenH probably has similar code.

This patch adds a method (con_notify) that will notify console drivers of impending console switches, passing them with the about-to-be-old (last) vc structure and about-to-be-new (wanted) vc structure. The console drivers can then elect to pass selected information to low-level drivers.

This is important to fbcon so it can detect a switch from a graphics console to a text console and vice versa. This will give underlying drivers a chance to update its hardware state. This is added via the method fbcon_state_switch(). Fbcon will, however, do a set_par if the _state_switch method is not availabe and if switching from a KD_GRAPHICS console.

Quoted 6 lines

Also updated rivafb to take advantage of this method. With this, switching to/from X with XFree86/Org nv driver works. Usually it hangs without the option usefbdev, or gets a Sig11 if with option usefbdev.

(Unfortunately it doesn't work for nVidia's binary nvidia driver, switching to the console is possible, switching back to X will hang the machine).

You don't need that. A method for that was _ALREADY_ added to the kernel, it's based on the fact that the blank() callback is called on switches between KD_TEXT and KD_GRAPHICS. After discussing the issue with Linus, we decided to add a parameter to it indicating the nature of the switch. You should be able to rely on that. Actually, if you look at the code, I'm forcing a set_par in this case. If this doesn't work, then I may have missed a code path, and that should be fixed but there is no need at this point to change the infrastructure.

Ben.

-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com

#3 lore raw
Quoted 9 lines · Benjamin Herrenschmidt

You don't need that. A method for that was _ALREADY_ added to the kernel, it's based on the fact that the blank() callback is called on switches between KD_TEXT and KD_GRAPHICS. After discussing the issue with Linus, we decided to add a parameter to it indicating the nature of the switch. You should be able to rely on that. Actually, if you look at the code, I'm forcing a set_par in this case. If this doesn't work, then I may have missed a code path, and that should be fixed but there is no need at this point to change the infrastructure.

Thanks Ben, I see it now. I did not realize it was in the console_blank hook. (I did not follow this list for a time). And no, I don't think you missed a code path. The problem is that we are calling fb_set_var->set_par too early, before X has really given up on the hardware. We can fix this by setting some kind of flag while in fbcon_blank, and depending on the setting of this flag, force a set_par in fbcon_switch instead.

I'll concoct a patch later. (I'll test James' new patch first).

Tony

-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com

#4 lore raw
Quoted 8 lines · Antonino A. Daplas

Thanks Ben, I see it now. I did not realize it was in the console_blank hook. (I did not follow this list for a time). And no, I don't think you missed a code path. The problem is that we are calling fb_set_var->set_par too early, before X has really given up on the hardware. We can fix this by setting some kind of flag while in fbcon_blank, and depending on the setting of this flag, force a set_par in fbcon_switch instead.

I'll concoct a patch later. (I'll test James' new patch first).

That would be a bug in X

If console switching, the 'unblank' is done, afaik, after X calls the ioctl to relinguish the console to the kernel.

When exiting X, I'm not sure, but that should be similar. If X still touches the HW after that, it's an X bug (and yes, I does that, at least in the radeon driver, afaik)

Ben.

-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com

#5 lore raw
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 9 lines · Antonino A. Daplas

Thanks Ben, I see it now. I did not realize it was in the console_blank hook. (I did not follow this list for a time). And no, I don't think you missed a code path. The problem is that we are calling fb_set_var->set_par too early, before X has really given up on the hardware. We can fix this by setting some kind of flag while in fbcon_blank, and depending on the setting of this flag, force a set_par in fbcon_switch instead.

I'll concoct a patch later. (I'll test James' new patch first).

Quoted 9 lines

That would be a bug in X

If console switching, the 'unblank' is done, afaik, after X calls the ioctl to relinguish the console to the kernel.

When exiting X, I'm not sure, but that should be similar. If X still touches the HW after that, it's an X bug (and yes, I does that, at least in the radeon driver, afaik)

Include nvidia into the list. With the nv driver, the whole machine hangs. The i810 has cursor sprite corruption, but has a workaround for it.

So, I would still like to do the set_par as late as possible such as in fbcon_switch(). (BTW, this fixes the riva driver)

Tony

-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com

#6 lore raw
Quoted 6 lines

Include nvidia into the list. With the nv driver, the whole machine hangs. The i810 has cursor sprite corruption, but has a workaround for it.

So, I would still like to do the set_par as late as possible such as in fbcon_switch(). (BTW, this fixes the riva driver)

Except that you may not have a switch, if for example an app switch to KD_GRAPHICS, do stuff with the engine, then back to KD_TEXT on the same console...

Ben.

-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com

#7 lore raw
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 6 lines

Include nvidia into the list. With the nv driver, the whole machine hangs. The i810 has cursor sprite corruption, but has a workaround for it.

So, I would still like to do the set_par as late as possible such as in fbcon_switch(). (BTW, this fixes the riva driver)

Except that you may not have a switch, if for example an app switch to KD_GRAPHICS, do stuff with the engine, then back to KD_TEXT on the same console...

fbcon_switch() will be called when there is a request to redraw the screen of the same vc, such as in the above, or when switching to a different vc.

I think the name 'con_switch' is misleading. The better term, IMO, is 'con_redraw'.

Tony

-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com

#8 lore raw
Quoted 6 lines

fbcon_switch() will be called when there is a request to redraw the screen of the same vc, such as in the above, or when switching to a different vc.

I think the name 'con_switch' is misleading. The better term, IMO, is 'con_redraw'.

Hrm... ok, I missed that one then. It would still be useful to figure out what's wrong with X, it may not be a driver problem, but rather an X core problem calling the driver "restore" callbacks at the wrong time, and thus more easily fixable

Ben.

-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training. Attend Black Hat Briefings & Training, Las Vegas July 24-29 - digital self defense, top technical experts, no vendor pitches, unmatched networking opportunities. Visit www.blackhat.com