Skip to contentSkip to conversation

Detect switching to X?

DISCUSSION Knut Petersen 2 participants 12 messages Nov 27, 2005 – Nov 28, 2005

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

Hi everybody,

I could significantly increase the speed of cyblafb if I decided to use some registers the trident driver of X* does not know about.

Is there any way for a framebuffer driver to detect that a switch to X is in progress?

cu,
knut

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click

#1 lore raw
Quoted 7 lines · Knut Petersen

Hi everybody,

I could significantly increase the speed of cyblafb if I decided to use some registers the trident driver of X* does not know about.

Is there any way for a framebuffer driver to detect that a switch to X is in progress?

None, although fbcon will detect switches from KD_TEXT<->KD_GRAPHICS. I'm thinking of adding optional fb_save_state() and fb_restore_state() hooks which fbcon will call before going to KD_TEXT and before going to KD_GRAPHICS respectively.

I have the code in my development tree since one of the drivers does not work with the experimental DRI driver. The DRI driver does not fully restore its hardware state so the fbdev driver has to do the restore for it.

Tony

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click

#2 lore raw

Hi Tony

Quoted 11 lines
Quoted 5 lines

Is there any way for a framebuffer driver to detect that a switch to X is in progress?

None, although fbcon will detect switches from KD_TEXT<->KD_GRAPHICS. I'm thinking of adding optional fb_save_state() and fb_restore_state() hooks which fbcon will call before going to KD_TEXT and before going to KD_GRAPHICS respectively.

Quoted 7 lines

I have the code in my development tree since one of the drivers does not work with the experimental DRI driver. The DRI driver does not fully restore its hardware state so the fbdev driver has to do the restore for it.

Please do submit that code as a patch to the main kernel tree as soon as possible.

I cannot take advantage of the full memory reserved for the cyberblade/i1 because the trident X driver only knows about the vga style way of setting the screen start address. The other way involves the usage of the register at GEBase + 0x10, but that disables the vga style setting completely.

There is one alternative way: I could hook somewhere into a periodically called interrupt, put some insane value into the vga style regs and check for a change. Then I would assume that X has switched to KD_GRAPHICS and enable the vga style again.

cu,
knut

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click

#3 lore raw
Quoted 19 lines · Knut Petersen

Hi Tony

Quoted 10 lines
Quoted 4 lines

Is there any way for a framebuffer driver to detect that a switch to X is in progress?

None, although fbcon will detect switches from KD_TEXT<->KD_GRAPHICS. I'm thinking of adding optional fb_save_state() and fb_restore_state() hooks which fbcon will call before going to KD_TEXT and before going to KD_GRAPHICS respectively.

Quoted 7 lines

I have the code in my development tree since one of the drivers does not work with the experimental DRI driver. The DRI driver does not fully restore its hardware state so the fbdev driver has to do the restore for it.

Quoted 3 lines

Please do submit that code as a patch to the main kernel tree as soon as possible.

The patch is not really palatable. It is a patch that attempts to fix bugs in X, not fbcon. Unless the problem is really widespread, then maybe I'll go for it for mainline.

Quoted 8 lines

I cannot take advantage of the full memory reserved for the cyberblade/i1 because
the trident X driver only knows about the vga style way of setting the screen start
address. The other way involves the usage of the register at GEBase + 0x10, but
that disables the vga style setting completely.

Quoted 6 lines

There is one alternative way: I could hook somewhere into a periodically called
interrupt, put some insane value into the vga style regs and check for a change.
Then I would assume that X has switched to KD_GRAPHICS and enable the vga style again.

You need not do that (do a periodic check). A set_par() will always be called by fbcon whenever the console transitions from KD_GRAPHICS to KD_TEXT. So all you need to do is possibly check some register that says the hardware is in legacy mode.

Tony

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click

#4 lore raw

Hi Tony,

Quoted 7 lines

The patch is not really palatable. It is a patch that attempts to fix bugs in X, not fbcon. Unless the problem is really widespread, then maybe I'll go for it for mainline.

Quoted 6 lines

You need not do that (do a periodic check). A set_par() will always be called by fbcon whenever the console transitions from KD_GRAPHICS to KD_TEXT. So all you need to do is possibly check some register that says the hardware is in legacy mode.

The problem is _not_ the transition KD_GRAPHICS to KD_TEXT, that is handled perfectly well. The problem is that after switching from KD_TEXT to KD_GRAPHICS the trident X driver is unable to set the correct screen start address because cyblafb disabled the bits of several registers the trident driver uses for that purpose.

If I would submit a patch to the X team to enhance the trident driver, that would only solve the problem for those that use that new driver. I would have to wait several years until I could be reasonably sure not to break the system of too many people.

Even without that problem it would be nice to inform the framebuffer drivers about an ongoing switch to/from KD_GRAPHICS. Now there often is garbage displayed for some fractions of a second while switching to X, that could be prevented if the framebuffer drivers would have the chance to e.g. clear the whole framebuffer memory before the X driver starts to switch video mode etc.

Today framebuffer drivers are limited by the fact that they need to leave the graphics engine in a state that current and older (but still used) X drivers can handle. That unreasonable limitation should be removed, and it can be removed by those optional fb_save_state() and fb_restore_state() hooks.

cu,
Knut

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click

#5 lore raw
Quoted 11 lines · Knut Petersen

Hi Tony,

Today framebuffer drivers are limited by the fact that they need to leave the graphics
engine in a state that current and older (but still used) X drivers can handle. That
unreasonable limitation should be removed, and it can be removed by those optional
fb_save_state() and fb_restore_state() hooks.

Okay.

Tony

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click

#6 lore raw
In reply to Knut Petersen
Quoted 10 lines · Knut Petersen

Hi Tony,

Today framebuffer drivers are limited by the fact that they need to leave the graphics
engine in a state that current and older (but still used) X drivers can handle. That
unreasonable limitation should be removed, and it can be removed by those optional
fb_save_state() and fb_restore_state() hooks.

Try this patch.

fb_save_state() will be called when going from KD_GRAPHICS to KD_TEXT. The driver has the opportunity here to save the current state of the hardware before it's touched by fbdev.

fb_restore_state() will be called when going from KD_TEXT to KD_GRAPHICS mode. The driver has the opportunity to set the hardware back to something recognizable by the graphics application.

The state saving and restoration methods are up to driver author. It can range from a simple hack, a single register save and restore to a full blown total hardware state save and restore.

Tony

drivers/video/console/fbcon.c +4 -1
index 1a8f0ea..9678045 100644
@@ -2181,11 +2181,14 @@ static int fbcon_blank(struct vc_data *v
 		ops->graphics = 1;
 
 		if (!blank) {
+			if (info->fbops->fb_save_state)
+				info->fbops->fb_save_state(info);
 			var.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_FORCE;
 			fb_set_var(info, &var);
 			ops->graphics = 0;
 			ops->var = info->var;
-		}
+		} else if (info->fbops->fb_restore_state)
+			info->fbops->fb_restore_state(info);
 	}
 
  	if (!fbcon_is_inactive(vc, info)) {
include/linux/fb.h +6 -0
index 58e6c21..7d6d970 100644
@@ -617,6 +617,12 @@ struct fb_ops {
 
 	/* perform fb specific mmap */
 	int (*fb_mmap)(struct fb_info *info, struct file *file, struct vm_area_struct *vma);
+
+	/* save current hardware state */
+	void (*fb_save_state)(struct fb_info *info);
+
+	/* restore saved state */
+	void (*fb_restore_state)(struct fb_info *info);
 };
 
 #ifdef CONFIG_FB_TILEBLITTING

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click

#7 lore raw

Hi Tony,

thanks for the quick reply.

Quoted 10 lines

Try this patch.

fb_save_state() will be called when going from KD_GRAPHICS to KD_TEXT. The driver has the opportunity here to save the current state of the hardware before it's touched by fbdev.
fb_restore_state() will be called when going from KD_TEXT to KD_GRAPHICS mode. The driver has the opportunity to set the hardware back to something recognizable by the graphics application.

Are you sure? I added a save_state and restore_state function to cyblafb, both including nothing but a printk and return. I also added a printk at the start of both the check_var and set_par functions of cyblafb. The "Scrollmode= ..." lines originate from a printk in updatescrollmode:

Loading of cyblafb and switching to it using the following commands:

echo -n "0" > /sys/class/graphics/fb0/con_rotate echo -n "0" > /sys/class/graphics/fb1/con_rotate con2fb /dev/fb0 /dev/tty1
rmmod cyblafb
sync
modprobe cyblafb scalign=4
con2fb /dev/fb1 /dev/tty1
echo -n "0" > /sys/class/graphics/fb0/con_rotate echo -n "0" > /sys/class/graphics/fb1/con_rotate setfont ~/lat9w-16.psfu.gz
rcgpm restart
echo -e '\033[?2c'

dmesg output:

   [ 4910.034508] cyblafb: CyblaFB version 0.55 normal exit.
   [ 4910.086590] cyblafb: CyblaFB version 0.55 initializing
   [ 4910.088746] cyblafb: Pixmap size = 8188, alignement = 4
   [ 4910.090688] ACPI: PCI Interrupt 0000:01:00.0[A] -> Link [LNKA] -> 
GSI 11 (level, low) -> IRQ 11
   [ 4910.094348] cyblafb: region 0x3c0/0x20 already reserved
   [ 4910.096321] cyblafb: region 0xe1800000/0x800000 already reserved
   [ 4910.098374] cyblafb: check_var
   [ 4910.106050] cyblafb: set_par
   [ 4910.108224] Scrollmode = SCROLL_PAN_MOVE
   [ 4910.121050] Scrollmode = SCROLL_PAN_MOVE
   [ 4910.138671] Scrollmode = SCROLL_PAN_MOVE
   [ 4910.138763] Scrollmode = SCROLL_PAN_MOVE
   [ 4910.180336] Scrollmode = SCROLL_PAN_MOVE

now switching to X:

   [ 4921.533936] Scrollmode = SCROLL_PAN_REDRAW

now switching back to framebuffer console:

   [ 4929.167382] cyblafb: set_par
   [ 4929.169506] Scrollmode = SCROLL_PAN_MOVE
   [ 4929.181895] cyblafb: save_state has been called, switching from 
KD_GRAPHICS to KD_TEXT
   [ 4929.181917] cyblafb: check_var
   [ 4929.181929] cyblafb: set_par
   [ 4929.184695] Scrollmode = SCROLL_PAN_MOVE

no switching to X again:

   [ 4933.273261] Scrollmode = SCROLL_PAN_REDRAW

1. restore_state is never called
2. there is a set_par prior to the call to save_state, but that´s irrelevant for me as there is a check_var and set_par call after save_state.

cu,
Knut

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click

#8 lore raw
Quoted 70 lines · Knut Petersen

Hi Tony,

thanks for the quick reply.

Quoted 12 lines

Try this patch.

fb_save_state() will be called when going from KD_GRAPHICS to KD_TEXT. The
driver has the opportunity here to save the current state of the hardware before it's touched by fbdev.
fb_restore_state() will be called when going from KD_TEXT to KD_GRAPHICS mode. The driver has the opportunity to set the hardware back to something
recognizable by the graphics application.

Are you sure? I added a save_state and restore_state function to cyblafb, both
including nothing but a printk and return. I also added a printk at the start of
both the check_var and set_par functions of cyblafb. The "Scrollmode= ..." lines
originate from a printk in updatescrollmode:

Loading of cyblafb and switching to it using the following commands:

echo -n "0" > /sys/class/graphics/fb0/con_rotate echo -n "0" > /sys/class/graphics/fb1/con_rotate con2fb /dev/fb0 /dev/tty1
rmmod cyblafb
sync
modprobe cyblafb scalign=4
con2fb /dev/fb1 /dev/tty1
echo -n "0" > /sys/class/graphics/fb0/con_rotate echo -n "0" > /sys/class/graphics/fb1/con_rotate setfont ~/lat9w-16.psfu.gz
rcgpm restart
echo -e '\033[?2c'

dmesg output:

   [ 4910.034508] cyblafb: CyblaFB version 0.55 normal exit.
   [ 4910.086590] cyblafb: CyblaFB version 0.55 initializing
   [ 4910.088746] cyblafb: Pixmap size = 8188, alignement = 4
   [ 4910.090688] ACPI: PCI Interrupt 0000:01:00.0[A] -> Link [LNKA] ->
GSI 11 (level, low) -> IRQ 11
   [ 4910.094348] cyblafb: region 0x3c0/0x20 already reserved
   [ 4910.096321] cyblafb: region 0xe1800000/0x800000 already reserved
   [ 4910.098374] cyblafb: check_var
   [ 4910.106050] cyblafb: set_par
   [ 4910.108224] Scrollmode = SCROLL_PAN_MOVE
   [ 4910.121050] Scrollmode = SCROLL_PAN_MOVE
   [ 4910.138671] Scrollmode = SCROLL_PAN_MOVE
   [ 4910.138763] Scrollmode = SCROLL_PAN_MOVE
   [ 4910.180336] Scrollmode = SCROLL_PAN_MOVE

now switching to X:

   [ 4921.533936] Scrollmode = SCROLL_PAN_REDRAW

now switching back to framebuffer console:

   [ 4929.167382] cyblafb: set_par
   [ 4929.169506] Scrollmode = SCROLL_PAN_MOVE
   [ 4929.181895] cyblafb: save_state has been called, switching from
KD_GRAPHICS to KD_TEXT
   [ 4929.181917] cyblafb: check_var
   [ 4929.181929] cyblafb: set_par
   [ 4929.184695] Scrollmode = SCROLL_PAN_MOVE
Quoted 8 lines

no switching to X again:

   [ 4933.273261] Scrollmode = SCROLL_PAN_REDRAW

1. restore_state is never called
2. there is a set_par prior to the call to save_state, but that´s irrelevant for me as
there is a check_var and set_par call after save_state.

Works here. I inserted printk's before the calls to fb_save|restore_state in fbcon.c, switched to X and console several times, and I get this:

fbcon: save state
fbcon: restore state
fbcon: save state
fbcon: restore state
fbcon: save state
fbcon: restore state

Tony

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click

#9 lore raw

Hi Tony,

Quoted 5 lines

Works here. I inserted printk's before the calls to fb_save|restore_state in fbcon.c, switched to X and console several times, and I get this:

Q: kernel version ?

cu,
knut

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click

#10 lore raw
Quoted 9 lines · Knut Petersen

Hi Tony,

Quoted 6 lines

Works here. I inserted printk's before the calls to fb_save|restore_state
in fbcon.c, switched to X and console several times, and I get this:

Q: kernel version ?

I have this code since 2.6.12 and thereabouts. Currently, I'm at linux-2.6.15-rc2-mm1.

You might want to also check drivers/char/vt.c:do_blank_screen(). If going to KD_GRAPHICS mode, entering_gfx != 0.

Tony

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click

#11 lore raw
Quoted 11 lines

I have this code since 2.6.12 and thereabouts. Currently, I'm at linux-2.6.15-rc2-mm1.

You might want to also check drivers/char/vt.c:do_blank_screen(). If going to KD_GRAPHICS mode, entering_gfx != 0.

Tony

Well, the code does work perfectly well. During the transition to KD_GRAPHICS there is first a switch to the tty that is used by X, then the mode switch occures. But I activated cyblafb for tty1 only, vesafb was in control of all other ttys. So the restore_state of cyblafb never was called. Stupid mistake on my side ...

Please submit the patch.

cu,
knut

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click