Home | History | Annotate | Line # | Download | only in nvidia
tegra_drm.h revision 1.4
      1 /* $NetBSD: tegra_drm.h,v 1.4 2015/11/14 11:55:36 jmcneill Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2015 Jared D. McNeill <jmcneill (at) invisible.ca>
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 
     29 #ifndef _ARM_TEGRA_DRM_H
     30 #define _ARM_TEGRA_DRM_H
     31 
     32 #include <drm/drm_fb_helper.h>
     33 
     34 #define DRIVER_AUTHOR		"Jared McNeill"
     35 
     36 #define DRIVER_NAME		"tegra"
     37 #define DRIVER_DESC		"NVIDIA Tegra K1"
     38 #define DRIVER_DATE		"20151108"
     39 
     40 #define DRIVER_MAJOR		0
     41 #define DRIVER_MINOR		1
     42 #define DRIVER_PATCHLEVEL	0
     43 
     44 struct tegra_framebuffer;
     45 
     46 struct tegra_gem_object;
     47 
     48 struct tegra_drm_softc {
     49 	device_t		sc_dev;
     50 	struct drm_device	*sc_ddev;
     51 
     52 	bus_space_tag_t		sc_bst;
     53 	bus_dma_tag_t		sc_dmat;
     54 
     55 	device_t		sc_ddcdev;
     56 	struct tegra_gpio_pin	*sc_pin_hpd;
     57 	struct tegra_gpio_pin	*sc_pin_pll;
     58 	struct tegra_gpio_pin	*sc_pin_power;
     59 
     60 	bool			sc_force_dvi;
     61 
     62 	uint32_t		sc_vbl_received[2];
     63 };
     64 
     65 struct tegra_drmfb_attach_args {
     66 	struct drm_device	*tfa_drm_dev;
     67 	struct drm_fb_helper	*tfa_fb_helper;
     68 	struct drm_fb_helper_surface_size tfa_fb_sizes;
     69 	bus_space_tag_t		tfa_fb_bst;
     70 	bus_dma_tag_t		tfa_fb_dmat;
     71 };
     72 
     73 struct tegra_crtc {
     74 	struct drm_crtc		base;
     75 	bus_space_tag_t		bst;
     76 	bus_space_handle_t	bsh;
     77 	bus_size_t		size;
     78 	int			intr;
     79 	int			index;
     80 	void			*ih;
     81 	bool			enabled;
     82 
     83 	struct tegra_gem_object	*cursor_obj;
     84 	int			cursor_x;
     85 	int			cursor_y;
     86 };
     87 
     88 struct tegra_encoder {
     89 	struct drm_encoder	base;
     90 	bus_space_tag_t		bst;
     91 	bus_space_handle_t	bsh;
     92 	bus_size_t		size;
     93 };
     94 
     95 struct tegra_connector {
     96 	struct drm_connector	base;
     97 	device_t		ddcdev;
     98 	struct i2c_adapter	*adapter;
     99 	struct tegra_gpio_pin	*hpd;
    100 
    101 	bool			has_hdmi_sink;
    102 	bool			has_audio;
    103 };
    104 
    105 struct tegra_gem_object {
    106 	struct drm_gem_object	base;
    107 	bus_dma_tag_t		dmat;
    108 	bus_dma_segment_t	dmasegs[1];
    109 	bus_size_t		dmasize;
    110 	bus_dmamap_t		dmamap;
    111 	void			*dmap;
    112 };
    113 
    114 struct tegra_framebuffer {
    115 	struct drm_framebuffer	base;
    116 	struct tegra_gem_object *obj;
    117 };
    118 
    119 struct tegra_fbdev {
    120 	struct drm_fb_helper	helper;
    121 };
    122 
    123 #define HDMI_READ(enc, reg)			\
    124     bus_space_read_4((enc)->bst, (enc)->bsh, (reg))
    125 #define HDMI_WRITE(enc, reg, val)		\
    126     bus_space_write_4((enc)->bst, (enc)->bsh, (reg), (val))
    127 #define HDMI_SET_CLEAR(enc, reg, set, clr)	\
    128     tegra_reg_set_clear((enc)->bst, (enc)->bsh, (reg), (set), (clr))
    129 
    130 #define DC_READ(crtc, reg)			\
    131     bus_space_read_4((crtc)->bst, (crtc)->bsh, (reg))
    132 #define DC_WRITE(crtc, reg, val)		\
    133     bus_space_write_4((crtc)->bst, (crtc)->bsh, (reg), (val))
    134 #define DC_SET_CLEAR(crtc, reg, set, clr)	\
    135     tegra_reg_set_clear((crtc)->bst, (crtc)->bsh, (reg), (set), (clr))
    136 
    137 #define TEGRA_DC_DEPTH		32
    138 
    139 #define tegra_drm_private(ddev)	(ddev)->dev_private
    140 #define to_tegra_crtc(x)	container_of(x, struct tegra_crtc, base)
    141 #define to_tegra_encoder(x)	container_of(x, struct tegra_encoder, base)
    142 #define to_tegra_connector(x)	container_of(x, struct tegra_connector, base)
    143 #define to_tegra_framebuffer(x)	container_of(x, struct tegra_framebuffer, base)
    144 #define to_tegra_fbdev(x)	container_of(x, struct tegra_fbdev, helper)
    145 #define to_tegra_gem_obj(x)	container_of(x, struct tegra_gem_object, base)
    146 
    147 int	tegra_drm_mode_init(struct drm_device *);
    148 int	tegra_drm_fb_init(struct drm_device *);
    149 u32	tegra_drm_get_vblank_counter(struct drm_device *, int);
    150 int	tegra_drm_enable_vblank(struct drm_device *, int);
    151 void	tegra_drm_disable_vblank(struct drm_device *, int);
    152 int	tegra_drm_framebuffer_init(struct drm_device *,
    153 	    struct tegra_framebuffer *);
    154 
    155 struct tegra_gem_object *tegra_drm_obj_alloc(struct drm_device *, size_t);
    156 void	tegra_drm_obj_free(struct tegra_gem_object *);
    157 
    158 int	tegra_drm_gem_fault(struct uvm_faultinfo *, vaddr_t, struct vm_page **,
    159 	    int, int, vm_prot_t, int);
    160 void	tegra_drm_gem_free_object(struct drm_gem_object *);
    161 
    162 #endif /* _ARM_TEGRA_DRM_H */
    163