Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 1 | /* |
| 2 | * vsp1_dl.h -- R-Car VSP1 Display List |
| 3 | * |
| 4 | * Copyright (C) 2015 Renesas Corporation |
| 5 | * |
| 6 | * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com) |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/device.h> |
| 15 | #include <linux/dma-mapping.h> |
| 16 | #include <linux/gfp.h> |
| 17 | #include <linux/slab.h> |
| 18 | |
| 19 | #include "vsp1.h" |
| 20 | #include "vsp1_dl.h" |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 21 | |
Laurent Pinchart | f81e83c | 2016-03-03 13:36:34 -0300 | [diff] [blame^] | 22 | #define VSP1_DL_NUM_ENTRIES 256 |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 23 | #define VSP1_DL_NUM_LISTS 3 |
| 24 | |
Laurent Pinchart | 1216198 | 2015-11-14 22:48:27 -0200 | [diff] [blame] | 25 | #define VSP1_DLH_INT_ENABLE (1 << 1) |
| 26 | #define VSP1_DLH_AUTO_START (1 << 0) |
| 27 | |
Laurent Pinchart | f81e83c | 2016-03-03 13:36:34 -0300 | [diff] [blame^] | 28 | struct vsp1_dl_header_list { |
| 29 | u32 num_bytes; |
| 30 | u32 addr; |
| 31 | } __attribute__((__packed__)); |
| 32 | |
Laurent Pinchart | 1216198 | 2015-11-14 22:48:27 -0200 | [diff] [blame] | 33 | struct vsp1_dl_header { |
| 34 | u32 num_lists; |
Laurent Pinchart | f81e83c | 2016-03-03 13:36:34 -0300 | [diff] [blame^] | 35 | struct vsp1_dl_header_list lists[8]; |
Laurent Pinchart | 1216198 | 2015-11-14 22:48:27 -0200 | [diff] [blame] | 36 | u32 next_header; |
| 37 | u32 flags; |
| 38 | } __attribute__((__packed__)); |
| 39 | |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 40 | struct vsp1_dl_entry { |
| 41 | u32 addr; |
| 42 | u32 data; |
| 43 | } __attribute__((__packed__)); |
| 44 | |
Laurent Pinchart | f81e83c | 2016-03-03 13:36:34 -0300 | [diff] [blame^] | 45 | /** |
| 46 | * struct vsp1_dl_body - Display list body |
| 47 | * @list: entry in the display list list of bodies |
| 48 | * @vsp1: the VSP1 device |
| 49 | * @entries: array of entries |
| 50 | * @dma: DMA address of the entries |
| 51 | * @size: size of the DMA memory in bytes |
| 52 | * @num_entries: number of stored entries |
| 53 | */ |
| 54 | struct vsp1_dl_body { |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 55 | struct list_head list; |
Laurent Pinchart | f81e83c | 2016-03-03 13:36:34 -0300 | [diff] [blame^] | 56 | struct vsp1_device *vsp1; |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 57 | |
Laurent Pinchart | f81e83c | 2016-03-03 13:36:34 -0300 | [diff] [blame^] | 58 | struct vsp1_dl_entry *entries; |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 59 | dma_addr_t dma; |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 60 | size_t size; |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 61 | |
Laurent Pinchart | f81e83c | 2016-03-03 13:36:34 -0300 | [diff] [blame^] | 62 | unsigned int num_entries; |
| 63 | }; |
| 64 | |
| 65 | /** |
| 66 | * struct vsp1_dl_list - Display list |
| 67 | * @list: entry in the display list manager lists |
| 68 | * @dlm: the display list manager |
| 69 | * @header: display list header, NULL for headerless lists |
| 70 | * @dma: DMA address for the header |
| 71 | * @body0: first display list body |
| 72 | * @fragments: list of extra display list bodies |
| 73 | */ |
| 74 | struct vsp1_dl_list { |
| 75 | struct list_head list; |
| 76 | struct vsp1_dl_manager *dlm; |
| 77 | |
| 78 | struct vsp1_dl_header *header; |
| 79 | dma_addr_t dma; |
| 80 | |
| 81 | struct vsp1_dl_body body0; |
| 82 | struct list_head fragments; |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 83 | }; |
| 84 | |
Laurent Pinchart | 1216198 | 2015-11-14 22:48:27 -0200 | [diff] [blame] | 85 | enum vsp1_dl_mode { |
| 86 | VSP1_DL_MODE_HEADER, |
| 87 | VSP1_DL_MODE_HEADERLESS, |
| 88 | }; |
| 89 | |
Laurent Pinchart | ef9621b | 2015-11-14 22:27:52 -0200 | [diff] [blame] | 90 | /** |
| 91 | * struct vsp1_dl_manager - Display List manager |
Laurent Pinchart | 1216198 | 2015-11-14 22:48:27 -0200 | [diff] [blame] | 92 | * @index: index of the related WPF |
| 93 | * @mode: display list operation mode (header or headerless) |
Laurent Pinchart | ef9621b | 2015-11-14 22:27:52 -0200 | [diff] [blame] | 94 | * @vsp1: the VSP1 device |
| 95 | * @lock: protects the active, queued and pending lists |
| 96 | * @free: array of all free display lists |
| 97 | * @active: list currently being processed (loaded) by hardware |
| 98 | * @queued: list queued to the hardware (written to the DL registers) |
| 99 | * @pending: list waiting to be queued to the hardware |
| 100 | */ |
| 101 | struct vsp1_dl_manager { |
Laurent Pinchart | 1216198 | 2015-11-14 22:48:27 -0200 | [diff] [blame] | 102 | unsigned int index; |
| 103 | enum vsp1_dl_mode mode; |
Laurent Pinchart | ef9621b | 2015-11-14 22:27:52 -0200 | [diff] [blame] | 104 | struct vsp1_device *vsp1; |
| 105 | |
| 106 | spinlock_t lock; |
| 107 | struct list_head free; |
| 108 | struct vsp1_dl_list *active; |
| 109 | struct vsp1_dl_list *queued; |
| 110 | struct vsp1_dl_list *pending; |
| 111 | }; |
| 112 | |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 113 | /* ----------------------------------------------------------------------------- |
Laurent Pinchart | f81e83c | 2016-03-03 13:36:34 -0300 | [diff] [blame^] | 114 | * Display List Body Management |
| 115 | */ |
| 116 | |
| 117 | /* |
| 118 | * Initialize a display list body object and allocate DMA memory for the body |
| 119 | * data. The display list body object is expected to have been initialized to |
| 120 | * 0 when allocated. |
| 121 | */ |
| 122 | static int vsp1_dl_body_init(struct vsp1_device *vsp1, |
| 123 | struct vsp1_dl_body *dlb, unsigned int num_entries, |
| 124 | size_t extra_size) |
| 125 | { |
| 126 | size_t size = num_entries * sizeof(*dlb->entries) + extra_size; |
| 127 | |
| 128 | dlb->vsp1 = vsp1; |
| 129 | dlb->size = size; |
| 130 | |
| 131 | dlb->entries = dma_alloc_wc(vsp1->dev, dlb->size, &dlb->dma, |
| 132 | GFP_KERNEL); |
| 133 | if (!dlb->entries) |
| 134 | return -ENOMEM; |
| 135 | |
| 136 | return 0; |
| 137 | } |
| 138 | |
| 139 | /* |
| 140 | * Cleanup a display list body and free allocated DMA memory allocated. |
| 141 | */ |
| 142 | static void vsp1_dl_body_cleanup(struct vsp1_dl_body *dlb) |
| 143 | { |
| 144 | dma_free_wc(dlb->vsp1->dev, dlb->size, dlb->entries, dlb->dma); |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * vsp1_dl_fragment_alloc - Allocate a display list fragment |
| 149 | * @vsp1: The VSP1 device |
| 150 | * @num_entries: The maximum number of entries that the fragment can contain |
| 151 | * |
| 152 | * Allocate a display list fragment with enough memory to contain the requested |
| 153 | * number of entries. |
| 154 | * |
| 155 | * Return a pointer to a fragment on success or NULL if memory can't be |
| 156 | * allocated. |
| 157 | */ |
| 158 | struct vsp1_dl_body *vsp1_dl_fragment_alloc(struct vsp1_device *vsp1, |
| 159 | unsigned int num_entries) |
| 160 | { |
| 161 | struct vsp1_dl_body *dlb; |
| 162 | int ret; |
| 163 | |
| 164 | dlb = kzalloc(sizeof(*dlb), GFP_KERNEL); |
| 165 | if (!dlb) |
| 166 | return NULL; |
| 167 | |
| 168 | ret = vsp1_dl_body_init(vsp1, dlb, num_entries, 0); |
| 169 | if (ret < 0) { |
| 170 | kfree(dlb); |
| 171 | return NULL; |
| 172 | } |
| 173 | |
| 174 | return dlb; |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * vsp1_dl_fragment_free - Free a display list fragment |
| 179 | * @dlb: The fragment |
| 180 | * |
| 181 | * Free the given display list fragment and the associated DMA memory. |
| 182 | * |
| 183 | * Fragments must only be freed explicitly if they are not added to a display |
| 184 | * list, as the display list will take ownership of them and free them |
| 185 | * otherwise. Manual free typically happens at cleanup time for fragments that |
| 186 | * have been allocated but not used. |
| 187 | * |
| 188 | * Passing a NULL pointer to this function is safe, in that case no operation |
| 189 | * will be performed. |
| 190 | */ |
| 191 | void vsp1_dl_fragment_free(struct vsp1_dl_body *dlb) |
| 192 | { |
| 193 | if (!dlb) |
| 194 | return; |
| 195 | |
| 196 | vsp1_dl_body_cleanup(dlb); |
| 197 | kfree(dlb); |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * vsp1_dl_fragment_write - Write a register to a display list fragment |
| 202 | * @dlb: The fragment |
| 203 | * @reg: The register address |
| 204 | * @data: The register value |
| 205 | * |
| 206 | * Write the given register and value to the display list fragment. The maximum |
| 207 | * number of entries that can be written in a fragment is specified when the |
| 208 | * fragment is allocated by vsp1_dl_fragment_alloc(). |
| 209 | */ |
| 210 | void vsp1_dl_fragment_write(struct vsp1_dl_body *dlb, u32 reg, u32 data) |
| 211 | { |
| 212 | dlb->entries[dlb->num_entries].addr = reg; |
| 213 | dlb->entries[dlb->num_entries].data = data; |
| 214 | dlb->num_entries++; |
| 215 | } |
| 216 | |
| 217 | /* ----------------------------------------------------------------------------- |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 218 | * Display List Transaction Management |
| 219 | */ |
| 220 | |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 221 | static struct vsp1_dl_list *vsp1_dl_list_alloc(struct vsp1_dl_manager *dlm) |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 222 | { |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 223 | struct vsp1_dl_list *dl; |
Laurent Pinchart | 1216198 | 2015-11-14 22:48:27 -0200 | [diff] [blame] | 224 | size_t header_size; |
Laurent Pinchart | f81e83c | 2016-03-03 13:36:34 -0300 | [diff] [blame^] | 225 | int ret; |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 226 | |
| 227 | dl = kzalloc(sizeof(*dl), GFP_KERNEL); |
| 228 | if (!dl) |
| 229 | return NULL; |
| 230 | |
Laurent Pinchart | f81e83c | 2016-03-03 13:36:34 -0300 | [diff] [blame^] | 231 | INIT_LIST_HEAD(&dl->fragments); |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 232 | dl->dlm = dlm; |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 233 | |
Laurent Pinchart | f81e83c | 2016-03-03 13:36:34 -0300 | [diff] [blame^] | 234 | /* Initialize the display list body and allocate DMA memory for the body |
| 235 | * and the optional header. Both are allocated together to avoid memory |
| 236 | * fragmentation, with the header located right after the body in |
| 237 | * memory. |
| 238 | */ |
| 239 | header_size = dlm->mode == VSP1_DL_MODE_HEADER |
| 240 | ? ALIGN(sizeof(struct vsp1_dl_header), 8) |
| 241 | : 0; |
| 242 | |
| 243 | ret = vsp1_dl_body_init(dlm->vsp1, &dl->body0, VSP1_DL_NUM_ENTRIES, |
| 244 | header_size); |
| 245 | if (ret < 0) { |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 246 | kfree(dl); |
| 247 | return NULL; |
| 248 | } |
| 249 | |
Laurent Pinchart | 1216198 | 2015-11-14 22:48:27 -0200 | [diff] [blame] | 250 | if (dlm->mode == VSP1_DL_MODE_HEADER) { |
Laurent Pinchart | f81e83c | 2016-03-03 13:36:34 -0300 | [diff] [blame^] | 251 | size_t header_offset = VSP1_DL_NUM_ENTRIES |
| 252 | * sizeof(*dl->body0.entries); |
| 253 | |
| 254 | dl->header = ((void *)dl->body0.entries) + header_offset; |
| 255 | dl->dma = dl->body0.dma + header_offset; |
| 256 | |
Laurent Pinchart | 1216198 | 2015-11-14 22:48:27 -0200 | [diff] [blame] | 257 | memset(dl->header, 0, sizeof(*dl->header)); |
Laurent Pinchart | f81e83c | 2016-03-03 13:36:34 -0300 | [diff] [blame^] | 258 | dl->header->lists[0].addr = dl->body0.dma; |
Laurent Pinchart | 1216198 | 2015-11-14 22:48:27 -0200 | [diff] [blame] | 259 | dl->header->flags = VSP1_DLH_INT_ENABLE; |
| 260 | } |
| 261 | |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 262 | return dl; |
| 263 | } |
| 264 | |
Laurent Pinchart | f81e83c | 2016-03-03 13:36:34 -0300 | [diff] [blame^] | 265 | static void vsp1_dl_list_free_fragments(struct vsp1_dl_list *dl) |
| 266 | { |
| 267 | struct vsp1_dl_body *dlb, *next; |
| 268 | |
| 269 | list_for_each_entry_safe(dlb, next, &dl->fragments, list) { |
| 270 | list_del(&dlb->list); |
| 271 | vsp1_dl_body_cleanup(dlb); |
| 272 | kfree(dlb); |
| 273 | } |
| 274 | } |
| 275 | |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 276 | static void vsp1_dl_list_free(struct vsp1_dl_list *dl) |
| 277 | { |
Laurent Pinchart | f81e83c | 2016-03-03 13:36:34 -0300 | [diff] [blame^] | 278 | vsp1_dl_body_cleanup(&dl->body0); |
| 279 | vsp1_dl_list_free_fragments(dl); |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 280 | kfree(dl); |
| 281 | } |
| 282 | |
| 283 | /** |
| 284 | * vsp1_dl_list_get - Get a free display list |
| 285 | * @dlm: The display list manager |
| 286 | * |
| 287 | * Get a display list from the pool of free lists and return it. |
| 288 | * |
| 289 | * This function must be called without the display list manager lock held. |
| 290 | */ |
| 291 | struct vsp1_dl_list *vsp1_dl_list_get(struct vsp1_dl_manager *dlm) |
| 292 | { |
| 293 | struct vsp1_dl_list *dl = NULL; |
| 294 | unsigned long flags; |
| 295 | |
| 296 | spin_lock_irqsave(&dlm->lock, flags); |
| 297 | |
| 298 | if (!list_empty(&dlm->free)) { |
| 299 | dl = list_first_entry(&dlm->free, struct vsp1_dl_list, list); |
| 300 | list_del(&dl->list); |
| 301 | } |
| 302 | |
| 303 | spin_unlock_irqrestore(&dlm->lock, flags); |
| 304 | |
| 305 | return dl; |
| 306 | } |
| 307 | |
Laurent Pinchart | d2c1b02 | 2016-03-03 09:26:47 -0300 | [diff] [blame] | 308 | /* This function must be called with the display list manager lock held.*/ |
| 309 | static void __vsp1_dl_list_put(struct vsp1_dl_list *dl) |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 310 | { |
| 311 | if (!dl) |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 312 | return; |
| 313 | |
Laurent Pinchart | f81e83c | 2016-03-03 13:36:34 -0300 | [diff] [blame^] | 314 | vsp1_dl_list_free_fragments(dl); |
| 315 | dl->body0.num_entries = 0; |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 316 | |
| 317 | list_add_tail(&dl->list, &dl->dlm->free); |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 318 | } |
| 319 | |
Laurent Pinchart | d2c1b02 | 2016-03-03 09:26:47 -0300 | [diff] [blame] | 320 | /** |
| 321 | * vsp1_dl_list_put - Release a display list |
| 322 | * @dl: The display list |
| 323 | * |
| 324 | * Release the display list and return it to the pool of free lists. |
| 325 | * |
| 326 | * Passing a NULL pointer to this function is safe, in that case no operation |
| 327 | * will be performed. |
| 328 | */ |
| 329 | void vsp1_dl_list_put(struct vsp1_dl_list *dl) |
| 330 | { |
| 331 | unsigned long flags; |
| 332 | |
| 333 | if (!dl) |
| 334 | return; |
| 335 | |
| 336 | spin_lock_irqsave(&dl->dlm->lock, flags); |
| 337 | __vsp1_dl_list_put(dl); |
| 338 | spin_unlock_irqrestore(&dl->dlm->lock, flags); |
| 339 | } |
| 340 | |
Laurent Pinchart | f81e83c | 2016-03-03 13:36:34 -0300 | [diff] [blame^] | 341 | /** |
| 342 | * vsp1_dl_list_write - Write a register to the display list |
| 343 | * @dl: The display list |
| 344 | * @reg: The register address |
| 345 | * @data: The register value |
| 346 | * |
| 347 | * Write the given register and value to the display list. Up to 256 registers |
| 348 | * can be written per display list. |
| 349 | */ |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 350 | void vsp1_dl_list_write(struct vsp1_dl_list *dl, u32 reg, u32 data) |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 351 | { |
Laurent Pinchart | f81e83c | 2016-03-03 13:36:34 -0300 | [diff] [blame^] | 352 | vsp1_dl_fragment_write(&dl->body0, reg, data); |
| 353 | } |
| 354 | |
| 355 | /** |
| 356 | * vsp1_dl_list_add_fragment - Add a fragment to the display list |
| 357 | * @dl: The display list |
| 358 | * @dlb: The fragment |
| 359 | * |
| 360 | * Add a display list body as a fragment to a display list. Registers contained |
| 361 | * in fragments are processed after registers contained in the main display |
| 362 | * list, in the order in which fragments are added. |
| 363 | * |
| 364 | * Adding a fragment to a display list passes ownership of the fragment to the |
| 365 | * list. The caller must not touch the fragment after this call, and must not |
| 366 | * free it explicitly with vsp1_dl_fragment_free(). |
| 367 | * |
| 368 | * Fragments are only usable for display lists in header mode. Attempt to |
| 369 | * add a fragment to a header-less display list will return an error. |
| 370 | */ |
| 371 | int vsp1_dl_list_add_fragment(struct vsp1_dl_list *dl, |
| 372 | struct vsp1_dl_body *dlb) |
| 373 | { |
| 374 | /* Multi-body lists are only available in header mode. */ |
| 375 | if (dl->dlm->mode != VSP1_DL_MODE_HEADER) |
| 376 | return -EINVAL; |
| 377 | |
| 378 | list_add_tail(&dlb->list, &dl->fragments); |
| 379 | return 0; |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 380 | } |
| 381 | |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 382 | void vsp1_dl_list_commit(struct vsp1_dl_list *dl) |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 383 | { |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 384 | struct vsp1_dl_manager *dlm = dl->dlm; |
| 385 | struct vsp1_device *vsp1 = dlm->vsp1; |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 386 | unsigned long flags; |
| 387 | bool update; |
| 388 | |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 389 | spin_lock_irqsave(&dlm->lock, flags); |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 390 | |
Laurent Pinchart | 1216198 | 2015-11-14 22:48:27 -0200 | [diff] [blame] | 391 | if (dl->dlm->mode == VSP1_DL_MODE_HEADER) { |
Laurent Pinchart | f81e83c | 2016-03-03 13:36:34 -0300 | [diff] [blame^] | 392 | struct vsp1_dl_header_list *hdr = dl->header->lists; |
| 393 | struct vsp1_dl_body *dlb; |
| 394 | unsigned int num_lists = 0; |
| 395 | |
| 396 | /* Fill the header with the display list bodies addresses and |
| 397 | * sizes. The address of the first body has already been filled |
| 398 | * when the display list was allocated. |
| 399 | * |
| 400 | * In header mode the caller guarantees that the hardware is |
| 401 | * idle at this point. |
Laurent Pinchart | 1216198 | 2015-11-14 22:48:27 -0200 | [diff] [blame] | 402 | */ |
Laurent Pinchart | f81e83c | 2016-03-03 13:36:34 -0300 | [diff] [blame^] | 403 | hdr->num_bytes = dl->body0.num_entries |
| 404 | * sizeof(*dl->header->lists); |
| 405 | |
| 406 | list_for_each_entry(dlb, &dl->fragments, list) { |
| 407 | num_lists++; |
| 408 | hdr++; |
| 409 | |
| 410 | hdr->addr = dlb->dma; |
| 411 | hdr->num_bytes = dlb->num_entries |
| 412 | * sizeof(*dl->header->lists); |
| 413 | } |
| 414 | |
| 415 | dl->header->num_lists = num_lists; |
Laurent Pinchart | 1216198 | 2015-11-14 22:48:27 -0200 | [diff] [blame] | 416 | vsp1_write(vsp1, VI6_DL_HDR_ADDR(dlm->index), dl->dma); |
| 417 | |
| 418 | dlm->active = dl; |
| 419 | goto done; |
| 420 | } |
| 421 | |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 422 | /* Once the UPD bit has been set the hardware can start processing the |
| 423 | * display list at any time and we can't touch the address and size |
| 424 | * registers. In that case mark the update as pending, it will be |
| 425 | * queued up to the hardware by the frame end interrupt handler. |
| 426 | */ |
| 427 | update = !!(vsp1_read(vsp1, VI6_DL_BODY_SIZE) & VI6_DL_BODY_SIZE_UPD); |
| 428 | if (update) { |
Laurent Pinchart | d2c1b02 | 2016-03-03 09:26:47 -0300 | [diff] [blame] | 429 | __vsp1_dl_list_put(dlm->pending); |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 430 | dlm->pending = dl; |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 431 | goto done; |
| 432 | } |
| 433 | |
| 434 | /* Program the hardware with the display list body address and size. |
| 435 | * The UPD bit will be cleared by the device when the display list is |
| 436 | * processed. |
| 437 | */ |
Laurent Pinchart | f81e83c | 2016-03-03 13:36:34 -0300 | [diff] [blame^] | 438 | vsp1_write(vsp1, VI6_DL_HDR_ADDR(0), dl->body0.dma); |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 439 | vsp1_write(vsp1, VI6_DL_BODY_SIZE, VI6_DL_BODY_SIZE_UPD | |
Laurent Pinchart | f81e83c | 2016-03-03 13:36:34 -0300 | [diff] [blame^] | 440 | (dl->body0.num_entries * sizeof(*dl->header->lists))); |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 441 | |
Laurent Pinchart | d2c1b02 | 2016-03-03 09:26:47 -0300 | [diff] [blame] | 442 | __vsp1_dl_list_put(dlm->queued); |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 443 | dlm->queued = dl; |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 444 | |
| 445 | done: |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 446 | spin_unlock_irqrestore(&dlm->lock, flags); |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | /* ----------------------------------------------------------------------------- |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 450 | * Display List Manager |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 451 | */ |
| 452 | |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 453 | /* Interrupt Handling */ |
| 454 | void vsp1_dlm_irq_display_start(struct vsp1_dl_manager *dlm) |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 455 | { |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 456 | spin_lock(&dlm->lock); |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 457 | |
| 458 | /* The display start interrupt signals the end of the display list |
| 459 | * processing by the device. The active display list, if any, won't be |
| 460 | * accessed anymore and can be reused. |
| 461 | */ |
Laurent Pinchart | d2c1b02 | 2016-03-03 09:26:47 -0300 | [diff] [blame] | 462 | __vsp1_dl_list_put(dlm->active); |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 463 | dlm->active = NULL; |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 464 | |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 465 | spin_unlock(&dlm->lock); |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 466 | } |
| 467 | |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 468 | void vsp1_dlm_irq_frame_end(struct vsp1_dl_manager *dlm) |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 469 | { |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 470 | struct vsp1_device *vsp1 = dlm->vsp1; |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 471 | |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 472 | spin_lock(&dlm->lock); |
| 473 | |
Laurent Pinchart | d2c1b02 | 2016-03-03 09:26:47 -0300 | [diff] [blame] | 474 | __vsp1_dl_list_put(dlm->active); |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 475 | dlm->active = NULL; |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 476 | |
Laurent Pinchart | 1216198 | 2015-11-14 22:48:27 -0200 | [diff] [blame] | 477 | /* Header mode is used for mem-to-mem pipelines only. We don't need to |
| 478 | * perform any operation as there can't be any new display list queued |
| 479 | * in that case. |
| 480 | */ |
| 481 | if (dlm->mode == VSP1_DL_MODE_HEADER) |
| 482 | goto done; |
| 483 | |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 484 | /* The UPD bit set indicates that the commit operation raced with the |
| 485 | * interrupt and occurred after the frame end event and UPD clear but |
| 486 | * before interrupt processing. The hardware hasn't taken the update |
| 487 | * into account yet, we'll thus skip one frame and retry. |
| 488 | */ |
| 489 | if (vsp1_read(vsp1, VI6_DL_BODY_SIZE) & VI6_DL_BODY_SIZE_UPD) |
| 490 | goto done; |
| 491 | |
| 492 | /* The device starts processing the queued display list right after the |
| 493 | * frame end interrupt. The display list thus becomes active. |
| 494 | */ |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 495 | if (dlm->queued) { |
| 496 | dlm->active = dlm->queued; |
| 497 | dlm->queued = NULL; |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | /* Now that the UPD bit has been cleared we can queue the next display |
| 501 | * list to the hardware if one has been prepared. |
| 502 | */ |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 503 | if (dlm->pending) { |
| 504 | struct vsp1_dl_list *dl = dlm->pending; |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 505 | |
Laurent Pinchart | f81e83c | 2016-03-03 13:36:34 -0300 | [diff] [blame^] | 506 | vsp1_write(vsp1, VI6_DL_HDR_ADDR(0), dl->body0.dma); |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 507 | vsp1_write(vsp1, VI6_DL_BODY_SIZE, VI6_DL_BODY_SIZE_UPD | |
Laurent Pinchart | f81e83c | 2016-03-03 13:36:34 -0300 | [diff] [blame^] | 508 | (dl->body0.num_entries * |
| 509 | sizeof(*dl->header->lists))); |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 510 | |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 511 | dlm->queued = dl; |
| 512 | dlm->pending = NULL; |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | done: |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 516 | spin_unlock(&dlm->lock); |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 517 | } |
| 518 | |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 519 | /* Hardware Setup */ |
| 520 | void vsp1_dlm_setup(struct vsp1_device *vsp1) |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 521 | { |
Laurent Pinchart | 351bbf9 | 2015-11-01 15:18:56 -0200 | [diff] [blame] | 522 | u32 ctrl = (256 << VI6_DL_CTRL_AR_WAIT_SHIFT) |
| 523 | | VI6_DL_CTRL_DC2 | VI6_DL_CTRL_DC1 | VI6_DL_CTRL_DC0 |
| 524 | | VI6_DL_CTRL_DLE; |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 525 | |
Laurent Pinchart | 351bbf9 | 2015-11-01 15:18:56 -0200 | [diff] [blame] | 526 | /* The DRM pipeline operates with display lists in Continuous Frame |
| 527 | * Mode, all other pipelines use manual start. |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 528 | */ |
| 529 | if (vsp1->drm) |
Laurent Pinchart | 351bbf9 | 2015-11-01 15:18:56 -0200 | [diff] [blame] | 530 | ctrl |= VI6_DL_CTRL_CFM0 | VI6_DL_CTRL_NH0; |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 531 | |
| 532 | vsp1_write(vsp1, VI6_DL_CTRL, ctrl); |
| 533 | vsp1_write(vsp1, VI6_DL_SWAP, VI6_DL_SWAP_LWS); |
| 534 | } |
| 535 | |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 536 | void vsp1_dlm_reset(struct vsp1_dl_manager *dlm) |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 537 | { |
Laurent Pinchart | d2c1b02 | 2016-03-03 09:26:47 -0300 | [diff] [blame] | 538 | unsigned long flags; |
| 539 | |
| 540 | spin_lock_irqsave(&dlm->lock, flags); |
| 541 | |
| 542 | __vsp1_dl_list_put(dlm->active); |
| 543 | __vsp1_dl_list_put(dlm->queued); |
| 544 | __vsp1_dl_list_put(dlm->pending); |
| 545 | |
| 546 | spin_unlock_irqrestore(&dlm->lock, flags); |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 547 | |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 548 | dlm->active = NULL; |
| 549 | dlm->queued = NULL; |
| 550 | dlm->pending = NULL; |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 551 | } |
| 552 | |
Laurent Pinchart | ef9621b | 2015-11-14 22:27:52 -0200 | [diff] [blame] | 553 | struct vsp1_dl_manager *vsp1_dlm_create(struct vsp1_device *vsp1, |
Laurent Pinchart | 1216198 | 2015-11-14 22:48:27 -0200 | [diff] [blame] | 554 | unsigned int index, |
Laurent Pinchart | ef9621b | 2015-11-14 22:27:52 -0200 | [diff] [blame] | 555 | unsigned int prealloc) |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 556 | { |
Laurent Pinchart | ef9621b | 2015-11-14 22:27:52 -0200 | [diff] [blame] | 557 | struct vsp1_dl_manager *dlm; |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 558 | unsigned int i; |
| 559 | |
Laurent Pinchart | ef9621b | 2015-11-14 22:27:52 -0200 | [diff] [blame] | 560 | dlm = devm_kzalloc(vsp1->dev, sizeof(*dlm), GFP_KERNEL); |
| 561 | if (!dlm) |
| 562 | return NULL; |
| 563 | |
Laurent Pinchart | 1216198 | 2015-11-14 22:48:27 -0200 | [diff] [blame] | 564 | dlm->index = index; |
| 565 | dlm->mode = index == 0 && !vsp1->info->uapi |
| 566 | ? VSP1_DL_MODE_HEADERLESS : VSP1_DL_MODE_HEADER; |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 567 | dlm->vsp1 = vsp1; |
| 568 | |
| 569 | spin_lock_init(&dlm->lock); |
| 570 | INIT_LIST_HEAD(&dlm->free); |
| 571 | |
| 572 | for (i = 0; i < prealloc; ++i) { |
| 573 | struct vsp1_dl_list *dl; |
| 574 | |
| 575 | dl = vsp1_dl_list_alloc(dlm); |
| 576 | if (!dl) |
Laurent Pinchart | ef9621b | 2015-11-14 22:27:52 -0200 | [diff] [blame] | 577 | return NULL; |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 578 | |
| 579 | list_add_tail(&dl->list, &dlm->free); |
| 580 | } |
| 581 | |
Laurent Pinchart | ef9621b | 2015-11-14 22:27:52 -0200 | [diff] [blame] | 582 | return dlm; |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 583 | } |
| 584 | |
Laurent Pinchart | ef9621b | 2015-11-14 22:27:52 -0200 | [diff] [blame] | 585 | void vsp1_dlm_destroy(struct vsp1_dl_manager *dlm) |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 586 | { |
| 587 | struct vsp1_dl_list *dl, *next; |
| 588 | |
Laurent Pinchart | ef9621b | 2015-11-14 22:27:52 -0200 | [diff] [blame] | 589 | if (!dlm) |
| 590 | return; |
| 591 | |
Laurent Pinchart | c2dd2513 | 2015-11-08 20:06:57 -0200 | [diff] [blame] | 592 | list_for_each_entry_safe(dl, next, &dlm->free, list) { |
| 593 | list_del(&dl->list); |
| 594 | vsp1_dl_list_free(dl); |
| 595 | } |
Takashi Saito | 1517b03 | 2015-09-07 01:40:25 -0300 | [diff] [blame] | 596 | } |