DRI for the FreeRunner

This project is about implementing direct rendering for the Openmoko Neo FreeRunner phone, with its SMedia Glamo3362 graphics accelerator. At the moment, the X server (Xglamo or xf86-video-glamo) takes control of the graphics chip's command queue and most of its memory, meaning that other applications can't use any of its features outside of the small set of operations which can be accelerated via X. With direct rendering, we will have a well-defined system to share access to the chip, enabling cooperation between the X server and programs using features such as hardware MPEG decoding or 3D graphics.

Technical Details

This is a DRI2 driver with KMS for a piece of fixed-function (i.e. no programmable pipeline) hardware. We use a GEM kernel interface for handling static buffers in VRAM. All command queue access is done via the kernel. 3D support is based on the Git head of Mesa, with periodic rebases to the latest.  2D acceleration is implemented using EXA. There will perhaps be the possibility to use Glamo's video decoding hardware via something like VDPAU or VAAPI.

The Xorg driver, xf86-video-glamo, is really two drivers rolled into one.  At a very early stage of initialisation, it detects whether the kernel supports KMS or not, and uses to the older fbdev-style driver if not.  If KMS is available, you get the whole DRI2-enabled environment and all the benefits of low-level fencing, and so on.

Status

The kernel work is mostly done.  It has interfaces for creating, destroying and mmapping buffers of VRAM, and allows userspace to submit command sequences to Glamo without knowing the actual addresses of the objects.  The accelerated X.org driver based on KMS, which allows X to make use of the new kernel interfaces for managing memory and command queue access, works apart from lacking xrandr.  DRI2 buffer swapping works, and Mesa can submit geometry via vertex buffers, but there isn't enough of the shader pipeline working that this can be tested.

Branch drm-tracking is based on the older 2.6.29 kernel, and branch gdrm-2.6.32 is based on the newer one.  2.6.32 is where the development work is done at the moment.

If you'd like to get involved, it's worth noting that the hardest part of development is figuring out the internals of KMS, Mesa and DRI. So far, handling the hardware hasn't been particularly difficult.

Repositories

Kernel: git://git.openmoko.org/git/kernel.git (branch gdrm-2.6.32 or drm-tracking)
DDX: git://git.openmoko.org/git/xf86-video-glamo.git (branch kms)
libdrm: git://git.bitwiz.org.uk/libdrm.git (branch glamo)
Unit tests: git://git.bitwiz.org.uk/glamo-dri-tests.git (branch master)
Mesa: git://git.bitwiz.org.uk/mesa.git (branch glamo)

Installing Glamo-DRI

This is reasonably simple in recent distributions: SHR now includes all the userspace parts by default, so you only have to compile and install a KMS kernel to get the benefits.  If you're running SHR, skip to step 6 now.  If you're running another distribution that doesn't yet have these bits, the steps 1-5 briefly describe how to compile them.  There used to be an elaborate description of how to set up OpenEmbedded for this here, but it fell out of date since JaMa's awesome work means that I don't have to worry about integrating the system and can just concentrate on the code.  This is a really really good thing, but unfortunately it means that you'll have to work out how these instructions relate to your cross-compilation environment yourself.

1. Build libdrm

Check out libdrm from the repository (see above), configure with --enable-glamo-experimental-api, compile and install.

2. Build Mesa

This has to be done before compiling the Xorg server, so that Xorg can detect that the right bits are available for GLX.  Just grab Mesa from the repository (see above), and configure with something like --disable-glx-tls --with-driver=dri --with-dri-drivers=swrast,glamo.  Then install.

3. Build the X server

Use the latest Xorg server from git.freedesktop.org.

4. Build xf86-video-glamo

Grab the latest xf86-video-glamo from here or git.openmoko.org, and configure with --enable-kms.  Compile and install.

5. Build the test programs (optional)

Check out the glamo-dri-tests repository and just run "make" then "make install".  The Makefile is very simple and can be modified as needed.

6. Compile and Install the Kernel

Download the Openmoko kernel source from git.openmoko.org, check out the gdrm-2.6.32 branch, and build. Build instructions are here. Use your own choice of configuration but answer y to "Direct Rendering Manager" (DRM) and "Glamo DRM Support" (MFD_GLAMO_DRM).

You can also use the older "drm-tracking" branch based on the 2.6.29 kernel.  It's know to have WSoDs for many people though.  Development work is focused on 2.6.32 currently.

Don't forget to install the modules to the FreeRunner before flashing the kernel image, otherwise bad stuff might happen (depending on your configuration).

7. Fire it Up

That's it. To test KMS, close down your old X server, if it's running, with something like this:

$ /etc/init.d/xserver-nodm stop

If you installed the Glamo DRI tests, now is a good time to try the KMS and GEM mmapping test:

$ gdrm-kms-addfb

Each time you press "Enter", the screen should change colour.  The rate at which this happens is the infamous speed of the bus to Glamo - that should give you an idea of what the "Glamo factor" really looks like.

Now restart the X server:

$ /etc/init.d/xserver-nodm start

And try some easy things like:

$ DISPLAY=:0 LIBGL_DEBUG=verbose glxinfo
$ DISPLAY=:0 LIBGL_DEBUG=verbose glxdemo

The old demos, "gdri-cmdq-submission" and "gdri-mem-manager" are no longer useful.