# \[PATCH\] Fix loading of module radeonfb on PowerMac

- Subsystems: FRAMEBUFFER LAYER, RADEON FRAMEBUFFER DISPLAY DRIVER, THE REST
- Maintainers: Helge Deller, Benjamin Herrenschmidt, Linus Torvalds
- List: linux-fbdev
- 6 messages, 4 authors
- Page: https://ratatoskr.run/linux-fbdev/2016/10/9493065/t

## \[PATCH\] Fix loading of module radeonfb on PowerMac

- From: Mathieu Malaterre \<hidden\>
- Date: 2016-10-08 12:09:26 
- Message: https://ratatoskr.run/linux-fbdev/2016/10/9493065.md

```text
When the linux kernel is build with (typical kernel ship with Debian
installer):

CONFIG_FB_OF=y
CONFIG_VT_HW_CONSOLE_BINDING=y
CONFIG_FB_RADEON=m

The offb driver takes precedence over module radeonfb. It is then
impossible to load the module, error reported is:

[   96.551486] radeonfb 0000:00:10.0: enabling device (0006 -> 0007)
[   96.551526] radeonfb 0000:00:10.0: BAR 0: can't reserve [mem 0x98000000-0x9fffffff pref]
[   96.551531] radeonfb (0000:00:10.0): cannot request region 0.
[   96.551545] radeonfb: probe of 0000:00:10.0 failed with error -16

This patch reproduce the behavior of the module radeon, so as to make it
possible to load radeonfb when offb is first loaded.

It should be noticed that `offb_destroy` is never called which explain the
need to skip error detection on the radeon side.

Signed-off-by: Mathieu Malaterre <redacted>
Link: https://bugs.debian.org/826629#57
Suggested-by: Lennart Sorensen <redacted>
---
 drivers/video/fbdev/aty/radeon_base.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/drivers/video/fbdev/aty/radeon_base.c b/drivers/video/fbdev/aty/radeon_base.c
index 218339a..6f9bacd 100644
--- a/drivers/video/fbdev/aty/radeon_base.c
+++ b/drivers/video/fbdev/aty/radeon_base.c
@@ -2259,6 +2259,22 @@ static struct bin_attribute edid2_attr = {
 	.read	= radeon_show_edid2,
 };
 
+static int radeon_kick_out_firmware_fb(struct pci_dev *pdev)
+{
+	struct apertures_struct *ap;
+
+	ap = alloc_apertures(1);
+	if (!ap)
+		return -ENOMEM;
+
+	ap->ranges[0].base = pci_resource_start(pdev, 0);
+	ap->ranges[0].size = pci_resource_len(pdev, 0);
+
+	remove_conflicting_framebuffers(ap, KBUILD_MODNAME, false);
+	kfree(ap);
+
+	return 0;
+}
 
 static int radeonfb_pci_register(struct pci_dev *pdev,
 				 const struct pci_device_id *ent)
@@ -2314,19 +2330,21 @@ static int radeonfb_pci_register(struct pci_dev *pdev,
 	rinfo->fb_base_phys = pci_resource_start (pdev, 0);
 	rinfo->mmio_base_phys = pci_resource_start (pdev, 2);
 
+	ret = radeon_kick_out_firmware_fb(pdev);
+	if (ret)
+		return ret;
+
 	/* request the mem regions */
 	ret = pci_request_region(pdev, 0, "radeonfb framebuffer");
 	if (ret < 0) {
 		printk( KERN_ERR "radeonfb (%s): cannot request region 0.\n",
 			pci_name(rinfo->pdev));
-		goto err_release_fb;
 	}
 
 	ret = pci_request_region(pdev, 2, "radeonfb mmio");
 	if (ret < 0) {
 		printk( KERN_ERR "radeonfb (%s): cannot request region 2.\n",
 			pci_name(rinfo->pdev));
-		goto err_release_pci0;
 	}
 
 	/* map the regions */
-- 
2.1.4

```

## Re: \[PATCH\] Fix loading of module radeonfb on PowerMac

- From: Tomi Valkeinen \<hidden\>
- Date: 2016-11-02 08:40:08 
- Message: https://ratatoskr.run/linux-fbdev/2016/11/9493407.md

```text
On 08/10/16 15:09, Mathieu Malaterre wrote:
> When the linux kernel is build with (typical kernel ship with Debian
> installer):
> 
> CONFIG_FB_OF=y
> CONFIG_VT_HW_CONSOLE_BINDING=y
> CONFIG_FB_RADEON=m
> 
> The offb driver takes precedence over module radeonfb. It is then
> impossible to load the module, error reported is:
> 
> [   96.551486] radeonfb 0000:00:10.0: enabling device (0006 -> 0007)
> [   96.551526] radeonfb 0000:00:10.0: BAR 0: can't reserve [mem 0x98000000-0x9fffffff pref]
> [   96.551531] radeonfb (0000:00:10.0): cannot request region 0.
> [   96.551545] radeonfb: probe of 0000:00:10.0 failed with error -16
> 
> This patch reproduce the behavior of the module radeon, so as to make it
> possible to load radeonfb when offb is first loaded.
> 
> It should be noticed that `offb_destroy` is never called which explain the
> need to skip error detection on the radeon side.

Why is that? It sounds rather bad if two drivers claim the same resources.

 Tomi

```

## Re: \[PATCH\] Fix loading of module radeonfb on PowerMac

- From: Mathieu Malaterre \<hidden\>
- Date: 2016-11-02 10:29:19 
- Message: https://ratatoskr.run/linux-fbdev/2016/11/9493410.md

```text
Tomi,

On Wed, Nov 2, 2016 at 9:28 AM, Tomi Valkeinen [ref] wrote:
> On 08/10/16 15:09, Mathieu Malaterre wrote:
>> When the linux kernel is build with (typical kernel ship with Debian
>> installer):
>>
>> CONFIG_FB_OF=y
>> CONFIG_VT_HW_CONSOLE_BINDING=y
>> CONFIG_FB_RADEON=m
>>
>> The offb driver takes precedence over module radeonfb. It is then
>> impossible to load the module, error reported is:
>>
>> [   96.551486] radeonfb 0000:00:10.0: enabling device (0006 -> 0007)
>> [   96.551526] radeonfb 0000:00:10.0: BAR 0: can't reserve [mem 0x98000000-0x9fffffff pref]
>> [   96.551531] radeonfb (0000:00:10.0): cannot request region 0.
>> [   96.551545] radeonfb: probe of 0000:00:10.0 failed with error -16
>>
>> This patch reproduce the behavior of the module radeon, so as to make it
>> possible to load radeonfb when offb is first loaded.
>>
>> It should be noticed that `offb_destroy` is never called which explain the
>> need to skip error detection on the radeon side.
>
> Why is that? It sounds rather bad if two drivers claim the same resources.

This has been working great so far for `radeon.ko`, so I assumed I
could shamelessly copy the behavior over to `radeonfb.ko`.

The original reference I found was from Benjamin Herrenschmidt here:
https://lists.freedesktop.org/archives/dri-devel/2010-August/002907.html

I am of course willing to try something else, but I would need some guidance.

Thanks much.
```

## Re: \[PATCH\] Fix loading of module radeonfb on PowerMac

- From: Lennart Sorensen \<hidden\>
- Date: 2016-11-02 15:43:38 
- Message: https://ratatoskr.run/linux-fbdev/2016/11/9493417.md

```text
On Wed, Nov 02, 2016 at 10:28:55AM +0200, Tomi Valkeinen wrote:
> On 08/10/16 15:09, Mathieu Malaterre wrote:
> > When the linux kernel is build with (typical kernel ship with Debian
> > installer):
> > 
> > CONFIG_FB_OF=y
> > CONFIG_VT_HW_CONSOLE_BINDING=y
> > CONFIG_FB_RADEON=m
> > 
> > The offb driver takes precedence over module radeonfb. It is then
> > impossible to load the module, error reported is:
> > 
> > [   96.551486] radeonfb 0000:00:10.0: enabling device (0006 -> 0007)
> > [   96.551526] radeonfb 0000:00:10.0: BAR 0: can't reserve [mem 0x98000000-0x9fffffff pref]
> > [   96.551531] radeonfb (0000:00:10.0): cannot request region 0.
> > [   96.551545] radeonfb: probe of 0000:00:10.0 failed with error -16
> > 
> > This patch reproduce the behavior of the module radeon, so as to make it
> > possible to load radeonfb when offb is first loaded.
> > 
> > It should be noticed that `offb_destroy` is never called which explain the
> > need to skip error detection on the radeon side.
> 
> Why is that? It sounds rather bad if two drivers claim the same resources.

My understanding from reading through the console code is that you only
call destroy when the driver isn't in use anymore, and that doesn't
happen until something else takes over the console, which can't happen
until the new driver is active, which can't happen because the resources
are already claimed by the old driver.

PCs might be able to drop back to text console, but powerpc doesn't have
one of those so offb stays active until something else takes over the
console job it seems.

The radeon driver doesn't reserve resources, it just uses them.
This seems to be the case of quite a few drivers.

-- 
Len Sorensen
```

## Re: \[PATCH\] Fix loading of module radeonfb on PowerMac

- From: Benjamin Herrenschmidt \<benh@kernel.crashing.org\>
- Date: 2016-11-03 03:54:00 
- Message: https://ratatoskr.run/linux-fbdev/2016/11/9493421.md

```text
On Wed, 2016-11-02 at 11:28 +0100, Mathieu Malaterre wrote:
> 
> This has been working great so far for `radeon.ko`, so I assumed I
> could shamelessly copy the behavior over to `radeonfb.ko`.
> 
> The original reference I found was from Benjamin Herrenschmidt here:
> https://lists.freedesktop.org/archives/dri-devel/2010-August/002907.h
> tml
> 
> I am of course willing to try something else, but I would need some
> guidance.

I missed your original patch but yes, the basic idea is that we kick
out offb when the "real" driver loads.

Cheers,
Ben.

```

## Re: \[PATCH\] Fix loading of module radeonfb on PowerMac

- From: Tomi Valkeinen \<hidden\>
- Date: 2016-11-14 11:30:31 
- Message: https://ratatoskr.run/linux-fbdev/2016/11/9493577.md

```text
On 08/10/16 15:09, Mathieu Malaterre wrote:
> When the linux kernel is build with (typical kernel ship with Debian
> installer):
> 
> CONFIG_FB_OF=y
> CONFIG_VT_HW_CONSOLE_BINDING=y
> CONFIG_FB_RADEON=m
> 
> The offb driver takes precedence over module radeonfb. It is then
> impossible to load the module, error reported is:
> 
> [   96.551486] radeonfb 0000:00:10.0: enabling device (0006 -> 0007)
> [   96.551526] radeonfb 0000:00:10.0: BAR 0: can't reserve [mem 0x98000000-0x9fffffff pref]
> [   96.551531] radeonfb (0000:00:10.0): cannot request region 0.
> [   96.551545] radeonfb: probe of 0000:00:10.0 failed with error -16
> 
> This patch reproduce the behavior of the module radeon, so as to make it
> possible to load radeonfb when offb is first loaded.
> 
> It should be noticed that `offb_destroy` is never called which explain the
> need to skip error detection on the radeon side.
> 
> Signed-off-by: Mathieu Malaterre <redacted>
> Link: https://bugs.debian.org/826629#57
> Suggested-by: Lennart Sorensen <redacted>
> ---
>  drivers/video/fbdev/aty/radeon_base.c | 22 ++++++++++++++++++++--
>  1 file changed, 20 insertions(+), 2 deletions(-)

Thanks, queued for 4.9 fixes.

 Tomi

```
