xref: /freebsd/sys/arm/nvidia/drm2/tegra_drm.h (revision 4d846d26)
1 /*-
2  * Copyright 1992-2015 Michal Meloun
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 #ifndef _TEGRA_DRM_H_
29 #define _TEGRA_DRM_H_
30 
31 #include <dev/gpio/gpiobusvar.h>
32 
33 struct tegra_bo {
34  	struct drm_gem_object	gem_obj;
35 	/* mapped memory buffer */
36 	vm_paddr_t		pbase;
37 	vm_offset_t		vbase;
38 	size_t			npages;
39 	vm_page_t 		*m;
40 	vm_object_t		cdev_pager;
41 };
42 
43 struct tegra_plane {
44 	struct drm_plane	drm_plane;
45 	int			index;		/* Window index */
46 };
47 
48 struct tegra_fb {
49 	struct drm_framebuffer	drm_fb;
50 	struct drm_fb_helper	fb_helper;
51 	struct tegra_bo		**planes;	/* Attached planes */
52 	int			nplanes;
53 
54 	/* Surface and display geometry */
55 	bool			block_linear;	/* Surface_kind */
56 	uint32_t		block_height;
57 	int			rotation; 	/* In degrees */
58 	bool			flip_x;		/* Inverted X-axis */
59 	bool			flip_y;		/* Inverted Y-axis */
60 };
61 
62 struct tegra_crtc {
63 	struct drm_crtc 	drm_crtc;
64 	device_t		dev;
65 	int			nvidia_head;
66 	vm_paddr_t		cursor_pbase;	/* Cursor buffer */
67 	void			*cursor_vbase;
68 };
69 
70 struct tegra_drm_encoder {
71 	device_t 		dev;
72 
73 	void 			*panel;		/* XXX For LVDS panel */
74 	device_t  		ddc;
75 	struct edid 		*edid;
76 
77 	gpio_pin_t		gpio_hpd;
78 
79 	struct drm_encoder 	encoder;
80 	struct drm_connector 	connector;
81 	int			(*setup_clock)(struct tegra_drm_encoder *output,
82 				    clk_t clk, uint64_t pclk);
83 };
84 
85 struct tegra_drm {
86 	struct drm_device 	drm_dev;
87 	struct tegra_fb 	*fb;		/* Prime framebuffer */
88 	int			pitch_align;
89 };
90 
91 /* tegra_drm_subr.c */
92 int tegra_drm_encoder_attach(struct tegra_drm_encoder *output, phandle_t node);
93 int tegra_drm_encoder_init(struct tegra_drm_encoder *output,
94     struct tegra_drm *drm);
95 int tegra_drm_encoder_exit(struct tegra_drm_encoder *output,
96     struct tegra_drm *drm);
97 enum drm_connector_status tegra_drm_connector_detect(
98     struct drm_connector *connector, bool force);
99 int tegra_drm_connector_get_modes(struct drm_connector *connector);
100 struct drm_encoder *tegra_drm_connector_best_encoder(
101     struct drm_connector *connector);
102 
103 /* tegra_dc.c */
104 void tegra_dc_cancel_page_flip(struct drm_crtc *drm_crtc,
105     struct drm_file *file);
106 void tegra_dc_enable_vblank(struct drm_crtc *drm_crtc);
107 void tegra_dc_disable_vblank(struct drm_crtc *drm_crtc);
108 int tegra_dc_get_pipe(struct drm_crtc *drm_crtc);
109 
110 /* tegra_fb.c */
111 struct fb_info *tegra_drm_fb_getinfo(struct drm_device *drm);
112 struct tegra_bo *tegra_fb_get_plane(struct tegra_fb *fb, int idx);
113 int tegra_drm_fb_create(struct drm_device *drm, struct drm_file *file,
114     struct drm_mode_fb_cmd2 *cmd, struct drm_framebuffer **fb_res);
115 int tegra_drm_fb_init(struct drm_device *drm);
116 void tegra_drm_fb_destroy(struct drm_device *drm);
117 
118 /* tegra_bo.c */
119 struct tegra_bo;
120 int tegra_bo_create(struct drm_device *drm, size_t size,
121     struct tegra_bo **res_bo);
122 void tegra_bo_driver_register(struct drm_driver *drm_drv);
123 
124 #endif /* _TEGRA_DRM_H_ */
125