ARM STM/i.MX: Allocate memory for framebuffer during probe
Subsystems (2)
PATCH 1/4 ARM STM/i.MX: Allocate memory for framebuffer during probe
With current code when the framebuffer is register, screen_base is not set yet. So when we want to access framebuffer from mmap we get a pointer to 0x0 instead of getting the pointer to the framebuffer address. This patch fix this bug by allocating memory for framebuffer during probe just before registering framebuffer driver.
--- drivers/video/stm.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
drivers/video/stm.c +10 -0
@@ -480,6 +480,7 @@ static int stmfb_probe(struct device_d *hw_dev) {struct imx_fb_videomode *pdata = hw_dev->platform_data;int ret; +unsigned size;/* just init */ fbi.info.priv = &fbi;
@@ -497,6 +498,15 @@ static int stmfb_probe(struct device_d *hw_dev) fbi.info.yres = fbi.info.mode->yres; fbi.info.bits_per_pixel =16 ; + size =calc_line_length (fbi.info.mode->xres, fbi.info.bits_per_pixel) * + fbi.info.mode->yres; + + ret =stmfb_memory_mmgt (&fbi.info, size); +if (ret !=0 ) { +dev_err (hw_dev,"Cannot allocate framebuffer memory\n" ); +return ret; + } + ret =register_framebuffer (&fbi.info);if (ret !=0 ) {dev_err (hw_dev,"Failed to register framebuffer\n" );
Signature · 9 lines
1.7.0.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Quoted 5 lines · Gregory CLEMENT
With current code when the framebuffer is register,
screen_baseis not set yet. So when we want to access framebuffer from mmap we get a pointer to0x0instead of getting the pointer to the framebuffer address. This patch fix this bug by allocating memory for framebuffer during probe just before registering framebuffer driver.
Are you sure? See below
Quoted 23 lines
Signed-off-by Gregory CLEMENT <[email protected]>--- drivers/video/stm.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)drivers/video/stm.c +3
-0@@ -480,6 +480,7 @@ static int stmfb_probe(struct device_d *hw_dev) {struct imx_fb_videomode *pdata = hw_dev->platform_data;int ret; +unsigned size;/* just init */ fbi.info.priv = &fbi;@@ -497,6 +498,15 @@ static int stmfb_probe(struct device_d *hw_dev) fbi.info.yres = fbi.info.mode->yres; fbi.info.bits_per_pixel =16 ; + size =calc_line_length (fbi.info.mode->xres, fbi.info.bits_per_pixel) * + fbi.info.mode->yres;
drivers/video/stm.c static int stmfb_probe(struct device_d *hw_dev) · line 512
Quoted 10 lines
drivers/video/stm.c +7
-0+ + ret =stmfb_memory_mmgt (&fbi.info, size); +if (ret !=0 ) { +dev_err (hw_dev,"Cannot allocate framebuffer memory\n" ); +return ret; + } + ret =register_framebuffer (&fbi.info);if (ret !=0 ) {dev_err (hw_dev,"Failed to register framebuffer\n" );
This probe function sets up the default mode. And register_framebuffer() itself calls stmfb_activate_var() which calls stmfb_memory_mmgt(). So, when the call to register_framebuffer() returns the 'screen_base' should no longer be NULL.
jbe
Signature · 9 lines
Pengutronix e.K. | Juergen Beisert | Linux Solutions for Science and Industry | Phone: +49-8766-939 228 | Vertretung Sued/Muenchen, Germany | Fax: +49-5121-206917-5555 | Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de/ | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Quoted 8 lines · Juergen Beisert
Quoted 5 lines · Gregory CLEMENT
With current code when the framebuffer is register,
screen_baseis not set yet. So when we want to access framebuffer from mmap we get a pointer to0x0instead of getting the pointer to the framebuffer address. This patch fix this bug by allocating memory for framebuffer during probe just before registering framebuffer driver.Are you sure? See below
It was the value I get at runtime at least.
Quoted 2 lines
Quoted 2 lines
Signed-off-by Gregory CLEMENT <[email protected]>
[...]
Quoted 5 lines
This probe function sets up the default mode. And
register_framebuffer()itself callsstmfb_activate_var()which callsstmfb_memory_mmgt(). So, when the call toregister_framebuffer()returns the 'screen_base' should no longer be NULL.
But in register_framebuffer first map_base get its value from screen_base and it is only after that fb_activate_var is called. And the problem is that mmap will not get screen_base but map_base and this one is set too early. Extract from register_framebuffer() in fb.c:
info->cdev.dev->map_base = (unsigned long)info->screen_base;
map_base get its value here ------^
info->cdev.dev->size = info->cdev.size;
dev = &info->dev;
dev->priv = info;
dev->id = id;
sprintf(dev->name, "fb");
register_device(&info->dev);
dev_add_param(dev, "enable", fb_enable_set, NULL, 0);
dev_set_param(dev, "enable", "0");
if (info->num_modes && (info->mode_list != NULL) &&
(info->fbops->fb_activate_var != NULL)) {
dev_add_param(dev, "mode_name", fb_setup_mode, NULL, 0);
dev_set_param(dev, "mode_name", info->mode_list[0].name);fb_activate_var is called here ------------------------^
This code is new for me, maybe I missed something.
Quoted 3 lines
jbe
Signature · 9 lines
Gregory Clement, Free Electrons Kernel, drivers, real-time and embedded Linux development, consulting, training and support. http://free-electrons.com _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Quoted 44 lines · Gregory CLEMENT
Quoted 8 lines · Juergen Beisert
Quoted 5 lines · Gregory CLEMENT
With current code when the framebuffer is register,
screen_baseis not set yet. So when we want to access framebuffer from mmap we get a pointer to0x0instead of getting the pointer to the framebuffer address. This patch fix this bug by allocating memory for framebuffer during probe just before registering framebuffer driver.Are you sure? See below
It was the value I get at runtime at least.
Quoted 1 line
Quoted 1 line
Signed-off-by Gregory CLEMENT <[email protected]>[...]
Quoted 4 lines
This probe function sets up the default mode. And
register_framebuffer()itself callsstmfb_activate_var()which callsstmfb_memory_mmgt(). So, when the call toregister_framebuffer()returns the 'screen_base' should no longer be NULL.But in
register_framebufferfirstmap_baseget its value fromscreen_baseand it is only after thatfb_activate_varis called. And the problem is that mmap will not getscreen_basebutmap_baseand this one is set too early. Extract fromregister_framebuffer()infb.c:info->cdev.dev->map_base = (unsigned long)info->screen_base; map_base get its value here ------^ info->cdev.dev->size = info->cdev.size; dev = &info->dev; dev->priv = info; dev->id = id; sprintf(dev->name, "fb"); register_device(&info->dev); dev_add_param(dev, "enable", fb_enable_set, NULL, 0); dev_set_param(dev, "enable", "0"); if (info->num_modes && (info->mode_list != NULL) && (info->fbops->fb_activate_var != NULL)) { dev_add_param(dev, "mode_name", fb_setup_mode, NULL, 0); dev_set_param(dev, "mode_name", info->mode_list[0].name);
Quoted 1 line
fb_activate_varis called here ------------------------^
And this call will call driver's stmfb_activate_var() (and(!) stmfb_memory_mmgt()).
But I will check it again.
jbe
Signature · 9 lines
Pengutronix e.K. | Juergen Beisert | Linux Solutions for Science and Industry | Phone: +49-8766-939 228 | Vertretung Sued/Muenchen, Germany | Fax: +49-5121-206917-5555 | Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de/ | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Quoted 41 lines · Juergen Beisert
Quoted 40 lines · Gregory CLEMENT
Quoted 8 lines · Juergen Beisert
Quoted 5 lines · Gregory CLEMENT
With current code when the framebuffer is register,
screen_baseis not set yet. So when we want to access framebuffer from mmap we get a pointer to0x0instead of getting the pointer to the framebuffer address. This patch fix this bug by allocating memory for framebuffer during probe just before registering framebuffer driver.Are you sure? See below
It was the value I get at runtime at least.
Quoted 1 line
Quoted 1 line
Signed-off-by Gregory CLEMENT <[email protected]>[...]
Quoted 4 lines
This probe function sets up the default mode. And
register_framebuffer()itself callsstmfb_activate_var()which callsstmfb_memory_mmgt(). So, when the call toregister_framebuffer()returns the 'screen_base' should no longer be NULL.But in
register_framebufferfirstmap_baseget its value fromscreen_baseand it is only after thatfb_activate_varis called. And the problem is that mmap will not getscreen_basebutmap_baseand this one is set too early. Extract fromregister_framebuffer()infb.c:info->cdev.dev->map_base = (unsigned long)info->screen_base; map_base get its value here ------^ info->cdev.dev->size = info->cdev.size; dev = &info->dev; dev->priv = info; dev->id = id; sprintf(dev->name, "fb"); register_device(&info->dev); dev_add_param(dev, "enable", fb_enable_set, NULL, 0); dev_set_param(dev, "enable", "0");
Quoted 8 lines
Quoted 5 lines
if (info->num_modes && (info->mode_list != NULL) && (info->fbops->fb_activate_var != NULL)) { dev_add_param(dev, "mode_name", fb_setup_mode, NULL, 0); dev_set_param(dev, "mode_name", info->mode_list[0].name);
fb_activate_varis called here ------------------------^And this call will call driver's
stmfb_activate_var()(and(!)stmfb_memory_mmgt()).
Yes I totally agree with this. But at this time it's too late because changing screen_base won't change map_base. And a call to memmap is a call to generic_memmap_rw which will return map_base.
I didn't find anywhere in video driver code a place where map_base is updated, that's why I think that once it get its value it won't change.
Quoted 4 lines
But I will check it again.
jbe
Signature · 9 lines
Gregory Clement, Free Electrons Kernel, drivers, real-time and embedded Linux development, consulting, training and support. http://free-electrons.com _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Quoted 48 lines · Gregory CLEMENT
Quoted 47 lines · Juergen Beisert
Quoted 45 lines · Gregory CLEMENT
Quoted 8 lines · Juergen Beisert
Quoted 5 lines · Gregory CLEMENT
With current code when the framebuffer is register,
screen_baseis not set yet. So when we want to access framebuffer from mmap we get a pointer to0x0instead of getting the pointer to the framebuffer address. This patch fix this bug by allocating memory for framebuffer during probe just before registering framebuffer driver.Are you sure? See below
It was the value I get at runtime at least.
Quoted 1 line
Quoted 1 line
Signed-off-by Gregory CLEMENT <[email protected]>[...]
Quoted 4 lines
This probe function sets up the default mode. And
register_framebuffer()itself callsstmfb_activate_var()which callsstmfb_memory_mmgt(). So, when the call toregister_framebuffer()returns the 'screen_base' should no longer be NULL.But in
register_framebufferfirstmap_baseget its value fromscreen_baseand it is only after thatfb_activate_varis called. And the problem is that mmap will not getscreen_basebutmap_baseand this one is set too early. Extract fromregister_framebuffer()infb.c:info->cdev.dev->map_base = (unsigned long)info->screen_base; map_base get its value here ------^ info->cdev.dev->size = info->cdev.size; dev = &info->dev; dev->priv = info; dev->id = id; sprintf(dev->name, "fb"); register_device(&info->dev); dev_add_param(dev, "enable", fb_enable_set, NULL, 0); dev_set_param(dev, "enable", "0"); if (info->num_modes && (info->mode_list != NULL) && (info->fbops->fb_activate_var != NULL)) { dev_add_param(dev, "mode_name", fb_setup_mode, NULL, 0); dev_set_param(dev, "mode_name", info->mode_list[0].name);
fb_activate_varis called here ------------------------^
Quoted 11 lines
Quoted 2 lines
And this call will call driver's
stmfb_activate_var()(and(!)stmfb_memory_mmgt()).Yes I totally agree with this. But at this time it's too late because changing
screen_basewon't changemap_base. And a call to memmap is a call togeneric_memmap_rwwhich will returnmap_base.
I didn't find anywhere in video driver code a place wheremap_baseis updated, that's why I think that once it get its value it won't change.Quoted 2 lines
But I will check it again.
Had you had some time to check it?
Will you take this patch ?
If you have any comments I am willing to take them in account to make a new version of this patch if it necessary.
Regards,
Quoted 4 lines
Quoted 2 lines
jbe
Signature · 9 lines
Gregory Clement, Free Electrons Kernel, drivers, real-time and embedded Linux development, consulting, training and support. http://free-electrons.com _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Quoted 58 lines · Gregory CLEMENT
Quoted 57 lines · Gregory CLEMENT
Quoted 41 lines · Juergen Beisert
Quoted 40 lines · Gregory CLEMENT
Quoted 8 lines · Juergen Beisert
Quoted 5 lines · Gregory CLEMENT
With current code when the framebuffer is register,
screen_baseis not set yet. So when we want to access framebuffer from mmap we get a pointer to0x0instead of getting the pointer to the framebuffer address. This patch fix this bug by allocating memory for framebuffer during probe just before registering framebuffer driver.Are you sure? See below
It was the value I get at runtime at least.
Quoted 1 line
Quoted 1 line
Signed-off-by Gregory CLEMENT <[email protected]>[...]
Quoted 4 lines
This probe function sets up the default mode. And
register_framebuffer()itself callsstmfb_activate_var()which callsstmfb_memory_mmgt(). So, when the call toregister_framebuffer()returns the 'screen_base' should no longer be NULL.But in
register_framebufferfirstmap_baseget its value fromscreen_baseand it is only after thatfb_activate_varis called. And the problem is that mmap will not getscreen_basebutmap_baseand this one is set too early. Extract fromregister_framebuffer()infb.c:info->cdev.dev->map_base = (unsigned long)info->screen_base; map_base get its value here ------^ info->cdev.dev->size = info->cdev.size; dev = &info->dev; dev->priv = info; dev->id = id; sprintf(dev->name, "fb"); register_device(&info->dev); dev_add_param(dev, "enable", fb_enable_set, NULL, 0); dev_set_param(dev, "enable", "0");Quoted 8 lines
Quoted 5 lines
if (info->num_modes && (info->mode_list != NULL) && (info->fbops->fb_activate_var != NULL)) { dev_add_param(dev, "mode_name", fb_setup_mode, NULL, 0); dev_set_param(dev, "mode_name", info->mode_list[0].name);
fb_activate_varis called here ------------------------^And this call will call driver's
stmfb_activate_var()(and(!)stmfb_memory_mmgt()).Yes I totally agree with this. But at this time it's too late because changing
screen_basewon't changemap_base. And a call to memmap is a call togeneric_memmap_rwwhich will returnmap_base.
I didn't find anywhere in video driver code a place wheremap_baseis updated, that's why I think that once it get its value it won't change.
Quoted 3 lines
Quoted 1 line
Quoted 1 line
But I will check it again.
Had you had some time to check it?
Not yet, sorry.
Quoted 3 lines
Will you take this patch ?
If you have any comments I am willing to take them in account to make a new version of this patch if it necessary.
Maybe I can check it tomorrow.
jbe
Signature · 9 lines
Pengutronix e.K. | Juergen Beisert | Linux Solutions for Science and Industry | Phone: +49-8766-939 228 | Vertretung Sued/Muenchen, Germany | Fax: +49-5121-206917-5555 | Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de/ | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox