Annotation of wikisrc/tutorials/x11/how_to_use_wsfb_uefi_bios_framebuffer.md, revision 1.2

1.2     ! nia         1: [[[!meta title="How to use Xorg's wsfb display driver with a UEFI/BIOS framebuffer, and change its resolution"]]
        !             2: 
1.1       nia         3: How to use Xorg's wsfb display driver with a UEFI/BIOS framebuffer, and change its resolution
                      4: =============================================================================================
                      5: 
                      6: ### Background
                      7: [wsfb(4)](https://man.netbsd.org/wsfb.4) is the Xorg graphics driver for the NetBSD [wsdisplay(4)](https://man.netbsd.org/wsdisplay.4) framebuffer device. `wsdisplay(4)`, similar to Linux's `/dev/fb` devices, provide access to _non-accelerated_ framebuffers, which are provided by _almost all_ modern cards. Most, if not all, _modern_ graphics cards provide what's called a _linear_ framebuffer: a chunk of memory where contiguous address locations map onto adjacent (X, Y) _pixels_. For example, assuming a 32 bits-per-pixel colour depth display, memory location `fbmem + 0` will hold the pixel at position (0,0); `fbmem + 4` corresponds to the pixel at (1, 0), and so on. (We'll skip the complication known as `stride` or `line_length` here.)
                      8: 
                      9: `wsdisplay(4)` can run on top of: 
                     10: 
                     11: 1. `genfb(4)`, the Generic PCI VGA framebuffer device (provided by UEFI or BIOS on x86), and other simple software framebuffers provided by hardware or firmware (e.g. simplefb on ARM)
                     12: 2. the accelerated [`drm(4)`](https://man.netbsd.org/drm.4) graphics devices (in `/dev/dri/card?`--which `wsfb` will use as a plain framebuffer).
                     13: 
                     14: ### Using `wsfb`
                     15: ### Step 1: Configuring `Xorg`
                     16: Use this `wsfb.conf` Xorg config fragment:
                     17:  
                     18: ```
                     19: Section "Device"
                     20:        Identifier  "Card0"
                     21:        Driver      "wsfb"
                     22: EndSection
                     23: ```
                     24: 
                     25: That is all that is needed. Xorg will autoconfigure everything else. Make sure you dump the `wsfb.conf` file into the correct Xorg config. directory. `/etc/X11/xorg.conf.d/` is the correct location for the Xorg in base. If you've installed the `modular-xorg` package, then the path will need change. Use this command to find your `config directory`:
                     26: ```
                     27: $ fgrep directory /var/log/Xorg.0.log
                     28: [    72.697] (==) Using config directory: "/usr/local/etc/X11/xorg.conf.d"
                     29: [    72.697] (==) Using system config directory "/usr/local/share/X11/xorg.conf.d"
                     30: ```
                     31: 
                     32: If your DRM kernel driver has loaded OK and is active, then it will have configured your graphics card with the best resolution for your screen and you can just run `X` right away (this wil be X with `wsfb` on `drmkms`, minus the DRM-provided accelerations). You don't need Step 2.
                     33: 
                     34: If you don't have a DRM driver, or if you can't load it, then if you start `X` now, you'll most probably get the bog-standard 1024x768x32 screen resolution provided by `genfb`, which might be OK, but, is not ideal. As the `wsfb`/`wsdisplay`/`genfb` combo. doesn't let you change resolutions on the fly (`xrandr`, for instance, doesn't work), we'll have to set a better resolution elsewhere: in the bootloader.
                     35: 
                     36: ### Step 2: Setting a better display mode.
                     37: Reboot, then at the bootloader menu, choose the option to get to the bootloader prompt. Here, on UEFI systems, we use the `gop` (Graphics Output Protocol) command like this:
                     38: List avaibable video modes first:
                     39: ```
                     40: > gop list
                     41:  0: 1366x768 BGRR pitch 1376 bpp 32
                     42:  1: 640x480 BGRR pitch 640 bpp 32
                     43: *2: 800x600 BGRR pitch 800 bpp 32
                     44:  3: 1024x768 BGRR pitch 1024 bpp 32
                     45: >
                     46: ```
                     47: The `*` indicates the (safe) mode that the bootloader will use by default. Note that on my laptop, mode `0` has a pitch (aka stride) of 1376 pixels. This means that on my graphics card (Asus X202E laptop), the framebuffer is _linear_, but, **not** fully contiguous. The 10 unusable pixels at the end of each row have to taken into account, or else, you'll be treated to a characteristic jagged, streaky display.
                     48: 
                     49: Choose the best mode, which is generally mode `0`:
                     50: ```
                     51: > gop 0
                     52: >
                     53: ```
                     54: The screen resolution will switch immediately. (And hopefully, your display won't go blank, which, these days, usually indicates a graphics card/BIOS/UEFI/whatever that doesn't implement the published standards correctly.)
                     55: 
                     56: If you have/use BIOS instead of UEFI, you can try the `vesa` command instead of `gop`:
                     57: 
                     58: ```
                     59: > vesa list
                     60: ...
                     61: > vesa 0xhhh
                     62: >
                     63: ```
                     64: If the mode you've chosen works, then you can add that `gop 0` or `vesa mode` command to `boot.cfg` so that it is activated automatically.
                     65: 
                     66: This is what `dmesg` will show, if you've disabled DRM (see below), or don't have it:
                     67: ```
                     68: $ dmesg | fgrep genfb
                     69: [     1.015430] genfb0 at pci0 dev 2 function 0: vendor 8086 product 0166 (rev. 0x09)
                     70: [     1.015430] genfb0: framebuffer at 0xe0000000, size 1366x768, depth 32, stride 5504
                     71: [     1.015430] genfb0: shadow framebuffer enabled, size 4128 KB
                     72: [     1.015430] wsdisplay0 at genfb0 kbdmux 1: console (default, vt100 emulation), using wskbd0
                     73: [     1.015430] drm at genfb0 not configured
                     74: ```
                     75: The resolution, depth and stride are all OK. And inside the Xorg server:
                     76: ```
                     77: $ xdpyinfo | fgrep -B1 -A1 resolution
                     78:   dimensions:    1366x768 pixels (310x174 millimeters)
                     79:   resolution:    112x112 dots per inch
                     80:   depths (7):    24, 1, 4, 8, 15, 16, 32
                     81: $ xrandr
                     82: xrandr: Failed to get size of gamma for output default
                     83: Screen 0: minimum 1366 x 768, current 1366 x 768, maximum 1366 x 768
                     84: default connected 1366x768+0+0 0mm x 0mm
                     85:    1366x768       0.00* 
                     86: $
                     87: ```
                     88: 
                     89: ### Limitations
                     90: 1. No OpenGL hardware acceleration - on x86 and aarch64, llvmpipe (a parallel CPU-based just-in-time renderer) will be used instead
                     91: 2. No X Display Power Management Signaling
                     92: 3. No X video extension (used for accelerated video playback)
                     93: 4. No DRI
                     94: 
                     95: #### Extra: How to disable built-in DRM driver using kernel's `userconf` manager
                     96: 
                     97: For testing, or if running `wsfb` on top of the DRM graphics driver does not work--it mostly should, actually).
                     98: 
                     99: At the bootloader prompt, pass the `-c` flag to the kernel:
                    100: ```
                    101: > boot -c
                    102: ```
                    103: The kernel will display a few lines, then immediately drop into the `userconf` prompt:
                    104: ```
                    105: uc> list                        # list all devs; look for your drmkms entry
                    106: uc> disable i915drmkms          # disable Intel DRM
                    107: uc> quit
                    108: ```
                    109: Once you've determined the device name using `userconf`, or, by trawling through the GENERIC kernel config file, you can disable the device using the bootloader like this:
                    110: ```
                    111: > userconf disable i915drmkms
                    112: ```
                    113: You can of course, add `userconf` commands also to `boot.conf`
                    114: 
                    115: #### Minimal `wsfb(4)` config fragment `/etc/X11/xorg.conf.d/wsfb.conf`
                    116: ```
                    117: Section "Device"
                    118:        Identifier  "Card0"
                    119:        Driver      "wsfb"
                    120: EndSection
                    121: ```
                    122: 
                    123: #### Minimal `wsfb(4)` `/etc/X11/xorg.conf` created using `X -configure`, and then changing the graphics device driver (`Section "Device"`) from `intel` to `wsfb`
                    124: 
                    125: ```
                    126: Section "ServerLayout"
                    127:        Identifier     "X.org Configured"
                    128:        Screen      0  "Screen0" 0 0
                    129:        InputDevice    "Mouse0" "CorePointer"
                    130:        InputDevice    "Keyboard0" "CoreKeyboard"
                    131: EndSection
                    132: 
                    133: Section "Files"
                    134:        ModulePath   "/usr/X11R7/lib/modules"
                    135:        FontPath     "/usr/X11R7/lib/X11/fonts/misc/"
                    136:        FontPath     "/usr/X11R7/lib/X11/fonts/TTF/"
                    137:        FontPath     "/usr/X11R7/lib/X11/fonts/Type1/"
                    138:        FontPath     "/usr/X11R7/lib/X11/fonts/75dpi/"
                    139:        FontPath     "/usr/X11R7/lib/X11/fonts/100dpi/"
                    140: EndSection
                    141: 
                    142: Section "Module"
                    143:        Load  "dri"
                    144:        Load  "dri2"
                    145:        Load  "glx"
                    146:        Load  "shadow"
                    147: EndSection
                    148: 
                    149: Section "InputDevice"
                    150:        Identifier  "Keyboard0"
                    151:        Driver      "kbd"
                    152: EndSection
                    153: 
                    154: Section "InputDevice"
                    155:        Identifier  "Mouse0"
                    156:        Driver      "mouse"
                    157:        Option      "Protocol" "wsmouse"
                    158:        Option      "Device" "/dev/wsmouse"
                    159:        Option      "ZAxisMapping" "4 5 6 7"
                    160: EndSection
                    161: 
                    162: Section "Monitor"
                    163:        Identifier   "Monitor0"
                    164:        VendorName   "Monitor Vendor"
                    165:        ModelName    "Monitor Model"
                    166: EndSection
                    167: 
                    168: Section "Device"
                    169:        Identifier  "Card0"
                    170:        Driver      "wsfb"
                    171: EndSection
                    172: 
                    173: Section "Screen"
                    174:        Identifier "Screen0"
                    175:        Device     "Card0"
                    176:        Monitor    "Monitor0"
                    177:        SubSection "Display"
                    178:                Viewport   0 0
                    179:                Depth     1
                    180:        EndSubSection
                    181:        SubSection "Display"
                    182:                Viewport   0 0
                    183:                Depth     4
                    184:        EndSubSection
                    185:        SubSection "Display"
                    186:                Viewport   0 0
                    187:                Depth     8
                    188:        EndSubSection
                    189:        SubSection "Display"
                    190:                Viewport   0 0
                    191:                Depth     15
                    192:        EndSubSection
                    193:        SubSection "Display"
                    194:                Viewport   0 0
                    195:                Depth     16
                    196:        EndSubSection
                    197:        SubSection "Display"
                    198:                Viewport   0 0
                    199:                Depth     24
                    200:        EndSubSection
                    201: EndSection
                    202: ```

CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb