1 /* 2 * Copyright © 2015 Broadcom 3 * 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. 7 */ 8 9 /* DOC: VC4 GEM BO management support. 10 * 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. 15 */ 16 17 #include "vc4_drv.h" 18 19 struct vc4_bo *vc4_bo_create(struct drm_device *dev, size_t size) 20 { 21 struct drm_gem_cma_object *cma_obj; 22 23 cma_obj = drm_gem_cma_create(dev, size); 24 if (IS_ERR(cma_obj)) 25 return NULL; 26 else 27 return to_vc4_bo(&cma_obj->base); 28 } 29 30 int vc4_dumb_create(struct drm_file *file_priv, 31 struct drm_device *dev, 32 struct drm_mode_create_dumb *args) 33 { 34 int min_pitch = DIV_ROUND_UP(args->width * args->bpp, 8); 35 struct vc4_bo *bo = NULL; 36 int ret; 37 38 if (args->pitch < min_pitch) 39 args->pitch = min_pitch; 40 41 if (args->size < args->pitch * args->height) 42 args->size = args->pitch * args->height; 43 44 bo = vc4_bo_create(dev, roundup(args->size, PAGE_SIZE)); 45 if (!bo) 46 return -ENOMEM; 47 48 ret = drm_gem_handle_create(file_priv, &bo->base.base, &args->handle); 49 drm_gem_object_unreference_unlocked(&bo->base.base); 50 51 return ret; 52 } 53