summaryrefslogtreecommitdiff
path: root/freedreno
AgeCommit message (Collapse)Author
2014-08-14freedreno: Use symbol visibility.Maarten Lankhorst
Hiding fd_device_del_locked, and fd_cleanup_bo_cache. Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
2014-06-18freedreno: add chip-id propertyRob Clark
Userspace needs to know the patch-revision in addition to just the gpu-id (ie. 320, 305, etc). Signed-off-by: Rob Clark <robclark@freedesktop.org>
2014-06-18freedreno: sync kernel headerRob Clark
Signed-off-by: Rob Clark <robclark@freedesktop.org>
2014-04-25freedreno: add missing fxn prototypeRob Clark
Signed-off-by: Rob Clark <robclark@freedesktop.org>
2014-03-19freedreno: zero out unused fieldRob Clark
Since realloc() doesn't zero-init. Signed-off-by: Rob Clark <robclark@freedesktop.org>
2014-03-16freedreno: do not leak drmVersionEmil Velikov
Cc: Rob Clark <robclark@freedesktop.org> Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Reviewed-by: Rob Clark <robdclark@gmail.com> Signed-off-by: Rob Clark <robclark@freedesktop.org>
2014-03-05freedreno/kgsl: don't even bother trying CREATE_FDRob Clark
Don't even bother trying DRM_KGSL_GEM_CREATE_FD. It hasn't worked since (afaict) 2.6.35 kernels. And in some cases seems to cause some problems. Instead just allocate a minimum size dummy object (just for purposes of having a handle) and then mmap the framebuffer as user-mem (which is deprecated, but seems to still work.. and as far as I can tell is the best option for now). Signed-off-by: Rob Clark <robclark@freedesktop.org>
2014-03-05freedreno: fix null ptr in error pathRob Clark
Signed-off-by: Rob Clark <robclark@freedesktop.org>
2014-03-05freedreno: simplify device creationRob Clark
Signed-off-by: Rob Clark <robclark@freedesktop.org>
2014-02-19freedreno: some msm-ring reset/flush fixesRob Clark
Need to update timestamp on all ring's associated with a submit (ie. both the binning pass and main ring). Also, make sure nr_reloc's in particular gets cleared if the rb is reset. Signed-off-by: Rob Clark <robclark@freedesktop.org>
2014-01-31freedreno: fix licenseRob Clark
The userspace headers were intended to be BSD license. Signed-off-by: Rob Clark <robclark@freedesktop.org>
2014-01-12freedreno: add fd_device_new_dup()Rob Clark
There seem to be some cases (I've noticed this switching resolution in some games, for example) where the fd can get closed() before the device and all it's bo's are destroyed. Which, if the drm device is opened again and bo's are allocated with the same handles, results that when the first pipe_screen/pipe_context is destroyed causes the first dev to close handles for bo's allocated by the second device. The easy solution to that is to add a mode where the fd_device creates it's own private fd (a dup()). Signed-off-by: Rob Clark <robclark@freedesktop.org>
2014-01-07freedreno: allow IB to different ringbufferRob Clark
Allow IB to different ringbuffer in addition to just different part of same ringbuffer. In particular, we need to add bo's to the parent (ie. one passed to flush) bo table, since the bo table applies to all the cmd buffers in submit ioctl. Signed-off-by: Rob Clark <robclark@freedesktop.org>
2014-01-07freedreno/kgsl: fix crash introduced w/ bo-cacheRob Clark
Signed-off-by: Rob Clark <robclark@freedesktop.org>
2013-12-13freedreno: add bo cacheRob Clark
Workloads which create many transient buffers cause significant CPU overhead in buffer allocation, zeroing, cache maint, and mmap setup. By caching and re-using existing buffers, the CPU overhead drops significantly. See: http://bloggingthemonkey.blogspot.com/2013/09/freedreno-update-moar-fps.html A simple time based policy is used for purging the cache. Once the kernel supports it, we could use madvise style API to handle memory pressure scenarios a bit better. Signed-off-by: Rob Clark <robclark@freedesktop.org>
2013-09-11freedreno: add missing NOSYNC flagRob Clark
Signed-off-by: Rob Clark <robclark@freedesktop.org>
2013-08-30freedreno: set automake options to include subdir-objectsEmil Velikov
Handles automake complains about lack of forward-compatibility, due to the source files in the kgsl and msm backends/folders. Cc: Rob Clark <robclark@freedesktop.org> Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2013-08-30freedreno: use local drm.h over the system oneEmil Velikov
Otherwise build will fail, as drm/drm.h is not available. Cc: Rob Clark <robclark@freedesktop.org> Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2013-08-28freedreno: add support for msm drmRob Clark
This adds support for the "msm" backend, using the upstream msm drm/kms driver. Signed-off-by: Rob Clark <robclark@freedesktop.org>
2013-08-28freedreno: support either kgsl or msmRob Clark
Split out common code and backend. Current backend is for 'kgsl' android driver, but a new backend will provide support for the upstream msm drm/kms driver. Signed-off-by: Rob Clark <robclark@freedesktop.org>
2013-05-17freedreno: also remove from name table on bo deleteRob Clark
When adding the name tracking, I missed removing from the name table when the bo was deleted, leaving a dangling pointer. Signed-off-by: Rob Clark <robclark@freedesktop.org>
2013-05-15freedreno: add some assertsRob Clark
Things are worse if we issueibcmds with bogus gpu ptrs, so it is better to just make userspace crash when things go pear shaped. Signed-off-by: Rob Clark <robclark@freedesktop.org>
2013-05-15freedreno: add handle and name trackingRob Clark
Due to the evil userspace buffer tracking we have to do, and hacks for creating GEM buffer from fbdev/scanout, "evil-twin" fd_bo objects are problematic. So introduce hashtable tracking of bo's and dev's, to avoid getting duplicate fd_bo ptrs for the same underlying gem object, in particular when importing via flink name. Signed-off-by: Rob Clark <robclark@freedesktop.org>
2013-04-25freedreno: add synchronization between mesa and ddxRob Clark
Super-cheezy way to synchronization between mesa and ddx.. the SET_ACTIVE ioctl gives us a way to stash a 32b # w/ a GEM bo, and GET_BUFINFO gives us a way to retrieve it. We use this to stash the timestamp of the last ISSUEIBCMDS on the buffer. To avoid an obscene amount of syscalls, we: 1) Only set the timestamp for buffers w/ an flink name, ie. only buffers shared across processes. This is enough to catch the DRI2 buffers. 2) Only set the timestamp for buffers submitted to the 3d ring and only check the timestamps on buffers submitted to the 2d ring. This should be enough to handle synchronizing of presentation blit. We could do synchronization in the other direction too, but that would be problematic if we are using the 3d ring from DDX, since client side wouldn't know this. The waiting on timestamp happens before flush, and setting of timestamp happens after flush. It is transparent to the user of libdrm_freedreno as all the tracking of buffers happens via _emit_reloc().. Signed-off-by: Rob Clark <robclark@freedesktop.org>
2013-04-22freedreno: add gpu-id propertyRob Clark
Gallium driver will need to query this to figure out whether to load the a2xx or a3xx driver. Signed-off-by: Rob Clark <robclark@freedesktop.org>
2013-04-13freedreno: add shifted relocRob Clark
Needed for RB_COPY_DEST_BASE register on a3xx. Signed-off-by: Rob Clark <robdclark@gmail.com>
2013-03-27makefiles: Add missing headers.Maarten Lankhorst
I even compile time tested this on a panda with make dist! Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
2013-02-14freedreno: add freedreno DRMRob Clark
The libdrm_freedreno helper layer for use by xf86-video-freedreno, fdre (freedreno r/e library and tests for driving gpu), and eventual gallium driver for the Adreno GPU. This uses the msm gpu driver from QCOM's android kernel tree. Note that current msm kernel driver is a bit strange. It provides a DRM interface for GEM, which is basically sufficient to have DRI2 working. But it does not provide KMS. And interface to 2d and 3d cores is via different other devices (/dev/kgsl-*). This is not quite how I'd write a DRM driver, but at this stage it is useful for xf86-video-freedreno and fdre (and eventual gallium driver) to be able to work on existing kernel driver from QCOM, to allow to capture cmdstream dumps from the binary blob drivers without having to reboot. So libdrm_freedreno attempts to hide most of the crazy. The intention is that when there is a proper kernel driver, it will be mostly just changes in libdrm_freedreno to adapt the gallium driver and xf86-video-freedreno (ignoring the fbdev->KMS changes). So don't look at freedreno as an example of how to write a libdrm module or a DRM driver.. it is just an attempt to paper over a non- standard kernel driver architecture. v1: original v2: hold ref's to pending bo's (because qcom's kernel driver doesn't), various bug fixes, add ringbuffer markers so we can emit IB's to portion of ringbuffer (so that gallium driver can use a single ringbuffer for both tile cmds and draw cmds. Signed-off-by: Rob Clark <robclark@freedesktop.org>
D, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * VA LINUX SYSTEMS AND/OR ITS 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. */ /* * ChangeLog: * 2001-11-16 Torsten Duwe <duwe@caldera.de> * added context constructor/destructor hooks, * needed by SiS driver's memory management. */ #include "drmP.h" /******************************************************************/ /** \name Context bitmap support */ /*@{*/ /** * Free a handle from the context bitmap. * * \param dev DRM device. * \param ctx_handle context handle. * * Clears the bit specified by \p ctx_handle in drm_device::ctx_bitmap and the entry * in drm_device::ctx_idr, while holding the drm_device::struct_mutex * lock. */ void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle) { mutex_lock(&dev->struct_mutex); idr_remove(&dev->ctx_idr, ctx_handle); mutex_unlock(&dev->struct_mutex); } /** * Context bitmap allocation. * * \param dev DRM device. * \return (non-negative) context handle on success or a negative number on failure. * * Allocate a new idr from drm_device::ctx_idr while holding the * drm_device::struct_mutex lock. */ static int drm_ctxbitmap_next(struct drm_device *dev) { int new_id; int ret; again: if (idr_pre_get(&dev->ctx_idr, GFP_KERNEL) == 0) { DRM_ERROR("Out of memory expanding drawable idr\n"); return -ENOMEM; } mutex_lock(&dev->struct_mutex); ret = idr_get_new_above(&dev->ctx_idr, NULL, DRM_RESERVED_CONTEXTS, &new_id); if (ret == -EAGAIN) { mutex_unlock(&dev->struct_mutex); goto again; } mutex_unlock(&dev->struct_mutex); return new_id; } /** * Context bitmap initialization. * * \param dev DRM device. * * Initialise the drm_device::ctx_idr */ int drm_ctxbitmap_init(struct drm_device *dev) { idr_init(&dev->ctx_idr); return 0; } /** * Context bitmap cleanup. * * \param dev DRM device. * * Free all idr members using drm_ctx_sarea_free helper function * while holding the drm_device::struct_mutex lock. */ void drm_ctxbitmap_cleanup(struct drm_device *dev) { mutex_lock(&dev->struct_mutex); idr_remove_all(&dev->ctx_idr); mutex_unlock(&dev->struct_mutex); } /*@}*/ /******************************************************************/ /** \name Per Context SAREA Support */ /*@{*/ /** * Get per-context SAREA. * * \param inode device inode. * \param file_priv DRM file private. * \param cmd command. * \param arg user argument pointing to a drm_ctx_priv_map structure. * \return zero on success or a negative number on failure. * * Gets the map from drm_device::ctx_idr with the handle specified and * returns its handle. */ int drm_getsareactx(struct drm_device *dev, void *data, struct drm_file *file_priv) { struct drm_ctx_priv_map *request = data; struct drm_map *map; struct drm_map_list *_entry; mutex_lock(&dev->struct_mutex); map = idr_find(&dev->ctx_idr, request->ctx_id); if (!map) { mutex_unlock(&dev->struct_mutex); return -EINVAL; } mutex_unlock(&dev->struct_mutex); request->handle = NULL; list_for_each_entry(_entry, &dev->maplist, head) { if (_entry->map == map) { request->handle = (void *)(unsigned long)_entry->user_token; break; } } if (request->handle == NULL) return -EINVAL; return 0; } /** * Set per-context SAREA. * * \param inode device inode. * \param file_priv DRM file private. * \param cmd command. * \param arg user argument pointing to a drm_ctx_priv_map structure. * \return zero on success or a negative number on failure. * * Searches the mapping specified in \p arg and update the entry in * drm_device::ctx_idr with it. */ int drm_setsareactx(struct drm_device *dev, void *data, struct drm_file *file_priv) { struct drm_ctx_priv_map *request = data; struct drm_map *map = NULL; struct drm_map_list *r_list = NULL; mutex_lock(&dev->struct_mutex); list_for_each_entry(r_list, &dev->maplist, head) { if (r_list->map && r_list->user_token == (unsigned long) request->handle) goto found; } bad: mutex_unlock(&dev->struct_mutex); return -EINVAL; found: map = r_list->map; if (!map) goto bad; if (IS_ERR(idr_replace(&dev->ctx_idr, map, request->ctx_id))) goto bad; mutex_unlock(&dev->struct_mutex); return 0; } /*@}*/ /******************************************************************/ /** \name The actual DRM context handling routines */ /*@{*/ /** * Switch context. * * \param dev DRM device. * \param old old context handle. * \param new new context handle. * \return zero on success or a negative number on failure. * * Attempt to set drm_device::context_flag. */ static int drm_context_switch(struct drm_device *dev, int old, int new) { if (test_and_set_bit(0, &dev->context_flag)) { DRM_ERROR("Reentering -- FIXME\n"); return -EBUSY; } DRM_DEBUG("Context switch from %d to %d\n", old, new); if (new == dev->last_context) { clear_bit(0, &dev->context_flag); return 0; } return 0; } /** * Complete context switch. * * \param dev DRM device. * \param new new context handle. * \return zero on success or a negative number on failure. * * Updates drm_device::last_context and drm_device::last_switch. Verifies the * hardware lock is held, clears the drm_device::context_flag and wakes up * drm_device::context_wait. */ static int drm_context_switch_complete(struct drm_device *dev, int new) { dev->last_context = new; /* PRE/POST: This is the _only_ writer. */ dev->last_switch = jiffies; if (!_DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock)) { DRM_ERROR("Lock isn't held after context switch\n"); } /* If a context switch is ever initiated when the kernel holds the lock, release that lock here. */ clear_bit(0, &dev->context_flag); wake_up(&dev->context_wait); return 0; } /** * Reserve contexts. * * \param inode device inode. * \param file_priv DRM file private. * \param cmd command. * \param arg user argument pointing to a drm_ctx_res structure. * \return zero on success or a negative number on failure. */ int drm_resctx(struct drm_device *dev, void *data, struct drm_file *file_priv) { struct drm_ctx_res *res = data; struct drm_ctx ctx; int i; if (res->count >= DRM_RESERVED_CONTEXTS) { memset(&ctx, 0, sizeof(ctx)); for (i = 0; i < DRM_RESERVED_CONTEXTS; i++) { ctx.handle = i; if (copy_to_user(&res->contexts[i], &ctx, sizeof(ctx))) return -EFAULT; } } res->count = DRM_RESERVED_CONTEXTS; return 0; } /** * Add context. * * \param inode device inode. * \param file_priv DRM file private. * \param cmd command. * \param arg user argument pointing to a drm_ctx structure. * \return zero on success or a negative number on failure. * * Get a new handle for the context and copy to userspace. */ int drm_addctx(struct drm_device *dev, void *data, struct drm_file *file_priv) { struct drm_ctx_list *ctx_entry; struct drm_ctx *ctx = data; ctx->handle = drm_ctxbitmap_next(dev); if (ctx->handle == DRM_KERNEL_CONTEXT) { /* Skip kernel's context and get a new one. */ ctx->handle = drm_ctxbitmap_next(dev); } DRM_DEBUG("%d\n", ctx->handle); if (ctx->handle == -1) { DRM_DEBUG("Not enough free contexts.\n"); /* Should this return -EBUSY instead? */ return -ENOMEM; } if (ctx->handle != DRM_KERNEL_CONTEXT) { if (dev->driver->context_ctor) if (!dev->driver->context_ctor(dev, ctx->handle)) { DRM_DEBUG("Running out of ctxs or memory.\n"); return -ENOMEM; } } ctx_entry = drm_alloc(sizeof(*ctx_entry), DRM_MEM_CTXLIST); if (!ctx_entry) { DRM_DEBUG("out of memory\n"); return -ENOMEM; } INIT_LIST_HEAD(&ctx_entry->head); ctx_entry->handle = ctx->handle; ctx_entry->tag = file_priv; mutex_lock(&dev->ctxlist_mutex); list_add(&ctx_entry->head, &dev->ctxlist); ++dev->ctx_count; mutex_unlock(&dev->ctxlist_mutex); return 0; } int drm_modctx(struct drm_device *dev, void *data, struct drm_file *file_priv) { /* This does nothing */ return 0; } /** * Get context. * * \param inode device inode. * \param file_priv DRM file private. * \param cmd command. * \param arg user argument pointing to a drm_ctx structure. * \return zero on success or a negative number on failure. */ int drm_getctx(struct drm_device *dev, void *data, struct drm_file *file_priv) { struct drm_ctx *ctx = data; /* This is 0, because we don't handle any context flags */ ctx->flags = 0; return 0; } /** * Switch context. * * \param inode device inode. * \param file_priv DRM file private. * \param cmd command. * \param arg user argument pointing to a drm_ctx structure. * \return zero on success or a negative number on failure. * * Calls context_switch(). */ int drm_switchctx(struct drm_device *dev, void *data, struct drm_file *file_priv) { struct drm_ctx *ctx = data; DRM_DEBUG("%d\n", ctx->handle); return drm_context_switch(dev, dev->last_context, ctx->handle); } /** * New context. * * \param inode device inode. * \param file_priv DRM file private. * \param cmd command. * \param arg user argument pointing to a drm_ctx structure. * \return zero on success or a negative number on failure. * * Calls context_switch_complete(). */ int drm_newctx(struct drm_device *dev, void *data, struct drm_file *file_priv) { struct drm_ctx *ctx = data; DRM_DEBUG("%d\n", ctx->handle); drm_context_switch_complete(dev, ctx->handle); return 0; } /** * Remove context. * * \param inode device inode. * \param file_priv DRM file private. * \param cmd command. * \param arg user argument pointing to a drm_ctx structure. * \return zero on success or a negative number on failure. * * If not the special kernel context, calls ctxbitmap_free() to free the specified context. */ int drm_rmctx(struct drm_device *dev, void *data, struct drm_file *file_priv) { struct drm_ctx *ctx = data; DRM_DEBUG("%d\n", ctx->handle); if (ctx->handle == DRM_KERNEL_CONTEXT + 1) { file_priv->remove_auth_on_close = 1; } if (ctx->handle != DRM_KERNEL_CONTEXT) { if (dev->driver->context_dtor) dev->driver->context_dtor(dev, ctx->handle); drm_ctxbitmap_free(dev, ctx->handle); } mutex_lock(&dev->ctxlist_mutex); if (!list_empty(&dev->ctxlist)) { struct drm_ctx_list *pos, *n; list_for_each_entry_safe(pos, n, &dev->ctxlist, head) { if (pos->handle == ctx->handle) { list_del(&pos->head); drm_free(pos, sizeof(*pos), DRM_MEM_CTXLIST); --dev->ctx_count; } } } mutex_unlock(&dev->ctxlist_mutex); return 0; } /*@}*/