linux/drivers/staging/mali/DX910-SW-99002-r5p2-00rel0/driver/src/devicedrv/mali/common/mali_soft_job.h
<<
>>
Prefs
   1/*
   2 * Copyright (C) 2013-2015 ARM Limited. All rights reserved.
   3 * 
   4 * This program is free software and is provided to you under the terms of the GNU General Public License version 2
   5 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
   6 * 
   7 * A copy of the licence is included with the program, and can also be obtained from Free Software
   8 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
   9 */
  10
  11#ifndef __MALI_SOFT_JOB_H__
  12#define __MALI_SOFT_JOB_H__
  13
  14#include "mali_osk.h"
  15
  16#include "mali_timeline.h"
  17
  18struct mali_timeline_fence;
  19struct mali_session_data;
  20struct mali_soft_job;
  21struct mali_soft_job_system;
  22
  23/**
  24 * Soft job types.
  25 *
  26 * Soft jobs of type MALI_SOFT_JOB_TYPE_USER_SIGNALED will only complete after activation if either
  27 * they are signaled by user-space (@ref mali_soft_job_system_signaled_job) or if they are timed out
  28 * by the Timeline system.
  29 * Soft jobs of type MALI_SOFT_JOB_TYPE_SELF_SIGNALED will release job resource automatically
  30 * in kernel when the job is activated.
  31 */
  32typedef enum mali_soft_job_type {
  33        MALI_SOFT_JOB_TYPE_SELF_SIGNALED,
  34        MALI_SOFT_JOB_TYPE_USER_SIGNALED,
  35} mali_soft_job_type;
  36
  37/**
  38 * Soft job state.
  39 *
  40 * mali_soft_job_system_start_job a job will first be allocated.The job's state set to MALI_SOFT_JOB_STATE_ALLOCATED.
  41 * Once the job is added to the timeline system, the state changes to MALI_SOFT_JOB_STATE_STARTED.
  42 *
  43 * For soft jobs of type MALI_SOFT_JOB_TYPE_USER_SIGNALED the state is changed to
  44 * MALI_SOFT_JOB_STATE_SIGNALED when @ref mali_soft_job_system_signal_job is called and the soft
  45 * job's state is MALI_SOFT_JOB_STATE_STARTED or MALI_SOFT_JOB_STATE_TIMED_OUT.
  46 *
  47 * If a soft job of type MALI_SOFT_JOB_TYPE_USER_SIGNALED is timed out before being signaled, the
  48 * state is changed to MALI_SOFT_JOB_STATE_TIMED_OUT.  This can only happen to soft jobs in state
  49 * MALI_SOFT_JOB_STATE_STARTED.
  50 *
  51 */
  52typedef enum mali_soft_job_state {
  53        MALI_SOFT_JOB_STATE_ALLOCATED,
  54        MALI_SOFT_JOB_STATE_STARTED,
  55        MALI_SOFT_JOB_STATE_SIGNALED,
  56        MALI_SOFT_JOB_STATE_TIMED_OUT,
  57} mali_soft_job_state;
  58
  59#define MALI_SOFT_JOB_INVALID_ID ((u32) -1)
  60
  61/**
  62 * Soft job struct.
  63 *
  64 * Soft job can be used to represent any kind of CPU work done in kernel-space.
  65 */
  66typedef struct mali_soft_job {
  67        mali_soft_job_type            type;                   /**< Soft job type.  Must be one of MALI_SOFT_JOB_TYPE_*. */
  68        u64                           user_job;               /**< Identifier for soft job in user space. */
  69        _mali_osk_atomic_t            refcount;               /**< Soft jobs are reference counted to prevent premature deletion. */
  70        struct mali_timeline_tracker  tracker;                /**< Timeline tracker for soft job. */
  71        mali_bool                     activated;              /**< MALI_TRUE if the job has been activated, MALI_FALSE if not. */
  72        _mali_osk_notification_t     *activated_notification; /**< Pre-allocated notification object for ACTIVATED_NOTIFICATION. */
  73
  74        /* Protected by soft job system lock. */
  75        u32                           id;                     /**< Used by user-space to find corresponding soft job in kernel-space. */
  76        mali_soft_job_state           state;                  /**< State of soft job, must be one of MALI_SOFT_JOB_STATE_*. */
  77        struct mali_soft_job_system  *system;                 /**< The soft job system this job is in. */
  78        _mali_osk_list_t              system_list;            /**< List element used by soft job system. */
  79} mali_soft_job;
  80
  81/**
  82 * Per-session soft job system.
  83 *
  84 * The soft job system is used to manage all soft jobs that belongs to a session.
  85 */
  86typedef struct mali_soft_job_system {
  87        struct mali_session_data *session;                    /**< The session this soft job system belongs to. */
  88        _MALI_OSK_LIST_HEAD(jobs_used);                       /**< List of all allocated soft jobs. */
  89
  90        _mali_osk_spinlock_irq_t *lock;                       /**< Lock used to protect soft job system and its soft jobs. */
  91        u32 lock_owner;                                       /**< Contains tid of thread that locked the system or 0, if not locked. */
  92        u32 last_job_id;                                      /**< Recored the last job id protected by lock. */
  93} mali_soft_job_system;
  94
  95/**
  96 * Create a soft job system.
  97 *
  98 * @param session The session this soft job system will belong to.
  99 * @return The new soft job system, or NULL if unsuccessful.
 100 */
 101struct mali_soft_job_system *mali_soft_job_system_create(struct mali_session_data *session);
 102
 103/**
 104 * Destroy a soft job system.
 105 *
 106 * @note The soft job must not have any started or activated jobs.  Call @ref
 107 * mali_soft_job_system_abort first.
 108 *
 109 * @param system The soft job system we are destroying.
 110 */
 111void mali_soft_job_system_destroy(struct mali_soft_job_system *system);
 112
 113/**
 114 * Create a soft job.
 115 *
 116 * @param system Soft job system to create soft job from.
 117 * @param type Type of the soft job.
 118 * @param user_job Identifier for soft job in user space.
 119 * @return New soft job if successful, NULL if not.
 120 */
 121struct mali_soft_job *mali_soft_job_create(struct mali_soft_job_system *system, mali_soft_job_type type, u64 user_job);
 122
 123/**
 124 * Destroy soft job.
 125 *
 126 * @param job Soft job to destroy.
 127 */
 128void mali_soft_job_destroy(struct mali_soft_job *job);
 129
 130/**
 131 * Start a soft job.
 132 *
 133 * The soft job will be added to the Timeline system which will then activate it after all
 134 * dependencies have been resolved.
 135 *
 136 * Create soft jobs with @ref mali_soft_job_create before starting them.
 137 *
 138 * @param job Soft job to start.
 139 * @param fence Fence representing dependencies for this soft job.
 140 * @return Point on soft job timeline.
 141 */
 142mali_timeline_point mali_soft_job_start(struct mali_soft_job *job, struct mali_timeline_fence *fence);
 143
 144/**
 145 * Use by user-space to signal that a soft job has completed.
 146 *
 147 * @note Only valid for soft jobs with type MALI_SOFT_JOB_TYPE_USER_SIGNALED.
 148 *
 149 * @note The soft job must be in state MALI_SOFT_JOB_STATE_STARTED for the signal to be successful.
 150 *
 151 * @note If the soft job was signaled successfully, or it received a time out, the soft job will be
 152 * destroyed after this call and should no longer be used.
 153 *
 154 * @note This function will block until the soft job has been activated.
 155 *
 156 * @param system The soft job system the job was started in.
 157 * @param job_id ID of soft job we are signaling.
 158 *
 159 * @return _MALI_OSK_ERR_ITEM_NOT_FOUND if the soft job ID was invalid, _MALI_OSK_ERR_TIMEOUT if the
 160 * soft job was timed out or _MALI_OSK_ERR_OK if we successfully signaled the soft job.
 161 */
 162_mali_osk_errcode_t mali_soft_job_system_signal_job(struct mali_soft_job_system *system, u32 job_id);
 163
 164/**
 165 * Used by the Timeline system to activate a soft job.
 166 *
 167 * @param job The soft job that is being activated.
 168 * @return A scheduling bitmask.
 169 */
 170mali_scheduler_mask mali_soft_job_system_activate_job(struct mali_soft_job *job);
 171
 172/**
 173 * Used by the Timeline system to timeout a soft job.
 174 *
 175 * A soft job is timed out if it completes or is signaled later than MALI_TIMELINE_TIMEOUT_HZ after
 176 * activation.
 177 *
 178 * @param job The soft job that is being timed out.
 179 * @return A scheduling bitmask.
 180 */
 181mali_scheduler_mask mali_soft_job_system_timeout_job(struct mali_soft_job *job);
 182
 183/**
 184 * Used to cleanup activated soft jobs in the soft job system on session abort.
 185 *
 186 * @param system The soft job system that is being aborted.
 187 */
 188void mali_soft_job_system_abort(struct mali_soft_job_system *system);
 189
 190#endif /* __MALI_SOFT_JOB_H__ */
 191