# radeon fails to initialize AGP,radeon_cp_init error [SOLVED]

## LukasGraf

Hi everybody!

I'm trying to get a ATI Radeon 9600 to work with the opensource radeon driver from X.org, but the driver fails to initialize AGP, and in dmesg I get a "radeon_cp_init called without lock held" error every time I start X. Below are the details about my setup, and what I already did and tried. Let's start with the errors I get:

After I run startx, this shows up in /var/log/Xorg.0.log:

```
(WW) RADEON(0): [agp] AGP not available

(EE) RADEON(0): [agp] AGP failed to initialize. Disabling the DRI.

(II) RADEON(0): [agp] You may want to make sure the agpgart kernel module is loaded before the radeon kernel module.

```

But agpgart is loaded, before radeon. So I checked dmesg:

```
[drm:radeon_cp_init] *ERROR* radeon_cp_init called without lock held, held  0 owner 00000000 dea4d800

[drm:drm_unlock] *ERROR* Process 1974 using kernel context 0

```

These two error messages are generated once every time I start X, reproducibly. Until I attempt to start X, dmesg doesn't show anything suspicous.

Setup:

Motherboard: ASUS K8V Deluxe (Host Bridge: VIA VT8385 [K8T800 AGP])

VGA: ATI Radeon 9600 (GPU: RV350)

```
# lspci -v | egrep "AGP|VGA"

00:00.0 Host bridge: VIA Technologies, Inc. VT8385 [K8T800 AGP] Host Bridge (rev 01)

        Capabilities: [80] AGP version 3.5

01:00.0 VGA compatible controller: ATI Technologies Inc RV350 AP [Radeon 9600] (prog-if 00 [VGA])

        Capabilities: [58] AGP version 3.0

```

BIOS Settings:

```
Search for MDA Resources  [no]

AGP Mode                  [AGP 4X]

AGP Fast Write            [disabled]

Graphics Aperture Size    [64MB]

```

Kernel: 2.6.16-gentoo-r9

Settings:

```
Device Drivers  --->

   Character devices  --->

      <M> /dev/agpgart (AGP Support)

      <M>     VIA chipset support

      < > Direct Rendering Manager (XFree86 4.1.0 and higher DRI support)

Power management options (ACPI, APM)  --->

   --- Power Management support

   [*]   Legacy Power Management API

```

Modules:

Instead of the kernel modules I use x11-base/x11-drm to provide DRM. I set VIDEO_CARDS="radeon vesa" in make.conf:

(I also tried the kernel modules earlier, same errors)

```
# emerge -pv x11-drm

[ebuild   R   ] x11-base/x11-drm-20060608  VIDEO_CARDS="radeon -i810 -mach64 -mga -nv -r128 -savage -sis -tdfx -via" 0 kB

```

(x11-base/x11-drm20050502 didn't compile for me, with a non-trivial error, 4.3.0-r7 doesn't support 2.6 kernels, so I had to use a ~x86 version (on an otherwise stable x86 system))

All modules are loaded in the correct order and with no error messages whatsoever:

```
# grep -v '#' /etc/modules.autoload.d/kernel-2.6

agpgart

via-agp

drm

radeon

```

```
# lsmod | egrep "radeon|agp"

radeon                115296  0

drm                    74968  1 radeon

via_agp                 8320  0

agpgart                29644  2 drm,via_agp

```

```
# # (After booting the system, before starting X:

# dmesg | egrep -i "error|fail|warn|unable|cannot|fatal"

#

```

X.org: x11-base/xorg-x11-7.0-r

```
# emerge -pv xorg-server xorg-x11

[ebuild   R   ] x11-base/xorg-server-1.0.2-r7  USE="dri -debug -ipv6 -minimal -xprint" 0 kB

[ebuild   R   ] x11-base/xorg-x11-7.0-r1  USE="-3dfx" INPUT_DEVICES="keyboard mouse [-*] " VIDEO_CARDS="radeon vesa [-*]" 0 kB

```

/etc/X11/xorg.conf: (relevant parts only)

```
Section "Module"

    :

    Load        "glx"   # libglx.a

    Load        "dri"   # libdri.a

    Load        "drm"   # libdrm.a

    :

EndSection

Section "dri"

    Mode 0666

EndSection

Section "Device"

         Identifier      "ATI Radeon 9600"

         Driver          "radeon"

         Option          "AGPMode"              "4"       # As set in BIOS

         Option          "AGPFastWrite"         "false"   # As set in BIOS

         Option          "UseInternalAGPGART"   "no"

         #Option         "RenderAccel"          "on"      # Commented that out to lower complexity for debugging

         BusID           "PCI:1:0:0"                      # As reported by lspci

         Screen 0

EndSection

Section "Screen"

    Identifier  "Screen0"

    Device      "ATI Radeon 9600"

    :

EndSection
```

This is about it. I'm not 100% sure the radeon_cp_init error actually leads to AGP failing, but I pretty much think so. At least, these errors sound very nasty  :Wink:  Also, the DRI Troubleshooting Guide says, the message 

```
[drm:radeon_cp_init] *ERROR* radeon_cp_init called without lock held
```

 is due to missing agpgart and specific AGP chipset modules. But I compiled and loaded both agpgart and via-agp modules. 

What makes me suspicous, is that the help in menuconfig states that AGP_VIA provides support for "VIA MVP3/Apollo Pro chipsets". But I have neither of those, I have got a VIA K8T800 chipset (VT8385 northbridge). So is the list of supported chipsets for AGP_VIA just not complete, or is my chipset actually not supported? But if so, I should see messages like 

```
agpgart: Unsupported Via chipset (device id: 0282), you might want to try agp_try_unsupported=1.

agpgart: no supported devices found. 
```

 in dmesg, which I don't.

I'm confused, clueless and tired, please help!  :Wink: Last edited by LukasGraf on Thu Jul 06, 2006 1:32 am; edited 2 times in total

----------

## whiskas

Well, it's obvious: the AGP kernel module has no support for your particular chipset, and DRM / DRI is not avaiable without AGP support.

You might want to try a 2.6.17-based kernel (or perhaps the -mm branch), I'm pretty sure they added support for newer VIA northbridges.

----------

## LukasGraf

Which one do you mean by "AGP kernel module"? The generic agpgart module, or the specifc via-agp module?

What you say makes perfect sense for me, but then, why don't I get a "agpgart: Unsupported Via chipset..." message in dmesg? As far as I can tell, agpgart loads fine, without complaining...

Hmm, unstable kernel or -mm sources is not really an option for me, I'd like to run a stable system. Maybe I can find a kernel patch for my VIA nothbridge.

Anyway, thanks for your reply!

----------

## whiskas

Ok, I completely misread you, for which I am very sorry  :Sad: 

Now, back to the problem at hand, I would try the following steps, in order:reemerge x11-base/x11-drm;do not autoload any of the related kernel modules, instead, load only via-agp by hand, then startx as usual; try a newer kernel (kernel.org says that the latest stable version of the Linux kernel is 2.6.17.3).And that's about all I can think of right now...

Edit: it seems that the newest kernel release has quite a few fixes for AGP and RADEON / DRM, so you might just want to give it a shot (including this one).

----------

## gami

Can you please post the output of 

```
lspci -n
```

----------

## LukasGraf

```
# lspci -n

00:00.0 0600: 1106:3188 (rev 01)

00:01.0 0604: 1106:b188

00:07.0 0c00: 1106:3044 (rev 46)

00:0a.0 0200: 11ab:4320 (rev 13)

00:0c.0 0200: 10b7:9200 (rev 78)

00:0f.0 0104: 1106:3149 (rev 80)

00:0f.1 0101: 1106:0571 (rev 06)

00:10.0 0c03: 1106:3038 (rev 81)

00:10.1 0c03: 1106:3038 (rev 81)

00:10.2 0c03: 1106:3038 (rev 81)

00:10.3 0c03: 1106:3038 (rev 81)

00:10.4 0c03: 1106:3104 (rev 86)

00:11.0 0601: 1106:3227

00:11.5 0401: 1106:3059 (rev 60)

00:18.0 0600: 1022:1100

00:18.1 0600: 1022:1101

00:18.2 0600: 1022:1102

00:18.3 0600: 1022:1103

01:00.0 0300: 1002:4150

01:00.1 0380: 1002:4170
```

----------

## LukasGraf

 *whiskas wrote:*   

> Ok, I completely misread you, for which I am very sorry 

 

No problem, I almost thought so  :Wink: 

 *Quote:*   

> Now, back to the problem at hand, I would try the following steps, in order:reemerge x11-base/x11-drm;do not autoload any of the related kernel modules, instead, load only via-agp by hand, then startx as usual; try a newer kernel (kernel.org says that the latest stable version of the Linux kernel is 2.6.17.3).And that's about all I can think of right now...

 

* Reemerged x11-drm

* Loaded modules by hand: First agpgart, then via-agp, drm and at last radeon

Didn't change anything, the error messages in dmesg and Xorg.0.log stay exactly the same.

* Loaded only via-agp by hand (which pulls in agpgart): Still the same result.

New kernel: I'll give it a shot, but I really don't like the idea of running a production system with an unstable kernel. The lastest stable kernel from upstream (kernel.org) isn't necessarily considered stable on gentoo yet. You're right, a lot in the are of AGP / Radeon seems to have changed with new kernels, I'll try a 2.6.17.x, and if it's only to proove that the problem is lying there..  :Wink: Last edited by LukasGraf on Wed Jul 05, 2006 5:15 pm; edited 1 time in total

----------

## gami

 *LukasGraf wrote:*   

> 
> 
> ```
> # lspci -n
> 
> ...

 

This is the entry the via-agp driver looks for. It is defined in linux/pci_ids.h as PCI_DEVICE_ID_VIA_8385_0. In the 2.6.16 series this device is not recognized by via-agp. I have had a similar problem with a different VIA chipset in the past. See this topic for the patch I needed.

You can try to create a similar patch for your chipset. Adding a new agp_device_ids entry to via_agp_device_ids and an ID entry to the agp_via_pci_table in via-agp.c should do the trick.

Once you have the patch working you might want to submit it to the agpgart maintainer Dave Jones.

----------

## LukasGraf

Ahh, this sounds very promising, thank you very much! 

I will take some time to read all the stuff, and try to come up with a patch that works. In case of sucess or failure, I'll report here  :Wink: 

----------

## LukasGraf

Ok, let's call it partial success  :Wink: 

The good thing is, my AGP bridge seems to be recognized by via-agp. The bad thing is, my system locks up when trying to start X...  :Confused: 

This is the patch I applied to linux/drivers/char/agp/via-agp.c:

```
--- /usr/src/linux-2.6.16-gentoo-r9/drivers/char/agp/via-agp.c.orig     2006-07-05 22:38:08.000000000 +0200

+++ /usr/src/linux-2.6.16-gentoo-r9/drivers/char/agp/via-agp.c  2006-07-05 23:42:49.000000000 +0200

@@ -285,6 +285,14 @@

                .chipset_name   = "KT266/KY266x/KT333",

        },

+

+        /* VT8385 */

+        {

+                .device_id      = PCI_DEVICE_ID_VIA_8385_0,

+                .chipset_name   = "K8T800",

+        },

+

+

        /* VT8633 (for CuMine/ Celeron) */

        {

                .device_id      = PCI_DEVICE_ID_VIA_8653_0,

@@ -501,6 +509,7 @@

        ID(PCI_DEVICE_ID_VIA_8363_0),

        ID(PCI_DEVICE_ID_VIA_8753_0),

        ID(PCI_DEVICE_ID_VIA_8367_0),

+       ID(PCI_DEVICE_ID_VIA_8385_0),

        ID(PCI_DEVICE_ID_VIA_8653_0),

        ID(PCI_DEVICE_ID_VIA_XM266),

        ID(PCI_DEVICE_ID_VIA_862X_0),
```

When loading the patched via-agp module, dmesg now gives me

```
Linux agpgart interface v0.101 (c) Dave Jones

agpgart: Detected VIA K8T800 chipset

agpgart: AGP aperture is 64M @ 0xf0000000
```

instead of just the first line. Yay!   :Smile: 

K8T800 is probably the .chipset_name I chose, but the apterture size is definitely correct. It is set to 64MB, and when I change it in the BIOS settings to 128MB, it shows up here. Nice  :Very Happy: 

However, starting X results in the system locking up completely (the power button is also dead). But hey, that means we're now at least accessing hardware, right?  :Wink: 

Xorg.0.log contains this: (From the beginning of the DRM stuff to EOF)

```
[drm] Initialized drm 1.0.1 20051102

ACPI: PCI Interrupt 0000:01:00.0[A] -> GSI 16 (level, low) -> IRQ 16

[drm] Initialized radeon 1.25.0 20060524 on minor 0: 

[drm] Used old pci detect: framebuffer loaded

(II) RADEON(0): [drm] DRM interface version 1.2

(II) RADEON(0): [drm] created "radeon" driver at busid "pci:0000:01:00.0"

(II) RADEON(0): [drm] added 8192 byte SAREA at 0xe1887000

(II) RADEON(0): [drm] mapped SAREA 0xe1887000 to 0xb7925000

(II) RADEON(0): [drm] framebuffer handle = 0xd0000000

(II) RADEON(0): [drm] added 1 reserved context for kernel

(II) RADEON(0): [agp] Mode 0x1f000a09 [AGP 0x1106/0x3188; Card 0x1002/0x4150]

(II) RADEON(0): [agp] 8192 kB allocated with handle 0x00000001

(II) RADEON(0): [agp] ring handle = 0xf0000000

(II) RADEON(0): [agp] Ring mapped at 0xa76e9000

(II) RADEON(0): [agp] ring read ptr handle = 0xf0101000

(II) RADEON(0): [agp] Ring read ptr mapped at 0xa76e8000

(II) RADEON(0): [agp] vertex/indirect buffers handle = 0xf0102000

(II) RADEON(0): [agp] Vertex/indirect buffers mapped at 0xa74e8000

(II) RADEON(0): [agp] GART texture map handle = 0xf0302000

(II) RADEON(0): [agp] GART Texture map mapped at 0xa7008000

(II) RADEON(0): [drm] register handle = 0xfd200000

(II) RADEON(0): [dri] Visual configs initialized

(**) RADEON(0): DRI New memory map param

(**) RADEON(0): RADEONInitMemoryMap() : 

(**) RADEON(0):   mem_size         : 0x10000000

(**) RADEON(0):   agp_size         : 0x000006b8

(**) RADEON(0):   agp_base         : 0xb7e52a20

(**) RADEON(0):   MC_FB_LOCATION   : 0xdfffd000

(**) RADEON(0):   MC_AGP_LOCATION  : 0xffffffc0

(**) RADEON(0): RADEONModeInit()

1280x1024     135.00  1280 1296 1440 1688  1024 1025 1028 1066 (24,32) +H +V

1280x1024     135.00  1280 1296 1440 1688  1024 1025 1028 1066 (24,32) +H +V

(**) RADEON(0): Pitch = 10485920 bytes (virtualX = 1280, displayWidth = 1280)

(**) RADEON(0): dc=13500, of=27000, fd=120, pd=2

(**) RADEON(0): RADEONInit returns 0x821b770

(**) RADEON(0): RADEONRestoreMode()

(**) RADEON(0): RADEONRestoreMode(0x821b770)

(**) RADEON(0): RADEONRestoreMemMapRegisters() : 

(**) RADEON(0):   MC_FB_LOCATION   : 0xdfffd000

(**) RADEON(0):   MC_AGP_LOCATION  : 0xffffffc0

(**) RADEON(0):   Map Changed ! Applying ...
```

Looks quite ok to me so far, it seems that the problem occurs while applying the map. But... which map? To what?

In order to get X up again, I tried to unload via-agp:

```
# rmmod via-agp
```

Oops:   :Wink: 

```
Oops: 0000 [#1]

PREEMPT SMP 

Modules linked in: radeon drm via_agp agpgart snd_pcm_oss snd_mixer_oss snd_seq_oss snd_seq_midi_event snd_seq snd_via82xx snd_mpu401_uart snd_rawmidi snd_seq_device snd_intel8x0 snd_ac97_codec snd_ac97_bus snd_pcm snd_timer snd snd_page_alloc

CPU:    0

EIP:    0060:[<e18f04c2>]    Not tainted VLI

EFLAGS: 00010246   (2.6.16-gentoo-r9 #5) 

EIP is at drm_lastclose+0x82/0x400 [drm]

eax: 00000000   ebx: fffffff4   ecx: 00000000   edx: df3ae8dc

esi: 00000001   edi: e1956780   ebp: df3ae800   esp: d8cfdf04

ds: 007b   es: 007b   ss: 0068

Process rmmod (pid: 10304, threadinfo=d8cfc000 task=c1645580)

Stack: <0>df3ae95c 00000000 00000880 df3ae800 00000001 e1956780 00000880 e18f7a35 

       df3ae800 c025736e dfe9b0e8 df3ae800 e18f7c3e df3ae800 d8cfdf44 e1956f00 

       00000000 00000000 e194e86f e1956780 c013ba4c e1956f00 00000880 d8cfdf64 

Call Trace:

 [<e18f7a35>] drm_cleanup+0x25/0x1c0 [drm]

 [<c025736e>] kobject_put+0x1e/0x30

 [<e18f7c3e>] drm_exit+0x6e/0xc0 [drm]

 [<e194e86f>] radeon_exit+0xf/0x172 [radeon]

 [<c013ba4c>] sys_delete_module+0x18c/0x1c0

 [<c015714f>] do_munmap+0x11f/0x180

 [<c0157201>] sys_munmap+0x51/0x80

 [<c0103105>] syscall_call+0x7/0xb

Code: 09 00 00 8d 85 5c 01 00 00 89 04 24 e8 b8 98 83 de 8b 55 00 85 d2 0f 85 1b 02 00 00 8b 85 dc 00 00 00 8d 95 dc 00 00 00 8d 58 f4 <8b> 7b 0c 89 54 24 08 83 ef 0c 39 d0 74 46 8d b5 cc 00 00 00 89 
```

Doesn't tell me much. drm_lastclose() is defined in linux-2.6.16-gentoo-r9/drivers/char/drm/drm_drv.c, but I have no idea what is going wrong here.

Thanks a lot for the help so far, I still think this is progress  :Wink: 

----------

## LukasGraf

[SOLVED]

Phew! After my own attempt of a patch to via-agp.c did not work out too well, I thought I'd look if there maybe is already some working being done on this in the 2.6.17 tree. But I found nothing, so I googled if there is any use of the PCI_DEVICE_ID_VIA_8385_0 somewhere at all. And yes there is, in the amd64-agp module. This module seems to use the on-CPU northbridge of AMD64 processors for GART. Which is fine for me, I've got an Athlon64 and a supported AGP bridge (which is still needed).

So, although there is a VIA chipset present, I don't want to use it, so I disable it, and use the amd64-agp module (not the AMD irongate stuff):

```
<M> /dev/agpgart (AGP Support)

< >     AMD Irongate, 761, and 762 chipset support

<M>     AMD Opteron/Athlon64 on-CPU GART support

< >     VIA chipset support

```

Update /etc/modules.autoload.d/kernel-2.6:

```
agpgart

amd64-agp

drm

radeon

```

Now, the addional kernel messages from dmesg look reeeally friendly   :Wink: :

```
agpgart: Found an AGP 3.5 compliant device at 0000:00:00.0.

agpgart: Putting AGP V3 device at 0000:00:00.0 into 4x mode

agpgart: Putting AGP V3 device at 0000:01:00.0 into 4x mode

[drm] Setting GART location based on new memory map

[drm] Loading R300 Microcode

[drm] writeback test succeeded in 1 usecs

```

Also Xorg.0.log looks promising:

```
(II) RADEON(0): [drm] DRM interface version 1.2

(II) RADEON(0): [drm] created "radeon" driver at busid "pci:0000:01:00.0"

(II) RADEON(0): [drm] added 8192 byte SAREA at 0xe1887000

(II) RADEON(0): [drm] mapped SAREA 0xe1887000 to 0xb78c6000

(II) RADEON(0): [drm] framebuffer handle = 0xd0000000

(II) RADEON(0): [drm] added 1 reserved context for kernel

(II) RADEON(0): [agp] Mode 0x1f000a09 [AGP 0x1106/0x3188; Card 0x1002/0x4150]

(II) RADEON(0): [agp] 8192 kB allocated with handle 0x00000001

(II) RADEON(0): [agp] ring handle = 0xf0000000

(II) RADEON(0): [agp] Ring mapped at 0xa768a000

(II) RADEON(0): [agp] ring read ptr handle = 0xf0101000

(II) RADEON(0): [agp] Ring read ptr mapped at 0xb78c5000

(II) RADEON(0): [agp] vertex/indirect buffers handle = 0xf0102000

(II) RADEON(0): [agp] Vertex/indirect buffers mapped at 0xa748a000

(II) RADEON(0): [agp] GART texture map handle = 0xf0302000

(II) RADEON(0): [agp] GART Texture map mapped at 0xa6faa000

(II) RADEON(0): [drm] register handle = 0xfd200000

(II) RADEON(0): [dri] Visual configs initialized

...

(**) RADEON(0):   Map Changed ! Applying ...

(**) RADEON(0):   Map applied, resetting engine ...

...

(II) RADEON(0): [drm] installed DRM signal handler

(II) RADEON(0): [DRI] installation complete

...

(II) RADEON(0): Direct rendering enabled

```

Sounds good. But when I check with glxinfo, also Xorg says "enabled", I get "direct rendering: no":

```
# glxinfo | grep "direct rendering"

direct rendering: No

```

So I enabled verbose debugging output for libGLand ran glxinfo again:

```
# export LIBGL_VERBOSE="" LIBGL_DEBUG=""

# glxinfo

name of display: :0.0

libGL error: dlopen /usr/lib//modules/dri/r300_dri.so failed (/usr/lib//modules/dri/r300_dri.so: cannot open shared object file: No such file or directory)

...

```

Hmm.. r300_dri.so exists, but in /usr/lib/xorg... So I just symlinked it, and that seems to do the trick:

```

euklid ~ # ln /usr/lib/xorg/modules/dri/r300_dri.so /usr/lib/modules/dri/r300_dri.so

euklid ~ # glxinfo | grep "direct rendering"

direct rendering: Yes

```

glxgears immediately shows the effect of the change: From ~150fps before to ~1200fps after  :Very Happy: 

Thanks for the help guys!

----------

