xref: /openbmc/linux/drivers/gpu/drm/udl/udl_drv.h (revision 3213486f)
1 /*
2  * Copyright (C) 2012 Red Hat
3  *
4  * based in parts on udlfb.c:
5  * Copyright (C) 2009 Roberto De Ioris <roberto@unbit.it>
6  * Copyright (C) 2009 Jaya Kumar <jayakumar.lkml@gmail.com>
7  * Copyright (C) 2009 Bernie Thompson <bernie@plugable.com>
8  *
9  * This file is subject to the terms and conditions of the GNU General Public
10  * License v2. See the file COPYING in the main directory of this archive for
11  * more details.
12  */
13 
14 #ifndef UDL_DRV_H
15 #define UDL_DRV_H
16 
17 #include <linux/usb.h>
18 #include <drm/drm_gem.h>
19 #include <linux/mm_types.h>
20 
21 #define DRIVER_NAME		"udl"
22 #define DRIVER_DESC		"DisplayLink"
23 #define DRIVER_DATE		"20120220"
24 
25 #define DRIVER_MAJOR		0
26 #define DRIVER_MINOR		0
27 #define DRIVER_PATCHLEVEL	1
28 
29 #define UDL_BO_CACHEABLE		(1 << 0)
30 #define UDL_BO_WC		(1 << 1)
31 
32 struct udl_device;
33 
34 struct urb_node {
35 	struct list_head entry;
36 	struct udl_device *dev;
37 	struct delayed_work release_urb_work;
38 	struct urb *urb;
39 };
40 
41 struct urb_list {
42 	struct list_head list;
43 	spinlock_t lock;
44 	struct semaphore limit_sem;
45 	int available;
46 	int count;
47 	size_t size;
48 };
49 
50 struct udl_fbdev;
51 
52 struct udl_device {
53 	struct device *dev;
54 	struct drm_device *ddev;
55 	struct usb_device *udev;
56 	struct drm_crtc *crtc;
57 
58 	struct mutex gem_lock;
59 
60 	int sku_pixel_limit;
61 
62 	struct urb_list urbs;
63 	atomic_t lost_pixels; /* 1 = a render op failed. Need screen refresh */
64 
65 	struct udl_fbdev *fbdev;
66 	char mode_buf[1024];
67 	uint32_t mode_buf_len;
68 	atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
69 	atomic_t bytes_identical; /* saved effort with backbuffer comparison */
70 	atomic_t bytes_sent; /* to usb, after compression including overhead */
71 	atomic_t cpu_kcycles_used; /* transpired during pixel processing */
72 };
73 
74 struct udl_gem_object {
75 	struct drm_gem_object base;
76 	struct page **pages;
77 	void *vmapping;
78 	struct sg_table *sg;
79 	unsigned int flags;
80 };
81 
82 #define to_udl_bo(x) container_of(x, struct udl_gem_object, base)
83 
84 struct udl_framebuffer {
85 	struct drm_framebuffer base;
86 	struct udl_gem_object *obj;
87 	bool active_16; /* active on the 16-bit channel */
88 };
89 
90 #define to_udl_fb(x) container_of(x, struct udl_framebuffer, base)
91 
92 /* modeset */
93 int udl_modeset_init(struct drm_device *dev);
94 void udl_modeset_restore(struct drm_device *dev);
95 void udl_modeset_cleanup(struct drm_device *dev);
96 int udl_connector_init(struct drm_device *dev, struct drm_encoder *encoder);
97 
98 struct drm_encoder *udl_encoder_init(struct drm_device *dev);
99 
100 struct urb *udl_get_urb(struct drm_device *dev);
101 
102 int udl_submit_urb(struct drm_device *dev, struct urb *urb, size_t len);
103 void udl_urb_completion(struct urb *urb);
104 
105 int udl_driver_load(struct drm_device *dev, unsigned long flags);
106 void udl_driver_unload(struct drm_device *dev);
107 void udl_driver_release(struct drm_device *dev);
108 
109 int udl_fbdev_init(struct drm_device *dev);
110 void udl_fbdev_cleanup(struct drm_device *dev);
111 void udl_fbdev_unplug(struct drm_device *dev);
112 struct drm_framebuffer *
113 udl_fb_user_fb_create(struct drm_device *dev,
114 		      struct drm_file *file,
115 		      const struct drm_mode_fb_cmd2 *mode_cmd);
116 
117 int udl_render_hline(struct drm_device *dev, int log_bpp, struct urb **urb_ptr,
118 		     const char *front, char **urb_buf_ptr,
119 		     u32 byte_offset, u32 device_byte_offset, u32 byte_width,
120 		     int *ident_ptr, int *sent_ptr);
121 
122 int udl_dumb_create(struct drm_file *file_priv,
123 		    struct drm_device *dev,
124 		    struct drm_mode_create_dumb *args);
125 int udl_gem_mmap(struct drm_file *file_priv, struct drm_device *dev,
126 		 uint32_t handle, uint64_t *offset);
127 
128 void udl_gem_free_object(struct drm_gem_object *gem_obj);
129 struct udl_gem_object *udl_gem_alloc_object(struct drm_device *dev,
130 					    size_t size);
131 struct dma_buf *udl_gem_prime_export(struct drm_device *dev,
132 				     struct drm_gem_object *obj, int flags);
133 struct drm_gem_object *udl_gem_prime_import(struct drm_device *dev,
134 				struct dma_buf *dma_buf);
135 
136 int udl_gem_get_pages(struct udl_gem_object *obj);
137 void udl_gem_put_pages(struct udl_gem_object *obj);
138 int udl_gem_vmap(struct udl_gem_object *obj);
139 void udl_gem_vunmap(struct udl_gem_object *obj);
140 int udl_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
141 vm_fault_t udl_gem_fault(struct vm_fault *vmf);
142 
143 int udl_handle_damage(struct udl_framebuffer *fb, int x, int y,
144 		      int width, int height);
145 
146 int udl_drop_usb(struct drm_device *dev);
147 
148 #define CMD_WRITE_RAW8   "\xAF\x60" /**< 8 bit raw write command. */
149 #define CMD_WRITE_RL8    "\xAF\x61" /**< 8 bit run length command. */
150 #define CMD_WRITE_COPY8  "\xAF\x62" /**< 8 bit copy command. */
151 #define CMD_WRITE_RLX8   "\xAF\x63" /**< 8 bit extended run length command. */
152 
153 #define CMD_WRITE_RAW16  "\xAF\x68" /**< 16 bit raw write command. */
154 #define CMD_WRITE_RL16   "\xAF\x69" /**< 16 bit run length command. */
155 #define CMD_WRITE_COPY16 "\xAF\x6A" /**< 16 bit copy command. */
156 #define CMD_WRITE_RLX16  "\xAF\x6B" /**< 16 bit extended run length command. */
157 
158 #endif
159