summaryrefslogtreecommitdiffstats
path: root/include/drm/drm_writeback.h
blob: 23df9d46300328452bca14212be467d93ead539a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * (C) COPYRIGHT 2016 ARM Limited. All rights reserved.
 * Author: Brian Starkey <brian.starkey@arm.com>
 *
 * This program is free software and is provided to you under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation, and any use by you of this program is subject to the terms
 * of such GNU licence.
 */

#ifndef __DRM_WRITEBACK_H__
#define __DRM_WRITEBACK_H__
#include <drm/drm_connector.h>
#include <drm/drm_encoder.h>
#include <linux/workqueue.h>

struct drm_writeback_connector {
	struct drm_connector base;

	/**
	 * @encoder: Internal encoder used by the connector to fulfill
	 * the DRM framework requirements. The users of the
	 * @drm_writeback_connector control the behaviour of the @encoder
	 * by passing the @enc_funcs parameter to drm_writeback_connector_init()
	 * function.
	 */
	struct drm_encoder encoder;

	/**
	 * @pixel_formats_blob_ptr:
	 *
	 * DRM blob property data for the pixel formats list on writeback
	 * connectors
	 * See also drm_writeback_connector_init()
	 */
	struct drm_property_blob *pixel_formats_blob_ptr;

	/** @job_lock: Protects job_queue */
	spinlock_t job_lock;

	/**
	 * @job_queue:
	 *
	 * Holds a list of a connector's writeback jobs; the last item is the
	 * most recent. The first item may be either waiting for the hardware
	 * to begin writing, or currently being written.
	 *
	 * See also: drm_writeback_queue_job() and
	 * drm_writeback_signal_completion()
	 */
	struct list_head job_queue;

	/**
	 * @fence_context:
	 *
	 * timeline context used for fence operations.
	 */
	unsigned int fence_context;
	/**
	 * @fence_lock:
	 *
	 * spinlock to protect the fences in the fence_context.
	 */
	spinlock_t fence_lock;
	/**
	 * @fence_seqno:
	 *
	 * Seqno variable used as monotonic counter for the fences
	 * created on the connector's timeline.
	 */
	unsigned long fence_seqno;
	/**
	 * @timeline_name:
	 *
	 * The name of the connector's fence timeline.
	 */
	char timeline_name[32];
};

struct drm_writeback_job {
	/**
	 * @cleanup_work:
	 *
	 * Used to allow drm_writeback_signal_completion to defer dropping the
	 * framebuffer reference to a workqueue
	 */
	struct work_struct cleanup_work;

	/**
	 * @list_entry:
	 *
	 * List item for the writeback connector's @job_queue
	 */
	struct list_head list_entry;

	/**
	 * @fb:
	 *
	 * Framebuffer to be written to by the writeback connector. Do not set
	 * directly, use drm_atomic_set_writeback_fb_for_connector()
	 */
	struct drm_framebuffer *fb;

	/**
	 * @out_fence:
	 *
	 * Fence which will signal once the writeback has completed
	 */
	struct dma_fence *out_fence;
};

static inline struct drm_writeback_connector *
drm_connector_to_writeback(struct drm_connector *connector)
{
	return container_of(connector, struct drm_writeback_connector, base);
}

int drm_writeback_connector_init(struct drm_device *dev,
				 struct drm_writeback_connector *wb_connector,
				 const struct drm_connector_funcs *con_funcs,
				 const struct drm_encoder_helper_funcs *enc_helper_funcs,
				 const u32 *formats, int n_formats);

void drm_writeback_queue_job(struct drm_writeback_connector *wb_connector,
			     struct drm_writeback_job *job);

void drm_writeback_cleanup_job(struct drm_writeback_job *job);

void
drm_writeback_signal_completion(struct drm_writeback_connector *wb_connector,
				int status);

struct dma_fence *
drm_writeback_get_out_fence(struct drm_writeback_connector *wb_connector);
#endif
edits" in Vim to see a list of people who contributed. * See README.txt for an overview of the Vim source code. */ /* * hashtab.c: Handling of a hashtable with Vim-specific properties. * * Each item in a hashtable has a NUL terminated string key. A key can appear * only once in the table. * * A hash number is computed from the key for quick lookup. When the hashes * of two different keys point to the same entry an algorithm is used to * iterate over other entries in the table until the right one is found. * To make the iteration work removed keys are different from entries where a * key was never present. * * The mechanism has been partly based on how Python Dictionaries are * implemented. The algorithm is from Knuth Vol. 3, Sec. 6.4. * * The hashtable grows to accommodate more entries when needed. At least 1/3 * of the entries is empty to keep the lookup efficient (at the cost of extra * memory). */ #include "vim.h" #if 0 # define HT_DEBUG // extra checks for table consistency and statistics static long hash_count_lookup = 0; // count number of hashtab lookups static long hash_count_perturb = 0; // count number of "misses" #endif // Magic value for algorithm that walks through the array. #define PERTURB_SHIFT 5 static int hash_may_resize(hashtab_T *ht, int minitems); #if 0 // currently not used /* * Create an empty hash table. * Returns NULL when out of memory. */ hashtab_T * hash_create(void) { hashtab_T *ht; ht = ALLOC_ONE(hashtab_T); if (ht != NULL) hash_init(ht); return ht; } #endif /* * Initialize an empty hash table. */ void hash_init(hashtab_T *ht) { // This zeroes all "ht_" entries and all the "hi_key" in "ht_smallarray". CLEAR_POINTER(ht); ht->ht_array = ht->ht_smallarray; ht->ht_mask = HT_INIT_SIZE - 1; } /* * Free the array of a hash table. Does not free the items it contains! * If "ht" is not freed then you should call hash_init() next! */ void hash_clear(hashtab_T *ht) { if (ht->ht_array != ht->ht_smallarray) vim_free(ht->ht_array); } #if defined(FEAT_SPELL) || defined(FEAT_TERMINAL) || defined(PROTO) /* * Free the array of a hash table and all the keys it contains. The keys must * have been allocated. "off" is the offset from the start of the allocate * memory to the location of the key (it's always positive). */ void hash_clear_all(hashtab_T *ht, int off) { long todo; hashitem_T *hi; todo = (long)ht->ht_used; for (hi = ht->ht_array; todo > 0; ++hi) { if (!HASHITEM_EMPTY(hi)) { vim_free(hi->hi_key - off); --todo; } } hash_clear(ht); } #endif /* * Find "key" in hashtable "ht". "key" must not be NULL. * Always returns a pointer to a hashitem. If the item was not found then * HASHITEM_EMPTY() is TRUE. The pointer is then the place where the key * would be added. * WARNING: The returned pointer becomes invalid when the hashtable is changed * (adding, setting or removing an item)! */ hashitem_T * hash_find(hashtab_T *ht, char_u *key) { return hash_lookup(ht, key, hash_hash(key)); } /* * Like hash_find(), but caller computes "hash". */ hashitem_T * hash_lookup(hashtab_T *ht, char_u *key, hash_T hash) { hash_T perturb; hashitem_T *freeitem; hashitem_T *hi; unsigned idx; #ifdef HT_DEBUG ++hash_count_lookup; #endif /* * Quickly handle the most common situations: * - return if there is no item at all * - skip over a removed item * - return if the item matches */ idx = (unsigned)(hash & ht->ht_mask); hi = &ht->ht_array[idx]; if (hi->hi_key == NULL) return hi; if (hi->hi_key == HI_KEY_REMOVED) freeitem = hi; else if (hi->hi_hash == hash && STRCMP(hi->hi_key, key) == 0) return hi; else freeitem = NULL; /* * Need to search through the table to find the key. The algorithm * to step through the table starts with large steps, gradually becoming * smaller down to (1/4 table size + 1). This means it goes through all * table entries in the end. * When we run into a NULL key it's clear that the key isn't there. * Return the first available slot found (can be a slot of a removed * item). */ for (perturb = hash; ; perturb >>= PERTURB_SHIFT) { #ifdef HT_DEBUG ++hash_count_perturb; // count a "miss" for hashtab lookup #endif idx = (unsigned)((idx << 2U) + idx + perturb + 1U); hi = &ht->ht_array[idx & ht->ht_mask]; if (hi->hi_key == NULL) return freeitem == NULL ? hi : freeitem; if (hi->hi_hash == hash && hi->hi_key != HI_KEY_REMOVED && STRCMP(hi->hi_key, key) == 0) return hi; if (hi->hi_key == HI_KEY_REMOVED && freeitem == NULL) freeitem = hi; } } #if defined(FEAT_EVAL) || defined(FEAT_SYN_HL) || defined(PROTO) /* * Print the efficiency of hashtable lookups. * Useful when trying different hash algorithms. * Called when exiting. */ void hash_debug_results(void) { # ifdef HT_DEBUG fprintf(stderr, "\r\n\r\n\r\n\r\n"); fprintf(stderr, "Number of hashtable lookups: %ld\r\n", hash_count_lookup); fprintf(stderr, "Number of perturb loops: %ld\r\n", hash_count_perturb); fprintf(stderr, "Percentage of perturb loops: %ld%%\r\n", hash_count_perturb * 100 / hash_count_lookup); # endif } #endif /* * Add item with key "key" to hashtable "ht". * Returns FAIL when out of memory or the key is already present. */ int hash_add(hashtab_T *ht, char_u *key) { hash_T hash = hash_hash(key); hashitem_T *hi; hi = hash_lookup(ht, key, hash); if (!HASHITEM_EMPTY(hi)) { internal_error("hash_add()"); return FAIL; } return hash_add_item(ht, hi, key, hash); } /* * Add item "hi" with "key" to hashtable "ht". "key" must not be NULL and * "hi" must have been obtained with hash_lookup() and point to an empty item. * "hi" is invalid after this! * Returns OK or FAIL (out of memory). */ int hash_add_item( hashtab_T *ht, hashitem_T *hi, char_u *key, hash_T hash) { // If resizing failed before and it fails again we can't add an item. if (ht->ht_error && hash_may_resize(ht, 0) == FAIL) return FAIL; ++ht->ht_used; ++ht->ht_changed; if (hi->hi_key == NULL) ++ht->ht_filled; hi->hi_key = key; hi->hi_hash = hash; // When the space gets low may resize the array. return hash_may_resize(ht, 0); } #if 0 // not used /* * Overwrite hashtable item "hi" with "key". "hi" must point to the item that * is to be overwritten. Thus the number of items in the hashtable doesn't * change. * Although the key must be identical, the pointer may be different, thus it's * set anyway (the key is part of an item with that key). * The caller must take care of freeing the old item. * "hi" is invalid after this! */ void hash_set(hashitem_T *hi, char_u *key) { hi->hi_key = key; } #endif /* * Remove item "hi" from hashtable "ht". "hi" must have been obtained with * hash_lookup(). * The caller must take care of freeing the item itself. */ void hash_remove(hashtab_T *ht, hashitem_T *hi) { --ht->ht_used; ++ht->ht_changed; hi->hi_key = HI_KEY_REMOVED; hash_may_resize(ht, 0); } /* * Lock a hashtable: prevent that ht_array changes. * Don't use this when items are to be added! * Must call hash_unlock() later. */ void hash_lock(hashtab_T *ht) { ++ht->ht_locked; } #if defined(FEAT_PROP_POPUP) || defined(PROTO) /* * Lock a hashtable at the specified number of entries. * Caller must make sure no more than "size" entries will be added. * Must call hash_unlock() later. */ void hash_lock_size(hashtab_T *ht, int size) { (void)hash_may_resize(ht, size); ++ht->ht_locked; } #endif /* * Unlock a hashtable: allow ht_array changes again. * Table will be resized (shrink) when necessary. * This must balance a call to hash_lock(). */ void hash_unlock(hashtab_T *ht) { --ht->ht_locked; (void)hash_may_resize(ht, 0); } /* * Shrink a hashtable when there is too much empty space. * Grow a hashtable when there is not enough empty space. * Returns OK or FAIL (out of memory). */ static int hash_may_resize( hashtab_T *ht, int minitems) // minimal number of items { hashitem_T temparray[HT_INIT_SIZE]; hashitem_T *oldarray, *newarray; hashitem_T *olditem, *newitem; unsigned newi; int todo; long_u oldsize, newsize; long_u minsize; long_u newmask; hash_T perturb; // Don't resize a locked table. if (ht->ht_locked > 0) return OK; #ifdef HT_DEBUG if (ht->ht_used > ht->ht_filled) emsg("hash_may_resize(): more used than filled"); if (ht->ht_filled >= ht->ht_mask + 1) emsg("hash_may_resize(): table completely filled"); #endif if (minitems == 0) { // Return quickly for small tables with at least two NULL items. NULL // items are required for the lookup to decide a key isn't there. if (ht->ht_filled < HT_INIT_SIZE - 1 && ht->ht_array == ht->ht_smallarray) return OK; /* * Grow or refill the array when it's more than 2/3 full (including * removed items, so that they get cleaned up). * Shrink the array when it's less than 1/5 full. When growing it is * at least 1/4 full (avoids repeated grow-shrink operations) */ oldsize = ht->ht_mask