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