Linux Audio

Check our new training course

Loading...
v4.6
 
 1/*
 
 2 * Copyright (C) 2013 Red Hat
 3 * Author: Rob Clark <robdclark@gmail.com>
 4 *
 5 * This program is free software; you can redistribute it and/or modify it
 6 * under the terms of the GNU General Public License version 2 as published by
 7 * the Free Software Foundation.
 8 *
 9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __MSM_KMS_H__
19#define __MSM_KMS_H__
20
21#include <linux/clk.h>
22#include <linux/regulator/consumer.h>
23
24#include "msm_drv.h"
25
26#define MAX_PLANE	4
27
28/* As there are different display controller blocks depending on the
29 * snapdragon version, the kms support is split out and the appropriate
30 * implementation is loaded at runtime.  The kms module is responsible
31 * for constructing the appropriate planes/crtcs/encoders/connectors.
32 */
33struct msm_kms_funcs {
34	/* hw initialization: */
35	int (*hw_init)(struct msm_kms *kms);
36	/* irq handling: */
37	void (*irq_preinstall)(struct msm_kms *kms);
38	int (*irq_postinstall)(struct msm_kms *kms);
39	void (*irq_uninstall)(struct msm_kms *kms);
40	irqreturn_t (*irq)(struct msm_kms *kms);
41	int (*enable_vblank)(struct msm_kms *kms, struct drm_crtc *crtc);
42	void (*disable_vblank)(struct msm_kms *kms, struct drm_crtc *crtc);
43	/* modeset, bracketing atomic_commit(): */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44	void (*prepare_commit)(struct msm_kms *kms, struct drm_atomic_state *state);
45	void (*complete_commit)(struct msm_kms *kms, struct drm_atomic_state *state);
46	/* functions to wait for atomic commit completed on each CRTC */
47	void (*wait_for_crtc_commit_done)(struct msm_kms *kms,
48					struct drm_crtc *crtc);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49	/* misc: */
50	const struct msm_format *(*get_format)(struct msm_kms *kms, uint32_t format);
51	long (*round_pixclk)(struct msm_kms *kms, unsigned long rate,
52			struct drm_encoder *encoder);
53	int (*set_split_display)(struct msm_kms *kms,
54			struct drm_encoder *encoder,
55			struct drm_encoder *slave_encoder,
56			bool is_cmd_mode);
 
 
 
57	/* cleanup: */
58	void (*destroy)(struct msm_kms *kms);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59};
60
61struct msm_kms {
62	const struct msm_kms_funcs *funcs;
 
63
64	/* irq handling: */
65	bool in_irq;
66	struct list_head irq_list;    /* list of mdp4_irq */
67	uint32_t vblank_mask;         /* irq bits set for userspace vblank */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68};
69
70static inline void msm_kms_init(struct msm_kms *kms,
71		const struct msm_kms_funcs *funcs)
72{
 
 
 
 
 
73	kms->funcs = funcs;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74}
75
76struct msm_kms *mdp4_kms_init(struct drm_device *dev);
77struct msm_kms *mdp5_kms_init(struct drm_device *dev);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
79#endif /* __MSM_KMS_H__ */
v5.14.15
  1/* SPDX-License-Identifier: GPL-2.0-only */
  2/*
  3 * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
  4 * Copyright (C) 2013 Red Hat
  5 * Author: Rob Clark <robdclark@gmail.com>
 
 
 
 
 
 
 
 
 
 
 
 
  6 */
  7
  8#ifndef __MSM_KMS_H__
  9#define __MSM_KMS_H__
 10
 11#include <linux/clk.h>
 12#include <linux/regulator/consumer.h>
 13
 14#include "msm_drv.h"
 15
 16#define MAX_PLANE	4
 17
 18/* As there are different display controller blocks depending on the
 19 * snapdragon version, the kms support is split out and the appropriate
 20 * implementation is loaded at runtime.  The kms module is responsible
 21 * for constructing the appropriate planes/crtcs/encoders/connectors.
 22 */
 23struct msm_kms_funcs {
 24	/* hw initialization: */
 25	int (*hw_init)(struct msm_kms *kms);
 26	/* irq handling: */
 27	void (*irq_preinstall)(struct msm_kms *kms);
 28	int (*irq_postinstall)(struct msm_kms *kms);
 29	void (*irq_uninstall)(struct msm_kms *kms);
 30	irqreturn_t (*irq)(struct msm_kms *kms);
 31	int (*enable_vblank)(struct msm_kms *kms, struct drm_crtc *crtc);
 32	void (*disable_vblank)(struct msm_kms *kms, struct drm_crtc *crtc);
 33
 34	/*
 35	 * Atomic commit handling:
 36	 *
 37	 * Note that in the case of async commits, the funcs which take
 38	 * a crtc_mask (ie. ->flush_commit(), and ->complete_commit())
 39	 * might not be evenly balanced with ->prepare_commit(), however
 40	 * each crtc that effected by a ->prepare_commit() (potentially
 41	 * multiple times) will eventually (at end of vsync period) be
 42	 * flushed and completed.
 43	 *
 44	 * This has some implications about tracking of cleanup state,
 45	 * for example SMP blocks to release after commit completes.  Ie.
 46	 * cleanup state should be also duplicated in the various
 47	 * duplicate_state() methods, as the current cleanup state at
 48	 * ->complete_commit() time may have accumulated cleanup work
 49	 * from multiple commits.
 50	 */
 51
 52	/**
 53	 * Enable/disable power/clks needed for hw access done in other
 54	 * commit related methods.
 55	 *
 56	 * If mdp4 is migrated to runpm, we could probably drop these
 57	 * and use runpm directly.
 58	 */
 59	void (*enable_commit)(struct msm_kms *kms);
 60	void (*disable_commit)(struct msm_kms *kms);
 61
 62	/**
 63	 * If the kms backend supports async commit, it should implement
 64	 * this method to return the time of the next vsync.  This is
 65	 * used to determine a time slightly before vsync, for the async
 66	 * commit timer to run and complete an async commit.
 67	 */
 68	ktime_t (*vsync_time)(struct msm_kms *kms, struct drm_crtc *crtc);
 69
 70	/**
 71	 * Prepare for atomic commit.  This is called after any previous
 72	 * (async or otherwise) commit has completed.
 73	 */
 74	void (*prepare_commit)(struct msm_kms *kms, struct drm_atomic_state *state);
 75
 76	/**
 77	 * Flush an atomic commit.  This is called after the hardware
 78	 * updates have already been pushed down to effected planes/
 79	 * crtcs/encoders/connectors.
 80	 */
 81	void (*flush_commit)(struct msm_kms *kms, unsigned crtc_mask);
 82
 83	/**
 84	 * Wait for any in-progress flush to complete on the specified
 85	 * crtcs.  This should not block if there is no in-progress
 86	 * commit (ie. don't just wait for a vblank), as it will also
 87	 * be called before ->prepare_commit() to ensure any potential
 88	 * "async" commit has completed.
 89	 */
 90	void (*wait_flush)(struct msm_kms *kms, unsigned crtc_mask);
 91
 92	/**
 93	 * Clean up after commit is completed.  This is called after
 94	 * ->wait_flush(), to give the backend a chance to do any
 95	 * post-commit cleanup.
 96	 */
 97	void (*complete_commit)(struct msm_kms *kms, unsigned crtc_mask);
 98
 99	/*
100	 * Format handling:
101	 */
102
103	/* get msm_format w/ optional format modifiers from drm_mode_fb_cmd2 */
104	const struct msm_format *(*get_format)(struct msm_kms *kms,
105					const uint32_t format,
106					const uint64_t modifiers);
107	/* do format checking on format modified through fb_cmd2 modifiers */
108	int (*check_modified_format)(const struct msm_kms *kms,
109			const struct msm_format *msm_fmt,
110			const struct drm_mode_fb_cmd2 *cmd,
111			struct drm_gem_object **bos);
112
113	/* misc: */
 
114	long (*round_pixclk)(struct msm_kms *kms, unsigned long rate,
115			struct drm_encoder *encoder);
116	int (*set_split_display)(struct msm_kms *kms,
117			struct drm_encoder *encoder,
118			struct drm_encoder *slave_encoder,
119			bool is_cmd_mode);
120	void (*set_encoder_mode)(struct msm_kms *kms,
121				 struct drm_encoder *encoder,
122				 bool cmd_mode);
123	/* cleanup: */
124	void (*destroy)(struct msm_kms *kms);
125
126	/* snapshot: */
127	void (*snapshot)(struct msm_disp_state *disp_state, struct msm_kms *kms);
128
129#ifdef CONFIG_DEBUG_FS
130	/* debugfs: */
131	int (*debugfs_init)(struct msm_kms *kms, struct drm_minor *minor);
132#endif
133};
134
135struct msm_kms;
136
137/*
138 * A per-crtc timer for pending async atomic flushes.  Scheduled to expire
139 * shortly before vblank to flush pending async updates.
140 */
141struct msm_pending_timer {
142	struct hrtimer timer;
143	struct kthread_work work;
144	struct kthread_worker *worker;
145	struct msm_kms *kms;
146	unsigned crtc_idx;
147};
148
149struct msm_kms {
150	const struct msm_kms_funcs *funcs;
151	struct drm_device *dev;
152
153	/* irq number to be passed on to drm_irq_install */
154	int irq;
155
156	/* mapper-id used to request GEM buffer mapped for scanout: */
157	struct msm_gem_address_space *aspace;
158
159	/* disp snapshot support */
160	struct kthread_worker *dump_worker;
161	struct kthread_work dump_work;
162	struct mutex dump_mutex;
163
164	/*
165	 * For async commit, where ->flush_commit() and later happens
166	 * from the crtc's pending_timer close to end of the frame:
167	 */
168	struct mutex commit_lock[MAX_CRTCS];
169	unsigned pending_crtc_mask;
170	struct msm_pending_timer pending_timers[MAX_CRTCS];
171};
172
173static inline int msm_kms_init(struct msm_kms *kms,
174		const struct msm_kms_funcs *funcs)
175{
176	unsigned i, ret;
177
178	for (i = 0; i < ARRAY_SIZE(kms->commit_lock); i++)
179		mutex_init(&kms->commit_lock[i]);
180
181	kms->funcs = funcs;
182
183	for (i = 0; i < ARRAY_SIZE(kms->pending_timers); i++) {
184		ret = msm_atomic_init_pending_timer(&kms->pending_timers[i], kms, i);
185		if (ret) {
186			return ret;
187		}
188	}
189
190	return 0;
191}
192
193static inline void msm_kms_destroy(struct msm_kms *kms)
194{
195	unsigned i;
196
197	for (i = 0; i < ARRAY_SIZE(kms->pending_timers); i++)
198		msm_atomic_destroy_pending_timer(&kms->pending_timers[i]);
199}
200
201struct msm_kms *mdp4_kms_init(struct drm_device *dev);
202struct msm_kms *mdp5_kms_init(struct drm_device *dev);
203struct msm_kms *dpu_kms_init(struct drm_device *dev);
204
205struct msm_mdss_funcs {
206	int (*enable)(struct msm_mdss *mdss);
207	int (*disable)(struct msm_mdss *mdss);
208	void (*destroy)(struct drm_device *dev);
209};
210
211struct msm_mdss {
212	struct drm_device *dev;
213	const struct msm_mdss_funcs *funcs;
214};
215
216int mdp5_mdss_init(struct drm_device *dev);
217int dpu_mdss_init(struct drm_device *dev);
218
219#define for_each_crtc_mask(dev, crtc, crtc_mask) \
220	drm_for_each_crtc(crtc, dev) \
221		for_each_if (drm_crtc_mask(crtc) & (crtc_mask))
222
223#define for_each_crtc_mask_reverse(dev, crtc, crtc_mask) \
224	drm_for_each_crtc_reverse(crtc, dev) \
225		for_each_if (drm_crtc_mask(crtc) & (crtc_mask))
226
227#endif /* __MSM_KMS_H__ */