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