# Need help in developing Asus Xonar Essence ST driver



## SchwarzerVossatka (Jun 21, 2014)

Hello. I've recently found this (https://github.com/polachok/xonar-freebsd/) driver for a family of "Asus Xonar" sound cards. Currently only Asus Xonar Essence STX is supported, but I want ST, so I made this patch: http://pastebin.com/Qb8BWPEN ,  according to an OSS driver (http://sourceforge.net/p/opensound/merc ... _cmi878x.c). The system detects the card and can direct sound output both to line out and headphones (the card produces a mechanical "click" sound in process), but there is no playback.

If I remove (#if 0/#endif) here


```
+#if 0
+               pcm1796_write(sc, XONAR_ST_CLOCK, 0x5, 0x8);
+               pcm1796_write(sc, XONAR_ST_CLOCK, 0x2, 0x0);
+               pcm1796_write(sc, XONAR_ST_CLOCK, 0x5, 0x1);
+#endif
```

the system will panic. These lines of code correspond to cs2000_init () function from OSS driver. Crash dump looks like:


```
> kgdb kernel vmcore.3 
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "amd64-marcel-freebsd"...

Unread portion of the kernel message buffer:
pcm0: <Asus Xonar Essence ST (AV100)> port 0xe800-0xe8ff irq 21 at device 6.0 on pci6
pcm0: AC97 codec0 found
pcm0: MPU401 found
can't re-use a leaf (buffersize)!
pcm0: channel0 (Multichannel)


Fatal trap 9: general protection fault while in kernel mode
cpuid = 1; apic id = 11
instruction pointer     = 0x20:0xffffffff80d30552
stack pointer           = 0x28:0xfffffe023a736160
frame pointer           = 0x28:0xfffffe023a7361b0
code segment            = base 0x0, limit 0xfffff, type 0x1b
                        = DPL 0, pres 1, long 1, def32 0, gran 1
processor eflags        = interrupt enabled, resume, IOPL = 0
current process         = 1536 (kldload)
trap number             = 9
panic: general protection fault
cpuid = 1
KDB: stack backtrace:
#0 0xffffffff808826b0 at kdb_backtrace+0x60
#1 0xffffffff8084a145 at panic+0x155
#2 0xffffffff80c345e2 at trap_fatal+0x3a2
#3 0xffffffff80c3421f at trap+0x7bf
#4 0xffffffff80c1b2e2 at calltrap+0x8
#5 0xffffffff82978066 at sndbuf_alloc+0x46
#6 0xffffffff8296c677 at xonar_chan_init+0x157
#7 0xffffffff8297b10b at chn_init+0x3ab
#8 0xffffffff8298954f at pcm_chn_create+0x27f
#9 0xffffffff82989859 at pcm_addchan+0x59
#10 0xffffffff8296bc84 at xonar_attach+0xab4
#11 0xffffffff80879b22 at device_attach+0x3a2
#12 0xffffffff8062330a at pci_driver_added+0xfa
#13 0xffffffff80877d0d at devclass_driver_added+0x7d
#14 0xffffffff80877c6c at devclass_add_driver+0x11c
#15 0xffffffff80835aab at module_register_init+0xfb
#16 0xffffffff8082b36e at linker_load_module+0xb6e
#17 0xffffffff8082c577 at kern_kldload+0xc7
Uptime: 1h29m45s
Dumping 705 out of 8139 MB:..3%..12%..21%..32%..41%..53%..62%..71%..82%..91%

Reading symbols from /boot/kernel/sem.ko.symbols...done.
Loaded symbols for /boot/kernel/sem.ko.symbols
Reading symbols from /boot/modules/nvidia.ko...done.
Loaded symbols for /boot/modules/nvidia.ko
Reading symbols from /boot/modules/vboxdrv.ko...done.
Loaded symbols for /boot/modules/vboxdrv.ko
Reading symbols from /boot/kernel/zfs.ko.symbols...done.
Loaded symbols for /boot/kernel/zfs.ko.symbols
Reading symbols from /boot/kernel/opensolaris.ko.symbols...done.
Loaded symbols for /boot/kernel/opensolaris.ko.symbols
Reading symbols from /home/vasily/xonar-freebsd/xonar-dump/snd_xonar.ko...done.
Loaded symbols for /home/vasily/xonar-freebsd/xonar-dump/snd_xonar.ko
Reading symbols from /boot/kernel/sound.ko.symbols...done.
Loaded symbols for /boot/kernel/sound.ko.symbols
#0  doadump (textdump=<value optimized out>) at pcpu.h:219
219     pcpu.h: No such file or directory.
        in pcpu.h
(kgdb) bt
#0  doadump (textdump=<value optimized out>) at pcpu.h:219
#1  0xffffffff80849dc0 in kern_reboot (howto=260) at /usr/src/sys/kern/kern_shutdown.c:447
#2  0xffffffff8084a184 in panic (fmt=<value optimized out>) at /usr/src/sys/kern/kern_shutdown.c:754
#3  0xffffffff80c345e2 in trap_fatal (frame=<value optimized out>, eva=<value optimized out>) at /usr/src/sys/amd64/amd64/trap.c:882
#4  0xffffffff80c3421f in trap (frame=<value optimized out>) at /usr/src/sys/amd64/amd64/trap.c:224
#5  0xffffffff80c1b2e2 in calltrap () at /usr/src/sys/amd64/amd64/exception.S:232
#6  0xffffffff80d30552 in bus_dmamem_alloc (dmat=0xffff00003df63500, vaddr=0xfffff8017fa5d408, flags=5, mapp=0xfffff8017fa5d478) at /usr/src/sys/x86/x86/busdma_machdep.c:505
#7  0xffffffff82978066 in sndbuf_alloc (b=0xfffff8017fa5d400, dmatag=<value optimized out>, dmaflags=<value optimized out>, size=<value optimized out>) at /usr/src/sys/modules/sound/sound/../../../dev/sound/pcm/buffer.c:101
#8  0xffffffff8296c677 in xonar_chan_setformat () from /home/vasily/xonar-freebsd/xonar-dump/snd_xonar.ko
#9  0x000000013a736230 in ?? ()
#10 0xfffff8017f75ea90 in ?? ()
#11 0xfffff8017f75ea90 in ?? ()
#12 0xfffff80008fc2c00 in ?? ()
#13 0xfffff8017fa5d400 in ?? ()
#14 0xfffff8017fa5d400 in ?? ()
#15 0x0000000000000001 in ?? ()
#16 0xfffff8017fa5d000 in ?? ()
#17 0xfffffe023a736270 in ?? ()
#18 0xffffffff8297b10b in chn_init (c=0xfffff8017f75ea00, devinfo=0xfffff8017f75ea90, dir=<value optimized out>, direction=0) at channel_if.h:29
Previous frame identical to this frame (corrupt stack?)
Current language:  auto; currently minimal
(kgdb) frame 6
#6  0xffffffff80d30552 in bus_dmamem_alloc (dmat=0xffff00003df63500, vaddr=0xfffff8017fa5d408, flags=5, mapp=0xfffff8017fa5d478) at /usr/src/sys/x86/x86/busdma_machdep.c:505
505             if (flags & BUS_DMA_NOWAIT)
(kgdb) q
```

It turns out that panic is caused by this line:


```
pcm1796_write(sc, XONAR_ST_CLOCK, 0x2, 0x0);
```

I can't understand what is going on here. Here you can download my kernel/crash dump/module: https://drive.google.com/file/d/0B1NArWn4pLpxcDlVSDBpZEE3YkU/edit?usp=sharing

Can anyone make a suggestion what I am doing wrong?


----------

