From patchwork Sat Jun 8 16:55:29 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: James Simmons X-Patchwork-Id: 2692891 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork2.kernel.org (Postfix) with ESMTP id 39B2FDF24C for ; Sat, 8 Jun 2013 17:04:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 31444E6179 for ; Sat, 8 Jun 2013 10:04:02 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) by gabe.freedesktop.org (Postfix) with ESMTP id 095C6E6147; Sat, 8 Jun 2013 09:55:32 -0700 (PDT) Received: from jsimmons (helo=localhost) by casper.infradead.org with local-esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UlMQM-00068m-0H; Sat, 08 Jun 2013 16:55:31 +0000 Date: Sat, 8 Jun 2013 17:55:29 +0100 (BST) From: James Simmons To: DRI development list Subject: [RFC 18/21] DRM: Add VIA drm driver Message-ID: User-Agent: Alpine 2.03 (LFD 1266 2009-07-14) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130608_175530_138934_B95CF401 X-CRM114-Status: GOOD ( 12.41 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on casper.infradead.org summary: Content analysis details: (-1.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 NO_RELAYS Informational: message was not relayed via SMTP -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: OpenChrome Development X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org commit 589665935a7ec7c29103c9ea4eb1d0ffc4b918d5 Author: James Simmons Date: Sat Jun 8 12:15:30 2013 -0400 via: New GEM/TTM kms ioctls New ioctls to allow userland to allocate TTM/GEM buffer objects. Obsolete UMS ioctls. Signed-Off-by: James Simmons diff --git a/drivers/gpu/drm/via/via_ioc32.c b/drivers/gpu/drm/via/via_ioc32.c new file mode 100644 index 0000000..03b8508 --- /dev/null +++ b/drivers/gpu/drm/via/via_ioc32.c @@ -0,0 +1,202 @@ +/* + * Copyright 2006 Tungsten Graphics Inc., Bismarck, ND., USA. + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sub license, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ +/* + * Authors: Thomas Hellström + */ + +#include "drmP.h" +#include "via_drv.h" + +static int +via_getparam(struct drm_device *dev, void *data, + struct drm_file *filp) +{ + struct drm_via_private *dev_priv = dev->dev_private; + struct drm_via_param *args = data; + int ret = 0; + + switch (args->param) { + case VIA_PARAM_CHIPSET_ID: + args->value = dev->pci_device; + break; + case VIA_PARAM_REVISION_ID: + args->value = dev_priv->revision; + break; + default: + ret = -EINVAL; + break; + } + return ret; +} + +/* Not yet supported */ +static int +via_setparam(struct drm_device *dev, void *data, + struct drm_file *filp) +{ + return -EINVAL; +} + +static int +via_gem_alloc(struct drm_device *dev, void *data, + struct drm_file *filp) +{ + struct drm_via_private *dev_priv = dev->dev_private; + struct drm_via_gem_create *args = data; + struct drm_gem_object *obj; + int ret = -ENOMEM; + + obj = ttm_gem_create(dev, &dev_priv->bdev, args->domains, false, + args->alignment, PAGE_SIZE, args->size); + if (obj && obj->driver_private) { + ret = drm_gem_handle_create(filp, obj, &args->handle); + /* drop reference from allocate - handle holds it now */ + drm_gem_object_unreference_unlocked(obj); + if (!ret) { + struct ttm_buffer_object *bo = obj->driver_private; + + args->domains = bo->mem.placement & TTM_PL_MASK_MEM; + args->map_handle = bo->addr_space_offset; + args->offset = bo->offset; + args->size = bo->mem.size; + + obj->read_domains = obj->write_domain = args->domains; + } + } + return ret; +} + +static int +via_gem_state(struct drm_device *dev, void *data, struct drm_file *file_priv) +{ + struct ttm_buffer_object *bo = NULL; + struct drm_via_gem_create *args = data; + struct drm_gem_object *obj = NULL; + struct ttm_placement placement; + int ret = -EINVAL; + + obj = drm_gem_object_lookup(dev, file_priv, args->handle); + if (!obj || !obj->driver_private) + return ret; + + bo = obj->driver_private; + + /* Don't bother to migrate to same domain */ + args->domains &= ~(bo->mem.placement & TTM_PL_MASK_MEM); + if (args->domains) { + ret = ttm_bo_reserve(bo, true, false, false, 0); + if (unlikely(ret)) + return ret; + + ttm_placement_from_domain(bo, &placement, args->domains, bo->bdev); + ret = ttm_bo_validate(bo, &placement, false, false); + ttm_bo_unreserve(bo); + + if (!ret) { + args->domains = bo->mem.placement & TTM_PL_MASK_MEM; + args->map_handle = bo->addr_space_offset; + args->offset = bo->offset; + args->size = bo->mem.size; + + obj->read_domains = obj->write_domain = args->domains; + } + } + mutex_lock(&dev->struct_mutex); + drm_gem_object_unreference(obj); + mutex_unlock(&dev->struct_mutex); + return ret; +} + +static int +via_gem_wait(struct drm_device *dev, void *data, struct drm_file *file_priv) +{ + struct drm_via_gem_wait *args = data; + struct ttm_buffer_object *bo; + struct drm_gem_object *obj; + bool no_wait; + int ret; + + obj = drm_gem_object_lookup(dev, file_priv, args->handle); + if (!obj) + return -EINVAL; + + no_wait = (args->no_wait != 0); + bo = obj->driver_private; + + ret = ttm_bo_reserve(bo, true, no_wait, false, 0); + if (unlikely(ret != 0)) + return ret; + + spin_lock(&bo->bdev->fence_lock); + if (bo->sync_obj) + ret = ttm_bo_wait(bo, true, true, no_wait); + ttm_bo_unreserve(bo); + spin_unlock(&bo->bdev->fence_lock); + + mutex_lock(&dev->struct_mutex); + drm_gem_object_unreference(obj); + mutex_unlock(&dev->struct_mutex); + return ret; +} + +#define KMS_INVALID_IOCTL(name) \ +int name(struct drm_device *dev, void *data, struct drm_file *file_priv)\ +{ \ + DRM_ERROR("invalid ioctl with kms %s\n", __func__); \ + return -EINVAL; \ +} + +KMS_INVALID_IOCTL(via_mem_alloc) +KMS_INVALID_IOCTL(via_mem_free) +KMS_INVALID_IOCTL(via_agp_init) +KMS_INVALID_IOCTL(via_fb_init) +KMS_INVALID_IOCTL(via_map_init) +KMS_INVALID_IOCTL(via_decoder_futex) +KMS_INVALID_IOCTL(via_dma_blit) +KMS_INVALID_IOCTL(via_dma_blit_sync) + +struct drm_ioctl_desc via_ioctls[] = { + DRM_IOCTL_DEF_DRV(VIA_ALLOCMEM, via_mem_alloc, DRM_AUTH), + DRM_IOCTL_DEF_DRV(VIA_FREEMEM, via_mem_free, DRM_AUTH), + DRM_IOCTL_DEF_DRV(VIA_AGP_INIT, via_agp_init, DRM_AUTH | DRM_MASTER), + DRM_IOCTL_DEF_DRV(VIA_FB_INIT, via_fb_init, DRM_AUTH | DRM_MASTER), + DRM_IOCTL_DEF_DRV(VIA_MAP_INIT, via_map_init, DRM_AUTH | DRM_MASTER), + DRM_IOCTL_DEF_DRV(VIA_DEC_FUTEX, via_decoder_futex, DRM_AUTH), + DRM_IOCTL_DEF_DRV(VIA_OLD_GEM_CREATE, via_gem_alloc, DRM_AUTH | DRM_UNLOCKED), + DRM_IOCTL_DEF_DRV(VIA_DMA_INIT, via_dma_init, DRM_AUTH), + DRM_IOCTL_DEF_DRV(VIA_CMDBUFFER, via_cmdbuffer, DRM_AUTH), + DRM_IOCTL_DEF_DRV(VIA_FLUSH, via_flush_ioctl, DRM_AUTH), + DRM_IOCTL_DEF_DRV(VIA_PCICMD, via_pci_cmdbuffer, DRM_AUTH), + DRM_IOCTL_DEF_DRV(VIA_CMDBUF_SIZE, via_cmdbuf_size, DRM_AUTH), + DRM_IOCTL_DEF_DRV(VIA_WAIT_IRQ, via_wait_irq, DRM_AUTH), + DRM_IOCTL_DEF_DRV(VIA_DMA_BLIT, via_dma_blit, DRM_AUTH), + DRM_IOCTL_DEF_DRV(VIA_BLIT_SYNC, via_dma_blit_sync, DRM_AUTH), + DRM_IOCTL_DEF_DRV(VIA_GETPARAM, via_getparam, DRM_AUTH | DRM_UNLOCKED), + DRM_IOCTL_DEF_DRV(VIA_SETPARAM, via_setparam, DRM_AUTH | DRM_MASTER | DRM_ROOT_ONLY), + DRM_IOCTL_DEF_DRV(VIA_GEM_CREATE, via_gem_alloc, DRM_AUTH | DRM_UNLOCKED), + DRM_IOCTL_DEF_DRV(VIA_GEM_WAIT, via_gem_wait, DRM_AUTH), + DRM_IOCTL_DEF_DRV(VIA_GEM_STATE, via_gem_state, DRM_AUTH), +}; + +int via_max_ioctl = DRM_ARRAY_SIZE(via_ioctls);