|
| 1 | +############### |
| 2 | +SGX Build Guide |
| 3 | +############### |
| 4 | + |
| 5 | +The graphics stack on SGX has been frozen. The last major change occured in |
| 6 | +release 09.01. This will capture the build process and some of the caviots of |
| 7 | +this legacy driver. |
| 8 | + |
| 9 | +This driver has been reworked as part of the kernel 6.1 support effort to mimic |
| 10 | +the build and structure of rogue. The stack consists of 3 main components with |
| 11 | +varying classifications: |
| 12 | + |
| 13 | + - The kernel module (KM) (Open Source, but out-of-tree) |
| 14 | + - The GLES 2.0 implementation (UM) (Closed Source, binary release) |
| 15 | + - The mesa shim (Open Source, but out-of-tree) |
| 16 | + |
| 17 | +All 3 of these components are required for GLES support. |
| 18 | + |
| 19 | +***************** |
| 20 | +SGX Kernel Module |
| 21 | +***************** |
| 22 | + |
| 23 | +The kernel module is responsible for: |
| 24 | + |
| 25 | + - Memory and power management |
| 26 | + - Monitoring device state |
| 27 | + - Orchestrating hardware recoveries |
| 28 | + - Creating an interface for the userspace server |
| 29 | + |
| 30 | +The source for the component is available at: |
| 31 | + |
| 32 | + https://git.ti.com/cgit/graphics/omap5-sgx-ddk-linux |
| 33 | + |
| 34 | +Building the SGX Kernel Module |
| 35 | +============================== |
| 36 | + |
| 37 | +The latest branch contains the most bugfixes and has been adapted for the widest |
| 38 | +general compatibility in modern applications. This is |
| 39 | +``1.17.4948957/mesa/k6.1``, and despite being tagged for kernel 6.1 it is also |
| 40 | +interoperable with kernel 6.6. |
| 41 | + |
| 42 | +The :file:`INSTALL` file gives a brief overview of how to build and install the |
| 43 | +module. This gives you the common variables, but it does leave out some of the |
| 44 | +more important ones for the build. The following variables are key and *must* |
| 45 | +match with the values used in the UM release: |
| 46 | + |
| 47 | + - ``BUILD`` -- Options: ``release`` or ``debug`` |
| 48 | + - ``PVR_BUILD_DIR`` -- Options: ``<platform>_linux``, for example ``ti572x_linux`` |
| 49 | + - ``WINDOW_SYSTEM`` -- Options: ``lws-generic``, ``xorg``, ``wayland``, ... |
| 50 | + |
| 51 | +These variables must be set for the build. To check for updated build variables |
| 52 | +please see the ``EXTRA_OEMAKE`` variable in the `ti-sgx-ddk-km recipe in |
| 53 | +meta-ti`_. This will always contain the latest required variables to compile the |
| 54 | +driver. |
| 55 | + |
| 56 | +.. _ti-sgx-ddk-km recipe in meta-ti: https://git.ti.com/cgit/arago-project/meta-ti/tree/meta-ti-bsp/recipes-bsp/powervr-drivers/ti-sgx-ddk-km_1.17.4948957.bb |
| 57 | + |
| 58 | +As previously mentioned these build options must match with the corresponding UM |
| 59 | +build options. Currently we only release binaries with ``BUILD=release`` and |
| 60 | +``WINDOW_SYSTEM=lws-generic``. The UM section will go previous exceptions |
| 61 | +to this. |
| 62 | + |
| 63 | +************************ |
| 64 | +SGX Userspace Components |
| 65 | +************************ |
| 66 | + |
| 67 | +The proprietary userspace components are required for all interactions with the |
| 68 | +GPU. It contains the firmware, GLES implementation, and the primary control |
| 69 | +server. Unlike rogue, the firmware is packaged as part of the control sever |
| 70 | +library. |
| 71 | + |
| 72 | +The binary release for this component is available at: |
| 73 | + |
| 74 | + https://git.ti.com/cgit/graphics/omap5-sgx-ddk-um-linux |
| 75 | + |
| 76 | +Installing the SGX Userspace Components |
| 77 | +======================================= |
| 78 | + |
| 79 | +The repository contains binaries for each platform in release specific branches. |
| 80 | +The newest release, which matches with the above mentioned kernel module branch |
| 81 | +is ``1.17.4948957/mesa/glibc-2.35``. This branch deviates from the existing |
| 82 | +naming pattern to indicate that unlike previous releases it required a new |
| 83 | +version of mesa and was linked against glibc-2.35. |
| 84 | + |
| 85 | +In the repository the following structure can be seen: |
| 86 | + |
| 87 | +.. code-block:: text |
| 88 | +
|
| 89 | + . |
| 90 | + ├── LICENSE |
| 91 | + ├── Makefile |
| 92 | + ├── README.md |
| 93 | + └── targetfs |
| 94 | + ├── common |
| 95 | + │ ├── 50-pvrsrvctl.rules.template |
| 96 | + │ ├── etc |
| 97 | + │ └── pvrsrvctl.service.template |
| 98 | + ├── ti335x_linux |
| 99 | + │ └── lws-generic |
| 100 | + ├── ti343x_linux |
| 101 | + │ └── lws-generic |
| 102 | + ├── ti437x_linux |
| 103 | + │ └── lws-generic |
| 104 | + ├── ti443x_linux |
| 105 | + │ └── lws-generic |
| 106 | + ├── ti572x_linux |
| 107 | + │ └── lws-generic |
| 108 | + └── ti654x_linux |
| 109 | + └── lws-generic |
| 110 | +
|
| 111 | +Under the :file:`targetfs` directory there is a subdirectory for each |
| 112 | +``PVR_BUILD_DIR`` build variable. Under that directory is a subdirectory |
| 113 | +corresponding to the ``WINDOW_SYSTEM`` build variable. Finally, under that |
| 114 | +directory is a subdirectory corresponding to the ``BUILD`` build variable. |
| 115 | + |
| 116 | +This is reflected in the :file:`Makefile` as: |
| 117 | + |
| 118 | +.. code-block:: Makefile |
| 119 | +
|
| 120 | + PRODUCTDIR := ./targetfs/${TARGET_PRODUCT}/${WINDOW_SYSTEM}/${BUILD} |
| 121 | +
|
| 122 | +The :file:`Makefile` simply unpacks this directory structure and installs the |
| 123 | +corresponding files into ``DESTDIR`` in the install step. Do not worry about the |
| 124 | +clean step, as this is used for development. |
| 125 | + |
| 126 | +Unlike rogue, there is an additional :file:`common` directory that contains |
| 127 | +startup script templates. These templates are automatically modified by the |
| 128 | +:file:`Makefile` as part of the install step. |
| 129 | + |
| 130 | +These are not strictly required, but you will need to manually start the device |
| 131 | +with :command:`pvrsrvctl` if you choose not to use these templates. Please note |
| 132 | +that this binary is, and always has been brittle. It likely will not realize |
| 133 | +what kernel you are running so you should specify ``--no-module`` when |
| 134 | +interacting with it. |
| 135 | + |
| 136 | +******************* |
| 137 | +SGX Mesa Components |
| 138 | +******************* |
| 139 | + |
| 140 | +Mesa, at this point in time, is a collection of GFX tools and utilities for |
| 141 | +setting up and interacting with rendering contexts. It contains everything from |
| 142 | +a DRI "megadriver" to full GLES/GL implementations. If you're interested in |
| 143 | +learning GFX under Linux it's worth familiarizing yourself with everything else |
| 144 | +it provides. |
| 145 | + |
| 146 | +For us, the important part is that DRI "megadriver." This is the mechanism used |
| 147 | +to determine what GLES / GL implementation is picked when you bind one of the |
| 148 | +previously mentioned API to a EGL context. This is also where things get tricky. |
| 149 | + |
| 150 | +Historically there has been some issues with embedded GFX because, unlike your |
| 151 | +standard PC GPU, we tend to mix and match actual Graphics Processing Units and |
| 152 | +Display Controllers. The megadriver uses the display device name to coordinate |
| 153 | +between API implementations. As such, we need a shim to act as a DRI driver and |
| 154 | +coordinate the link with the SGX GLES implementation. |
| 155 | + |
| 156 | +This shim, currently, is provided in the form of a Gallium Frontend. This is the |
| 157 | +main reason for the fork and the 60 odd patches we carry at the following repo: |
| 158 | + |
| 159 | + https://gitlab.freedesktop.org/StaticRocket/mesa |
| 160 | + |
| 161 | +There are also other nice-to-have features there such as additional pixel |
| 162 | +formats, minor fixups, and a few performance tweaks IMG have picked up over the |
| 163 | +years, but the main reason we need it is for that shim. |
| 164 | + |
| 165 | +Building the SGX Mesa Components |
| 166 | +================================ |
| 167 | + |
| 168 | +We recommend following the `Mesa build guide`_ for general options. Right now |
| 169 | +the mesa components use a standard interface that allows you to pick any |
| 170 | +``powervr/*`` branch equal to or greater than ``22.3.5``. |
| 171 | + |
| 172 | +The only necessary build options are: |
| 173 | + |
| 174 | + - ``-Dgallium-drivers=sgx`` -- This is a comma separated list, just make sure |
| 175 | + sgx is present in it. |
| 176 | + |
| 177 | + - ``-Dgallium-sgx-alias=`` -- This should match the display controller you |
| 178 | + want to bind to. This can either be ``tilcdc``, ``tidss``, or ``omapdrm`` |
| 179 | + depending on the device. |
| 180 | + |
| 181 | +This will produce 3 important files relevant to the shim mechanism we discussed |
| 182 | +earlier: |
| 183 | + |
| 184 | + - :file:`sgx_dri.so` -- Main DRI interface |
| 185 | + |
| 186 | + - :file:`pvr_dri.so` -- GPU interface that points back to :file:`sgx_dri.so`. |
| 187 | + This is required in the case an application attempts to interact with the |
| 188 | + GPU directly because the DRI device is still registered with the name |
| 189 | + ``pvr``. |
| 190 | + |
| 191 | + - :file:`<display>_dri.so` -- Display controller interface that points back |
| 192 | + at :file:`sgx_dri.so`. Will be named after the value specified with |
| 193 | + ``-Dgallium-sgx-alias``. |
| 194 | + |
| 195 | +******************* |
| 196 | +Using the SGX Stack |
| 197 | +******************* |
| 198 | + |
| 199 | +Assuming you're using the SDK or you've built and installed the above correctly, |
| 200 | +you should see a message similar to the following in :command:`dmesg` after the |
| 201 | +kernel module is loaded: |
| 202 | + |
| 203 | +.. code-block:: dmesg |
| 204 | +
|
| 205 | + [ 17.344567] [drm] Initialized pvr 1.17.4948957 20110701 for 56000000.gpu on minor 1 |
| 206 | +
|
| 207 | +If the module loads but does not detect the device, make sure your device tree |
| 208 | +has defined the node properly, corresponding to one of the values of |
| 209 | +``powervr_id_table`` in the :file:`services4/srvkm/env/linux/module.c`. |
| 210 | + |
| 211 | +Upon starting the userspace daemon you should see the following message: |
| 212 | + |
| 213 | +.. code-block:: dmesg |
| 214 | +
|
| 215 | + [ 29.277564] PVR_K: UM DDK-(4948957) and KM DDK-(4948957) match. [ OK ] |
| 216 | +
|
| 217 | +You should now be able to issue a simple test. We recommend |
| 218 | +:command:`glmark2-es2-drm`. You should see the following indicating you are |
| 219 | +using the correct driver: |
| 220 | + |
| 221 | +.. code-block:: console |
| 222 | +
|
| 223 | + root@am335x-evm:~# glmark2-es2-drm |
| 224 | + MESA: info: Loaded libpvr_dri_support.so |
| 225 | + ======================================================= |
| 226 | + glmark2 2021.12 |
| 227 | + ======================================================= |
| 228 | + OpenGL Information |
| 229 | + GL_VENDOR: Imagination Technologies |
| 230 | + GL_RENDERER: PowerVR SGX 530 |
| 231 | + GL_VERSION: OpenGL ES 2.0 build 1.17@4948957 |
| 232 | + ======================================================= |
| 233 | +
|
| 234 | +The ``GL_VENDOR`` should report ``Imagination Technologies`` with the renderer |
| 235 | +corresponding to the graphics processor in that device. |
| 236 | + |
| 237 | +.. _Mesa build guide: https://docs.mesa3d.org/install.html |
| 238 | + |
0 commit comments