2 * Copyright © 2015 Broadcom
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
9 /* DOC: VC4 GEM BO management support.
11 * The VC4 GPU architecture (both scanout and rendering) has direct
12 * access to system memory with no MMU in between. To support it, we
13 * use the GEM CMA helper functions to allocate contiguous ranges of
14 * physical memory for our BOs.
19 struct vc4_bo
*vc4_bo_create(struct drm_device
*dev
, size_t size
)
21 struct drm_gem_cma_object
*cma_obj
;
23 cma_obj
= drm_gem_cma_create(dev
, size
);
27 return to_vc4_bo(&cma_obj
->base
);
30 int vc4_dumb_create(struct drm_file
*file_priv
,
31 struct drm_device
*dev
,
32 struct drm_mode_create_dumb
*args
)
34 int min_pitch
= DIV_ROUND_UP(args
->width
* args
->bpp
, 8);
35 struct vc4_bo
*bo
= NULL
;
38 if (args
->pitch
< min_pitch
)
39 args
->pitch
= min_pitch
;
41 if (args
->size
< args
->pitch
* args
->height
)
42 args
->size
= args
->pitch
* args
->height
;
44 bo
= vc4_bo_create(dev
, roundup(args
->size
, PAGE_SIZE
));
48 ret
= drm_gem_handle_create(file_priv
, &bo
->base
.base
, &args
->handle
);
49 drm_gem_object_unreference_unlocked(&bo
->base
.base
);