# How do I unmirror my HDMI display?



## Jay F. Shachter (Jul 22, 2020)

Esteemed Colleagues:

When I connect my laptop to an HDMI device with an HDMI cable, and then boot into FreeBSD 12.1, my two screens are mirrored.  This is sometimes what I want, but sometimes it is not what I want.  I would like to be able to unmirror my screens, as I can do on Linux with `xrandr --output HDMI-0 --right-of eDP` (or words to that effect, I am doing this from memory).  But when I boot into FreeBSD, `xrandr` doesn't even report two different displays.  Instead of reporting either eDP or HDMI-0, it says only 
	
	



```
Screen 0: minimum 1366 x 768, current 1368 x 768, maximum 1368 x 768
```
 On Linux (I have 3 different Linux distributions installed on my laptop -- OpenSuSE, LinuxMint, and a Red Hat clone -- but they all behave the same in this regard), `xrandr` always reports both screens, whether they are mirrored or not, and always reports several modes for each screen.

Also, speaking of my HDMI device (I know this is a different topic, but maybe you can answer this one too), I am unable to access my HDMI audio when I boot my laptop into FreeBSD, or, more precisely, I have not figured out how to access my HDMI audio when I boot my laptop into FreeBSD, which I would like to be able to do because it is of much higher quality than my laptop audio.  `mpv -audio-device=help` lists numerous audio devices and, in particular, lists three different /dev/dsp? devices, but none of those devices is the HDMI device.  `vlc` lists only the three /dev/dsp? devices, and none of them is the HDMI device.  In fact, I have no idea what /dev/dsp0 and /dev/dsp2 are supposed to be; /dev/dsp1 is the laptop builtin speakers and the others two never do anything when I send audio to them.

Speaking of `mpv` (I know this is a second different topic, but maybe you can answer this one too), I invite you to consider an unanswered question that I have had since October 2019, ever since I upgraded to FreeBSD 12.  In a question that I posted to the FreeBSD forums under the title "Colors are messed up when returning to the graphics console from a non-graphics console", I stated that whenever I leave the graphics screen with CTRL-ALT-F? and then return to it, the (I am guessing) colormap changes, and the colors are messed up.  They are so messed up that the only thing to do is log out of the graphics screen, which causes the display manager (`wdm`, but I am sure that makes no difference) to restart the X server.  I could also have mentioned in that October 2019 posting that the exact same thing happens, even without my leaving the graphics screen, whenever my mouse enters an `mplayer` or `mpv` window.  The colors are permanently messed up -- they remain messed up after my mouse leaves the window -- and they are so messed up that there is nothing to do but log out and restart the X server.  `vlc` doesn't do this.  How do I prevent this from happening, or, alternately, how do I minimize the damage (no pun intended, I realize that "damage" is a term of art when speaking to people who work with X windows) by manually saving the colormap and then manually restoring it?

As always, thank you in advance for any and all replies.

                     jay at m5 dot chicago dot il dot us


----------



## wolffnx (Jul 22, 2020)

hi Jay , do you have and nvidia video card installed?

for the audio part you should run
`cat /dev/sndstat`
for example mine output is like this:

```
pcm0: <NVIDIA GTX550 (HDMI/DP 8ch)> (play)
pcm1: <NVIDIA GTX550 (HDMI/DP 8ch)> (play) default
pcm2: <NVIDIA GTX550 (HDMI/DP 8ch)> (play)
pcm3: <NVIDIA GTX550 (HDMI/DP 8ch)> (play)
pcm4: <Realtek ALC887 (Rear Analog)> (play/rec)
pcm5: <Realtek ALC887 (Front Analog)> (play/rec)
No devices installed from userspace.
```

next select the default audio device
`hw.snd.default_unit=1`
in my case I have 2 , the default HDMI(1) and the motherboard one(5)
and done,almost all applications use the default output by default


----------



## Jay F. Shachter (Jul 23, 2020)

According to the output of `pciconf  -lvVc`, I have a Radeon video card:

```
vgapci0@pci0:0:1:0:     class=0x030000 card=0x82f6103c chip=0x98511002 rev=0x40 hdr=0x00
    vendor     = 'Advanced Micro Devices, Inc. [AMD/ATI]'
    device     = 'Mullins [Radeon R4/R5 Graphics]'
    class      = display
    subclass   = VGA
    cap 09[48] = vendor (length 8)
    cap 01[50] = powerspec 3  supports D0 D1 D2 D3  current D0
    cap 10[58] = PCI-Express 2 root endpoint max data 128(256) RO NS
    cap 05[a0] = MSI supports 1 message, 64 bit 
    ecap 000b[100] = Vendor 1 ID 1
    ecap 0019[270] = PCIe Sec 1 lane errors 0
    ecap 000f[2b0] = ATS 1
    ecap 0013[2c0] = unknown 1
    ecap 001b[2d0] = unknown 1
```

One might think that perhaps the HDMI port is treated as another display device, but it is not.  The only appearance of the string "HDMI" in the `pciconf` output refers to the audio HDMI device:


```
hdac0@pci0:0:1:1:       class=0x040300 card=0x82f6103c chip=0x98401002 rev=0x00 hdr=0x00
    vendor     = 'Advanced Micro Devices, Inc. [AMD/ATI]'
    device     = 'Kabini HDMI/DP Audio'
    class      = multimedia
    subclass   = HDA
    cap 09[48] = vendor (length 8)
    cap 01[50] = powerspec 3  supports D0 D1 D2 D3  current D0
    cap 10[58] = PCI-Express 2 root endpoint max data 128(256) RO NS
    cap 05[a0] = MSI supports 1 message, 64 bit enabled with 1 message
    ecap 000b[100] = Vendor 1 ID 1
```

However, the laptop is definitely accessing the HDMI display device, because it is sending it everything that it is sending to the local display.  Nevertheless, `xrandr` only knows about 1 display device, which it calls "Screen 0".

The audio behavior is even more perplexing.  The most facile explanation, the explanation one is tempted to give, is that HDMI output does not work.  But it does work.  It has been empirically tested.  When I boot my laptop into Linux, I have no problem detecting the HDMI audio output, and sending audio to it.  It simply does not work -- yet -- on FreeBSD.

On my FreeBSD system, here is the original output of `cat /dev/sndstat`:

```
Installed devices:
pcm0: <ATI R6xx (HDMI)> (play)
pcm1: <Realtek ALC282 (Analog)> (play/rec) default
pcm2: <Realtek ALC282 (Analog)> (play/rec)
No devices installed from userspace.
```

We see from the above that the system appears to detect an HDMI audio output.  And then, here is the output of `cat /dev/sndstat`, after I do `sysctl hw.snd.default_unit=0`:

```
Installed devices:
pcm0: <ATI R6xx (HDMI)> (play) default
pcm1: <Realtek ALC282 (Analog)> (play/rec)
pcm2: <Realtek ALC282 (Analog)> (play/rec)
No devices installed from userspace.
```

This is, so far, exactly what one would expect.  The problem is that I am still unable (or, hopefully, have not yet figured out how) to send sound to the HDMI device.  The `mpv` command does not change.  It still sends audio to the laptop's builtin, low-quality speakers, despite the `sysctl`.  The `play` command does change.  It is now silent.  Another consequence of the `sysctl` command is that the behavior of `alsamixer` changes.  It now shows only 2 playback columns, and 0 capture columns, as is appropriate for a device that has no capture capabilities.  The 2 playback columns are clearly not muted.  And yet, I cannot send audio output to the HDMI device.

As always, I thank you, and my other esteemed colleagues, in advance, for any and all replies, to any of the 3 questions that I asked in my original posting, which are all, so far, unanswered.


----------



## wolffnx (Jul 23, 2020)

Jay F. Shachter said:


> According to the output of `pciconf  -lvVc`, I have a Radeon video card:
> 
> ```
> vgapci0@pci0:0:1:0:     class=0x030000 card=0x82f6103c chip=0x98511002 rev=0x40 hdr=0x00
> ...


maybe you have to make anothers post for separate problems

if you have a nvidia card, you got a gui configure tool, but for a radeon I am lost

2 tips...you are using OSS in FreeBSD the is not ALSA , and OSS use `mixer` to change volume values
and try another application , like audacious or vlc (after you made the steps above)


----------



## olli@ (Jul 23, 2020)

As a simple test, you can install a command line tool like audio/mpg123 to play an mp3 file. It definitely respects the `sysctl hw.snd.default_unit` setting. The mixer(8) command can be used to change the volume – be sure it’s not set to 0.

HDMI audio output works perfectly fine for me, but my HDMI is on an Nvidia card, not Radeon. Maybe someone else with Radeon can chime in and confirm that it works for him, too.


----------



## Mjölnir (Jul 23, 2020)

Did you install graphics/drm-kmod, sysutils/radeontool & sysutils/radeontop?
Is the _radeonkms_ kernel module loaded? If yes, from /boot/kernel or from /boot/modules?


----------



## Jay F. Shachter (Jul 27, 2020)

I installed those three ports, as you advised.  And I rebooted afterwards.  It made zero difference to any of my three problems.

The `xrandr` command still sees only 1 display:


```
$ xrandr
xrandr: Failed to get size of gamma for output default
Screen 0: minimum 1366 x 768, current 1368 x 768, maximum 1368 x 768
default connected 1368x768+0+0 0mm x 0mm
   1366x768       0.00  
   1368x768       0.00* 
$
```

(The first line is sent to standard error, the remaining lines are sent to standard output.)  It is therefore still impossible to use `xrandr` to unmirror my 2 displays, which remain mirrored.

The contents of /dev/sndstat, the behavior of the `play` (or `mpg123`, as one poster recommended -- it makes no difference), `mpv`, and `alsamixer` commands, and how those things are affected (or unaffected) by various arguments to `sysctl hw.snd.default_unit=`, are completely and utterly unchanged.

Finally, the colors are still hopelessly messed up, whenever I leave the graphics console with CTRL-ALT-F? and then return to it, or whenever I move my mouse into an `mpv` or `mplayer` window.

To answer your question: Yes, radeonkms is loaded.  It think it was always loaded, but I have been explicitly loading it for a long time.  Here is the relevant line from /etc/rc.conf:


```
kld_list="geom_linux_lvm if_rtwn_pci radeonkms"
```

And, of course, the `kldstat` command correctly reports that the module is loaded.


----------



## Mjölnir (Jul 27, 2020)

Jay F. Shachter said:


> [...] To answer your question: Yes, radeonkms is loaded.  It think it was always loaded, but I have been explicitly loading it for a long time.  Here is the relevant line from /etc/rc.conf:
> 
> ```
> kld_list="geom_linux_lvm if_rtwn_pci radeonkms"
> ...


It should be loaded from /boot/modules, not standard /boot/kernel?  You can add to the _ALIAS_ section of /usr/local/etc/pkg.conf

```
message: "query '[%C/%n] %M'",
```
 and read `pkg message drm-fbsd12.0-kmod | less`.  It's a good idea to read through all `pkg message|less`, anyway.


----------



## zeising@ (Aug 4, 2020)

Can you verify that radeonkms actually attaches to the hardware when loading? What does dmesg say? It should not be loaded from the loader, rather add it to kld_list in /etc/rc.conf, or load it manually with kldload.  Make sure you use the full path, /boot/modules/radeonkms.ko, otherwise it will load the old driver in /boot/kernel.
What GPU are you using?


----------

