xref: /freebsd/sys/arm/nvidia/drm2/tegra_drm.h (revision aa1a8ff2d6dbc51ef058f46f3db5a8bb77967145)
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 #ifndef _TEGRA_DRM_H_
27 #define _TEGRA_DRM_H_
28 
29 #include <dev/gpio/gpiobusvar.h>
30 
31 struct tegra_bo {
32  	struct drm_gem_object	gem_obj;
33 	/* mapped memory buffer */
34 	vm_paddr_t		pbase;
35 	vm_offset_t		vbase;
36 	size_t			npages;
37 	vm_page_t 		*m;
38 	vm_object_t		cdev_pager;
39 };
40 
41 struct tegra_plane {
42 	struct drm_plane	drm_plane;
43 	int			index;		/* Window index */
44 };
45 
46 struct tegra_fb {
47 	struct drm_framebuffer	drm_fb;
48 	struct drm_fb_helper	fb_helper;
49 	struct tegra_bo		**planes;	/* Attached planes */
50 	int			nplanes;
51 
52 	/* Surface and display geometry */
53 	bool			block_linear;	/* Surface_kind */
54 	uint32_t		block_height;
55 	int			rotation; 	/* In degrees */
56 	bool			flip_x;		/* Inverted X-axis */
57 	bool			flip_y;		/* Inverted Y-axis */
58 };
59 
60 struct tegra_crtc {
61 	struct drm_crtc 	drm_crtc;
62 	device_t		dev;
63 	int			nvidia_head;
64 	vm_paddr_t		cursor_pbase;	/* Cursor buffer */
65 	void			*cursor_vbase;
66 };
67 
68 struct tegra_drm_encoder {
69 	device_t 		dev;
70 
71 	void 			*panel;		/* XXX For LVDS panel */
72 	device_t  		ddc;
73 	struct edid 		*edid;
74 
75 	gpio_pin_t		gpio_hpd;
76 
77 	struct drm_encoder 	encoder;
78 	struct drm_connector 	connector;
79 	int			(*setup_clock)(struct tegra_drm_encoder *output,
80 				    clk_t clk, uint64_t pclk);
81 };
82 
83 struct tegra_drm {
84 	struct drm_device 	drm_dev;
85 	struct tegra_fb 	*fb;		/* Prime framebuffer */
86 	int			pitch_align;
87 };
88 
89 /* tegra_drm_subr.c */
90 int tegra_drm_encoder_attach(struct tegra_drm_encoder *output, phandle_t node);
91 int tegra_drm_encoder_init(struct tegra_drm_encoder *output,
92     struct tegra_drm *drm);
93 int tegra_drm_encoder_exit(struct tegra_drm_encoder *output,
94     struct tegra_drm *drm);
95 enum drm_connector_status tegra_drm_connector_detect(
96     struct drm_connector *connector, bool force);
97 int tegra_drm_connector_get_modes(struct drm_connector *connector);
98 struct drm_encoder *tegra_drm_connector_best_encoder(
99     struct drm_connector *connector);
100 
101 /* tegra_dc.c */
102 void tegra_dc_cancel_page_flip(struct drm_crtc *drm_crtc,
103     struct drm_file *file);
104 void tegra_dc_enable_vblank(struct drm_crtc *drm_crtc);
105 void tegra_dc_disable_vblank(struct drm_crtc *drm_crtc);
106 int tegra_dc_get_pipe(struct drm_crtc *drm_crtc);
107 
108 /* tegra_fb.c */
109 struct fb_info *tegra_drm_fb_getinfo(struct drm_device *drm);
110 struct tegra_bo *tegra_fb_get_plane(struct tegra_fb *fb, int idx);
111 int tegra_drm_fb_create(struct drm_device *drm, struct drm_file *file,
112     struct drm_mode_fb_cmd2 *cmd, struct drm_framebuffer **fb_res);
113 int tegra_drm_fb_init(struct drm_device *drm);
114 void tegra_drm_fb_destroy(struct drm_device *drm);
115 
116 /* tegra_bo.c */
117 struct tegra_bo;
118 int tegra_bo_create(struct drm_device *drm, size_t size,
119     struct tegra_bo **res_bo);
120 void tegra_bo_driver_register(struct drm_driver *drm_drv);
121 
122 #endif /* _TEGRA_DRM_H_ */
123