linux/drivers/gpu/drm/i915/display/intel_frontbuffer.h
<<
>>
Prefs
   1/*
   2 * Copyright (c) 2014-2016 Intel Corporation
   3 *
   4 * Permission is hereby granted, free of charge, to any person obtaining a
   5 * copy of this software and associated documentation files (the "Software"),
   6 * to deal in the Software without restriction, including without limitation
   7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
   8 * and/or sell copies of the Software, and to permit persons to whom the
   9 * Software is furnished to do so, subject to the following conditions:
  10 *
  11 * The above copyright notice and this permission notice (including the next
  12 * paragraph) shall be included in all copies or substantial portions of the
  13 * Software.
  14 *
  15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21 * IN THE SOFTWARE.
  22 */
  23
  24#ifndef __INTEL_FRONTBUFFER_H__
  25#define __INTEL_FRONTBUFFER_H__
  26
  27#include <linux/atomic.h>
  28#include <linux/kref.h>
  29
  30#include "gem/i915_gem_object_types.h"
  31#include "i915_active.h"
  32
  33struct drm_i915_private;
  34
  35enum fb_op_origin {
  36        ORIGIN_GTT,
  37        ORIGIN_CPU,
  38        ORIGIN_CS,
  39        ORIGIN_FLIP,
  40        ORIGIN_DIRTYFB,
  41        ORIGIN_CURSOR_UPDATE,
  42};
  43
  44struct intel_frontbuffer {
  45        struct kref ref;
  46        atomic_t bits;
  47        struct i915_active write;
  48        struct drm_i915_gem_object *obj;
  49        struct rcu_head rcu;
  50};
  51
  52void intel_frontbuffer_flip_prepare(struct drm_i915_private *i915,
  53                                    unsigned frontbuffer_bits);
  54void intel_frontbuffer_flip_complete(struct drm_i915_private *i915,
  55                                     unsigned frontbuffer_bits);
  56void intel_frontbuffer_flip(struct drm_i915_private *i915,
  57                            unsigned frontbuffer_bits);
  58
  59void intel_frontbuffer_put(struct intel_frontbuffer *front);
  60
  61static inline struct intel_frontbuffer *
  62__intel_frontbuffer_get(const struct drm_i915_gem_object *obj)
  63{
  64        struct intel_frontbuffer *front;
  65
  66        if (likely(!rcu_access_pointer(obj->frontbuffer)))
  67                return NULL;
  68
  69        rcu_read_lock();
  70        do {
  71                front = rcu_dereference(obj->frontbuffer);
  72                if (!front)
  73                        break;
  74
  75                if (unlikely(!kref_get_unless_zero(&front->ref)))
  76                        continue;
  77
  78                if (likely(front == rcu_access_pointer(obj->frontbuffer)))
  79                        break;
  80
  81                intel_frontbuffer_put(front);
  82        } while (1);
  83        rcu_read_unlock();
  84
  85        return front;
  86}
  87
  88struct intel_frontbuffer *
  89intel_frontbuffer_get(struct drm_i915_gem_object *obj);
  90
  91void __intel_fb_invalidate(struct intel_frontbuffer *front,
  92                           enum fb_op_origin origin,
  93                           unsigned int frontbuffer_bits);
  94
  95/**
  96 * intel_frontbuffer_invalidate - invalidate frontbuffer object
  97 * @front: GEM object to invalidate
  98 * @origin: which operation caused the invalidation
  99 *
 100 * This function gets called every time rendering on the given object starts and
 101 * frontbuffer caching (fbc, low refresh rate for DRRS, panel self refresh) must
 102 * be invalidated. For ORIGIN_CS any subsequent invalidation will be delayed
 103 * until the rendering completes or a flip on this frontbuffer plane is
 104 * scheduled.
 105 */
 106static inline bool intel_frontbuffer_invalidate(struct intel_frontbuffer *front,
 107                                                enum fb_op_origin origin)
 108{
 109        unsigned int frontbuffer_bits;
 110
 111        if (!front)
 112                return false;
 113
 114        frontbuffer_bits = atomic_read(&front->bits);
 115        if (!frontbuffer_bits)
 116                return false;
 117
 118        __intel_fb_invalidate(front, origin, frontbuffer_bits);
 119        return true;
 120}
 121
 122void __intel_fb_flush(struct intel_frontbuffer *front,
 123                      enum fb_op_origin origin,
 124                      unsigned int frontbuffer_bits);
 125
 126/**
 127 * intel_frontbuffer_flush - flush frontbuffer object
 128 * @front: GEM object to flush
 129 * @origin: which operation caused the flush
 130 *
 131 * This function gets called every time rendering on the given object has
 132 * completed and frontbuffer caching can be started again.
 133 */
 134static inline void intel_frontbuffer_flush(struct intel_frontbuffer *front,
 135                                           enum fb_op_origin origin)
 136{
 137        unsigned int frontbuffer_bits;
 138
 139        if (!front)
 140                return;
 141
 142        frontbuffer_bits = atomic_read(&front->bits);
 143        if (!frontbuffer_bits)
 144                return;
 145
 146        __intel_fb_flush(front, origin, frontbuffer_bits);
 147}
 148
 149void intel_frontbuffer_track(struct intel_frontbuffer *old,
 150                             struct intel_frontbuffer *new,
 151                             unsigned int frontbuffer_bits);
 152
 153#endif /* __INTEL_FRONTBUFFER_H__ */
 154