drm_bufs.c revision 1450
98N/A * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved. 98N/A * Generic buffer template 919N/A * \author Rickard E. (Rik) Faith <faith@valinux.com> 919N/A * \author Gareth Hughes <gareth@valinux.com> 919N/A * Created: Thu Nov 23 03:10:50 2000 by gareth@valinux.com 919N/A * Copyright 1999, 2000 Precision Insight, Inc., Cedar Park, Texas. 919N/A * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 919N/A * Copyright (c) 2009, 2012, Intel Corporation. 919N/A * Permission is hereby granted, free of charge, to any person obtaining a 919N/A * copy of this software and associated documentation files (the "Software"), 919N/A * to deal in the Software without restriction, including without limitation 919N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense, 919N/A * and/or sell copies of the Software, and to permit persons to whom the 98N/A * Software is furnished to do so, subject to the following conditions: 98N/A * The above copyright notice and this permission notice (including the next 98N/A * paragraph) shall be included in all copies or substantial portions of the 98N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 851N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 98N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 911N/A * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 911N/A * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 911N/A * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 911N/A * OTHER DEALINGS IN THE SOFTWARE. 536N/A#
error "No define for _LP64, _SYSCALL32_IMPL or _ILP32" * Because the kernel-userspace ABI is fixed at a 32-bit offset * while PCI resources may live above that, we ignore the map * offset for maps of type _DRM_FRAMEBUFFER or _DRM_REGISTERS. * It is assumed that each driver will have only one resource of default:
/* Make gcc happy */ * Core function to create a range of memory available for mapping by a * Adjusts the memory offset to its absolute value according to the mapping * type. Adds the map to the map list drm_device::maplist. Adds MTRR's where * applicable and if supported by the kernel. /* Only allow shared memory to be removable since we only keep enough * book keeping information about shared memory to allow for removal DRM_DEBUG(
"offset = 0x%08llx, size = 0x%08lx, type = %d\n",
/* page-align _DRM_SHM maps. They are allocated here so there is no security * hole created by that and it works around various broken drivers that use * a non-aligned quantity to map the SAREA. --BenH /* Some drivers preinitialize some maps, without the X Server * needing to be aware of it. Therefore, we just return success * when the server tries to create a duplicate map. "mismatched sizes, (%ld vs %ld)\n",
"mismatched sizes, (%ld vs %ld)\n",
/* Prevent a 2nd X Server from creating a 2nd lock */ /* Assign a 32-bit handle */ /* We do it here so that dev->struct_mutex protects the increment */ * Ioctl to specify a range of memory that is available for mapping by a * \param inode device inode. * \param file_priv DRM file private. * \param arg pointer to a drm_map structure. * \return zero on success or a negative value on error. /* avoid a warning on 64-bit, this casting isn't very nice, but the API is set so too late */ * Remove a map private from list and deallocate resources if the mapping * Searches the map on drm_device::maplist, removes it from the list, see if * its being used, and free any associate resource (such as MTRR's) if it's not /* Find the list entry for the map and remove it */ /* The rmmap ioctl appears to be unnecessary. All mappings are torn down on * the last close of the device, and this is necessary for cleanup when things * exit uncleanly. Therefore, having userland manually remove mappings seems * like a pointless exercise since they're going away anyway. * One use case might be after addmap is allowed for normal users for SHM and * gets used by drivers that the server doesn't need to care about. This seems * \param inode device inode. * \param file_priv DRM file private. * \param arg pointer to a struct drm_map structure. * \return zero on success or a negative value on error. /* List has wrapped around to the head pointer, or its empty we didn't /* Register and framebuffer maps are permanent */ * Cleanup after an error on one of the addbufs() functions. * \param entry buffer entry where the error occurred. * Frees any pages and buffers associated with the given entry. "drm_cleanup_buf_error: not implemented");
* Add AGP buffers for DMA transfers. * \param dev struct drm_device to which the buffers are to be added. * \param request pointer to a struct drm_buf_desc describing the request. * \return zero on success or a negative number on failure. * After some sanity checks creates a drm_buf structure for each buffer and * reallocates the buffer list of the same size order to accommodate the new return -
ENOMEM;
/* May only call once for each order */ /* Set count correctly so we free the proper amount. */ /* Free the entry because it isn't valid */ return -
ENOMEM;
/* May only call once for each order */ /* Set count correctly so we free the proper amount. */ /* Free the entry because it isn't valid */ * Add buffers for DMA transfers (ioctl). * \param inode device inode. * \param file_priv DRM file private. * \param arg pointer to a struct drm_buf_desc request. * \return zero on success or a negative number on failure. * According with the memory type specified in drm_buf_desc::flags and the * build options, it dispatches the call either to addbufs_agp(), * addbufs_sg() or addbufs_pci() for AGP, scatter-gather or consistent * PCI memory respectively. * Get information about the buffer mappings. * This was originally mean for debugging purposes, or by a sophisticated * client library to determine how best to use the available buffers (e.g., * large buffers can be used for image transfer). * \param inode device inode. * \param file_priv DRM file private. * \param arg pointer to a drm_buf_info structure. * \return zero on success or a negative number on failure. * Increments drm_device::buf_use while holding the drm_device::count_lock * lock, preventing of allocating more buffers after this call. Information * about each requested buffer is then copied into user space. ++
dev->
buf_use;
/* Can't allocate more after this call */ * Specifies a low and high water mark for buffer allocation * \param inode device inode. * \param file_priv DRM file private. * \param arg a pointer to a drm_buf_desc structure. * \return zero on success or a negative number on failure. * Verifies that the size order is bounded between the admissible orders and * updates the respective drm_device_dma::bufs entry low and high water mark. * \note This ioctl is deprecated and mostly never used. * Unreserve the buffers in list, previously reserved using drmDMA. * \param inode device inode. * \param file_priv DRM file private. * \param arg pointer to a drm_buf_free structure. * \return zero on success or a negative number on failure. * Calls free_buffer() for each used buffer. * This function is primarily used for debugging. DRM_ERROR(
"Process %d freeing buffer not owned\n",
* Maps all of the DMA buffers into client-virtual space (ioctl). * \param inode device inode. * \param file_priv DRM file private. * \param arg pointer to a drm_buf_map structure. * \return zero on success or a negative number on failure. * Maps the AGP, SG or PCI buffer region with do_mmap(), and copies information * about each buffer into user space. For PCI buffers, it calls do_mmap() with * offset equal to 0, which drm_mmap() interpretes as PCI buffers and calls dev->
buf_use++;
/* Can't allocate more after this call */ * Compute size order. Returns the exponent of the smaller power of two which * is greater or equal to given number. * \todo Can be made faster.