xref: /aosp_15_r20/external/libdrm/man/drm-memory.7.rst (revision 7688df22e49036ff52a766b7101da3a49edadb8c)
1*7688df22SAndroid Build Coastguard Worker==========
2*7688df22SAndroid Build Coastguard Workerdrm-memory
3*7688df22SAndroid Build Coastguard Worker==========
4*7688df22SAndroid Build Coastguard Worker
5*7688df22SAndroid Build Coastguard Worker---------------------
6*7688df22SAndroid Build Coastguard WorkerDRM Memory Management
7*7688df22SAndroid Build Coastguard Worker---------------------
8*7688df22SAndroid Build Coastguard Worker
9*7688df22SAndroid Build Coastguard Worker:Date: September 2012
10*7688df22SAndroid Build Coastguard Worker:Manual section: 7
11*7688df22SAndroid Build Coastguard Worker:Manual group: Direct Rendering Manager
12*7688df22SAndroid Build Coastguard Worker
13*7688df22SAndroid Build Coastguard WorkerSynopsis
14*7688df22SAndroid Build Coastguard Worker========
15*7688df22SAndroid Build Coastguard Worker
16*7688df22SAndroid Build Coastguard Worker``#include <xf86drm.h>``
17*7688df22SAndroid Build Coastguard Worker
18*7688df22SAndroid Build Coastguard WorkerDescription
19*7688df22SAndroid Build Coastguard Worker===========
20*7688df22SAndroid Build Coastguard Worker
21*7688df22SAndroid Build Coastguard WorkerMany modern high-end GPUs come with their own memory managers. They even
22*7688df22SAndroid Build Coastguard Workerinclude several different caches that need to be synchronized during access.
23*7688df22SAndroid Build Coastguard WorkerTextures, framebuffers, command buffers and more need to be stored in memory
24*7688df22SAndroid Build Coastguard Workerthat can be accessed quickly by the GPU. Therefore, memory management on GPUs
25*7688df22SAndroid Build Coastguard Workeris highly driver- and hardware-dependent.
26*7688df22SAndroid Build Coastguard Worker
27*7688df22SAndroid Build Coastguard WorkerHowever, there are several frameworks in the kernel that are used by more than
28*7688df22SAndroid Build Coastguard Workerone driver. These can be used for trivial mode-setting without requiring
29*7688df22SAndroid Build Coastguard Workerdriver-dependent code. But for hardware-accelerated rendering you need to read
30*7688df22SAndroid Build Coastguard Workerthe manual pages for the driver you want to work with.
31*7688df22SAndroid Build Coastguard Worker
32*7688df22SAndroid Build Coastguard WorkerDumb-Buffers
33*7688df22SAndroid Build Coastguard Worker------------
34*7688df22SAndroid Build Coastguard Worker
35*7688df22SAndroid Build Coastguard WorkerAlmost all in-kernel DRM hardware drivers support an API called *Dumb-Buffers*.
36*7688df22SAndroid Build Coastguard WorkerThis API allows to create buffers of arbitrary size that can be used for
37*7688df22SAndroid Build Coastguard Workerscanout. These buffers can be memory mapped via **mmap**\ (2) so you can render
38*7688df22SAndroid Build Coastguard Workerinto them on the CPU. However, GPU access to these buffers is often not
39*7688df22SAndroid Build Coastguard Workerpossible. Therefore, they are fine for simple tasks but not suitable for
40*7688df22SAndroid Build Coastguard Workercomplex compositions and renderings.
41*7688df22SAndroid Build Coastguard Worker
42*7688df22SAndroid Build Coastguard WorkerThe ``DRM_IOCTL_MODE_CREATE_DUMB`` ioctl can be used to create a dumb buffer.
43*7688df22SAndroid Build Coastguard WorkerThe kernel will return a 32-bit handle that can be used to manage the buffer
44*7688df22SAndroid Build Coastguard Workerwith the DRM API. You can create framebuffers with **drmModeAddFB**\ (3) and
45*7688df22SAndroid Build Coastguard Workeruse it for mode-setting and scanout. To access the buffer, you first need to
46*7688df22SAndroid Build Coastguard Workerretrieve the offset of the buffer. The ``DRM_IOCTL_MODE_MAP_DUMB`` ioctl
47*7688df22SAndroid Build Coastguard Workerrequests the DRM subsystem to prepare the buffer for memory-mapping and returns
48*7688df22SAndroid Build Coastguard Workera fake-offset that can be used with **mmap**\ (2).
49*7688df22SAndroid Build Coastguard Worker
50*7688df22SAndroid Build Coastguard WorkerThe ``DRM_IOCTL_MODE_CREATE_DUMB`` ioctl takes as argument a structure of type
51*7688df22SAndroid Build Coastguard Worker``struct drm_mode_create_dumb``:
52*7688df22SAndroid Build Coastguard Worker
53*7688df22SAndroid Build Coastguard Worker::
54*7688df22SAndroid Build Coastguard Worker
55*7688df22SAndroid Build Coastguard Worker   struct drm_mode_create_dumb {
56*7688df22SAndroid Build Coastguard Worker       __u32 height;
57*7688df22SAndroid Build Coastguard Worker       __u32 width;
58*7688df22SAndroid Build Coastguard Worker       __u32 bpp;
59*7688df22SAndroid Build Coastguard Worker       __u32 flags;
60*7688df22SAndroid Build Coastguard Worker
61*7688df22SAndroid Build Coastguard Worker       __u32 handle;
62*7688df22SAndroid Build Coastguard Worker       __u32 pitch;
63*7688df22SAndroid Build Coastguard Worker       __u64 size;
64*7688df22SAndroid Build Coastguard Worker   };
65*7688df22SAndroid Build Coastguard Worker
66*7688df22SAndroid Build Coastguard WorkerThe fields *height*, *width*, *bpp* and *flags* have to be provided by the
67*7688df22SAndroid Build Coastguard Workercaller. The other fields are filled by the kernel with the return values.
68*7688df22SAndroid Build Coastguard Worker*height* and *width* are the dimensions of the rectangular buffer that is
69*7688df22SAndroid Build Coastguard Workercreated. *bpp* is the number of bits-per-pixel and must be a multiple of 8. You
70*7688df22SAndroid Build Coastguard Workermost commonly want to pass 32 here. The flags field is currently unused and
71*7688df22SAndroid Build Coastguard Workermust be zeroed. Different flags to modify the behavior may be added in the
72*7688df22SAndroid Build Coastguard Workerfuture. After calling the ioctl, the handle, pitch and size fields are filled
73*7688df22SAndroid Build Coastguard Workerby the kernel. *handle* is a 32-bit gem handle that identifies the buffer. This
74*7688df22SAndroid Build Coastguard Workeris used by several other calls that take a gem-handle or memory-buffer as
75*7688df22SAndroid Build Coastguard Workerargument. The *pitch* field is the pitch (or stride) of the new buffer. Most
76*7688df22SAndroid Build Coastguard Workerdrivers use 32-bit or 64-bit aligned stride-values. The size field contains the
77*7688df22SAndroid Build Coastguard Workerabsolute size in bytes of the buffer. This can normally also be computed with
78*7688df22SAndroid Build Coastguard Worker``(height * pitch + width) * bpp / 4``.
79*7688df22SAndroid Build Coastguard Worker
80*7688df22SAndroid Build Coastguard WorkerTo prepare the buffer for **mmap**\ (2) you need to use the
81*7688df22SAndroid Build Coastguard Worker``DRM_IOCTL_MODE_MAP_DUMB`` ioctl. It takes as argument a structure of type
82*7688df22SAndroid Build Coastguard Worker``struct drm_mode_map_dumb``:
83*7688df22SAndroid Build Coastguard Worker
84*7688df22SAndroid Build Coastguard Worker::
85*7688df22SAndroid Build Coastguard Worker
86*7688df22SAndroid Build Coastguard Worker   struct drm_mode_map_dumb {
87*7688df22SAndroid Build Coastguard Worker       __u32 handle;
88*7688df22SAndroid Build Coastguard Worker       __u32 pad;
89*7688df22SAndroid Build Coastguard Worker
90*7688df22SAndroid Build Coastguard Worker       __u64 offset;
91*7688df22SAndroid Build Coastguard Worker   };
92*7688df22SAndroid Build Coastguard Worker
93*7688df22SAndroid Build Coastguard WorkerYou need to put the gem-handle that was previously retrieved via
94*7688df22SAndroid Build Coastguard Worker``DRM_IOCTL_MODE_CREATE_DUMB`` into the *handle* field. The *pad* field is
95*7688df22SAndroid Build Coastguard Workerunused padding and must be zeroed. After completion, the *offset* field will
96*7688df22SAndroid Build Coastguard Workercontain an offset that can be used with **mmap**\ (2) on the DRM
97*7688df22SAndroid Build Coastguard Workerfile-descriptor.
98*7688df22SAndroid Build Coastguard Worker
99*7688df22SAndroid Build Coastguard WorkerIf you don't need your dumb-buffer, anymore, you have to destroy it with
100*7688df22SAndroid Build Coastguard Worker``DRM_IOCTL_MODE_DESTROY_DUMB``. If you close the DRM file-descriptor, all open
101*7688df22SAndroid Build Coastguard Workerdumb-buffers are automatically destroyed. This ioctl takes as argument a
102*7688df22SAndroid Build Coastguard Workerstructure of type ``struct drm_mode_destroy_dumb``:
103*7688df22SAndroid Build Coastguard Worker
104*7688df22SAndroid Build Coastguard Worker::
105*7688df22SAndroid Build Coastguard Worker
106*7688df22SAndroid Build Coastguard Worker   struct drm_mode_destroy_dumb {
107*7688df22SAndroid Build Coastguard Worker       __u32 handle;
108*7688df22SAndroid Build Coastguard Worker   };
109*7688df22SAndroid Build Coastguard Worker
110*7688df22SAndroid Build Coastguard WorkerYou only need to put your handle into the *handle* field. After this call, the
111*7688df22SAndroid Build Coastguard Workerhandle is invalid and may be reused for new buffers by the dumb-API.
112*7688df22SAndroid Build Coastguard Worker
113*7688df22SAndroid Build Coastguard WorkerTTM
114*7688df22SAndroid Build Coastguard Worker---
115*7688df22SAndroid Build Coastguard Worker
116*7688df22SAndroid Build Coastguard Worker*TTM* stands for *Translation Table Manager* and is a generic memory-manager
117*7688df22SAndroid Build Coastguard Workerprovided by the kernel. It does not provide a common user-space API so you need
118*7688df22SAndroid Build Coastguard Workerto look at each driver interface if you want to use it. See for instance the
119*7688df22SAndroid Build Coastguard Workerradeon man pages for more information on memory-management with radeon and TTM.
120*7688df22SAndroid Build Coastguard Worker
121*7688df22SAndroid Build Coastguard WorkerGEM
122*7688df22SAndroid Build Coastguard Worker---
123*7688df22SAndroid Build Coastguard Worker
124*7688df22SAndroid Build Coastguard Worker*GEM* stands for *Graphics Execution Manager* and is a generic DRM
125*7688df22SAndroid Build Coastguard Workermemory-management framework in the kernel, that is used by many different
126*7688df22SAndroid Build Coastguard Workerdrivers. GEM is designed to manage graphics memory, control access to the
127*7688df22SAndroid Build Coastguard Workergraphics device execution context and handle essentially NUMA environment
128*7688df22SAndroid Build Coastguard Workerunique to modern graphics hardware. GEM allows multiple applications to share
129*7688df22SAndroid Build Coastguard Workergraphics device resources without the need to constantly reload the entire
130*7688df22SAndroid Build Coastguard Workergraphics card. Data may be shared between multiple applications with gem
131*7688df22SAndroid Build Coastguard Workerensuring that the correct memory synchronization occurs.
132*7688df22SAndroid Build Coastguard Worker
133*7688df22SAndroid Build Coastguard WorkerGEM provides simple mechanisms to manage graphics data and control execution
134*7688df22SAndroid Build Coastguard Workerflow within the linux DRM subsystem. However, GEM is not a complete framework
135*7688df22SAndroid Build Coastguard Workerthat is fully driver independent. Instead, if provides many functions that are
136*7688df22SAndroid Build Coastguard Workershared between many drivers, but each driver has to implement most of
137*7688df22SAndroid Build Coastguard Workermemory-management with driver-dependent ioctls. This manpage tries to describe
138*7688df22SAndroid Build Coastguard Workerthe semantics (and if it applies, the syntax) that is shared between all
139*7688df22SAndroid Build Coastguard Workerdrivers that use GEM.
140*7688df22SAndroid Build Coastguard Worker
141*7688df22SAndroid Build Coastguard WorkerAll GEM APIs are defined as **ioctl**\ (2) on the DRM file descriptor. An
142*7688df22SAndroid Build Coastguard Workerapplication must be authorized via **drmAuthMagic**\ (3) to the current
143*7688df22SAndroid Build Coastguard WorkerDRM-Master to access the GEM subsystem. A driver that does not support GEM will
144*7688df22SAndroid Build Coastguard Workerreturn ``ENODEV`` for all these ioctls. Invalid object handles return
145*7688df22SAndroid Build Coastguard Worker``EINVAL`` and invalid object names return ``ENOENT``.
146*7688df22SAndroid Build Coastguard Worker
147*7688df22SAndroid Build Coastguard WorkerGem provides explicit memory management primitives. System pages are allocated
148*7688df22SAndroid Build Coastguard Workerwhen the object is created, either as the fundamental storage for hardware
149*7688df22SAndroid Build Coastguard Workerwhere system memory is used by the graphics processor directly, or as backing
150*7688df22SAndroid Build Coastguard Workerstore for graphics-processor resident memory.
151*7688df22SAndroid Build Coastguard Worker
152*7688df22SAndroid Build Coastguard WorkerObjects are referenced from user-space using handles. These are, for all
153*7688df22SAndroid Build Coastguard Workerintents and purposes, equivalent to file descriptors but avoid the overhead.
154*7688df22SAndroid Build Coastguard WorkerNewer kernel drivers also support the **drm-prime** (7) infrastructure which
155*7688df22SAndroid Build Coastguard Workercan return real file-descriptor for GEM-handles using the linux DMA-BUF API.
156*7688df22SAndroid Build Coastguard WorkerObjects may be published with a name so that other applications and processes
157*7688df22SAndroid Build Coastguard Workercan access them. The name remains valid as long as the object exists.
158*7688df22SAndroid Build Coastguard WorkerGEM-objects are reference counted in the kernel. The object is only destroyed
159*7688df22SAndroid Build Coastguard Workerwhen all handles from user-space were closed.
160*7688df22SAndroid Build Coastguard Worker
161*7688df22SAndroid Build Coastguard WorkerGEM-buffers cannot be created with a generic API. Each driver provides its own
162*7688df22SAndroid Build Coastguard WorkerAPI to create GEM-buffers. See for example ``DRM_I915_GEM_CREATE``,
163*7688df22SAndroid Build Coastguard Worker``DRM_NOUVEAU_GEM_NEW`` or ``DRM_RADEON_GEM_CREATE``. Each of these ioctls
164*7688df22SAndroid Build Coastguard Workerreturns a GEM-handle that can be passed to different generic ioctls. The
165*7688df22SAndroid Build Coastguard Worker*libgbm* library from the *mesa3D* distribution tries to provide a
166*7688df22SAndroid Build Coastguard Workerdriver-independent API to create GBM buffers and retrieve a GBM-handle to them.
167*7688df22SAndroid Build Coastguard WorkerIt allows to create buffers for different use-cases including scanout,
168*7688df22SAndroid Build Coastguard Workerrendering, cursors and CPU-access. See the libgbm library for more information
169*7688df22SAndroid Build Coastguard Workeror look at the driver-dependent man-pages (for example **drm-intel**\ (7) or
170*7688df22SAndroid Build Coastguard Worker**drm-radeon**\ (7)).
171*7688df22SAndroid Build Coastguard Worker
172*7688df22SAndroid Build Coastguard WorkerGEM-buffers can be closed with **drmCloseBufferHandle**\ (3). It takes as
173*7688df22SAndroid Build Coastguard Workerargument the GEM-handle to be closed. After this call the GEM handle cannot be
174*7688df22SAndroid Build Coastguard Workerused by this process anymore and may be reused for new GEM objects by the GEM
175*7688df22SAndroid Build Coastguard WorkerAPI.
176*7688df22SAndroid Build Coastguard Worker
177*7688df22SAndroid Build Coastguard WorkerIf you want to share GEM-objects between different processes, you can create a
178*7688df22SAndroid Build Coastguard Workername for them and pass this name to other processes which can then open this
179*7688df22SAndroid Build Coastguard WorkerGEM-object. Names are currently 32-bit integer IDs and have no special
180*7688df22SAndroid Build Coastguard Workerprotection. That is, if you put a name on your GEM-object, every other client
181*7688df22SAndroid Build Coastguard Workerthat has access to the DRM device and is authenticated via
182*7688df22SAndroid Build Coastguard Worker**drmAuthMagic**\ (3) to the current DRM-Master, can *guess* the name and open
183*7688df22SAndroid Build Coastguard Workeror access the GEM-object. If you want more fine-grained access control, you can
184*7688df22SAndroid Build Coastguard Workeruse the new **drm-prime**\ (7) API to retrieve file-descriptors for
185*7688df22SAndroid Build Coastguard WorkerGEM-handles. To create a name for a GEM-handle, you use the
186*7688df22SAndroid Build Coastguard Worker``DRM_IOCTL_GEM_FLINK`` ioctl. It takes as argument a structure of type
187*7688df22SAndroid Build Coastguard Worker``struct drm_gem_flink``:
188*7688df22SAndroid Build Coastguard Worker
189*7688df22SAndroid Build Coastguard Worker::
190*7688df22SAndroid Build Coastguard Worker
191*7688df22SAndroid Build Coastguard Worker   struct drm_gem_flink {
192*7688df22SAndroid Build Coastguard Worker       __u32 handle;
193*7688df22SAndroid Build Coastguard Worker       __u32 name;
194*7688df22SAndroid Build Coastguard Worker   };
195*7688df22SAndroid Build Coastguard Worker
196*7688df22SAndroid Build Coastguard WorkerYou have to put your handle into the *handle* field. After completion, the
197*7688df22SAndroid Build Coastguard Workerkernel has put the new unique name into the name field. You can now pass
198*7688df22SAndroid Build Coastguard Workerthis name to other processes which can then import the name with the
199*7688df22SAndroid Build Coastguard Worker``DRM_IOCTL_GEM_OPEN`` ioctl. It takes as argument a structure of type
200*7688df22SAndroid Build Coastguard Worker``struct drm_gem_open``:
201*7688df22SAndroid Build Coastguard Worker
202*7688df22SAndroid Build Coastguard Worker::
203*7688df22SAndroid Build Coastguard Worker
204*7688df22SAndroid Build Coastguard Worker   struct drm_gem_open {
205*7688df22SAndroid Build Coastguard Worker       __u32 name;
206*7688df22SAndroid Build Coastguard Worker
207*7688df22SAndroid Build Coastguard Worker       __u32 handle;
208*7688df22SAndroid Build Coastguard Worker       __u32 size;
209*7688df22SAndroid Build Coastguard Worker   };
210*7688df22SAndroid Build Coastguard Worker
211*7688df22SAndroid Build Coastguard WorkerYou have to fill in the *name* field with the name of the GEM-object that you
212*7688df22SAndroid Build Coastguard Workerwant to open. The kernel will fill in the *handle* and *size* fields with the
213*7688df22SAndroid Build Coastguard Workernew handle and size of the GEM-object. You can now access the GEM-object via
214*7688df22SAndroid Build Coastguard Workerthe handle as if you created it with the GEM API.
215*7688df22SAndroid Build Coastguard Worker
216*7688df22SAndroid Build Coastguard WorkerBesides generic buffer management, the GEM API does not provide any generic
217*7688df22SAndroid Build Coastguard Workeraccess. Each driver implements its own functionality on top of this API. This
218*7688df22SAndroid Build Coastguard Workerincludes execution-buffers, GTT management, context creation, CPU access, GPU
219*7688df22SAndroid Build Coastguard WorkerI/O and more. The next higher-level API is *OpenGL*. So if you want to use more
220*7688df22SAndroid Build Coastguard WorkerGPU features, you should use the *mesa3D* library to create OpenGL contexts on
221*7688df22SAndroid Build Coastguard WorkerDRM devices. This does *not* require any windowing-system like X11, but can
222*7688df22SAndroid Build Coastguard Workeralso be done on raw DRM devices. However, this is beyond the scope of this
223*7688df22SAndroid Build Coastguard Workerman-page. You may have a look at other mesa3D man pages, including libgbm and
224*7688df22SAndroid Build Coastguard WorkerlibEGL. 2D software-rendering (rendering with the CPU) can be achieved with the
225*7688df22SAndroid Build Coastguard Workerdumb-buffer-API in a driver-independent fashion, however, for
226*7688df22SAndroid Build Coastguard Workerhardware-accelerated 2D or 3D rendering you must use OpenGL. Any other API that
227*7688df22SAndroid Build Coastguard Workertries to abstract the driver-internals to access GEM-execution-buffers and
228*7688df22SAndroid Build Coastguard Workerother GPU internals, would simply reinvent OpenGL so it is not provided. But if
229*7688df22SAndroid Build Coastguard Workeryou need more detailed information for a specific driver, you may have a look
230*7688df22SAndroid Build Coastguard Workerinto the driver-manpages, including **drm-intel**\ (7), **drm-radeon**\ (7) and
231*7688df22SAndroid Build Coastguard Worker**drm-nouveau**\ (7). However, the **drm-prime**\ (7) infrastructure and the
232*7688df22SAndroid Build Coastguard Workergeneric GEM API as described here allow display-managers to handle
233*7688df22SAndroid Build Coastguard Workergraphics-buffers and render-clients without any deeper knowledge of the GPU
234*7688df22SAndroid Build Coastguard Workerthat is used. Moreover, it allows to move objects between GPUs and implement
235*7688df22SAndroid Build Coastguard Workercomplex display-servers that don't do any rendering on their own. See its
236*7688df22SAndroid Build Coastguard Workerman-page for more information.
237*7688df22SAndroid Build Coastguard Worker
238*7688df22SAndroid Build Coastguard WorkerExamples
239*7688df22SAndroid Build Coastguard Worker========
240*7688df22SAndroid Build Coastguard Worker
241*7688df22SAndroid Build Coastguard WorkerThis section includes examples for basic memory-management tasks.
242*7688df22SAndroid Build Coastguard Worker
243*7688df22SAndroid Build Coastguard WorkerDumb-Buffers
244*7688df22SAndroid Build Coastguard Worker------------
245*7688df22SAndroid Build Coastguard Worker
246*7688df22SAndroid Build Coastguard WorkerThis examples shows how to create a dumb-buffer via the generic DRM API.
247*7688df22SAndroid Build Coastguard WorkerThis is driver-independent (as long as the driver supports dumb-buffers)
248*7688df22SAndroid Build Coastguard Workerand provides memory-mapped buffers that can be used for scanout. This
249*7688df22SAndroid Build Coastguard Workerexample creates a full-HD 1920x1080 buffer with 32 bits-per-pixel and a
250*7688df22SAndroid Build Coastguard Workercolor-depth of 24 bits. The buffer is then bound to a framebuffer which
251*7688df22SAndroid Build Coastguard Workercan be used for scanout with the KMS API (see **drm-kms**\ (7)).
252*7688df22SAndroid Build Coastguard Worker
253*7688df22SAndroid Build Coastguard Worker::
254*7688df22SAndroid Build Coastguard Worker
255*7688df22SAndroid Build Coastguard Worker   struct drm_mode_create_dumb creq;
256*7688df22SAndroid Build Coastguard Worker   struct drm_mode_destroy_dumb dreq;
257*7688df22SAndroid Build Coastguard Worker   struct drm_mode_map_dumb mreq;
258*7688df22SAndroid Build Coastguard Worker   uint32_t fb;
259*7688df22SAndroid Build Coastguard Worker   int ret;
260*7688df22SAndroid Build Coastguard Worker   void *map;
261*7688df22SAndroid Build Coastguard Worker
262*7688df22SAndroid Build Coastguard Worker   /* create dumb buffer */
263*7688df22SAndroid Build Coastguard Worker   memset(&creq, 0, sizeof(creq));
264*7688df22SAndroid Build Coastguard Worker   creq.width = 1920;
265*7688df22SAndroid Build Coastguard Worker   creq.height = 1080;
266*7688df22SAndroid Build Coastguard Worker   creq.bpp = 32;
267*7688df22SAndroid Build Coastguard Worker   ret = drmIoctl(fd, DRM_IOCTL_MODE_CREATE_DUMB, &creq);
268*7688df22SAndroid Build Coastguard Worker   if (ret < 0) {
269*7688df22SAndroid Build Coastguard Worker       /* buffer creation failed; see "errno" for more error codes */
270*7688df22SAndroid Build Coastguard Worker       ...
271*7688df22SAndroid Build Coastguard Worker   }
272*7688df22SAndroid Build Coastguard Worker   /* creq.pitch, creq.handle and creq.size are filled by this ioctl with
273*7688df22SAndroid Build Coastguard Worker    * the requested values and can be used now. */
274*7688df22SAndroid Build Coastguard Worker
275*7688df22SAndroid Build Coastguard Worker   /* create framebuffer object for the dumb-buffer */
276*7688df22SAndroid Build Coastguard Worker   ret = drmModeAddFB(fd, 1920, 1080, 24, 32, creq.pitch, creq.handle, &fb);
277*7688df22SAndroid Build Coastguard Worker   if (ret) {
278*7688df22SAndroid Build Coastguard Worker       /* frame buffer creation failed; see "errno" */
279*7688df22SAndroid Build Coastguard Worker       ...
280*7688df22SAndroid Build Coastguard Worker   }
281*7688df22SAndroid Build Coastguard Worker   /* the framebuffer "fb" can now used for scanout with KMS */
282*7688df22SAndroid Build Coastguard Worker
283*7688df22SAndroid Build Coastguard Worker   /* prepare buffer for memory mapping */
284*7688df22SAndroid Build Coastguard Worker   memset(&mreq, 0, sizeof(mreq));
285*7688df22SAndroid Build Coastguard Worker   mreq.handle = creq.handle;
286*7688df22SAndroid Build Coastguard Worker   ret = drmIoctl(fd, DRM_IOCTL_MODE_MAP_DUMB, &mreq);
287*7688df22SAndroid Build Coastguard Worker   if (ret) {
288*7688df22SAndroid Build Coastguard Worker       /* DRM buffer preparation failed; see "errno" */
289*7688df22SAndroid Build Coastguard Worker       ...
290*7688df22SAndroid Build Coastguard Worker   }
291*7688df22SAndroid Build Coastguard Worker   /* mreq.offset now contains the new offset that can be used with mmap() */
292*7688df22SAndroid Build Coastguard Worker
293*7688df22SAndroid Build Coastguard Worker   /* perform actual memory mapping */
294*7688df22SAndroid Build Coastguard Worker   map = mmap(0, creq.size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, mreq.offset);
295*7688df22SAndroid Build Coastguard Worker   if (map == MAP_FAILED) {
296*7688df22SAndroid Build Coastguard Worker       /* memory-mapping failed; see "errno" */
297*7688df22SAndroid Build Coastguard Worker       ...
298*7688df22SAndroid Build Coastguard Worker   }
299*7688df22SAndroid Build Coastguard Worker
300*7688df22SAndroid Build Coastguard Worker   /* clear the framebuffer to 0 */
301*7688df22SAndroid Build Coastguard Worker   memset(map, 0, creq.size);
302*7688df22SAndroid Build Coastguard Worker
303*7688df22SAndroid Build Coastguard WorkerReporting Bugs
304*7688df22SAndroid Build Coastguard Worker==============
305*7688df22SAndroid Build Coastguard Worker
306*7688df22SAndroid Build Coastguard WorkerBugs in this manual should be reported to
307*7688df22SAndroid Build Coastguard Workerhttps://gitlab.freedesktop.org/mesa/drm/-/issues
308*7688df22SAndroid Build Coastguard Worker
309*7688df22SAndroid Build Coastguard WorkerSee Also
310*7688df22SAndroid Build Coastguard Worker========
311*7688df22SAndroid Build Coastguard Worker
312*7688df22SAndroid Build Coastguard Worker**drm**\ (7), **drm-kms**\ (7), **drm-prime**\ (7), **drmAvailable**\ (3),
313*7688df22SAndroid Build Coastguard Worker**drmOpen**\ (3), **drm-intel**\ (7), **drm-radeon**\ (7), **drm-nouveau**\ (7)
314